| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880 |
- package com.jyxt.getdatabyview;
- import com.jyxt.getdatabyview.view.repository.IBPSRepository;
- import com.jyxt.getdatabyview.view.repository.LISViewRepository;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
- import java.sql.Timestamp;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.YearMonth;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import java.util.stream.Collectors;
- @Component
- public class HandleData {
- private static final Logger log = LoggerFactory.getLogger(GetDataByViewApplication.class);
- @Autowired
- private LISViewRepository lisViewRepository;
- @Autowired
- private IBPSRepository ibpsRepository;
- @Value("${showTestCodeName}")
- private String showTestCodeName;
- @Value("${manualQryMonth}")
- private String manualQryMonth;
- @Value("${resultWithUnit}")
- private String resultWithUnit;
- @Value("${pushDate}")
- private String pushDate;
- public static final Map<String, String> RerunSampleField = new HashMap<>();
- public static final Map<String, String> UnControlReportField = new HashMap<>();
- public static final Map<String, String> PositionTransferField = new HashMap<>();
- public static final Map<String, String> DepartmentLeaderField = new HashMap<>();
- static {
- // 静态初始化块中填充数据
- RerunSampleField.put("CREATEBY", "bian_zhi_ren_");
- RerunSampleField.put("CREATETIME", "bian_zhi_shi_jian");
- RerunSampleField.put("SAMPLECODE", "biao_ben_bian_hao");
- // RerunSampleField.put("TESTCODE", "xiang_mu_id_");
- RerunSampleField.put("TESTCODENAME", "fu_jian_xiang_mu_");
- RerunSampleField.put("INITIALRESULT", "ce_ding_zhi_chu_j");
- RerunSampleField.put("RERUNRESULT", "ce_ding_zhi_fu_ji");
- RerunSampleField.put("REPORTRESULT", "bao_gao_zhi_");
- RerunSampleField.put("AUDITUSER", "jian_yan_zhe_");
- RerunSampleField.put("REPORTTIME", "bao_gao_shi_jian_");
- RerunSampleField.put("RERUNMETHODNOTE", "bei_zhu_fu_jian_f");
- RerunSampleField.put("PATNAME", "xing_ming_");
- RerunSampleField.put("RERUNMETHOD", "fu_jian_fang_shi_");
- RerunSampleField.put("UNIT", "dan_wei_");
- UnControlReportField.put("TestCode","");
- UnControlReportField.put("QCName","zhi_kong_pin_ming");
- UnControlReportField.put("QCLot","");
- UnControlReportField.put("QCDate","");
- UnControlReportField.put("QCResult","");
- UnControlReportField.put("SD","");
- UnControlReportField.put("Quant","");
- UnControlReportField.put("Qual","");
- UnControlReportField.put("ErrorType","");
- UnControlReportField.put("Reason","");
- UnControlReportField.put("Action","");
- UnControlReportField.put("QCFinalResult","");
- UnControlReportField.put("IsInControl","");
- UnControlReportField.put("AffectsPatientSamples","");
- UnControlReportField.put("AffectsResultReporting","");
- UnControlReportField.put("Notes","");
- UnControlReportField.put("QCFinalResult","");
- PositionTransferField.put("G002","生化免疫组"); //茂源生化
- PositionTransferField.put("G004","生化免疫组"); //茂源免疫
- PositionTransferField.put("G032","临检组"); //茂源临检
- PositionTransferField.put("G009",""); //茂源急诊
- PositionTransferField.put("G007","分子组"); //茂源分子
- PositionTransferField.put("G031","微生物组"); //茂源微生物
- PositionTransferField.put("G036","文化路院区"); //文化大检验
- PositionTransferField.put("G014","文化路院区"); //文化微生物
- PositionTransferField.put("Y032","临检组"); //茂源临检(夜班)
- PositionTransferField.put("Y009",""); //茂源急诊(夜班)
- PositionTransferField.put("Y036","文化路院区"); //文化大检验(夜班)
- DepartmentLeaderField.put("1353738806028664832","1353762416025927680"); //生化免疫组 刘文
- DepartmentLeaderField.put("1353739566586003456","1353762457495011328"); //临检组 梁骑
- DepartmentLeaderField.put("1353739652615372800","1353762484493746176"); //微生物组 张红
- DepartmentLeaderField.put("1353739725613039616","1353762508984287232"); //分子组 许媛
- DepartmentLeaderField.put("1353739809322958848","1353762523634991104"); //文化路院区 马强
- //DepartmentLeaderField.put("1353739909701042176","1353762541930545152"); //医疗助理组 杨珣
- }
- public void startHandleData(List<Map<String, Object>> retList, String lisTable) {
- List<Map<String, Object>> existList = ibpsRepository.qryExistData(lisTable);
- retList = cleanExistData(lisTable,retList,existList);
- log.info("table:"+lisTable+" get data:"+retList.size());
- if (lisTable.equals("V_JT_TestCodeRerunRecord")){
- log.info("ready to analyse rerun testcode");
- HandleRerunSample(retList);
- }
- if (lisTable.equals("V_JT_QCMonthReport")){
- log.info("ready to analyse QC month report");
- HandleMonthReport(retList);
- }
- if (lisTable.equals("V_JT_OutOfControlReport")){
- log.info("ready to analyse UnControl report");
- HandleUnControlReport(retList);
- }
- if (lisTable.equals("V_JT_InfectiousReport")){
- log.info("ready to analyse infectious report");
- HandleInfectiousReport(retList);
- }
- if (lisTable.equals("V_JT_AdditionalRequest")){
- log.info("ready to analyse additional request");
- HandleAdditionalRequest(retList);
- }
- }
- public List<Map<String, Object>> cleanExistData(String lisTable, List<Map<String, Object>> lisList, List<Map<String, Object>> existList) {
- if (lisTable.equals("V_JT_TestCodeRerunRecord")){
- // 1. 创建Set存储existList中所有id_的值(转换为字符串形式)
- Set<String> existIdSet = new HashSet<>();
- for (Map<String, Object> existMap : existList) {
- Object idObj = existMap.get("biao_ben_bian_hao");
- existIdSet.add(idObj == null ? null : idObj.toString());
- }
- // 2. 过滤rerunTestList:只保留id不在existIdSet中的元素
- List<Map<String, Object>> resultList = new ArrayList<>();
- for (Map<String, Object> testMap : lisList) {
- Object idObj = testMap.get("SAMPLECODE");
- String idStr = idObj == null ? null : idObj.toString();
- // 如果当前条码不在existIdSet中,则保留
- if (!existIdSet.contains(idStr)) {
- resultList.add(testMap);
- }
- }
- return resultList;
- }
- if (lisTable.equals("V_JT_QCMonthReport")){
- // 1. 创建Set存储existList中所有id_的值(转换为字符串形式)
- Set<String> existIdSet = new HashSet<>();
- for (Map<String, Object> existMap : existList) {
- Object idObj = existMap.get("id_");
- existIdSet.add(idObj == null ? null : idObj.toString());
- }
- // 2. 过滤rerunTestList:只保留id不在existIdSet中的元素
- List<Map<String, Object>> resultList = new ArrayList<>();
- for (Map<String, Object> testMap : lisList) {
- Object idObj = testMap.get("REPORTID");
- String idStr = idObj == null ? null : idObj.toString();
- // 如果当前条码不在existIdSet中,则保留
- if (!existIdSet.contains(idStr)) {
- resultList.add(testMap);
- }
- }
- return resultList;
- }
- if (lisTable.equals("V_JT_OutOfControlReport")) {
- // 1. 创建Set存储existList中所有 bian_zhi_shi_jian 的值(转换为字符串形式)
- Set<String> existIdSet = new HashSet<>();
- for (Map<String, Object> existMap : existList) {
- Object idObj = existMap.get("id_");
- existIdSet.add(idObj == null ? null : idObj.toString());
- }
- // 2. 过滤lisList:只保留 bian_zhi_shi_jian 不在 existIdSet 中的元素
- List<Map<String, Object>> resultList = new ArrayList<>();
- for (Map<String, Object> testMap : lisList) {
- Object idObj = testMap.get("RESULT_NO");
- String idStr = idObj == null ? null : idObj.toString();
- if (!existIdSet.contains(idStr)) {
- resultList.add(testMap);
- }
- }
- return resultList;
- }
- if (lisTable.equals("V_JT_InfectiousReport")) {
- // 1. 创建Set存储existList中所有 tiao_ma_hao_ 的值(转换为字符串形式)
- Set<String> existIdSet = new HashSet<>();
- // log.info("existList:"+existList);
- // log.info("lisList:"+lisList);
- for (Map<String, Object> existMap : existList) {
- Object idObj = existMap.get("tiao_ma_hao_");
- existIdSet.add(idObj == null ? null : idObj.toString());
- }
- // 2. 过滤lisList:只保留 SampleCode 不在 existIdSet 中的元素
- List<Map<String, Object>> resultList = new ArrayList<>();
- for (Map<String, Object> testMap : lisList) {
- Object idObj = testMap.get("SAMPLECODE");
- String idStr = idObj == null ? null : idObj.toString();
- if (!existIdSet.contains(idStr)) {
- resultList.add(testMap);
- // log.info("not exist,add:"+testMap);
- }
- }
- return resultList;
- }
- if (lisTable.equals("V_JT_AdditionalRequest")) {
- // 1. 创建Set存储existList中所有 tiao_ma_hao_ 的值(转换为字符串形式)
- Set<String> existIdSet = new HashSet<>();
- // log.info("existList:"+existList);
- // log.info("lisList:"+lisList);
- for (Map<String, Object> existMap : existList) {
- Object idObj = existMap.get("bian_zhi_shi_jian");
- existIdSet.add(idObj == null ? null : idObj.toString());
- }
- // 2. 过滤lisList:只保留 SampleCode 不在 existIdSet 中的元素
- List<Map<String, Object>> resultList = new ArrayList<>();
- for (Map<String, Object> testMap : lisList) {
- Object idObj = testMap.get("REGTIME");
- String idStr = idObj == null ? null : idObj.toString();
- if (!existIdSet.contains(idStr)) {
- resultList.add(testMap);
- // log.info("not exist,add:"+testMap);
- }
- }
- return resultList;
- }
- return null;
- }
- public void HandleRerunSample(List<Map<String, Object>> retList){
- if (retList.size() > 0) {
- String fieldName = null;
- String fieldValue = null;
- List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
- for (Map entityMap : retList) {
- Map<String, Object> insertMap = new HashMap<>();
- for (Object entry : entityMap.keySet()) {
- fieldName = null;
- fieldValue = null;
- fieldName = RerunSampleField.get(entry.toString());
- Object value = entityMap.get(entry.toString());
- fieldValue = value != null ? value.toString() : "";
- if (fieldName != null) {
- insertMap.put(fieldName, fieldValue);
- }
- }
- //补充其他字段信息
- insertMap.put("id_", UUID.randomUUID().toString());
- insertMap.put("shi_fou_guo_shen_", "已完成");
- String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(entityMap.get("CREATEBY")));
- String auditUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(entityMap.get("AUDITUSER")));
- if (createUserInfo.split("\\^")[0].equals("-1")) {
- log.warn("error userInfo,skip to insert:"+createUserInfo);
- continue;
- }
- if (auditUserInfo.split("\\^")[0].equals("-1")) {
- log.warn("error auditUserInfo,skip to insert:"+auditUserInfo);
- continue;
- }
- insertMap.put("create_by_", createUserInfo.trim().split("@")[0]);
- insertMap.put("create_time_", getCurTime("yyyy-MM-dd HH:mm:ss"));
- insertMap.put("bian_zhi_ren_", createUserInfo.trim().split("@")[0]);
- insertMap.put("jian_yan_zhe_", String.valueOf(entityMap.get("AUDITUSER")));
- insertMap.put("jian_yan_yuan_", auditUserInfo.trim().split("@")[0]);
- insertMap.put("ri_qi_", String.valueOf(entityMap.get("CREATETIME")).split(" ")[0]);
- String lisLocation = String.valueOf(entityMap.get("GROUPNAME"));
- String locationID = ibpsRepository.getPosiByName(lisLocation.substring(0, 2));
- insertMap.put("bian_zhi_bu_men_", locationID);
- insertList.add(insertMap);
- }
- // insertList = lisViewRepository.query2("ss");
- String res = ibpsRepository.saveToTable(insertList, "t_fjbbjlb","1");
- if(res.equals("success")){
- log.info("success insert:"+insertList.size()+" datas");
- } else {
- log.info("fail insert");
- }
- }else{
- log.info("No New Rerun Sample exist!");
- }
- }
- public void HandleMonthReport(List<Map<String, Object>> retList){
- if (retList.size() > 0) {
- String fieldName = null;
- String fieldValue = null;
- List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
- for (Map entityMap : retList) {
- Map<String, Object> insertReportMap = new HashMap<>();
- insertReportMap.put("id_", entityMap.get("REPORTID"));
- insertReportMap.put("shi_fou_guo_shen_", "待推送");
- insertReportMap.put("create_time_", getCurTime("yyyy-MM-dd HH:mm:ss"));
- String editUser = entityMap.get("CREATEBY").toString();
- String launchUser = ibpsRepository.getUserIDByName(editUser);
- //insertReportMap.put("bian_zhi_shi_jian", String.valueOf(formattedDateTime));
- String posID = ibpsRepository.getPosiByCode(entityMap.get("GROUPCODE").toString());
- if (posID != "-1") {
- insertReportMap.put("di_dian_", posID);
- insertReportMap.put("bian_zhi_bu_men_", posID);
- // insertReportMap.put("bian_zhi_ren_", editUserInfo.split("@")[0]);
- insertReportMap.put("zhi_kong_pin_", launchUser); //质控品字段已弃用,现当作发起人字段用来支持多人,编制人字段由实际启动的人决定
- } else{
- log.info("error launchUser or posID,skip to insert,posID:"+posID+" ,launchUser:"+editUser);
- continue;
- }
- insertReportMap.put("xi_tong_ming_chen", entityMap.get("GROUPNAME")+"全组仪器");
- insertReportMap.put("ji_lu_bian_hao_", entityMap.get("CREATETIME").toString().substring(0, 4) + "-" + entityMap.get("CREATETIME").toString().substring(4));
- insertList.add(insertReportMap);
- }
- String res = ibpsRepository.saveToTable(insertList, "t_dlxmsnzkyfx", "1");
- if(res.equals("success")){
- log.info("table:t_dlxmsnzkyfx success insert:"+insertList.size()+" datas");
- handQCTestCode(insertList);
- } else {
- log.info("fail insert t_dlxmsnzkyfx");
- }
- }else{
- log.info("No New MonthReport exist!");
- }
- };
- public String handQCTestCode(List<Map<String, Object>> reportList) {
- Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
- long sequenceCounter = 0;
- for (Map<String, Object> reportMap : reportList) {
- String reportID = getStringValue(reportMap, "id_");
- if (reportID == null || reportID.isEmpty()) {
- continue; // 跳过无效的报告ID
- }
- List<Map<String, Object>> retList = lisViewRepository.getQCTestCodeList(reportID);
- if (retList == null || retList.isEmpty()) {
- continue; // 跳过空结果
- }
- List<Map<String, Object>> insertList = new ArrayList<>();
- // 在循环外部定义序列号计数器
- for (Map<String, Object> entityMap : retList) {
- Map<String, Object> insertMap = new HashMap<>();
- // 生成有序ID:时间戳+自增序列号
- String orderedId = String.format("%d-%06d",
- currentTimestamp.getTime(), // 使用时间戳
- sequenceCounter++ // 自增序列号
- );
- insertMap.put("id_", orderedId);
- insertMap.put("parent_id_", getStringValue(entityMap, "REPORTID"));
- insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
- // 简化条件判断
- String testCodeValue = showTestCodeName.equals("1") ?
- getStringValue(entityMap, "TESTCODENAME") :
- getStringValue(entityMap, "TESTCODE");
- insertMap.put("xiang_mu_", testCodeValue);
- // 使用辅助方法简化代码
- putIfNotNull(insertMap, "zhi_kong_pin_pi_h", entityMap, "LOTNUMBER");
- putIfNotNull(insertMap, "pi_hao_kai_shi_sh", entityMap, "LOTSTARTTIME");
- putIfNotNull(insertMap, "zhi_kong_tu_dan_w", entityMap, "QCCHARTUNIT");
- putIfNotNull(insertMap, "zhi_kong_tu_shui_", entityMap, "QCCHARTLEVEL");
- putIfNotNull(insertMap, "zhi_kong_tu_jun_z", entityMap, "QCCHARTAVG");
- putIfNotNull(insertMap, "zhi_kong_tu_sd_", entityMap, "QCCHARTSD");
- putIfNotNull(insertMap, "zhi_kong_tu_cv_", entityMap, "QCCHARTCV");
- putIfNotNull(insertMap, "yuan_shi_jun_zhi_", entityMap, "RAWDATAAVG");
- putIfNotNull(insertMap, "yuan_shi_sd_", entityMap, "RAWDATASD");
- putIfNotNull(insertMap, "yuan_shi_cv_", entityMap, "RAWDATACV");
- putIfNotNull(insertMap, "yuan_shi_n_", entityMap, "RAWDATAN");
- putIfNotNull(insertMap, "shi_kong_shu_", entityMap, "ROWDATAOC");
- putIfNotNull(insertMap, "chu_jun_zhi_", entityMap, "CONTROLDATAAVG");
- putIfNotNull(insertMap, "chu_sd_", entityMap, "CONTROLDATASD");
- putIfNotNull(insertMap, "chu_cv_", entityMap, "CONTROLDATACV");
- putIfNotNull(insertMap, "lei_jun_zhi_", entityMap, "ACCUMDATAAVG");
- putIfNotNull(insertMap, "lei_sd_", entityMap, "ACCUMDATASD");
- putIfNotNull(insertMap, "lei_cv_", entityMap, "ACCUMDATACV");
- putIfNotNull(insertMap, "lei_n_", entityMap, "ACCUMDATAN");
- putIfNotNull(insertMap, "zai_kong_lv_", entityMap, "ACCUMDATAPER");
- putIfNotNull(insertMap, "cv_kong_zhi_fan_w", entityMap, "CVRANGE");
- putIfNotNull(insertMap, "zhi_kong_chang_ji", entityMap, "QCMFG");
- putIfNotNull(insertMap, "shi_kong_gui_ze_", entityMap, "QCRule");
- putIfNotNull(insertMap, "shi_fou_he_ge_", entityMap, "PASS");
- putIfNotNull(insertMap, "she_bei_ming_chen", entityMap, "DEVICENAME");
- insertList.add(insertMap);
- }
- if (!insertList.isEmpty()) {
- String res = ibpsRepository.saveToTable(insertList, "t_dlxmsnzkyfxzb", "1");
- if ("success".equals(res)) {
- log.info("table:t_dlxmsnzkyfxzb success insert: {} datas", insertList.size());
- } else {
- log.info("fail insert t_dlxmsnzkyfxzb");
- }
- }
- }
- return "success";
- }
- public void HandleUnControlReport(List<Map<String, Object>> retList){
- if (retList.size() > 0) {
- Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
- long sequenceCounter = 0;
- List<Map<String, Object>> insertList = new ArrayList<>();
- for (Map<String, Object> retMap : retList) {
- Map<String, Object> insertMap = new HashMap<>();
- // 生成有序ID:时间戳+自增序列号
- String orderedId = String.format("%d-%06d",
- currentTimestamp.getTime(), // 使用时间戳
- sequenceCounter++ // 自增序列号
- );
- insertMap.put("id_", orderedId);
- insertMap.put("id_", retMap.get("RESULT_NO"));
- insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
- String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("CREATEUSER")));
- if(createUserInfo.contains("未找到")){
- log.warn(createUserInfo);
- continue;
- }
- // insertMap.put("create_by_", createUserInfo.split("@")[0]);
- // insertMap.put("bian_zhi_ren_", createUserInfo.split("@")[0]);
- // insertMap.put("bian_zhi_shi_jian", String.valueOf(retMap.get("CREATETIME")));
- insertMap.put("di_dian_", ibpsRepository.getPosiByCode("LOCAL"));
- insertMap.put("shi_fou_guo_shen_", "待处理");
- insertMap.put("zhuan_ye_zu_", ibpsRepository.getPosiByCode(retMap.get("GROUP_ID").toString()));
- // insertMap.put("cao_zuo_zhe_", createUserInfo.split("@")[0]);
- insertMap.put("yi_qi_ming_", retMap.get("TESTCODE"));
- insertMap.put("xiang_mu_ming_", retMap.get("DEVICECODE"));
- insertMap.put("zhi_kong_pin_ming", retMap.get("QCNAME"));
- insertMap.put("zhi_kong_pi_hao_", retMap.get("QCLOT"));
- String qcDate = (String) retMap.get("QCDATE");
- String formatted = qcDate == null ? null :
- LocalDate.parse(qcDate, DateTimeFormatter.ofPattern("yyyyMMdd"))
- .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
- insertMap.put("shi_kong_ri_qi_", formatted);
- insertMap.put("shi_kong_de_zhi_k", retMap.get("QCRESULT"));
- insertMap.put("she_ding_ba_zhi_", retMap.get("STANDARD_SD"));
- //定量解析
- // 获取原始 QUANT 值
- String quant = (String) retMap.get("QUANT");
- Set<String> dingLiangSet = new LinkedHashSet<>(); // 用 LinkedHashSet 保持插入顺序,同时去重
- List<String> qiTaList = new ArrayList<>();
- if (quant != null && !quant.trim().isEmpty()) {
- String[] parts = quant.split(",");
- for (String part : parts) {
- String item = part.trim();
- if (item.isEmpty()) continue;
- if ("1-3s".equals(item)) {
- dingLiangSet.add("1");
- } else if ("2-2s".equals(item)) {
- dingLiangSet.add("2");
- } else if ("R-4s".equals(item)) {
- dingLiangSet.add("3");
- } else {
- // 其他情况:归为 4,并记录到 qi_ta_shuo_ming_
- dingLiangSet.add("4");
- qiTaList.add(item);
- }
- }
- }
- // 拼接 ding_liang_
- String dingLiangStr = String.join(",", dingLiangSet);
- // 拼接 qi_ta_shuo_ming_
- String qiTaStr = String.join(",", qiTaList);
- // 放入 insertMap
- insertMap.put("ding_liang_", dingLiangStr);
- insertMap.put("qi_ta_shuo_ming_", qiTaStr);
- insertMap.put("qi_ta_miao_shu_", retMap.get("REASON"));
- insertMap.put("chu_li_cuo_shi_", "6");
- insertMap.put("qi_ta_cuo_shi_", retMap.get("ACTION"));
- insertMap.put("chu_li_hou_zhi_ko", retMap.get("QCFINALRESULT"));
- insertMap.put("shi_fou_zai_kong_", "是".equals(retMap.get("ISINCONTROL")) ? "2" : "1");
- insertMap.put("shi_kong_shi_fou_","是".equals(retMap.get("AFFECTSPATIENTSAMPLES")) ? "2" : "1");
- insertMap.put("shi_fou_ying_xian", "是".equals(retMap.get("AFFECTSRESULTREPORTING")) ? "2" : "1");
- insertMap.put("shuo_ming_", retMap.get("NOTES"));
- insertMap.put("fen_xi_yu_zhi_xin", retMap.get("ANALYSIS"));
- insertList.add(insertMap);
- }
- if (!insertList.isEmpty()) {
- String res = ibpsRepository.saveToTable(insertList, "t_snzkskbgvb", "1");
- // String res = "1";
- if ("success".equals(res)) {
- log.info("table:t_snzkskbgvb success insert: {} datas", insertList.size());
- } else {
- log.error("fail insert t_snzkskbgvb");
- }
- }
- } else {
- log.info("No New Uncontrol Report exist!");
- }
- }
- public void HandleInfectiousReport(List<Map<String, Object>> retList){
- if (retList.size() > 0) {
- Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
- long sequenceCounter = 0;
- List<Map<String, Object>> insertList = new ArrayList<>();
- for (Map<String, Object> retMap : retList) {
- Map<String, Object> insertMap = new HashMap<>();
- // 生成有序ID:时间戳+自增序列号
- String orderedId = String.format("%d-%06d",
- currentTimestamp.getTime(), // 使用时间戳
- sequenceCounter++ // 自增序列号
- );
- insertMap.put("id_", orderedId);
- insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
- String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("REGISTERUSER")));
- if(createUserInfo.contains("未找到")){
- log.warn("createUserInfo:"+createUserInfo);
- continue;
- }
- String workGroupID = ibpsRepository.getPosiByCode(retMap.get("GROUPID").toString());
- if(workGroupID.contains("-1")){
- log.warn("workGroupID:"+workGroupID);
- continue;
- }
- insertMap.put("create_by_", createUserInfo.split("@")[0]);
- insertMap.put("bian_zhi_ren_", createUserInfo.split("@")[0]);
- insertMap.put("bian_zhi_shi_jian", String.valueOf(retMap.get("REGISTERDATE")));
- insertMap.put("bian_zhi_bu_men_", workGroupID);
- insertMap.put("di_dian_", ibpsRepository.getPosiByCode("LOCAL"));
- insertMap.put("shi_fou_guo_shen_", "已完成");
- insertMap.put("song_jian_ke_shi_", retMap.get("DEPARTMENT"));
- insertMap.put("song_jian_yi_shen", retMap.get("DOCTOR"));
- insertMap.put("bing_ren_xing_min", retMap.get("PATNAME"));
- insertMap.put("xing_bie_", retMap.get("GENDER"));
- insertMap.put("nian_ling_", retMap.get("AGE").toString().replace("岁",""));
- insertMap.put("jian_yan_jie_guo_", retMap.get("REPORTRESULT"));
- insertMap.put("bao_gao_ri_qi_", retMap.get("REPORTDATE"));
- insertMap.put("feed_back_dr_time", retMap.get("FEEDBACKDOCTOR"));
- insertMap.put("feed_back_hosp_ti", retMap.get("FEEDBACKDPHM"));
- insertMap.put("tiao_ma_hao_", retMap.get("SAMPLECODE"));
- insertList.add(insertMap);
- }
- if (!insertList.isEmpty()) {
- String res = ibpsRepository.saveToTable(insertList, "t_crbbgdjb", "1");
- // String res = "success";
- if ("success".equals(res)) {
- log.info("table:t_crbbgdjb success insert: {} datas", insertList.size());
- } else {
- log.error("fail insert t_crbbgdjb");
- }
- }
- }else {
- log.info("No New Infectious Report exist!");
- }
- }
- public void HandleAdditionalRequest(List<Map<String, Object>> retList){
- if (retList.size() > 0) {
- Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
- long sequenceCounter = 0;
- List<Map<String, Object>> insertList = new ArrayList<>();
- for (Map<String, Object> retMap : retList) {
- Map<String, Object> insertMap = new HashMap<>();
- // 生成有序ID:时间戳+自增序列号
- String orderedId = String.format("%d-%06d",
- currentTimestamp.getTime(), // 使用时间戳
- sequenceCounter++ // 自增序列号
- );
- insertMap.put("id_", orderedId);
- insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
- String createUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("REGUSER")));
- //String inUserInfo = ibpsRepository.getUserInfoByName(String.valueOf(retMap.get("INSPUSER")));
- if(createUserInfo.contains("未找到")){
- log.warn("createUserInfo:"+createUserInfo);
- continue;
- }
- String workGroupID = ibpsRepository.getPosiByCode(retMap.get("REGLOCATION").toString());
- if(workGroupID.contains("-1")){
- log.warn("workGroupID:"+workGroupID);
- continue;
- }
- insertMap.put("create_by_", createUserInfo.split("@")[0]);
- insertMap.put("bian_zhi_ren_", createUserInfo.split("@")[0]);
- insertMap.put("bian_zhi_shi_jian", String.valueOf(retMap.get("REGTIME")));
- insertMap.put("bian_zhi_bu_men_", workGroupID);
- insertMap.put("di_dian_", ibpsRepository.getPosiByCode("LOCAL"));
- insertMap.put("shi_fou_guo_shen_", "已完成");
- insertMap.put("shen_qing_shi_jia", retMap.get("REQTIME"));
- insertMap.put("ke_shi_zh", retMap.get("REQLOCATION"));
- insertMap.put("shen_qing_ren_zh", retMap.get("REQUSER"));
- //insertMap.put("shen_qing_ren_", retMap.get("REQUSER"));
- insertMap.put("yang_pin_bian_hao", retMap.get("SAMPLECODE"));
- insertMap.put("nei_ron_zh", retMap.get("TESTCODE"));
- insertMap.put("jian_yan_shi_xian", String.valueOf(retMap.get("ADDTIME")));
- insertMap.put("ke_shi_lei_xing_", "外部");
- insertMap.put("deng_ji_ren_yuan_", "受理");
- // insertMap.put("jie_shou_ren_yuan", inUserInfo.split("@")[0]);
- insertMap.put("jie_shou_ren_yuan", String.valueOf(retMap.get("INSPUSER")));
- insertMap.put("song_da_qing_kuan", "已送");
- insertMap.put("song_da_ren_yuan_", retMap.get("RECUSER"));
- insertMap.put("song_da_shi_jian_", String.valueOf(retMap.get("RECTIME")));
- insertMap.put("bei_zhu_", retMap.get("REMARK"));
- insertList.add(insertMap);
- }
- if (!insertList.isEmpty()) {
- String res = ibpsRepository.saveToTable(insertList, "t_fjjysqdjb", "1");
- // String res = "success";
- if ("success".equals(res)) {
- log.info("table:t_fjjysqdjb success insert: {} datas", insertList.size());
- } else {
- log.error("fail insert t_fjjysqdjb");
- }
- }
- }else {
- log.info("No New Additional Request exist!");
- }
- }
- // 辅助方法:安全获取字符串值,避免空指针异常
- private String getStringValue(Map<String, Object> map, String key) {
- Object value = map.get(key);
- return value == null ? "" : value.toString();
- }
- // 辅助方法:简化条件插入操作
- private void putIfNotNull(Map<String, Object> targetMap, String targetKey,
- Map<String, Object> sourceMap, String sourceKey) {
- Object value = sourceMap.get(sourceKey);
- if (value != null) {
- targetMap.put(targetKey, value.toString());
- if(targetKey.equals("pi_hao_kai_shi_sh")){
- targetMap.put(targetKey, value.toString().substring(0,10));
- }
- if(targetKey.equals("shi_fou_he_ge_")){
- if(value.toString().equals("Y")){
- targetMap.put(targetKey, "合格");
- }
- if(value.toString().equals("N")){
- targetMap.put(targetKey, "不合格");
- }
- }
- } else {
- targetMap.put(targetKey, "");
- }
- }
- public void HandQIData(List<Map<String, Object>>qualityIndicatorList){
- // 创建用于存储更新数据的列表
- List<Map<String, Object>> updateDataList = new ArrayList<>();
- if (qualityIndicatorList == null || qualityIndicatorList.isEmpty()) {
- // 执行退出操作
- return;
- }
- // Set<String> distinctSet = new HashSet<>();
- // for (Map<String, Object> item : qualityIndicatorList) {
- // Object value = item.get("bian_zhi_shi_jian");
- // if (value != null) {
- // distinctSet.add(value.toString());
- // }
- // }
- // // 转换为List
- // List<String> distinctList = new ArrayList<>(distinctSet);
- YearMonth currentYearMonth = YearMonth.now();
- YearMonth previousMonth = currentYearMonth.minusMonths(1);
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年M月份", Locale.CHINA);
- String DateRange = DateRangeUtil.getDateRange(previousMonth.format(formatter));
- if(!manualQryMonth.equals("")){
- DateRange = DateRangeUtil.getDateRange(manualQryMonth);
- } else {
- manualQryMonth = previousMonth.format(formatter);
- }
- List<Map<String, Object>> lisRetList = lisViewRepository.GetLISRes(DateRange);
- List<Map<String, Object>> matchList = new ArrayList<>();
- for (Map<String, Object> undoQIMap : qualityIndicatorList) {
- String editTime = undoQIMap.get("bian_zhi_shi_jian").toString();
- //如果不是当前月份退出
- if(!editTime.equals(manualQryMonth)){
- continue;
- }
- matchList = MatchLISRes(undoQIMap, lisRetList, matchList, getCurTime("yyyy-MM-dd HH:mm:ss"));
- }
- if (matchList == null) {
- log.info("no match data found");
- return;
- }
- //测试输出matchList
- StringBuilder outString = new StringBuilder("current matchList:\n");
- for(Map<String, Object> retMap : matchList){
- outString.append(retMap.toString()).append("\n");
- }
- log.info(outString.toString());
- String retValue = ibpsRepository.saveToTable(matchList,"t_zlzbpjzb","2");
- if(retValue.equals("success")){
- log.info("success update:"+matchList.size()+" datas");
- } else {
- log.info("fail update");
- }
- //以下暂停使用
- // for (Map<String, Object> qualityIndicatorMap : qualityIndicatorList) {
- // log.info(qualityIndicatorMap.toString());
- // String DateRange = DateRangeUtil.getDateRange(qualityIndicatorMap.get("bian_zhi_shi_jian").toString());
- // String QryItem = qualityIndicatorMap.get("bei_zhu_").toString().split(":")[1];
- //
- // String id = qualityIndicatorMap.get("id_").toString();
- // String compareRes = ValueEvaluator.evaluateValue(retVal,qualityIndicatorMap.get("yuan_shi_shu_ju_").toString());
- // // 将数据添加到更新列表
- // Map<String, Object> updateData = new HashMap<>();
- // updateData.put("id", id);
- // updateData.put("retVal", retVal);
- // updateData.put("compareRes", compareRes);
- // updateDataList.add(updateData);
- // }
- // // 调用抽离的保存方法
- // ibpsRepository.updateQualityIndicatorData(updateDataList);
- }
- //与LIS中List进行匹配
- public List<Map<String, Object>> MatchLISRes(Map<String, Object> undoQIMap, List<Map<String, Object>> lisRetList, List<Map<String, Object>> matchList, Timestamp formattedDateTime) {
- // 如果 matchList 为 null,则初始化
- if (matchList == null) {
- matchList = new ArrayList<>();
- }
- // 获取 bei_zhu_ 字段值
- String beiZhu = (String) undoQIMap.get("bei_zhu_");
- // 在 lisRetList 中查找匹配的记录
- for (Map<String, Object> lisMap : lisRetList) {
- String currentLisFlag = (String) lisMap.get("lisFlag");
- if (beiZhu.equals(currentLisFlag)) {
- // 找到匹配项,创建新的匹配记录
- Map<String, Object> matchRecord = new HashMap<>();
- matchRecord.put("id_", undoQIMap.get("id_")); // 从 undoQIMap 取 id_
- //计算是否达标
- String curValue = lisMap.get("percentage").toString();
- String compChar = undoQIMap.get("yuan_shi_shu_ju_").toString();
- String compRes = ValueEvaluator.evaluateValue(curValue, compChar);
- matchRecord.put("da_biao_qing_kuan", compRes);
- if(resultWithUnit.equals("1")){
- curValue = curValue + compChar.split("@")[2];
- }
- matchRecord.put("shi_ji_shu_zhi_", curValue);
- matchRecord.put("zhuang_tai_", "已完成");
- matchRecord.put("update_time_", formattedDateTime);
- log.info("curValue:"+curValue+", compChar:"+compChar+", cpmpare result:"+compRes);
- matchList.add(matchRecord);
- break; // 找到匹配后跳出内层循环
- }
- }
- return matchList;
- }
- public void AbilityMonitor(){
- // 1. 转为 Set 便于 O(1) 查询
- Set<String> pushDates = new HashSet<>(Arrays.asList(pushDate.split(",")));
- // 2. 获取当前日期的 MMdd 格式
- String todayMMDD = LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd"));
- // 3. 判断是否匹配
- if (pushDates.contains(todayMMDD)) {
- log.info("in abilitymonitor day!");
- // Timestamp currentTimestamp = getCurTime("yyyy-MM-dd HH:mm:ss");
- //先取全部监督内容,后面不用再多次去数据库获取
- List<Map<String, Object>> contentList = ibpsRepository.getMonitorContent();
- List<Map<String, Object>> employeeList = ibpsRepository.getAllUser();
- for (Map<String, Object> employeeMap : employeeList) {
- String userID = (String) employeeMap.get("ID_");
- String userName = (String) employeeMap.get("NAME_");
- //String depIDStr = (String) employeeMap.get("POSITIONS_");
- //改成取主部门
- String depIDStr = ibpsRepository.getMainPos(userID);
- if (depIDStr == null || depIDStr.trim().isEmpty()) {
- continue;
- }
- // 按逗号分割,去除前后空格(防御性编程)
- String[] depIDs = depIDStr.split(",");
- for (String depID : depIDs) {
- depID = depID.trim(); // 去除可能的空格,如 "dept1, dept2"
- if (depID.isEmpty()) {
- continue; // 跳过空片段(例如末尾多逗号:"a,b,")
- }
- // 每条数据:userID, userName, depID
- String monitorUser = DepartmentLeaderField.get(depID);
- if (monitorUser != null) {
- List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
- Map<String, Object> insertMap = new HashMap<>();
- List<Map<String, Object>> monitorItemList = getMonitorItem(contentList, depID);
- if (monitorItemList != null) {
- //先插主表 t_lhryjdjlb
- String mainID = UUID.randomUUID().toString();
- insertMap.put("id_", mainID);
- insertMap.put("create_by_",monitorUser);
- insertMap.put("bian_zhi_ren_",monitorUser);
- insertMap.put("create_time_",getCurTime("yyyy-MM-dd HH:mm:ss"));
- insertMap.put("shi_fou_guo_shen_","待推送");
- insertMap.put("bian_zhi_bu_men_",depID);
- //insertMap.put("bian_zhi_shi_jian",String.valueOf(getCurTime("yyyy-MM-dd")));
- insertMap.put("bian_zhi_shi_jian", LocalDate.now().toString());
- insertMap.put("bei_jian_du_ren_y",userID);
- insertMap.put("zhi_liang_jian_du","检验员");
- insertMap.put("jian_du_gang_wei_","1382414549667282944"); //固定岗位:检验员id
- String curDay = String.valueOf(getCurTime("yyyy-MM-dd HH:mm:ss"));
- insertMap.put("jian_ce_shi_jian_",curDay.split(" ")[0]);
- insertMap.put("jian_du_kai_shi_s",curDay.split(" ")[0]);
- insertMap.put("jian_du_jie_shu_s",curDay.split(" ")[0]);
- insertMap.put("shi_wu_shuo_ming_","被监督人员:"+userName+",监督事由:在岗检验人员每季度定期监督,监督岗位:检验员");
- insertMap.put("yi_jian_","该人员能力符合相关要求。");
- insertMap.put("jian_du_fang_shi_","观察操作");
- insertMap.put("jian_du_shi_you_","在岗检验人员每季度定期监督");
- insertList.add(insertMap);
- // log.info(insertList.toString());
- // String retValue = "success";
- String retValue = ibpsRepository.saveToTable(insertList,"t_lhryjdjlb","1");
- if(retValue.equals("success")){
- log.info("success insert into lhryjdjlb:"+insertList.size()+" datas");
- //再插子表 t_lhryjdjlzb
- List<Map<String, Object>> insertChildList = new ArrayList<Map<String, Object>>();
- Integer sequenceCounter = 0;
- String orderedId = "";
- Timestamp createTime = getCurTime("yyyy-MM-dd HH:mm:ss");
- for (Map<String, Object> monitorItem : monitorItemList) {
- Map<String, Object> insertChildMap = new HashMap<>();
- orderedId = mainID+"@"+String.valueOf(sequenceCounter); // 自增序列号
- sequenceCounter++;
- insertChildMap.put("id_", orderedId);
- insertChildMap.put("jian_du_xiang_mu_", monitorItem.get("DIR"));
- insertChildMap.put("jian_du_nei_rong_", monitorItem.get("DESCs"));
- insertChildMap.put("jian_du_jie_guo_", "是");
- insertChildMap.put("parent_id_", mainID);
- insertChildMap.put("create_time_", createTime);
- insertChildList.add(insertChildMap);
- }
- // log.info(insertChildList.toString());
- // String retChildValue = "success";
- String retChildValue = ibpsRepository.saveToTable(insertChildList,"t_lhryjdjlzb","1");
- if(retValue.equals("success")){
- log.info("success insert into lhryjdjlzb:"+insertChildList.size()+" datas");
- } else {
- log.info("fail insert");
- }
- } else {
- log.info("fail insert");
- }
- }
- }
- }
- }
- } else {
- log.info("not in abilitymonitor day");
- }
- }
- public List<Map<String, Object>> getMonitorItem(List<Map<String, Object>> contentList, String depID) {
- return contentList.stream()
- .filter(map -> Objects.equals(depID, map.get("DEPID")))
- .sorted(Comparator.comparingInt((Map<String, Object> map) -> {
- Object xuHaoObj = map.get("SEQ");
- if (xuHaoObj instanceof Number) {
- return ((Number) xuHaoObj).intValue();
- } else if (xuHaoObj instanceof String) {
- try {
- return Integer.parseInt((String) xuHaoObj);
- } catch (NumberFormatException e) {
- return Integer.MAX_VALUE;
- }
- } else {
- return Integer.MAX_VALUE;
- }
- }).reversed())
- .collect(Collectors.toList());
- }
- public Timestamp getCurTime(String formartterStr){
- LocalDateTime currentDateTime = LocalDateTime.now();
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formartterStr);
- String formattedDateTime = currentDateTime.format(formatter);
- Timestamp currentTimestamp = Timestamp.valueOf(formattedDateTime);
- return currentTimestamp;
- }
- }
|