销售合同的部分修改,新增设计文件集成代码、要货计划集成代码
This commit is contained in:
parent
fda5357dc5
commit
67efd8a404
@ -0,0 +1,575 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
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;
|
||||||
|
import org.ssssssss.magicboot.constant.URLConstant;
|
||||||
|
import org.ssssssss.magicboot.entity.Filter;
|
||||||
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
|
||||||
|
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("开始同步设计文件");
|
||||||
|
|
||||||
|
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("SJWJ250509-0003"))
|
||||||
|
), "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");
|
||||||
|
|
||||||
|
//开始查询该单据是否已经集成过
|
||||||
|
JSONObject isLog = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLog = restTemplate.getForObject("http://localhost:18088/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);//设计文件编号
|
||||||
|
erpDesignMap.put("org_number", "zyierp");//组织编码
|
||||||
|
erpDesignMap.put("billtype_number", "pm_requirapplybill_STD_BT_S");//单据类型
|
||||||
|
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", "zyierp");//部门编码
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = designDocData.getJSONArray("owner");
|
||||||
|
|
||||||
|
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", ownerIdList)
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject ownerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
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("bizorg_number", "zyierp");//采购组织
|
||||||
|
erpDesignMap.put("project_number", designDocData.getString("project_id__c"));//todo 项目号(商机)
|
||||||
|
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
|
||||||
|
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_id__c__r"));//设计文件明细
|
||||||
|
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", "G08000001");//todo 建议供应商
|
||||||
|
|
||||||
|
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 = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/pssc/pm_requirapplybill/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("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} 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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logResMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设计文件更新接口
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/syncUp/designDoc")
|
||||||
|
public void upDesignDoc() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
log.info("开始同步设计文件");
|
||||||
|
|
||||||
|
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("SJWJ250509-0003"))
|
||||||
|
), "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");
|
||||||
|
|
||||||
|
//开始查询该单据是否已经集成过
|
||||||
|
JSONObject isLog = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLog = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_sjwj&log_type=DFUP&dataId=" + designDocId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否已经执行过
|
||||||
|
if (!isLog.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前单据已经集成过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("当前单据没有集成过,将开始向下执行");
|
||||||
|
|
||||||
|
//开始封装传输至ERP中的请求
|
||||||
|
String erpId = designDocData.getString("erp_id__c") != null ? designDocData.getString("erp_id__c") : "";
|
||||||
|
|
||||||
|
if ("".equals(erpId)) {
|
||||||
|
log.info("当前单据erp_id__c为空,不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map erpDesignMap = new HashMap<>();
|
||||||
|
erpDesignMap.put("id", erpId);//erpId
|
||||||
|
erpDesignMap.put("billno", designDocName);//设计文件编号
|
||||||
|
erpDesignMap.put("org_number", "zyierp");//组织编码
|
||||||
|
erpDesignMap.put("billtype_number", "pm_requirapplybill_STD_BT_S");//单据类型
|
||||||
|
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", "zyierp");//部门编码
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = designDocData.getJSONArray("owner");
|
||||||
|
|
||||||
|
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", ownerIdList)
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject ownerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
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("bizorg_number", "zyierp");//采购组织
|
||||||
|
erpDesignMap.put("project_number", designDocData.getString("project_id__c"));//todo 项目号(商机)
|
||||||
|
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
|
||||||
|
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_id__c__r"));//设计文件明细
|
||||||
|
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", "G08000001");//todo 建议供应商
|
||||||
|
|
||||||
|
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 = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/pssc/pm_requirapplybill/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", "DFUP");
|
||||||
|
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("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} 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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logResMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,642 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
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;
|
||||||
|
import org.ssssssss.magicboot.constant.URLConstant;
|
||||||
|
import org.ssssssss.magicboot.entity.Filter;
|
||||||
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 要货计划
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @return null
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/goods_plan")
|
||||||
|
@Slf4j
|
||||||
|
public class GoodsPlanController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//new GoodsPlanController().syncGoodsPlan();
|
||||||
|
new GoodsPlanController().updateGoodsPlan();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步新增要货计划
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/goodsPlan")
|
||||||
|
public void syncGoodsPlan() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
log.info("开始同步要货计划");
|
||||||
|
|
||||||
|
//要货计划请求
|
||||||
|
JSONObject getGoodsPlan = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("YHJH20250508-0002")),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "purchase_plan__c");
|
||||||
|
|
||||||
|
JSONObject goodsPlanRes = new JSONObject();
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
try {
|
||||||
|
goodsPlanRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getGoodsPlan, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否请求成功
|
||||||
|
if (!"success".equals(goodsPlanRes.getString("errorDescription")) || goodsPlanRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("请求失败或数据不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//请求成功
|
||||||
|
for (Object goodsPlanObj : goodsPlanRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
//将Obj转为JSONObject
|
||||||
|
JSONObject goodsPlanData = JSON.parseObject(JSON.toJSONString(goodsPlanObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的要货计划数据为:" + goodsPlanData);
|
||||||
|
|
||||||
|
//获取当前单据的唯一id
|
||||||
|
String goodsPlanId = goodsPlanData.getString("_id");
|
||||||
|
|
||||||
|
//获取当前单据名称
|
||||||
|
String goodsPlanName = goodsPlanData.getString("name");
|
||||||
|
|
||||||
|
//获取当前单据的创建时间
|
||||||
|
String createTime = goodsPlanData.getString("create_time");
|
||||||
|
|
||||||
|
//开始查询该单据是否已经集成过
|
||||||
|
JSONObject logRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_goodsplan&log_type=GP&dataId=" + goodsPlanId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前单据已经集成过了");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("当前单据没有集成过");
|
||||||
|
|
||||||
|
//开始封装传输至ERP的请求
|
||||||
|
log.info("开始封装请求");
|
||||||
|
|
||||||
|
Map erpGoodsPlanReq = new HashMap<>();
|
||||||
|
erpGoodsPlanReq.put("f9w5_crmid", goodsPlanId);
|
||||||
|
erpGoodsPlanReq.put("billno", goodsPlanName);//单据编号
|
||||||
|
erpGoodsPlanReq.put("billtype_number", "f9w5_sm_purchaseplan_BT");//单据类型
|
||||||
|
erpGoodsPlanReq.put("org_number", "zyierp");//组织编码
|
||||||
|
|
||||||
|
//开始获取需求日期
|
||||||
|
long biztime = goodsPlanData.getLong("requirement_date__c");
|
||||||
|
|
||||||
|
Date date = new Date(biztime);
|
||||||
|
erpGoodsPlanReq.put("biztime", date);//需求日期
|
||||||
|
|
||||||
|
//部门编码
|
||||||
|
String deptCode = "";
|
||||||
|
|
||||||
|
List deptIdList = goodsPlanData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanReq.put("dept", "zyierp");//todo 归属部门
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = goodsPlanData.getJSONArray("owner");
|
||||||
|
|
||||||
|
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", ownerIdList)
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject ownerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanReq.put("operator", "ID-000011");//todo 负责人
|
||||||
|
|
||||||
|
//根据要货计划查询要货计划明细
|
||||||
|
JSONObject getGoodsPlanDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "purchase_plan__c", Arrays.asList(goodsPlanId))
|
||||||
|
), "purchase_plan_details__c");
|
||||||
|
|
||||||
|
JSONObject goodsPlanDetailRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
goodsPlanDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getGoodsPlanDetail, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("要货计划明细查询结果为:" + goodsPlanDetailRes);
|
||||||
|
|
||||||
|
if (!"success".equals(goodsPlanDetailRes.getString("errorDescription")) || goodsPlanDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("要货计划明细查询失败不存在当前要货计划明细");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("要货计划明细存在,继续向下执行");
|
||||||
|
|
||||||
|
//明细列表
|
||||||
|
List goodsPlanDetailList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object goodsPlanDetailObj : goodsPlanDetailRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject goodsPlanDetailData = JSON.parseObject(JSON.toJSONString(goodsPlanDetailObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的要货计划明细数据为:" + goodsPlanDetailData);
|
||||||
|
|
||||||
|
//开始封装要货计划明细数据
|
||||||
|
Map erpGoodsPlanDetailReq = new HashMap<>();
|
||||||
|
erpGoodsPlanDetailReq.put("f9w5_crmentryid", goodsPlanDetailData.getString("_id"));//crm明细id
|
||||||
|
erpGoodsPlanDetailReq.put("material_number", goodsPlanDetailData.getString("material_id__c__r"));//物料编号
|
||||||
|
erpGoodsPlanDetailReq.put("entryorg_number", "zyierp");//组织编码
|
||||||
|
erpGoodsPlanDetailReq.put("qty", goodsPlanDetailData.getBigDecimal("quantity__c") != null ? goodsPlanDetailData.getBigDecimal("quantity__c") : 0);//数量
|
||||||
|
//erpGoodsPlanDetailReq.put("lot_number", goodsPlanDetailData.getString("batch_number__c") != null ? goodsPlanDetailData.getString("batch_number__c") : "");//批号
|
||||||
|
erpGoodsPlanDetailReq.put("entrycomment", goodsPlanDetailData.getString("remark__c") != null ? goodsPlanDetailData.getString("remark__c") : "");//备注
|
||||||
|
erpGoodsPlanDetailReq.put("f9w5_contractno", goodsPlanDetailData.getString("sales_contract_number__c__r") != null ? goodsPlanDetailData.getString("sales_contract_number__c__r") : "");//销售合同编号
|
||||||
|
|
||||||
|
//开始查询项目号
|
||||||
|
String projectId = goodsPlanDetailData.getString("project_name__c") != null ? goodsPlanDetailData.getString("project_name__c") : "";
|
||||||
|
|
||||||
|
//开始查询项目号
|
||||||
|
JSONObject getProjectReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(projectId))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject projectRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProjectReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
String projectCode = "";
|
||||||
|
|
||||||
|
if ("success".equals(projectRes.getString("errorDescription")) && !projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject projectData = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
projectCode = projectData.getString("opportunity_id__c") != null ? projectData.getString("opportunity_id__c") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanDetailReq.put("f9w5_project_number", projectCode);//项目号
|
||||||
|
|
||||||
|
goodsPlanDetailList.add(erpGoodsPlanDetailReq);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanReq.put("billentry", goodsPlanDetailList);
|
||||||
|
|
||||||
|
//开始封装要货计划请求
|
||||||
|
System.out.println("erp请求为:" + JSON.parseObject(JSON.toJSONString(erpGoodsPlanReq)));
|
||||||
|
|
||||||
|
Map erpContractData = new HashMap<>();
|
||||||
|
erpContractData.put("data", Arrays.asList(erpGoodsPlanReq));//请求体
|
||||||
|
|
||||||
|
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 goodsPlanReqEntity = new HttpEntity(erpContractData, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(goodsPlanReqEntity)));
|
||||||
|
|
||||||
|
//开始向金蝶发起请求
|
||||||
|
String goodsPlanUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/sm/f9w5_sm_purchaseplan/purchaseplanSave";
|
||||||
|
|
||||||
|
JSONObject erpGoodsPlanRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpGoodsPlanRes = restTemplate.postForObject(goodsPlanUrl, goodsPlanReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("要货计划结果为:" + JSON.parseObject(JSON.toJSONString(erpGoodsPlanRes)));
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", goodsPlanId);
|
||||||
|
backReqMap.put("dataObjectApiName", "purchase_plan__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "GP");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", goodsPlanName);
|
||||||
|
logMap.put("data_id", goodsPlanId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(goodsPlanReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(erpGoodsPlanRes));
|
||||||
|
logMap.put("tableName", "send_log_goodsplan");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(erpGoodsPlanRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", erpGoodsPlanRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + erpGoodsPlanRes.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", erpGoodsPlanRes.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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logResMap);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 要货计划更新接口
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/update/goodsPlan")
|
||||||
|
public void updateGoodsPlan() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
log.info("开始同步更新要货计划");
|
||||||
|
|
||||||
|
//要货计划请求
|
||||||
|
JSONObject getGoodsPlan = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("YHJH20250508-0002")),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "purchase_plan__c");
|
||||||
|
|
||||||
|
JSONObject goodsPlanRes = new JSONObject();
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
try {
|
||||||
|
goodsPlanRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getGoodsPlan, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否请求成功
|
||||||
|
if (!"success".equals(goodsPlanRes.getString("errorDescription")) || goodsPlanRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("请求失败或数据不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//请求成功
|
||||||
|
for (Object goodsPlanObj : goodsPlanRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
//将Obj转为JSONObject
|
||||||
|
JSONObject goodsPlanData = JSON.parseObject(JSON.toJSONString(goodsPlanObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的要货计划数据为:" + goodsPlanData);
|
||||||
|
|
||||||
|
//获取当前单据的唯一id
|
||||||
|
String goodsPlanId = goodsPlanData.getString("_id");
|
||||||
|
|
||||||
|
//获取当前单据名称
|
||||||
|
String goodsPlanName = goodsPlanData.getString("name");
|
||||||
|
|
||||||
|
//获取当前单据的最后修改时间
|
||||||
|
String lastModifyTime = goodsPlanData.getString("last_modified_time");
|
||||||
|
|
||||||
|
//开始查询该单据是否已经集成过
|
||||||
|
JSONObject logRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_goodsplan&log_type=GPUP&dataId=" + goodsPlanId + "&mark=" + lastModifyTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前单据已经更新过了");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("当前单据没有集成过");
|
||||||
|
|
||||||
|
//开始封装传输至ERP的请求
|
||||||
|
log.info("开始封装请求");
|
||||||
|
|
||||||
|
//获取ERPID
|
||||||
|
String erpId = goodsPlanData.getString("erp_id__c") != null ? goodsPlanData.getString("erp_id__c") : "";
|
||||||
|
|
||||||
|
if ("".equals(erpId)) {
|
||||||
|
log.info("当前单据erp_id__c为空,不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("存在ERPID,继续向下执行!");
|
||||||
|
|
||||||
|
Map erpGoodsPlanReq = new HashMap<>();
|
||||||
|
erpGoodsPlanReq.put("id", erpId);
|
||||||
|
erpGoodsPlanReq.put("f9w5_crmid", goodsPlanId);
|
||||||
|
erpGoodsPlanReq.put("billno", goodsPlanName);//单据编号
|
||||||
|
erpGoodsPlanReq.put("billtype_number", "f9w5_sm_purchaseplan_BT");//单据类型
|
||||||
|
erpGoodsPlanReq.put("org_number", "zyierp");//组织编码
|
||||||
|
|
||||||
|
//开始获取需求日期
|
||||||
|
long biztime = goodsPlanData.getLong("requirement_date__c");
|
||||||
|
|
||||||
|
Date date = new Date(biztime);
|
||||||
|
erpGoodsPlanReq.put("biztime", date);//需求日期
|
||||||
|
|
||||||
|
//部门编码
|
||||||
|
String deptCode = "";
|
||||||
|
|
||||||
|
List deptIdList = goodsPlanData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanReq.put("dept", "zyierp");//todo 归属部门
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = goodsPlanData.getJSONArray("owner");
|
||||||
|
|
||||||
|
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", ownerIdList)
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject ownerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanReq.put("operator", "ID-000011");//todo 负责人
|
||||||
|
|
||||||
|
//根据要货计划查询要货计划明细
|
||||||
|
JSONObject getGoodsPlanDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "purchase_plan__c", Arrays.asList(goodsPlanId))
|
||||||
|
), "purchase_plan_details__c");
|
||||||
|
|
||||||
|
JSONObject goodsPlanDetailRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
goodsPlanDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getGoodsPlanDetail, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("要货计划明细查询结果为:" + goodsPlanDetailRes);
|
||||||
|
|
||||||
|
if (!"success".equals(goodsPlanDetailRes.getString("errorDescription")) || goodsPlanDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("要货计划明细查询失败不存在当前要货计划明细");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("要货计划明细存在,继续向下执行");
|
||||||
|
|
||||||
|
//明细列表
|
||||||
|
List goodsPlanDetailList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object goodsPlanDetailObj : goodsPlanDetailRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject goodsPlanDetailData = JSON.parseObject(JSON.toJSONString(goodsPlanDetailObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的要货计划明细数据为:" + goodsPlanDetailData);
|
||||||
|
|
||||||
|
//开始封装要货计划明细数据
|
||||||
|
Map erpGoodsPlanDetailReq = new HashMap<>();
|
||||||
|
erpGoodsPlanDetailReq.put("f9w5_crmentryid", goodsPlanDetailData.getString("_id"));//crm明细id
|
||||||
|
erpGoodsPlanDetailReq.put("material_number", goodsPlanDetailData.getString("material_id__c__r"));//物料编号
|
||||||
|
erpGoodsPlanDetailReq.put("entryorg_number", "zyierp");//组织编码
|
||||||
|
erpGoodsPlanDetailReq.put("qty", goodsPlanDetailData.getBigDecimal("quantity__c") != null ? goodsPlanDetailData.getBigDecimal("quantity__c") : 0);//数量
|
||||||
|
//erpGoodsPlanDetailReq.put("lot_number", goodsPlanDetailData.getString("batch_number__c") != null ? goodsPlanDetailData.getString("batch_number__c") : "");//批号
|
||||||
|
erpGoodsPlanDetailReq.put("entrycomment", goodsPlanDetailData.getString("remark__c") != null ? goodsPlanDetailData.getString("remark__c") : "");//备注
|
||||||
|
erpGoodsPlanDetailReq.put("f9w5_contractno", goodsPlanDetailData.getString("sales_contract_number__c__r") != null ? goodsPlanDetailData.getString("sales_contract_number__c__r") : "");//销售合同编号
|
||||||
|
|
||||||
|
//开始查询项目号
|
||||||
|
String projectId = goodsPlanDetailData.getString("project_name__c") != null ? goodsPlanDetailData.getString("project_name__c") : "";
|
||||||
|
|
||||||
|
//开始查询项目号
|
||||||
|
JSONObject getProjectReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(projectId))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject projectRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProjectReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
String projectCode = "";
|
||||||
|
|
||||||
|
if ("success".equals(projectRes.getString("errorDescription")) && !projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject projectData = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
projectCode = projectData.getString("opportunity_id__c") != null ? projectData.getString("opportunity_id__c") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanDetailReq.put("f9w5_project_number", projectCode);//项目号
|
||||||
|
|
||||||
|
goodsPlanDetailList.add(erpGoodsPlanDetailReq);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
erpGoodsPlanReq.put("billentry", goodsPlanDetailList);
|
||||||
|
|
||||||
|
//开始封装要货计划请求
|
||||||
|
System.out.println("erp请求为:" + JSON.parseObject(JSON.toJSONString(erpGoodsPlanReq)));
|
||||||
|
|
||||||
|
Map erpContractData = new HashMap<>();
|
||||||
|
erpContractData.put("data", Arrays.asList(erpGoodsPlanReq));//请求体
|
||||||
|
|
||||||
|
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 goodsPlanReqEntity = new HttpEntity(erpContractData, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(goodsPlanReqEntity)));
|
||||||
|
|
||||||
|
//开始向金蝶发起请求
|
||||||
|
String goodsPlanUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/sm/f9w5_sm_purchaseplan/purchaseplanSave";
|
||||||
|
|
||||||
|
JSONObject erpGoodsPlanRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpGoodsPlanRes = restTemplate.postForObject(goodsPlanUrl, goodsPlanReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("要货计划结果为:" + JSON.parseObject(JSON.toJSONString(erpGoodsPlanRes)));
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", goodsPlanId);
|
||||||
|
backReqMap.put("dataObjectApiName", "purchase_plan__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "GPUP");
|
||||||
|
logMap.put("syn_type", "1");
|
||||||
|
logMap.put("data_name", goodsPlanName);
|
||||||
|
logMap.put("data_id", goodsPlanId);
|
||||||
|
logMap.put("mark", lastModifyTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(goodsPlanReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(erpGoodsPlanRes));
|
||||||
|
logMap.put("tableName", "send_log_goodsplan");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(erpGoodsPlanRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", erpGoodsPlanRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + erpGoodsPlanRes.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", erpGoodsPlanRes.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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logResMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -307,6 +307,7 @@ public class XSHTController {
|
|||||||
contractDetailMap.put("baseunit", contractDetailData.getString("unit__c__r") != null ? contractDetailData.getString("unit__c__r") : "");//单位
|
contractDetailMap.put("baseunit", contractDetailData.getString("unit__c__r") != null ? contractDetailData.getString("unit__c__r") : "");//单位
|
||||||
//contractDetailMap.put("baseunit", "TEST0001");//todo 单位
|
//contractDetailMap.put("baseunit", "TEST0001");//todo 单位
|
||||||
contractDetailMap.put("unit_number", "pcs");//单位编码
|
contractDetailMap.put("unit_number", "pcs");//单位编码
|
||||||
|
contractDetailMap.put("f9w5_unit1_number", "pcs");//单位编码
|
||||||
contractDetailMap.put("baseqty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
|
contractDetailMap.put("baseqty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
|
||||||
contractDetailMap.put("qty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
|
contractDetailMap.put("qty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
|
||||||
contractDetailMap.put("priceandtax", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//含税单价
|
contractDetailMap.put("priceandtax", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//含税单价
|
||||||
|
Loading…
x
Reference in New Issue
Block a user