设计文件和预签合同的代码优化更新

This commit is contained in:
itzhang 2025-07-04 17:07:34 +08:00
parent 36746331fb
commit 90ccbac340
4 changed files with 296 additions and 3 deletions

View File

@ -607,7 +607,13 @@ public class DesignController {
//直发现场时间
long siteDirectTime = designDocDetailData.getLong("change_direct_delivery_time__c") != null ? designDocDetailData.getLong("change_direct_delivery_time__c") : 0;
designDocDetailMap.put("deliveryTime", new Date(siteDirectTime));
Date siteDirectTimeDate = null;
if (siteDirectTime != 0){
siteDirectTimeDate = new Date(siteDirectTime);
}
designDocDetailMap.put("deliveryTime", siteDirectTimeDate);
//直发现场地点
designDocDetailMap.put("deliveryLocation", designDocDetailData.getString("change_direct_delivery_location__c") != null ? designDocDetailData.getString("change_direct_delivery_location__c") : "");
//需求日期

View File

@ -58,6 +58,7 @@ public class PreContractController {
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
new Filter("N", "is_initial__c", Arrays.asList("true")),
//new Filter("EQ", "name", Arrays.asList("YQ2505220005")),
new Filter("EQ", "life_status", Arrays.asList("normal"))
), "pre_signed_contract__c");
@ -579,4 +580,289 @@ public class PreContractController {
System.out.println("日志插入结果为:" + logRes);
}
}
/**
* 预签合同期初数据
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/pastContract")
public void pastContract() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
//new Filter("EQ", "name", Arrays.asList("YQ2505220005")),
new Filter("EQ", "is_initial__c", Arrays.asList("true")),
new Filter("EQ", "life_status", Arrays.asList("normal"))
), "pre_signed_contract__c");
JSONObject preContractRes = new JSONObject();
try {
preContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, preContractReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("查询结果为:" + preContractRes);
//判断查询是否成功
if (!"success".equals(preContractRes.getString("errorDescription")) || preContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或者没有符合条件的单据");
return;
}
//数据存在
for (Object preContractObj : preContractRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject preContractData = JSON.parseObject(JSON.toJSONString(preContractObj));
System.out.println("当前正在处理的数据为:" + preContractData);
String preContractId = preContractData.getString("_id");
//String createTime = preContractData.getString("create_time");
String createTime = preContractData.getString("last_modified_time");
//根据唯一id和创建时间查询是否已经执行当前数据
JSONObject preContractIsExist = new JSONObject();
try {
preContractIsExist = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=QCYQHT&dataId=" + preContractId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(preContractIsExist);
if (!preContractIsExist.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("没有集成过,将继续向下执行");
long documentDate = preContractData.getLong("document_date__c");
Date date = new Date(documentDate);
//开始封装传输至ERP的请求
Map erpContractReq = new HashMap<>();
erpContractReq.put("billno", preContractData.getString("name"));//预签合同编号
erpContractReq.put("crmid", preContractData.getString("_id"));//CRM唯一性编码
erpContractReq.put("project_number", preContractData.getString("opportunity_id__c"));//项目号
//erpContractReq.put("project_number", "SJ20250424-0033");//项目号
erpContractReq.put("billtype_number", "conm_salcontract_BT_YQ");//单据类型
erpContractReq.put("billname", preContractData.getString("project_name__c") != null ? preContractData.getString("project_name__c") : "预签合同");//合同名称
erpContractReq.put("type_number", "XSHT-YQ01");//合同类型
erpContractReq.put("contparties_number", preContractData.getString("our_company_name__c") != null ? preContractData.getString("our_company_name__c") : "");//合同主体
erpContractReq.put("createorg_number", preContractData.getString("our_company_name__c") != null ? preContractData.getString("our_company_name__c") : "");//销售组织编码
erpContractReq.put("org_number", preContractData.getString("our_company_name__c") != null ? preContractData.getString("our_company_name__c") : "");//销售组织编码
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
erpContractReq.put("biztime", date);//签订日期,单据日期
erpContractReq.put("biztimebegin", date);//起始日期
erpContractReq.put("biztimeend", date);//截止日期
erpContractReq.put("party1st", preContractData.getString("contract_unit_name__c__r"));//甲方
erpContractReq.put("party2nd", preContractData.getString("our_company_name__c"));//乙方
erpContractReq.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
erpContractReq.put("isentrysumamt", false);//isentrysumamt
//部门编码
String deptCode = "";
List deptIdList = preContractData.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") : "";
}
//erpContractReq.put("dept", "ZHY");//归属部门
erpContractReq.put("dept", deptCode);//归属部门
//erpContractReq.put("dept_number", "004");//归属部门
erpContractReq.put("dept_number", deptCode);//归属部门
//获取负责人编码
String ownerCode = "";
List ownerIdList = preContractData.getJSONArray("owner");
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();
}
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") : "";
}
//erpContractReq.put("operator", "ID-000016");//todo 负责人
erpContractReq.put("operator", ownerCode);//负责人
//合同单位
String customerId = preContractData.getString("contract_unit_name__c");
//根据客户唯一id查询客户名称
JSONObject customerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, customerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("客户名称查询失败或者不存在,直接跳过更新");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
erpContractReq.put("reccustomer_number", preContractData.getString("referenced_field__c"));//收获客户单位名称
//erpContractReq.put("customer_number", "Cus-000007");//todo 合同单位名称
erpContractReq.put("settlecustomer_number", preContractData.getString("billing_customer_code__c") != null ? preContractData.getString("billing_customer_code__c") : "");//结算客户
erpContractReq.put("payingcustomer_number", preContractData.getString("payment_customer_code__c") != null ? preContractData.getString("payment_customer_code__c") : "");//付款客户
//获取产品线
erpContractReq.put("productline_number", preContractData.getString("product_line__c"));//产品线
//获取具体安装方式
erpContractReq.put("installationmethod", preContractData.getString("installation_method__c"));//安装方式
//行业类型
erpContractReq.put("industrytype_number", preContractData.getString("industry_type__c"));//行业类型
erpContractReq.put("province", preContractData.getString("field_t3fgo__c__r"));//
erpContractReq.put("city", preContractData.getString("field_ngwth__c__r"));//
erpContractReq.put("county", preContractData.getString("field_K5p2C__c__r"));//
erpContractReq.put("deviceqty", preContractData.getBigDecimal("device_quantity__c") != null ? preContractData.getBigDecimal("device_quantity__c") : 0);//设备数量
erpContractReq.put("totalallamount", preContractData.getBigDecimal("pre_signed_amount__c") != null ? preContractData.getBigDecimal("pre_signed_amount__c") : 0);//预签金额
erpContractReq.put("warranty", preContractData.getBigDecimal("warranty_period_months__c") != null ? preContractData.getBigDecimal("warranty_period_months__c") : 0);//质保期
Map erpContractData = new HashMap<>();
erpContractData.put("data", Arrays.asList(erpContractReq));//请求体
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 contractReqEntity = new HttpEntity(erpContractData, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
//开始向金蝶发起请求
String contractUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/conm/conm_salcontract/initcontractsave";
JSONObject contractRes = new JSONObject();
try {
contractRes = restTemplate.postForObject(contractUrl, contractReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", preContractId);
backReqMap.put("dataObjectApiName", "pre_signed_contract__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "QCYQHT");
logMap.put("syn_type", "0");
logMap.put("data_name", preContractData.getString("name"));
logMap.put("data_id", preContractId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(contractReqEntity));
logMap.put("send_res", JSON.toJSONString(contractRes));
logMap.put("tableName", "send_log_htxx");
//判断是否执行成功
if ("0".equals(contractRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", contractRes.getJSONObject("data").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(contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + contractRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", contractRes.getString("message"));
}
//开始回写
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);
//开始记录日志
JSONObject logRes = new JSONObject();
try {
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("日志插入结果为:" + logRes);
}
}
}

View File

@ -60,12 +60,13 @@ public class CrmTask {
* @return void
* @Author weiloong_zhang
*/
// @Scheduled(cron = "0 0/1 * * * ?")
// @Scheduled(cron = "0/45 * * * * ?")
// private void configureTasks() throws Exception {
// System.out.println("开始同步ERP数据");
// crmTokenController.tokenReSync();
// preContractController.syncContract();
// preContractController.bgPreContract();
// preContractController.pastContract();
// frameContractController.syncFrameContract();
// frameContractController.syncFrameContractBG();
// xshtController.syncXSHT();

View File

@ -35,7 +35,7 @@ public class CrmTaskTZ {
* @return void
* @Author weiloong_zhang
*/
// @Scheduled(cron = "0 0/2 * * * ?")
// @Scheduled(cron = "0 0/1 * * * ?")
// private void configureTasks() throws Exception {
// System.out.println("开始同步台账数据");
// projectInitiateController.syncProjectInitiate();