|
|
@@ -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, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|