diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/Enum/ProductClassEnum.java b/magic-boot/src/main/java/org/ssssssss/magicboot/Enum/ProductClassEnum.java index b2284eb..6b7ace5 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/Enum/ProductClassEnum.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/Enum/ProductClassEnum.java @@ -4,15 +4,18 @@ import java.util.HashMap; import java.util.Map; public enum ProductClassEnum { - 核算提取("1"), - PCR("2"), - 克隆及电泳("3"), + 核酸提取系列("1"), + PCR系列("2"), + 克隆及电泳系列("3"), 免疫学("4"), 细胞生物学("5"), 小分子化学物("6"), 耗材("7"), 仪器设备("8"), - 医疗器械("9"); + 医疗器械("9"), + WG实验服务("10"), + 实验服务("11"), + Thermo赛默飞("12"); private final String value; diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CustomerController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CustomerController.java index dda02bc..9e6d3be 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CustomerController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CustomerController.java @@ -79,6 +79,72 @@ public class CustomerController { String customerName = customerData.getString("name"); String modifyTime = customerData.getString("last_modified_time"); + //根据客户名称查询ERP中是否已经存在重名数据 + Map getYSCustomerMap = new HashMap(); + getYSCustomerMap.put("name", customerName); + getYSCustomerMap.put("pageSize", 10); + getYSCustomerMap.put("pageIndex", 1); + + //开始获取token + String ysToken = ""; + + try { + ysToken = new YSSignUtils().getYSToken(); + } catch (Exception e) { + e.printStackTrace(); + } + + String getCustomerByNameURL = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/merchant/newlist?access_token=" + ysToken; + + JSONObject erpCustomerRes = new JSONObject(); + + try { + erpCustomerRes = restTemplate.postForObject(getCustomerByNameURL, getYSCustomerMap, JSONObject.class); + } catch (HttpStatusCodeException e) { + // 获取响应体的错误信息 + String errorBody = e.getResponseBodyAsString(); + System.out.println("调用接口失败,状态码:" + e.getStatusCode()); + System.out.println("错误响应:" + errorBody); + + // 将错误响应封装为 JSONObject(可选) + erpCustomerRes = JSONObject.parseObject(errorBody); + } catch (RestClientException e) { + System.out.println("调用接口失败:" + e.getMessage()); + } + + if ("200".equals(erpCustomerRes.getString("code")) && !erpCustomerRes.getJSONArray("data").isEmpty()) { + log.info("ERP中已经存在重名数据,将不再继续向下执行"); + + JSONObject erpCustomerData = erpCustomerRes.getJSONArray("data").getJSONObject(0); + + String erpCustomerId = erpCustomerData.getString("id"); + + String erpCustomerCode = erpCustomerData.getString("code"); + + //开始封装回写数据 + Map backReqMap = new HashMap(); + backReqMap.put("_id", customerId); + backReqMap.put("dataObjectApiName", "AccountObj"); + backReqMap.put("customer_code__c", erpCustomerCode); + backReqMap.put("ERP_ID__c", erpCustomerId); + backReqMap.put("response_status__c", "同步成功"); + backReqMap.put("sync_status__c", "option_sync_success__c"); + + JSONObject updateCustomerReq = crmRequestUtil.updateCRM(backReqMap); + + JSONObject updateCustomerRes = new JSONObject(); + + try { + updateCustomerRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, updateCustomerReq, JSONObject.class); + } catch (RestClientException e) { + e.printStackTrace(); + } + + System.out.println("客户更新状态为:" + updateCustomerRes); + + continue; + } + //开始判断是否存在当前数据 JSONObject isLogRes = new JSONObject(); @@ -93,7 +159,6 @@ public class CustomerController { continue; } - log.info("日志不存在,将继续向下执行"); log.info("日志不存在,将继续向下执行"); //开始封装和处理数据 @@ -123,20 +188,23 @@ public class CustomerController { //营销伙伴-默认 是 customerReq.put("merchantRole.merchantOptions", true); //管理组织 - String orgCode = customerData.getString("management_organization__c") != null ? customerData.getString("management_organization__c") : ""; +// String orgCode = customerData.getString("management_organization__c") != null ? customerData.getString("management_organization__c") : ""; +// +// if (orgCode.equals("")) { +// log.info("管理组织为空,将不再继续向下执行"); +// continue; +// } - if (orgCode.equals("")) { - log.info("管理组织为空,将不再继续向下执行"); - continue; - } - - customerReq.put("createOrgCode", orgCode); + customerReq.put("createOrgCode", "HSJT"); //客户编码 customerReq.put("code", customerData.getString("account_no")); //客户名称 - customerReq.put("name", Maps.of("simplifiedName", customerName)); + Map simplifiedName = new HashMap<>(); + simplifiedName.put("simplifiedName", customerName); + + customerReq.put("name", simplifiedName); //客户简称 - customerReq.put("shortname", Maps.of("simplifiedName", customerData.getString("client_short_name__c") != null ? customerData.getString("client_short_name__c") : customerName)); + customerReq.put("shortname", simplifiedName); //地址信息 //截取CRM中的详细地址 String province = customerData.getString("province") != null ? customerData.getString("province") : ""; @@ -146,30 +214,46 @@ public class CustomerController { String addressStr = province + city + district + address; - customerReq.put("address", Maps.of("simplifiedName", addressStr)); + Map addressMap = new HashMap<>(); + addressMap.put("address", addressStr); + addressMap.put("addressCode", customerData.getString("postal_code__c") != null ? customerData.getString("postal_code__c") : "250000"); + addressMap.put("isDefault", true); + + customerReq.put("merchantAddressInfos", Arrays.asList(addressMap)); + + //联系人信息 + Map merchantContactInfos = new HashMap<>(); + + Map fullName = new HashMap<>(); + fullName.put("simplifiedName", customerName); + + merchantContactInfos.put("fullName", fullName); + merchantContactInfos.put("isDefault", true); + merchantContactInfos.put("mobile", customerData.getString("tel") != null ? customerData.getString("tel") : ""); + merchantContactInfos.put("areaCodeMobile", "+86-" + customerData.getString("tel") != null ? customerData.getString("tel") : ""); + merchantContactInfos.put("email", customerData.getString("email") != null ? customerData.getString("email") : ""); + + customerReq.put("merchantContactInfos", Arrays.asList(merchantContactInfos)); //发票信息 Map invoiceMap = new HashMap<>(); invoiceMap.put("title", "11233221121");//发票抬头 invoiceMap.put("taxNo", "");//发票信息 - invoiceMap.put("address", "");//发票地址 + + Map invoiceAddress = new HashMap<>(); + invoiceAddress.put("simplifiedName", ""); + + invoiceMap.put("address", invoiceAddress);//发票地址 invoiceMap.put("bankName_Name", "");//银行网点 invoiceMap.put("bankAccount", "");//银行账号 invoiceMap.put("isDefault", true);//默认 - customerReq.put("invoice", invoiceMap); + customerReq.put("merchantAgentInvoiceInfos", Arrays.asList(invoiceMap)); Map customerMap = new HashMap<>(); customerMap.put("data", Arrays.asList(customerReq)); - //开始获取token - String ysToken = ""; - - try { - ysToken = new YSSignUtils().getYSToken(); - } catch (Exception e) { - e.printStackTrace(); - } + System.out.println(JSON.parse(JSON.toJSONString(customerMap))); //开始封装请求url String url = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/merchant/integration/newbatchsave?access_token=" + ysToken; @@ -210,7 +294,7 @@ public class CustomerController { logMap.put("tableName", "send_log_khxx"); //判断是否执行成功 - if ("200".equals(customerYSRes.getString("code"))) { + if ("200".equals(customerYSRes.getString("code")) && customerYSRes.getJSONArray("data").getJSONObject(0).getInteger("successCount") > 0) { log.info("同步成功"); logMap.put("log_status", "0"); logMap.put("res_body", "同步成功"); @@ -225,6 +309,7 @@ public class CustomerController { logMap.put("log_status", "1"); logMap.put("res_body", "同步失败:" + customerYSRes.getString("message") != null ? customerYSRes.getString("message") : "同步失败,未知原因"); backReqMap.put("sync_status__c", "option_sync_failed__c"); + backReqMap.put("response_status__c", customerYSRes.getString("message") != null ? customerYSRes.getString("message") : "同步失败,未知原因"); } @@ -313,6 +398,73 @@ public class CustomerController { String customerId = customerData.getString("_id"); String customerName = customerData.getString("name"); String modifyTime = customerData.getString("last_modified_time"); + String customerCode = customerData.getString("contact_id__c"); + + //根据客户名称查询ERP中是否已经存在重名数据 + Map getYSCustomerMap = new HashMap(); + getYSCustomerMap.put("name", customerName); + getYSCustomerMap.put("pageSize", 10); + getYSCustomerMap.put("pageIndex", 1); + + //开始获取token + String ysToken = ""; + + try { + ysToken = new YSSignUtils().getYSToken(); + } catch (Exception e) { + e.printStackTrace(); + } + + String getCustomerByNameURL = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/merchant/newlist?access_token=" + ysToken; + + JSONObject erpCustomerRes = new JSONObject(); + + try { + erpCustomerRes = restTemplate.postForObject(getCustomerByNameURL, getYSCustomerMap, JSONObject.class); + } catch (HttpStatusCodeException e) { + // 获取响应体的错误信息 + String errorBody = e.getResponseBodyAsString(); + System.out.println("调用接口失败,状态码:" + e.getStatusCode()); + System.out.println("错误响应:" + errorBody); + + // 将错误响应封装为 JSONObject(可选) + erpCustomerRes = JSONObject.parseObject(errorBody); + } catch (RestClientException e) { + System.out.println("调用接口失败:" + e.getMessage()); + } + + if ("200".equals(erpCustomerRes.getString("code")) && !erpCustomerRes.getJSONArray("data").isEmpty()) { + log.info("ERP中已经存在重名数据,将不再继续向下执行"); + + JSONObject erpCustomerData = erpCustomerRes.getJSONArray("data").getJSONObject(0); + + String erpCustomerId = erpCustomerData.getString("id"); + + String erpCustomerCode = erpCustomerData.getString("code"); + + //开始封装回写数据 + Map backReqMap = new HashMap(); + backReqMap.put("_id", customerId); + backReqMap.put("dataObjectApiName", "ContactObj"); + backReqMap.put("contact_code__c", erpCustomerCode); + backReqMap.put("erp_id__c", erpCustomerId); + backReqMap.put("response_status__c", "同步成功"); + backReqMap.put("sync_status__c", "option_sync_success__c"); + + JSONObject updateCustomerReq = crmRequestUtil.updateCRM(backReqMap); + + JSONObject updateCustomerRes = new JSONObject(); + + try { + updateCustomerRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, updateCustomerReq, JSONObject.class); + } catch (RestClientException e) { + e.printStackTrace(); + } + + System.out.println("客户更新状态为:" + updateCustomerRes); + + continue; + } //开始查询当前数据是否已经同步过 JSONObject isLogRes = new JSONObject(); @@ -332,8 +484,8 @@ public class CustomerController { //开始封装数据 Map contactMap = new HashMap<>(); + contactMap.put("sourceUnique", customerCode); contactMap.put("enterpriseNature", 0); - contactMap.put("sourceUnique", customerData.getString("contact_id__c")); contactMap.put("transTypeCode", "SYCSR001");//客户类型-通用 //开始获取客户分类 @@ -347,8 +499,8 @@ public class CustomerController { //枚举类获取客户分类编码 String customerCategoryName = AccountCategoryEnum.getValueByName(contactCategory); - contactMap.put("customerClass_Name", customerCategoryName);//客户分类 - contactMap.put("customerClassCode", customerCategoryName);//客户分类 + contactMap.put("customerClass_Name", "KH09");//客户分类 + contactMap.put("customerClassCode", "KH09");//客户分类 //纳税类别 contactMap.put("taxPayingCategories", 0); @@ -358,13 +510,17 @@ public class CustomerController { contactMap.put("merchantRole.merchantOptions", true); //管理组织 - contactMap.put("createOrgCode", customerData.getString("management_organization__c") != null ? customerData.getString("management_organization__c") : ""); + contactMap.put("createOrgCode", "HSJT"); //客户编码 - contactMap.put("code", customerData.getString("contact_id__c")); + contactMap.put("code", customerCode); //客户名称 - contactMap.put("name", customerData.getString("name")); + Map nameMap = new HashMap<>(); + nameMap.put("simplifiedName", customerData.getString("name")); + contactMap.put("name", nameMap); //客户简称 - contactMap.put("shortname", customerData.getString("name")); + Map shortnameMap = new HashMap<>(); + shortnameMap.put("simplifiedName", customerData.getString("name")); + contactMap.put("shortname", shortnameMap); //上级客户 contactMap.put("parentCustomerCode", customerData.getString("parent_customer_code__c") != null ? customerData.getString("parent_customer_code__c") : ""); //todo 专营业务员(还没有集成) @@ -388,80 +544,62 @@ public class CustomerController { if ("success".equals(salesManRes.getString("errorDescription")) && !salesManRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { JSONObject salesManData = salesManRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); - salesManId = salesManData.getString("erp_code__c") != null ? salesManData.getString("erp_code__c") : ""; + salesManId = salesManData.getString("erp_id__c") != null ? salesManData.getString("erp_id__c") : ""; } + Map saleManMap = new HashMap<>(); + saleManMap.put("professSalesmanId", salesManId); + saleManMap.put("isDefault", true); + //专管业务员 - contactMap.put("professSalesmanCode", salesManId); + contactMap.put("principals", Arrays.asList(saleManMap)); - //todo 科室名(暂未集成) - String departmentName = customerData.getString("institute_department__c") != null ? customerData.getString("institute_department__c") : ""; + //科室名 + Map merchantCharacter = new HashMap<>(); - JSONObject getDepartment = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "_id", Arrays.asList(departmentName)) - ), "department_institute__c"); - - JSONObject departmentRes = new JSONObject(); - - try { - departmentRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDepartment, JSONObject.class); - } catch (RestClientException e) { - e.printStackTrace(); - } - - String departmentCode = ""; - - if ("success".equals(departmentRes.getString("errorDescription")) && !departmentRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { - JSONObject departmentData = departmentRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); - departmentCode = departmentData.getString("erp_code__c") != null ? departmentData.getString("erp_code__c") : ""; - } + String departmentId = customerData.getString("department_institution_erp__c") != null ? customerData.getString("department_institution_erp__c") : ""; //科室 - contactMap.put("merchantCharacter__Y005", departmentCode); + merchantCharacter.put("KSYS01", departmentId); //课题组 - String projectGroupName = customerData.getString("research_group_name__c") != null ? customerData.getString("research_group_name__c") : ""; - - JSONObject getProjectGroup = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "_id", Arrays.asList(projectGroupName)) - ), "topic_group__c"); - - JSONObject projectGroupRes = new JSONObject(); - - try { - projectGroupRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProjectGroup, JSONObject.class); - } catch (RestClientException e) { - e.printStackTrace(); - } - - String projectGroupCode = ""; - - if ("success".equals(projectGroupRes.getString("errorDescription")) && !projectGroupRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { - JSONObject projectGroupData = projectGroupRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); - projectGroupCode = projectGroupData.getString("erp_code__c") != null ? projectGroupData.getString("erp_code__c") : ""; - } + String projectGroupId = customerData.getString("topic_group_erpid__c") != null ? customerData.getString("topic_group_erpid__c") : ""; //课题组 - contactMap.put("merchantCharacter__K0003", projectGroupCode); + merchantCharacter.put("KTZ001", projectGroupId); + + contactMap.put("merchantCharacter", merchantCharacter); //联系人信息 + Map merchantContactInfos = new HashMap<>(); + Map fullName = new HashMap<>(); fullName.put("simplifiedName", customerName); - contactMap.put("fullName", fullName); - contactMap.put("mobile", customerData.getString("mobile1") != null ? customerData.getString("mobile1") : ""); + + merchantContactInfos.put("fullName", fullName); + merchantContactInfos.put("isDefault", true); + merchantContactInfos.put("areaCodeMobile", "+86-" + customerData.getString("mobile1") != null ? customerData.getString("mobile1") : ""); + merchantContactInfos.put("mobile", customerData.getString("mobile1") != null ? customerData.getString("mobile1") : ""); + + contactMap.put("merchantContactInfos", Arrays.asList(merchantContactInfos)); + //发票信息 + Map invoiceMap = new HashMap<>(); + invoiceMap.put("title", "11233221121");//发票抬头 + invoiceMap.put("taxNo", "");//发票信息 + + Map invoiceAddress = new HashMap<>(); + invoiceAddress.put("simplifiedName", "");//发票地址 + + invoiceMap.put("address", invoiceAddress); + invoiceMap.put("bankName", "");//银行网点 + invoiceMap.put("bankAccount", "");//银行账号 + invoiceMap.put("isDefault", true);//默认 + + contactMap.put("merchantAgentInvoiceInfos", Arrays.asList(invoiceMap)); Map customerMap = new HashMap<>(); customerMap.put("data", Arrays.asList(contactMap)); System.out.println(JSON.parseObject(JSON.toJSONString(customerMap))); - //开始获取token - String ysToken = ""; - - try { - ysToken = new YSSignUtils().getYSToken(); - } catch (Exception e) { - e.printStackTrace(); - } - //开始封装请求url String url = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/merchant/integration/newbatchsave?access_token=" + ysToken; diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/DeptController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/DeptController.java index 58274ef..71dfa07 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/DeptController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/DeptController.java @@ -14,10 +14,7 @@ import org.ssssssss.magicboot.entity.Filter; import org.ssssssss.magicboot.utils.CrmRequestUtil; import org.ssssssss.magicboot.utils.YSSignUtils; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * 部门 @@ -51,12 +48,12 @@ public class DeptController { log.info("开始同步部门"); Map getDeptReq = new HashMap(); - getDeptReq.put("parentId", "2132046702701969413"); + getDeptReq.put("parentId", "2163138383273525256"); getDeptReq.put("pageSize", 100); getDeptReq.put("pageIndex", 1); getDeptReq.put("externalOrg", 0); getDeptReq.put("sourceType", 1); - getDeptReq.put("codes", Arrays.asList("SKJ-BM04")); + getDeptReq.put("codes", Arrays.asList("SKJ-BM12.03")); getDeptReq.put("dr", 0); getDeptReq.put("funcTypeCode", "orgunit"); @@ -130,7 +127,7 @@ public class DeptController { //开始封装请求 Map deptMapReq = new HashMap<>(); //部门编码 - deptMapReq.put("dept_code", deptData.getString("code")); + deptMapReq.put("dept_code", deptData.getString("code").replace("SKJ-", "")); //部门名称 deptMapReq.put("name", deptData.getString("name")); //部门简称 @@ -144,9 +141,15 @@ public class DeptController { //获取当前处理单据地等级 String pid = "999999"; String parentId = ""; + String departmentOwner = ""; + + if ("2163138383273525256".equals(deptId)){ + log.info("当前处理部门为最上级部门"); + continue; + } //判断级别,如果是2,则是思科捷最上级,如果不是2则是下级 - if (!deptId.equals("2132046702701969413")) { + if (!deptId.equals("2163138383273525256")) { //级别小于2,则获取上级部门 //需要获取一下详情以拿到上级部门ID JSONObject getDeptSuperior = new JSONObject(); @@ -176,33 +179,66 @@ public class DeptController { parentId = getDeptSuperior.getJSONObject("data").getString("parent"); - JSONObject getPid = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "erp_id__c", Arrays.asList(parentId)), - new Filter("EQ", "life_status", Arrays.asList("normal")) - ), "DepartmentObj"); + departmentOwner = getDeptSuperior.getJSONObject("data").getString("principal_name"); - JSONObject getPidRes = new JSONObject(); + if (parentId.equals("2163138383273525256")) { + pid = "999999"; + } else { + JSONObject getPid = crmRequestUtil.getCRMList(Arrays.asList( + new Filter("EQ", "erp_id__c", Arrays.asList(parentId)), + new Filter("EQ", "life_status", Arrays.asList("normal")) + ), "DepartmentObj"); - try { - getPidRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getPid, JSONObject.class); - } catch (RestClientException e) { - e.printStackTrace(); + JSONObject getPidRes = new JSONObject(); + + try { + getPidRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getPid, JSONObject.class); + } catch (RestClientException e) { + e.printStackTrace(); + } + + if (!"success".equals(getPidRes.getString("errorDescription")) || getPidRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { + log.info("上级部门不存在"); + continue; + } + pid = getPidRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"); } - - if (!"success".equals(getPidRes.getString("errorDescription")) || getPidRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { - log.info("上级部门不存在"); - continue; - } - pid = getPidRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"); } deptMapReq.put("parent_id", Arrays.asList(pid)); deptMapReq.put("field_1aF2M__c", parentId); + + //开始查询部门负责人 + JSONObject getOwner = crmRequestUtil.getCRMList(Arrays.asList( + new Filter("EQ", "name", Arrays.asList(departmentOwner)), + new Filter("EQ", "life_status", Arrays.asList("normal")) + ), "PersonnelObj"); + + JSONObject getOwnerRes = new JSONObject(); + + try { + getOwnerRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getOwner, JSONObject.class); + } catch (RestClientException e) { + e.printStackTrace(); + } + + List ownerList = new ArrayList(); + + if ("success".equals(getOwnerRes.getString("errorDescription")) && !getOwnerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { + JSONObject ownerData = getOwnerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); + + String ownerUserId = ownerData.getString("user_id"); + + ownerList = Arrays.asList(ownerUserId); + } + + deptMapReq.put("manager_id", ownerList); + deptMapReq.put("dataObjectApiName", "DepartmentObj"); //开始查询是否已经存在重名部门 JSONObject getDept = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "name", Arrays.asList(deptName)), + new Filter("EQ", "erp_id__c", Arrays.asList(deptId)), new Filter("EQ", "life_status", Arrays.asList("normal")) ), "DepartmentObj"); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/InstituteController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/InstituteController.java index 07132f9..e1965ac 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/InstituteController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/InstituteController.java @@ -100,8 +100,8 @@ public class InstituteController { //开始封装数据 Map institute = new HashMap<>(); - institute.put("sourceUnique", "2267063578082148361"); - institute.put("custdocdefid", "2157208682701520904"); + institute.put("sourceUnique", "2173701348530847754"); + institute.put("custdocdefid", "2163884255875694593"); institute.put("code", instituteData.getString("department_institution_id__c")); //名称 @@ -138,6 +138,8 @@ public class InstituteController { request.put("unmatchedStrategy", "add"); request.put("data", Arrays.asList(institute)); + System.out.println(JSON.parseObject(JSON.toJSONString(request))); + //开始获取token String ysToken = ""; @@ -186,13 +188,54 @@ public class InstituteController { logMap.put("tableName", "send_log_khxx"); //判断是否执行成功 - if ("200".equals(instituteYSRes.getString("code"))) { + if ("200".equals(instituteYSRes.getString("code")) && instituteYSRes.getJSONObject("data").getInteger("successCount") > 0) { log.info("同步成功"); logMap.put("log_status", "0"); logMap.put("res_body", "同步成功"); //获取ERPID JSONObject erpMap = instituteYSRes.getJSONObject("data").getJSONArray("infos").getJSONObject(0); + + //获取ERPID + String erpId = erpMap.getString("id"); + + //根据erpId查询erp编码 + Map erpCodeMap = new HashMap<>(); + erpCodeMap.put("ids", Arrays.asList(erpId)); + erpCodeMap.put("custdocdefid", "2163884255875694593"); + erpCodeMap.put("pageIndex", 1); + erpCodeMap.put("pageSize", 10); + + System.out.println(JSON.parse(JSON.toJSONString(erpCodeMap))); + + //开始发起请求 + String getCodeUrl = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/customerdoc/batchQueryDetail?access_token=" + ysToken; + + JSONObject erpCodeRes = new JSONObject(); + + try { + erpCodeRes = restTemplate.postForObject(getCodeUrl, erpCodeMap, JSONObject.class); + } catch (HttpStatusCodeException e) { + // 获取响应体的错误信息 + String errorBody = e.getResponseBodyAsString(); + System.out.println("调用接口失败,状态码:" + e.getStatusCode()); + System.out.println("错误响应:" + errorBody); + + // 将错误响应封装为 JSONObject(可选) + erpCodeRes = JSONObject.parseObject(errorBody); + } catch (RestClientException e) { + System.out.println("调用接口失败:" + e.getMessage()); + } + + System.out.println(erpCodeRes); + + if ("200".equals(erpCodeRes.getString("code")) && !erpCodeRes.getJSONObject("data").getJSONArray("recordList").isEmpty()) { + //开始获取当前单据的编码 + JSONObject erpCodeData = erpCodeRes.getJSONObject("data").getJSONArray("recordList").getJSONObject(0); + + backReqMap.put("field_h57mR__c", erpCodeData.getString("code")); + } + backReqMap.put("field_eO8gK__c", erpMap.getString("id")); backReqMap.put("sync_status__c", "option_sync_success__c"); backReqMap.put("response_status__c", "同步成功"); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/PersonController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/PersonController.java index 2c0ad43..caf26ad 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/PersonController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/PersonController.java @@ -50,14 +50,15 @@ public class PersonController { //开始封装请求参数 LinkedHashMap getPersonReq = new LinkedHashMap<>(); getPersonReq.put("pageIndex", 1); - getPersonReq.put("pageSize", 1); + getPersonReq.put("pageSize", 300); getPersonReq.put("objid", ""); getPersonReq.put("name", ""); getPersonReq.put("mobile", ""); getPersonReq.put("email", ""); - getPersonReq.put("orgIds", Arrays.asList("2132046702701969413")); + getPersonReq.put("orgIds", Arrays.asList()); getPersonReq.put("userId", ""); getPersonReq.put("pubts", ""); + getPersonReq.put("unit_id", "2163138383273525256"); //getPersonReq.put("enable", Arrays.asList(0)); System.out.println("人员列表请求参数为:" + JSON.toJSONString(getPersonReq)); @@ -92,7 +93,7 @@ public class PersonController { System.out.println("调用接口失败:" + e.getMessage()); } - System.out.println(personRes); + //System.out.println(personRes); if (!"200".equals(personRes.getString("code")) || personRes.getJSONObject("data").getJSONArray("recordList").isEmpty()) { log.info("erp请求产品失败或者没有符合条件的数据"); @@ -111,9 +112,10 @@ public class PersonController { String personName = personData.getString("name"); String modifyTime = personData.getString("modifiedtime"); - Integer dr = personData.getInteger("dr"); + String orgId = personData.getString("unit_id") != null ? personData.getString("unit_id") : ""; - if (dr == 1) { + if (!"2163138383273525256".equals(orgId)) { + log.info("当前人员不是思科捷组织的员工"); continue; } @@ -138,6 +140,8 @@ public class PersonController { personMapReq.put("dataObjectApiName", "PersonnelObj"); //erp编码 personMapReq.put("erp_code__c", personData.getString("code")); + //员工编号 + personMapReq.put("employee_number", personData.getString("code")); //erpId personMapReq.put("erp_id__c", personId); //系统名 @@ -165,6 +169,20 @@ public class PersonController { personMapReq.put("sex", crmSex); + //员工状态 + String personStatus = personData.getString("enable"); + + //1是正常,0是禁用 + switch (personStatus) { + case "1": + personMapReq.put("status", "0"); + break; + + case "2": + personMapReq.put("status", "1"); + break; + } + //生日 String birthday = personData.getString("birthdate") != null ? personData.getString("birthdate") : ""; @@ -202,8 +220,11 @@ public class PersonController { personMapReq.put("note__c", personData.getString("remark") != null ? personData.getString("remark") : ""); //todo 组织 + //获取主职信息 + JSONObject mainJob = personData.getJSONArray("mainJobList").getJSONObject(0); + //主属部门 - String dept = personData.getString("dept_id") != null ? personData.getString("dept_id") : ""; + String dept = mainJob.getString("dept_id") != null ? mainJob.getString("dept_id") : ""; if ("".equals(dept)) { log.info("部门为空"); @@ -239,9 +260,6 @@ public class PersonController { personMapReq.put("main_department", Arrays.asList(dept_id)); - //获取主职信息 - JSONObject mainJob = personData.getJSONArray("mainJobList").getJSONObject(0); - //职务 String jobStr = mainJob.getString("job_id") != null ? mainJob.getString("job_id") : ""; @@ -289,9 +307,9 @@ public class PersonController { e.printStackTrace(); } - if ("success".equals(getLeaderRes.getString("errorDescription")) && getLeaderRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { + if ("success".equals(getLeaderRes.getString("errorDescription")) && !getLeaderRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { log.info("主管存在"); - String leader_id = getLeaderRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"); + String leader_id = getLeaderRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("user_id"); personMapReq.put("leader", Arrays.asList(leader_id)); } @@ -333,9 +351,11 @@ public class PersonController { e.printStackTrace(); } + System.out.println("人员数据为:" + getPersonFromCRMRes); + Boolean isExist = true; - if ("success".equals(getPersonFromCRMRes.getString("errorDescription")) && getPersonFromCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { + if ("success".equals(getPersonFromCRMRes.getString("errorDescription")) && !getPersonFromCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { log.info("该人员已经存在"); JSONObject personMainReq = getPersonFromCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductCategoryController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductCategoryController.java index 476ccd9..e99ae28 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductCategoryController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductCategoryController.java @@ -66,12 +66,12 @@ public class ProductCategoryController { //开始封装请求 Map getCategoryReq = new HashMap<>(); getCategoryReq.put("pageIndex", 1); - getCategoryReq.put("pageSize", 100); + getCategoryReq.put("pageSize", 500); //getCategoryReq.put("code", "000007"); - getCategoryReq.put("endTime", nowStr); - getCategoryReq.put("beginTime", twoDaysAgoStr); +// getCategoryReq.put("endTime", nowStr); +// getCategoryReq.put("beginTime", twoDaysAgoStr); System.out.println(JSONObject.parseObject(JSON.toJSONString(getCategoryReq))); @@ -123,6 +123,18 @@ public class ProductCategoryController { String categoryCode = categoryData.getString("code"); String categoryName = categoryData.getJSONObject("name").getString("simplifiedName"); + if (categoryCode.length() < 3) { + log.info("产品分类长度小于3,将不再处理"); + continue; + } + + String categoryCodeStr = categoryCode.substring(0, 3); + + if (!categoryCodeStr.equals("A01") && !categoryCodeStr.equals("A02") && !categoryCodeStr.equals("A03") && !categoryCodeStr.equals("B03")) { + log.info("产品分类不符合要求,将不再处理"); + continue; + } + //开始查询是否已经执行过了 JSONObject isLogRes = new JSONObject(); @@ -152,38 +164,43 @@ public class ProductCategoryController { categoryReq.put("category_describe", remark); //判断是否存在上级部门 - String parentCode = categoryData.getString("parent") != null ? categoryData.getString("parent") : ""; + String parentCode = categoryData.getString("parentCode") != null ? categoryData.getString("parentCode") : ""; + String level = categoryData.getString("level") != null ? categoryData.getString("level") : ""; - if (!"".equals(parentCode)) { - log.info("上级部门存在,将查询上级部门"); + if (!"1".equals(level)) { - JSONObject parentCategoryReq = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "erp_id__c", Arrays.asList(parentCode)), - new Filter("EQ", "life_status", Arrays.asList("normal")) - ), "ProductCategoryObj"); + if (!"".equals(parentCode)) { + log.info("上级部门存在,将查询上级部门"); - JSONObject parentCategoryRes = new JSONObject(); + JSONObject parentCategoryReq = crmRequestUtil.getCRMList(Arrays.asList( + new Filter("EQ", "category_code", Arrays.asList(parentCode)), + new Filter("EQ", "life_status", Arrays.asList("normal")) + ), "ProductCategoryObj"); - try { - parentCategoryRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, parentCategoryReq, JSONObject.class); - } catch (RestClientException e) { - e.printStackTrace(); + JSONObject parentCategoryRes = new JSONObject(); + + try { + parentCategoryRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, parentCategoryReq, JSONObject.class); + } catch (RestClientException e) { + e.printStackTrace(); + } + + if ("success".equals(parentCategoryRes.getString("errorDescription")) && !parentCategoryRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { + log.info("上级分类存在"); + JSONObject parentCategoryData = parentCategoryRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); + + categoryReq.put("pid", parentCategoryData.getString("_id")); + } else { + log.info("上级分类不存在,pid直接传空值"); + continue; + } } - if ("success".equals(parentCategoryRes.getString("errorDescription")) && !parentCategoryRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) { - log.info("上级分类存在"); - JSONObject parentCategoryData = parentCategoryRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0); - - categoryReq.put("pid", parentCategoryData.getString("_id")); - } else { - log.info("上级分类不存在,不再向下执行"); - continue; - } } //查询是否已存在当前单据 JSONObject isExist = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "erp_id__c", Arrays.asList(categoryId)), + new Filter("EQ", "category_code", Arrays.asList(categoryCode)), new Filter("EQ", "life_status", Arrays.asList("normal")) ), "ProductCategoryObj"); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductController.java index d82014f..1a79f8d 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProductController.java @@ -77,12 +77,12 @@ public class ProductController { //开始封装请求 Map getProductReq = new HashMap<>(); getProductReq.put("pageIndex", 1); - getProductReq.put("pageSize", 100); + getProductReq.put("pageSize", 10); - getProductReq.put("code", "000008"); + //getProductReq.put("code", "000008"); - getProductReq.put("endTime", nowStr); - getProductReq.put("beginTime", twoDaysAgoStr); +// getProductReq.put("endTime", nowStr); +// getProductReq.put("beginTime", twoDaysAgoStr); System.out.println(JSONObject.parseObject(JSON.toJSONString(getProductReq))); @@ -191,7 +191,7 @@ public class ProductController { product.put("product_category_id", categoryData.getString("_id")); //todo 产品线 - String productLineStr = ""; + String productLineStr = productData.getString("productLineName") != null ? productData.getString("productLineName") : ""; String productLine = ""; if (!productLineStr.equals("")) { @@ -202,12 +202,11 @@ public class ProductController { product.put("product_line", productLine); //品牌 JSONObject productBrand = productData.getJSONObject("productCharacterDef"); - //品牌封装 - product.put("brand_name__c", productBrand.getString("PP0001") != null ? productBrand.getString("PP0001") : ""); + product.put("brand_name__c", productBrand.getString("PP01") != null ? productBrand.getString("PP01") : ""); //todo 产品大类 - String productBigClassStr = ""; + String productBigClassStr = productBrand.getString("CPDL_name") != null ? productBrand.getString("CPDL_name") : ""; String productBigClass = ""; if (!productBigClassStr.equals("")) { @@ -216,7 +215,7 @@ public class ProductController { product.put("product_category__c", productBigClass); //产品标准价格 - product.put("price", productBrand.getBigDecimal("MLJ01") != null ? productBrand.getBigDecimal("MLJ01") : BigDecimal.ZERO); + product.put("price", productBrand.getBigDecimal("MLJ") != null ? productBrand.getBigDecimal("MLJ") : BigDecimal.ZERO); //单位 String unitStr = productData.getString("unitName") != null ? productData.getString("unitName") : ""; diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ResearchGroupController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ResearchGroupController.java index 1af1ab5..29d3507 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ResearchGroupController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ResearchGroupController.java @@ -50,7 +50,7 @@ public class ResearchGroupController { log.info("开始同步课题组"); JSONObject getResearch = crmRequestUtil.getCRMList(Arrays.asList( - new Filter("EQ", "name", Arrays.asList("保护伞课题组")) + new Filter("EQ", "name", Arrays.asList("保护伞T病毒课题组")) ), "topic_group__c"); JSONObject researchRes = new JSONObject(); @@ -95,8 +95,8 @@ public class ResearchGroupController { //开始封装 Map researchMap = new HashMap(); - researchMap.put("sourceUnique", "2141608528251453447"); - researchMap.put("custdocdefid", "2137219552709181445"); + researchMap.put("sourceUnique", "2171495625126313995"); + researchMap.put("custdocdefid", "2163852876860358656"); //编码 researchMap.put("code", researchData.getString("topic_group_code__c") != null ? researchData.getString("topic_group_code__c") : ""); @@ -182,13 +182,54 @@ public class ResearchGroupController { logMap.put("tableName", "send_log_khxx"); //判断是否执行成功 - if ("200".equals(researchYSRes.getString("code"))) { + if ("200".equals(researchYSRes.getString("code")) && researchYSRes.getJSONObject("data").getInteger("successCount") > 0) { log.info("同步成功"); logMap.put("log_status", "0"); logMap.put("res_body", "同步成功"); //获取ERPID JSONObject erpMap = researchYSRes.getJSONObject("data").getJSONArray("infos").getJSONObject(0); + + //获取ERPID + String erpId = erpMap.getString("id"); + + //根据erpId查询erp编码 + Map erpCodeMap = new HashMap<>(); + erpCodeMap.put("ids", Arrays.asList(erpId)); + erpCodeMap.put("custdocdefid", "2163852876860358656"); + erpCodeMap.put("pageIndex", 1); + erpCodeMap.put("pageSize", 10); + + System.out.println(JSON.parse(JSON.toJSONString(erpCodeMap))); + + //开始发起请求 + String getCodeUrl = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/customerdoc/batchQueryDetail?access_token=" + ysToken; + + JSONObject erpCodeRes = new JSONObject(); + + try { + erpCodeRes = restTemplate.postForObject(getCodeUrl, erpCodeMap, JSONObject.class); + } catch (HttpStatusCodeException e) { + // 获取响应体的错误信息 + String errorBody = e.getResponseBodyAsString(); + System.out.println("调用接口失败,状态码:" + e.getStatusCode()); + System.out.println("错误响应:" + errorBody); + + // 将错误响应封装为 JSONObject(可选) + erpCodeRes = JSONObject.parseObject(errorBody); + } catch (RestClientException e) { + System.out.println("调用接口失败:" + e.getMessage()); + } + + System.out.println(erpCodeRes); + + if ("200".equals(erpCodeRes.getString("code")) && !erpCodeRes.getJSONObject("data").getJSONArray("recordList").isEmpty()) { + //开始获取当前单据的编码 + JSONObject erpCodeData = erpCodeRes.getJSONObject("data").getJSONArray("recordList").getJSONObject(0); + + backReqMap.put("topic_group_code__c", erpCodeData.getString("code")); + } + backReqMap.put("erp_id__c", erpMap.getString("id")); backReqMap.put("sync_status__c", "option_sync_success__c"); backReqMap.put("response_status__c", "同步成功"); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/utils/YSSignUtils.java b/magic-boot/src/main/java/org/ssssssss/magicboot/utils/YSSignUtils.java index aad2c89..adb06e1 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/utils/YSSignUtils.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/utils/YSSignUtils.java @@ -24,7 +24,8 @@ public class YSSignUtils { private RestTemplate restTemplate = new RestTemplate(); - private static final String appSecret = "9e14a58b43975fc735adf16cd3570a2e297cf12e"; + //private static final String appSecret = "9e14a58b43975fc735adf16cd3570a2e297cf12e"; + private static final String appSecret = "41978857c894f5ca5e975a6bd0f577f4b0030e05";//正式环境 /** * 用友生成签名方法 @@ -34,7 +35,8 @@ public class YSSignUtils { */ public String sign(long timestamp) throws Exception { Map params = new HashMap<>(); - params.put("appKey", "9f874bdd564543ea96206398c7d07cbf"); +// params.put("appKey", "9f874bdd564543ea96206398c7d07cbf");//测试 + params.put("appKey", "15371aac60ed4feaa7192ba0ab7a2098");//正式 params.put("timestamp", String.valueOf(timestamp)); //排序并拼接参数 @@ -64,6 +66,7 @@ public class YSSignUtils { /** * token获取方法 * 单独构造url防止spring自动编码 + * * @return null * @Author weiloong_zhang */ @@ -89,12 +92,12 @@ public class YSSignUtils { timestamp = Instant.now().toEpochMilli(); log.info("当前时间戳: {}", timestamp); signature = new YSSignUtils().sign(timestamp); - }while (signature.contains("+")); + } while (signature.contains("+")); //构造URL,确保signature不被Spring编码 String ysGetTokenUrl = UriComponentsBuilder .fromHttpUrl("https://c1.yonyoucloud.com/iuap-api-auth/open-auth/selfAppAuth/getAccessToken") - .queryParam("appKey", "9f874bdd564543ea96206398c7d07cbf") + .queryParam("appKey", "15371aac60ed4feaa7192ba0ab7a2098") .queryParam("timestamp", timestamp) .queryParam("signature", "{signature}")//用模板方式绕过自动编码 .build(false) @@ -124,10 +127,11 @@ public class YSSignUtils { } /** - * 防止token失效 - * @return void - * @Author weiloong_zhang - */ + * 防止token失效 + * + * @return void + * @Author weiloong_zhang + */ public void getYSTokenTest() throws Exception { String ysToken = getYSToken();