Просмотр исходного кода

增加室内质控月分析接口

huangws 7 месяцев назад
Родитель
Сommit
f1c5079308

+ 2 - 3
GetDataByView/src/main/java/com/jyxt/getdatabyview/GetDataByViewApplication.java

@@ -33,8 +33,8 @@ public class GetDataByViewApplication implements CommandLineRunner{
     @Autowired
     private ConfigurableApplicationContext context;
 
-    public List<String> lisTableList = Arrays.asList("V_JT_TestCodeRerunRecord", "V_JT_QCMonthReport", "V_JT_QCTestCodeReport");
-
+    public List<String> lisTableList = Arrays.asList("V_JT_TestCodeRerunRecord", "V_JT_QCMonthReport");//
+//    public List<String> lisTableList = Arrays.asList("V_JT_QCMonthReport");//
 
     public static void main(String[] args) {
         SpringApplication.run(GetDataByViewApplication.class, args);
@@ -49,7 +49,6 @@ public class GetDataByViewApplication implements CommandLineRunner{
             if(retList != null){
                 handleData.startHandleData(retList,lisTable);
             }
-
         }
         log.info("<-- -----------this turn finish...------------->");
         context.close(); // 直接关闭上下文

+ 192 - 19
GetDataByView/src/main/java/com/jyxt/getdatabyview/HandleData.java

@@ -5,6 +5,7 @@ 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;
@@ -22,6 +23,9 @@ public class HandleData {
     @Autowired
     private IBPSRepository ibpsRepository;
 
+    @Value("${showTestCodeName}")
+    private String showTestCodeName;
+
     public static final Map<String, String> RerunSampleField = new HashMap<>();
 
     static {
@@ -44,9 +48,63 @@ public class HandleData {
 
 
     public void startHandleData(List<Map<String, Object>> retList, String lisTable) {
-        List<Map<String, Object>> existList = ibpsRepository.qryExistData();
-        retList = cleanExistData(retList,existList);
-        log.info("get data:"+retList.size());
+        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 get rerun testcode");
+            HandleRerunSample(retList);
+        }
+        if (lisTable.equals("V_JT_QCMonthReport")){
+            log.info("ready to get QC month report");
+            HandleMonthReport(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;
+        }
+        return null;
+    }
+
+    public void HandleRerunSample(List<Map<String, Object>> retList){
         if (retList.size() > 0) {
             String fieldName = null;
             String fieldValue = null;
@@ -88,7 +146,7 @@ public class HandleData {
                 insertMap.put("bian_zhi_bu_men_", createUserInfo.split("@")[1]);
                 insertList.add(insertMap);
             }
-//            insertList = lisViewRepository.query2("ss");
+            //            insertList = lisViewRepository.query2("ss");
             String res = ibpsRepository.saveToTable(insertList, "t_fjbbjlb");
             if(res.equals("success")){
                 log.info("success insert:"+insertList.size()+" datas");
@@ -98,29 +156,144 @@ public class HandleData {
         }
     }
 
-    public List<Map<String, Object>> cleanExistData(List<Map<String, Object>> rerunTestList, List<Map<String, Object>> existList) {
-        // 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());
+    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_", "待推送");
+                LocalDateTime currentDateTime = LocalDateTime.now();
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                String formattedDateTime = currentDateTime.format(formatter);
+                insertReportMap.put("create_time_", Timestamp.valueOf(String.valueOf(formattedDateTime)));
+                String editUser = entityMap.get("CREATEBY").toString();
+                String editUserInfo = ibpsRepository.getUserInfoByName(editUser);
+                insertReportMap.put("bian_zhi_shi_jian", String.valueOf(formattedDateTime));
+                String posID = ibpsRepository.getPosiByCode(entityMap.get("GROUPCODE").toString());
+                if ((posID != "-1")&&(!editUserInfo.split("\\^")[0].equals("-1"))) {
+                    insertReportMap.put("di_dian_", posID);
+                    insertReportMap.put("bian_zhi_bu_men_", posID);
+                    insertReportMap.put("bian_zhi_ren_", editUserInfo.split("@")[0]);
+                } else{
+                    log.info("error editUserInfo or posID,skip to insert,posID:"+posID+" ,editUserInfo:"+editUserInfo);
+                    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");
+            if(res.equals("success")){
+                log.info("table:t_dlxmsnzkyfx success insert:"+insertList.size()+" datas");
+                handQCTestCode(insertList);
+            } else {
+                log.info("fail insert t_dlxmsnzkyfx");
+            }
+
         }
+    };
+
+    public String handQCTestCode(List<Map<String, Object>> reportList) {
+        LocalDateTime currentDateTime = LocalDateTime.now();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String formattedDateTime = currentDateTime.format(formatter);
+        Timestamp currentTimestamp = Timestamp.valueOf(currentDateTime);
+
+        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<>();
+                insertMap.put("id_", UUID.randomUUID().toString());
+                insertMap.put("parent_id_", getStringValue(entityMap, "REPORTID"));
+                insertMap.put("create_time_", currentTimestamp); // 直接使用Timestamp,避免字符串转换
 
-        // 2. 过滤rerunTestList:只保留id不在existIdSet中的元素
-        List<Map<String, Object>> resultList = new ArrayList<>();
-        for (Map<String, Object> testMap : rerunTestList) {
-            Object idObj = testMap.get("SAMPLECODE");
+                // 简化条件判断
+                String testCodeValue = showTestCodeName.equals("1") ?
+                        getStringValue(entityMap, "TESTCODENAME") :
+                        getStringValue(entityMap, "TESTCODE");
+                insertMap.put("xiang_mu_", testCodeValue);
 
-            String idStr = idObj == null ? null : idObj.toString();
+                // 使用辅助方法简化代码
+                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");
+                insertList.add(insertMap);
+            }
 
-            // 如果当前条码不在existIdSet中,则保留
-            if (!existIdSet.contains(idStr)) {
-                resultList.add(testMap);
+            if (!insertList.isEmpty()) {
+                String res = ibpsRepository.saveToTable(insertList, "t_dlxmsnzkyfxzb");
+                if ("success".equals(res)) {
+                    log.info("table:t_dlxmsnzkyfxzb success insert: {} datas", insertList.size());
+                } else {
+                    log.info("fail insert t_dlxmsnzkyfxzb");
+                }
             }
         }
-        return resultList;
+        return "success";
     }
 
+    // 辅助方法:安全获取字符串值,避免空指针异常
+    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, "");
+        }
+    }
 
 }

+ 24 - 4
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/repository/IBPSRepository.java

@@ -34,11 +34,18 @@ public class IBPSRepository {
     public static List<Map<String, Object>> userList = new ArrayList<>();
     public static List<Map<String, Object>> posiList = new ArrayList<>();
 
-    public List<Map<String, Object>> qryExistData(){
+    public List<Map<String, Object>> qryExistData(String lisTable){
         List<Map<String, Object>> existList = null;
-        String sqlQry = "SELECT * FROM t_fjbbjlb WHERE bian_zhi_shi_jian >= DATE_SUB(NOW(), INTERVAL 24 HOUR)";
-        log.info("excute sql:"+sqlQry);
-        existList = jdbcTemplate.queryForList(sqlQry);
+        if(lisTable.equals("V_JT_TestCodeRerunRecord")){
+            String sqlQry = "SELECT * FROM t_fjbbjlb WHERE bian_zhi_shi_jian >= DATE_SUB(NOW(), INTERVAL 24 HOUR)";
+            log.info("excute sql:"+sqlQry);
+            existList = jdbcTemplate.queryForList(sqlQry);
+        }
+        if(lisTable.equals("V_JT_QCMonthReport")){
+            String sqlQry = "select id_ from t_dlxmsnzkyfx";
+            log.info("excute sql:"+sqlQry);
+            existList = jdbcTemplate.queryForList(sqlQry);
+        }
         return existList;
     }
 
@@ -148,4 +155,17 @@ public class IBPSRepository {
         return retVal;
     }
 
+    public String getPosiByCode(String positionCode) {
+        String retVal = "-1";
+        for (Map<String, Object> map : posiList) {
+            Object descObj = map.get("DESC_");
+            if (descObj != null && String.valueOf(descObj).contains(positionCode)) {
+                Object idObj = map.get("ID_");
+                retVal = idObj != null ? String.valueOf(idObj) : "-1";
+                break;
+            }
+        }
+        return retVal;
+    }
+
 }

+ 27 - 19
GetDataByView/src/main/java/com/jyxt/getdatabyview/view/repository/LISViewRepository.java

@@ -4,6 +4,7 @@ import com.jyxt.getdatabyview.view.LISView;
 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.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
@@ -12,10 +13,7 @@ import org.springframework.stereotype.Repository;
 
 import java.sql.Timestamp;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Component   // 通用注解
 @Repository
@@ -25,6 +23,8 @@ public class LISViewRepository {
     @Autowired
     private JdbcTemplate jdbcTemplate;
 
+    @Value("${onlyQrySecondDay}")
+    private String onlyQrySecondDay;
 
     public List<Map<String, Object>> query(String tableName) {
         List<Map<String, Object>> retList = null;
@@ -43,23 +43,19 @@ public class LISViewRepository {
             }
         }
         //月分析主表
-        if(tableName.equals("V_JT_QCMonthReport!!")) {
-            try{
-                //        String sqlQry = "SELECT * FROM V_JT_TestCodeRerunRecord WHERE TO_DATE(CreateTime, 'YYYY-MM-DD HH24:MI:SS') >= SYSDATE-1";
-                String sqlQry = "select * from t_zztest";
-                log.info("excute sql:"+sqlQry);
-                retList = jdbcTemplate.queryForList(sqlQry);
-                return retList;
-            } catch (Exception e) {
-                log.error(e.getMessage());
-                e.printStackTrace();
-                return retList;
+        if(tableName.equals("V_JT_QCMonthReport")) {
+            // 新增条件判断:当需要检查首日时,验证当前日期是否为1号
+            if ("1".equals(onlyQrySecondDay)) {
+                Calendar calendar = Calendar.getInstance();
+                int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
+                if (currentDay != 2) {
+                    log.info("非当月第二日,跳过查询");
+                    return retList;  // 非1号直接返回空列表
+                }
             }
-        }
-        //月分析子表
-        if(tableName.equals("V_JT_QCMonthReport!!!!")) {
             try{
-                        String sqlQry = "SELECT * FROM V_JT_TestCodeRerunRecord WHERE TO_DATE(CreateTime, 'YYYY-MM-DD HH24:MI:SS') >= SYSDATE-1";
+//                String sqlQry = "select reportID,createtime,groupcode,groupname from V_JT_QCMonthReport where createtime=TO_CHAR(SYSDATE, 'YYYYMM')";     //生产环境sql
+                String sqlQry = "select REPORTID,CREATETIME,CREATEBY,GROUPCODE,GROUPNAME from V_JT_QCMonthReport where createtime = DATE_FORMAT(CURDATE(), '%Y%m')"; //本地调试sql
 //                String sqlQry = "select * from t_zztest";
                 log.info("excute sql:"+sqlQry);
                 retList = jdbcTemplate.queryForList(sqlQry);
@@ -73,6 +69,18 @@ public class LISViewRepository {
         return retList;
     }
 
+    public List<Map<String, Object>> getQCTestCodeList(String reportID) {
+        List<Map<String, Object>> retList = new ArrayList<>();
+        String sqlQry = "select * from V_JT_QCTestCodeReport where reportID='"+reportID+"'";
+        log.info("excute sql:"+sqlQry);
+        try {
+            retList = jdbcTemplate.queryForList(sqlQry);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return retList;
+    }
+
     public List<Map<String, Object>> query2(String tableName) {
         List<Map<String, Object>> retList = new ArrayList<>();
         Map<String, Object> dataMap = new HashMap<>();

+ 13 - 9
GetDataByView/src/main/resources/application.properties

@@ -1,13 +1,13 @@
 spring.application.name=GetDataByView
-spring.datasource.jdbc-url=jdbc:oracle:thin:@192.168.0.7:1521/lis
-spring.datasource.username=xhoffline
-spring.datasource.password=7540000E
-spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
-#spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
-#spring.datasource.username=root
-#spring.datasource.password=test001
-#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.second-datasource.jdbc-url = jdbc:mysql://localhost:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
+#spring.datasource.jdbc-url=jdbc:oracle:thin:@192.168.0.7:1521/lis
+#spring.datasource.username=xhoffline
+#spring.datasource.password=7540000E
+#spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
+spring.datasource.jdbc-url=jdbc:mysql://localhost:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
+spring.datasource.username=root
+spring.datasource.password=test001
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.second-datasource.jdbc-url = jdbc:mysql://192.168.2.212:3306/klims-ibps3?characterEncoding=utf8&useSSL=false
 spring.second-datasource.username = root
 spring.second-datasource.password = test001
 spring.second-datasource.driver-class-name = com.mysql.cj.jdbc.Driver
@@ -16,3 +16,7 @@ spring.second-datasource.driver-class-name = com.mysql.cj.jdbc.Driver
 logging.level.root=INFO
 #1 or 0,1 means only qry,0 means update
 config.qryMode=0
+#1 means only in secord day every month,0 means everyday
+onlyQrySecondDay=0
+#1 means Chinese name,0 means code
+showTestCodeName=1