进货单监听回调

畅捷通同步方案更新
YXY 11 months ago
parent ad7d1f5580
commit 43a3a99f2b

@ -100,7 +100,7 @@ public abstract class CJTOperateCallBackAbstract {
erpLarkTempRelation.setCreateTime(date);
erpLarkTempRelation.setUpdateTime(date);
JSONObject body = req.getBody();
if (body != null){
if (body != null) {
erpLarkTempRelation.setRemark(body.toJSONString());
}
erpLarkTempRelation.setFlag(FlagStatus.OK.getCode());
@ -124,7 +124,7 @@ public abstract class CJTOperateCallBackAbstract {
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
String msgType = req.getMsgType();
JSONObject jsonObject = null;
if (!msgType.contains("Delete")){
if (!msgType.contains("Delete")) {
LarkCJTRequestBody cjtRequestBody = new LarkCJTRequestBody(req.getVoucherId());
LarkCJTRequest cjtRequest = new LarkCJTRequest(getRequestUrl(), cjtAccountEnum.getAppKey(), cjtAccountEnum.getAppSecret(), generateToken(req), cjtRequestBody);
LarkOkHttpHelper.post(cjtRequest);
@ -206,6 +206,12 @@ public abstract class CJTOperateCallBackAbstract {
protected void addRecord(CJTEdiCallbackRequestVo req, JSONObject header) {
//获取已经存在的明细
List<ErpLarkRelation> existRecords = getExistRecords(req);
//如果存在相同的记录,则跳过插入步骤
if (CollectionUtils.isNotEmpty(existRecords)) {
return;
}
//多维表格id
String toTableId = req.getLarkToTableId();
//明细信息

@ -0,0 +1,117 @@
package com.ruoyi.flyingbook.strategy.cjt;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.enums.CjtAccountEnum;
import com.ruoyi.common.enums.CjtCallBackOperateEnum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.flyingbook.domain.edi.CJTEdiCallbackRequestVo;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Component("purchaseArrivalOrderCallBackOperate")
public class PurchaseArrivalOrderCallBackOperate extends CJTOperateCallBackAbstract{
@Override
protected void syncRecord(CJTEdiCallbackRequestVo req, JSONObject returnBody) {
CjtCallBackOperateEnum msgTypeEnum = req.getMsgTypeEnum();
switch (msgTypeEnum) {
case PURCHASE_ARRIVAL_ORDER_CREATE:
addRecord(req, returnBody);
break;
case PURCHASE_ARRIVAL_ORDER_UPDATE:
updateRecord(req,returnBody);
break;
case PURCHASE_ARRIVAL_ORDER_DELETE:
deleteRecord(req);
break;
default:
break;
}
}
@Override
protected String buildUniqueKey(String toTableId, JSONObject header, JSONObject detail,CjtAccountEnum cjtAccountEnum) {
StringBuilder sb = new StringBuilder();
if (cjtAccountEnum.getCode().equals(CjtAccountEnum.TWO.getCode())){
JSONObject inventory = detail.getJSONObject("Inventory");
if (inventory == null) {
sb.append("null").append("_");
} else {
sb.append(inventory.get("Code")).append("_");
}
sb.append(header.get("Code")).append("_");
sb.append(detail.get("DetailMemo"));
}else {
JSONObject inventory = detail.getJSONObject("Inventory");
if (inventory == null) {
sb.append("null").append("_");
} else {
sb.append(inventory.get("Code")).append("_");
}
sb.append(detail.get("Quantity")).append("_");
sb.append(header.get("Code")).append("_");
sb.append(detail.get("DetailMemo"));
}
return sb.toString();
}
@Override
protected Map<String, Object> buildLarkBody(JSONObject header, JSONObject detail, CjtAccountEnum cjtAccountEnum) {
Map<String, Object> body = new HashMap<>();
body.put("采购订单号", header.getString("PurchaseOrderCode"));
JSONObject inventory = detail.getJSONObject("Inventory");
if (inventory != null){
body.put("存货编码", inventory.getString("Code"));
body.put("存货", inventory.getString("Name"));
body.put("规格型号", inventory.getString("Specification"));
}
JSONObject unit = detail.getJSONObject("Unit");
if (unit != null){
body.put("采购单位", unit.getString("Name"));
}
body.put("数量", detail.getDoubleValue("Quantity"));
body.put("单据日期", DateUtils.str2long(header.getString("VoucherDate"), DateUtils.YYYY_MM_DD));
body.put("创建时间", System.currentTimeMillis());
body.put("单据编号", header.getString("Code"));
JSONObject partner = header.getJSONObject("Partner");
if (partner != null){
body.put("供应商", partner.getString("Name"));
}
JSONObject voucherState = header.getJSONObject("VoucherState");
if (voucherState != null){
body.put("单据状态", voucherState.getString("Name"));
}
JSONObject warehouse = detail.getJSONObject("Warehouse");
if (warehouse != null){
body.put("仓库", warehouse.getString("Name"));
}
body.put("明细备注", detail.getString("DetailMemo"));
return body;
}
@Override
protected String getRequestUrl() {
return REQUEST_ROOT_PATH + "/tplus/api/v2/PurchaseArrivalOpenApi/GetVoucherDTO";
}
@Override
protected String getMethodUrl() {
return REQUEST_ROOT_PATH + "/tplus/api/v2/PurchaseArrivalOpenApi/FindVoucherList";
}
@Override
protected String getDetailName() {
return "PurchaseOrderDetails";
}
}
Loading…
Cancel
Save