ViewController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. package com.zskk.control;
  2. import java.io.BufferedOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.text.ParseException;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Date;
  12. import java.util.HashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. import com.alibaba.fastjson.JSON;
  16. import com.alibaba.fastjson.JSONArray;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.aliyun.oss.OSS;
  19. import com.aliyun.oss.OSSClientBuilder;
  20. import com.jfinal.core.Controller;
  21. import com.jfinal.kit.PropKit;
  22. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  23. import com.jfinal.plugin.activerecord.Db;
  24. import com.jfinal.plugin.activerecord.Record;
  25. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  26. import com.jfinal.plugin.druid.DruidPlugin;
  27. import com.zskk.service.DataService;
  28. import com.zskk.service.ServiceFactory;
  29. import com.zskk.service.ThreadPoolService;
  30. import okhttp3.FormBody;
  31. import okhttp3.MediaType;
  32. import okhttp3.OkHttpClient;
  33. import okhttp3.Request;
  34. import okhttp3.RequestBody;
  35. import okhttp3.Response;
  36. public class ViewController extends Controller {
  37. private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
  38. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  39. /**
  40. * 在被连接数据库执行sql语句
  41. */
  42. public void executeSql() {
  43. try {
  44. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  45. this.renderJson(d);
  46. } catch (Exception e) {
  47. // TODO: handle exception
  48. this.renderText(e.toString());
  49. }
  50. }
  51. /**
  52. * 在被连接数据库执行sql语句
  53. */
  54. public void executeSqlprint() {
  55. try {
  56. List<Record> d = Db.use("print").find(this.getPara("sqlstr"));
  57. this.renderJson(d);
  58. } catch (Exception e) {
  59. // TODO: handle exception
  60. this.renderText(e.toString());
  61. }
  62. }
  63. /**
  64. * 在被连接数据库执行sql语句
  65. */
  66. public void executeSqlUpdate() {
  67. try {
  68. Integer d = Db.use("connected").update(this.getPara("sqlstr"));
  69. this.renderText(d.toString());
  70. } catch (Exception e) {
  71. // TODO: handle exception
  72. this.renderText(e.toString());
  73. }
  74. }
  75. public void testConn() {
  76. try {
  77. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  78. druidPluginConnected.start();
  79. // 配置ActiveRecord插件
  80. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("print", druidPluginConnected);
  81. arpConnected.setDialect(new SqlServerDialect());
  82. arpConnected.start();
  83. } catch (Exception e) {
  84. // TODO: handle exception
  85. this.renderText(e.toString());
  86. }
  87. }
  88. public void sd() {
  89. try {
  90. DataService dService = ServiceFactory.getService(DataService.class);
  91. JSONArray jsonArray = dService.getBindList(this.getPara("s"),this.getPara("f"));
  92. for (Object object : jsonArray) {
  93. try {
  94. JSONObject jsonObject = JSON.parseObject(object.toString());
  95. String source = "";
  96. String[] sources = jsonObject.getString("source").split(",");
  97. for (int i = 0; i < sources.length; i++) {
  98. switch (sources[i]) {
  99. case "1":
  100. String sp1 = i==0?"":",";
  101. source = source + sp1+ "数字影像云公众号";
  102. break;
  103. case "2":
  104. String sp2 = i==0?"":",";
  105. source = source +sp2+ "集成链接";
  106. break;
  107. case "3":
  108. String sp3 = i==0?"":",";
  109. source = source +sp3+ "推送短信";
  110. break;
  111. default:
  112. break;
  113. }
  114. }
  115. Record recordei = Db.use("connected").findFirst("select * from examinfo where studyuid=?", jsonObject.getString("studyuid"));
  116. Record recordrc = Db.use("connected").findFirst("select * from reportcheck where studyuid=?", jsonObject.getString("studyuid"));
  117. Record recordri = Db.use("connected").findFirst("select * from reportinfo where studyuid=?", jsonObject.getString("studyuid"));
  118. if (recordei==null && recordrc==null && recordri==null) {
  119. continue;
  120. }
  121. if (recordei!=null) {
  122. Db.use("connected").update("update examinfo set ViewFlag='1',ViewTime=?,ViewName=? where studyuid=?",jsonObject.getString("createdAt"),source,jsonObject.getString("studyuid"));
  123. }
  124. if (recordrc!=null) {
  125. Db.use("connected").update("update reportcheck set ViewFlag='1',ViewTime=?,ViewName=? where studyuid=?",jsonObject.getString("createdAt"),source,jsonObject.getString("studyuid"));
  126. }
  127. if (recordri!=null) {
  128. Db.use("connected").update("update reportinfo set ViewFlag='1',ViewTime=?,ViewName=? where studyuid=?",jsonObject.getString("createdAt"),source,jsonObject.getString("studyuid"));
  129. }
  130. } catch (Exception e) {
  131. // TODO: handle exception
  132. continue;
  133. }
  134. }
  135. renderJson(jsonArray);
  136. } catch (Exception e) {
  137. // TODO: handle exception
  138. renderText(e.toString());
  139. }
  140. }
  141. public void sdtb() {
  142. try {
  143. DataService dService = ServiceFactory.getService(DataService.class);
  144. Record record = Db.use("connected").findFirst("select * from reportcheck where studyuid=?",this.getPara("code"));
  145. Map<String, String> params = new HashMap<>();
  146. // 1:exam_id 2:patient_num 3:accession_num 4:study_uid
  147. params.put("type", "4");
  148. params.put("institution_id", PropKit.get("institution_id"));
  149. params.put("code", record.getStr("studyuid"));
  150. // 报告医生姓名
  151. params.put("report_doctor_name", record.getStr("reportdoctor"));
  152. // 报告时间
  153. params.put("report_datetime", record.getStr("reportdate"));
  154. // 审核医生姓名
  155. params.put("review_doctor_name",
  156. record.getStr("reviewdoctor") == null ? "" : record.getStr("reviewdoctor"));
  157. // 审核时间
  158. params.put("review_datetime", record.getStr("checktime"));
  159. // 确认医生姓名
  160. params.put("confirm_doctor_name",
  161. record.getStr("reviewdoctor") == null ? "" : record.getStr("reviewdoctor"));
  162. // 确认时间
  163. params.put("confirm_datetime", record.getStr("checktime"));
  164. // 意见建议
  165. params.put("impression", record.getStr("impression"));
  166. // 影像所见
  167. params.put("description", record.getStr("description"));
  168. // exams表
  169. // 申请科室
  170. params.put("application_department", record.getStr("department"));
  171. // 申请医生
  172. params.put("application_doctor", record.getStr("clinicaldoctor"));
  173. // 临床诊断
  174. params.put("clin_diag", record.getStr("diagnosis") == null ? "" : record.getStr("diagnosis"));
  175. // 症状
  176. params.put("clin_symp", record.getStr("symptom"));
  177. // patient_infos表
  178. // 患者姓名
  179. params.put("name", record.getStr("patientname"));
  180. // 患者手机号
  181. params.put("phone", record.getStr("phone"));
  182. // 患者身份证号
  183. params.put("card_num", record.getStr("idcard"));
  184. // 检查结果1阴2阳
  185. params.put("report_result", "0");
  186. // 门诊号住院号
  187. params.put("hopitalized_no", "");
  188. String x =dService.saveReport(params);
  189. Map<String, String> annex_params = new HashMap<>();
  190. annex_params.put("institution_id", PropKit.get("institution_id"));
  191. annex_params.put("type", "4");
  192. annex_params.put("code", record.getStr("studyuid"));
  193. //附件类型1.mp4 2.pdf 3.jpeg
  194. annex_params.put("annex_class_code", "3");
  195. dService.saveAnnex(annex_params, record.getStr("reportpath"));
  196. renderText(x);
  197. } catch (Exception e) {
  198. // TODO: handle exception
  199. renderText(e.toString());
  200. }
  201. }
  202. public void dld() {
  203. DataService dService = ServiceFactory.getService(DataService.class);
  204. List<Record> records = Db.use("print").find("select * from IMAGEVIEW where ADDTIME >? order by ADDTIME desc",this.getPara("time"));
  205. for (Record record : records) {
  206. try {
  207. if (record == null) {
  208. continue;
  209. }
  210. Map<String, String> annex_params = new HashMap<>();
  211. annex_params.put("institution_id", PropKit.get("institution_id"));
  212. annex_params.put("type", "2");
  213. annex_params.put("code", record.getStr("CHECKID"));
  214. //附件类型1.mp4 2.pdf 3.jpeg 4.png
  215. annex_params.put("annex_class_code", "4");
  216. annex_params.put("exam_datetime", parseStringToDate2(record.getStr("ADDTIME")));
  217. dService.saveAnnex(annex_params, record.getStr("IMGURL"));
  218. } catch (Exception e) {
  219. // TODO: handle exception
  220. continue;
  221. }
  222. }
  223. renderText(records.toString());
  224. }
  225. /**
  226. * 日期字符串格式转换
  227. *
  228. * @param dateStr
  229. * @return
  230. */
  231. private String parseStringToDate1() {
  232. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  233. Date date = new Date();
  234. String timeString = null;
  235. Long i = date.getTime();
  236. Long j = i - 43200;
  237. Date newdate = new Date(j);
  238. timeString = sdf.format(newdate);
  239. return timeString;
  240. }
  241. /**
  242. * 日期字符串格式转换
  243. * @param dateStr
  244. * @return
  245. */
  246. private String parseStringToDate2(String dateStr) {
  247. if (dateStr == null) {
  248. return "";
  249. }
  250. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  251. Date date = null;
  252. String timeString = null;
  253. try {
  254. date = sdf.parse(dateStr);
  255. SimpleDateFormat sdf2= new SimpleDateFormat("yyyyMMdd");
  256. timeString = sdf2.format(date);
  257. } catch (ParseException e) {
  258. // TODO Auto-generated catch block
  259. e.printStackTrace();
  260. }
  261. return timeString;
  262. }
  263. public static String getFileWithUrl(String url, String filename) {
  264. Request request = new Request.Builder().url(url).build();
  265. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  266. if (!response.isSuccessful())
  267. throw new IOException("Unexpected code " + response);
  268. InputStream inputStream = response.body().source().inputStream();
  269. // 本地文件夹目录(下载位置)
  270. String folder = PropKit.get("oss_localPath");
  271. // 下载文件保存位置
  272. String savepath = folder + "/" + filename;
  273. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
  274. byte[] data = new byte[1024];
  275. int len;
  276. int available = inputStream.available();
  277. while ((len = inputStream.read(data)) != -1) {
  278. bufferedOutputStream.write(data, 0, len);
  279. }
  280. bufferedOutputStream.flush();
  281. bufferedOutputStream.close();
  282. inputStream.close();
  283. return savepath;
  284. } catch (IOException e) {
  285. // TODO Auto-generated catch block
  286. e.printStackTrace();
  287. return "";
  288. }
  289. }
  290. public static DruidPlugin createConnectedDruidPlugin() {
  291. return new DruidPlugin(PropKit.get("jdbcUrl_print"), PropKit.get("user_print"),PropKit.get("password_print").trim());
  292. }
  293. /**
  294. * post请求
  295. * @param url-请求地址
  296. * @param map-参数集合
  297. * @return
  298. */
  299. private static String doPost(String url, Map<String, String> map) {
  300. FormBody.Builder builder = new FormBody.Builder();
  301. for (String key : map.keySet()) {
  302. builder.add(key, map.get(key));
  303. }
  304. RequestBody formBody = builder.build();
  305. Request request = new Request.Builder().url(url).post(formBody).build();
  306. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  307. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  308. String content = response.body().string();
  309. return content;
  310. } catch (IOException e) {
  311. // TODO Auto-generated catch block
  312. e.printStackTrace();
  313. return null;
  314. }
  315. }
  316. /**
  317. * 日期字符串格式转换
  318. * @param dateStr
  319. * @return
  320. */
  321. private Date parseStringToDate(String dateStr) {
  322. if (dateStr == null) {
  323. return new Date();
  324. }
  325. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  326. Date date = null;
  327. try {
  328. date = sdf.parse(dateStr);
  329. } catch (ParseException e) {
  330. // TODO Auto-generated catch block
  331. e.printStackTrace();
  332. }
  333. return date;
  334. }
  335. private String parseStringToDate() {
  336. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
  337. Date date = new Date();
  338. String timeString = sdf.format(date);
  339. return timeString;
  340. }
  341. public static void main(String[] args) {
  342. Map<String,String> paramsMap=new HashMap<String,String>();
  343. paramsMap.put("institution_id", "44100001");
  344. String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
  345. System.out.println(contentString);
  346. }
  347. }