add:增加erp同步工具类
This commit is contained in:
@@ -0,0 +1,151 @@
|
|||||||
|
package org.nl.common.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.github.javaparser.utils.Log;
|
||||||
|
import com.kingdee.bos.webapi.entity.*;
|
||||||
|
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
|
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
||||||
|
import org.nl.wms.external_system.erp.dto.ErpSec;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author gongbaoxiong
|
||||||
|
* Erp单据公共类
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ErpServiceUtils {
|
||||||
|
@Resource
|
||||||
|
ErpSec erpSec;
|
||||||
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建api
|
||||||
|
*/
|
||||||
|
private K3CloudApi getCloudApi() {
|
||||||
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
|
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||||
|
return new K3CloudApi(identifyInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param query 查询条件
|
||||||
|
*/
|
||||||
|
public JSONArray queryBills(ErpQuery query) {
|
||||||
|
if (StringUtils.isBlank(query.getFormId())) {
|
||||||
|
throw new BadRequestException("参数异常");
|
||||||
|
}
|
||||||
|
boolean islock = lock.tryLock();
|
||||||
|
List<Object> result = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
if (islock) {
|
||||||
|
String jsonString = JSON.toJSONString(query);
|
||||||
|
K3CloudApi cloudApi = getCloudApi();
|
||||||
|
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||||
|
for (List<Object> list : lists) {
|
||||||
|
for (Object r : list) {
|
||||||
|
String fid = r.toString();
|
||||||
|
if (StringUtils.isEmpty(fid)) {
|
||||||
|
log.error("单据同步失败,没有找到FID");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
OperateParam param = new OperateParam();
|
||||||
|
param.setId(fid);
|
||||||
|
OperatorResult view = cloudApi.view(query.getFormId(), param);
|
||||||
|
RepoStatus status = view.getResult().getResponseStatus();
|
||||||
|
if (status.isIsSuccess()) {
|
||||||
|
new ArrayList<>();
|
||||||
|
result.add(view.getResult().getResult());
|
||||||
|
} else {
|
||||||
|
ArrayList<RepoError> errors = status.getErrors();
|
||||||
|
log.error("查询ID [{}] 时出现异常: {}", fid, errors.stream().map(RepoError::getMessage).collect(Collectors.joining(",")));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("查询ID [{}] 时出现异常: {}", fid, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("当前同步操作正在执行,稍后再试");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BadRequestException(ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return JSON.parseArray(JSON.toJSONString(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单据保存
|
||||||
|
*/
|
||||||
|
public JSONObject save(JSONObject from) {
|
||||||
|
String result;
|
||||||
|
try {
|
||||||
|
//要回传的json数据
|
||||||
|
String json = from.toJSONString();
|
||||||
|
result = getCloudApi().save(from.getString("formid"), json);
|
||||||
|
from.put("result", result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Log.error(ex.getMessage());
|
||||||
|
from.put("result", ex.getMessage());
|
||||||
|
}
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单据审核
|
||||||
|
*/
|
||||||
|
public JSONObject audit(JSONObject from) {
|
||||||
|
String result;
|
||||||
|
//执行回传
|
||||||
|
try {
|
||||||
|
String json = from.toJSONString();
|
||||||
|
result = getCloudApi().audit(from.getString("formid"), json);
|
||||||
|
from.put("result", result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Log.error(ex.getMessage());
|
||||||
|
from.put("result", ex.getMessage());
|
||||||
|
}
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单据下推
|
||||||
|
*/
|
||||||
|
public JSONObject push(JSONObject from) {
|
||||||
|
String result;
|
||||||
|
//执行回传
|
||||||
|
try {
|
||||||
|
//要回传的json数据
|
||||||
|
String json = from.toJSONString();
|
||||||
|
result = getCloudApi().push(from.getString("TargetFormId"), json);
|
||||||
|
from.put("result", result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Log.error(ex.getMessage());
|
||||||
|
from.put("result", ex.getMessage());
|
||||||
|
}
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -128,10 +128,16 @@ public class SyncErpService {
|
|||||||
* 合格证保存
|
* 合格证保存
|
||||||
*/
|
*/
|
||||||
public JSONObject process(JSONObject from) {
|
public JSONObject process(JSONObject from) {
|
||||||
//执行回传
|
|
||||||
return erpServiceUtils.save(from);
|
return erpServiceUtils.save(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单据审核
|
||||||
|
*/
|
||||||
|
public JSONObject audit(JSONObject from) {
|
||||||
|
return erpServiceUtils.audit(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据同步
|
* 数据同步
|
||||||
|
|||||||
@@ -133,6 +133,13 @@ public class SyncFormMappingController {
|
|||||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/audit")
|
||||||
|
@Log("单据审核")
|
||||||
|
public ResponseEntity<Object> audit(@RequestBody JSONObject form){
|
||||||
|
JSONObject result = syncErpService.audit(form);
|
||||||
|
return new ResponseEntity<>(result,HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/push")
|
@PostMapping("/push")
|
||||||
@Log("下推测试")
|
@Log("下推测试")
|
||||||
public ResponseEntity<Object> push(@RequestBody JSONObject form){
|
public ResponseEntity<Object> push(@RequestBody JSONObject form){
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ public class SyncErpBillsScheduleService {
|
|||||||
"SAL_SaleOrder", "FStockOrgId",
|
"SAL_SaleOrder", "FStockOrgId",
|
||||||
"PUR_ReceiveBill", "FStockOrgId",
|
"PUR_ReceiveBill", "FStockOrgId",
|
||||||
"PUR_MRAPP", "FPURCHASEORGID",
|
"PUR_MRAPP", "FPURCHASEORGID",
|
||||||
"ka7c19edf9d4b4b39b8cc4a06802163b0", "F_PMSY_PrdOrgId");
|
"ka7c19edf9d4b4b39b8cc4a06802163b0", "F_PMSY_PrdOrgId",
|
||||||
|
"STK_TransferDirect", "FStockOrgId");
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -116,13 +117,15 @@ public class SyncErpBillsScheduleService {
|
|||||||
if (StringUtils.isNotBlank(code)) {
|
if (StringUtils.isNotBlank(code)) {
|
||||||
filterString = "FBillNo = '" + code + "'";
|
filterString = "FBillNo = '" + code + "'";
|
||||||
} else {
|
} else {
|
||||||
filterString = BillOrg_Mapping.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
filterString = BillOrg_Mapping.get(formType) + " = '750572' ";
|
||||||
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||||
filterString += " AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + timeStart + " 00:00:00' AND F_PMSY_CreateDate <= '" + timeEnd + " 23:59:59' ";
|
filterString += "AND FDocumentStatus = 'C' AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + timeStart + " 00:00:00' AND F_PMSY_CreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
} else if ("SAL_SaleOrder".equals(formType)) {
|
} else if ("SAL_SaleOrder".equals(formType)) {
|
||||||
filterString += " AND FCloseStatus ='A' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
filterString += " AND FDocumentStatus = 'C' AND FCloseStatus ='A' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
|
} else if ("STK_TransferDirect".equals(formType)||"STK_MisDelivery".equals(formType)||"PUR_MRB".equals(formType)||"SAL_RETURNSTOCK".equals(formType)) {
|
||||||
|
filterString += " AND FDocumentStatus ='B' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
} else {
|
} else {
|
||||||
filterString += " AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
filterString += " AND FDocumentStatus = 'C' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ErpQuery query = new ErpQuery();
|
ErpQuery query = new ErpQuery();
|
||||||
@@ -134,7 +137,7 @@ public class SyncErpBillsScheduleService {
|
|||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||||
Set<String> ids = new HashSet<>();
|
Set<String> ids = new HashSet<>();
|
||||||
for (List<Object> list : lists) {
|
for (List<Object> list : lists) {
|
||||||
for (Object r : list) {
|
for (Object r : list) {
|
||||||
@@ -191,6 +194,14 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
//单据明细
|
//单据明细
|
||||||
if (StringUtils.isBlank(f.getCode())) {
|
if (StringUtils.isBlank(f.getCode())) {
|
||||||
|
//除了合格证相关单据,其他都过滤非立库仓库组织
|
||||||
|
if (!"PRD_MO".equals(f.getForm_type()) && !"PUR_ReceiveBill".equals(f.getForm_type())) {
|
||||||
|
if (StringUtils.isNotBlank(f.getForm_data().getString("SrcStockId_Id"))) {
|
||||||
|
if (!"1233925".equals(f.getForm_data().getString("SrcStockId_Id")) && !"1233926".equals(f.getForm_data().getString("SrcStockId_Id"))) {
|
||||||
|
continue 外部;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
f.setParent_id(mainId + "$" + formType);
|
f.setParent_id(mainId + "$" + formType);
|
||||||
}
|
}
|
||||||
f.setId(f.getId() + "$" + f.getForm_type());
|
f.setId(f.getId() + "$" + f.getForm_type());
|
||||||
|
|||||||
Reference in New Issue
Block a user