金蝶部分集成程序
This commit is contained in:
parent
f91f1716ab
commit
426a2ccb3e
@ -8,15 +8,15 @@ package org.ssssssss.magicboot.constant;
|
|||||||
* @Author weiloong_zhang
|
* @Author weiloong_zhang
|
||||||
*/
|
*/
|
||||||
public class CertificateConstant {
|
public class CertificateConstant {
|
||||||
// public static final String APP_ID = "FSAID_131f56a";//appId
|
public static final String APP_ID = "FSAID_131f56a";//appId
|
||||||
// public static final String PERMANENT_CODE = "1A49B50861909007935CAB5E33E52BAA";//永久授权码
|
public static final String PERMANENT_CODE = "1A49B50861909007935CAB5E33E52BAA";//永久授权码
|
||||||
// public static final String APP_SECRET = "5bda722932a54e80a05d2cc9b1722fed";//appSecret
|
public static final String APP_SECRET = "5bda722932a54e80a05d2cc9b1722fed";//appSecret
|
||||||
// public static final String CORP_ID = "FSCID_11F505C980B5FE43D5D7230567802E09";//企业Id
|
public static final String CORP_ID = "FSCID_11F505C980B5FE43D5D7230567802E09";//企业Id
|
||||||
// public static final String CURRENT_OPEN_USERID = "FSUID_50D3C26809B163F663DC8557268A8D44";//当前登录用户id
|
public static final String CURRENT_OPEN_USERID = "FSUID_50D3C26809B163F663DC8557268A8D44";//当前登录用户id
|
||||||
|
|
||||||
public static final String APP_ID = "FSAID_131fa51";//appId
|
// public static final String APP_ID = "FSAID_131fa51";//appId
|
||||||
public static final String PERMANENT_CODE = "EF03533F6929B59934A7E1155221420B";//永久授权码
|
// public static final String PERMANENT_CODE = "EF03533F6929B59934A7E1155221420B";//永久授权码
|
||||||
public static final String APP_SECRET = "1ce9804037ff4baf9d308bd32a4ec6ef";//appSecret
|
// public static final String APP_SECRET = "1ce9804037ff4baf9d308bd32a4ec6ef";//appSecret
|
||||||
public static final String CORP_ID = "FSCID_EC935623350FB07DBF52F84F49874A81";//企业Id
|
// public static final String CORP_ID = "FSCID_EC935623350FB07DBF52F84F49874A81";//企业Id
|
||||||
public static final String CURRENT_OPEN_USERID = "FSUID_7B52D1CF1B01E5A2A143E250A5B60595";//当前登录用户id
|
// public static final String CURRENT_OPEN_USERID = "FSUID_7B52D1CF1B01E5A2A143E250A5B60595";//当前登录用户id
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,436 @@
|
|||||||
|
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.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/bank")
|
||||||
|
@Slf4j
|
||||||
|
public class BankInfoController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new BankInfoController().updateBankInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 银行信息同步接口
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/bankInfo")
|
||||||
|
public void syncBankInfo() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
log.info("开始同步银行信息");
|
||||||
|
|
||||||
|
//获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
log.info("当前时间:{}", now);
|
||||||
|
//获取两天前的时间
|
||||||
|
LocalDateTime twoDaysAgo = now.minusDays(2);
|
||||||
|
|
||||||
|
//将时间转换样式
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String twoDaysAgoStr = twoDaysAgo.format(formatter);
|
||||||
|
|
||||||
|
//开始查询部门(暂时使用固定值)
|
||||||
|
Map data = new HashMap<>();
|
||||||
|
data.put("createtime", twoDaysAgoStr);
|
||||||
|
//data.put("number", Arrays.asList("ZHY002.005.003.004"));
|
||||||
|
// data.put("level", "3");
|
||||||
|
|
||||||
|
Map deptReq = new HashMap<>();
|
||||||
|
deptReq.put("data", data);
|
||||||
|
deptReq.put("pageNo", 1);
|
||||||
|
deptReq.put("pageSize", 1);
|
||||||
|
|
||||||
|
//开始获取金蝶token
|
||||||
|
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
||||||
|
|
||||||
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
|
log.info("金蝶token为空或不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装请求头
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("accessToken", accessToken);
|
||||||
|
|
||||||
|
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
String bankInfoUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
||||||
|
|
||||||
|
String bankInfoResStr = "";
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
try {
|
||||||
|
bankInfoResStr = restTemplate.postForObject(bankInfoUrl, bankReqEntity, String.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject bankInfoRes = JSONObject.parseObject(bankInfoResStr);
|
||||||
|
|
||||||
|
System.out.println("金蝶银行信息结果为:" + bankInfoRes);
|
||||||
|
|
||||||
|
if (!"0".equals(bankInfoRes.getString("errorCode")) || bankInfoRes.getJSONObject("data").isEmpty() || bankInfoRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
|
||||||
|
log.info("金蝶查询银行信息失败或者没有符合条件的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("数据存在,将继续向下执行");
|
||||||
|
|
||||||
|
for (Object bankInfoObj : bankInfoRes.getJSONObject("data").getJSONArray("rows")) {
|
||||||
|
JSONObject bankInfoData = JSON.parseObject(JSON.toJSONString(bankInfoObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的银行信息数据为:" + bankInfoData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//银行名称
|
||||||
|
String bankName = bankInfoData.getString("name");
|
||||||
|
//行号
|
||||||
|
String bankNumber = bankInfoData.getString("number");
|
||||||
|
//todo 创建时间
|
||||||
|
String createTime = "2025-05-14 00:00:00";
|
||||||
|
|
||||||
|
//开始查询是否已经集成过了
|
||||||
|
JSONObject isLog = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLog = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_bank&log_type=BANK&dataId=" + bankNumber + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLog.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前银行已经集成过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装数据
|
||||||
|
Map bankInfoMap = new HashMap<>();
|
||||||
|
bankInfoMap.put("name", bankNumber);//行号
|
||||||
|
bankInfoMap.put("bank_name__c", bankName);//银行名称
|
||||||
|
bankInfoMap.put("province__c", bankInfoData.getString("province_name") != null ? bankInfoData.getString("province_name") : "");//省份
|
||||||
|
bankInfoMap.put("city_banking__c", bankInfoData.getString("city_name") != null ? bankInfoData.getString("city_name") : "");//市
|
||||||
|
bankInfoMap.put("country_region__c", bankInfoData.getString("country_fullname") != null ? bankInfoData.getString("country_fullname") : "");//国家地区
|
||||||
|
bankInfoMap.put("branch_number__c", bankInfoData.getString("union_number") != null ? bankInfoData.getString("union_number") : "");//联行号
|
||||||
|
bankInfoMap.put("dataObjectApiName", "bank_info__c");
|
||||||
|
|
||||||
|
//发起请求前查询是否已存在该数据
|
||||||
|
JSONObject isCrmExist = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList(bankNumber)),
|
||||||
|
new Filter("EQ", "bank_name__c", Arrays.asList(bankName))
|
||||||
|
), "bank_info__c");
|
||||||
|
|
||||||
|
JSONObject isCrmExistRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isCrmExistRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, isCrmExist, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(isCrmExistRes.getString("errorDescription")) && !isCrmExistRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("数据已存在,将执行更新");
|
||||||
|
JSONObject isCrmExistData = isCrmExistRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
bankInfoMap.put("_id", isCrmExistData.getString("_id"));
|
||||||
|
|
||||||
|
//更新请求
|
||||||
|
JSONObject updateReq = crmRequestUtil.updateCRM(bankInfoMap);
|
||||||
|
|
||||||
|
JSONObject updateRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, updateReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("更新结果为:" + JSON.parseObject(JSON.toJSONString(updateRes)));
|
||||||
|
|
||||||
|
//记录日志
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "BANKUP");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", bankName);
|
||||||
|
logMap.put("data_id", bankNumber);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(updateReq));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(updateRes));
|
||||||
|
logMap.put("tableName", "send_log_bank");
|
||||||
|
|
||||||
|
//判断
|
||||||
|
if ("success".equals(updateRes.getString("errorDescription"))) {
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
} else {
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败" + updateRes.getString("errorMessage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject logRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.postForObject("http://localhost:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("数据不存在,将执行创建");
|
||||||
|
|
||||||
|
JSONObject createReq = crmRequestUtil.createCRM(bankInfoMap);
|
||||||
|
|
||||||
|
JSONObject createRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
createRes = restTemplate.postForObject(URLConstant.CREATE_CRM_CUSTOMER_MAIN, createReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("创建结果为:" + JSON.parseObject(JSON.toJSONString(createRes)));
|
||||||
|
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "BANK");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", bankName);
|
||||||
|
logMap.put("data_id", bankNumber);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(createReq));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(createRes));
|
||||||
|
logMap.put("tableName", "send_log_bank");
|
||||||
|
|
||||||
|
//判断
|
||||||
|
if ("success".equals(createRes.getString("errorDescription"))) {
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
} else {
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败" + createRes.getString("errorMessage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject logRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.postForObject("http://localhost:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 银行信息更新方法
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/update/bankInfo")
|
||||||
|
public void updateBankInfo() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
log.info("开始同步银行信息");
|
||||||
|
|
||||||
|
//获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
log.info("当前时间:{}", now);
|
||||||
|
//获取两天前的时间
|
||||||
|
LocalDateTime twoDaysAgo = now.minusDays(2);
|
||||||
|
|
||||||
|
//将时间转换样式
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String twoDaysAgoStr = twoDaysAgo.format(formatter);
|
||||||
|
|
||||||
|
//开始查询部门(暂时使用固定值)
|
||||||
|
Map data = new HashMap<>();
|
||||||
|
data.put("modifytime", twoDaysAgoStr);
|
||||||
|
//data.put("number", Arrays.asList("ZHY002.005.003.004"));
|
||||||
|
// data.put("level", "3");
|
||||||
|
|
||||||
|
Map deptReq = new HashMap<>();
|
||||||
|
deptReq.put("data", data);
|
||||||
|
deptReq.put("pageNo", 1);
|
||||||
|
deptReq.put("pageSize", 1);
|
||||||
|
|
||||||
|
//开始获取金蝶token
|
||||||
|
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
||||||
|
|
||||||
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
|
log.info("金蝶token为空或不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装请求头
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("accessToken", accessToken);
|
||||||
|
|
||||||
|
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
String bankInfoUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
|
||||||
|
|
||||||
|
String bankInfoResStr = "";
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
try {
|
||||||
|
bankInfoResStr = restTemplate.postForObject(bankInfoUrl, bankReqEntity, String.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject bankInfoRes = JSONObject.parseObject(bankInfoResStr);
|
||||||
|
|
||||||
|
System.out.println("金蝶银行信息结果为:" + bankInfoRes);
|
||||||
|
|
||||||
|
if (!"0".equals(bankInfoRes.getString("errorCode")) || bankInfoRes.getJSONObject("data").isEmpty() || bankInfoRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
|
||||||
|
log.info("金蝶查询银行信息失败或者没有符合条件的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("数据存在,将继续向下执行");
|
||||||
|
|
||||||
|
for (Object bankInfoObj : bankInfoRes.getJSONObject("data").getJSONArray("rows")) {
|
||||||
|
JSONObject bankInfoData = JSON.parseObject(JSON.toJSONString(bankInfoObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的银行信息数据为:" + bankInfoData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//银行名称
|
||||||
|
String bankName = bankInfoData.getString("name");
|
||||||
|
//行号
|
||||||
|
String bankNumber = bankInfoData.getString("number");
|
||||||
|
//todo 最新更新时间
|
||||||
|
String modifyTime = "2025-05-14 00:00:00";
|
||||||
|
|
||||||
|
//开始查询是否已经集成过了
|
||||||
|
JSONObject isLog = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLog = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_bank&log_type=BANKUP&dataId=" + bankNumber + "&mark=" + modifyTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLog.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前银行已经集成过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装数据
|
||||||
|
Map bankInfoMap = new HashMap<>();
|
||||||
|
bankInfoMap.put("name", bankNumber);//行号
|
||||||
|
bankInfoMap.put("bank_name__c", bankName);//银行名称
|
||||||
|
bankInfoMap.put("province__c", bankInfoData.getString("province_name") != null ? bankInfoData.getString("province_name") : "");//省份
|
||||||
|
bankInfoMap.put("city_banking__c", bankInfoData.getString("city_name") != null ? bankInfoData.getString("city_name") : "");//市
|
||||||
|
bankInfoMap.put("country_region__c", bankInfoData.getString("country_fullname") != null ? bankInfoData.getString("country_fullname") : "");//国家地区
|
||||||
|
bankInfoMap.put("branch_number__c", bankInfoData.getString("union_number") != null ? bankInfoData.getString("union_number") : "");//联行号
|
||||||
|
bankInfoMap.put("dataObjectApiName", "bank_info__c");
|
||||||
|
|
||||||
|
//发起请求前查询是否已存在该数据
|
||||||
|
JSONObject isCrmExist = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList(bankNumber)),
|
||||||
|
new Filter("EQ", "bank_name__c", Arrays.asList(bankName))
|
||||||
|
), "bank_info__c");
|
||||||
|
|
||||||
|
JSONObject isCrmExistRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isCrmExistRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, isCrmExist, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(isCrmExistRes.getString("errorDescription")) || isCrmExistRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("数据不存在或者查询失败,将不再继续向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject isCrmExistData = isCrmExistRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
bankInfoMap.put("_id", isCrmExistData.getString("_id"));
|
||||||
|
|
||||||
|
//更新请求
|
||||||
|
JSONObject updateReq = crmRequestUtil.updateCRM(bankInfoMap);
|
||||||
|
|
||||||
|
JSONObject updateRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, updateReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("更新结果为:" + JSON.parseObject(JSON.toJSONString(updateRes)));
|
||||||
|
|
||||||
|
//记录日志
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "BANKUP");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", bankName);
|
||||||
|
logMap.put("data_id", bankNumber);
|
||||||
|
logMap.put("mark", modifyTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(updateReq));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(updateRes));
|
||||||
|
logMap.put("tableName", "send_log_bank");
|
||||||
|
|
||||||
|
//判断
|
||||||
|
if ("success".equals(updateRes.getString("errorDescription"))) {
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
} else {
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败" + updateRes.getString("errorMessage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject logRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.postForObject("http://localhost:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志记录结果为:" + logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -47,7 +47,7 @@ public class DesignController {
|
|||||||
log.info("开始同步设计文件");
|
log.info("开始同步设计文件");
|
||||||
|
|
||||||
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "name", Arrays.asList("SJWJ250509-0003"))
|
new Filter("EQ", "name", Arrays.asList("SJWJ250522-0013"))
|
||||||
), "design_file__c");
|
), "design_file__c");
|
||||||
|
|
||||||
JSONObject designDocRes = new JSONObject();
|
JSONObject designDocRes = new JSONObject();
|
||||||
@ -99,8 +99,8 @@ public class DesignController {
|
|||||||
//开始封装传输至ERP中的请求
|
//开始封装传输至ERP中的请求
|
||||||
Map erpDesignMap = new HashMap<>();
|
Map erpDesignMap = new HashMap<>();
|
||||||
erpDesignMap.put("billno", designDocName);//设计文件编号
|
erpDesignMap.put("billno", designDocName);//设计文件编号
|
||||||
erpDesignMap.put("org_number", "zyierp");//组织编码
|
erpDesignMap.put("org_number", "ZHY");//组织编码
|
||||||
erpDesignMap.put("billtype_number", "pm_requirapplybill_STD_BT_S");//单据类型
|
erpDesignMap.put("billtype_number", "pm_requirapplybill_BT_sjwjxf");//单据类型
|
||||||
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
|
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
|
||||||
|
|
||||||
//开始获取单据日期
|
//开始获取单据日期
|
||||||
@ -132,7 +132,7 @@ public class DesignController {
|
|||||||
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
erpDesignMap.put("dept_number", "zyierp");//部门编码
|
erpDesignMap.put("dept_number", "004");//部门编码
|
||||||
|
|
||||||
//获取负责人编码
|
//获取负责人编码
|
||||||
String ownerCode = "";
|
String ownerCode = "";
|
||||||
@ -157,9 +157,9 @@ public class DesignController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
|
erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
|
||||||
erpDesignMap.put("bizorg_number", "zyierp");//采购组织
|
erpDesignMap.put("bizorg_number", "ZHY");//采购组织
|
||||||
erpDesignMap.put("project_number", designDocData.getString("project_id__c"));//todo 项目号(商机)
|
erpDesignMap.put("project_number", "SJ20250424-0033");//todo 项目号(商机)
|
||||||
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
|
erpDesignMap.put("contractno", designDocData.getString("pre_signed_contract_id__c__r"));//合同号
|
||||||
erpDesignMap.put("crmid", designDocId);//crm唯一id
|
erpDesignMap.put("crmid", designDocId);//crm唯一id
|
||||||
erpDesignMap.put("comment", designDocData.getString("remark__c") != null ? designDocData.getString("remark__c") : "");//备注
|
erpDesignMap.put("comment", designDocData.getString("remark__c") != null ? designDocData.getString("remark__c") : "");//备注
|
||||||
|
|
||||||
|
@ -0,0 +1,318 @@
|
|||||||
|
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.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/frame")
|
||||||
|
@Slf4j
|
||||||
|
public class FrameContractController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new FrameContractController().syncFrameContract();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步框架合同
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public void syncFrameContract() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject frameContract = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("KJ2505200005"))
|
||||||
|
), "framework_contract__c");
|
||||||
|
|
||||||
|
JSONObject frameContractRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
frameContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, frameContract, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(frameContractRes.getString("errorDescription")) || frameContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("查询失败或者不存在符合条件的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("查询成功,继续向下执行");
|
||||||
|
|
||||||
|
for (Object frameContractObj : frameContractRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject frameContractData = JSON.parseObject(JSON.toJSONString(frameContractObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的框架合同数据为:" + frameContractData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
String frameContractId = frameContractData.getString("_id");
|
||||||
|
//合同名称
|
||||||
|
String frameContractName = frameContractData.getString("name");
|
||||||
|
//创建时间
|
||||||
|
String createTime = frameContractData.getString("create_time");
|
||||||
|
|
||||||
|
//开始查询是否已经集成过该合同
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_htxx&log_type=KJHT&dataId=" + frameContractId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
//开始封装数据
|
||||||
|
Map frameContractReqMap = new HashMap<>();
|
||||||
|
frameContractReqMap.put("billno", frameContractName);//合同编号
|
||||||
|
frameContractReqMap.put("crmid", frameContractId);//合同编号
|
||||||
|
|
||||||
|
//开始查询商机编号
|
||||||
|
String businessId = frameContractData.getString("business_opportunity__c") != null ? frameContractData.getString("business_opportunity__c") : "";
|
||||||
|
|
||||||
|
if (businessId == null || businessId.equals("")) {
|
||||||
|
log.info("当前数据没有商机编号,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject businessReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(businessId))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject businessRes = new JSONObject();
|
||||||
|
|
||||||
|
businessRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, businessReq, JSONObject.class);
|
||||||
|
|
||||||
|
String projectCode = "";
|
||||||
|
if ("success".equals(businessRes.getString("errorDescription")) && !businessRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject businessData = businessRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
projectCode = businessData.getString("opportunity_id__c");
|
||||||
|
}
|
||||||
|
|
||||||
|
frameContractReqMap.put("project_number", "SJ20250424-0033");//todo 项目号(商机编号)
|
||||||
|
frameContractReqMap.put("billtype_number", "conm_salcontract_BT_QD");//erp单据类型
|
||||||
|
frameContractReqMap.put("zhybilltype", frameContractData.getString("contract_type__c") != null ? frameContractData.getString("contract_type__c") : "");//合同类型
|
||||||
|
frameContractReqMap.put("billname", frameContractData.getString("contract_name__c") != null ? frameContractData.getString("contract_name__c") : "");//合同名称
|
||||||
|
frameContractReqMap.put("type_number", "XSHT-QD03");//合同类型
|
||||||
|
frameContractReqMap.put("contparties_number", "BU-0002");//合同主体
|
||||||
|
frameContractReqMap.put("createorg_number", "zyierp");//销售组织编码
|
||||||
|
frameContractReqMap.put("org_number", "zyierp");//销售组织编码
|
||||||
|
frameContractReqMap.put("currency_number", "CNY");//本位币.货币代码
|
||||||
|
frameContractReqMap.put("settlecurrency_number", "CNY");//结算币别.货币代码
|
||||||
|
|
||||||
|
long signDate = frameContractData.getLong("signing_date__c");
|
||||||
|
|
||||||
|
frameContractReqMap.put("biztime", signDate);//签订日期,单据日期
|
||||||
|
frameContractReqMap.put("biztimebegin", signDate);//起始日期
|
||||||
|
frameContractReqMap.put("biztimeend", signDate);//截止日期
|
||||||
|
|
||||||
|
frameContractReqMap.put("party1st", frameContractData.getString("contract_unit_name__c__r") != null ? frameContractData.getString("contract_unit_name__c__r") : "");//甲方
|
||||||
|
frameContractReqMap.put("party2nd", frameContractData.getString("our_company_name__c__r") != null ? frameContractData.getString("our_company_name__c__r") : "");//乙方
|
||||||
|
frameContractReqMap.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
|
||||||
|
|
||||||
|
//部门编码
|
||||||
|
String deptCode = "";
|
||||||
|
|
||||||
|
List deptIdList = frameContractData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
frameContractReqMap.put("dept", deptCode);//归属部门
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = frameContractData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
frameContractReqMap.put("operator", "ZHY12025");//todo 负责人
|
||||||
|
|
||||||
|
//合同单位
|
||||||
|
String customerId = frameContractData.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"));//合同单位名称
|
||||||
|
frameContractReqMap.put("customer_number", "Cus-000007");//todo 合同单位名称
|
||||||
|
|
||||||
|
//获取产品线
|
||||||
|
|
||||||
|
frameContractReqMap.put("productline_number", frameContractData.getString("product_line__c"));//产品线
|
||||||
|
|
||||||
|
//获取具体安装方式
|
||||||
|
|
||||||
|
frameContractReqMap.put("installationmethod", frameContractData.getString("installation_method__c"));//安装方式
|
||||||
|
|
||||||
|
//行业类型
|
||||||
|
frameContractReqMap.put("industrytype_number", frameContractData.getString("industry_type__c"));//行业类型
|
||||||
|
frameContractReqMap.put("province", frameContractData.getString("field_t3fgo__c__r"));//省
|
||||||
|
frameContractReqMap.put("city", frameContractData.getString("field_ngwth__c__r"));//市
|
||||||
|
frameContractReqMap.put("county", frameContractData.getString("field_K5p2C__c__r"));//县
|
||||||
|
frameContractReqMap.put("station", frameContractData.getString("single_choice__c") != null ? frameContractData.getString("single_choice__c") : "");//局级
|
||||||
|
frameContractReqMap.put("delivery", frameContractData.getString("ship_on_payment_received__c") != null ? frameContractData.getString("ship_on_payment_received__c") : "");//款到发货
|
||||||
|
frameContractReqMap.put("projectsource", frameContractData.getString("project_source__c") != null ? frameContractData.getString("project_source__c") : "");//项目来源
|
||||||
|
frameContractReqMap.put("salesmethod", frameContractData.getString("sales_method__c") != null ? frameContractData.getString("sales_method__c") : "");//销售方式
|
||||||
|
|
||||||
|
Map erpFrameContractReqMap = new HashMap<>();
|
||||||
|
erpFrameContractReqMap.put("data", Arrays.asList(frameContractReqMap));//请求体
|
||||||
|
|
||||||
|
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(erpFrameContractReqMap, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
|
||||||
|
|
||||||
|
//开始向金蝶发起请求
|
||||||
|
String contractUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/conm/conm_salcontract/savecontract";
|
||||||
|
|
||||||
|
JSONObject contractRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
contractRes = restTemplate.postForObject(contractUrl, contractReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", frameContractId);
|
||||||
|
backReqMap.put("dataObjectApiName", "framework_contract__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "KJHT");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", frameContractName);
|
||||||
|
logMap.put("data_id", frameContractId);
|
||||||
|
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", "同步成功");
|
||||||
|
} 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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,531 @@
|
|||||||
|
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.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/invoice")
|
||||||
|
@Slf4j
|
||||||
|
public class InvoiceController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//new InvoiceController().syncInvoice();
|
||||||
|
new InvoiceController().syncRedInvoice();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发票同步
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync_invoice")
|
||||||
|
public void syncInvoice() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject getInvoice = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("20250522-000007"))
|
||||||
|
), "InvoiceApplicationObj");
|
||||||
|
|
||||||
|
log.info("开始同步创建发票");
|
||||||
|
|
||||||
|
JSONObject invoiceRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
invoiceRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInvoice, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(invoiceRes.getString("errorDescription")) || invoiceRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("发票查询失败或者不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("单据存在,继续向下执行");
|
||||||
|
|
||||||
|
for (Object invoiceObj : invoiceRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject invoiceData = JSON.parseObject(JSON.toJSONString(invoiceObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的发票为:" + invoiceData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//发票CRMID
|
||||||
|
String invoiceId = invoiceData.getString("_id");
|
||||||
|
//发票名称
|
||||||
|
String invoiceName = invoiceData.getString("name");
|
||||||
|
//开票创建时间
|
||||||
|
String createTime = invoiceData.getString("create_time");
|
||||||
|
|
||||||
|
//开始判断数据库中是否存在数据
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_invoice&log_type=KP&dataId=" + invoiceId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
//开始封装请求
|
||||||
|
Map invoiceMap = new HashMap();
|
||||||
|
|
||||||
|
String invoiceType = invoiceData.getString("record_type") != null ? invoiceData.getString("record_type") : "";
|
||||||
|
invoiceMap.put("billsourcetype", "blue");
|
||||||
|
invoiceMap.put("crmid", invoiceData.getString("sales1_contract__c"));//销售合同CRMID
|
||||||
|
|
||||||
|
invoiceMap.put("crminvoiceid", invoiceId);//crm开票申请ID
|
||||||
|
|
||||||
|
//开票类型
|
||||||
|
String invoiceKinds = invoiceData.getString("invoice_type") != null ? invoiceData.getString("invoice_type") : "";
|
||||||
|
|
||||||
|
invoiceMap.put("invoicetype", invoiceKinds);
|
||||||
|
|
||||||
|
invoiceMap.put("comment", invoiceData.getString("remark") != null ? invoiceData.getString("remark") : "");//发票备注
|
||||||
|
invoiceMap.put("buyeremail", invoiceData.getString("invoice_delivery_email__c") != null ? invoiceData.getString("invoice_delivery_email__c") : "2019326567@qq.com");//发票推送邮箱
|
||||||
|
invoiceMap.put("asstact_number", "Cus-000001");//todo 往来户(客户名称)
|
||||||
|
invoiceMap.put("buyertaxno", invoiceData.getString("tax_id") != null ? invoiceData.getString("tax_id") : "");//纳税人识别号
|
||||||
|
//开票地址
|
||||||
|
String invoice_add = invoiceData.getString("invoice_add") != null ? invoiceData.getString("invoice_add") : "";
|
||||||
|
invoiceMap.put("buyeraddr", invoice_add);//购方地址
|
||||||
|
//电话
|
||||||
|
String invoice_phone = invoiceData.getString("invoice_tel") != null ? invoiceData.getString("invoice_tel") : "";
|
||||||
|
|
||||||
|
invoiceMap.put("buyerphone", invoice_phone);//购方电话
|
||||||
|
|
||||||
|
//开户行
|
||||||
|
String account_bank = invoiceData.getString("account_bank") != null ? invoiceData.getString("account_bank") : "";
|
||||||
|
invoiceMap.put("buyerbank", account_bank);
|
||||||
|
//开户账号
|
||||||
|
String account_bank_no = invoiceData.getString("account_bank_no") != null ? invoiceData.getString("account_bank_no") : "";
|
||||||
|
invoiceMap.put("buyerbanknumber", account_bank_no);
|
||||||
|
|
||||||
|
//是否展示地址电话
|
||||||
|
Boolean isShowTel = invoiceData.getBoolean("show_address_phone__c");
|
||||||
|
invoiceMap.put("showbuyeraddresstel", isShowTel);
|
||||||
|
|
||||||
|
//是否展示明细
|
||||||
|
Boolean isShowDetail = invoiceData.getBoolean("invoice_details_complete__c");
|
||||||
|
invoiceMap.put("showdetails", isShowDetail);
|
||||||
|
|
||||||
|
//是否展示开户行及账号
|
||||||
|
Boolean isShowBank = invoiceData.getBoolean("show_bank_account__c");
|
||||||
|
invoiceMap.put("showbuyerbank", isShowBank);
|
||||||
|
|
||||||
|
//是否含软
|
||||||
|
String isHasSoft = invoiceData.getString("is_contain_soft__c");
|
||||||
|
Boolean isHasSoftBool = false;
|
||||||
|
|
||||||
|
switch (isHasSoft) {
|
||||||
|
case "v2j71Ak5p":
|
||||||
|
isHasSoftBool = true;
|
||||||
|
break;
|
||||||
|
case "YOZj917km":
|
||||||
|
isHasSoftBool = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
invoiceMap.put("issoftworks", isHasSoftBool);
|
||||||
|
|
||||||
|
//todo 软著版本编码
|
||||||
|
invoiceMap.put("softworks_number", "21321321");
|
||||||
|
|
||||||
|
//开始查询明细
|
||||||
|
JSONObject getInvoiceDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "invoice_id", Arrays.asList(invoiceId))
|
||||||
|
), "InvoiceApplicationLinesObj");
|
||||||
|
|
||||||
|
JSONObject invoiceDetailRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
invoiceDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInvoiceDetail, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(invoiceDetailRes.getString("errorDescription")) || invoiceDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("发票明细查询失败或者不存在");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("发票明细查询成功,将继续向下执行");
|
||||||
|
|
||||||
|
List entry = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object invoiceDetailObj : invoiceDetailRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject invoiceDetailData = JSON.parseObject(JSON.toJSONString(invoiceDetailObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的明细为:" + invoiceDetailData);
|
||||||
|
Map entryMap = new HashMap();
|
||||||
|
|
||||||
|
if (invoiceType.equals("default__c")) {
|
||||||
|
//blue传销售合同明细id
|
||||||
|
entryMap.put("crmentryid", invoiceDetailData.getString("sales_contract_details__c"));
|
||||||
|
} else if (invoiceType.equals("record_3pGf2__c")) {
|
||||||
|
//red传开票申请单明细id
|
||||||
|
entryMap.put("crmentryid", invoiceDetailData.getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
entryMap.put("crminvoiceentryid", invoiceDetailData.getString("_id"));//开票申请明细id
|
||||||
|
entryMap.put("goodsname", invoiceDetailData.getString("invoice_product_name__c") != null ? invoiceDetailData.getString("invoice_product_name__c") : "");//商品名称
|
||||||
|
entryMap.put("softworks_number", invoiceDetailData.getString("invoice_product_num__c") != null ? invoiceDetailData.getString("invoice_product_num__c") : "");//软著编码
|
||||||
|
entryMap.put("taxratecodeid_number", "109060310");//todo 税收分类
|
||||||
|
entryMap.put("quantity", invoiceDetailData.getBigDecimal("field_9C0j7__c") != null ? invoiceDetailData.getBigDecimal("field_9C0j7__c") : 0);//数量
|
||||||
|
entryMap.put("taxunitprice", invoiceDetailData.getBigDecimal("tax_inclusive_unit_price__c") != null ? invoiceDetailData.getBigDecimal("tax_inclusive_unit_price__c") : 0);//含税单价
|
||||||
|
entryMap.put("recamount", invoiceDetailData.getBigDecimal("invoiced_amount") != null ? invoiceDetailData.getBigDecimal("invoiced_amount") : 0);//应收金额-开票小计
|
||||||
|
entryMap.put("taxrateid_number", invoiceDetailData.getString("tax_rate_code__c") != null ? invoiceDetailData.getString("tax_rate_code__c") : "");//TODO 税率编码
|
||||||
|
entryMap.put("measureunit_number", invoiceDetailData.getString("unit__c") != null ? invoiceDetailData.getString("unit__c") : "");//计量单位
|
||||||
|
entryMap.put("specification", invoiceDetailData.getString("specification_model__c") != null ? invoiceDetailData.getString("specification_model__c") : "");//规格型号
|
||||||
|
|
||||||
|
entry.add(entryMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
invoiceMap.put("entry", entry);
|
||||||
|
|
||||||
|
//开始获取token
|
||||||
|
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 invoiceReqEntity = new HttpEntity(invoiceMap, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(invoiceReqEntity)));
|
||||||
|
|
||||||
|
String invoiceUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/ar/arbusbill/createInvoice";
|
||||||
|
|
||||||
|
JSONObject erpInvoiceRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpInvoiceRes = restTemplate.postForObject(invoiceUrl, invoiceReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(erpInvoiceRes);
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", invoiceId);
|
||||||
|
backReqMap.put("dataObjectApiName", "InvoiceApplicationObj");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "KP");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", invoiceName);
|
||||||
|
logMap.put("data_id", invoiceId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(invoiceReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(erpInvoiceRes));
|
||||||
|
logMap.put("tableName", "send_log_invoice");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(erpInvoiceRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", erpInvoiceRes.getJSONObject("data").getString("pkId"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + erpInvoiceRes.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", erpInvoiceRes.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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红冲发票同步
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public void syncRedInvoice() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject getRedInvoice = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("HCFP2505-0002"))
|
||||||
|
), "custom_object_example1__c");
|
||||||
|
|
||||||
|
JSONObject redInvoiceRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
redInvoiceRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getRedInvoice, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(redInvoiceRes.getString("errorDescription")) || redInvoiceRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("未找到红冲发票或者查询失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object redInvoiceObj : redInvoiceRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject redInvoiceData = JSON.parseObject(JSON.toJSONString(redInvoiceObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理数据为:" + redInvoiceData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//唯一性编码
|
||||||
|
String redInvoiceId = redInvoiceData.getString("_id");
|
||||||
|
//红冲单号
|
||||||
|
String redInvoiceName = redInvoiceData.getString("name");
|
||||||
|
//红冲单创建时间
|
||||||
|
String createTime = redInvoiceData.getString("create_time");
|
||||||
|
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_invoice&log_type=REDKP&dataId=" + redInvoiceId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("查询日志结果为:" + isLogRes);
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
Map invoiceMap = new HashMap();
|
||||||
|
invoiceMap.put("billsourcetype", "red");//单据类型
|
||||||
|
invoiceMap.put("crmid", redInvoiceData.getString("blue_invoice_application__c"));//红冲开票CRMID
|
||||||
|
invoiceMap.put("crminvoiceid", redInvoiceId);//CRM红冲开票申请ID
|
||||||
|
invoiceMap.put("invoicetype", redInvoiceData.getString("invoice_type__c") != null ? redInvoiceData.getString("invoice_type__c") : "");//开票类型
|
||||||
|
invoiceMap.put("comment", redInvoiceData.getString("invoice_note__c") != null ? redInvoiceData.getString("invoice_note__c") : "");//备注
|
||||||
|
invoiceMap.put("buyeremail", redInvoiceData.getString("invoice_delivery_email__c") != null ? redInvoiceData.getString("invoice_delivery_email__c") : "2019326567@qq.com");//发票推送邮箱
|
||||||
|
invoiceMap.put("asstact_number", "Cus-000001");//todo 往来户(客户)
|
||||||
|
invoiceMap.put("buyertaxno", redInvoiceData.getString("tax_identification_number__c") != null ? redInvoiceData.getString("tax_identification_number__c") : "");//纳税识别号
|
||||||
|
invoiceMap.put("buyeraddr", redInvoiceData.getString("invoice_address__c") != null ? redInvoiceData.getString("invoice_address__c") : "");//地址
|
||||||
|
invoiceMap.put("buyerphone", redInvoiceData.getString("field_SM1Wc__c") != null ? redInvoiceData.getString("field_SM1Wc__c") : "");//电话
|
||||||
|
invoiceMap.put("showbuyeraddresstel", redInvoiceData.getBooleanValue("show_address_phone__c"));//是否展示地址电话
|
||||||
|
invoiceMap.put("buyerbank", redInvoiceData.getString("bank_branch__c") != null ? redInvoiceData.getString("bank_branch__c") : "");//开户行
|
||||||
|
invoiceMap.put("buyerbanknumber", redInvoiceData.getString("account_number__c") != null ? redInvoiceData.getString("account_number__c") : "");//开户行账号
|
||||||
|
invoiceMap.put("showbuyerbank", redInvoiceData.getBooleanValue("show_bank_account__c"));//是否展示开户行
|
||||||
|
invoiceMap.put("showdetails", redInvoiceData.getBooleanValue("is_display_invoice_details__c"));//是否展示发票明细(名称、数量、单价、单位、规格)
|
||||||
|
|
||||||
|
String isSoftWorks = redInvoiceData.getString("is_contain_soft__c");
|
||||||
|
Boolean isSoftWorksFlag = false;
|
||||||
|
switch (isSoftWorks) {
|
||||||
|
case "v2j71Ak5p":
|
||||||
|
isSoftWorksFlag = true;
|
||||||
|
break;
|
||||||
|
case "YOZj917km":
|
||||||
|
isSoftWorksFlag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
invoiceMap.put("issoftworks", isSoftWorksFlag);//是否含软
|
||||||
|
|
||||||
|
invoiceMap.put("softworks_number", "ooooaaaa");//软著版本编码
|
||||||
|
invoiceMap.put("blueinvoiceno", redInvoiceData.getString("original_invoice_number__c") != null ? redInvoiceData.getString("original_invoice_number__c") : "");//待冲蓝字发票号码
|
||||||
|
invoiceMap.put("redreason", redInvoiceData.getString("redemption_reason__c") != null ? redInvoiceData.getString("redemption_reason__c") : "");//冲红原因
|
||||||
|
|
||||||
|
//开始查询明细数据
|
||||||
|
JSONObject getInvoiceDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "red_invoice_application__c", Arrays.asList(redInvoiceId))
|
||||||
|
), "red_invoice_details__c");
|
||||||
|
|
||||||
|
JSONObject invoiceDetailRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
invoiceDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInvoiceDetail, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(invoiceDetailRes.getString("errorDescription")) || invoiceDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("请求失败或数据不存在");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("查询明细数据成功,继续向下执行和封装");
|
||||||
|
|
||||||
|
List<Map> invoiceDetailList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object invoiceDetailObj : invoiceDetailRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject invoiceDetailData = JSON.parseObject(JSON.toJSONString(invoiceDetailObj));
|
||||||
|
|
||||||
|
Map invoiceDetailMap = new HashMap();
|
||||||
|
invoiceDetailMap.put("crmentryid", invoiceDetailData.getString("invoice_application_detail__c"));
|
||||||
|
invoiceDetailMap.put("crminvoiceentryid", invoiceDetailData.getString("_id"));
|
||||||
|
invoiceDetailMap.put("goodsname", invoiceDetailData.getString("name__c") != null ? invoiceDetailData.getString("name__c") : "");//商品名称
|
||||||
|
invoiceDetailMap.put("taxratecodeid_number", "109060310");//todo 税收分类编码-商品分类编码
|
||||||
|
|
||||||
|
BigDecimal quality = invoiceDetailData.getBigDecimal("red_canceled_quantity__c");
|
||||||
|
|
||||||
|
if (quality.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
quality = quality.negate();
|
||||||
|
}
|
||||||
|
invoiceDetailMap.put("quality", quality);//数量
|
||||||
|
invoiceDetailMap.put("taxunitprice", invoiceDetailData.getBigDecimal("tax_inclusive_unit_price__c"));//含税单价
|
||||||
|
|
||||||
|
BigDecimal receivablePrice = invoiceDetailData.getBigDecimal("unit_price_taxINCLUDED_tot__c");
|
||||||
|
|
||||||
|
if (receivablePrice.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
receivablePrice = receivablePrice.negate();
|
||||||
|
}
|
||||||
|
invoiceDetailMap.put("recamount", receivablePrice);//应收金额
|
||||||
|
invoiceDetailMap.put("taxrateid_number", invoiceDetailData.getString("tax_rate_code__c"));//税率编码
|
||||||
|
invoiceDetailMap.put("measureunit_number", invoiceDetailData.getString("unit__c") != null ? invoiceDetailData.getString("unit__c") : "");//计量单位
|
||||||
|
invoiceDetailMap.put("specification", invoiceDetailData.getString("specification_model__c"));//规格型号
|
||||||
|
|
||||||
|
invoiceDetailList.add(invoiceDetailMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
invoiceMap.put("entry", invoiceDetailList);
|
||||||
|
|
||||||
|
//开始获取token
|
||||||
|
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 invoiceReqEntity = new HttpEntity(invoiceMap, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(invoiceReqEntity)));
|
||||||
|
|
||||||
|
String invoiceUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/ar/arbusbill/createInvoice";
|
||||||
|
|
||||||
|
JSONObject erpInvoiceRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpInvoiceRes = restTemplate.postForObject(invoiceUrl, invoiceReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(erpInvoiceRes);
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", redInvoiceId);
|
||||||
|
backReqMap.put("dataObjectApiName", "custom_object_example1__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "REDKP");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", redInvoiceName);
|
||||||
|
logMap.put("data_id", redInvoiceId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(invoiceReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(erpInvoiceRes));
|
||||||
|
logMap.put("tableName", "send_log_invoice");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(erpInvoiceRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", erpInvoiceRes.getJSONObject("data").getString("pkId"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + erpInvoiceRes.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", erpInvoiceRes.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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,11 +18,12 @@ import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预签合同
|
* 预签合同
|
||||||
* @param
|
*
|
||||||
* @return null
|
* @param
|
||||||
* @Author weiloong_zhang
|
* @return null
|
||||||
*/
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/pre/contract")
|
@RequestMapping("/api/pre/contract")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -32,6 +33,7 @@ public class PreContractController {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new PreContractController().syncContract();
|
new PreContractController().syncContract();
|
||||||
|
//new PreContractController().bgPreContract();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ public class PreContractController {
|
|||||||
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "name", Arrays.asList("YQHT-20250427-0001")),
|
new Filter("EQ", "name", Arrays.asList("YQ2505220005")),
|
||||||
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
), "pre_signed_contract__c");
|
), "pre_signed_contract__c");
|
||||||
|
|
||||||
@ -99,14 +101,14 @@ public class PreContractController {
|
|||||||
Map erpContractReq = new HashMap<>();
|
Map erpContractReq = new HashMap<>();
|
||||||
erpContractReq.put("billno", preContractData.getString("name"));//预签合同编号
|
erpContractReq.put("billno", preContractData.getString("name"));//预签合同编号
|
||||||
erpContractReq.put("crmid", preContractData.getString("_id"));//CRM唯一性编码
|
erpContractReq.put("crmid", preContractData.getString("_id"));//CRM唯一性编码
|
||||||
erpContractReq.put("project_number", preContractData.getString("opportunity_id__c"));//项目号
|
//erpContractReq.put("project_number", preContractData.getString("opportunity_id__c"));//项目号
|
||||||
//erpContractReq.put("project_number", "SJ20250424-0033");//项目号
|
erpContractReq.put("project_number", "SJ20250424-0033");//项目号
|
||||||
erpContractReq.put("billtype_number", "conm_salcontract_BT_YQ");//单据类型
|
erpContractReq.put("billtype_number", "conm_salcontract_BT_YQ");//单据类型
|
||||||
erpContractReq.put("billname", preContractData.getString("contract_name__c"));//合同名称
|
erpContractReq.put("billname", preContractData.getString("contract_name__c") != null ? preContractData.getString("contract_name__c") : "预签合同测试");//合同名称
|
||||||
erpContractReq.put("type_number", "XSHT-YQ01");//合同类型
|
erpContractReq.put("type_number", "XSHT-YQ01");//合同类型
|
||||||
erpContractReq.put("contparties_number", "BU-0002");//合同主体
|
erpContractReq.put("contparties_number", "ZHY");//合同主体
|
||||||
erpContractReq.put("createorg_number", "zyierp");//销售组织编码
|
erpContractReq.put("createorg_number", "ZHY");//销售组织编码
|
||||||
erpContractReq.put("org_number", "zyierp");//销售组织编码
|
erpContractReq.put("org_number", "ZHY");//销售组织编码
|
||||||
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
|
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
|
||||||
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
|
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
|
||||||
erpContractReq.put("biztime", date);//签订日期,单据日期
|
erpContractReq.put("biztime", date);//签订日期,单据日期
|
||||||
@ -139,7 +141,8 @@ public class PreContractController {
|
|||||||
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
erpContractReq.put("dept", deptCode);//归属部门
|
erpContractReq.put("dept", "ZHY");//归属部门
|
||||||
|
erpContractReq.put("dept_number", "004");//归属部门
|
||||||
|
|
||||||
//获取负责人编码
|
//获取负责人编码
|
||||||
String ownerCode = "";
|
String ownerCode = "";
|
||||||
@ -163,7 +166,7 @@ public class PreContractController {
|
|||||||
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
|
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
erpContractReq.put("operator", "ZHY12025");//todo 负责人
|
erpContractReq.put("operator", "ID-000016");//todo 负责人
|
||||||
|
|
||||||
//合同单位
|
//合同单位
|
||||||
String customerId = preContractData.getString("contract_unit_name__c");
|
String customerId = preContractData.getString("contract_unit_name__c");
|
||||||
@ -188,8 +191,8 @@ public class PreContractController {
|
|||||||
|
|
||||||
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
//erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
|
erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
|
||||||
erpContractReq.put("customer_number", "Cus-000007");//合同单位名称
|
//erpContractReq.put("customer_number", "Cus-000007");//todo 合同单位名称
|
||||||
|
|
||||||
//获取产品线
|
//获取产品线
|
||||||
|
|
||||||
@ -298,4 +301,299 @@ public class PreContractController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预签合同变更
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/bg_pre_contract")
|
||||||
|
public void bgPreContract() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject preContractBGReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("YQHTBG20250518-0002"))
|
||||||
|
), "pre_signed_contract_amendm__c");
|
||||||
|
|
||||||
|
JSONObject preContractBGRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
preContractBGRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, preContractBGReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("预签合同变更查询结果为:" + preContractBGRes);
|
||||||
|
|
||||||
|
if (!"success".equals(preContractBGRes.getString("errorDescription")) || preContractBGRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("不存在要变更的预签合同");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object preContractBGObj : preContractBGRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject preContractBGData = JSON.parseObject(JSON.toJSONString(preContractBGObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的单据为:" + preContractBGData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//唯一ID
|
||||||
|
String preContractId = preContractBGData.getString("_id");
|
||||||
|
//单据名称
|
||||||
|
String preContractName = preContractBGData.getString("name");
|
||||||
|
//创建时间
|
||||||
|
String createTime = preContractBGData.getString("create_time");
|
||||||
|
|
||||||
|
//开始查询是否已经集成过该单据
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_htxx&log_type=YQHTBG&dataId=" + preContractId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
//开始封装数据
|
||||||
|
Map preContractBGMap = new HashMap<>();
|
||||||
|
//开始封装传输至ERP的请求
|
||||||
|
//preContractBGMap.put("billno", preContractBGData.getString("source_pre_signed_contract__c__r"));//原预签合同编号
|
||||||
|
preContractBGMap.put("crmid", preContractBGData.getString("source_pre_signed_contract__c"));//CRM唯一性编码
|
||||||
|
|
||||||
|
//开始查询项目号
|
||||||
|
String projectCode = "";
|
||||||
|
|
||||||
|
if (preContractBGData.getString("business_opportunity__c") != null) {
|
||||||
|
projectCode = preContractBGData.getString("business_opportunity__c");
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject projectReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(projectCode))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject projectRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, projectReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("项目号查询结果为:" + projectRes);
|
||||||
|
|
||||||
|
if (!"success".equals(projectRes.getString("errorDescription")) || projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("商机不存在,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
projectCode = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("opportunity_id__c");
|
||||||
|
|
||||||
|
//preContractBGMap.put("project_number", projectCode);//项目号
|
||||||
|
preContractBGMap.put("project_number", "SJ20250424-0033");//项目号
|
||||||
|
preContractBGMap.put("billtype_number", "conm_salcontract_BT_YQ");//单据类型
|
||||||
|
preContractBGMap.put("billname", preContractBGData.getString("contract_name__c") != null ? preContractBGData.getString("contract_name__c") : "测试");//todo 合同名称
|
||||||
|
preContractBGMap.put("type_number", "XSHT-YQ01");//合同类型
|
||||||
|
preContractBGMap.put("contparties_number", "BU-0002");//合同主体
|
||||||
|
preContractBGMap.put("createorg_number", "zyierp");//销售组织编码
|
||||||
|
preContractBGMap.put("org_number", "zyierp");//销售组织编码
|
||||||
|
preContractBGMap.put("currency_number", "CNY");//本位币.货币代码
|
||||||
|
preContractBGMap.put("settlecurrency_number", "CNY");//结算币别.货币代码
|
||||||
|
|
||||||
|
//日期格式化为Date
|
||||||
|
long documentDate = preContractBGData.getLong("document_date__c");
|
||||||
|
preContractBGMap.put("biztime", new Date(documentDate));//签订日期,单据日期
|
||||||
|
preContractBGMap.put("biztimebegin", new Date(documentDate));//起始日期
|
||||||
|
preContractBGMap.put("biztimeend", new Date(documentDate));//截止日期
|
||||||
|
preContractBGMap.put("party1st", preContractBGData.getString("contract_unit_name__c__r"));//甲方
|
||||||
|
preContractBGMap.put("party2nd", preContractBGData.getString("our_company_name__c"));//乙方
|
||||||
|
preContractBGMap.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
|
||||||
|
|
||||||
|
//部门编码
|
||||||
|
String deptCode = "";
|
||||||
|
|
||||||
|
List deptIdList = preContractBGData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
preContractBGMap.put("dept", deptCode);//归属部门
|
||||||
|
preContractBGMap.put("dept_number", "004");//归属部门
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = preContractBGData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
preContractBGMap.put("operator", "ID-000016");//todo 负责人
|
||||||
|
preContractBGMap.put("user_operatornumber", "ID-000016");//todo 负责人
|
||||||
|
|
||||||
|
//合同单位
|
||||||
|
String customerId = preContractBGData.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);
|
||||||
|
|
||||||
|
//preContractBGMap.put("customer_number", customerData.getString("account_no"));//合同单位名称
|
||||||
|
preContractBGMap.put("customer_number", "Cus-000007");//todo 合同单位名称
|
||||||
|
|
||||||
|
//获取产品线
|
||||||
|
|
||||||
|
preContractBGMap.put("productline_number", preContractBGData.getString("product_line__c"));//产品线
|
||||||
|
|
||||||
|
//获取具体安装方式
|
||||||
|
|
||||||
|
preContractBGMap.put("installationmethod", preContractBGData.getString("installation_method__c"));//安装方式
|
||||||
|
|
||||||
|
//行业类型
|
||||||
|
preContractBGMap.put("industrytype_number", preContractBGData.getString("industry_type__c"));//行业类型
|
||||||
|
preContractBGMap.put("deviceqty", preContractBGData.getBigDecimal("device_quantity__c") != null ? preContractBGData.getBigDecimal("device_quantity__c") : 0);//设备数量
|
||||||
|
preContractBGMap.put("totalallamount", preContractBGData.getBigDecimal("pre_signed_amount__c") != null ? preContractBGData.getBigDecimal("pre_signed_amount__c") : 0);//预签金额
|
||||||
|
preContractBGMap.put("warranty", preContractBGData.getBigDecimal("warranty_period_months__c") != null ? preContractBGData.getBigDecimal("warranty_period_months__c") : 0);//质保期
|
||||||
|
|
||||||
|
Map erpContractBGDataReq = new HashMap<>();
|
||||||
|
erpContractBGDataReq.put("data", Arrays.asList(preContractBGMap));//请求体
|
||||||
|
|
||||||
|
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(erpContractBGDataReq, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
|
||||||
|
|
||||||
|
//开始向金蝶发起请求
|
||||||
|
String contractUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/conm/salcontract/change";
|
||||||
|
|
||||||
|
String erpPreContractBGRes = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpPreContractBGRes = restTemplate.postForObject(contractUrl, contractReqEntity, String.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject erpPreContractBGResJson = JSON.parseObject(erpPreContractBGRes);
|
||||||
|
|
||||||
|
System.out.println("金蝶预签结果为:" + erpPreContractBGResJson);
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", preContractId);
|
||||||
|
backReqMap.put("dataObjectApiName", "pre_signed_contract_amendm__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "YQHTBG");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", preContractName);
|
||||||
|
logMap.put("data_id", preContractId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(contractReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(erpPreContractBGResJson));
|
||||||
|
logMap.put("tableName", "send_log_htxx");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(erpPreContractBGResJson.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", erpPreContractBGResJson.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", "同步失败:" + erpPreContractBGResJson.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", erpPreContractBGResJson.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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,289 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
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.util.LinkedMultiValueMap;
|
||||||
|
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 org.ssssssss.magicboot.constant.URLConstant;
|
||||||
|
import org.ssssssss.magicboot.entity.Filter;
|
||||||
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/quality/feedback")
|
||||||
|
@Slf4j
|
||||||
|
public class QualityBackController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new QualityBackController().qualityFeedBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 问题质量反馈单更新
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/quality_back")
|
||||||
|
public void qualityFeedBack() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
log.info("开始同步新建质量反馈单");
|
||||||
|
|
||||||
|
JSONObject getQualityBack = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("ZLXXFK202505160001"))
|
||||||
|
), "quality_feedback_form__c");
|
||||||
|
|
||||||
|
JSONObject qualityBack = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
qualityBack = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getQualityBack, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(qualityBack.getString("errorDescription")) || qualityBack.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("质量反馈单请求失败,或者不存在符合条件的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("质量反馈单请求成功,继续向下执行");
|
||||||
|
|
||||||
|
for (Object qualityBackObj : qualityBack.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject qualityBackData = JSON.parseObject(JSON.toJSONString(qualityBackObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的数据为:" + qualityBackData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//唯一性id
|
||||||
|
String qualityId = qualityBackData.getString("_id");
|
||||||
|
//反馈单单号
|
||||||
|
String qualityName = qualityBackData.getString("name");
|
||||||
|
//反馈单创建时间
|
||||||
|
String createTime = qualityBackData.getString("create_time");
|
||||||
|
|
||||||
|
//开始查询当前单据是否已经集成过
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_quality&log_type=Quality&dataId=" + qualityId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
//开始封装数据
|
||||||
|
Map qualityReqMap = new HashMap<>();
|
||||||
|
qualityReqMap.put("billno", qualityName);//单据编号
|
||||||
|
qualityReqMap.put("crmid", qualityId);//CRM唯一id
|
||||||
|
|
||||||
|
//获取负责人编码
|
||||||
|
String ownerCode = "";
|
||||||
|
|
||||||
|
List ownerIdList = qualityBackData.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") : "";
|
||||||
|
}
|
||||||
|
qualityReqMap.put("provider_number", "ZHY10542");//todo 反馈人(负责人编号)
|
||||||
|
|
||||||
|
//部门编码
|
||||||
|
String deptCode = "";
|
||||||
|
|
||||||
|
List deptIdList = qualityBackData.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") : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
qualityReqMap.put("dept_number", "zyierp");//归属部门
|
||||||
|
|
||||||
|
qualityReqMap.put("org_number", "zyierp");//todo 组织编码
|
||||||
|
qualityReqMap.put("contractno", qualityBackData.getString("contract_number__c__r") != null ? qualityBackData.getString("contract_number__c__r") : "");//销售合同号
|
||||||
|
qualityReqMap.put("productionbatch", qualityBackData.getString("production_batch__c") != null ? qualityBackData.getString("production_batch__c") : "");//生产批次
|
||||||
|
|
||||||
|
long askedTime = qualityBackData.getLong("required_processing_time__c") != null ? qualityBackData.getLong("required_processing_time__c") : 0;
|
||||||
|
qualityReqMap.put("handletime", new Date(askedTime));//要求处理时间
|
||||||
|
|
||||||
|
long installTime = qualityBackData.getLong("installation_time__c") != null ? qualityBackData.getLong("installation_time__c") : 0;
|
||||||
|
qualityReqMap.put("installtime", new Date(installTime));//项目安装时间
|
||||||
|
|
||||||
|
long happenTime = qualityBackData.getLong("event_occurrence_time__c") != null ? qualityBackData.getLong("event_occurrence_time__c") : 0;
|
||||||
|
qualityReqMap.put("occurrencetime", new Date(happenTime));//事件发生时间
|
||||||
|
|
||||||
|
//产品型号
|
||||||
|
qualityReqMap.put("productmodel", qualityBackData.getString("product_model__c") != null ? qualityBackData.getString("product_model__c") : "");//产品型号
|
||||||
|
qualityReqMap.put("problemdesc", qualityBackData.getString("on_site_issue_description__c") != null ? qualityBackData.getString("on_site_issue_description__c") : "");//现场问题描述
|
||||||
|
|
||||||
|
Map erpQualityData = new HashMap<>();
|
||||||
|
erpQualityData.put("data", Arrays.asList(qualityReqMap));//请求体
|
||||||
|
|
||||||
|
//开始获取token
|
||||||
|
String token = new KDTokenController().getKDAccessTokenTest();
|
||||||
|
|
||||||
|
if (token == null || token.equals("")) {
|
||||||
|
log.info("金蝶token为空或不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("accessToken", token);
|
||||||
|
headers.set("Idempotency-Key", uuid);
|
||||||
|
|
||||||
|
HttpEntity qualityBackReqEntity = new HttpEntity(erpQualityData, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(qualityBackReqEntity)));
|
||||||
|
|
||||||
|
String qualityBackUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/qcqi/f9w5_problemfeedback/save";
|
||||||
|
|
||||||
|
String qualityBackRes = "";
|
||||||
|
try {
|
||||||
|
qualityBackRes = restTemplate.postForObject(qualityBackUrl, qualityBackReqEntity, String.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject qualityBackResJson = JSON.parseObject(qualityBackRes);
|
||||||
|
|
||||||
|
System.out.println("质量反馈结果为:" + qualityBackResJson);
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", qualityId);
|
||||||
|
backReqMap.put("dataObjectApiName", "quality_feedback_form__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "Quality");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", qualityName);
|
||||||
|
logMap.put("data_id", qualityId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(erpQualityData));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(qualityBackResJson));
|
||||||
|
logMap.put("tableName", "send_log_quality");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(qualityBackResJson.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", qualityBackResJson.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", "同步失败:" + qualityBackResJson.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", qualityBackResJson.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 logRes = new JSONObject();
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.postForObject("http://localhost:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
|
||||||
|
|
||||||
|
//判断是否存在附件
|
||||||
|
if (qualityBackData.getJSONArray("attachment__c") == null || qualityBackData.getJSONArray("attachment__c").isEmpty()) {
|
||||||
|
log.info("该质量反馈单不存在附件,将不再向下执行。");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//附件存在,将开始执行附件上传
|
||||||
|
List attachmentList = qualityBackData.getJSONArray("attachment__c");
|
||||||
|
|
||||||
|
MultiValueMap<String, Object> body = crmRequestUtil.proxyUploadFileToTarget(attachmentList, qualityId);
|
||||||
|
|
||||||
|
//开始封装请求实体
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
httpHeaders.set("accessToken", token);
|
||||||
|
|
||||||
|
HttpEntity entity = new HttpEntity(body, httpHeaders);
|
||||||
|
|
||||||
|
//开始发起传输
|
||||||
|
JSONObject fileRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
fileRes = restTemplate.postForObject("http://192.168.31.233:8022/ierp/kapi/v2/f9w5/qcqi/feedback/uploadFile", entity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("附件上传结果为:" + fileRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ public class XSHTController {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new XSHTController().syncXSHT();
|
new XSHTController().syncXSHT();
|
||||||
|
//new XSHTController().isComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +46,7 @@ public class XSHTController {
|
|||||||
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "name", Arrays.asList("ZHY250506-0002")),
|
new Filter("EQ", "name", Arrays.asList("ZHY2505220017")),
|
||||||
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
), "SaleContractObj");
|
), "SaleContractObj");
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public class XSHTController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//判断查询是否成功
|
//判断查询是否成功
|
||||||
if (!"success".equals(ContractRes.getString("errorDescription")) && ContractRes.getJSONObject("data").getJSONArray("records").isEmpty()) {
|
if (!"success".equals(ContractRes.getString("errorDescription")) && ContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
log.info("查询失败或者没有符合条件的单据");
|
log.info("查询失败或者没有符合条件的单据");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -121,17 +122,17 @@ public class XSHTController {
|
|||||||
|
|
||||||
//开始封装传输至ERP的请求
|
//开始封装传输至ERP的请求
|
||||||
Map erpContractReq = new HashMap<>();
|
Map erpContractReq = new HashMap<>();
|
||||||
erpContractReq.put("billno", contractData.getString("name"));//预签合同编号
|
erpContractReq.put("billno", contractData.getString("name"));//合同编号
|
||||||
erpContractReq.put("crmid", contractData.getString("_id"));//CRM唯一性编码
|
erpContractReq.put("crmid", contractData.getString("_id"));//CRM唯一性编码
|
||||||
erpContractReq.put("project_number", projectCode);//项目号
|
erpContractReq.put("project_number", projectCode);//项目号
|
||||||
erpContractReq.put("zhybilltype", contractData.getString("contract_type__c"));//合同类型
|
erpContractReq.put("zhybilltype", contractData.getString("contract_type__c"));//合同类型
|
||||||
//erpContractReq.put("project_number", "SJ20250424-0033");//项目号
|
//erpContractReq.put("project_number", "SJ20250424-0033");//项目号
|
||||||
erpContractReq.put("billtype_number", "conm_salcontract_BT_QD");//单据类型
|
erpContractReq.put("billtype_number", "conm_salcontract_BT_QD");//单据类型
|
||||||
erpContractReq.put("billname", contractData.getString("contract_name__c"));//合同名称
|
erpContractReq.put("billname", "ceshiceshi");//合同名称
|
||||||
erpContractReq.put("type_number", "XSHT-QD01");//合同类型
|
erpContractReq.put("type_number", "XSHT-QD01");//合同类型
|
||||||
erpContractReq.put("contparties_number", "BU-0002");//合同主体
|
erpContractReq.put("contparties_number", "ZHY");//合同主体
|
||||||
erpContractReq.put("createorg_number", "zyierp");//销售组织编码
|
erpContractReq.put("createorg_number", "ZHY");//销售组织编码
|
||||||
erpContractReq.put("org_number", "zyierp");//销售组织编码
|
erpContractReq.put("org_number", "ZHY");//销售组织编码
|
||||||
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
|
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
|
||||||
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
|
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
|
||||||
erpContractReq.put("biztime", date);//签订日期,单据日期
|
erpContractReq.put("biztime", date);//签订日期,单据日期
|
||||||
@ -166,7 +167,7 @@ public class XSHTController {
|
|||||||
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
erpContractReq.put("dept", deptCode);//归属部门
|
erpContractReq.put("dept", "zyierp");//归属部门
|
||||||
|
|
||||||
//获取负责人编码
|
//获取负责人编码
|
||||||
String ownerCode = "";
|
String ownerCode = "";
|
||||||
@ -190,7 +191,7 @@ public class XSHTController {
|
|||||||
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
|
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
erpContractReq.put("operator", "ZHY12025");//todo 负责人
|
erpContractReq.put("operator", "ZHY10542");//todo 负责人
|
||||||
|
|
||||||
//合同单位
|
//合同单位
|
||||||
String customerId = contractData.getString("account_id");
|
String customerId = contractData.getString("account_id");
|
||||||
@ -216,7 +217,7 @@ public class XSHTController {
|
|||||||
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
//erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
|
//erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
|
||||||
erpContractReq.put("customer_number", "Cus-000007");//合同单位名称
|
erpContractReq.put("customer_number", "Cus-000001");//合同单位名称
|
||||||
|
|
||||||
//获取产品线
|
//获取产品线
|
||||||
erpContractReq.put("productline_number", contractData.getString("product_line__c"));//产品线
|
erpContractReq.put("productline_number", contractData.getString("product_line__c"));//产品线
|
||||||
@ -300,13 +301,15 @@ public class XSHTController {
|
|||||||
|
|
||||||
//开始封装销售合同明细
|
//开始封装销售合同明细
|
||||||
Map contractDetailMap = new HashMap();
|
Map contractDetailMap = new HashMap();
|
||||||
|
contractDetailMap.put("linetype_number", "020");//行类型
|
||||||
contractDetailMap.put("materialname", contractDetailData.getString("product_name__c"));//产品名称
|
contractDetailMap.put("materialname", contractDetailData.getString("product_name__c"));//产品名称
|
||||||
//contractDetailMap.put("material_number", contractDetailData.getString("product_id__r"));//物料编号
|
//contractDetailMap.put("material_number", contractDetailData.getString("product_id__r"));//物料编号
|
||||||
contractDetailMap.put("material_number", "TEST0001");//物料编号
|
contractDetailMap.put("material_number", "TEST0001");//todo 物料编号
|
||||||
contractDetailMap.put("specifications", contractDetailData.getString("specification__c") != null ? contractDetailData.getString("specification__c") : "");//规格
|
contractDetailMap.put("specifications", 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", 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("unit1_number", "pcs");//单位编码
|
||||||
contractDetailMap.put("f9w5_unit1_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);//数量
|
||||||
@ -420,4 +423,154 @@ public class XSHTController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否竣工
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/isComplete")
|
||||||
|
public void isComplete() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject contractReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("ZHY2505180013")),
|
||||||
|
new Filter("EQ", "is_completed__c", Arrays.asList("yes"))
|
||||||
|
), "SaleContractObj");
|
||||||
|
|
||||||
|
JSONObject contractRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
contractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, contractReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(contractRes.getString("errorDescription")) || contractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("没有找到销售合同");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("数据存在,继续向下执行");
|
||||||
|
|
||||||
|
for (Object contractObj : contractRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject contractData = JSON.parseObject(JSON.toJSONString(contractObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的销售合同数据为:" + contractData);
|
||||||
|
|
||||||
|
//开始查询该销售合同是否已经执行过
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
String contractId = contractData.getString("_id");
|
||||||
|
|
||||||
|
String contractName = contractData.getString("name");
|
||||||
|
|
||||||
|
String createTime = contractData.getString("create_time");
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_htxx&log_type=是否竣工&dataId=" + contractId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
//开始封装请求
|
||||||
|
Map isCompleteReqMap = new HashMap<>();
|
||||||
|
isCompleteReqMap.put("billno", contractName);
|
||||||
|
|
||||||
|
Map isCompleteReq = new HashMap<>();
|
||||||
|
isCompleteReq.put("model", isCompleteReqMap);
|
||||||
|
|
||||||
|
//开始获取token
|
||||||
|
String accessToken = new KDTokenController().getKDAccessTokenTest();
|
||||||
|
|
||||||
|
if (accessToken == null || accessToken.equals("")) {
|
||||||
|
log.info("金蝶token为空或不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("accessToken", accessToken);
|
||||||
|
|
||||||
|
HttpEntity isCompleteEntity = new HttpEntity(isCompleteReq, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(isCompleteEntity)));
|
||||||
|
|
||||||
|
JSONObject isCompleteRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isCompleteRes = restTemplate.postForObject("http://192.168.31.233:8022/ierp/kapi/v2/f9w5/f9w5_conm_ext/salcontract/beComplete", isCompleteEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(isCompleteRes)));
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
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", "是否竣工");
|
||||||
|
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(isCompleteEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(isCompleteRes));
|
||||||
|
logMap.put("tableName", "send_log_htxx");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(isCompleteRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("completion_sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + isCompleteRes.getString("message"));
|
||||||
|
backReqMap.put("completion_sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_info__c", isCompleteRes.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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package org.ssssssss.magicboot.utils;
|
package org.ssssssss.magicboot.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.ssssssss.magicboot.constant.CertificateConstant;
|
import org.ssssssss.magicboot.constant.CertificateConstant;
|
||||||
import org.ssssssss.magicboot.constant.URLConstant;
|
import org.ssssssss.magicboot.constant.URLConstant;
|
||||||
import org.ssssssss.magicboot.entity.Filter;
|
import org.ssssssss.magicboot.entity.Filter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本工具类用于封装向纷享销客发送的请求参数,后续会完善其他的参数方法
|
* 本工具类用于封装向纷享销客发送的请求参数,后续会完善其他的参数方法
|
||||||
@ -312,4 +315,79 @@ public class CrmRequestUtil {
|
|||||||
return corpAccessToken;
|
return corpAccessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 纷享销客文件转码base64
|
||||||
|
*
|
||||||
|
* @param fileList
|
||||||
|
* @return java.lang.String[]
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
public MultiValueMap<String, Object> proxyUploadFileToTarget(List<?> fileList, String crmId) {
|
||||||
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
|
body.add("crmId", crmId);
|
||||||
|
body.add("fieldName", "f9w5_feedbackinfoattach");
|
||||||
|
|
||||||
|
if (fileList == null || fileList.isEmpty()) {
|
||||||
|
log.info("文件列表为空");
|
||||||
|
return body; // 返回空map而不是null
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object fileObj : fileList) {
|
||||||
|
JSONObject fileData = JSON.parseObject(JSON.toJSONString(fileObj));
|
||||||
|
|
||||||
|
Map<String, Object> fileReq = new HashMap<>();
|
||||||
|
fileReq.put("corpAccessToken", getCRMToken());
|
||||||
|
fileReq.put("corpId", CertificateConstant.CORP_ID);
|
||||||
|
fileReq.put("mediaTypeDesc", "DOCUMENT");
|
||||||
|
fileReq.put("mediaId", fileData.getString("path"));
|
||||||
|
fileReq.put("igonreMediaIdConvert", false);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
HttpEntity<Map<String, Object>> fileReqEntity = new HttpEntity<>(fileReq, headers);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResponseEntity<byte[]> fileResp = restTemplate.exchange(
|
||||||
|
"https://open.fxiaoke.com/media/download",
|
||||||
|
HttpMethod.POST,
|
||||||
|
fileReqEntity,
|
||||||
|
byte[].class);
|
||||||
|
|
||||||
|
if (fileResp.getStatusCode() == HttpStatus.OK && fileResp.getBody() != null) {
|
||||||
|
byte[] fileBytes = fileResp.getBody();
|
||||||
|
String fileName = fileData.getString("filename");
|
||||||
|
String contentType = fileData.getString("ext");
|
||||||
|
|
||||||
|
ByteArrayResource byteArrayResource = new ByteArrayResource(fileBytes) {
|
||||||
|
@Override
|
||||||
|
public String getFilename() {
|
||||||
|
return fileName != null ? fileName : UUID.randomUUID() + ".dat";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpHeaders fileHeaders = new HttpHeaders();
|
||||||
|
fileHeaders.setContentDispositionFormData("files", byteArrayResource.getFilename());
|
||||||
|
|
||||||
|
try {
|
||||||
|
fileHeaders.setContentType(MediaType.parseMediaType(
|
||||||
|
contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM_VALUE));
|
||||||
|
} catch (Exception e) {
|
||||||
|
fileHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(byteArrayResource, fileHeaders);
|
||||||
|
body.add("files", fileEntity);
|
||||||
|
} else {
|
||||||
|
log.error("文件下载失败,mediaId: {}", fileData.getString("path"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("下载文件出错", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user