2025-06-11 13:58:36 +08:00
|
|
|
|
package com.management.controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.management.constant.ERPURLConstant;
|
|
|
|
|
import com.management.constant.URLConstant;
|
|
|
|
|
import com.management.entity.Filter;
|
|
|
|
|
import com.management.utils.CrmRequestUtil;
|
|
|
|
|
import com.management.utils.KingDeeUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.client.RestClientException;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
import java.math.BigDecimal;
|
2025-06-11 13:58:36 +08:00
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设计文件
|
|
|
|
|
*
|
|
|
|
|
* @param
|
|
|
|
|
* @return null
|
|
|
|
|
* @Author weiloong_zhang
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/design")
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class DesignController {
|
|
|
|
|
|
|
|
|
|
private RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
new DesignController().syncDesign();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设计文件同步
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @Author weiloong_zhang
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/sync/designDoc")
|
|
|
|
|
public void syncDesign() {
|
|
|
|
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
|
|
|
|
log.info("开始同步设计文件");
|
|
|
|
|
|
|
|
|
|
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
|
|
|
|
|
|
|
|
|
|
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
//new Filter("IS", "erp_id__c", Arrays.asList("")),
|
|
|
|
|
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
|
|
|
|
|
//new Filter("EQ", "name", Arrays.asList("SJWJ250528-0022")),
|
|
|
|
|
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
|
|
|
|
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
|
|
|
|
), "design_file__c");
|
|
|
|
|
|
|
|
|
|
JSONObject designDocRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
designDocRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDoc, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!"success".equals(designDocRes.getString("errorDescription")) || designDocRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
log.info("查询失败或者不存在符合条件的数据");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("查询成功,继续向下执行");
|
|
|
|
|
|
|
|
|
|
for (Object designDocObj : designDocRes.getJSONObject("data").getJSONArray("dataList")) {
|
|
|
|
|
JSONObject designDocData = JSON.parseObject(JSON.toJSONString(designDocObj));
|
|
|
|
|
|
|
|
|
|
System.out.println("当前正在处理的设计文件数据为:" + designDocData);
|
|
|
|
|
|
|
|
|
|
//当前设计文件的唯一id
|
|
|
|
|
String designDocId = designDocData.getString("_id");
|
|
|
|
|
|
|
|
|
|
//当前单据的编号
|
|
|
|
|
String designDocName = designDocData.getString("name");
|
|
|
|
|
|
|
|
|
|
//当前单据的创建时间
|
|
|
|
|
//String createTime = designDocData.getString("create_time");
|
|
|
|
|
String createTime = designDocData.getString("last_modified_time");
|
|
|
|
|
|
|
|
|
|
//开始查询该单据是否已经集成过
|
|
|
|
|
JSONObject isLog = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
isLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_sjwj&log_type=DF&dataId=" + designDocId + "&mark=" + createTime, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断是否已经执行过
|
|
|
|
|
if (!isLog.getJSONArray("data").isEmpty()) {
|
|
|
|
|
log.info("当前单据已经集成过了,将不再向下执行");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("当前单据没有集成过,将开始向下执行");
|
|
|
|
|
|
|
|
|
|
//开始封装传输至ERP中的请求
|
|
|
|
|
Map erpDesignMap = new HashMap<>();
|
|
|
|
|
erpDesignMap.put("billno", designDocName);//设计文件编号
|
|
|
|
|
|
|
|
|
|
//判断组织编码
|
|
|
|
|
String orgCode = "";
|
|
|
|
|
if (designDocData.getString("erp_organization_sales_con__c__v") != null && !"".equals(designDocData.getString("erp_organization_sales_con__c__v"))) {
|
|
|
|
|
orgCode = designDocData.getString("erp_organization_sales_con__c__v");
|
|
|
|
|
} else if (designDocData.getString("erp_organization_pre_contr__c__v") != null && !"".equals(designDocData.getString("erp_organization_pre_contr__c__v"))) {
|
|
|
|
|
orgCode = designDocData.getString("erp_organization_pre_contr__c__v");
|
|
|
|
|
} else {
|
|
|
|
|
log.info("当前单据没有组织编码,将不再向下执行");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
erpDesignMap.put("org_number", orgCode);//组织编码
|
|
|
|
|
erpDesignMap.put("billtype_number", "pm_requirapplybill_BT_sjwjxf");//单据类型
|
|
|
|
|
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
|
|
|
|
|
|
|
|
|
|
//开始获取单据日期
|
|
|
|
|
long bizTime = designDocData.getLong("document_date__c");
|
|
|
|
|
Date date = new Date(bizTime);
|
|
|
|
|
|
|
|
|
|
erpDesignMap.put("biztime", date);//单据日期
|
|
|
|
|
|
|
|
|
|
//部门编码
|
|
|
|
|
String deptCode = "";
|
|
|
|
|
|
|
|
|
|
List deptIdList = designDocData.getJSONArray("data_own_department");
|
|
|
|
|
|
|
|
|
|
//开始查询部门编码
|
|
|
|
|
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "_id", deptIdList)
|
|
|
|
|
), "DepartmentObj");
|
|
|
|
|
|
|
|
|
|
JSONObject deptRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
|
|
|
|
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//erpDesignMap.put("dept_number", "004");//部门编码
|
|
|
|
|
erpDesignMap.put("dept_number", deptCode);//部门编码
|
|
|
|
|
|
|
|
|
|
//获取负责人编码
|
|
|
|
|
String ownerCode = "";
|
|
|
|
|
|
|
|
|
|
List ownerIdList = designDocData.getJSONArray("owner");
|
|
|
|
|
|
|
|
|
|
System.out.println(ownerIdList);
|
|
|
|
|
|
|
|
|
|
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "user_id", ownerIdList)
|
|
|
|
|
), "PersonnelObj");
|
|
|
|
|
|
|
|
|
|
JSONObject ownerRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("查询负责人结果为:" + ownerRes);
|
|
|
|
|
|
|
|
|
|
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
|
|
|
|
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
|
|
|
|
|
erpDesignMap.put("bizuser_number", ownerCode);//人员编码
|
|
|
|
|
erpDesignMap.put("bizorg_number", orgCode);//采购组织
|
2025-06-13 17:09:43 +08:00
|
|
|
|
erpDesignMap.put("project_number", designDocData.getString("project_id__c") != null ? designDocData.getString("project_id__c") : "");//项目号(商机)
|
2025-06-16 09:08:51 +08:00
|
|
|
|
|
|
|
|
|
//合同
|
|
|
|
|
String contractNo = "";
|
|
|
|
|
|
|
|
|
|
if (designDocData.getString("sales_contract_number__c__r") != null) {
|
|
|
|
|
contractNo = designDocData.getString("sales_contract_number__c__r");
|
|
|
|
|
} else if (designDocData.getString("pre_signed_contract_id__c__r") != null) {
|
|
|
|
|
contractNo = designDocData.getString("pre_signed_contract_id__c__r");
|
|
|
|
|
} else {
|
|
|
|
|
log.info("当前单据没有合同号,将不再向下执行");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
erpDesignMap.put("contractno", contractNo);//合同号
|
2025-06-11 13:58:36 +08:00
|
|
|
|
erpDesignMap.put("crmid", designDocId);//crm唯一id
|
|
|
|
|
erpDesignMap.put("comment", designDocData.getString("remark__c") != null ? designDocData.getString("remark__c") : "");//备注
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始获取设计文件明细
|
|
|
|
|
JSONObject getDesignDocDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "design_file__c", Arrays.asList(designDocId))
|
|
|
|
|
), "design_file_details__c");
|
|
|
|
|
|
|
|
|
|
JSONObject designDocDetailRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
designDocDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDocDetail, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!"success".equals(designDocDetailRes.getString("errorDescription")) || designDocDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
log.info("查询失败或不存在当前设计文件明细");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List designDocList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (Object designDocDetailObj : designDocDetailRes.getJSONObject("data").getJSONArray("dataList")) {
|
|
|
|
|
JSONObject designDocDetailData = JSON.parseObject(JSON.toJSONString(designDocDetailObj));
|
|
|
|
|
|
|
|
|
|
System.out.println("当前正在处理的设计文件明细数据为:" + designDocDetailData);
|
|
|
|
|
|
|
|
|
|
//开始封装设计文件明细
|
|
|
|
|
Map designDocDetailMap = new HashMap<>();
|
|
|
|
|
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_name__c"));//设计文件明细
|
|
|
|
|
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
|
|
|
|
|
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
|
|
|
|
|
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
|
|
|
|
|
designDocDetailMap.put("entrycomment", designDocDetailData.getString("remark__c") != null ? designDocDetailData.getString("remark__c") : "");//备注
|
|
|
|
|
designDocDetailMap.put("supplier_number", designDocDetailData.getString("supplier_code__c") != null ? designDocDetailData.getString("supplier_code__c") : "");//建议供应商
|
|
|
|
|
|
|
|
|
|
designDocList.add(designDocDetailMap);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
erpDesignMap.put("billentry", designDocList);
|
|
|
|
|
|
|
|
|
|
Map erpContractData = new HashMap<>();
|
|
|
|
|
erpContractData.put("data", Arrays.asList(erpDesignMap));//请求体
|
|
|
|
|
|
|
|
|
|
System.out.println("erp请求为:" + JSON.parseObject(JSON.toJSONString(erpContractData)));
|
|
|
|
|
|
|
|
|
|
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
|
|
|
|
|
|
|
|
|
if (accessToken == null || accessToken.equals("")) {
|
|
|
|
|
log.info("金蝶token为空或不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String uuid = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
|
//开始封装请求头
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
|
headers.set("accessToken", accessToken);
|
|
|
|
|
headers.set("Idempotency-Key", uuid);
|
|
|
|
|
|
|
|
|
|
HttpEntity designDocReqEntity = new HttpEntity(erpContractData, headers);
|
|
|
|
|
|
|
|
|
|
System.out.println("请求为:" + JSON.parseObject(JSON.toJSONString(designDocReqEntity)));
|
|
|
|
|
|
|
|
|
|
//开始向金蝶发起请求
|
|
|
|
|
String designPlanUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/pssc/requirapplybillSave";
|
|
|
|
|
|
|
|
|
|
JSONObject erpDesignDocRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
erpDesignDocRes = restTemplate.postForObject(designPlanUrl, designDocReqEntity, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("设计文件结果为:" + JSON.parseObject(JSON.toJSONString(erpDesignDocRes)));
|
|
|
|
|
|
|
|
|
|
//开始封装回写程序
|
|
|
|
|
Map backReqMap = new HashMap();
|
|
|
|
|
backReqMap.put("_id", designDocId);
|
|
|
|
|
backReqMap.put("dataObjectApiName", "design_file__c");
|
|
|
|
|
|
|
|
|
|
//开始封装日志
|
|
|
|
|
Map logMap = new HashMap<>();
|
|
|
|
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
logMap.put("log_type", "DF");
|
|
|
|
|
logMap.put("syn_type", "0");
|
|
|
|
|
logMap.put("data_name", designDocName);
|
|
|
|
|
logMap.put("data_id", designDocId);
|
|
|
|
|
logMap.put("mark", createTime);
|
|
|
|
|
logMap.put("send_body", JSON.toJSONString(designDocReqEntity));
|
|
|
|
|
logMap.put("send_res", JSON.toJSONString(erpDesignDocRes));
|
|
|
|
|
logMap.put("tableName", "send_log_sjwj");
|
|
|
|
|
|
|
|
|
|
//判断是否执行成功
|
|
|
|
|
if ("0".equals(erpDesignDocRes.getString("errorCode"))) {
|
|
|
|
|
//同步成功
|
|
|
|
|
logMap.put("log_status", "0");
|
|
|
|
|
logMap.put("res_body", "同步成功");
|
|
|
|
|
backReqMap.put("erp_id__c", erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getString("id"));
|
|
|
|
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
|
|
|
|
backReqMap.put("response_info__c", "同步成功");
|
|
|
|
|
|
|
|
|
|
//审核
|
|
|
|
|
KingDeeUtils kingDeeUtils = new KingDeeUtils();
|
|
|
|
|
kingDeeUtils.audit(erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getString("id"), "pm_requirapplybill");
|
|
|
|
|
} else {
|
|
|
|
|
//同步失败
|
|
|
|
|
logMap.put("log_status", "1");
|
|
|
|
|
logMap.put("res_body", "同步失败:" + erpDesignDocRes.getString("message"));
|
|
|
|
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
|
|
|
|
backReqMap.put("response_info__c", erpDesignDocRes.getString("message"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始回写
|
|
|
|
|
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
|
|
|
|
|
|
|
|
|
|
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
|
|
|
|
|
|
|
|
|
|
JSONObject backRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, backReq, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("回写结果为:" + backRes);
|
|
|
|
|
|
|
|
|
|
//开始记录日志
|
|
|
|
|
JSONObject logResMap = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
logResMap = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("日志插入结果为:" + logResMap);
|
|
|
|
|
|
|
|
|
|
//判断一下设计文件的状态,没有成功就不传了
|
|
|
|
|
if (!"0".equals(erpDesignDocRes.getString("errorCode"))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始封装明细回写程序
|
|
|
|
|
for (Object resultObj : erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getJSONArray("entry")) {
|
|
|
|
|
JSONObject resultData = JSON.parseObject(JSON.toJSONString(resultObj));
|
|
|
|
|
|
|
|
|
|
String erpLineId = resultData.getString("entryid");
|
|
|
|
|
String crmLineId = resultData.getString("crmentryid");
|
|
|
|
|
|
|
|
|
|
//开始封装
|
|
|
|
|
Map backMap = new HashMap();
|
|
|
|
|
backMap.put("_id", crmLineId);
|
|
|
|
|
backMap.put("erp_line_id__c", erpLineId);
|
|
|
|
|
backMap.put("dataObjectApiName", "design_file_details__c");
|
|
|
|
|
|
|
|
|
|
JSONObject detailReq = crmRequestUtil.updateCRM(backMap);
|
|
|
|
|
|
|
|
|
|
JSONObject detailRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
detailRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, detailReq, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("明细回写结果为:" + detailRes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-13 17:09:43 +08:00
|
|
|
|
* 设计文件变更接口
|
2025-06-11 13:58:36 +08:00
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @Author weiloong_zhang
|
|
|
|
|
*/
|
2025-06-13 17:09:43 +08:00
|
|
|
|
@PostMapping("/sync/designDocBG")
|
2025-06-11 13:58:36 +08:00
|
|
|
|
public void upDesignDoc() {
|
|
|
|
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
JSONObject getDesignBGDoc = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "name", Arrays.asList("2025-06-13-00007"))
|
|
|
|
|
), "design_file__c__changeObj__c");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println("设计文件变更接口请求为:" + JSON.parseObject(JSON.toJSONString(getDesignBGDoc)));
|
|
|
|
|
|
|
|
|
|
JSONObject designBGDocRes = new JSONObject();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
|
|
|
|
try {
|
2025-06-13 17:09:43 +08:00
|
|
|
|
designBGDocRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignBGDoc, JSONObject.class);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println("设计文件变更结果为:" + JSON.parseObject(JSON.toJSONString(designBGDocRes)));
|
|
|
|
|
|
|
|
|
|
if (!"success".equals(designBGDocRes.getString("errorDescription")) || designBGDocRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
log.info("未找到设计文件变更数据或者查询失败");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
log.info("当前设计文件变更数据存在");
|
|
|
|
|
for (Object designBGDocObj : designBGDocRes.getJSONObject("data").getJSONArray("dataList")) {
|
|
|
|
|
JSONObject designBGDocData = JSON.parseObject(JSON.toJSONString(designBGDocObj));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println("当前正在处理的设计文件变更数据为:" + designBGDocData);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//开始截取关键数据
|
|
|
|
|
String designBGDocId = designBGDocData.getString("_id");
|
|
|
|
|
String designBGDocName = designBGDocData.getString("name");
|
|
|
|
|
String createTime = designBGDocData.getString("create_time");
|
|
|
|
|
String originalName = designBGDocData.getString("original_data__r");
|
|
|
|
|
String originalId = designBGDocData.getString("original_data");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//开始判断该单据是否已经执行过
|
|
|
|
|
JSONObject isLogRes = new JSONObject();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
|
|
|
|
try {
|
2025-06-13 17:09:43 +08:00
|
|
|
|
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_sjwj&log_type=DFBG&dataId=" + designBGDocId + "&mark=" + createTime, JSONObject.class);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
|
|
|
|
log.info("当前数据已经执行过了,将不再向下执行");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
log.info("日志不存在,将继续向下执行");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//开始封装主表数据
|
|
|
|
|
Map designBGDocMap = new HashMap();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//开始获取部门数据
|
|
|
|
|
//获取部门
|
|
|
|
|
String ownerDept = designBGDocData.getString("owner_department_id") != null ? designBGDocData.getString("owner_department_id") : "";
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
JSONObject getDept = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "_id", Arrays.asList(ownerDept))
|
2025-06-11 13:58:36 +08:00
|
|
|
|
), "DepartmentObj");
|
|
|
|
|
|
|
|
|
|
JSONObject deptRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
2025-06-13 17:09:43 +08:00
|
|
|
|
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getDept, JSONObject.class);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
if (!"success".equals(deptRes.getString("errorDescription")) || deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
log.info("不存在该部门,将不再向下执行");
|
|
|
|
|
continue;
|
2025-06-11 13:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
String deptERPCode = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("field_Vj6sf__c");
|
|
|
|
|
designBGDocMap.put("dept", "ZHY");//部门编码
|
|
|
|
|
//designBGDocMap.put("dept", deptERPCode);//部门
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//申请日期
|
|
|
|
|
long changeDate = designBGDocData.getLong("changed_time");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
Date changeDateFormat = new Date(changeDate);
|
|
|
|
|
designBGDocMap.put("biztime", changeDateFormat);//申请日期
|
|
|
|
|
//申请人
|
|
|
|
|
List ownerId = designBGDocData.getJSONArray("change_owner") != null ? designBGDocData.getJSONArray("change_owner") : new ArrayList<>();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
JSONObject getOwner = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "user_id", ownerId)
|
2025-06-11 13:58:36 +08:00
|
|
|
|
), "PersonnelObj");
|
|
|
|
|
|
|
|
|
|
JSONObject ownerRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
2025-06-13 17:09:43 +08:00
|
|
|
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getOwner, JSONObject.class);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
if (!"success".equals(ownerRes.getString("errorDescription")) || ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
log.info("负责人不存在或者请求失败");
|
|
|
|
|
continue;
|
2025-06-11 13:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println("负责人数据为:" + ownerRes);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
String ownerUserId = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("field_T1xid__c");
|
|
|
|
|
designBGDocData.put("bizuser", "ID-000016");//负责人
|
|
|
|
|
//designBGDocMap.put("bizuser", ownerUserId);//申请人
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//采购组织
|
|
|
|
|
//判断组织编码
|
|
|
|
|
String orgCode = "";
|
|
|
|
|
if (designBGDocData.getString("change_erp_organization_sales_con__c") != null && !"".equals(designBGDocData.getString("change_erp_organization_sales_con__c"))) {
|
|
|
|
|
orgCode = designBGDocData.getString("change_erp_organization_sales_con__c");
|
|
|
|
|
} else if (designBGDocData.getString("change_erp_organization_pre_contr__c") != null && !"".equals(designBGDocData.getString("change_erp_organization_pre_contr__c"))) {
|
|
|
|
|
orgCode = designBGDocData.getString("change_erp_organization_pre_contr__c");
|
|
|
|
|
} else {
|
|
|
|
|
log.info("当前单据没有组织编码,将不再向下执行");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
designBGDocMap.put("bizorg", orgCode);//采购组织
|
|
|
|
|
//销售合同号
|
|
|
|
|
designBGDocMap.put("contractno", designBGDocData.getString("change_sales_contract_number__c__r") != null ? designBGDocData.getString("change_sales_contract_number__c__r") : "");
|
|
|
|
|
//项目号
|
|
|
|
|
designBGDocMap.put("project", designBGDocData.getString("change_project_id__c") != null ? designBGDocData.getString("change_project_id__c") : "");
|
|
|
|
|
//CRMID
|
|
|
|
|
designBGDocMap.put("crmid", originalId);
|
|
|
|
|
//ERPID
|
|
|
|
|
designBGDocMap.put("erpId", designBGDocData.getString("change_erp_id__c") != null ? designBGDocData.getString("change_erp_id__c") : "");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
String changeReason = designBGDocData.getString("changed_reason") != null ? designBGDocData.getString("changed_reason") : "";
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//开始获取EP明细
|
|
|
|
|
JSONObject getDesignDocDetails = crmRequestUtil.getCRMList(Arrays.asList(
|
|
|
|
|
new Filter("EQ", "changed_data", Arrays.asList(designBGDocId))
|
|
|
|
|
), "design_file_details__c__changeObj__c");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
JSONObject designDocDetailsRes = new JSONObject();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
try {
|
|
|
|
|
designDocDetailsRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDocDetails, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
if (!"success".equals(designDocDetailsRes.getString("errorDescription")) || designDocDetailsRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|
|
|
|
log.info("请求失败或者该变更单不存在明细,将不再向下执行");
|
|
|
|
|
continue;
|
2025-06-11 13:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
log.info("设计文件变更单明细存在,将继续向下执行");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
List designDocDetailList = new ArrayList();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
for (Object designDocDetailObj : designDocDetailsRes.getJSONObject("data").getJSONArray("dataList")) {
|
|
|
|
|
JSONObject designDocDetailData = JSON.parseObject(JSON.toJSONString(designDocDetailObj));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println("设计文件变更单明细数据为:" + designDocDetailData);
|
|
|
|
|
|
|
|
|
|
//开始封装设计文件变更单明细数据
|
|
|
|
|
Map designDocDetailMap = new HashMap();
|
|
|
|
|
//物料编码
|
|
|
|
|
designDocDetailMap.put("material", designDocDetailData.getString("change_material_id__c__r") != null ? designDocDetailData.getString("change_material_id__c__r") : "");
|
|
|
|
|
//数量
|
|
|
|
|
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("change_quantity__c") != null ? designDocDetailData.getBigDecimal("change_quantity__c") : BigDecimal.ZERO);
|
|
|
|
|
//需求原因
|
|
|
|
|
designDocDetailMap.put("reqdes", changeReason);
|
|
|
|
|
//todo 建议供应商
|
|
|
|
|
designDocDetailMap.put("supplier", "");
|
|
|
|
|
//项目号
|
|
|
|
|
designDocDetailMap.put("project", designDocDetailData.getString("change_project_details__c__r") != null ? designDocDetailData.getString("change_project_details__c__r") : "");
|
|
|
|
|
//需求日期
|
|
|
|
|
long reqDate = designDocDetailData.getLong("create_time");
|
|
|
|
|
Date reqDateDate = new Date(reqDate);
|
|
|
|
|
designDocDetailMap.put("reqdate", reqDateDate);
|
|
|
|
|
//CRM行ID
|
|
|
|
|
designDocDetailMap.put("crmEntryId", designDocDetailData.getString("original_detail_data"));
|
|
|
|
|
//ERP行明细
|
|
|
|
|
designDocDetailMap.put("entryId", designDocDetailData.getString("change_erp_line_id__c") != null ? designDocDetailData.getString("change_erp_line_id__c") : "");
|
|
|
|
|
|
|
|
|
|
designDocDetailList.add(designDocDetailMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始封装明细
|
|
|
|
|
designBGDocMap.put("entryList", designDocDetailList);
|
|
|
|
|
|
|
|
|
|
//开始获取ERPToken
|
2025-06-11 13:58:36 +08:00
|
|
|
|
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
|
|
|
|
|
|
|
|
|
if (accessToken == null || accessToken.equals("")) {
|
|
|
|
|
log.info("金蝶token为空或不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String uuid = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
|
//开始封装请求头
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
|
headers.set("accessToken", accessToken);
|
|
|
|
|
headers.set("Idempotency-Key", uuid);
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
HttpEntity designDocReqEntity = new HttpEntity(designBGDocMap, headers);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println(JSON.parseObject(JSON.toJSONString(designDocReqEntity)));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
String designUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/pssc/requirapply/change";
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
JSONObject designDocRes = new JSONObject();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
|
|
|
|
try {
|
2025-06-13 17:09:43 +08:00
|
|
|
|
designDocRes = restTemplate.postForObject(designUrl, designDocReqEntity, JSONObject.class);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println(JSON.parseObject(JSON.toJSONString(designDocRes)));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
|
|
|
|
|
//开始封装回写程序
|
|
|
|
|
Map backReqMap = new HashMap();
|
2025-06-13 17:09:43 +08:00
|
|
|
|
backReqMap.put("_id", originalId);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
backReqMap.put("dataObjectApiName", "design_file__c");
|
|
|
|
|
|
|
|
|
|
//开始封装日志
|
|
|
|
|
Map logMap = new HashMap<>();
|
|
|
|
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
2025-06-13 17:09:43 +08:00
|
|
|
|
logMap.put("log_type", "DFBG");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
logMap.put("syn_type", "0");
|
2025-06-13 17:09:43 +08:00
|
|
|
|
logMap.put("data_name", designBGDocName);
|
|
|
|
|
logMap.put("data_id", designBGDocId);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
logMap.put("mark", createTime);
|
|
|
|
|
logMap.put("send_body", JSON.toJSONString(designDocReqEntity));
|
2025-06-13 17:09:43 +08:00
|
|
|
|
logMap.put("send_res", JSON.toJSONString(designDocRes));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
logMap.put("tableName", "send_log_sjwj");
|
|
|
|
|
|
|
|
|
|
//判断是否执行成功
|
2025-06-13 17:09:43 +08:00
|
|
|
|
if ("0".equals(designDocRes.getString("errorCode"))) {
|
2025-06-11 13:58:36 +08:00
|
|
|
|
//同步成功
|
|
|
|
|
logMap.put("log_status", "0");
|
|
|
|
|
logMap.put("res_body", "同步成功");
|
2025-06-13 17:09:43 +08:00
|
|
|
|
//backReqMap.put("updated_erp_id__c", contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
2025-06-13 17:09:43 +08:00
|
|
|
|
backReqMap.put("response_info__c", "变更同步成功");
|
|
|
|
|
|
|
|
|
|
//开始审核
|
|
|
|
|
// KingDeeUtils kingDeeUtils = new KingDeeUtils();
|
|
|
|
|
// kingDeeUtils.audit(contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} else {
|
|
|
|
|
//同步失败
|
|
|
|
|
logMap.put("log_status", "1");
|
2025-06-13 17:09:43 +08:00
|
|
|
|
logMap.put("res_body", "同步失败:" + designDocRes.getString("message"));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
2025-06-13 17:09:43 +08:00
|
|
|
|
backReqMap.put("response_info__c", "变更失败:" + designDocRes.getString("message"));
|
2025-06-11 13:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始回写
|
|
|
|
|
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
|
|
|
|
|
|
|
|
|
|
JSONObject backRes = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, backReq, JSONObject.class);
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("回写结果为:" + backRes);
|
|
|
|
|
|
|
|
|
|
//开始记录日志
|
2025-06-13 17:09:43 +08:00
|
|
|
|
JSONObject logRes = new JSONObject();
|
2025-06-11 13:58:36 +08:00
|
|
|
|
try {
|
2025-06-13 17:09:43 +08:00
|
|
|
|
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 17:09:43 +08:00
|
|
|
|
System.out.println("日志插入结果为:" + logRes);
|
2025-06-11 13:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|