浩赛集成优化内容
This commit is contained in:
parent
891476e60d
commit
3c0e6f91f0
@ -77,9 +77,9 @@ public class ProductController {
|
|||||||
//开始封装请求
|
//开始封装请求
|
||||||
Map getProductReq = new HashMap<>();
|
Map getProductReq = new HashMap<>();
|
||||||
getProductReq.put("pageIndex", 1);
|
getProductReq.put("pageIndex", 1);
|
||||||
getProductReq.put("pageSize", 10);
|
getProductReq.put("pageSize", 100);
|
||||||
|
|
||||||
getProductReq.put("productCodeList", Arrays.asList("A02.0005.PA569345"));
|
//getProductReq.put("productCodeList", Arrays.asList("A02.0005.PA569345"));
|
||||||
|
|
||||||
// getProductReq.put("endTime", nowStr);
|
// getProductReq.put("endTime", nowStr);
|
||||||
// getProductReq.put("beginTime", twoDaysAgoStr);
|
// getProductReq.put("beginTime", twoDaysAgoStr);
|
||||||
@ -156,6 +156,7 @@ public class ProductController {
|
|||||||
product.put("name", productCode);//产品货号
|
product.put("name", productCode);//产品货号
|
||||||
product.put("product_name__c", productName);//产品名称
|
product.put("product_name__c", productName);//产品名称
|
||||||
product.put("product_spec", productData.getString("modelDescription") != null ? productData.getString("modelDescription") : "");//规格型号
|
product.put("product_spec", productData.getString("modelDescription") != null ? productData.getString("modelDescription") : "");//规格型号
|
||||||
|
product.put("erp_unit_code__c", productData.getString("unitCode") != null ? productData.getString("unitCode") : "");//ERP单位编码
|
||||||
//产品短码
|
//产品短码
|
||||||
product.put("product_short_code__c", productData.getString("model") != null ? productData.getString("model") : "");
|
product.put("product_short_code__c", productData.getString("model") != null ? productData.getString("model") : "");
|
||||||
//物料分类
|
//物料分类
|
||||||
|
@ -0,0 +1,523 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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.HttpStatusCodeException;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.ssssssss.magicboot.Enum.OrderTradeTypeEnum;
|
||||||
|
import org.ssssssss.magicboot.Enum.SalesOrgEnum;
|
||||||
|
import org.ssssssss.magicboot.Enum.TaxRateEnum;
|
||||||
|
import org.ssssssss.magicboot.constant.URLConstant;
|
||||||
|
import org.ssssssss.magicboot.entity.Filter;
|
||||||
|
import org.ssssssss.magicboot.utils.ChineseMoneyUtil;
|
||||||
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
import org.ssssssss.magicboot.utils.YSSignUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/hs")
|
||||||
|
@Slf4j
|
||||||
|
public class SalesController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new SalesController().syncSales();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向CRM中传递销售订单数据
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
@PostMapping("/sync/salesOrder/toCrm")
|
||||||
|
public void syncSales() {
|
||||||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
||||||
|
|
||||||
|
log.info("开始执行销售订单变更同步");
|
||||||
|
|
||||||
|
//获取当前的时间
|
||||||
|
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
String nowStr = now.format(sdf);
|
||||||
|
|
||||||
|
log.info("当前时间:{}", nowStr);
|
||||||
|
|
||||||
|
//获取两天前的时间
|
||||||
|
LocalDateTime twoDaysAgo = now.minusDays(1);//直接减去2天
|
||||||
|
|
||||||
|
String twoDaysAgoStr = twoDaysAgo.format(sdf);
|
||||||
|
|
||||||
|
log.info("两天前的时间:{}", twoDaysAgoStr);
|
||||||
|
|
||||||
|
Map getSalesOrder = new HashMap<>();
|
||||||
|
getSalesOrder.put("pageIndex", 1);
|
||||||
|
getSalesOrder.put("pageSize", 10);
|
||||||
|
getSalesOrder.put("isSum", true);
|
||||||
|
getSalesOrder.put("code", "DD25082200001");
|
||||||
|
|
||||||
|
Map simpleVO = new HashMap<>();
|
||||||
|
simpleVO.put("op", "gt");
|
||||||
|
simpleVO.put("field", "modifyTime");
|
||||||
|
simpleVO.put("value1", twoDaysAgoStr);
|
||||||
|
|
||||||
|
getSalesOrder.put("simpleVOs", Arrays.asList(simpleVO));
|
||||||
|
|
||||||
|
System.out.println(JSONObject.parseObject(JSON.toJSONString(getSalesOrder)));
|
||||||
|
|
||||||
|
//开始获取token
|
||||||
|
String erpToken = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
erpToken = new YSSignUtils().getYSToken();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始发起请求
|
||||||
|
String url = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/sd/voucherorder/list" + "?access_token=" + erpToken;//url
|
||||||
|
|
||||||
|
JSONObject salesOrderRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
salesOrderRes = restTemplate.postForObject(url, getSalesOrder, JSONObject.class);
|
||||||
|
} catch (HttpStatusCodeException e) {
|
||||||
|
// 获取响应体的错误信息
|
||||||
|
String errorBody = e.getResponseBodyAsString();
|
||||||
|
System.out.println("调用接口失败,状态码:" + e.getStatusCode());
|
||||||
|
System.out.println("错误响应:" + errorBody);
|
||||||
|
|
||||||
|
// 将错误响应封装为 JSONObject(可选)
|
||||||
|
salesOrderRes = JSONObject.parseObject(errorBody);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
System.out.println("调用接口失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(salesOrderRes);
|
||||||
|
|
||||||
|
if (!"200".equals(salesOrderRes.getString("code")) || salesOrderRes.getJSONObject("data").getJSONArray("recordList").isEmpty()) {
|
||||||
|
log.info("erp请求订单失败或者没有符合条件的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("erp请求订单成功,继续向下执行");
|
||||||
|
|
||||||
|
for (Object salesOrderObj : salesOrderRes.getJSONObject("data").getJSONArray("recordList")) {
|
||||||
|
JSONObject salesOrderData = JSON.parseObject(JSON.toJSONString(salesOrderObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理的销售订单数据为:" + salesOrderData);
|
||||||
|
|
||||||
|
//开始截取关键数据
|
||||||
|
String salesOrderId = salesOrderData.getString("id");
|
||||||
|
String salesOrderCode = salesOrderData.getString("code");
|
||||||
|
String modifyTime = salesOrderData.getString("modifyTime");
|
||||||
|
|
||||||
|
JSONObject isLogRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLogRes = restTemplate.getForObject("http://localhost:18080/Log/query/log_data?table=send_log_xsdd&log_type=XSDDCRM&dataId=" + salesOrderId + "&mark=" + modifyTime, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
||||||
|
log.info("销售订单已经执行过了,将不再继续向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("销售订单没有执行过,将继续执行");
|
||||||
|
|
||||||
|
//先查询CRM中是否存在当前销售订单
|
||||||
|
JSONObject getOrderFromCRM = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(salesOrderId)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "SalesOrderObj");
|
||||||
|
|
||||||
|
JSONObject orderFromCRMRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
orderFromCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getOrderFromCRM, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(orderFromCRMRes.getString("errorDescription")) && !orderFromCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
log.info("查询成功,当前数据已经在CRM中存在,将不再继续向下执行");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("开始封装主表数据");
|
||||||
|
|
||||||
|
//开始封装主表数据
|
||||||
|
Map salesOrderMain = new HashMap<>();
|
||||||
|
salesOrderMain.put("erp_id__c", salesOrderId);
|
||||||
|
//开始获取交易类型
|
||||||
|
String tradeType = salesOrderData.getString("transactionTypeId_name") != null ? salesOrderData.getString("transactionTypeId_name") : "";
|
||||||
|
String tradeTypeStr = "";
|
||||||
|
|
||||||
|
if (!tradeType.equals("")) {
|
||||||
|
tradeTypeStr = OrderTradeTypeEnum.getValueByName(tradeType);
|
||||||
|
}
|
||||||
|
salesOrderMain.put("order_type__c", tradeTypeStr);
|
||||||
|
|
||||||
|
//销售组织
|
||||||
|
String salesOrg = salesOrderData.getString("salesOrgId_name") != null ? salesOrderData.getString("salesOrgId_name") : "";
|
||||||
|
String salesOrgStr = "";
|
||||||
|
|
||||||
|
if (!salesOrg.equals("")) {
|
||||||
|
salesOrgStr = SalesOrgEnum.getValueByName(salesOrg);
|
||||||
|
}
|
||||||
|
|
||||||
|
salesOrderMain.put("field_1Vkdk__c", salesOrgStr);
|
||||||
|
|
||||||
|
//单据日期
|
||||||
|
String docDateStr = salesOrderData.getString("vouchdate") != null ? salesOrderData.getString("vouchdate") : "";
|
||||||
|
|
||||||
|
// 解析格式
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
LocalDateTime localDateTime = LocalDateTime.parse(docDateStr, formatter);
|
||||||
|
|
||||||
|
// 转换为时间戳(毫秒)
|
||||||
|
long docDataStamp = localDateTime
|
||||||
|
.atZone(ZoneId.systemDefault()) // 系统默认时区
|
||||||
|
.toInstant()
|
||||||
|
.toEpochMilli();
|
||||||
|
|
||||||
|
salesOrderMain.put("order_time", docDataStamp);
|
||||||
|
|
||||||
|
//联系人
|
||||||
|
String contactERPId = salesOrderData.getString("agentId") != null ? salesOrderData.getString("agentId") : "";
|
||||||
|
//String contactERPId = "2339048217807683589";//todo 测试
|
||||||
|
|
||||||
|
//开始查询联系人信息
|
||||||
|
JSONObject getContact = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(contactERPId)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "ContactObj");
|
||||||
|
|
||||||
|
JSONObject contactRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
contactRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getContact, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(contactRes.getString("errorDescription")) && !contactRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject contactData = contactRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
salesOrderMain.put("contact_person__c", contactData.getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//客户单位
|
||||||
|
//获取自定义字段
|
||||||
|
JSONObject customizeData = salesOrderData.getJSONObject("orderDefineCharacter");
|
||||||
|
|
||||||
|
//获取客户erp编码
|
||||||
|
String customerERPId = customizeData.getString("SJKH01") != null ? customizeData.getString("SJKH01") : "";
|
||||||
|
//String customerERPId = "2339048071778795532"; //todo 测试
|
||||||
|
|
||||||
|
JSONObject getCustomer = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "ERP_ID__c", Arrays.asList(customerERPId)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "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()) {
|
||||||
|
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
salesOrderMain.put("account_id", customerData.getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//课题组
|
||||||
|
String researchGroup = customizeData.getString("KTZ001") != null ? customizeData.getString("KTZ001") : "";
|
||||||
|
//String researchGroup = "2337485545509224455"; //todo 测试
|
||||||
|
|
||||||
|
JSONObject getResearchGroup = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(researchGroup)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "topic_group__c");
|
||||||
|
|
||||||
|
JSONObject researchGroupRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
researchGroupRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getResearchGroup, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(researchGroupRes.getString("errorDescription")) && !researchGroupRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject researchGroupData = researchGroupRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
salesOrderMain.put("research_team__c", researchGroupData.getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//院所或者科室
|
||||||
|
String institute = customizeData.getString("KSYS01") != null ? customizeData.getString("KSYS01") : "";
|
||||||
|
//String institute = "2337485150355456003";
|
||||||
|
|
||||||
|
JSONObject getInstitute = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(institute)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "department_institute__c");
|
||||||
|
|
||||||
|
JSONObject instituteRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
instituteRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInstitute, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(instituteRes.getString("errorDescription")) && !instituteRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject instituteData = instituteRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
salesOrderMain.put("institution_or_department__c", instituteData.getString("_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//销售员
|
||||||
|
String salesman = salesOrderData.getString("corpContact") != null ? salesOrderData.getString("corpContact") : "";
|
||||||
|
|
||||||
|
JSONObject getSalesman = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "erp_id__c", Arrays.asList(salesman)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "PersonnelObj");
|
||||||
|
|
||||||
|
JSONObject salesmanRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
salesmanRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getSalesman, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(salesmanRes.getString("errorDescription")) && !salesmanRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject salesmanData = salesmanRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
String userId = salesmanData.getString("user_id") != null ? salesmanData.getString("user_id") : "";
|
||||||
|
|
||||||
|
salesOrderMain.put("owner", Arrays.asList(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
//合同编号
|
||||||
|
salesOrderMain.put("contract_number__c", customizeData.getString("HT01") != null ? customizeData.getString("HT01") : "");
|
||||||
|
|
||||||
|
//付款方式
|
||||||
|
salesOrderMain.put("field_0f31k__c", customizeData.getString("FKFS01") != null ? customizeData.getString("FKFS01") : "");
|
||||||
|
|
||||||
|
//核销备注
|
||||||
|
salesOrderMain.put("reconciliation_note__c", customizeData.getString("ZDY0006") != null ? customizeData.getString("ZDY0006") : "");
|
||||||
|
|
||||||
|
//备注
|
||||||
|
salesOrderMain.put("delivery_comment", customizeData.getString("memo") != null ? customizeData.getString("memo") : "");
|
||||||
|
|
||||||
|
//收货地址
|
||||||
|
salesOrderMain.put("delivery_address__c", customizeData.getString("orderShippingAddress") != null ? customizeData.getString("orderShippingAddress") : "");
|
||||||
|
|
||||||
|
//销售订单金额
|
||||||
|
salesOrderMain.put("order_amount", salesOrderData.getBigDecimal("orderPayMoney") != null ? salesOrderData.getBigDecimal("orderPayMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//中文大写
|
||||||
|
String chineseMoney = ChineseMoneyUtil.toChinese(salesOrderData.getBigDecimal("orderPayMoney") != null ? salesOrderData.getBigDecimal("orderPayMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
salesOrderMain.put("order_amount_in_words__c", chineseMoney);
|
||||||
|
|
||||||
|
salesOrderMain.put("dataObjectApiName", "SalesOrderObj");
|
||||||
|
|
||||||
|
//开始查询销售订单明细
|
||||||
|
String detailUrl = "https://c1.yonyoucloud.com/iuap-api-gateway/yonbip/sd/voucherorder/detail?access_token=" + erpToken + "&id=" + salesOrderId;
|
||||||
|
|
||||||
|
JSONObject salesOrderDetail = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
salesOrderDetail = restTemplate.getForObject(detailUrl, JSONObject.class);
|
||||||
|
} catch (HttpStatusCodeException e) {
|
||||||
|
//获取响应体的错误信息
|
||||||
|
String errorBody = e.getResponseBodyAsString();
|
||||||
|
System.out.println("调用接口失败,状态码:" + e.getStatusCode());
|
||||||
|
System.out.println("错误响应:" + errorBody);
|
||||||
|
|
||||||
|
//将错误响应封装为 JSONObject(可选)
|
||||||
|
salesOrderDetail = JSONObject.parseObject(errorBody);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
System.out.println("调用接口失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("查询的销售订单数据为" + salesOrderDetail);
|
||||||
|
|
||||||
|
if (!"200".equals(salesOrderDetail.getString("code")) || salesOrderDetail.getJSONObject("data").getJSONArray("orderDetails").isEmpty()) {
|
||||||
|
log.info("erp请求销售订单明细失败或者没有符合条件数据");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List orderDetailList = new ArrayList();
|
||||||
|
|
||||||
|
for (Object orderDetailObj : salesOrderDetail.getJSONObject("data").getJSONArray("orderDetails")) {
|
||||||
|
JSONObject orderDetailData = JSON.parseObject(JSON.toJSONString(orderDetailObj));
|
||||||
|
|
||||||
|
System.out.println("当前正在处理数据为:" + orderDetailData);
|
||||||
|
|
||||||
|
//开始封装明细数据
|
||||||
|
Map orderDetailMap = new HashMap();
|
||||||
|
//erp行Id
|
||||||
|
orderDetailMap.put("field_9b817__c", orderDetailData.getString("id"));
|
||||||
|
|
||||||
|
//获取产品编码
|
||||||
|
String productCode = orderDetailData.getString("productCode") != null ? orderDetailData.getString("productCode") : "";
|
||||||
|
|
||||||
|
//根据物料编码查询CRM产品
|
||||||
|
JSONObject getProduct = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList(productCode)),
|
||||||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
||||||
|
), "ProductObj");
|
||||||
|
|
||||||
|
JSONObject productRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
productRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProduct, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("success".equals(productRes.getString("errorDescription")) && !productRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
||||||
|
JSONObject productData = productRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
||||||
|
|
||||||
|
orderDetailMap.put("product_id", productData.getString("_id"));
|
||||||
|
//目录价
|
||||||
|
orderDetailMap.put("product_price", productData.getBigDecimal("price") != null ? productData.getBigDecimal("price") : BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
//计划发货日期
|
||||||
|
String planShipDate = orderDetailData.getString("consignTime") != null ? orderDetailData.getString("consignTime") : "";
|
||||||
|
|
||||||
|
LocalDateTime planShipDateTime = LocalDateTime.parse(planShipDate, formatter);
|
||||||
|
|
||||||
|
// 转换为时间戳(毫秒)
|
||||||
|
long planShipStamp = planShipDateTime
|
||||||
|
.atZone(ZoneId.systemDefault()) // 系统默认时区
|
||||||
|
.toInstant()
|
||||||
|
.toEpochMilli();
|
||||||
|
|
||||||
|
orderDetailMap.put("planned_shipment_date__c", planShipStamp);
|
||||||
|
|
||||||
|
//规格型号
|
||||||
|
orderDetailMap.put("specification_model__c", orderDetailData.getString("modelDescription") != null ? orderDetailData.getString("modelDescription") : "");
|
||||||
|
|
||||||
|
//折扣
|
||||||
|
JSONObject orderDetailDefineCharacter = orderDetailData.getJSONObject("orderDetailDefineCharacter");
|
||||||
|
orderDetailMap.put("discount", orderDetailDefineCharacter.getBigDecimal("ZKL01") != null ? orderDetailDefineCharacter.getBigDecimal("ZKL01") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//数量
|
||||||
|
orderDetailMap.put("quantity", orderDetailData.getBigDecimal("qty") != null ? orderDetailData.getBigDecimal("qty") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//含税单价
|
||||||
|
orderDetailMap.put("sales_price", orderDetailData.getBigDecimal("oriTaxUnitPrice") != null ? orderDetailData.getBigDecimal("oriTaxUnitPrice") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//含税小计
|
||||||
|
orderDetailMap.put("subtotal", orderDetailData.getBigDecimal("oriSum") != null ? orderDetailData.getBigDecimal("oriSum") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//税率
|
||||||
|
BigDecimal taxRate = orderDetailData.getBigDecimal("taxRate") != null ? orderDetailData.getBigDecimal("taxRate") : BigDecimal.ZERO;
|
||||||
|
String taxRateStr = TaxRateEnum.getCode(taxRate);
|
||||||
|
|
||||||
|
orderDetailMap.put("tax_rate__c", taxRate);
|
||||||
|
orderDetailMap.put("tax_rate_code__c", taxRateStr);
|
||||||
|
|
||||||
|
//税额
|
||||||
|
JSONObject orderPrice = orderDetailData.getJSONObject("orderDetailPrices");
|
||||||
|
orderDetailMap.put("field_11b7H__c", orderPrice.getBigDecimal("oriTax") != null ? orderPrice.getBigDecimal("oriTax") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//库存组织
|
||||||
|
orderDetailMap.put("inventory_organization__c", orderDetailData.getString("stockOrgId_code") != null ? orderDetailData.getString("stockOrgId_code") : "");
|
||||||
|
|
||||||
|
//行备注
|
||||||
|
orderDetailMap.put("remark", orderDetailData.getString("memo") != null ? orderDetailData.getString("memo") : "");
|
||||||
|
|
||||||
|
//市场活动备注
|
||||||
|
orderDetailMap.put("field_Jz17y__c", orderDetailDefineCharacter.getString("SCHDBZ") != null ? orderDetailDefineCharacter.getString("SCHDBZ") : "");
|
||||||
|
|
||||||
|
//无税金额
|
||||||
|
orderDetailMap.put("field_dt212__c", orderPrice.getBigDecimal("oriMoney") != null ? orderPrice.getBigDecimal("oriMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//含税单价
|
||||||
|
orderDetailMap.put("sales_price", orderDetailData.getBigDecimal("oriTaxUnitPrice") != null ? orderDetailData.getBigDecimal("oriTaxUnitPrice") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//无税单价
|
||||||
|
orderDetailMap.put("field_jyqC3__c", orderPrice.getBigDecimal("oriMoney") != null ? orderPrice.getBigDecimal("oriMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
orderDetailList.add(orderDetailMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
//开始封装
|
||||||
|
Map details = new HashMap<>();
|
||||||
|
details.put("SalesOrderProductObj", orderDetailList);
|
||||||
|
|
||||||
|
JSONObject updateOrder = crmRequestUtil.crmWithDetail(salesOrderMain, details);
|
||||||
|
|
||||||
|
System.out.println("销售订单请求为:" + updateOrder);
|
||||||
|
|
||||||
|
//开始封装日志
|
||||||
|
Map logMap = new HashMap<>();
|
||||||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
logMap.put("syn_type", "0");
|
||||||
|
logMap.put("log_type", "XSDDCRM");
|
||||||
|
logMap.put("data_name", salesOrderCode);
|
||||||
|
logMap.put("data_id", salesOrderId);
|
||||||
|
logMap.put("mark", modifyTime);
|
||||||
|
logMap.put("send_body", JSON.toJSONString(updateOrder));
|
||||||
|
logMap.put("tableName", "send_log_xsdd");
|
||||||
|
|
||||||
|
JSONObject updateOrderRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateOrderRes = restTemplate.postForObject(URLConstant.CREATE_CRM_MAIN, updateOrder, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("创建结果为:" + JSON.parseObject(JSON.toJSONString(updateOrderRes)));
|
||||||
|
|
||||||
|
if ("success".equals(updateOrderRes.getString("errorDescription"))) {
|
||||||
|
logMap.put("log_status", "0");
|
||||||
|
logMap.put("res_body", "同步成功");
|
||||||
|
} else {
|
||||||
|
logMap.put("log_status", "1");
|
||||||
|
logMap.put("res_body", "同步失败" + updateOrderRes.getString("errorMessage"));
|
||||||
|
}
|
||||||
|
|
||||||
|
logMap.put("send_res", JSON.toJSONString(updateOrderRes));
|
||||||
|
logMap.put("send_memo", JSON.toJSONString(updateOrderRes));
|
||||||
|
|
||||||
|
JSONObject logRes = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logRes = restTemplate.postForObject("http://localhost:18080/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("日志插入结果为:" + logRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,6 +15,7 @@ import org.ssssssss.magicboot.Enum.SalesOrgEnum;
|
|||||||
import org.ssssssss.magicboot.Enum.TaxRateEnum;
|
import org.ssssssss.magicboot.Enum.TaxRateEnum;
|
||||||
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.ChineseMoneyUtil;
|
||||||
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
import org.ssssssss.magicboot.utils.YSSignUtils;
|
import org.ssssssss.magicboot.utils.YSSignUtils;
|
||||||
|
|
||||||
@ -338,6 +339,14 @@ public class SalesOrderBGController {
|
|||||||
//收货地址
|
//收货地址
|
||||||
salesOrderMain.put("delivery_address__c", customizeData.getString("orderShippingAddress") != null ? customizeData.getString("orderShippingAddress") : "");
|
salesOrderMain.put("delivery_address__c", customizeData.getString("orderShippingAddress") != null ? customizeData.getString("orderShippingAddress") : "");
|
||||||
|
|
||||||
|
//销售订单金额
|
||||||
|
salesOrderMain.put("order_amount", salesOrderData.getBigDecimal("orderPayMoney") != null ? salesOrderData.getBigDecimal("orderPayMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
//中文大写
|
||||||
|
String chineseMoney = ChineseMoneyUtil.toChinese(salesOrderData.getBigDecimal("orderPayMoney") != null ? salesOrderData.getBigDecimal("orderPayMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
|
salesOrderMain.put("order_amount_in_words__c", chineseMoney);
|
||||||
|
|
||||||
salesOrderMain.put("dataObjectApiName", "SalesOrderObj");
|
salesOrderMain.put("dataObjectApiName", "SalesOrderObj");
|
||||||
|
|
||||||
//开始查询销售订单明细
|
//开始查询销售订单明细
|
||||||
@ -459,7 +468,7 @@ public class SalesOrderBGController {
|
|||||||
orderDetailMap.put("sales_price", orderDetailData.getBigDecimal("oriTaxUnitPrice") != null ? orderDetailData.getBigDecimal("oriTaxUnitPrice") : BigDecimal.ZERO);
|
orderDetailMap.put("sales_price", orderDetailData.getBigDecimal("oriTaxUnitPrice") != null ? orderDetailData.getBigDecimal("oriTaxUnitPrice") : BigDecimal.ZERO);
|
||||||
|
|
||||||
//无税单价
|
//无税单价
|
||||||
orderDetailMap.put("field_jyqC3__c", orderPrice.getBigDecimal("oriUnitPrice") != null ? orderPrice.getBigDecimal("oriUnitPrice") : BigDecimal.ZERO);
|
orderDetailMap.put("field_jyqC3__c", orderPrice.getBigDecimal("oriMoney") != null ? orderPrice.getBigDecimal("oriMoney") : BigDecimal.ZERO);
|
||||||
|
|
||||||
String orderDetailId = orderDetailData.getString("id");
|
String orderDetailId = orderDetailData.getString("id");
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ public class SalesOrderController {
|
|||||||
salesDetail.put("orderDetailDefineCharacter", orderDetailDefineCharacter);
|
salesDetail.put("orderDetailDefineCharacter", orderDetailDefineCharacter);
|
||||||
|
|
||||||
//销售单位
|
//销售单位
|
||||||
String salesUnit = salesDetailData.getString("sales_unit__c") != null ? salesDetailData.getString("sales_unit__c") : "";
|
String salesUnit = salesDetailData.getString("product_unit_code__c") != null ? salesDetailData.getString("product_unit_code__c") : "";
|
||||||
|
|
||||||
salesDetail.put("iProductAuxUnitId", salesUnit);
|
salesDetail.put("iProductAuxUnitId", salesUnit);
|
||||||
salesDetail.put("masterUnitId", salesUnit);
|
salesDetail.put("masterUnitId", salesUnit);
|
||||||
|
@ -0,0 +1,118 @@
|
|||||||
|
package org.ssssssss.magicboot.utils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 金额转换工具类
|
||||||
|
* @param
|
||||||
|
* @return null
|
||||||
|
* @Author weiloong_zhang
|
||||||
|
*/
|
||||||
|
public class ChineseMoneyUtil {
|
||||||
|
|
||||||
|
private static final String[] CN_UPPER_NUMBER = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
|
||||||
|
private static final String[] CN_UPPER_UNIT = {"", "拾", "佰", "仟"};
|
||||||
|
private static final String[] CN_UPPER_GROUP = {"", "万", "亿", "兆", "京", "垓", "秭", "穰"};
|
||||||
|
|
||||||
|
private static final String CN_YUAN = "元";
|
||||||
|
private static final String CN_JIAO = "角";
|
||||||
|
private static final String CN_FEN = "分";
|
||||||
|
private static final String CN_INTEGER = "整";
|
||||||
|
private static final String CN_NEGATIVE = "负";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 金额转中文大写
|
||||||
|
*
|
||||||
|
* @param amount BigDecimal 金额
|
||||||
|
* @return 中文大写金额
|
||||||
|
*/
|
||||||
|
public static String toChinese(BigDecimal amount) {
|
||||||
|
if (amount == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean negative = amount.signum() < 0;
|
||||||
|
amount = amount.abs();
|
||||||
|
|
||||||
|
long number = amount.movePointRight(2).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
|
||||||
|
long integerPart = number / 100;
|
||||||
|
int fractionPart = (int) (number % 100);
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (integerPart > 0) {
|
||||||
|
sb.append(integerToChinese(integerPart)).append(CN_YUAN);
|
||||||
|
} else {
|
||||||
|
sb.append("零").append(CN_YUAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fractionPart == 0) {
|
||||||
|
sb.append(CN_INTEGER);
|
||||||
|
} else {
|
||||||
|
int jiao = fractionPart / 10;
|
||||||
|
int fen = fractionPart % 10;
|
||||||
|
if (jiao > 0) {
|
||||||
|
sb.append(CN_UPPER_NUMBER[jiao]).append(CN_JIAO);
|
||||||
|
}
|
||||||
|
if (fen > 0) {
|
||||||
|
sb.append(CN_UPPER_NUMBER[fen]).append(CN_FEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (negative) {
|
||||||
|
sb.insert(0, CN_NEGATIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//转换整数部分
|
||||||
|
private static String integerToChinese(long number) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int groupIndex = 0;
|
||||||
|
boolean needZero = false;
|
||||||
|
|
||||||
|
while (number > 0) {
|
||||||
|
int section = (int) (number % 10000);
|
||||||
|
if (section != 0) {
|
||||||
|
String sectionChinese = sectionToChinese(section);
|
||||||
|
if (needZero) {
|
||||||
|
sb.insert(0, "零");
|
||||||
|
needZero = false;
|
||||||
|
}
|
||||||
|
sb.insert(0, sectionChinese + CN_UPPER_GROUP[groupIndex]);
|
||||||
|
} else {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
needZero = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
number /= 10000;
|
||||||
|
groupIndex++;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//转换每四位
|
||||||
|
private static String sectionToChinese(int section) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int unitIndex = 0;
|
||||||
|
boolean zeroFlag = true;
|
||||||
|
|
||||||
|
while (section > 0) {
|
||||||
|
int digit = section % 10;
|
||||||
|
if (digit == 0) {
|
||||||
|
if (!zeroFlag) {
|
||||||
|
zeroFlag = true;
|
||||||
|
sb.insert(0, CN_UPPER_NUMBER[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
zeroFlag = false;
|
||||||
|
sb.insert(0, CN_UPPER_NUMBER[digit] + CN_UPPER_UNIT[unitIndex]);
|
||||||
|
}
|
||||||
|
unitIndex++;
|
||||||
|
section /= 10;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user