销售合同竣工状态筛选条件优化,供应商新需求更新
This commit is contained in:
parent
e418474a07
commit
e56e462009
@ -2,6 +2,7 @@ package com.management.controller;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.management.constant.CertificateConstant;
|
||||||
import com.management.constant.ERPURLConstant;
|
import com.management.constant.ERPURLConstant;
|
||||||
import com.management.constant.URLConstant;
|
import com.management.constant.URLConstant;
|
||||||
import com.management.entity.Filter;
|
import com.management.entity.Filter;
|
||||||
@ -74,6 +75,83 @@ public class VendorController {
|
|||||||
String vendorName = vendorData.getString("name");
|
String vendorName = vendorData.getString("name");
|
||||||
String createTime = vendorData.getString("last_modified_time");
|
String createTime = vendorData.getString("last_modified_time");
|
||||||
|
|
||||||
|
//根据供应商名称查询是否已存在重名数据
|
||||||
|
JSONObject getRepeatedVendor = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList(vendorName)),
|
||||||
|
new Filter("N", "record_type", Arrays.asList("record_ev1gl__c")),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "SupplierObj");
|
||||||
|
|
||||||
|
JSONObject repeatedVendorRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
repeatedVendorRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getRepeatedVendor, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(repeatedVendorRes.getString("errorDescription")) && !repeatedVendorRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("存在重名的数据");
|
||||||
|
|
||||||
|
//开始获取关键数据
|
||||||
|
JSONObject repeatedVendorData = repeatedVendorRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的数据为:" + repeatedVendorData);
|
||||||
|
|
||||||
|
//开始获取该数据的ERP信息
|
||||||
|
String erpId = repeatedVendorData.getString("erp_number__c") != null ? repeatedVendorData.getString("erp_number__c") : "";
|
||||||
|
|
||||||
|
String updateRes = updateVendorType(repeatedVendorData);
|
||||||
|
|
||||||
|
String isSuccess = "";
|
||||||
|
|
||||||
|
if ("同步更新状态成功".equals(updateRes)) {
|
||||||
|
isSuccess = "option_sync_success__c";
|
||||||
|
} else {
|
||||||
|
isSuccess = "option_sync_failure__c";
|
||||||
|
}
|
||||||
|
|
||||||
|
//将当前单据的单位编号改成重名供应商的erp单据编号
|
||||||
|
Map valueMap = new HashMap<>();
|
||||||
|
valueMap.put("_id", vendorId);
|
||||||
|
valueMap.put("erpCode", erpId);
|
||||||
|
valueMap.put("isSuccess", isSuccess);
|
||||||
|
valueMap.put("status", updateRes);
|
||||||
|
|
||||||
|
Map parameters = new HashMap<>();
|
||||||
|
parameters.put("value", valueMap);
|
||||||
|
parameters.put("name", "syncArg");
|
||||||
|
parameters.put("type", "Map");
|
||||||
|
|
||||||
|
Map dataMap = new HashMap<>();
|
||||||
|
dataMap.put("api_name", "CstmCtrl_ZdkhQ__c");
|
||||||
|
dataMap.put("postId", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
dataMap.put("parameters", Arrays.asList(parameters));
|
||||||
|
|
||||||
|
Map erpVendorReq = new HashMap<>();
|
||||||
|
erpVendorReq.put("corpAccessToken", crmRequestUtil.getCRMToken());
|
||||||
|
erpVendorReq.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
|
||||||
|
erpVendorReq.put("corpId", CertificateConstant.CORP_ID);
|
||||||
|
erpVendorReq.put("data", dataMap);
|
||||||
|
|
||||||
|
JSONObject erpVendorRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpVendorRes = restTemplate.postForObject("https://open.fxiaoke.com/cgi/crm/v2/special/function", erpVendorReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("供应商回写结果为:" + erpVendorRes);
|
||||||
|
|
||||||
|
if (!erpVendorRes.getString("errorCode").equals("0")) {
|
||||||
|
log.info("供应商回写失败");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//开始查询日子是否存在当前单据
|
//开始查询日子是否存在当前单据
|
||||||
JSONObject isLog = new JSONObject();
|
JSONObject isLog = new JSONObject();
|
||||||
|
|
||||||
@ -449,4 +527,122 @@ public class VendorController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改erp中的供应商类型
|
||||||
|
*
|
||||||
|
* @param vendorData
|
||||||
|
* @return void
|
||||||
|
* @param:
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
public String updateVendorType(JSONObject vendorData) {
|
||||||
|
if (vendorData == null) {
|
||||||
|
return "同步失败,vendorData为null";
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的供应商数据为:" + vendorData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
String vendorId = vendorData.getString("_id");
|
||||||
|
String vendorName = vendorData.getString("name");
|
||||||
|
String createTime = vendorData.getString("last_modified_time");
|
||||||
|
String erpId = vendorData.getString("erp_id__c") != null ? vendorData.getString("erp_id__c") : "";
|
||||||
|
|
||||||
|
if ("".equals(erpId)){
|
||||||
|
log.info("当前单据erp_id__c为空,不再向下执行");
|
||||||
|
return "当前单据erp_id__c为空,不再向下执行";
|
||||||
|
}
|
||||||
|
|
||||||
|
Map vendorMap = new HashMap<>();
|
||||||
|
vendorMap.put("id", erpId);
|
||||||
|
vendorMap.put("createorg_number", "zyierp");
|
||||||
|
vendorMap.put("f9w5_isconstruction", true);
|
||||||
|
|
||||||
|
//供应商最终请求
|
||||||
|
Map vendorReq = new HashMap<>();
|
||||||
|
vendorReq.put("data", Arrays.asList(vendorMap));
|
||||||
|
|
||||||
|
//开始获取token
|
||||||
|
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
||||||
|
|
||||||
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
|
log.info("金蝶token为空或不存在");
|
||||||
|
return "失败,金蝶token为空";
|
||||||
|
}
|
||||||
|
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 vendorReqEntity = new HttpEntity(vendorReq, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(vendorReqEntity)));
|
||||||
|
|
||||||
|
//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/bdSupplierUpdate";
|
||||||
|
|
||||||
|
JSONObject vendorERPRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
vendorERPRes = restTemplate.postForObject(vendorUrl, vendorReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(vendorERPRes);
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", vendorId);
|
||||||
|
backReqMap.put("dataObjectApiName", "SupplierObj");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "供应商更新状态");
|
||||||
|
logMap.put("syn_type", "1");
|
||||||
|
logMap.put("data_name", vendorName);
|
||||||
|
logMap.put("data_id", vendorId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(vendorReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(vendorERPRes));
|
||||||
|
logMap.put("tableName", "send_log_vendor");
|
||||||
|
|
||||||
|
|
||||||
|
String result = "";
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(vendorERPRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", vendorERPRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_status__c", "更新操作同步成功");
|
||||||
|
result = "同步更新状态成功";
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + vendorERPRes.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_status__c", "更新失败:" + vendorERPRes.getString("message"));
|
||||||
|
result = "同步更新状态失败:" + vendorERPRes.getString("message");
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始记录日志
|
||||||
|
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);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1005,7 +1005,8 @@ public class XSHTController {
|
|||||||
JSONObject contractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject contractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
//new Filter("EQ", "name", Arrays.asList("ZHY2505180013")),
|
//new Filter("EQ", "name", Arrays.asList("ZHY2505180013")),
|
||||||
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
|
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
|
||||||
new Filter("N", "is_initial__c", Arrays.asList("true")),
|
//new Filter("N", "is_initial__c", Arrays.asList("true")),
|
||||||
|
new Filter("EQ", "completion_sync_status__c", Arrays.asList("option_pending_sync__c")),
|
||||||
new Filter("EQ", "is_completed__c", Arrays.asList("yes"))
|
new Filter("EQ", "is_completed__c", Arrays.asList("yes"))
|
||||||
), "SaleContractObj");
|
), "SaleContractObj");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user