HandleData.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. package com.jyxt.getdatabyview;
  2. import com.jyxt.getdatabyview.view.repository.IBPSRepository;
  3. import com.jyxt.getdatabyview.view.repository.LISViewRepository;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.stereotype.Component;
  9. import java.sql.Timestamp;
  10. import java.time.LocalDate;
  11. import java.time.LocalDateTime;
  12. import java.time.YearMonth;
  13. import java.time.format.DateTimeFormatter;
  14. import java.util.*;
  15. import java.util.stream.Collectors;
  16. @Component
  17. public class HandleData {
  18. private static final Logger log = LoggerFactory.getLogger(GetDataByViewApplication.class);
  19. @Autowired
  20. private LISViewRepository lisViewRepository;
  21. @Autowired
  22. private IBPSRepository ibpsRepository;
  23. @Value("${showTestCodeName}")
  24. private String showTestCodeName;
  25. @Value("${manualQryMonth}")
  26. private String manualQryMonth;
  27. @Value("${resultWithUnit}")
  28. private String resultWithUnit;
  29. @Value("${pushDate}")
  30. private String pushDate;
  31. public static final Map<String, String> RerunSampleField = new HashMap<>();
  32. public static final Map<String, String> UnControlReportField = new HashMap<>();
  33. public static final Map<String, String> PositionTransferField = new HashMap<>();
  34. public static final Map<String, String> DepartmentLeaderField = new HashMap<>();
  35. static {
  36. // 静态初始化块中填充数据
  37. RerunSampleField.put("CREATEBY", "bian_zhi_ren_");
  38. RerunSampleField.put("CREATETIME", "bian_zhi_shi_jian");
  39. RerunSampleField.put("SAMPLECODE", "biao_ben_bian_hao");
  40. // RerunSampleField.put("TESTCODE", "xiang_mu_id_");
  41. RerunSampleField.put("TESTCODENAME", "fu_jian_xiang_mu_");
  42. RerunSampleField.put("INITIALRESULT", "ce_ding_zhi_chu_j");
  43. RerunSampleField.put("RERUNRESULT", "ce_ding_zhi_fu_ji");
  44. RerunSampleField.put("REPORTRESULT", "bao_gao_zhi_");
  45. RerunSampleField.put("AUDITUSER", "jian_yan_zhe_");
  46. RerunSampleField.put("REPORTTIME", "bao_gao_shi_jian_");
  47. RerunSampleField.put("RERUNMETHODNOTE", "bei_zhu_fu_jian_f");
  48. RerunSampleField.put("PATNAME", "xing_ming_");
  49. RerunSampleField.put("RERUNMETHOD", "fu_jian_fang_shi_");
  50. RerunSampleField.put("UNIT", "dan_wei_");
  51. UnControlReportField.put("TestCode","");
  52. UnControlReportField.put("QCName","zhi_kong_pin_ming");
  53. UnControlReportField.put("QCLot","");
  54. UnControlReportField.put("QCDate","");
  55. UnControlReportField.put("QCResult","");
  56. UnControlReportField.put("SD","");
  57. UnControlReportField.put("Quant","");
  58. UnControlReportField.put("Qual","");
  59. UnControlReportField.put("ErrorType","");
  60. UnControlReportField.put("Reason","");
  61. UnControlReportField.put("Action","");
  62. UnControlReportField.put("QCFinalResult","");
  63. UnControlReportField.put("IsInControl","");
  64. UnControlReportField.put("AffectsPatientSamples","");
  65. UnControlReportField.put("AffectsResultReporting","");
  66. UnControlReportField.put("Notes","");
  67. UnControlReportField.put("QCFinalResult","");
  68. PositionTransferField.put("G002","生化免疫组"); //茂源生化
  69. PositionTransferField.put("G004","生化免疫组"); //茂源免疫
  70. PositionTransferField.put("G032","临检组"); //茂源临检
  71. PositionTransferField.put("G009",""); //茂源急诊
  72. PositionTransferField.put("G007","分子组"); //茂源分子
  73. PositionTransferField.put("G031","微生物组"); //茂源微生物
  74. PositionTransferField.put("G036","文化路院区"); //文化大检验
  75. PositionTransferField.put("G014","文化路院区"); //文化微生物
  76. PositionTransferField.put("Y032","临检组"); //茂源临检(夜班)
  77. PositionTransferField.put("Y009",""); //茂源急诊(夜班)
  78. PositionTransferField.put("Y036","文化路院区"); //文化大检验(夜班)
  79. DepartmentLeaderField.put("1353738806028664832","1353762416025927680"); //生化免疫组 刘文
  80. DepartmentLeaderField.put("1353739566586003456","1353762457495011328"); //临检组 梁骑
  81. DepartmentLeaderField.put("1353739652615372800","1353762484493746176"); //微生物组 张红
  82. DepartmentLeaderField.put("1353739725613039616","1353762508984287232"); //分子组 许媛
  83. DepartmentLeaderField.put("1353739809322958848","1353762523634991104"); //文化路院区 马强
  84. //DepartmentLeaderField.put("1353739909701042176","1353762541930545152"); //医疗助理组 杨珣
  85. }
  86. public void startHandleData(List<Map<String, Object>> retList, String lisTable) {
  87. List<Map<String, Object>> existList = ibpsRepository.qryExistData(lisTable);
  88. retList = cleanExistData(lisTable,retList,existList);
  89. log.info("table:"+lisTable+" get data:"+retList.size());
  90. if (lisTable.equals("V_JT_TestCodeRerunRecord")){
  91. log.info("ready to analyse rerun testcode");
  92. HandleRerunSample(retList);
  93. }
  94. if (lisTable.equals("V_JT_QCMonthReport")){
  95. log.info("ready to analyse QC month report");
  96. HandleMonthReport(retList);
  97. }
  98. if (lisTable.equals("V_JT_OutOfControlReport")){
  99. log.info("ready to analyse UnControl report");
  100. HandleUnControlReport(retList);
  101. }
  102. if (lisTable.equals("V_JT_InfectiousReport")){
  103. log.info("ready to analyse infectious report");
  104. HandleInfectiousReport(retList);
  105. }
  106. if (lisTable.equals("V_JT_AdditionalRequest")){
  107. log.info("ready to analyse additional request");
  108. HandleAdditionalRequest(retList);
  109. }
  110. }
  111. public List<Map<String, Object>> cleanExistData(String lisTable, List<Map<String, Object>> lisList, List<Map<String, Object>> existList) {
  112. if (lisTable.equals("V_JT_TestCodeRerunRecord")){
  113. // 1. 创建Set存储existList中所有id_的值(转换为字符串形式)
  114. Set<String> existIdSet = new HashSet<>();
  115. for (Map<String, Object> existMap : existList) {
  116. Object idObj = existMap.get("biao_ben_bian_hao");
  117. existIdSet.add(idObj == null ? null : idObj.toString());
  118. }
  119. // 2. 过滤rerunTestList:只保留id不在existIdSet中的元素
  120. List<Map<String, Object>> resultList = new ArrayList<>();
  121. for (Map<String, Object> testMap : lisList) {
  122. Object idObj = testMap.get("SAMPLECODE");
  123. String idStr = idObj == null ? null : idObj.toString();
  124. // 如果当前条码不在existIdSet中,则保留
  125. if (!existIdSet.contains(idStr)) {
  126. resultList.add(testMap);
  127. }
  128. }
  129. return resultList;
  130. }
  131. if (lisTable.equals("V_JT_QCMonthReport")){
  132. // 1. 创建Set存储existList中所有id_的值(转换为字符串形式)
  133. Set<String> existIdSet = new HashSet<>();
  134. for (Map<String, Object> existMap : existList) {
  135. Object idObj = existMap.get("id_");
  136. existIdSet.add(idObj == null ? null : idObj.toString());
  137. }
  138. // 2. 过滤rerunTestList:只保留id不在existIdSet中的元素
  139. List<Map<String, Object>> resultList = new ArrayList<>();
  140. for (Map<String, Object> testMap : lisList) {
  141. Object idObj = testMap.get("REPORTID");
  142. String idStr = idObj == null ? null : idObj.toString();
  143. // 如果当前条码不在existIdSet中,则保留
  144. if (!existIdSet.contains(idStr)) {
  145. resultList.add(testMap);
  146. }
  147. }
  148. return resultList;
  149. }
  150. if (lisTable.equals("V_JT_OutOfControlReport")) {
  151. // 1. 创建Set存储existList中所有 bian_zhi_shi_jian 的值(转换为字符串形式)
  152. Set<String> existIdSet = new HashSet<>();
  153. for (Map<String, Object> existMap : existList) {
  154. Object idObj = existMap.get("id_");
  155. existIdSet.add(idObj == null ? null : idObj.toString());
  156. }
  157. // 2. 过滤lisList:只保留 bian_zhi_shi_jian 不在 existIdSet 中的元素
  158. List<Map<String, Object>> resultList = new ArrayList<>();
  159. for (Map<String, Object> testMap : lisList) {
  160. Object idObj = testMap.get("RESULT_NO");
  161. String idStr = idObj == null ? null : idObj.toString();
  162. if (!existIdSet.contains(idStr)) {
  163. resultList.add(testMap);
  164. }
  165. }
  166. return resultList;
  167. }
  168. if (lisTable.equals("V_JT_InfectiousReport")) {
  169. // 1. 创建Set存储existList中所有 tiao_ma_hao_ 的值(转换为字符串形式)
  170. Set<String> existIdSet = new HashSet<>();
  171. // log.info("existList:"+existList);
  172. // log.info("lisList:"+lisList);
  173. for (Map<String, Object> existMap : existList) {
  174. Object idObj = existMap.get("tiao_ma_hao_");
  175. existIdSet.add(idObj == null ? null : idObj.toString());
  176. }
  177. // 2. 过滤lisList:只保留 SampleCode 不在 existIdSet 中的元素
  178. List<Map<String, Object>> resultList = new ArrayList<>();
  179. for (Map<String, Object> testMap : lisList) {
  180. Object idObj = testMap.get("SAMPLECODE");
  181. String idStr = idObj == null ? null : idObj.toString();
  182. if (!existIdSet.contains(idStr)) {
  183. resultList.add(testMap);
  184. // log.info("not exist,add:"+testMap);
  185. }
  186. }
  187. return resultList;
  188. }
  189. if (lisTable.equals("V_JT_AdditionalRequest")) {
  190. // 1. 创建Set存储existList中所有 tiao_ma_hao_ 的值(转换为字符串形式)
  191. Set<String> existIdSet = new HashSet<>();
  192. // log.info("existList:"+existList);
  193. // log.info("lisList:"+lisList);
  194. for (Map<String, Object> existMap : existList) {
  195. Object idObj = existMap.get("bian_zhi_shi_jian");
  196. existIdSet.add(idObj == null ? null : idObj.toString());
  197. }
  198. // 2. 过滤lisList:只保留 SampleCode 不在 existIdSet 中的元素
  199. List<Map<String, Object>> resultList = new ArrayList<>();
  200. for (Map<String, Object> testMap : lisList) {
  201. Object idObj = testMap.get("REGTIME");
  202. String idStr = idObj == null ? null : idObj.toString();
  203. if (!existIdSet.contains(idStr)) {
  204. resultList.add(testMap);
  205. // log.info("not exist,add:"+testMap);
  206. }
  207. }
  208. return resultList;
  209. }
  210. return null;
  211. }
  212. public void HandleRerunSample(List<Map<String, Object>> retList){
  213. if (retList.size() > 0) {
  214. String fieldName = null;
  215. String fieldValue = null;
  216. List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
  217. for (Map entityMap : retList) {
  218. Map<String, Object> insertMap = new HashMap<>();
  219. for (Object entry : entityMap.keySet()) {
  220. fieldName = null;
  221. fieldValue = null;
  222. fieldName = RerunSampleField.get(entry.toString());
  223. Object value = entityMap.get(entry.toString());
  224. fieldValue = value != null ? value.toString() : "";
  225. if (fieldName != null) {
  226. insertMap.put(fieldName, fieldValue);
  227. }
  228. }
  229. //补充其他字段信息
  230. insertMap.put("id_", UUID.randomUUID().toString());
  231. insertMap.put("shi_fou_guo_shen_", "已完成");
  232. String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(entityMap.get("CREATEBY")));
  233. String auditUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(entityMap.get("AUDITUSER")));
  234. if (createUserInfo.split("\\^")[0].equals("-1")) {
  235. log.warn("error userInfo,skip to insert:"+createUserInfo);
  236. continue;
  237. }
  238. if (auditUserInfo.split("\\^")[0].equals("-1")) {
  239. log.warn("error auditUserInfo,skip to insert:"+auditUserInfo);
  240. continue;
  241. }
  242. insertMap.put("create_by_", createUserInfo.trim().split("@")[0]);
  243. insertMap.put("create_time_", getCurTime("yyyy-MM-dd HH:mm:ss"));
  244. insertMap.put("bian_zhi_ren_", createUserInfo.trim().split("@")[0]);
  245. insertMap.put("jian_yan_zhe_", String.valueOf(entityMap.get("AUDITUSER")));
  246. insertMap.put("jian_yan_yuan_", auditUserInfo.trim().split("@")[0]);
  247. insertMap.put("ri_qi_", String.valueOf(entityMap.get("CREATETIME")).split(" ")[0]);
  248. String lisLocation = String.valueOf(entityMap.get("GROUPNAME"));
  249. String locationID = ibpsRepository.getPosiByName(lisLocation.substring(0, 2));
  250. insertMap.put("bian_zhi_bu_men_", locationID);
  251. insertList.add(insertMap);
  252. }
  253. // insertList = lisViewRepository.query2("ss");
  254. String res = ibpsRepository.saveToTable(insertList, "t_fjbbjlb","1");
  255. if(res.equals("success")){
  256. log.info("success insert:"+insertList.size()+" datas");
  257. } else {
  258. log.info("fail insert");
  259. }
  260. }else{
  261. log.info("No New Rerun Sample exist!");
  262. }
  263. }
  264. public void HandleMonthReport(List<Map<String, Object>> retList){
  265. if (retList.size() > 0) {
  266. String fieldName = null;
  267. String fieldValue = null;
  268. List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
  269. for (Map entityMap : retList) {
  270. Map<String, Object> insertReportMap = new HashMap<>();
  271. insertReportMap.put("id_", entityMap.get("REPORTID"));
  272. insertReportMap.put("shi_fou_guo_shen_", "待推送");
  273. insertReportMap.put("create_time_", getCurTime("yyyy-MM-dd HH:mm:ss"));
  274. String editUser = entityMap.get("CREATEBY").toString();
  275. String launchUser = ibpsRepository.getUserIDByName(editUser);
  276. //insertReportMap.put("bian_zhi_shi_jian", String.valueOf(formattedDateTime));
  277. String posID = ibpsRepository.getPosiByCode(entityMap.get("GROUPCODE").toString());
  278. if (posID != "-1") {
  279. insertReportMap.put("di_dian_", posID);
  280. insertReportMap.put("bian_zhi_bu_men_", posID);
  281. // insertReportMap.put("bian_zhi_ren_", editUserInfo.split("@")[0]);
  282. insertReportMap.put("zhi_kong_pin_", launchUser); //质控品字段已弃用,现当作发起人字段用来支持多人,编制人字段由实际启动的人决定
  283. } else{
  284. log.info("error launchUser or posID,skip to insert,posID:"+posID+" ,launchUser:"+editUser);
  285. continue;
  286. }
  287. insertReportMap.put("xi_tong_ming_chen", entityMap.get("GROUPNAME")+"全组仪器");
  288. insertReportMap.put("ji_lu_bian_hao_", entityMap.get("CREATETIME").toString().substring(0, 4) + "-" + entityMap.get("CREATETIME").toString().substring(4));
  289. insertList.add(insertReportMap);
  290. }
  291. String res = ibpsRepository.saveToTable(insertList, "t_dlxmsnzkyfx", "1");
  292. if(res.equals("success")){
  293. log.info("table:t_dlxmsnzkyfx success insert:"+insertList.size()+" datas");
  294. handQCTestCode(insertList);
  295. } else {
  296. log.info("fail insert t_dlxmsnzkyfx");
  297. }
  298. }else{
  299. log.info("No New MonthReport exist!");
  300. }
  301. };
  302. public String handQCTestCode(List<Map<String, Object>> reportList) {
  303. Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
  304. long sequenceCounter = 0;
  305. for (Map<String, Object> reportMap : reportList) {
  306. String reportID = getStringValue(reportMap, "id_");
  307. if (reportID == null || reportID.isEmpty()) {
  308. continue; // 跳过无效的报告ID
  309. }
  310. List<Map<String, Object>> retList = lisViewRepository.getQCTestCodeList(reportID);
  311. if (retList == null || retList.isEmpty()) {
  312. continue; // 跳过空结果
  313. }
  314. List<Map<String, Object>> insertList = new ArrayList<>();
  315. // 在循环外部定义序列号计数器
  316. for (Map<String, Object> entityMap : retList) {
  317. Map<String, Object> insertMap = new HashMap<>();
  318. // 生成有序ID:时间戳+自增序列号
  319. String orderedId = String.format("%d-%06d",
  320. currentTimestamp.getTime(), // 使用时间戳
  321. sequenceCounter++ // 自增序列号
  322. );
  323. insertMap.put("id_", orderedId);
  324. insertMap.put("parent_id_", getStringValue(entityMap, "REPORTID"));
  325. insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
  326. // 简化条件判断
  327. String testCodeValue = showTestCodeName.equals("1") ?
  328. getStringValue(entityMap, "TESTCODENAME") :
  329. getStringValue(entityMap, "TESTCODE");
  330. insertMap.put("xiang_mu_", testCodeValue);
  331. // 使用辅助方法简化代码
  332. putIfNotNull(insertMap, "zhi_kong_pin_pi_h", entityMap, "LOTNUMBER");
  333. putIfNotNull(insertMap, "pi_hao_kai_shi_sh", entityMap, "LOTSTARTTIME");
  334. putIfNotNull(insertMap, "zhi_kong_tu_dan_w", entityMap, "QCCHARTUNIT");
  335. putIfNotNull(insertMap, "zhi_kong_tu_shui_", entityMap, "QCCHARTLEVEL");
  336. putIfNotNull(insertMap, "zhi_kong_tu_jun_z", entityMap, "QCCHARTAVG");
  337. putIfNotNull(insertMap, "zhi_kong_tu_sd_", entityMap, "QCCHARTSD");
  338. putIfNotNull(insertMap, "zhi_kong_tu_cv_", entityMap, "QCCHARTCV");
  339. putIfNotNull(insertMap, "yuan_shi_jun_zhi_", entityMap, "RAWDATAAVG");
  340. putIfNotNull(insertMap, "yuan_shi_sd_", entityMap, "RAWDATASD");
  341. putIfNotNull(insertMap, "yuan_shi_cv_", entityMap, "RAWDATACV");
  342. putIfNotNull(insertMap, "yuan_shi_n_", entityMap, "RAWDATAN");
  343. putIfNotNull(insertMap, "shi_kong_shu_", entityMap, "ROWDATAOC");
  344. putIfNotNull(insertMap, "chu_jun_zhi_", entityMap, "CONTROLDATAAVG");
  345. putIfNotNull(insertMap, "chu_sd_", entityMap, "CONTROLDATASD");
  346. putIfNotNull(insertMap, "chu_cv_", entityMap, "CONTROLDATACV");
  347. putIfNotNull(insertMap, "lei_jun_zhi_", entityMap, "ACCUMDATAAVG");
  348. putIfNotNull(insertMap, "lei_sd_", entityMap, "ACCUMDATASD");
  349. putIfNotNull(insertMap, "lei_cv_", entityMap, "ACCUMDATACV");
  350. putIfNotNull(insertMap, "lei_n_", entityMap, "ACCUMDATAN");
  351. putIfNotNull(insertMap, "zai_kong_lv_", entityMap, "ACCUMDATAPER");
  352. putIfNotNull(insertMap, "cv_kong_zhi_fan_w", entityMap, "CVRANGE");
  353. putIfNotNull(insertMap, "zhi_kong_chang_ji", entityMap, "QCMFG");
  354. putIfNotNull(insertMap, "shi_kong_gui_ze_", entityMap, "QCRule");
  355. putIfNotNull(insertMap, "shi_fou_he_ge_", entityMap, "PASS");
  356. putIfNotNull(insertMap, "she_bei_ming_chen", entityMap, "DEVICENAME");
  357. insertList.add(insertMap);
  358. }
  359. if (!insertList.isEmpty()) {
  360. String res = ibpsRepository.saveToTable(insertList, "t_dlxmsnzkyfxzb", "1");
  361. if ("success".equals(res)) {
  362. log.info("table:t_dlxmsnzkyfxzb success insert: {} datas", insertList.size());
  363. } else {
  364. log.info("fail insert t_dlxmsnzkyfxzb");
  365. }
  366. }
  367. }
  368. return "success";
  369. }
  370. public void HandleUnControlReport(List<Map<String, Object>> retList){
  371. if (retList.size() > 0) {
  372. Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
  373. long sequenceCounter = 0;
  374. List<Map<String, Object>> insertList = new ArrayList<>();
  375. for (Map<String, Object> retMap : retList) {
  376. Map<String, Object> insertMap = new HashMap<>();
  377. // 生成有序ID:时间戳+自增序列号
  378. String orderedId = String.format("%d-%06d",
  379. currentTimestamp.getTime(), // 使用时间戳
  380. sequenceCounter++ // 自增序列号
  381. );
  382. insertMap.put("id_", orderedId);
  383. insertMap.put("id_", retMap.get("RESULT_NO"));
  384. insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
  385. String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("CREATEUSER")));
  386. if(createUserInfo.contains("未找到")){
  387. log.warn(createUserInfo);
  388. continue;
  389. }
  390. // insertMap.put("create_by_", createUserInfo.split("@")[0]);
  391. // insertMap.put("bian_zhi_ren_", createUserInfo.split("@")[0]);
  392. // insertMap.put("bian_zhi_shi_jian", String.valueOf(retMap.get("CREATETIME")));
  393. insertMap.put("di_dian_", ibpsRepository.getPosiByCode("LOCAL"));
  394. insertMap.put("shi_fou_guo_shen_", "待处理");
  395. insertMap.put("zhuan_ye_zu_", ibpsRepository.getPosiByCode(retMap.get("GROUP_ID").toString()));
  396. // insertMap.put("cao_zuo_zhe_", createUserInfo.split("@")[0]);
  397. insertMap.put("yi_qi_ming_", retMap.get("TESTCODE"));
  398. insertMap.put("xiang_mu_ming_", retMap.get("DEVICECODE"));
  399. insertMap.put("zhi_kong_pin_ming", retMap.get("QCNAME"));
  400. insertMap.put("zhi_kong_pi_hao_", retMap.get("QCLOT"));
  401. String qcDate = (String) retMap.get("QCDATE");
  402. String formatted = qcDate == null ? null :
  403. LocalDate.parse(qcDate, DateTimeFormatter.ofPattern("yyyyMMdd"))
  404. .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
  405. insertMap.put("shi_kong_ri_qi_", formatted);
  406. insertMap.put("shi_kong_de_zhi_k", retMap.get("QCRESULT"));
  407. insertMap.put("she_ding_ba_zhi_", retMap.get("STANDARD_SD"));
  408. //定量解析
  409. // 获取原始 QUANT 值
  410. String quant = (String) retMap.get("QUANT");
  411. Set<String> dingLiangSet = new LinkedHashSet<>(); // 用 LinkedHashSet 保持插入顺序,同时去重
  412. List<String> qiTaList = new ArrayList<>();
  413. if (quant != null && !quant.trim().isEmpty()) {
  414. String[] parts = quant.split(",");
  415. for (String part : parts) {
  416. String item = part.trim();
  417. if (item.isEmpty()) continue;
  418. if ("1-3s".equals(item)) {
  419. dingLiangSet.add("1");
  420. } else if ("2-2s".equals(item)) {
  421. dingLiangSet.add("2");
  422. } else if ("R-4s".equals(item)) {
  423. dingLiangSet.add("3");
  424. } else {
  425. // 其他情况:归为 4,并记录到 qi_ta_shuo_ming_
  426. dingLiangSet.add("4");
  427. qiTaList.add(item);
  428. }
  429. }
  430. }
  431. // 拼接 ding_liang_
  432. String dingLiangStr = String.join(",", dingLiangSet);
  433. // 拼接 qi_ta_shuo_ming_
  434. String qiTaStr = String.join(",", qiTaList);
  435. // 放入 insertMap
  436. insertMap.put("ding_liang_", dingLiangStr);
  437. insertMap.put("qi_ta_shuo_ming_", qiTaStr);
  438. insertMap.put("qi_ta_miao_shu_", retMap.get("REASON"));
  439. insertMap.put("chu_li_cuo_shi_", "6");
  440. insertMap.put("qi_ta_cuo_shi_", retMap.get("ACTION"));
  441. insertMap.put("chu_li_hou_zhi_ko", retMap.get("QCFINALRESULT"));
  442. insertMap.put("shi_fou_zai_kong_", "是".equals(retMap.get("ISINCONTROL")) ? "2" : "1");
  443. insertMap.put("shi_kong_shi_fou_","是".equals(retMap.get("AFFECTSPATIENTSAMPLES")) ? "2" : "1");
  444. insertMap.put("shi_fou_ying_xian", "是".equals(retMap.get("AFFECTSRESULTREPORTING")) ? "2" : "1");
  445. insertMap.put("shuo_ming_", retMap.get("NOTES"));
  446. insertMap.put("fen_xi_yu_zhi_xin", retMap.get("ANALYSIS"));
  447. insertList.add(insertMap);
  448. }
  449. if (!insertList.isEmpty()) {
  450. String res = ibpsRepository.saveToTable(insertList, "t_snzkskbgvb", "1");
  451. // String res = "1";
  452. if ("success".equals(res)) {
  453. log.info("table:t_snzkskbgvb success insert: {} datas", insertList.size());
  454. } else {
  455. log.error("fail insert t_snzkskbgvb");
  456. }
  457. }
  458. } else {
  459. log.info("No New Uncontrol Report exist!");
  460. }
  461. }
  462. public void HandleInfectiousReport(List<Map<String, Object>> retList){
  463. if (retList.size() > 0) {
  464. Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
  465. long sequenceCounter = 0;
  466. List<Map<String, Object>> insertList = new ArrayList<>();
  467. for (Map<String, Object> retMap : retList) {
  468. Map<String, Object> insertMap = new HashMap<>();
  469. // 生成有序ID:时间戳+自增序列号
  470. String orderedId = String.format("%d-%06d",
  471. currentTimestamp.getTime(), // 使用时间戳
  472. sequenceCounter++ // 自增序列号
  473. );
  474. insertMap.put("id_", orderedId);
  475. insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
  476. String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("REGISTERUSER")));
  477. if(createUserInfo.contains("未找到")){
  478. log.warn("createUserInfo:"+createUserInfo);
  479. continue;
  480. }
  481. String workGroupID = ibpsRepository.getPosiByCode(retMap.get("GROUPID").toString());
  482. if(workGroupID.contains("-1")){
  483. log.warn("workGroupID:"+workGroupID);
  484. continue;
  485. }
  486. insertMap.put("create_by_", createUserInfo.split("@")[0]);
  487. insertMap.put("bian_zhi_ren_", createUserInfo.split("@")[0]);
  488. insertMap.put("bian_zhi_shi_jian", String.valueOf(retMap.get("REGISTERDATE")));
  489. insertMap.put("bian_zhi_bu_men_", workGroupID);
  490. insertMap.put("di_dian_", ibpsRepository.getPosiByCode("LOCAL"));
  491. insertMap.put("shi_fou_guo_shen_", "已完成");
  492. insertMap.put("song_jian_ke_shi_", retMap.get("DEPARTMENT"));
  493. insertMap.put("song_jian_yi_shen", retMap.get("DOCTOR"));
  494. insertMap.put("bing_ren_xing_min", retMap.get("PATNAME"));
  495. insertMap.put("xing_bie_", retMap.get("GENDER"));
  496. insertMap.put("nian_ling_", retMap.get("AGE").toString().replace("岁",""));
  497. insertMap.put("jian_yan_jie_guo_", retMap.get("REPORTRESULT"));
  498. insertMap.put("bao_gao_ri_qi_", retMap.get("REPORTDATE"));
  499. insertMap.put("feed_back_dr_time", retMap.get("FEEDBACKDOCTOR"));
  500. insertMap.put("feed_back_hosp_ti", retMap.get("FEEDBACKDPHM"));
  501. insertMap.put("tiao_ma_hao_", retMap.get("SAMPLECODE"));
  502. insertList.add(insertMap);
  503. }
  504. if (!insertList.isEmpty()) {
  505. String res = ibpsRepository.saveToTable(insertList, "t_crbbgdjb", "1");
  506. // String res = "success";
  507. if ("success".equals(res)) {
  508. log.info("table:t_crbbgdjb success insert: {} datas", insertList.size());
  509. } else {
  510. log.error("fail insert t_crbbgdjb");
  511. }
  512. }
  513. }else {
  514. log.info("No New Infectious Report exist!");
  515. }
  516. }
  517. public void HandleAdditionalRequest(List<Map<String, Object>> retList){
  518. if (retList.size() > 0) {
  519. Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
  520. long sequenceCounter = 0;
  521. List<Map<String, Object>> insertList = new ArrayList<>();
  522. for (Map<String, Object> retMap : retList) {
  523. Map<String, Object> insertMap = new HashMap<>();
  524. // 生成有序ID:时间戳+自增序列号
  525. String orderedId = String.format("%d-%06d",
  526. currentTimestamp.getTime(), // 使用时间戳
  527. sequenceCounter++ // 自增序列号
  528. );
  529. insertMap.put("id_", orderedId);
  530. insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
  531. String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("REGUSER")));
  532. //String inUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("INSPUSER")));
  533. if(createUserInfo.contains("未找到")){
  534. log.warn("createUserInfo:"+createUserInfo);
  535. continue;
  536. }
  537. String workGroupID = ibpsRepository.getPosiByCode(retMap.get("REGLOCATION").toString());
  538. if(workGroupID.contains("-1")){
  539. log.warn("workGroupID:"+workGroupID);
  540. continue;
  541. }
  542. insertMap.put("create_by_", createUserInfo.split("@")[0]);
  543. insertMap.put("bian_zhi_ren_", createUserInfo.split("@")[0]);
  544. insertMap.put("bian_zhi_shi_jian", String.valueOf(retMap.get("REGTIME")));
  545. insertMap.put("bian_zhi_bu_men_", workGroupID);
  546. insertMap.put("di_dian_", ibpsRepository.getPosiByCode("LOCAL"));
  547. insertMap.put("shi_fou_guo_shen_", "已完成");
  548. insertMap.put("shen_qing_shi_jia", retMap.get("REQTIME"));
  549. insertMap.put("ke_shi_zh", retMap.get("REQLOCATION"));
  550. insertMap.put("shen_qing_ren_zh", retMap.get("REQUSER"));
  551. //insertMap.put("shen_qing_ren_", retMap.get("REQUSER"));
  552. insertMap.put("yang_pin_bian_hao", retMap.get("SAMPLECODE"));
  553. insertMap.put("nei_ron_zh", retMap.get("TESTCODE"));
  554. insertMap.put("jian_yan_shi_xian", String.valueOf(retMap.get("ADDTIME")));
  555. insertMap.put("ke_shi_lei_xing_", "外部");
  556. insertMap.put("deng_ji_ren_yuan_", "受理");
  557. // insertMap.put("jie_shou_ren_yuan", inUserInfo.split("@")[0]);
  558. insertMap.put("jie_shou_ren_yuan", String.valueOf(retMap.get("INSPUSER")));
  559. insertMap.put("song_da_qing_kuan", "已送");
  560. insertMap.put("song_da_ren_yuan_", retMap.get("RECUSER"));
  561. insertMap.put("song_da_shi_jian_", String.valueOf(retMap.get("RECTIME")));
  562. insertMap.put("bei_zhu_", retMap.get("REMARK"));
  563. insertList.add(insertMap);
  564. }
  565. if (!insertList.isEmpty()) {
  566. String res = ibpsRepository.saveToTable(insertList, "t_fjjysqdjb", "1");
  567. // String res = "success";
  568. if ("success".equals(res)) {
  569. log.info("table:t_fjjysqdjb success insert: {} datas", insertList.size());
  570. } else {
  571. log.error("fail insert t_fjjysqdjb");
  572. }
  573. }
  574. }else {
  575. log.info("No New Additional Request exist!");
  576. }
  577. }
  578. // 辅助方法:安全获取字符串值,避免空指针异常
  579. private String getStringValue(Map<String, Object> map, String key) {
  580. Object value = map.get(key);
  581. return value == null ? "" : value.toString();
  582. }
  583. // 辅助方法:简化条件插入操作
  584. private void putIfNotNull(Map<String, Object> targetMap, String targetKey,
  585. Map<String, Object> sourceMap, String sourceKey) {
  586. Object value = sourceMap.get(sourceKey);
  587. if (value != null) {
  588. targetMap.put(targetKey, value.toString());
  589. if(targetKey.equals("pi_hao_kai_shi_sh")){
  590. targetMap.put(targetKey, value.toString().substring(0,10));
  591. }
  592. if(targetKey.equals("shi_fou_he_ge_")){
  593. if(value.toString().equals("Y")){
  594. targetMap.put(targetKey, "合格");
  595. }
  596. if(value.toString().equals("N")){
  597. targetMap.put(targetKey, "不合格");
  598. }
  599. }
  600. } else {
  601. targetMap.put(targetKey, "");
  602. }
  603. }
  604. public void HandQIData(List<Map<String, Object>>qualityIndicatorList){
  605. // 创建用于存储更新数据的列表
  606. List<Map<String, Object>> updateDataList = new ArrayList<>();
  607. if (qualityIndicatorList == null || qualityIndicatorList.isEmpty()) {
  608. // 执行退出操作
  609. return;
  610. }
  611. // Set<String> distinctSet = new HashSet<>();
  612. // for (Map<String, Object> item : qualityIndicatorList) {
  613. // Object value = item.get("bian_zhi_shi_jian");
  614. // if (value != null) {
  615. // distinctSet.add(value.toString());
  616. // }
  617. // }
  618. // // 转换为List
  619. // List<String> distinctList = new ArrayList<>(distinctSet);
  620. YearMonth currentYearMonth = YearMonth.now();
  621. YearMonth previousMonth = currentYearMonth.minusMonths(1);
  622. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年M月份", Locale.CHINA);
  623. String DateRange = DateRangeUtil.getDateRange(previousMonth.format(formatter));
  624. if(!manualQryMonth.equals("")){
  625. DateRange = DateRangeUtil.getDateRange(manualQryMonth);
  626. } else {
  627. manualQryMonth = previousMonth.format(formatter);
  628. }
  629. List<Map<String, Object>> lisRetList = lisViewRepository.GetLISRes(DateRange);
  630. List<Map<String, Object>> matchList = new ArrayList<>();
  631. for (Map<String, Object> undoQIMap : qualityIndicatorList) {
  632. String editTime = undoQIMap.get("bian_zhi_shi_jian").toString();
  633. //如果不是当前月份退出
  634. if(!editTime.equals(manualQryMonth)){
  635. continue;
  636. }
  637. matchList = MatchLISRes(undoQIMap, lisRetList, matchList, getCurTime("yyyy-MM-dd HH:mm:ss"));
  638. }
  639. if (matchList == null) {
  640. log.info("no match data found");
  641. return;
  642. }
  643. //测试输出matchList
  644. StringBuilder outString = new StringBuilder("current matchList:\n");
  645. for(Map<String, Object> retMap : matchList){
  646. outString.append(retMap.toString()).append("\n");
  647. }
  648. log.info(outString.toString());
  649. String retValue = ibpsRepository.saveToTable(matchList,"t_zlzbpjzb","2");
  650. if(retValue.equals("success")){
  651. log.info("success update:"+matchList.size()+" datas");
  652. } else {
  653. log.info("fail update");
  654. }
  655. //以下暂停使用
  656. // for (Map<String, Object> qualityIndicatorMap : qualityIndicatorList) {
  657. // log.info(qualityIndicatorMap.toString());
  658. // String DateRange = DateRangeUtil.getDateRange(qualityIndicatorMap.get("bian_zhi_shi_jian").toString());
  659. // String QryItem = qualityIndicatorMap.get("bei_zhu_").toString().split(":")[1];
  660. //
  661. // String id = qualityIndicatorMap.get("id_").toString();
  662. // String compareRes = ValueEvaluator.evaluateValue(retVal,qualityIndicatorMap.get("yuan_shi_shu_ju_").toString());
  663. // // 将数据添加到更新列表
  664. // Map<String, Object> updateData = new HashMap<>();
  665. // updateData.put("id", id);
  666. // updateData.put("retVal", retVal);
  667. // updateData.put("compareRes", compareRes);
  668. // updateDataList.add(updateData);
  669. // }
  670. // // 调用抽离的保存方法
  671. // ibpsRepository.updateQualityIndicatorData(updateDataList);
  672. }
  673. //与LIS中List进行匹配
  674. public List<Map<String, Object>> MatchLISRes(Map<String, Object> undoQIMap, List<Map<String, Object>> lisRetList, List<Map<String, Object>> matchList, Timestamp formattedDateTime) {
  675. // 如果 matchList 为 null,则初始化
  676. if (matchList == null) {
  677. matchList = new ArrayList<>();
  678. }
  679. // 获取 bei_zhu_ 字段值
  680. String beiZhu = (String) undoQIMap.get("bei_zhu_");
  681. // 在 lisRetList 中查找匹配的记录
  682. for (Map<String, Object> lisMap : lisRetList) {
  683. String currentLisFlag = (String) lisMap.get("lisFlag");
  684. if (beiZhu.equals(currentLisFlag)) {
  685. // 找到匹配项,创建新的匹配记录
  686. Map<String, Object> matchRecord = new HashMap<>();
  687. matchRecord.put("id_", undoQIMap.get("id_")); // 从 undoQIMap 取 id_
  688. //计算是否达标
  689. String curValue = lisMap.get("percentage").toString();
  690. String compChar = undoQIMap.get("yuan_shi_shu_ju_").toString();
  691. String compRes = ValueEvaluator.evaluateValue(curValue, compChar);
  692. matchRecord.put("da_biao_qing_kuan", compRes);
  693. if(resultWithUnit.equals("1")){
  694. curValue = curValue + compChar.split("@")[2];
  695. }
  696. matchRecord.put("shi_ji_shu_zhi_", curValue);
  697. matchRecord.put("zhuang_tai_", "已完成");
  698. matchRecord.put("update_time_", formattedDateTime);
  699. log.info("curValue:"+curValue+", compChar:"+compChar+", cpmpare result:"+compRes);
  700. matchList.add(matchRecord);
  701. break; // 找到匹配后跳出内层循环
  702. }
  703. }
  704. return matchList;
  705. }
  706. public void AbilityMonitor(){
  707. // 1. 转为 Set 便于 O(1) 查询
  708. Set<String> pushDates = new HashSet<>(Arrays.asList(pushDate.split(",")));
  709. // 2. 获取当前日期的 MMdd 格式
  710. String todayMMDD = LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd"));
  711. // 3. 判断是否匹配
  712. if (pushDates.contains(todayMMDD)) {
  713. log.info("in abilitymonitor day!");
  714. // Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
  715. //先取全部监督内容,后面不用再多次去数据库获取
  716. List<Map<String, Object>> contentList = ibpsRepository.getMonitorContent();
  717. List<Map<String, Object>> employeeList = ibpsRepository.getAllUser();
  718. for (Map<String, Object> employeeMap : employeeList) {
  719. String userID = (String) employeeMap.get("ID_");
  720. String userName = (String) employeeMap.get("NAME_");
  721. //String depIDStr = (String) employeeMap.get("POSITIONS_");
  722. //改成取主部门
  723. String depIDStr = ibpsRepository.getMainPos(userID);
  724. if (depIDStr == null || depIDStr.trim().isEmpty()) {
  725. continue;
  726. }
  727. // 按逗号分割,去除前后空格(防御性编程)
  728. String[] depIDs = depIDStr.split(",");
  729. for (String depID : depIDs) {
  730. depID = depID.trim(); // 去除可能的空格,如 "dept1, dept2"
  731. if (depID.isEmpty()) {
  732. continue; // 跳过空片段(例如末尾多逗号:"a,b,")
  733. }
  734. // 每条数据:userID, userName, depID
  735. String monitorUser = DepartmentLeaderField.get(depID);
  736. if (monitorUser != null) {
  737. List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
  738. Map<String, Object> insertMap = new HashMap<>();
  739. List<Map<String, Object>> monitorItemList = getMonitorItem(contentList, depID);
  740. if (monitorItemList != null) {
  741. //先插主表 t_lhryjdjlb
  742. String mainID = UUID.randomUUID().toString();
  743. insertMap.put("id_", mainID);
  744. insertMap.put("create_by_",monitorUser);
  745. insertMap.put("bian_zhi_ren_",monitorUser);
  746. insertMap.put("create_time_",getCurTime("yyyy-MM-dd HH:mm:ss"));
  747. insertMap.put("shi_fou_guo_shen_","待推送");
  748. insertMap.put("bian_zhi_bu_men_",depID);
  749. //insertMap.put("bian_zhi_shi_jian",String.valueOf(getCurTime("yyyy-MM-dd")));
  750. insertMap.put("bian_zhi_shi_jian", LocalDate.now().toString());
  751. insertMap.put("bei_jian_du_ren_y",userID);
  752. insertMap.put("zhi_liang_jian_du","检验员");
  753. insertMap.put("jian_du_gang_wei_","1382414549667282944"); //固定岗位:检验员id
  754. String curDay = String.valueOf(getCurTime("yyyy-MM-dd HH:mm:ss"));
  755. insertMap.put("jian_ce_shi_jian_",curDay.split(" ")[0]);
  756. insertMap.put("jian_du_kai_shi_s",curDay.split(" ")[0]);
  757. insertMap.put("jian_du_jie_shu_s",curDay.split(" ")[0]);
  758. insertMap.put("shi_wu_shuo_ming_","被监督人员:"+userName+",监督事由:在岗检验人员每季度定期监督,监督岗位:检验员");
  759. insertMap.put("yi_jian_","该人员能力符合相关要求。");
  760. insertMap.put("jian_du_fang_shi_","观察操作");
  761. insertMap.put("jian_du_shi_you_","在岗检验人员每季度定期监督");
  762. insertList.add(insertMap);
  763. // log.info(insertList.toString());
  764. // String retValue = "success";
  765. String retValue = ibpsRepository.saveToTable(insertList,"t_lhryjdjlb","1");
  766. if(retValue.equals("success")){
  767. log.info("success insert into lhryjdjlb:"+insertList.size()+" datas");
  768. //再插子表 t_lhryjdjlzb
  769. List<Map<String, Object>> insertChildList = new ArrayList<Map<String, Object>>();
  770. Integer sequenceCounter = 0;
  771. String orderedId = "";
  772. Timestamp createTime = getCurTime("yyyy-MM-dd HH:mm:ss");
  773. for (Map<String, Object> monitorItem : monitorItemList) {
  774. Map<String, Object> insertChildMap = new HashMap<>();
  775. orderedId = mainID+"@"+String.valueOf(sequenceCounter); // 自增序列号
  776. sequenceCounter++;
  777. insertChildMap.put("id_", orderedId);
  778. insertChildMap.put("jian_du_xiang_mu_", monitorItem.get("DIR"));
  779. insertChildMap.put("jian_du_nei_rong_", monitorItem.get("DESCs"));
  780. insertChildMap.put("jian_du_jie_guo_", "是");
  781. insertChildMap.put("parent_id_", mainID);
  782. insertChildMap.put("create_time_", createTime);
  783. insertChildList.add(insertChildMap);
  784. }
  785. // log.info(insertChildList.toString());
  786. // String retChildValue = "success";
  787. String retChildValue = ibpsRepository.saveToTable(insertChildList,"t_lhryjdjlzb","1");
  788. if(retValue.equals("success")){
  789. log.info("success insert into lhryjdjlzb:"+insertChildList.size()+" datas");
  790. } else {
  791. log.info("fail insert");
  792. }
  793. } else {
  794. log.info("fail insert");
  795. }
  796. }
  797. }
  798. }
  799. }
  800. } else {
  801. log.info("not in abilitymonitor day");
  802. }
  803. }
  804. public List<Map<String, Object>> getMonitorItem(List<Map<String, Object>> contentList, String depID) {
  805. return contentList.stream()
  806. .filter(map -> Objects.equals(depID, map.get("DEPID")))
  807. .sorted(Comparator.comparingInt((Map<String, Object> map) -> {
  808. Object xuHaoObj = map.get("SEQ");
  809. if (xuHaoObj instanceof Number) {
  810. return ((Number) xuHaoObj).intValue();
  811. } else if (xuHaoObj instanceof String) {
  812. try {
  813. return Integer.parseInt((String) xuHaoObj);
  814. } catch (NumberFormatException e) {
  815. return Integer.MAX_VALUE;
  816. }
  817. } else {
  818. return Integer.MAX_VALUE;
  819. }
  820. }).reversed())
  821. .collect(Collectors.toList());
  822. }
  823. public Timestamp getCurTime(String formartterStr){
  824. LocalDateTime currentDateTime = LocalDateTime.now();
  825. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formartterStr);
  826. String formattedDateTime = currentDateTime.format(formatter);
  827. Timestamp currentTimestamp = Timestamp.valueOf(formattedDateTime);
  828. return currentTimestamp;
  829. }
  830. }