将台账设备回退到了原本的状态,将金蝶的测试系统的鉴权信息换到了158环境,并修改了token的请求的部分方法,修改了金蝶正式环境的手机号码,修改了银行信息和供应商的ERP传输环境,新增了期初合同。
This commit is contained in:
parent
582afa484c
commit
32108809c8
@ -1,6 +1,6 @@
|
|||||||
package com.management.constant;
|
package com.management.constant;
|
||||||
|
|
||||||
public class ERPURLConstant {
|
public class ERPURLConstant {
|
||||||
public static final String ERP_URL = "http://192.168.31.233:8022";//erp地址
|
public static final String ERP_URL = "http://192.168.31.158:8022";//erp地址
|
||||||
public static final String ACCOUNT_ID = "2095345516136108032";//erp地址
|
public static final String ACCOUNT_ID = "2246658461007874048";//erp地址
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class BankInfoController {
|
|||||||
deptReq.put("pageSize", 1999);
|
deptReq.put("pageSize", 1999);
|
||||||
|
|
||||||
//开始获取金蝶token
|
//开始获取金蝶token
|
||||||
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
String accessToken = new KDTokenController().getKDAccessToken();
|
||||||
|
|
||||||
if (accessToken == null || accessToken.equals("")) {
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
log.info("金蝶token为空或不存在");
|
log.info("金蝶token为空或不存在");
|
||||||
@ -85,7 +85,8 @@ public class BankInfoController {
|
|||||||
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
|
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
|
||||||
|
|
||||||
//开始发起请求
|
//开始发起请求
|
||||||
String bankInfoUrl = ERPURLConstant.ERP_URL +"/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
//String bankInfoUrl = ERPURLConstant.ERP_URL +"/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
||||||
|
String bankInfoUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
||||||
|
|
||||||
String bankInfoResStr = "";
|
String bankInfoResStr = "";
|
||||||
|
|
||||||
@ -292,7 +293,7 @@ public class BankInfoController {
|
|||||||
deptReq.put("pageSize", 1999);
|
deptReq.put("pageSize", 1999);
|
||||||
|
|
||||||
//开始获取金蝶token
|
//开始获取金蝶token
|
||||||
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
String accessToken = new KDTokenController().getKDAppToken();
|
||||||
|
|
||||||
if (accessToken == null || accessToken.equals("")) {
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
log.info("金蝶token为空或不存在");
|
log.info("金蝶token为空或不存在");
|
||||||
@ -307,7 +308,8 @@ public class BankInfoController {
|
|||||||
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
|
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
|
||||||
|
|
||||||
//开始发起请求
|
//开始发起请求
|
||||||
String bankInfoUrl = ERPURLConstant.ERP_URL+"/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
//String bankInfoUrl = ERPURLConstant.ERP_URL+"/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
||||||
|
String bankInfoUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
||||||
|
|
||||||
String bankInfoResStr = "";
|
String bankInfoResStr = "";
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class KDTokenController {
|
|||||||
|
|
||||||
//请求参数
|
//请求参数
|
||||||
LinkedHashMap accessTokenParams = new LinkedHashMap<>();
|
LinkedHashMap accessTokenParams = new LinkedHashMap<>();
|
||||||
accessTokenParams.put("user", "19819780536");
|
accessTokenParams.put("user", "18660772123");
|
||||||
accessTokenParams.put("usertype", "Mobile");
|
accessTokenParams.put("usertype", "Mobile");
|
||||||
accessTokenParams.put("apptoken", getKDAppToken());
|
accessTokenParams.put("apptoken", getKDAppToken());
|
||||||
accessTokenParams.put("tenantid", "zyierp");
|
accessTokenParams.put("tenantid", "zyierp");
|
||||||
@ -153,8 +153,8 @@ public class KDTokenController {
|
|||||||
String appTokenUrl = ERPURLConstant.ERP_URL + "/ierp/api/getAppToken.do";
|
String appTokenUrl = ERPURLConstant.ERP_URL + "/ierp/api/getAppToken.do";
|
||||||
//请求参数
|
//请求参数
|
||||||
LinkedHashMap appTokenParams = new LinkedHashMap<>();
|
LinkedHashMap appTokenParams = new LinkedHashMap<>();
|
||||||
appTokenParams.put("appId", "FXXKCRM");
|
appTokenParams.put("appId", "erpapi");
|
||||||
appTokenParams.put("appSecret", "FXXKCRM20251234a!");
|
appTokenParams.put("appSecret", "ZHYkdERPapi@2025");
|
||||||
appTokenParams.put("tenantid", "zyierp");
|
appTokenParams.put("tenantid", "zyierp");
|
||||||
appTokenParams.put("accountId", ERPURLConstant.ACCOUNT_ID);
|
appTokenParams.put("accountId", ERPURLConstant.ACCOUNT_ID);
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ public class KDTokenController {
|
|||||||
|
|
||||||
//请求参数
|
//请求参数
|
||||||
LinkedHashMap accessTokenParams = new LinkedHashMap<>();
|
LinkedHashMap accessTokenParams = new LinkedHashMap<>();
|
||||||
accessTokenParams.put("user", "19819780536");
|
accessTokenParams.put("user", "18660772123");
|
||||||
accessTokenParams.put("usertype", "Mobile");
|
accessTokenParams.put("usertype", "Mobile");
|
||||||
accessTokenParams.put("apptoken", getKDAppTokenTest());
|
accessTokenParams.put("apptoken", getKDAppTokenTest());
|
||||||
accessTokenParams.put("tenantid", "zyierp");
|
accessTokenParams.put("tenantid", "zyierp");
|
||||||
|
@ -0,0 +1,504 @@
|
|||||||
|
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.util.MultiValueMap;
|
||||||
|
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 java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/past")
|
||||||
|
@Slf4j
|
||||||
|
public class PastContractController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new PastContractController().syncPastContract();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 期初合同
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/past_contract")
|
||||||
|
public void syncPastContract() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject getPastContract = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("0024"))
|
||||||
|
), "SaleContractObj");
|
||||||
|
|
||||||
|
JSONObject pastContractRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
pastContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getPastContract, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(pastContractRes.getString("errorDescription")) || pastContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("未找到期初合同数据或者查询失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("当前期初合同数据存在");
|
||||||
|
|
||||||
|
for (Object pastContractObj : pastContractRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject contractData = JSON.parseObject(JSON.toJSONString(pastContractObj));
|
||||||
|
|
||||||
|
System.out.println("当前期初合同数据为:" + contractData);
|
||||||
|
|
||||||
|
//合同唯一id
|
||||||
|
String contractId = contractData.getString("_id");
|
||||||
|
//合同名称
|
||||||
|
String contractName = contractData.getString("name");
|
||||||
|
//创建时间
|
||||||
|
//String createTime = contractData.getString("create_time");
|
||||||
|
String createTime = contractData.getString("last_modified_time");
|
||||||
|
|
||||||
|
//查看数据库表中是否已执行过当前数据
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=XSHTQC&dataId=" + contractId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(isLogRes);
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("没有集成过,将继续向下执行");
|
||||||
|
|
||||||
|
//签订日期
|
||||||
|
long documentDate = contractData.getLong("contract_time");
|
||||||
|
|
||||||
|
Date date = new Date(documentDate);
|
||||||
|
|
||||||
|
//开始查询项目号(商机)
|
||||||
|
JSONObject projectReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(contractData.getString("opportunity_name__c")))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject projectRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, projectReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(projectRes.getString("errorDescription")) || projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("项目号不存在,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String projectCode = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("opportunity_id__c");
|
||||||
|
|
||||||
|
//合同种类
|
||||||
|
String contractType = contractData.getString("contract_zl__c") != null ? contractData.getString("contract_zl__c") : "";
|
||||||
|
|
||||||
|
if (contractType.equals("")) {
|
||||||
|
log.info("合同种类不存在,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String contractMainType = "";
|
||||||
|
String contractTypeStr = "";
|
||||||
|
|
||||||
|
if (contractType.equals("option_sales_contract_details__c")) {
|
||||||
|
contractMainType = "XSHT-QD01";
|
||||||
|
contractTypeStr = "020";
|
||||||
|
} else if (contractType.equals("option_sales_contract_total_amoun__c")) {
|
||||||
|
contractMainType = "XSHT-QD02";
|
||||||
|
contractTypeStr = "020-1";
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装传输至ERP的请求
|
||||||
|
Map erpContractReq = new HashMap<>();
|
||||||
|
erpContractReq.put("billno", contractData.getString("name"));//合同编号
|
||||||
|
erpContractReq.put("crmid", contractData.getString("_id"));//CRM唯一性编码
|
||||||
|
erpContractReq.put("suitscope", "A");//todo 适用组织范围
|
||||||
|
//erpContractReq.put("project_number", projectCode);//项目号
|
||||||
|
erpContractReq.put("zhybilltype", contractData.getString("contract_type__c"));//合同类型
|
||||||
|
erpContractReq.put("project_number", "SJ20250424-0033");//项目号
|
||||||
|
erpContractReq.put("billtype_number", "conm_salcontract_BT_QD");//单据类型
|
||||||
|
erpContractReq.put("billname", contractData.getString("project_name__c") != null ? contractData.getString("project_name__c") : "销售合同");//合同名称
|
||||||
|
erpContractReq.put("type_number", contractMainType);//合同类型
|
||||||
|
erpContractReq.put("contparties_number", contractData.getString("our_company_name__c") != null ? contractData.getString("our_company_name__c") : "");//合同主体
|
||||||
|
erpContractReq.put("createorg_number", contractData.getString("our_company_name__c") != null ? contractData.getString("our_company_name__c") : "");//销售组织编码
|
||||||
|
erpContractReq.put("org_number", contractData.getString("our_company_name__c") != null ? contractData.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", contractData.getString("account_id__r") != null ? contractData.getString("account_id__r") : "");//甲方
|
||||||
|
erpContractReq.put("party2nd", contractData.getString("our_company_name__c__r") != null ? contractData.getString("our_company_name__c__r") : "");//乙方
|
||||||
|
erpContractReq.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
|
||||||
|
erpContractReq.put("totalallamount", 0);//价税合计
|
||||||
|
erpContractReq.put("deviceqty", 0);//价税合计
|
||||||
|
erpContractReq.put("iselecsignature", false);//是否电子签章
|
||||||
|
|
||||||
|
//部门编码
|
||||||
|
String deptCode = "";
|
||||||
|
|
||||||
|
List deptIdList = contractData.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", "zyierp");//归属部门
|
||||||
|
erpContractReq.put("dept", deptCode);//归属部门
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = contractData.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", "ZHY10542");//todo 负责人
|
||||||
|
erpContractReq.put("operator", ownerCode);//todo 负责人
|
||||||
|
|
||||||
|
//合同单位
|
||||||
|
String customerId = contractData.getString("account_id");
|
||||||
|
|
||||||
|
//根据客户唯一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") != null ? customerData.getString("account_no") : "");//合同单位名称
|
||||||
|
erpContractReq.put("reccustomer_number", contractData.getString("receiver_customer__c") != null ? contractData.getString("receiver_customer__c") : "");//收获客户单位名称
|
||||||
|
//erpContractReq.put("customer_number", "Cus-000001");//合同单位名称
|
||||||
|
erpContractReq.put("settlecustomer_number", contractData.getString("billing_customer_code__c") != null ? contractData.getString("billing_customer_code__c") : "");//结算客户
|
||||||
|
erpContractReq.put("payingcustomer_number", contractData.getString("payment_customer_code__c") != null ? contractData.getString("payment_customer_code__c") : "");//付款客户
|
||||||
|
|
||||||
|
//获取产品线
|
||||||
|
erpContractReq.put("productline_number", contractData.getString("product_line__c") != null ? contractData.getString("product_line__c") : "");//产品线
|
||||||
|
|
||||||
|
//获取具体安装方式
|
||||||
|
erpContractReq.put("installationmethod", contractData.getString("installation_method__c") != null ? contractData.getString("installation_method__c") : "");//安装方式
|
||||||
|
|
||||||
|
//行业类型
|
||||||
|
erpContractReq.put("industrytype_number", contractData.getString("industry_type__c") != null ? contractData.getString("industry_type__c") : "");//行业类型
|
||||||
|
erpContractReq.put("province", contractData.getString("field_9IuQE__c__r") != null ? contractData.getString("field_9IuQE__c__r") : "");//省
|
||||||
|
erpContractReq.put("city", contractData.getString("field_9IuQE__c__r") != null ? contractData.getString("field_9IuQE__c__r") : "");//市
|
||||||
|
erpContractReq.put("county", contractData.getString("field_e9XrV__c") != null ? contractData.getString("field_e9XrV__c") : "");//县
|
||||||
|
erpContractReq.put("warranty", contractData.getBigDecimal("warranty_period_months__c") != null ? contractData.getBigDecimal("warranty_period_months__c") : 0);//质保期
|
||||||
|
|
||||||
|
//是否招投标
|
||||||
|
Boolean isBidding = null;
|
||||||
|
|
||||||
|
switch (contractData.getString("is_bidding__c")) {
|
||||||
|
case "yes":
|
||||||
|
isBidding = true;
|
||||||
|
break;
|
||||||
|
case "no":
|
||||||
|
isBidding = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
isBidding = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
erpContractReq.put("isbidding", isBidding);
|
||||||
|
|
||||||
|
erpContractReq.put("customerpropert", contractData.getString("customer_attribute__c") != null ? contractData.getString("customer_attribute__c") : "");//客户属性
|
||||||
|
erpContractReq.put("station", contractData.getString("bureau_level__c") != null ? contractData.getString("bureau_level__c") : "");//局级
|
||||||
|
|
||||||
|
//款到发货
|
||||||
|
Boolean delivery = null;
|
||||||
|
|
||||||
|
switch (contractData.getString("ship_on_payment_received__c")) {
|
||||||
|
case "yes":
|
||||||
|
delivery = true;
|
||||||
|
break;
|
||||||
|
case "no":
|
||||||
|
delivery = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
delivery = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
erpContractReq.put("delivery", delivery);
|
||||||
|
|
||||||
|
//项目来源
|
||||||
|
erpContractReq.put("projectsource", contractData.getString("project_source__c") != null ? contractData.getString("project_source__c") : "");
|
||||||
|
|
||||||
|
//销售方式
|
||||||
|
erpContractReq.put("salesmethod", contractData.getString("sales_method__c") != null ? contractData.getString("sales_method__c") : "");
|
||||||
|
|
||||||
|
//付款方式
|
||||||
|
Map paymentMethodMap = new HashMap<>();
|
||||||
|
//收款比例
|
||||||
|
paymentMethodMap.put("payrate", contractData.getBigDecimal("prepayment_ratio__c") != null ? contractData.getBigDecimal("prepayment_ratio__c") : BigDecimal.ZERO);
|
||||||
|
//预付款金额
|
||||||
|
paymentMethodMap.put("payamount", contractData.getBigDecimal("pre_invoice_amount__c") != null ? contractData.getBigDecimal("pre_invoice_amount__c") : BigDecimal.ZERO);
|
||||||
|
//是否预收
|
||||||
|
paymentMethodMap.put("isprepay", false);
|
||||||
|
|
||||||
|
erpContractReq.put("payentry", Arrays.asList(paymentMethodMap));
|
||||||
|
|
||||||
|
//根据合同号查询合同明细
|
||||||
|
JSONObject contractDetailReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "sale_contract_id", Arrays.asList(contractId))
|
||||||
|
), "SaleContractLineObj");
|
||||||
|
|
||||||
|
JSONObject contractDetailRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
contractDetailRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, contractDetailReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(contractDetailRes.getString("errorDescription")) || contractDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("合同明细查询失败或者不存在,直接跳过");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//合同明细存在,继续向下执行
|
||||||
|
List contractDetailList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object contractDetailObj : contractDetailRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject contractDetailData = JSON.parseObject(JSON.toJSONString(contractDetailObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的明细为:" + contractDetailData);
|
||||||
|
|
||||||
|
//开始封装销售合同明细
|
||||||
|
Map contractDetailMap = new HashMap();
|
||||||
|
contractDetailMap.put("linetype_number", contractTypeStr);//行类型
|
||||||
|
contractDetailMap.put("goodsname", contractDetailData.getString("product_name__c"));//产品名称
|
||||||
|
//contractDetailMap.put("material_number", contractDetailData.getString("product_id__r"));//物料编号
|
||||||
|
contractDetailMap.put("material_number", "TEST0001");//todo 物料编号
|
||||||
|
contractDetailMap.put("specification", contractDetailData.getString("specification__c") != null ? contractDetailData.getString("specification__c") : "");//规格
|
||||||
|
contractDetailMap.put("baseunit", contractDetailData.getString("unit__c__r") != null ? contractDetailData.getString("unit__c__r") : "");//单位
|
||||||
|
//contractDetailMap.put("baseunit", "TEST0001");//todo 单位
|
||||||
|
contractDetailMap.put("unit_number", contractDetailData.getString("unit__c") != null ? contractDetailData.getString("unit__c") : "");//单位编码
|
||||||
|
contractDetailMap.put("unit1_number", contractDetailData.getString("unit__c") != null ? contractDetailData.getString("unit__c") : "");//单位编码
|
||||||
|
contractDetailMap.put("f9w5_unit1_number", contractDetailData.getString("unit__c") != null ? contractDetailData.getString("unit__c") : "");//单位编码
|
||||||
|
contractDetailMap.put("baseqty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
|
||||||
|
contractDetailMap.put("qty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
|
||||||
|
contractDetailMap.put("priceandtax", contractDetailData.getBigDecimal("sales_price") != null ? contractDetailData.getBigDecimal("sales_price") : 0);//含税单价
|
||||||
|
//contractDetailMap.put("taxrateid_number", contractDetailData.getBigDecimal("tax_rate__c") != null ? contractDetailData.getBigDecimal("tax_rate__c") : 0);//税率
|
||||||
|
contractDetailMap.put("taxrateid_number", "V13");//税率
|
||||||
|
contractDetailMap.put("curamountandtax", contractDetailData.getBigDecimal("subtotal") != null ? contractDetailData.getBigDecimal("subtotal") : 0);//价税合计
|
||||||
|
//contractDetailMap.put("curtaxamount", contractDetailData.getBigDecimal("tax_amount__c") != null ? contractDetailData.getBigDecimal("tax_amount__c") : 0);//金额
|
||||||
|
contractDetailMap.put("crmentryid", contractDetailData.getString("_id"));//明细id
|
||||||
|
|
||||||
|
contractDetailList.add(contractDetailMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装明细
|
||||||
|
erpContractReq.put("billentry", contractDetailList);
|
||||||
|
|
||||||
|
System.out.println("erp请求为:" + JSON.parseObject(JSON.toJSONString(erpContractReq)));
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(contractRes)));
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", contractId);
|
||||||
|
backReqMap.put("dataObjectApiName", "SaleContractObj");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "XSHTQC");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", contractName);
|
||||||
|
logMap.put("data_id", contractId);
|
||||||
|
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);
|
||||||
|
|
||||||
|
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
|
||||||
|
|
||||||
|
JSONObject backRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, 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);
|
||||||
|
|
||||||
|
log.info("开始同步销售合同附件");
|
||||||
|
|
||||||
|
//判断销售合同是否执行成功
|
||||||
|
String contractERPID = "";
|
||||||
|
|
||||||
|
if ("0".equals(contractRes.getString("errorCode"))) {
|
||||||
|
log.info("销售合同执行成功");
|
||||||
|
contractERPID = contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id");
|
||||||
|
} else {
|
||||||
|
log.info("销售合同执行失败,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List contractFileList = contractData.getJSONArray("contract_attachment__c") != null ? contractData.getJSONArray("contract_attachment__c") : new ArrayList();
|
||||||
|
|
||||||
|
if (contractFileList == null || contractFileList.isEmpty()) {
|
||||||
|
log.info("该销售合同不存在附件,将不再向下执行。");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("附件存在,继续向下执行");
|
||||||
|
|
||||||
|
MultiValueMap<String, Object> body = crmRequestUtil.contractFile(contractFileList, Long.parseLong(contractERPID));
|
||||||
|
|
||||||
|
//开始封装请求实体
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
httpHeaders.set("accessToken", accessToken);
|
||||||
|
|
||||||
|
HttpEntity entity = new HttpEntity(body, httpHeaders);
|
||||||
|
|
||||||
|
//开始发起传输
|
||||||
|
JSONObject fileRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
fileRes = restTemplate.postForObject(ERPURLConstant.ERP_URL + "/ierp/kapi/v2/frame/attachment/uploadFile", entity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("附件上传结果为:" + fileRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,8 +41,9 @@ public class VendorController {
|
|||||||
|
|
||||||
JSONObject getVendor = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject getVendor = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "life_status", Arrays.asList("normal")),
|
new Filter("EQ", "life_status", Arrays.asList("normal")),
|
||||||
new Filter("EQ", "name", Arrays.asList("山东研了究的僧教育科技有限公司")),
|
//new Filter("EQ", "name", Arrays.asList("山东研了究的僧教育科技有限公司")),
|
||||||
new Filter("EQ", "sync_status__c", Arrays.asList("option_pending_sync__c"))
|
new Filter("EQ", "sync_status__c", Arrays.asList("option_pending_sync__c")),
|
||||||
|
new Filter("GT", "create_time", Arrays.asList("1751035349267"))
|
||||||
), "SupplierObj");
|
), "SupplierObj");
|
||||||
|
|
||||||
JSONObject vendorRes = new JSONObject();
|
JSONObject vendorRes = new JSONObject();
|
||||||
@ -144,7 +145,7 @@ public class VendorController {
|
|||||||
vendorReq.put("data", Arrays.asList(vendorMap));
|
vendorReq.put("data", Arrays.asList(vendorMap));
|
||||||
|
|
||||||
//开始获取token
|
//开始获取token
|
||||||
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
String accessToken = new KDTokenController().getKDAccessToken();
|
||||||
|
|
||||||
if (accessToken == null || accessToken.equals("")) {
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
log.info("金蝶token为空或不存在");
|
log.info("金蝶token为空或不存在");
|
||||||
@ -161,7 +162,8 @@ public class VendorController {
|
|||||||
|
|
||||||
System.out.println(JSON.parseObject(JSON.toJSONString(vendorReqEntity)));
|
System.out.println(JSON.parseObject(JSON.toJSONString(vendorReqEntity)));
|
||||||
|
|
||||||
String vendorUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/basedata/bd_supplier/bdSupplierSave";
|
//String vendorUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/basedata/bd_supplier/bdSupplierSave";
|
||||||
|
String vendorUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/basedata/bd_supplier/bdSupplierSave";
|
||||||
|
|
||||||
JSONObject vendorERPRes = new JSONObject();
|
JSONObject vendorERPRes = new JSONObject();
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ public class DeviceInstallController {
|
|||||||
System.out.println(JSON.parseObject(JSON.toJSONString(reqEntity)));
|
System.out.println(JSON.parseObject(JSON.toJSONString(reqEntity)));
|
||||||
|
|
||||||
//开始发起请求
|
//开始发起请求
|
||||||
String deviceUrl = "http://192.168.5.55:9011/crm/initInstallationDevice";
|
String deviceUrl = "http://192.168.5.55:9011/crm/updateDeviceContract";
|
||||||
|
|
||||||
JSONObject deviceResult = new JSONObject();
|
JSONObject deviceResult = new JSONObject();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user