| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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.stereotype.Component;
- import java.sql.Timestamp;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- @Component
- public class HandleData {
- private static final Logger log = LoggerFactory.getLogger(GetDataByViewApplication.class);
- @Autowired
- private LISViewRepository lisViewRepository;
- @Autowired
- private IBPSRepository ibpsRepository;
- public static final Map<String, String> RerunSampleField = 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_");
- }
- 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());
- 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.info("error userInfo,skip to insert:"+createUserInfo);
- continue;
- }
- if (auditUserInfo.split("\\^")[0].equals("-1")) {
- log.info("error auditUserInfo,skip to insert:"+auditUserInfo);
- continue;
- }
- LocalDateTime currentDateTime = LocalDateTime.now();
- DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- String formattedDateTime = currentDateTime.format(formatter2);
- insertMap.put("create_by_", createUserInfo.trim().split("@")[0]);
- insertMap.put("create_time_", Timestamp.valueOf(String.valueOf(formattedDateTime)));
- insertMap.put("bian_zhi_ren_", createUserInfo.trim().split("@")[0]);
- insertMap.put("jian_yan_zhe_", auditUserInfo.trim().split("@")[0]);
- insertMap.put("jian_yan_yuan_", auditUserInfo.trim().split("@")[0]);
- insertMap.put("ri_qi_", String.valueOf(entityMap.get("CREATETIME")).split(" ")[0]);
- insertMap.put("bian_zhi_bu_men_", createUserInfo.split("@")[1]);
- insertList.add(insertMap);
- }
- // insertList = lisViewRepository.query2("ss");
- String res = ibpsRepository.saveToTable(insertList, "t_fjbbjlb");
- if(res.equals("success")){
- log.info("success insert:"+insertList.size()+" datas");
- } else {
- log.info("fail insert");
- }
- }
- }
- 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());
- }
- // 2. 过滤rerunTestList:只保留id不在existIdSet中的元素
- List<Map<String, Object>> resultList = new ArrayList<>();
- for (Map<String, Object> testMap : rerunTestList) {
- Object idObj = testMap.get("SAMPLECODE");
- String idStr = idObj == null ? null : idObj.toString();
- // 如果当前条码不在existIdSet中,则保留
- if (!existIdSet.contains(idStr)) {
- resultList.add(testMap);
- }
- }
- return resultList;
- }
- }
|