金蝶部分集成程序优化和新增
This commit is contained in:
parent
71a2889878
commit
53e73dd147
@ -14,6 +14,7 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
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 org.ssssssss.magicboot.utils.CrmRequestUtil;
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
import org.ssssssss.magicboot.utils.KingDeeUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -47,7 +48,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("SJWJ250522-0013"))
|
new Filter("EQ", "name", Arrays.asList("SJWJ250528-0022"))
|
||||||
), "design_file__c");
|
), "design_file__c");
|
||||||
|
|
||||||
JSONObject designDocRes = new JSONObject();
|
JSONObject designDocRes = new JSONObject();
|
||||||
@ -159,7 +160,7 @@ public class DesignController {
|
|||||||
erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
|
erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
|
||||||
erpDesignMap.put("bizorg_number", "ZHY");//采购组织
|
erpDesignMap.put("bizorg_number", "ZHY");//采购组织
|
||||||
erpDesignMap.put("project_number", "SJ20250424-0033");//todo 项目号(商机)
|
erpDesignMap.put("project_number", "SJ20250424-0033");//todo 项目号(商机)
|
||||||
erpDesignMap.put("contractno", designDocData.getString("pre_signed_contract_id__c__r"));//合同号
|
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__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") : "");//备注
|
||||||
|
|
||||||
@ -191,7 +192,7 @@ public class DesignController {
|
|||||||
|
|
||||||
//开始封装设计文件明细
|
//开始封装设计文件明细
|
||||||
Map designDocDetailMap = new HashMap<>();
|
Map designDocDetailMap = new HashMap<>();
|
||||||
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_id__c__r"));//设计文件明细
|
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_name__c"));//设计文件明细
|
||||||
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
|
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
|
||||||
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
|
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
|
||||||
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
|
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
|
||||||
@ -227,7 +228,7 @@ public class DesignController {
|
|||||||
System.out.println("请求为:" + JSON.parseObject(JSON.toJSONString(designDocReqEntity)));
|
System.out.println("请求为:" + JSON.parseObject(JSON.toJSONString(designDocReqEntity)));
|
||||||
|
|
||||||
//开始向金蝶发起请求
|
//开始向金蝶发起请求
|
||||||
String designPlanUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/pssc/pm_requirapplybill/requirapplybillSave";
|
String designPlanUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/pssc/requirapplybillSave";
|
||||||
|
|
||||||
JSONObject erpDesignDocRes = new JSONObject();
|
JSONObject erpDesignDocRes = new JSONObject();
|
||||||
|
|
||||||
@ -261,9 +262,13 @@ public class DesignController {
|
|||||||
//同步成功
|
//同步成功
|
||||||
logMap.put("log_status", "0");
|
logMap.put("log_status", "0");
|
||||||
logMap.put("res_body", "同步成功");
|
logMap.put("res_body", "同步成功");
|
||||||
backReqMap.put("erp_id__c", erpDesignDocRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
backReqMap.put("erp_id__c", erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
backReqMap.put("sync_status__c", "option_sync_success__c");
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
backReqMap.put("response_info__c", "同步成功");
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
|
||||||
|
//审核
|
||||||
|
KingDeeUtils kingDeeUtils = new KingDeeUtils();
|
||||||
|
kingDeeUtils.audit(erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getString("id"), "pm_requirapplybill");
|
||||||
} else {
|
} else {
|
||||||
//同步失败
|
//同步失败
|
||||||
logMap.put("log_status", "1");
|
logMap.put("log_status", "1");
|
||||||
@ -297,12 +302,44 @@ public class DesignController {
|
|||||||
|
|
||||||
System.out.println("日志插入结果为:" + logResMap);
|
System.out.println("日志插入结果为:" + logResMap);
|
||||||
|
|
||||||
|
//判断一下设计文件的状态,没有成功就不传了
|
||||||
|
if (!"0".equals(erpDesignDocRes.getString("errorCode"))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装明细回写程序
|
||||||
|
for (Object resultObj : erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getJSONArray("entry")) {
|
||||||
|
JSONObject resultData = JSON.parseObject(JSON.toJSONString(resultObj));
|
||||||
|
|
||||||
|
String erpLineId = resultData.getString("entryid");
|
||||||
|
String crmLineId = resultData.getString("crmentryid");
|
||||||
|
|
||||||
|
//开始封装
|
||||||
|
Map backMap = new HashMap();
|
||||||
|
backMap.put("_id", crmLineId);
|
||||||
|
backMap.put("erp_line_id__c", erpLineId);
|
||||||
|
backMap.put("dataObjectApiName", "design_file_details__c");
|
||||||
|
|
||||||
|
JSONObject detailReq = crmRequestUtil.updateCRM(backMap);
|
||||||
|
|
||||||
|
JSONObject detailRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
detailRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, detailReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("明细回写结果为:" + detailRes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设计文件更新接口
|
* 设计文件更新接口
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @Author weiloong_zhang
|
* @Author weiloong_zhang
|
||||||
*/
|
*/
|
||||||
@ -372,7 +409,7 @@ public class DesignController {
|
|||||||
Map erpDesignMap = new HashMap<>();
|
Map erpDesignMap = new HashMap<>();
|
||||||
erpDesignMap.put("id", erpId);//erpId
|
erpDesignMap.put("id", erpId);//erpId
|
||||||
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_STD_BT_S");//单据类型
|
||||||
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
|
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
|
||||||
|
|
||||||
@ -405,7 +442,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", "ZHY");//部门编码
|
||||||
|
|
||||||
//获取负责人编码
|
//获取负责人编码
|
||||||
String ownerCode = "";
|
String ownerCode = "";
|
||||||
@ -430,7 +467,7 @@ 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", designDocData.getString("project_id__c"));//todo 项目号(商机)
|
||||||
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
|
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
|
||||||
erpDesignMap.put("crmid", designDocId);//crm唯一id
|
erpDesignMap.put("crmid", designDocId);//crm唯一id
|
||||||
@ -464,7 +501,7 @@ public class DesignController {
|
|||||||
|
|
||||||
//开始封装设计文件明细
|
//开始封装设计文件明细
|
||||||
Map designDocDetailMap = new HashMap<>();
|
Map designDocDetailMap = new HashMap<>();
|
||||||
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_id__c__r"));//设计文件明细
|
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_name__c"));//设计文件明细
|
||||||
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
|
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
|
||||||
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
|
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
|
||||||
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
|
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
|
||||||
|
@ -26,8 +26,8 @@ public class InvoiceController {
|
|||||||
private RestTemplate restTemplate = new RestTemplate();
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//new InvoiceController().syncInvoice();
|
new InvoiceController().syncInvoice();
|
||||||
new InvoiceController().syncRedInvoice();
|
//new InvoiceController().syncRedInvoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +41,7 @@ public class InvoiceController {
|
|||||||
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
JSONObject getInvoice = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject getInvoice = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "name", Arrays.asList("20250522-000007"))
|
new Filter("EQ", "name", Arrays.asList("20250527-000010"))
|
||||||
), "InvoiceApplicationObj");
|
), "InvoiceApplicationObj");
|
||||||
|
|
||||||
log.info("开始同步创建发票");
|
log.info("开始同步创建发票");
|
||||||
@ -95,6 +95,7 @@ public class InvoiceController {
|
|||||||
|
|
||||||
String invoiceType = invoiceData.getString("record_type") != null ? invoiceData.getString("record_type") : "";
|
String invoiceType = invoiceData.getString("record_type") != null ? invoiceData.getString("record_type") : "";
|
||||||
invoiceMap.put("billsourcetype", "blue");
|
invoiceMap.put("billsourcetype", "blue");
|
||||||
|
invoiceMap.put("f9w5_crmbillno", invoiceName);//单据编号
|
||||||
invoiceMap.put("crmid", invoiceData.getString("sales1_contract__c"));//销售合同CRMID
|
invoiceMap.put("crmid", invoiceData.getString("sales1_contract__c"));//销售合同CRMID
|
||||||
|
|
||||||
invoiceMap.put("crminvoiceid", invoiceId);//crm开票申请ID
|
invoiceMap.put("crminvoiceid", invoiceId);//crm开票申请ID
|
||||||
@ -106,7 +107,34 @@ public class InvoiceController {
|
|||||||
|
|
||||||
invoiceMap.put("comment", invoiceData.getString("remark") != null ? invoiceData.getString("remark") : "");//发票备注
|
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("buyeremail", invoiceData.getString("invoice_delivery_email__c") != null ? invoiceData.getString("invoice_delivery_email__c") : "2019326567@qq.com");//发票推送邮箱
|
||||||
invoiceMap.put("asstact_number", "Cus-000001");//todo 往来户(客户名称)
|
|
||||||
|
|
||||||
|
//开票单位编码
|
||||||
|
String customerId = invoiceData.getString("invoice_unit__c") != null ? invoiceData.getString("invoice_unit__c") : "TEST0001";
|
||||||
|
|
||||||
|
//根据客户唯一id查询客户编码
|
||||||
|
JSONObject getCustomer = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(customerId))
|
||||||
|
), "AccountObj");
|
||||||
|
|
||||||
|
JSONObject customerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
customerRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getCustomer, 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);
|
||||||
|
|
||||||
|
String customerNumber = customerData.getString("account_no");
|
||||||
|
|
||||||
|
invoiceMap.put("asstact_number", customerNumber);//往来户(客户)
|
||||||
invoiceMap.put("buyertaxno", invoiceData.getString("tax_id") != null ? invoiceData.getString("tax_id") : "");//纳税人识别号
|
invoiceMap.put("buyertaxno", invoiceData.getString("tax_id") != null ? invoiceData.getString("tax_id") : "");//纳税人识别号
|
||||||
//开票地址
|
//开票地址
|
||||||
String invoice_add = invoiceData.getString("invoice_add") != null ? invoiceData.getString("invoice_add") : "";
|
String invoice_add = invoiceData.getString("invoice_add") != null ? invoiceData.getString("invoice_add") : "";
|
||||||
@ -306,7 +334,7 @@ public class InvoiceController {
|
|||||||
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
JSONObject getRedInvoice = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject getRedInvoice = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "name", Arrays.asList("HCFP2505-0002"))
|
new Filter("EQ", "name", Arrays.asList("HCFP2505-0003"))
|
||||||
), "custom_object_example1__c");
|
), "custom_object_example1__c");
|
||||||
|
|
||||||
JSONObject redInvoiceRes = new JSONObject();
|
JSONObject redInvoiceRes = new JSONObject();
|
||||||
@ -354,12 +382,39 @@ public class InvoiceController {
|
|||||||
|
|
||||||
Map invoiceMap = new HashMap();
|
Map invoiceMap = new HashMap();
|
||||||
invoiceMap.put("billsourcetype", "red");//单据类型
|
invoiceMap.put("billsourcetype", "red");//单据类型
|
||||||
|
invoiceMap.put("f9w5_crmbillno", redInvoiceName);//单据编号
|
||||||
invoiceMap.put("crmid", redInvoiceData.getString("blue_invoice_application__c"));//红冲开票CRMID
|
invoiceMap.put("crmid", redInvoiceData.getString("blue_invoice_application__c"));//红冲开票CRMID
|
||||||
invoiceMap.put("crminvoiceid", redInvoiceId);//CRM红冲开票申请ID
|
invoiceMap.put("crminvoiceid", redInvoiceId);//CRM红冲开票申请ID
|
||||||
invoiceMap.put("invoicetype", redInvoiceData.getString("invoice_type__c") != null ? redInvoiceData.getString("invoice_type__c") : "");//开票类型
|
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("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("buyeremail", redInvoiceData.getString("invoice_delivery_email__c") != null ? redInvoiceData.getString("invoice_delivery_email__c") : "2019326567@qq.com");//发票推送邮箱
|
||||||
invoiceMap.put("asstact_number", "Cus-000001");//todo 往来户(客户)
|
|
||||||
|
//开票单位编码
|
||||||
|
String customerId = redInvoiceData.getString("customer_name__c") != null ? redInvoiceData.getString("customer_name__c") : "TEST0001";
|
||||||
|
|
||||||
|
//根据客户唯一id查询客户编码
|
||||||
|
JSONObject getCustomer = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(customerId))
|
||||||
|
), "AccountObj");
|
||||||
|
|
||||||
|
JSONObject customerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
customerRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getCustomer, 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);
|
||||||
|
|
||||||
|
String customerNumber = customerData.getString("account_no");
|
||||||
|
|
||||||
|
invoiceMap.put("asstact_number", customerNumber);//往来户(客户)
|
||||||
invoiceMap.put("buyertaxno", redInvoiceData.getString("tax_identification_number__c") != null ? redInvoiceData.getString("tax_identification_number__c") : "");//纳税识别号
|
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("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("buyerphone", redInvoiceData.getString("field_SM1Wc__c") != null ? redInvoiceData.getString("field_SM1Wc__c") : "");//电话
|
||||||
@ -492,7 +547,7 @@ public class InvoiceController {
|
|||||||
//同步成功
|
//同步成功
|
||||||
logMap.put("log_status", "0");
|
logMap.put("log_status", "0");
|
||||||
logMap.put("res_body", "同步成功");
|
logMap.put("res_body", "同步成功");
|
||||||
backReqMap.put("erp_id__c", erpInvoiceRes.getJSONObject("data").getString("pkId"));
|
backReqMap.put("field_UB1hE__c", erpInvoiceRes.getJSONObject("data").getString("pkId"));
|
||||||
backReqMap.put("sync_status__c", "option_sync_success__c");
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
backReqMap.put("response_info__c", "同步成功");
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
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 org.ssssssss.magicboot.utils.CrmRequestUtil;
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
import org.ssssssss.magicboot.utils.KingDeeUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ public class PreContractController {
|
|||||||
//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") != null ? preContractData.getString("contract_name__c") : "预签合同测试");//合同名称
|
erpContractReq.put("billname", preContractData.getString("project_name__c") != null ? preContractData.getString("project_name__c") : "预签合同");//合同名称
|
||||||
erpContractReq.put("type_number", "XSHT-YQ01");//合同类型
|
erpContractReq.put("type_number", "XSHT-YQ01");//合同类型
|
||||||
erpContractReq.put("contparties_number", "ZHY");//合同主体
|
erpContractReq.put("contparties_number", "ZHY");//合同主体
|
||||||
erpContractReq.put("createorg_number", "ZHY");//销售组织编码
|
erpContractReq.put("createorg_number", "ZHY");//销售组织编码
|
||||||
@ -268,6 +269,10 @@ public class PreContractController {
|
|||||||
backReqMap.put("erp_id__c", contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
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("sync_status__c", "option_sync_success__c");
|
||||||
backReqMap.put("response_info__c", "同步成功");
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
|
||||||
|
//开始审核
|
||||||
|
KingDeeUtils kingDeeUtils = new KingDeeUtils();
|
||||||
|
kingDeeUtils.audit(contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract_BT_YQ");
|
||||||
} else {
|
} else {
|
||||||
//同步失败
|
//同步失败
|
||||||
logMap.put("log_status", "1");
|
logMap.put("log_status", "1");
|
||||||
@ -564,6 +569,10 @@ public class PreContractController {
|
|||||||
backReqMap.put("erp_id__c", erpPreContractBGResJson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
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("sync_status__c", "option_sync_success__c");
|
||||||
backReqMap.put("response_info__c", "同步成功");
|
backReqMap.put("response_info__c", "同步成功");
|
||||||
|
|
||||||
|
//审核
|
||||||
|
KingDeeUtils kingDeeUtils = new KingDeeUtils();
|
||||||
|
kingDeeUtils.audit(erpPreContractBGResJson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
|
||||||
} else {
|
} else {
|
||||||
//同步失败
|
//同步失败
|
||||||
logMap.put("log_status", "1");
|
logMap.put("log_status", "1");
|
||||||
|
@ -44,7 +44,7 @@ public class QualityBackController {
|
|||||||
log.info("开始同步新建质量反馈单");
|
log.info("开始同步新建质量反馈单");
|
||||||
|
|
||||||
JSONObject getQualityBack = crmRequestUtil.getCRMList(Arrays.asList(
|
JSONObject getQualityBack = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
new Filter("EQ", "name", Arrays.asList("ZLXXFK202505160001"))
|
new Filter("EQ", "name", Arrays.asList("ZLXXFK202505270002"))
|
||||||
), "quality_feedback_form__c");
|
), "quality_feedback_form__c");
|
||||||
|
|
||||||
JSONObject qualityBack = new JSONObject();
|
JSONObject qualityBack = new JSONObject();
|
||||||
@ -142,9 +142,8 @@ public class QualityBackController {
|
|||||||
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
qualityReqMap.put("dept_number", "zyierp");//归属部门
|
qualityReqMap.put("dept_number", "ZHY");//归属部门
|
||||||
|
qualityReqMap.put("org_number", "ZHY");//todo 组织编码
|
||||||
qualityReqMap.put("org_number", "zyierp");//todo 组织编码
|
|
||||||
qualityReqMap.put("contractno", qualityBackData.getString("contract_number__c__r") != null ? qualityBackData.getString("contract_number__c__r") : "");//销售合同号
|
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") : "");//生产批次
|
qualityReqMap.put("productionbatch", qualityBackData.getString("production_batch__c") != null ? qualityBackData.getString("production_batch__c") : "");//生产批次
|
||||||
|
|
||||||
|
@ -0,0 +1,651 @@
|
|||||||
|
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.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/reimbursement")
|
||||||
|
@Slf4j
|
||||||
|
public class ReimbursementController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new ReimbursementController().syncReimbursement();
|
||||||
|
//new ReimbursementController().syncPublicExpenses();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报销查询同步 todo 需要完善
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/reimburse")
|
||||||
|
public void syncReimbursement() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
log.info("开始同步银行信息");
|
||||||
|
|
||||||
|
//获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
log.info("当前时间:{}", now);
|
||||||
|
//获取两天前的时间
|
||||||
|
LocalDateTime twoDaysAgo = now.minusDays(1);
|
||||||
|
|
||||||
|
//将时间转换样式
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String twoDaysAgoStr = twoDaysAgo.format(formatter);
|
||||||
|
String nowStr = now.format(formatter);
|
||||||
|
|
||||||
|
//开始查询f费用报销单
|
||||||
|
Map data = new HashMap<>();
|
||||||
|
data.put("startTime", twoDaysAgoStr);
|
||||||
|
data.put("endTime", nowStr);
|
||||||
|
|
||||||
|
Map expensesMap = new HashMap<>();
|
||||||
|
expensesMap.put("data", data);
|
||||||
|
expensesMap.put("pageNo", 1);
|
||||||
|
expensesMap.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 expensesEntity = new HttpEntity(expensesMap, headers);
|
||||||
|
|
||||||
|
String expensesUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/em/er_dailyreimbursebill/dailyreimbursebillQuery";
|
||||||
|
|
||||||
|
JSONObject expensesRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesRes = restTemplate.postForObject(expensesUrl, expensesEntity, JSONObject.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(expensesRes);
|
||||||
|
|
||||||
|
//开始判断是否存在符合条件的数据
|
||||||
|
if (!"0".equals(expensesRes.getString("errorCode")) || expensesRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
|
||||||
|
log.info("查询失败或者没有符合条件的单据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("数据存在,将继续向下执行");
|
||||||
|
|
||||||
|
for (Object expensesObj : expensesRes.getJSONObject("data").getJSONArray("rows")) {
|
||||||
|
JSONObject expensesData = JSON.parseObject(JSON.toJSONString(expensesObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的报销单数据为:" + expensesData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//ERPID
|
||||||
|
String expensesId = expensesData.getString("erpid");
|
||||||
|
//String expensesId = "6467554454212545";
|
||||||
|
String expensesCode = expensesData.getString("billno");//编码
|
||||||
|
String modifyTime = expensesData.getString("modifytime");//最后修改时间
|
||||||
|
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_fybx&log_type=FY&dataId=" + expensesId + "&mark=" + modifyTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前报销单存在日志,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("不存在日志,继续向下执行");
|
||||||
|
|
||||||
|
//开始封装请求
|
||||||
|
Map expensesMapReq = new HashMap<>();
|
||||||
|
expensesMapReq.put("erp_document_number__c", expensesCode);//单据编号
|
||||||
|
expensesMapReq.put("erp_id__c", expensesId);//单据ERPID
|
||||||
|
expensesMapReq.put("record_type", "record_kYs9j__c");//业务类型
|
||||||
|
expensesMapReq.put("dataObjectApiName", "ExpenseClaimFormObj");//对象名称
|
||||||
|
|
||||||
|
//开始获取时间数据并转换为字符串
|
||||||
|
String bizDate = expensesData.getString("bizdate");
|
||||||
|
|
||||||
|
// 定义时间格式
|
||||||
|
DateTimeFormatter formatterB = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
// 解析字符串为 LocalDateTime
|
||||||
|
LocalDateTime localDateTime = LocalDateTime.parse(bizDate, formatterB);
|
||||||
|
|
||||||
|
// 转换为时间戳(毫秒)
|
||||||
|
long timestamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||||
|
expensesMapReq.put("application_date", timestamp);//申请日期
|
||||||
|
|
||||||
|
//获取负责人信息
|
||||||
|
String ownerCode = "ID-000016";//todo 负责人编码
|
||||||
|
|
||||||
|
JSONObject getOwner = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "field_T1xid__c", Arrays.asList(ownerCode))
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject ownerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getOwner, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(ownerRes.getString("errorDescription")) || ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("负责人不存在或者请求失败");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("负责人数据为:" + ownerRes);
|
||||||
|
|
||||||
|
//开始截取负责人user_id
|
||||||
|
String ownerUserId = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("user_id");
|
||||||
|
expensesMapReq.put("owner", Arrays.asList(ownerUserId));
|
||||||
|
expensesMapReq.put("applicant", Arrays.asList(ownerUserId));
|
||||||
|
|
||||||
|
//todo 费用承担公司
|
||||||
|
String costCompany = expensesData.getString("costcompany_number");
|
||||||
|
|
||||||
|
//事由
|
||||||
|
String description = expensesData.getString("description") != null ? expensesData.getString("description") : "";
|
||||||
|
expensesMapReq.put("reason_for_event__c", description);//事由
|
||||||
|
|
||||||
|
//开始判断CRM里面是否已经存在该单据
|
||||||
|
Boolean isExist = false;
|
||||||
|
|
||||||
|
JSONObject getExpenses = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(expensesId)),
|
||||||
|
new Filter("EQ", "erp_document_number__c", Arrays.asList(expensesCode))
|
||||||
|
), "ExpenseClaimFormObj");
|
||||||
|
|
||||||
|
JSONObject expensesCRMRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getExpenses, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(expensesCRMRes.getString("errorDescription")) && !expensesCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("该报销单已经存在");
|
||||||
|
isExist = true;
|
||||||
|
expensesMapReq.put("_id", expensesCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装明细数据
|
||||||
|
List expensesDetails = new ArrayList<>();
|
||||||
|
for (Object expensesDetailObj : expensesData.getJSONArray("expenseentryentity")) {
|
||||||
|
JSONObject expensesDetailData = JSON.parseObject(JSON.toJSONString(expensesDetailObj));
|
||||||
|
System.out.println("当前正在处理的报销单明细数据为:" + expensesDetailData);
|
||||||
|
|
||||||
|
//开始封装明细数据
|
||||||
|
Map expensesDetailMap = new HashMap<>();
|
||||||
|
expensesDetailMap.put("record_type", "default__c");
|
||||||
|
|
||||||
|
String costProject = expensesDetailData.getString("std_project_number");
|
||||||
|
|
||||||
|
//项目号
|
||||||
|
if (costProject.contains("SJ")) {
|
||||||
|
//商机编号
|
||||||
|
JSONObject getBusiness = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "opportunity_id__c", Arrays.asList(costProject))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject businessRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
businessRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getBusiness, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(businessRes.getString("errorDescription")) && !businessRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject businessData = businessRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
expensesDetailMap.put("", businessData.getString("_id"));
|
||||||
|
}
|
||||||
|
} else if (costProject.contains("XM")) {
|
||||||
|
//项目编号
|
||||||
|
JSONObject getProject = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "project_no__c", Arrays.asList(costProject))
|
||||||
|
), "ProjectObj");
|
||||||
|
|
||||||
|
JSONObject projectRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProject, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(projectRes.getString("errorDescription")) && !projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject projectData = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
expensesDetailMap.put("project_id", projectData.getString("_id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo 成本中心
|
||||||
|
String costCenter = expensesDetailData.getString("expensesDetailData") != null ? expensesDetailData.getString("expensesDetailData") : "";
|
||||||
|
|
||||||
|
expensesDetailMap.put("amount", expensesDetailData.getBigDecimal("expenseamount"));//金额(价税合计)
|
||||||
|
expensesDetailMap.put("erp_row_id__c", expensesDetailData.getString("entryId"));//ERP行ID
|
||||||
|
|
||||||
|
//开始根据ERP行ID判断是否已经集成过该单据
|
||||||
|
JSONObject getExpensesDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(expensesDetailData.getString("entryId")))
|
||||||
|
), "ExpenseClaimFormDetailObj");
|
||||||
|
|
||||||
|
JSONObject expensesDetailCRMRes = new JSONObject();
|
||||||
|
try {
|
||||||
|
expensesDetailCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getExpensesDetail, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(expensesDetailCRMRes.getString("errorDescription")) && !expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("该报销单明细已经存在");
|
||||||
|
expensesDetailMap.put("_id", expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
expensesDetails.add(expensesDetailMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Map detailsMap = new HashMap<>();
|
||||||
|
detailsMap.put("ExpenseClaimFormDetailObj", expensesDetails);
|
||||||
|
|
||||||
|
JSONObject expensesReq = crmRequestUtil.crmWithDetail(expensesMapReq, detailsMap);
|
||||||
|
|
||||||
|
System.out.println("费用报销请求结果为:" + expensesReq);
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "FY");
|
||||||
|
logMap.put("data_name", expensesCode);
|
||||||
|
logMap.put("data_id", expensesId);
|
||||||
|
logMap.put("mark", modifyTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(expensesReq));
|
||||||
|
logMap.put("tableName", "send_log_fybx");
|
||||||
|
|
||||||
|
JSONObject expensesCRMReq = new JSONObject();
|
||||||
|
|
||||||
|
if (isExist) {
|
||||||
|
//已存在该单据,将进行更新
|
||||||
|
logMap.put("syn_type", "1");
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesCRMReq = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, expensesReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("费用报销更新请求结果为:" + expensesCRMReq);
|
||||||
|
} else {
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesCRMReq = restTemplate.postForObject(URLConstant.CREATE_CRM_CUSTOMER_MAIN, expensesReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("费用报销创建请求结果为:" + expensesCRMReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(expensesCRMReq.getString("errorDescription"))) {
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
} else {
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败" + expensesCRMReq.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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对公报销 todo 待完善
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public void syncPublicExpenses() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
log.info("开始同步对公报销信息");
|
||||||
|
|
||||||
|
//获取当前时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
log.info("当前时间:{}", now);
|
||||||
|
//获取两天前的时间
|
||||||
|
LocalDateTime twoDaysAgo = now.minusDays(5);
|
||||||
|
|
||||||
|
//将时间转换样式
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String twoDaysAgoStr = twoDaysAgo.format(formatter);
|
||||||
|
String nowStr = now.format(formatter);
|
||||||
|
|
||||||
|
//开始查询f费用报销单
|
||||||
|
Map data = new HashMap<>();
|
||||||
|
data.put("startTime", twoDaysAgoStr);
|
||||||
|
data.put("endTime", nowStr);
|
||||||
|
|
||||||
|
Map expensesMap = new HashMap<>();
|
||||||
|
expensesMap.put("data", data);
|
||||||
|
expensesMap.put("pageNo", 1);
|
||||||
|
expensesMap.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 expensesEntity = new HttpEntity(expensesMap, headers);
|
||||||
|
|
||||||
|
String expensesUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/em/er_publicreimbursebill/publicreimbursebillQuery";
|
||||||
|
|
||||||
|
JSONObject expensesRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesRes = restTemplate.postForObject(expensesUrl, expensesEntity, JSONObject.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(expensesRes);
|
||||||
|
|
||||||
|
//判断是否成功或者数据是否存在
|
||||||
|
if (!"0".equals(expensesRes.getString("errorCode")) || expensesRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
|
||||||
|
log.info("查询失败或者没有符合条件的单据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object expensesObj : expensesRes.getJSONObject("data").getJSONArray("rows")) {
|
||||||
|
JSONObject expensesData = JSON.parseObject(JSON.toJSONString(expensesObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理数据为:" + expensesData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//ERPID
|
||||||
|
String erpId = expensesData.getString("erpid");
|
||||||
|
//单据名称
|
||||||
|
String erpNo = expensesData.getString("billno");
|
||||||
|
//最后修改时间
|
||||||
|
String modifyTime = expensesData.getString("modifytime");
|
||||||
|
|
||||||
|
//开始判断是否已经集成过该单据
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_fybx&log_type=FYDG&dataId=" + erpId + "&mark=" + modifyTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前数据已经执行过了,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志不存在,将继续向下执行");
|
||||||
|
|
||||||
|
//开始封装请求参数
|
||||||
|
Map expensesMainReq = new HashMap();
|
||||||
|
expensesMainReq.put("erp_document_number__c", erpNo);//ERP单据编码
|
||||||
|
expensesMainReq.put("erp_id__c", erpId);//ERP单据ID
|
||||||
|
expensesMainReq.put("record_type", "record_Lu2Cc__c");
|
||||||
|
expensesMainReq.put("dataObjectApiName", "ExpenseClaimFormObj");//对象名称
|
||||||
|
expensesMainReq.put("reason_for_event__c", expensesData.getString("description") != null ? expensesData.getString("description") : "");//事由
|
||||||
|
|
||||||
|
//开始获取时间数据并转换为字符串
|
||||||
|
String bizDate = expensesData.getString("bizdate");
|
||||||
|
|
||||||
|
// 定义时间格式
|
||||||
|
DateTimeFormatter formatterB = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
// 解析字符串为 LocalDateTime
|
||||||
|
LocalDateTime localDateTime = LocalDateTime.parse(bizDate, formatterB);
|
||||||
|
|
||||||
|
// 转换为时间戳(毫秒)
|
||||||
|
long timestamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||||
|
expensesMainReq.put("application_date", timestamp);//申请日期
|
||||||
|
|
||||||
|
//获取负责人信息
|
||||||
|
String ownerCode = "ID-000016";//todo 负责人编码
|
||||||
|
|
||||||
|
JSONObject getOwner = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "field_T1xid__c", Arrays.asList(ownerCode))
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject ownerRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getOwner, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(ownerRes.getString("errorDescription")) || ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("负责人不存在或者请求失败");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("负责人数据为:" + ownerRes);
|
||||||
|
|
||||||
|
//开始截取负责人user_id
|
||||||
|
String ownerUserId = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("user_id");
|
||||||
|
expensesMainReq.put("owner", Arrays.asList(ownerUserId));
|
||||||
|
expensesMainReq.put("applicant", Arrays.asList(ownerUserId));
|
||||||
|
|
||||||
|
//开始判断CRM里面是否已经存在该单据
|
||||||
|
Boolean isExist = false;
|
||||||
|
|
||||||
|
JSONObject getExpenses = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(erpId)),
|
||||||
|
new Filter("EQ", "erp_document_number__c", Arrays.asList(erpNo))
|
||||||
|
), "ExpenseClaimFormObj");
|
||||||
|
|
||||||
|
JSONObject expensesCRMRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesCRMRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getExpenses, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(expensesCRMRes.getString("errorDescription")) && !expensesCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("该报销单已经存在");
|
||||||
|
isExist = true;
|
||||||
|
expensesMainReq.put("_id", expensesCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
List expensesDetailReq = new ArrayList();
|
||||||
|
|
||||||
|
//开始封装明细数据
|
||||||
|
for (Object expenseDetailObj : expensesData.getJSONArray("expenseentryentity")) {
|
||||||
|
JSONObject expenseDetailData = JSON.parseObject(JSON.toJSONString(expenseDetailObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理明细数据为:" + expenseDetailData);
|
||||||
|
|
||||||
|
//开始封装明细数据
|
||||||
|
Map expensesDetail = new HashMap();
|
||||||
|
expensesDetail.put("record_type", "record_Eex1M__c");//对公报销
|
||||||
|
|
||||||
|
String projectCode = expenseDetailData.getString("std_project_number") != null ? expenseDetailData.getString("std_project_number") : "";
|
||||||
|
|
||||||
|
//开始判断项目来源
|
||||||
|
if (projectCode.contains("SJ")) {
|
||||||
|
//商机编号
|
||||||
|
JSONObject getBusiness = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "opportunity_id__c", Arrays.asList(projectCode))
|
||||||
|
), "NewOpportunityObj");
|
||||||
|
|
||||||
|
JSONObject businessRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
businessRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getBusiness, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(businessRes.getString("errorDescription")) && !businessRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject businessData = businessRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
expensesDetail.put("", businessData.getString("_id"));
|
||||||
|
}
|
||||||
|
} else if (projectCode.contains("XM")) {
|
||||||
|
//项目编号
|
||||||
|
JSONObject getProject = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "project_no__c", Arrays.asList(projectCode))
|
||||||
|
), "ProjectObj");
|
||||||
|
|
||||||
|
JSONObject projectRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProject, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(projectRes.getString("errorDescription")) && !projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject projectData = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
expensesDetail.put("project_id", projectData.getString("_id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expensesDetail.put("amount", expenseDetailData.getBigDecimal("expenseamount"));//金额(价税合计)
|
||||||
|
expensesDetail.put("erp_row_id__c", expenseDetailData.getString("entryId"));//ERP行ID
|
||||||
|
|
||||||
|
//开始根据ERP行ID判断是否已经集成过该单据
|
||||||
|
JSONObject getExpensesDetail = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(expenseDetailData.getString("entryId")))
|
||||||
|
), "ExpenseClaimFormDetailObj");
|
||||||
|
|
||||||
|
JSONObject expensesDetailCRMRes = new JSONObject();
|
||||||
|
try {
|
||||||
|
expensesDetailCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getExpensesDetail, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(expensesDetailCRMRes.getString("errorDescription")) && !expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("该报销单明细已经存在");
|
||||||
|
expensesDetail.put("_id", expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
expensesDetailReq.add(expensesDetail);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map detailsMap = new HashMap<>();
|
||||||
|
detailsMap.put("ExpenseClaimFormDetailObj", expensesDetailReq);
|
||||||
|
|
||||||
|
JSONObject expensesReq = crmRequestUtil.crmWithDetail(expensesMainReq, detailsMap);
|
||||||
|
|
||||||
|
System.out.println("费用报销请求结果为:" + expensesReq);
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "FYDG");
|
||||||
|
logMap.put("data_name", erpNo);
|
||||||
|
logMap.put("data_id", erpId);
|
||||||
|
logMap.put("mark", modifyTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(expensesReq));
|
||||||
|
logMap.put("tableName", "send_log_fybx");
|
||||||
|
|
||||||
|
JSONObject expensesCRMReq = new JSONObject();
|
||||||
|
|
||||||
|
if (isExist) {
|
||||||
|
//已存在该单据,将进行更新
|
||||||
|
logMap.put("syn_type", "1");
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesCRMReq = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, expensesReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("费用报销更新请求结果为:" + expensesCRMReq);
|
||||||
|
} else {
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
|
||||||
|
try {
|
||||||
|
expensesCRMReq = restTemplate.postForObject(URLConstant.CREATE_CRM_CUSTOMER_MAIN, expensesReq, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("费用报销创建请求结果为:" + expensesCRMReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(expensesCRMReq.getString("errorDescription"))) {
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
} else {
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败" + expensesCRMReq.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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,235 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import groovyjarjarpicocli.CommandLine;
|
||||||
|
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.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/tendering")
|
||||||
|
@Slf4j
|
||||||
|
public class TenderingController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new TenderingController().syncTendering();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投标费用
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/tendering")
|
||||||
|
public void syncTendering() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
JSONObject getTendering = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList("BSGM250509"))
|
||||||
|
), "bid_application__c");
|
||||||
|
|
||||||
|
JSONObject tenderingRes = new JSONObject();
|
||||||
|
|
||||||
|
//开始查询
|
||||||
|
try {
|
||||||
|
tenderingRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getTendering, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"success".equals(tenderingRes.getString("errorDescription")) && tenderingRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("投标费用请求失败或者没有符合条件的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("投标费用请求成功,继续向下执行");
|
||||||
|
|
||||||
|
for (Object tenderingObj : tenderingRes.getJSONObject("data").getJSONArray("dataList")) {
|
||||||
|
JSONObject tenderingData = JSON.parseObject(JSON.toJSONString(tenderingObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理数据为:" + tenderingData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
//唯一性ID
|
||||||
|
String tenderingId = tenderingData.getString("_id");
|
||||||
|
//投标单号
|
||||||
|
String tenderingName = tenderingData.getString("name");
|
||||||
|
//投标单创建时间
|
||||||
|
String createTime = tenderingData.getString("create_time");
|
||||||
|
|
||||||
|
//开始判断是否集成过该单据了
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18088/Log/query/log_data?table=send_log_tendering&log_type=TBFY&dataId=" + tenderingId + "&mark=" + createTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("当前投标单存在日志,将不再向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("不存在日志,继续向下执行");
|
||||||
|
|
||||||
|
//开始封装请求
|
||||||
|
Map tenderingMapReq = new HashMap<>();
|
||||||
|
tenderingMapReq.put("number", tenderingData.getString("field_31pd4__c"));//标书购买申请流水号
|
||||||
|
tenderingMapReq.put("f9w5_crmid", tenderingId);//标书购买申请ID
|
||||||
|
tenderingMapReq.put("name", tenderingData.getString("opportunity_name__c__r") != null ? tenderingData.getString("opportunity_name__c__r") : "");//商机名称
|
||||||
|
|
||||||
|
//申请类型
|
||||||
|
String applyType = tenderingData.getString("application_type__c") != null ? tenderingData.getString("application_type__c") : "";
|
||||||
|
|
||||||
|
String applyTypeStr = "";
|
||||||
|
|
||||||
|
switch (applyType) {
|
||||||
|
case "cNKcx460m":
|
||||||
|
applyTypeStr = "A";
|
||||||
|
break;
|
||||||
|
case "option1":
|
||||||
|
applyTypeStr = "B";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
applyTypeStr = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
tenderingMapReq.put("f9w5_applytype", applyTypeStr);//申请类型
|
||||||
|
tenderingMapReq.put("f9w5_lot", tenderingData.getString("batch_name__c") != null ? tenderingData.getString("batch_name__c") : "");//批次名称
|
||||||
|
tenderingMapReq.put("createorg_number", "ZHY");//组织
|
||||||
|
|
||||||
|
//供应商ID
|
||||||
|
String vendorId = tenderingData.getString("bidding_agency__c") != null ? tenderingData.getString("bidding_agency__c") : "";
|
||||||
|
|
||||||
|
String vendorErpCode = "";
|
||||||
|
if (vendorId != null && !vendorId.equals("")) {
|
||||||
|
JSONObject getVendor = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "_id", Arrays.asList(vendorId))
|
||||||
|
), "SupplierObj");
|
||||||
|
|
||||||
|
JSONObject vendorRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
vendorRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getVendor, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(vendorRes.getString("errorDescription")) && !vendorRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
vendorErpCode = vendorRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("erp_number__c");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tenderingMapReq.put("f9w5_institution_number", vendorErpCode);//招投标代理机构
|
||||||
|
|
||||||
|
Map data = new HashMap<>();
|
||||||
|
data.put("data", tenderingMapReq);
|
||||||
|
|
||||||
|
//开始获取ERP的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 tenderingReqEntity = new HttpEntity(data, headers);
|
||||||
|
|
||||||
|
System.out.println(JSON.parseObject(JSON.toJSONString(tenderingReqEntity)));
|
||||||
|
|
||||||
|
String tenderingUrl = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/em/f9w5_tenderbuyapply/save";
|
||||||
|
|
||||||
|
JSONObject tenderingERPRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
tenderingERPRes = restTemplate.postForObject(tenderingUrl, tenderingReqEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(tenderingERPRes);
|
||||||
|
|
||||||
|
//开始封装回写程序
|
||||||
|
Map backReqMap = new HashMap();
|
||||||
|
backReqMap.put("_id", tenderingId);
|
||||||
|
backReqMap.put("dataObjectApiName", "bid_application__c");
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("log_type", "TBFY");
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("data_name", tenderingName);
|
||||||
|
logMap.put("data_id", tenderingId);
|
||||||
|
logMap.put("mark", createTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(tenderingReqEntity));
|
||||||
|
logMap.put("send_res", JSON.toJSONString(tenderingERPRes));
|
||||||
|
logMap.put("tableName", "send_log_tendering");
|
||||||
|
|
||||||
|
//判断是否执行成功
|
||||||
|
if ("0".equals(tenderingERPRes.getString("errorCode"))) {
|
||||||
|
//同步成功
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
backReqMap.put("erp_id__c", tenderingERPRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_success__c");
|
||||||
|
backReqMap.put("response_status__c", "同步成功");
|
||||||
|
} else {
|
||||||
|
//同步失败
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败:" + tenderingERPRes.getString("message"));
|
||||||
|
backReqMap.put("sync_status__c", "option_sync_failure__c");
|
||||||
|
backReqMap.put("response_status__c", tenderingERPRes.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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,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("ZHY2505220017")),
|
new Filter("EQ", "name", Arrays.asList("ZHY2505280021")),
|
||||||
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
), "SaleContractObj");
|
), "SaleContractObj");
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ public class XSHTController {
|
|||||||
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", "ceshiceshi");//合同名称
|
erpContractReq.put("billname", contractData.getString("project_name__c") != null ? contractData.getString("project_name__c") : "销售合同");//合同名称
|
||||||
erpContractReq.put("type_number", "XSHT-QD01");//合同类型
|
erpContractReq.put("type_number", "XSHT-QD01");//合同类型
|
||||||
erpContractReq.put("contparties_number", "ZHY");//合同主体
|
erpContractReq.put("contparties_number", "ZHY");//合同主体
|
||||||
erpContractReq.put("createorg_number", "ZHY");//销售组织编码
|
erpContractReq.put("createorg_number", "ZHY");//销售组织编码
|
||||||
@ -216,8 +216,8 @@ 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-000001");//合同单位名称
|
//erpContractReq.put("customer_number", "Cus-000001");//合同单位名称
|
||||||
|
|
||||||
//获取产品线
|
//获取产品线
|
||||||
erpContractReq.put("productline_number", contractData.getString("product_line__c"));//产品线
|
erpContractReq.put("productline_number", contractData.getString("product_line__c"));//产品线
|
||||||
@ -302,10 +302,10 @@ public class XSHTController {
|
|||||||
//开始封装销售合同明细
|
//开始封装销售合同明细
|
||||||
Map contractDetailMap = new HashMap();
|
Map contractDetailMap = new HashMap();
|
||||||
contractDetailMap.put("linetype_number", "020");//行类型
|
contractDetailMap.put("linetype_number", "020");//行类型
|
||||||
contractDetailMap.put("materialname", contractDetailData.getString("product_name__c"));//产品名称
|
contractDetailMap.put("goodsname", 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");//todo 物料编号
|
contractDetailMap.put("material_number", "TEST0001");//todo 物料编号
|
||||||
contractDetailMap.put("specifications", contractDetailData.getString("specification__c") != null ? contractDetailData.getString("specification__c") : "");//规格
|
contractDetailMap.put("specification", contractDetailData.getString("specification__c") != null ? contractDetailData.getString("specification__c") : "");//规格
|
||||||
contractDetailMap.put("baseunit", contractDetailData.getString("unit__c__r") != null ? contractDetailData.getString("unit__c__r") : "");//单位
|
contractDetailMap.put("baseunit", 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");//单位编码
|
||||||
@ -313,11 +313,11 @@ public class XSHTController {
|
|||||||
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);//数量
|
||||||
contractDetailMap.put("priceandtax", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//含税单价
|
contractDetailMap.put("priceandtax", contractDetailData.getBigDecimal("sales_price") != null ? contractDetailData.getBigDecimal("sales_price") : 0);//含税单价
|
||||||
//contractDetailMap.put("taxrateid_number", contractDetailData.getBigDecimal("tax_rate__c") != null ? contractDetailData.getBigDecimal("tax_rate__c") : 0);//税率
|
//contractDetailMap.put("taxrateid_number", contractDetailData.getBigDecimal("tax_rate__c") != null ? contractDetailData.getBigDecimal("tax_rate__c") : 0);//税率
|
||||||
contractDetailMap.put("taxrateid_number", "V13");//税率
|
contractDetailMap.put("taxrateid_number", "V13");//税率
|
||||||
contractDetailMap.put("curamountandtax", contractDetailData.getBigDecimal("subtotal") != null ? contractDetailData.getBigDecimal("subtotal") : 0);//价税合计
|
contractDetailMap.put("curamountandtax", contractDetailData.getBigDecimal("subtotal") != null ? contractDetailData.getBigDecimal("subtotal") : 0);//价税合计
|
||||||
contractDetailMap.put("curtaxamount", contractDetailData.getBigDecimal("tax_amount__c") != null ? contractDetailData.getBigDecimal("tax_amount__c") : 0);//金额
|
//contractDetailMap.put("curtaxamount", contractDetailData.getBigDecimal("tax_amount__c") != null ? contractDetailData.getBigDecimal("tax_amount__c") : 0);//金额
|
||||||
contractDetailMap.put("crmentryid", contractDetailData.getString("_id"));//明细id
|
contractDetailMap.put("crmentryid", contractDetailData.getString("_id"));//明细id
|
||||||
|
|
||||||
contractDetailList.add(contractDetailMap);
|
contractDetailList.add(contractDetailMap);
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
package org.ssssssss.magicboot.utils;
|
||||||
|
|
||||||
|
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.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.ssssssss.magicboot.controller.KDTokenController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class KingDeeUtils {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ERPID和单据类型进行审核
|
||||||
|
*
|
||||||
|
* @param ErpId
|
||||||
|
* @param BillType:
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
public void audit(String ErpId, String BillType) {
|
||||||
|
String url = "http://192.168.31.233:8022/ierp/kapi/v2/f9w5/devportal/operation/submit";
|
||||||
|
|
||||||
|
//开始封装参数
|
||||||
|
Map auditParams = new HashMap();
|
||||||
|
auditParams.put("erpId", ErpId);
|
||||||
|
auditParams.put("formId", BillType);
|
||||||
|
|
||||||
|
//开始获取accessToken
|
||||||
|
//开始获取金蝶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 auditEntity = new HttpEntity(auditParams, headers);
|
||||||
|
|
||||||
|
JSONObject auditResult = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
auditResult = restTemplate.postForObject(url, auditEntity, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("审核单据的状态为:" + auditResult);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user