package com.malk.eastar.schedule; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONObject; import com.malk.eastar.service.AitableService; import com.malk.eastar.service.DDCoreClient; import com.malk.eastar.service.YidaService; import com.malk.utils.UtilMap; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.util.*; /** * 新的定时任务 */ @Slf4j @Configuration @EnableScheduling @ConditionalOnProperty(name = {"enable.scheduling"}) public class ScheduleTaskNew { @Autowired private DDCoreClient ddCoreClient; @Autowired private AitableService aitableService; @Autowired private YidaService yidaService; /** * 更新员工在职情况 */ @Scheduled(cron = "0 0 6 * * ?") public void updateEmployeeStatus() { log.info("更新员工在职情况"); /* 查询业务小组档案中的成员信息 */ List ltcBusinessUserData = new ArrayList<>(); try { ltcBusinessUserData = yidaService.queryLtcAllBusinessUserData(); } catch (Exception e) { log.error("查询业务小组档案中的成员信息异常",e); } /* 查询最近一周的离职人员 */ List> leaveEmployeeData = new ArrayList<>(); try { Date startTime = DateUtil.lastWeek(); Date endTime = DateUtil.yesterday(); leaveEmployeeData = ddCoreClient.getLeaveEmployeeData(startTime, endTime); if(leaveEmployeeData.isEmpty()){ log.info("最近一周没有人员离职"); }else{ log.info("最近一周有离职人员"); log.info(JSONObject.toJSONString(leaveEmployeeData)); } } catch (Exception e) { log.error("查询最近一周的离职人员异常",e); } try { /* 业务员已离职,更新状态 */ if(!leaveEmployeeData.isEmpty()){ for (Map bu : ltcBusinessUserData){ for (int i = 0; i < leaveEmployeeData.size(); i++) { if(UtilMap.getString(bu, "userId").equals(UtilMap.getString(leaveEmployeeData.get(i), "userId"))){ yidaService.setLtcBusinessUserLeave(UtilMap.getString(bu, "formInstId")); log.info("更新业务小组档案[userId={}]记录在职情况为已离职",UtilMap.getString(bu, "userId")); break; } } } } } catch (Exception e) { log.error("更新员工在职情况异常",e); } } /** * 客户数据清洗 */ // @Scheduled(cron = "0 18 19 * * ?") public void cleanCustomerData20260509() { /* 查询(易思达)客户名册所有记录 */ log.info("查询(易思达)客户名册所有记录"); List ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 更新字段: 进入私海时间、最后跟进时间 */ String formInstId; long privateSeaTime; long lastContactTime; for (Map ltcCustomerRecord : ltcCustomerData){ formInstId = UtilMap.getString(ltcCustomerRecord, "formInstId"); System.out.println(ltcCustomerRecord.get("customerName").toString()); try { privateSeaTime = DateUtil.current(); lastContactTime = privateSeaTime; yidaService.updateLtcCustomerBasicInfo8(formInstId,privateSeaTime,lastContactTime); } catch (Exception e) { log.error("更新易思达系统客户记录异常",e); } } log.info("客户数据清洗完成"); } /** * 客户数据清洗 */ // @Scheduled(cron = "0 40 18 * * ?") public void cleanCustomerData20260430() { /* 从项目总表(系统1)获取客户数据 */ List sys1CustomerData = new ArrayList<>(); // 项目总表客户数据 try { sys1CustomerData = aitableService.querySys1CustomerData(); log.info("项目总表客户数量="+sys1CustomerData.size()); } catch (Exception e) { log.error("查询项目总表客户数据异常",e); } /* 查询业务小组档案中的成员信息 */ List ltcBusinessUserData = new ArrayList<>(); try { ltcBusinessUserData = yidaService.queryLtcAllBusinessUserData(); } catch (Exception e) { log.error("查询业务小组档案中的成员信息异常",e); } String aiTableId; //AI表格ID String customerName1; Object businessUserUnionId; String businessUserId; String customerLevel; String newOrOld; String businessLeaderUserId; String businessDepartment; List deptIdList; // for (Map sys1CustomerRecord : sys1CustomerData) { // aiTableId = ""; // businessUserId = ""; // customerLevel = ""; // newOrOld = ""; // businessLeaderUserId = ""; // businessDepartment = ""; // if (sys1CustomerRecord.get("aiTableId") != null) { // aiTableId = sys1CustomerRecord.get("aiTableId").toString(); // } // if (sys1CustomerRecord.get("customerName") != null) { // customerName1 = sys1CustomerRecord.get("customerName").toString(); // if("Big Sky Games Limited".equals(customerName1)){ // businessUserUnionId = sys1CustomerRecord.get("businessUserUnionId"); // if (businessUserUnionId != null) { // try { // businessUserId = ddCoreClient.getUserIdByUnionId(businessUserUnionId.toString()); // if(businessUserId.isEmpty()){ // throw new RuntimeException("businessUserUserId为空"); // } // } catch (Exception e) { // log.error("没有找到业务员unionId["+businessUserUnionId+"]对应的userId"); // } // } // if(businessUserId!=null && !businessUserId.isEmpty()){ // for (int i = 0; i < ltcBusinessUserData.size(); i++) { // if(UtilMap.getString(ltcBusinessUserData.get(i), "userId").equals(businessUserId)){ // businessLeaderUserId = UtilMap.getString(ltcBusinessUserData.get(i), "businessLeaderUserId"); // if(businessLeaderUserId.isEmpty()){ // businessLeaderUserId = null; // } // break; // } // } // try { // deptIdList = ddCoreClient.getDeptIdListByUserId(businessUserId); // if(deptIdList!=null && !deptIdList.isEmpty()){ // businessDepartment = String.valueOf(deptIdList.get(0)); // } // if(businessDepartment.isEmpty()){ // businessDepartment = null; // } // } catch (Exception e) { // log.error("获取业务userId与业务部门映射异常",e); // } // } // if (sys1CustomerRecord.get("customerLevel") != null) { // customerLevel = sys1CustomerRecord.get("customerLevel").toString(); // } // if (sys1CustomerRecord.get("newOrOld") != null) { // newOrOld = sys1CustomerRecord.get("newOrOld").toString(); // } // System.out.println("aiTableId="+aiTableId+",customerName1="+customerName1 // +",businessUserId="+businessUserId+",customerLevel="+customerLevel // +",newOrOld="+newOrOld+",businessLeaderUserId="+businessLeaderUserId // +",businessDepartment="+businessDepartment); // } // } // } /* 查询(易思达)客户名册所有记录 */ log.info("查询(易思达)客户名册所有记录"); List ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 寻找易思达系统不存在的客户,并新增 */ List ltcCustomerAddData = new ArrayList<>(); Map> customerNameUpperCaseMap = new HashMap<>(); String customerName1UpperCase; String customerName2; String customerName2UpperCase; List maplist; for (Map sys1CustomerRecord : sys1CustomerData){ if(sys1CustomerRecord.get("customerName")!= null){ customerName1 = sys1CustomerRecord.get("customerName").toString(); if(!customerName1.isEmpty()){ /* 按大写客户名称归类 */ customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); if(customerNameUpperCaseMap.containsKey(customerName1UpperCase)){ maplist = customerNameUpperCaseMap.get(customerName1UpperCase); }else{ maplist = new ArrayList<>(); } maplist.add(sys1CustomerRecord); customerNameUpperCaseMap.put(customerName1UpperCase,maplist); } } } boolean isExist; for(String customerNameUpperCase : customerNameUpperCaseMap.keySet()){ isExist = false; for (int i=0; i ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 更新字段: 客户当前分级、客户潜在等级、上一年分级、AI表格映射ID */ String formInstId; String customerLevel; //客户当前分级 String customerPotentialLevel; //客户潜在等级 for (Map ltcCustomerRecord : ltcCustomerData){ formInstId = UtilMap.getString(ltcCustomerRecord, "formInstId"); customerPotentialLevel = UtilMap.getString(ltcCustomerRecord, "customerPotentialLevel"); if( "A".equals(customerPotentialLevel) ||"B".equals(customerPotentialLevel) ||"C".equals(customerPotentialLevel) ||"D".equals(customerPotentialLevel) ){ customerPotentialLevel = "潜"+customerPotentialLevel; }else if("E".equals(customerPotentialLevel)){ customerPotentialLevel = "保稳E"; }else if( "潜A".equals(customerPotentialLevel) ||"潜B".equals(customerPotentialLevel) ||"潜C".equals(customerPotentialLevel) ||"潜D".equals(customerPotentialLevel) ||"保稳E".equals(customerPotentialLevel) ){ //不变 }else{ customerPotentialLevel = ""; } customerLevel = customerPotentialLevel; try { yidaService.updateLtcCustomerBasicInfo7(formInstId,customerLevel,customerPotentialLevel); } catch (Exception e) { log.error("更新易思达系统客户记录异常",e); } } log.info("客户数据清洗完成"); } /** * 客户数据清洗 */ // @Scheduled(cron = "0 45 16 * * ?") public void cleanCustomerData20260427() { /* 查询(易思达)客户名册所有记录 */ log.info("查询(易思达)客户名册所有记录"); List ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 更新字段: 客户当前分级、客户潜在等级、上一年分级、AI表格映射ID */ String formInstId; // for (Map ltcCustomerRecord : ltcCustomerData){ // formInstId = UtilMap.getString(ltcCustomerRecord, "formInstId"); // if(ltcCustomerRecord.get("aiTableId")!=null && !ltcCustomerRecord.get("aiTableId").toString().isEmpty()){ // try { // yidaService.updateLtcCustomerBasicInfo5(formInstId,"","","",""); // } catch (Exception e) { // log.error("更新易思达系统客户记录异常",e); // } // } // } /* 新老客户信息 */ Map ltcCustomerNewOrOldMap = new HashMap<>(); String ltcCustomeNameUpper; String ltcNewOrOld; for (Map ltcCustomerRecord : ltcCustomerData){ ltcCustomeNameUpper = ltcCustomerRecord.get("customerName").toString().replaceAll(" ","").toUpperCase(); if(ltcCustomerRecord.get("newOrOld")==null){ ltcNewOrOld = ""; }else{ ltcNewOrOld = ltcCustomerRecord.get("newOrOld").toString(); } ltcCustomerNewOrOldMap.put(ltcCustomeNameUpper, ltcNewOrOld); } /* 从项目总表(系统1)获取客户数据 */ List sys1CustomerData = new ArrayList<>(); // 项目总表客户数据 try { sys1CustomerData = aitableService.querySys1CustomerData(); log.info("项目总表客户数量="+sys1CustomerData.size()); } catch (Exception e) { log.error("查询项目总表客户数据异常",e); } /* 获取项目总表客户数据,按大写客户名称分组 */ Map> customerNameUpperCaseMap = new HashMap<>(); String customerName1; String customerName1UpperCase; List maplist; for (Map sys1CustomerRecord : sys1CustomerData){ if(sys1CustomerRecord.get("customerName")!= null){ customerName1 = sys1CustomerRecord.get("customerName").toString(); if(!customerName1.isEmpty()){ /* 按大写客户名称归类 */ customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); if(customerNameUpperCaseMap.containsKey(customerName1UpperCase)){ maplist = customerNameUpperCaseMap.get(customerName1UpperCase); }else{ maplist = new ArrayList<>(); } maplist.add(sys1CustomerRecord); customerNameUpperCaseMap.put(customerName1UpperCase,maplist); } } } System.out.println("大写客户名称数量="+customerNameUpperCaseMap.keySet().size()); /* 遍历易思达客户数据 */ String customerName2; String customerName2UpperCase; String customerNames; String customerLevel; //客户当前分级 String customerNewOrOld; //新老客户 String aiTableId; //AI表格映射ID for (Map ltcCustomerRecord : ltcCustomerData){ customerName2 = ltcCustomerRecord.get("customerName").toString(); customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); if(customerNameUpperCaseMap.containsKey(customerName2UpperCase)){ /* 获取新系统和项目总表共有的客户(可能匹配到多个) */ maplist = customerNameUpperCaseMap.get(customerName2UpperCase); if(maplist!=null && !maplist.isEmpty()){ if(maplist.size()==1){ formInstId = UtilMap.getString(ltcCustomerRecord, "formInstId"); aiTableId = maplist.get(0).get("aiTableId").toString(); customerLevel = maplist.get(0).get("customerLevel").toString(); customerNewOrOld = maplist.get(0).get("newOrOld").toString(); if(!customerNewOrOld.equals(ltcCustomerNewOrOldMap.get(customerName2UpperCase))){ if(!"不合作".equals(ltcCustomerNewOrOldMap.get(customerName2UpperCase))){ System.out.println("易思达客户["+customerName2+"]:"+ltcCustomerNewOrOldMap.get(customerName2UpperCase)+",项目总表客户["+maplist.get(0).get("customerName").toString()+"]:"+customerNewOrOld); }else{ customerNewOrOld = "不合作"; } } try { yidaService.updateLtcCustomerBasicInfo6(formInstId,"保稳E",customerLevel,customerNewOrOld,aiTableId); } catch (Exception e) { log.error("更新易思达系统客户记录异常",e); } }else{ customerNames = maplist.get(0).get("customerName").toString(); for(int i=1; i ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 查询业务小组档案中的成员信息 */ List ltcBusinessUserData = new ArrayList<>(); try { ltcBusinessUserData = yidaService.queryLtcAllBusinessUserData(); } catch (Exception e) { log.error("查询业务小组档案中的成员信息异常",e); } /* 获取业务userId与名称、业务部门映射 */ Map businessUserIdDeptIdMap = new HashMap<>(); Map businessUserIdNameMap = new HashMap<>(); String businessUserId; for (Map ltcCustomerRecord : ltcCustomerData){ businessUserId = UtilMap.getString(ltcCustomerRecord, "userId"); if(!businessUserId.isEmpty()){ if(!businessUserIdDeptIdMap.containsKey(businessUserId)){ businessUserIdDeptIdMap.put(businessUserId,""); } if(!businessUserIdNameMap.containsKey(businessUserId)){ businessUserIdNameMap.put(businessUserId,""); } } } List deptIdList; for (String userId : businessUserIdDeptIdMap.keySet()) { try { deptIdList = ddCoreClient.getDeptIdListByUserId(userId); if(!deptIdList.isEmpty()){ businessUserIdDeptIdMap.put(userId, String.valueOf(deptIdList.get(0))); } } catch (Exception e) { // log.error("获取业务userId与业务部门映射异常",e); } } for (String userId : businessUserIdNameMap.keySet()) { try { businessUserIdNameMap.put(userId,ddCoreClient.getNameByUserId(userId)); } catch (Exception e) { // log.error("获取业务userId与名称映射异常",e); } } /* 更新字段: 业务userId、负责人文本、业务组长、业务部门 */ String formInstId; String testUseFlag; String userId; String businessName; String businessLeaderUserId; String businessDepartment; for (Map ltcCustomerRecord : ltcCustomerData){ testUseFlag = UtilMap.getString(ltcCustomerRecord, "testUseFlag"); if(testUseFlag.equals("否")){ formInstId = UtilMap.getString(ltcCustomerRecord, "formInstId"); userId = UtilMap.getString(ltcCustomerRecord, "userId"); if(userId != null && !userId.isEmpty()){ businessName = businessUserIdNameMap.get(userId); businessLeaderUserId = null; for (int i = 0; i < ltcBusinessUserData.size(); i++) { if(UtilMap.getString(ltcBusinessUserData.get(i), "userId").equals(userId)){ businessLeaderUserId = UtilMap.getString(ltcBusinessUserData.get(i), "businessLeaderUserId"); if(businessLeaderUserId.isEmpty()){ businessLeaderUserId = null; } break; } } businessDepartment = businessUserIdDeptIdMap.get(userId); if(businessDepartment.isEmpty()){ businessDepartment = null; } }else{ userId = ""; businessName = ""; businessLeaderUserId = null; businessDepartment = null; } try { yidaService.updateLtcCustomerBasicInfo4(formInstId,userId,businessName,businessLeaderUserId,businessDepartment); } catch (Exception e) { log.error("更新易思达系统客户记录异常",e); } } } log.info("客户数据清洗完成"); } /** * 客户数据清洗 */ // @Scheduled(cron = "0 35 18 * * ?") public void cleanCustomerData() { /* 从项目总表(系统1)获取客户数据 */ List sys1CustomerData = new ArrayList<>(); // 项目总表客户数据 try { sys1CustomerData = aitableService.querySys1CustomerData(); log.info("参与比对的项目总表客户数量="+sys1CustomerData.size()); } catch (Exception e) { log.error("查询项目总表客户数据异常",e); } /* 汇总业务员unionId,一一找到对应的业务员userId */ Map unionIdUserIdMap = new HashMap<>(); String businessUserUnionId; String businessUserId; for (Map record : sys1CustomerData) { businessUserUnionId = record.get("businessUserUnionId"); if (businessUserUnionId != null && !businessUserUnionId.isEmpty()) { unionIdUserIdMap.put(businessUserUnionId, ""); } } for (Map.Entry entry : unionIdUserIdMap.entrySet()) { businessUserUnionId = entry.getKey(); try { businessUserId = ddCoreClient.getUserIdByUnionId(businessUserUnionId); if(businessUserId.isEmpty()){ throw new RuntimeException("businessUserUserId为空"); } unionIdUserIdMap.put(businessUserUnionId,businessUserId); } catch (Exception e) { // log.error("获取业务员unionId["+businessUserUnionId+"]对应的userId异常",e); log.error("没有找到业务员unionId["+businessUserUnionId+"]对应的userId"); } } for (Map record : sys1CustomerData) { businessUserUnionId = record.get("businessUserUnionId"); if (businessUserUnionId != null && !businessUserUnionId.isEmpty()) { record.put("businessUserId",unionIdUserIdMap.get(businessUserUnionId)); } } /* 从EASTAR业务数字化(系统2)获取客户数据 */ List sys2CustomerData = new ArrayList<>(); // EASTAR业务数字化客户数据 try { sys2CustomerData = yidaService.querySys2CustomerData(); log.info("参与比对的EASTAR业务数字化客户数量="+sys2CustomerData.size()); } catch (Exception e) { log.error("查询EASTAR业务数字化客户数据异常",e); } //更新客户数据清洗中的多行记录(客户名册part2) // try { // yidaService.updateSys1Sys2CustomerPart2Data(sys2CustomerData); // } catch (Exception e) { // log.error("更新客户数据清洗中的多行记录(客户名册part2)异常",e); // } /* 对比两个系统的客户数据,找到系统1独有的客户数据,系统2独有的客户数据,以及系统1和系统2有相同客户名称的客户数据 */ String customerName; List sys1CustomerNames = new ArrayList<>(); for (Map record : sys1CustomerData) { customerName = record.get("customerName"); if (customerName != null && !customerName.isEmpty()) { sys1CustomerNames.add(customerName); } } List sys2CustomerNames = new ArrayList<>(); for (Map record : sys2CustomerData) { customerName = record.get("customerName"); if (customerName != null && !customerName.isEmpty()) { sys2CustomerNames.add(customerName); } } List onlyInSys1 = new ArrayList<>(sys1CustomerNames); onlyInSys1.removeAll(sys2CustomerNames); List onlyInSys2 = new ArrayList<>(sys2CustomerNames); onlyInSys2.removeAll(sys1CustomerNames); List inBothSys = new ArrayList<>(sys1CustomerNames); inBothSys.retainAll(sys2CustomerNames); log.info("系统1独有客户数量: {}", onlyInSys1.size()); log.info("系统2独有客户数量: {}", onlyInSys2.size()); log.info("两个系统共有客户数量: {}", inBothSys.size()); /* 合并两个系统的客户数据 */ List sys1Sys2CustomerData = new ArrayList<>(); Map sys1Sys2CustomerRecord; Map tempCustomerRecord; String sys1BusinessUserName; String sys2BusinessUserName; String sys1unionid; String sys1userid; String sys2userid; boolean isAnyDifference; //是否有差异 for(String customerNameInBothSys : inBothSys){ //遍历两个系统共有客户 sys1BusinessUserName = ""; sys2BusinessUserName = ""; sys1unionid = ""; sys1userid = ""; sys2userid = ""; for (int i = 0; i < sys1CustomerData.size(); i++) { if(customerNameInBothSys.equals(sys1CustomerData.get(i).get("customerName"))){ tempCustomerRecord = sys1CustomerData.get(i); sys1BusinessUserName = tempCustomerRecord.get("businessUserName")==null?"":tempCustomerRecord.get("businessUserName").toString(); sys1unionid = tempCustomerRecord.get("businessUserUnionId")==null?"":tempCustomerRecord.get("businessUserUnionId").toString(); sys1userid = tempCustomerRecord.get("businessUserId")==null?"":tempCustomerRecord.get("businessUserId").toString(); break; } } for (int i = 0; i < sys2CustomerData.size(); i++) { if (customerNameInBothSys.equals(sys2CustomerData.get(i).get("customerName"))){ tempCustomerRecord = sys2CustomerData.get(i); sys2BusinessUserName = tempCustomerRecord.get("businessUserName")==null?"":tempCustomerRecord.get("businessUserName").toString(); sys2userid = tempCustomerRecord.get("businessUserId")==null?"":tempCustomerRecord.get("businessUserId").toString(); break; } } if (!sys1userid.isEmpty() && !sys2userid.isEmpty()){ if(sys1userid.equals(sys2userid)){ //两个系统用户id都非空,且无差异 isAnyDifference = false; }else{ //两个系统用户id都非空,且有差异 isAnyDifference = true; } }else if(sys1userid.isEmpty() && sys2userid.isEmpty()){ //两个系统用户id都为空,没有差异 isAnyDifference = false; }else{ //一个系统用户id为空,一个系统用户id不为空,有差异 isAnyDifference = true; } sys1Sys2CustomerRecord = new HashMap<>(); sys1Sys2CustomerRecord.put("customerName",customerNameInBothSys); sys1Sys2CustomerRecord.put("sys1BusinessUserName",sys1BusinessUserName); sys1Sys2CustomerRecord.put("sys2BusinessUserName",sys2BusinessUserName); sys1Sys2CustomerRecord.put("sys1unionid",sys1unionid); sys1Sys2CustomerRecord.put("sys1userid",sys1userid); sys1Sys2CustomerRecord.put("sys2userid",sys2userid); sys1Sys2CustomerRecord.put("isAnyDifference", isAnyDifference ?"是":"否"); sys1Sys2CustomerRecord.put("source", "系统1和系统2共有客户"); sys1Sys2CustomerData.add(sys1Sys2CustomerRecord); } for(String customerNameInSys1 : onlyInSys1){ //遍历系统1独有客户 sys1BusinessUserName = ""; sys1unionid = ""; sys1userid = ""; for (int i = 0; i < sys1CustomerData.size(); i++) { if(customerNameInSys1.equals(sys1CustomerData.get(i).get("customerName"))){ tempCustomerRecord = sys1CustomerData.get(i); sys1BusinessUserName = tempCustomerRecord.get("businessUserName")==null?"":tempCustomerRecord.get("businessUserName").toString(); sys1unionid = tempCustomerRecord.get("businessUserUnionId")==null?"":tempCustomerRecord.get("businessUserUnionId").toString(); sys1userid = tempCustomerRecord.get("businessUserId")==null?"":tempCustomerRecord.get("businessUserId").toString(); break; } } sys1Sys2CustomerRecord = new HashMap<>(); sys1Sys2CustomerRecord.put("customerName",customerNameInSys1); sys1Sys2CustomerRecord.put("sys1BusinessUserName",sys1BusinessUserName); sys1Sys2CustomerRecord.put("sys1unionid",sys1unionid); sys1Sys2CustomerRecord.put("sys1userid",sys1userid); sys1Sys2CustomerRecord.put("isAnyDifference", "否"); sys1Sys2CustomerRecord.put("source", "项目总表(系统1)独有客户"); sys1Sys2CustomerData.add(sys1Sys2CustomerRecord); } for (String customerNameInSys2 : onlyInSys2){ //遍历系统2独有客户 sys2BusinessUserName = ""; sys2userid = ""; for (int i = 0; i < sys2CustomerData.size(); i++) { if(customerNameInSys2.equals(sys2CustomerData.get(i).get("customerName"))){ tempCustomerRecord = sys2CustomerData.get(i); sys2BusinessUserName = tempCustomerRecord.get("businessUserName")==null?"":tempCustomerRecord.get("businessUserName").toString(); sys2userid = tempCustomerRecord.get("businessUserId")==null?"":tempCustomerRecord.get("businessUserId").toString(); break; } } sys1Sys2CustomerRecord = new HashMap<>(); sys1Sys2CustomerRecord.put("customerName",customerNameInSys2); sys1Sys2CustomerRecord.put("sys2BusinessUserName",sys2BusinessUserName); sys1Sys2CustomerRecord.put("sys2userid",sys2userid); sys1Sys2CustomerRecord.put("isAnyDifference", "否"); sys1Sys2CustomerRecord.put("source", "Eastar业务数字化(系统2)独有客户"); sys1Sys2CustomerData.add(sys1Sys2CustomerRecord); } /* 添加记录到客户数据清洗 */ // try { // yidaService.insertSys1Sys2CustomerAllData(sys1Sys2CustomerData); // } catch (Exception e) { // log.error("添加记录到客户数据清洗异常",e); // } log.info("客户数据清洗完成"); } /** * 更新客户测试使用标识 */ // @Scheduled(cron = "0 35 10 * * ?") public void updateCustomerTestFlag() { /* 查询所有已离职的员工 */ // List> leaveEmployeeData = new ArrayList<>(); // try { // leaveEmployeeData = ddCoreClient.getAllLeaveEmployeeData(); // } catch (Exception e) { // log.error("查询所有已离职的员工异常",e); // } /* 查询(客户数据清洗)客户名册all所有记录 */ log.info("查询(客户数据清洗)客户名册all所有记录"); List sys1Sys2CustomerData = new ArrayList<>(); try { sys1Sys2CustomerData = yidaService.querySys1Sys2CustomerAllData(); } catch (Exception e) { log.error("查询(客户数据清洗)客户名册all所有记录异常",e); } /* 查询(易思达)客户名册所有记录 */ log.info("查询(易思达)客户名册所有记录"); List ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册所有记录异常",e); } /* 对比后更新“测试使用”标识 */ // log.info("对比后更新“测试使用”标识"); // List testLtcCustomers = new ArrayList<>(); // String customerName; // boolean isTest; // for (Map ltcCustomerRecord : ltcCustomerData) { // isTest = true; // customerName = UtilMap.getString(ltcCustomerRecord, "customerName"); // if (customerName != null && !customerName.isEmpty()) { // customerName = customerName.trim(); // for (int i = 0; i < sys1Sys2CustomerData.size(); i++) { // if(customerName.equals(UtilMap.getString(sys1Sys2CustomerData.get(i), "customerName"))){ // isTest = false; // break; // } // } // if(isTest){ // testLtcCustomers.add(ltcCustomerRecord); // } // } // } // log.info("测试使用客户数量: {}", testLtcCustomers.size()); // int updateTestFlagCount = 0; // for (Map testLtcCustomer : testLtcCustomers){ // try { // yidaService.updateLtcCustomerTestFlag(UtilMap.getString(testLtcCustomer, "formInstId")); // updateTestFlagCount++; // System.out.println("更新测试使用标识成功:"+updateTestFlagCount); // Thread.sleep(3000); // } catch (Exception e) { // log.error("更新测试使用标识异常",e); // } // } log.info("更新客户测试使用标识完成"); } /** * 同步客户与业务 */ // @Scheduled(cron = "0 51 16 * * ?") public void syncCustomerAndBusinessUser() { /* 查询(易思达)客户名册所有记录 */ log.info("查询(易思达)客户名册所有记录"); List ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 查询(客户数据清洗)私海客户所有记录 */ // log.info("查询(客户数据清洗)私海客户所有记录"); // List privateSeaCustomerData = new ArrayList<>(); // try { // privateSeaCustomerData = yidaService.querySys1Sys2PrivateCustomerData(); // } catch (Exception e) { // log.error("查询(客户数据清洗)私海客户所有记录异常",e); // } /* 查询(客户数据清洗)公海客户所有记录 */ // log.info("查询(客户数据清洗)公海客户所有记录"); // List publicSeaCustomerData = new ArrayList<>(); // try { // publicSeaCustomerData = yidaService.querySys1Sys2PublicCustomerData(); // } catch (Exception e) { // log.error("查询(客户数据清洗)公海客户所有记录异常",e); // } /* 查询(客户数据清洗)不合作客户所有记录 */ // log.info("查询(客户数据清洗)不合作客户所有记录"); // List uncooperativeSeaCustomerData = new ArrayList<>(); // try { // uncooperativeSeaCustomerData = yidaService.querySys1Sys2UncooperativeCustomerData(); // } catch (Exception e) { // log.error("查询(客户数据清洗)不合作客户所有记录异常",e); // } /* 比对私海客户(客户名称去空格后转大写) 匹配成功则更新 */ // String customerName1; // String customerName1UpperCase; // String businessUserId; // String customerName2; // String customerName2UpperCase; // String businessUserId2; // String formInstId; // for(Map privateSeaCustomerRecord : privateSeaCustomerData){ // customerName1 = UtilMap.getString(privateSeaCustomerRecord, "customerName"); // customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); // businessUserId = UtilMap.getString(privateSeaCustomerRecord, "businessUserId"); // for (int i = 0; i < ltcCustomerData.size(); i++) { // customerName2 = UtilMap.getString(ltcCustomerData.get(i), "customerName"); // customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); // businessUserId2 = UtilMap.getString(ltcCustomerData.get(i), "userId"); //// formInstId = UtilMap.getString(ltcCustomerData.get(i), "formInstId"); // if(customerName1UpperCase.equals(customerName2UpperCase)){ // /* // 客户名称(大写)一致,更新易思达系统客户基本信息(客户公司名、业务、公海/私海、测试使用) // */ //// try { //// yidaService.updateLtcCustomerBasicInfo(formInstId,customerName1,businessUserId,"私","否"); //// } catch (Exception e) { //// log.error("更新易思达系统客户基本信息异常",e); //// } // // if(businessUserId==null || businessUserId.isEmpty()){ // if(businessUserId2==null || businessUserId2.isEmpty()){ // //两边一致 // }else{ // System.out.println("两边不一致:"+customerName1); // } // }else{ // if(businessUserId2==null || businessUserId2.isEmpty()){ // System.out.println("两边不一致:"+customerName1); // }else{ // if(businessUserId.equals(businessUserId2)){ // //两边一致 // }else{ // System.out.println("两边不一致:"+customerName1); // } // } // } // // break; // } // } // } /* 比对私海客户(客户名称去空格后转大写) 未匹配到则新增 */ // String customerName1; // String customerName1UpperCase; // String customerName2; // String customerName2UpperCase; // boolean isNew; // for (Map privateSeaCustomerRecord : privateSeaCustomerData){ // isNew = true; // customerName1 = UtilMap.getString(privateSeaCustomerRecord, "customerName"); // customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); // for (int i = 0; i < ltcCustomerData.size(); i++){ // customerName2 = UtilMap.getString(ltcCustomerData.get(i), "customerName"); // customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); // if(customerName1UpperCase.equals(customerName2UpperCase)){ // isNew = false; // break; // } // } // if(isNew){ // /* // 是新客户,新增易思达系统客户记录 // */ // privateSeaCustomerRecord.put("seaType","私"); // privateSeaCustomerRecord.put("newOrOld","新"); // privateSeaCustomerRecord.put("testUseFlag","否"); // try { // yidaService.insertCustomerData(privateSeaCustomerRecord); // } catch (Exception e) { // log.error("新增易思达系统客户记录异常",e); // } // } // } /* 比对公海客户(客户名称去空格后转大写) */ // String customerName1; // String customerName1UpperCase; // String businessUserId; // String customerName2; // String customerName2UpperCase; // String businessUserId2; // String formInstId; // for(Map publicSeaCustomerRecord : publicSeaCustomerData){ // customerName1 = UtilMap.getString(publicSeaCustomerRecord, "customerName"); // customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); // businessUserId = UtilMap.getString(publicSeaCustomerRecord, "businessUserId"); // for (int i = 0; i < ltcCustomerData.size(); i++) { // customerName2 = UtilMap.getString(ltcCustomerData.get(i), "customerName"); // customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); // businessUserId2 = UtilMap.getString(ltcCustomerData.get(i), "userId"); //// formInstId = UtilMap.getString(ltcCustomerData.get(i), "formInstId"); // if(customerName1UpperCase.equals(customerName2UpperCase)){ // /* // 客户名称(大写)一致,更新易思达系统客户基本信息(客户公司名、业务、公海/私海、测试使用) // */ //// try { //// yidaService.updateLtcCustomerBasicInfo(formInstId,customerName1,null,"公","否"); //// } catch (Exception e) { //// log.error("更新易思达系统客户基本信息异常",e); //// } // if(businessUserId==null || businessUserId.isEmpty()){ // if(businessUserId2==null || businessUserId2.isEmpty()){ // //两边一致 // }else{ // System.out.println("两边不一致:"+customerName1); // } // }else{ // if(businessUserId2==null || businessUserId2.isEmpty()){ // System.out.println("两边不一致:"+customerName1); // }else{ // if(businessUserId.equals(businessUserId2)){ // //两边一致 // }else{ // System.out.println("两边不一致:"+customerName1); // } // } // } // break; // } // } // } /* 比对公海客户(客户名称去空格后转大写) 未匹配到则新增 */ // String customerName1; // String customerName1UpperCase; // String customerName2; // String customerName2UpperCase; // boolean isNew; // for (Map publicSeaCustomerRecord : publicSeaCustomerData){ // isNew = true; // customerName1 = UtilMap.getString(publicSeaCustomerRecord, "customerName"); // customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); // for (int i = 0; i < ltcCustomerData.size(); i++){ // customerName2 = UtilMap.getString(ltcCustomerData.get(i), "customerName"); // customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); // if(customerName1UpperCase.equals(customerName2UpperCase)){ // isNew = false; // break; // } // } // if(isNew){ // /* // 是新客户,新增易思达系统客户记录 // */ // publicSeaCustomerRecord.put("seaType","公"); // publicSeaCustomerRecord.put("businessUserId",null); // publicSeaCustomerRecord.put("newOrOld","新"); // publicSeaCustomerRecord.put("testUseFlag","否"); // try { // yidaService.insertCustomerData(publicSeaCustomerRecord); // } catch (Exception e) { // log.error("新增易思达系统客户记录异常",e); // } // } // } /* 比对不合作客户(客户名称去空格后转大写) */ // String customerName1; // String customerName1UpperCase; // String businessUserId; // String customerName2; // String customerName2UpperCase; // String businessUserId2; // String formInstId; // for(Map uncooperativeSeaCustomerRecord : uncooperativeSeaCustomerData){ // customerName1 = UtilMap.getString(uncooperativeSeaCustomerRecord, "customerName"); // customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); // businessUserId = UtilMap.getString(uncooperativeSeaCustomerRecord, "businessUserId"); // for (int i = 0; i < ltcCustomerData.size(); i++) { // customerName2 = UtilMap.getString(ltcCustomerData.get(i), "customerName"); // customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); // businessUserId2 = UtilMap.getString(ltcCustomerData.get(i), "userId"); //// formInstId = UtilMap.getString(ltcCustomerData.get(i), "formInstId"); // if(customerName1UpperCase.equals(customerName2UpperCase)){ // /* // 客户名称(大写)一致,更新易思达系统客户基本信息(客户公司名、业务、公海/私海、测试使用) // */ //// try { //// yidaService.updateLtcCustomerBasicInfo2(formInstId,customerName1,null,"公","不合作","否"); //// } catch (Exception e) { //// log.error("更新易思达系统客户基本信息异常",e); //// } // if(businessUserId==null || businessUserId.isEmpty()){ // if(businessUserId2==null || businessUserId2.isEmpty()){ // //两边一致 // }else{ // System.out.println("两边不一致:"+customerName1); // } // }else{ // if(businessUserId2==null || businessUserId2.isEmpty()){ // System.out.println("两边不一致:"+customerName1); // }else{ // if(businessUserId.equals(businessUserId2)){ // //两边一致 // }else{ // System.out.println("两边不一致:"+customerName1); // } // } // } // break; // } // } // } /* 比对不合作客户(客户名称去空格后转大写) 未匹配到则新增 */ // String customerName1; // String customerName1UpperCase; // String customerName2; // String customerName2UpperCase; // boolean isNew; // for (Map uncooperativeSeaCustomerRecord : uncooperativeSeaCustomerData){ // isNew = true; // customerName1 = UtilMap.getString(uncooperativeSeaCustomerRecord, "customerName"); // customerName1UpperCase = customerName1.replaceAll(" ","").toUpperCase(); // for (int i = 0; i < ltcCustomerData.size(); i++){ // customerName2 = UtilMap.getString(ltcCustomerData.get(i), "customerName"); // customerName2UpperCase = customerName2.replaceAll(" ","").toUpperCase(); // if(customerName1UpperCase.equals(customerName2UpperCase)){ // isNew = false; // break; // } // } // if(isNew){ // /* // 是新客户,新增易思达系统客户记录 // */ // uncooperativeSeaCustomerRecord.put("seaType","公"); // uncooperativeSeaCustomerRecord.put("businessUserId",null); // uncooperativeSeaCustomerRecord.put("newOrOld","不合作"); // uncooperativeSeaCustomerRecord.put("testUseFlag","否"); // try { // yidaService.insertCustomerData(uncooperativeSeaCustomerRecord); // } catch (Exception e) { // log.error("新增易思达系统客户记录异常",e); // } // } // } log.info("同步客户与业务完成"); } /** * 补充客户基本信息 */ // @Scheduled(cron = "0 30 11 * * ?") public void supplementTheCustomerData() { /* 查询(易思达)客户名册所有记录 */ log.info("查询(易思达)客户名册所有记录"); List ltcCustomerData = new ArrayList<>(); try { ltcCustomerData = yidaService.queryLtcAllCustomerData(); } catch (Exception e) { log.error("查询(易思达)客户名册异常",e); } /* 查询业务小组档案中的成员信息 */ List ltcBusinessUserData = new ArrayList<>(); try { ltcBusinessUserData = yidaService.queryLtcAllBusinessUserData(); } catch (Exception e) { log.error("查询业务小组档案中的成员信息异常",e); } /* 更新字段: 客户验重 业务userId 业务组长 是否大客户 */ String formInstId; String customerName; String customerNameUpperCase; String userId; String userIdText; String businessLeaderUserId; for(Map ltcCustomerRecord : ltcCustomerData){ customerName = UtilMap.getString(ltcCustomerRecord, "customerName"); customerNameUpperCase = customerName.replaceAll(" ","").toUpperCase(); userId = UtilMap.getString(ltcCustomerRecord, "userId"); userIdText = UtilMap.getString(ltcCustomerRecord, "userIdText"); businessLeaderUserId = null; // for (int i = 0; i < ltcBusinessUserData.size(); i++) { // if(UtilMap.getString(ltcBusinessUserData.get(i), "userId").equals(userId)){ // businessLeaderUserId = UtilMap.getString(ltcBusinessUserData.get(i), "businessLeaderUserId"); // if(businessLeaderUserId.isEmpty()){ // businessLeaderUserId = null; // } // break; // } // } try { System.out.println(customerName); formInstId = UtilMap.getString(ltcCustomerRecord, "formInstId"); // yidaService.updateLtcCustomerBasicInfo3(formInstId,customerNameUpperCase,userId,businessLeaderUserId,"否"); yidaService.updateLtcCustomerBasicInfo4(formInstId,"","",null,null); } catch (Exception e) { log.error("更新易思达系统客户记录异常",e); } } log.info("补充客户基本信息完成"); } }