123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package com.zskk.control;
- import java.io.IOException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.jfinal.core.Controller;
- import com.jfinal.kit.PropKit;
- import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
- import com.jfinal.plugin.activerecord.Db;
- import com.jfinal.plugin.activerecord.Record;
- import com.jfinal.plugin.activerecord.dialect.OracleDialect;
- import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
- import com.jfinal.plugin.druid.DruidPlugin;
- import com.zskk.tools.AESUtils;
- import okhttp3.FormBody;
- import okhttp3.MediaType;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- public class ViewController extends Controller {
- private static final MediaType JSON_CODE = MediaType.get("application/json");
- private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
- /**
- * 在被连接数据库执行sql语句
- */
- public void executeSql() {
- try {
- List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
- this.renderJson(d);
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
-
- }
- /**
- * 获取未出报告的检查列表
- * @param instutionId
- * @param number
- */
- public void getExamList() {
- String IV = "0000000000000000";
- Map <String,String> map = new HashMap<String,String>();
- map.put("exam_status","3");
- map.put("createAt", "2023-06-01 00:00:00,2023-06-15 12:00:00");
- map.put("num", "20");
- String aesEncryptStr = AESUtils.aesEncryptStr(JSON.toJSONString(map), PropKit.get("nw_key"),IV);
- Map <String,String> mapaes = new HashMap<String,String>();
- mapaes.put("data",aesEncryptStr);
- String content = postWithParameters("http://127.0.0.1:8082/df/view/getExam", mapaes);
- this.renderText(content);
- // JSONObject jsonObject = JSON.parseObject(content);
- // if (!jsonObject.getString("msg").equals("success")) {
- // return null;
- // }
- String aesDecodeStr ="";
- try {
- aesDecodeStr = AESUtils.aesDecodeStr(content, PropKit.get("nw_key"),IV);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- // return null;
- }
- // JSONArray jsonArray = JSON.parseArray(aesDecodeStr);
- // return jsonArray;
- // this.renderJson(jsonArray);
- }
-
- public void testConn() {
- try {
- DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
- druidPluginConnected.start();
- // 配置ActiveRecord插件
- ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
- arpConnected.setDialect(new OracleDialect());
- arpConnected.start();
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- public static DruidPlugin createConnectedDruidPlugin() {
- return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
- }
- public void testConn2() {
- try {
- DruidPlugin druidPluginConnected = createConnectedDruidPlugin2(this.getPara("url"),this.getPara("name"),this.getPara("pass"));
- druidPluginConnected.start();
- // 配置ActiveRecord插件
- ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
- arpConnected.setDialect(new OracleDialect());
- arpConnected.start();
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- public void testWeb() {
- try {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("functionCode", "queryPatByPatId");
- jsonObject.put("userid", "1301");
- JSONObject jsonObject2 = new JSONObject();
- jsonObject2.put("pattoken", "appuserrequest");
- jsonObject2.put("hispatid", this.getPara("hpid"));
- jsonObject.put("data", jsonObject2);
- // String c=postWithJson(this.getPara("hpid")"http://192.168.100.181:8102/api/tjwebapi/CommQuery",jsonObject);
- String c=postWithJson(this.getPara("url","http://192.168.100.181:8102/api/tjwebapi/CommQuery"),jsonObject);
- this.renderText(c);
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- public String postWithJson(String url, JSONObject jsonObject) {
- RequestBody requestBody = RequestBody.create(JSON_CODE, jsonObject.toJSONString());
- Request request = new Request.Builder().url(url).post(requestBody).build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful())
- throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- System.out.println(content);
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
-
- public static DruidPlugin createConnectedDruidPlugin2(String url,String name,String pass) {
- return new DruidPlugin(url, name,pass.trim());
- }
- /**
- * post请求
- * @param url-请求地址
- * @param map-参数集合
- * @return
- */
- private static String doPost(String url, Map<String, String> map) {
- FormBody.Builder builder = new FormBody.Builder();
- for (String key : map.keySet()) {
- builder.add(key, map.get(key));
- }
- RequestBody formBody = builder.build();
- Request request = new Request.Builder().url(url).post(formBody).build();
-
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * 日期字符串格式转换
- * @param dateStr
- * @return
- */
- private Date parseStringToDate(String dateStr) {
- if (dateStr == null) {
- return new Date();
- }
- SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = null;
- try {
- date = sdf.parse(dateStr);
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return date;
- }
- public static String postWithParameters(String url, Map<String, String> map) {
-
- FormBody.Builder formbody = new FormBody.Builder();
-
- for (Map.Entry<String, String> entry : map.entrySet()) {
- formbody.add(entry.getKey(), entry.getValue());
- }
- RequestBody requestBody = formbody.build();
-
- Request request = new Request.Builder()
- .url(url)
- .post(requestBody)
- .build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
- public static void main(String[] args) {
- Map<String,String> paramsMap=new HashMap<String,String>();
- paramsMap.put("institution_id", "44100001");
- String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
- System.out.println(contentString);
- }
- }
|