add:增加Erp单据枚举
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
package org.nl.common.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.api.R;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.exception.BadRequestException;
|
||||
import org.nl.common.utils.ForkMap;
|
||||
import org.nl.common.utils.MapOf;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
@@ -38,6 +34,17 @@ public enum StatusEnum {
|
||||
OTHER_TASK_TYPE(ForkMap.of("转运", "70","tranforTask")),
|
||||
profit_loss(ForkMap.of("盘亏", "0",null,"盘盈", "1",null,"实盘", "2",null)),
|
||||
|
||||
/**
|
||||
* ERP回传单据类型
|
||||
*/
|
||||
ERP_TYPE(ForkMap.of("PRD_MO", "10", "生产订单", "PUR_ReceiveBill", "11", "收料通知单",
|
||||
"SAL_SaleOrder", "12", "销售订单", "PRD_INSTOCK", "13", "生产入库单", "STK_InStock", "14", "采购入库单",
|
||||
"PRD_PPBOM", "20", "生产用料清单", "PRD_PickMtrl", "21", "生产领料单",
|
||||
"ka7c19edf9d4b4b39b8cc4a06802163b0", "22", "简单生产领料单",
|
||||
"STK_TransferDirect", "23", "调拨出库单", "SAL_RETURNSTOCK", "24", "销售退货单",
|
||||
"PUR_MRB", "25", "采购退料单", "STK_MisDelivery", "26", "其他出库单")),
|
||||
|
||||
|
||||
/**
|
||||
* 任务类型
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.exception.BadRequestException;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -99,27 +100,20 @@ public class SpelUtil {
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
for (String field : fieldSkip.keySet()) {
|
||||
String skip = fieldSkip.get(field);
|
||||
if (skip.charAt(0) == '#'){
|
||||
String value = skip;
|
||||
if (skip.contains("#M")){
|
||||
try {
|
||||
Expression expression = SpelUtil.SPEL_PARSER.parseExpression(skip);
|
||||
String value = expression.getValue(context, String.class);
|
||||
if (field.equals("product_area")){
|
||||
String product_area = Product_Area_Mapping.get(value);
|
||||
if (StringUtils.isEmpty(product_area)){
|
||||
product_area = "A1";
|
||||
}
|
||||
value = product_area;
|
||||
}
|
||||
result.put(field,value);
|
||||
value = expression.getValue(context, String.class);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
throw new BadRequestException("当前业务数据没有映射字段"+field+" 对应的数据"+skip);
|
||||
}
|
||||
}else {
|
||||
result.put(field,skip);
|
||||
}else if(skip.contains("#V[")){
|
||||
//直接指定参数#V['value'] = value
|
||||
value = skip.split("'")[1];
|
||||
}
|
||||
|
||||
|
||||
result.put(field,value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,8 @@ public class SyncErpService {
|
||||
* 单据审核
|
||||
*/
|
||||
public JSONObject audit(JSONObject from) {
|
||||
return erpServiceUtils.audit(from);
|
||||
// return erpServiceUtils.audit(from);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package org.nl.wms.flow_manage.flow.service.classprocessimpl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
||||
@@ -24,10 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/*
|
||||
@@ -42,9 +36,9 @@ public class SyncReceiptProcessHandler implements ClassProcess {
|
||||
IPmFormDataService iPmFormDataService;
|
||||
@Autowired
|
||||
ErpSec erpSec;
|
||||
|
||||
@Resource
|
||||
private ErpServiceUtils erpServiceUtils;
|
||||
|
||||
/**
|
||||
* 回执单回传
|
||||
*/
|
||||
@@ -79,8 +73,14 @@ public class SyncReceiptProcessHandler implements ClassProcess {
|
||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||
JSONObject res;
|
||||
if (Integer.parseInt(StatusEnum.ERP_TYPE.code(formid)) > 22) {
|
||||
String result = erpServiceUtils.audit(formData).getString("result");
|
||||
res = JSONObject.parseObject(result);
|
||||
} else {
|
||||
String result = cloudApi.save(formid, formData.toJSONString());
|
||||
JSONObject res = JSONObject.parseObject(result);
|
||||
res = JSONObject.parseObject(result);
|
||||
}
|
||||
JSONObject responseStatus = res.getJSONObject("Result").getJSONObject("ResponseStatus");
|
||||
boolean isSuccess = responseStatus.getBooleanValue("IsSuccess");
|
||||
JSONArray errors = responseStatus.getJSONArray("Errors");
|
||||
|
||||
@@ -203,7 +203,6 @@
|
||||
<select id="existFormDataList" resultType="java.lang.String">
|
||||
SELECT id
|
||||
FROM pm_form_data
|
||||
WHERE DATE(create_time) = CURDATE()
|
||||
</select>
|
||||
<select id="existFormCodeDataList" resultType="java.lang.String">
|
||||
SELECT code
|
||||
|
||||
@@ -58,14 +58,32 @@ public class SyncErpBillsScheduleService {
|
||||
|
||||
@Autowired
|
||||
private PmFormDataMapper pmFormDataMapper;
|
||||
private static Map<String, String> BillOrg_Mapping = MapOf.of(
|
||||
//组织机构
|
||||
private static final Map<String, String> BILL_ORG_MAPPING = MapOf.of(
|
||||
"PRD_PPBOM", "FPrdOrgId",
|
||||
"PRD_MO", "FPrdOrgId",
|
||||
"SAL_SaleOrder", "FStockOrgId",
|
||||
"PRD_PickMtrl", "FStockOrgId",
|
||||
"PUR_ReceiveBill", "FStockOrgId",
|
||||
"PUR_MRAPP", "FPURCHASEORGID",
|
||||
"ka7c19edf9d4b4b39b8cc4a06802163b0", "F_PMSY_PrdOrgId",
|
||||
"STK_TransferDirect", "FStockOrgId");
|
||||
"STK_TransferDirect", "FStockOrgId",
|
||||
"SAL_RETURNSTOCK", "FStockOrgId",
|
||||
"PUR_MRB", "FStockOrgId",
|
||||
"STK_MisDelivery", "FStockOrgId");
|
||||
//仓库信息
|
||||
private static final Map<String, String> BILL_STOCK_ID_MAPPING = MapOf.of(
|
||||
"PRD_PPBOM", "stock_Id",
|
||||
"PRD_MO", "stockId",
|
||||
"PRD_PickMtrl", "stockId",
|
||||
"SAL_SaleOrder", "stockId",
|
||||
"PUR_ReceiveBill", "StockID_Id",
|
||||
"PUR_MRAPP", "FPURCHASEORGID",
|
||||
"ka7c19edf9d4b4b39b8cc4a06802163b0", "stockId",
|
||||
"STK_TransferDirect", "SrcStockId_Id",
|
||||
"SAL_RETURNSTOCK", "stockId",
|
||||
"PUR_MRB", "stockId",
|
||||
"STK_MisDelivery", "stockId");
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
@@ -75,7 +93,6 @@ public class SyncErpBillsScheduleService {
|
||||
LuceneAppender.traceIdTL.set(BaseCode.intToChars(IdUtil.getLongId()));
|
||||
//List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
||||
List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "ka7c19edf9d4b4b39b8cc4a06802163b0", "PRD_PPBOM", "PRD_MO", "SAL_SaleOrder", "PUR_ReceiveBill", "PUR_MRAPP"));
|
||||
//List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "ka7c19edf9d4b4b39b8cc4a06802163b0","PRD_PPBOM","PRD_MO","SAL_SaleOrder","PUR_ReceiveBill","PUR_MRAPP"));
|
||||
for (SyncFormMapping m : list) {
|
||||
JSONArray mappingJson = m.getMapping_json();
|
||||
String mappingString = JSON.toJSONString(mappingJson);
|
||||
@@ -86,148 +103,9 @@ public class SyncErpBillsScheduleService {
|
||||
}
|
||||
}
|
||||
|
||||
public String manualSync(String formType, String code, String startTime, String endTime) {
|
||||
if (StringUtils.isEmpty(formType)) {
|
||||
throw new BadRequestException("单据类型不能为空");
|
||||
}
|
||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, formType));
|
||||
JSONArray mappingJson = syncFormMapping.getMapping_json();
|
||||
String mappingString = JSON.toJSONString(mappingJson);
|
||||
return manualSyncData(mappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), code, startTime, endTime);
|
||||
}
|
||||
|
||||
private String manualSyncData(String mappingJson, String formType, Boolean dtlSplit, String code, String start, String end) {
|
||||
boolean islock = lock.tryLock();
|
||||
Map errorMsg = new HashMap<>();
|
||||
try {
|
||||
if (islock) {
|
||||
//单据同步总数
|
||||
List<Object> result = new ArrayList<>();
|
||||
// 获取当前日期
|
||||
String timeEnd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||
String timeStart = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
||||
if (StringUtils.isNotBlank(start) && StringUtils.isNotBlank(end)) {
|
||||
timeStart = start;
|
||||
timeEnd = end;
|
||||
}
|
||||
//String filterString = "FUseOrgId='750572'";
|
||||
String filterString;
|
||||
if (StringUtils.isNotBlank(code)) {
|
||||
filterString = "FBillNo = '" + code + "'";
|
||||
} else {
|
||||
filterString = BillOrg_Mapping.get(formType) + " = '750572' ";
|
||||
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||
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)) {
|
||||
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 {
|
||||
filterString += " AND FDocumentStatus = 'C' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||
}
|
||||
}
|
||||
ErpQuery query = new ErpQuery();
|
||||
query.setFilterString(filterString);
|
||||
query.setFormId(formType);
|
||||
query.setFieldKeys("FID");
|
||||
query.setLimit(0);
|
||||
String jsonString = JSON.toJSONString(query);
|
||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (List<Object> list : lists) {
|
||||
for (Object r : list) {
|
||||
String fid = r.toString();
|
||||
if (StringUtils.isEmpty(fid)) {
|
||||
log.error("单据同步失败,没有找到FID");
|
||||
continue;
|
||||
}
|
||||
ids.add(fid);
|
||||
}
|
||||
}
|
||||
OperateParam param = new OperateParam();
|
||||
for (String id : ids) {
|
||||
try {
|
||||
param.setId(id);
|
||||
OperatorResult view = cloudApi.view(formType, param);
|
||||
RepoStatus status = view.getResult().getResponseStatus();
|
||||
if (status.isIsSuccess()) {
|
||||
result.add(view.getResult().getResult());
|
||||
} else {
|
||||
ArrayList<RepoError> errors = status.getErrors();
|
||||
errorMsg.put(id, errorMsg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorMsg.put("id","处理ID异常"+e.getMessage());
|
||||
}
|
||||
}
|
||||
//物料同步
|
||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
||||
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||
外部:
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
Object r = result.get(i);
|
||||
try {
|
||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||
//主单据
|
||||
final String mainId=formDataList.stream().filter(rd -> StringUtils.isNotBlank(rd.getCode())).collect(Collectors.toList()).get(0).getId();
|
||||
Set<String> materials = formDataList.stream().filter(rd -> StringUtils.isBlank(rd.getCode())).map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
||||
List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new QueryWrapper<MdMeMaterialbase>().select("material_id").in("material_id", materials));
|
||||
Set<String> materialHas = materialList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
||||
for (String m : materials) {
|
||||
if (!materialHas.contains(m)) {
|
||||
Boolean materialSync = queryMaterialInfo(materialMappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), m, cloudApi);
|
||||
if (!materialSync) {
|
||||
continue 外部;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PmFormData f : formDataList) {
|
||||
if (exitFormDataList.contains(f.getId() + "$" + f.getForm_type())) {
|
||||
continue 外部;
|
||||
}
|
||||
//单据明细
|
||||
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.setId(f.getId() + "$" + f.getForm_type());
|
||||
formDataService.save(f);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorMsg.put("result第"+i+1+"条解析异常:",e.getMessage());
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(errorMsg)){
|
||||
throw new BadRequestException("同步成功"+(result.size()-errorMsg.size())+"条,失败信息:"+errorMsg.toString());
|
||||
}else {
|
||||
return "同步成功,共计"+result.size()+"条";
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException("当前同步操作正在执行,稍后再试");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new BadRequestException(ex.getMessage());
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动同步
|
||||
*/
|
||||
public void syncData(String mappingJson, String formType, Boolean dtlSplit) {
|
||||
boolean islock = lock.tryLock();
|
||||
try {
|
||||
@@ -241,7 +119,7 @@ public class SyncErpBillsScheduleService {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||
String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
||||
String filterString = BillOrg_Mapping.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
||||
String filterString = BILL_ORG_MAPPING.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
||||
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||
filterString += " AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + sevenDaysAgo + " 00:00:00' AND F_PMSY_CreateDate <= '" + today + " 23:59:59' ";
|
||||
} else if ("SAL_SaleOrder".equals(formType)) {
|
||||
@@ -344,6 +222,177 @@ public class SyncErpBillsScheduleService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手动同步
|
||||
*/
|
||||
public String manualSync(String formType, String code, String startTime, String endTime) {
|
||||
if (StringUtils.isEmpty(formType)) {
|
||||
throw new BadRequestException("单据类型不能为空");
|
||||
}
|
||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, formType));
|
||||
JSONArray mappingJson = syncFormMapping.getMapping_json();
|
||||
String mappingString = JSON.toJSONString(mappingJson);
|
||||
return manualSyncData(mappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), code, startTime, endTime);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手动同步
|
||||
*/
|
||||
private String manualSyncData(String mappingJson, String formType, Boolean dtlSplit, String code, String start, String end) {
|
||||
boolean islock = lock.tryLock();
|
||||
Map errorMsg = new HashMap<>();
|
||||
try {
|
||||
if (islock) {
|
||||
//单据同步总数
|
||||
List<Object> result = new ArrayList<>();
|
||||
// 获取当前日期
|
||||
String timeEnd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||
String timeStart = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
||||
if (StringUtils.isNotBlank(start) && StringUtils.isNotBlank(end)) {
|
||||
timeStart = start;
|
||||
timeEnd = end;
|
||||
}
|
||||
//String filterString = "FUseOrgId='750572'";
|
||||
String filterString;
|
||||
if (StringUtils.isNotBlank(code)) {
|
||||
filterString = "FBillNo = '" + code + "'";
|
||||
} else {
|
||||
filterString = BILL_ORG_MAPPING.get(formType) + " = '750572' ";
|
||||
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||
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)) {
|
||||
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 {
|
||||
filterString += " AND FDocumentStatus = 'C' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
||||
}
|
||||
}
|
||||
ErpQuery query = new ErpQuery();
|
||||
query.setFilterString(filterString);
|
||||
query.setFormId(formType);
|
||||
query.setFieldKeys("FID");
|
||||
query.setLimit(0);
|
||||
String jsonString = JSON.toJSONString(query);
|
||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (List<Object> list : lists) {
|
||||
for (Object r : list) {
|
||||
String fid = r.toString();
|
||||
if (StringUtils.isEmpty(fid)) {
|
||||
log.error("单据同步失败,没有找到FID");
|
||||
continue;
|
||||
}
|
||||
ids.add(fid);
|
||||
}
|
||||
}
|
||||
OperateParam param = new OperateParam();
|
||||
for (String id : ids) {
|
||||
try {
|
||||
param.setId(id);
|
||||
OperatorResult view = cloudApi.view(formType, param);
|
||||
RepoStatus status = view.getResult().getResponseStatus();
|
||||
if (status.isIsSuccess()) {
|
||||
result.add(view.getResult().getResult());
|
||||
} else {
|
||||
errorMsg.put(id, errorMsg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorMsg.put("id","处理ID异常"+e.getMessage());
|
||||
}
|
||||
}
|
||||
//物料同步
|
||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
||||
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||
外部:
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
Object r = result.get(i);
|
||||
try {
|
||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||
//主单据
|
||||
List<PmFormData> mainBill = formDataList.stream().filter(rd -> StringUtils.isNotBlank(rd.getCode())).collect(Collectors.toList());
|
||||
//主单据Id
|
||||
final String mainId = mainBill.get(0).getId();
|
||||
//仓库Key
|
||||
final String stockId = BILL_STOCK_ID_MAPPING.get(formType);
|
||||
//除了合格证相关单据,其他都过滤非立库仓库组织
|
||||
if (!"PRD_MO".equals(formType) && !"PUR_ReceiveBill".equals(formType)) {
|
||||
//明细单据
|
||||
List<PmFormData> detailBills = formDataList.stream()
|
||||
.filter(rs -> StringUtils.isBlank(rs.getCode()))
|
||||
.collect(Collectors.toList());
|
||||
//仓库信息
|
||||
List<PmFormData> detailWithStock = detailBills.stream()
|
||||
.filter(rd -> StringUtils.isNotBlank(rd.getForm_data().getString(stockId)))
|
||||
.collect(Collectors.toList());
|
||||
//托盘1233925与料箱库1233926
|
||||
List<PmFormData> filteredDetails = detailWithStock.stream()
|
||||
.filter(rt -> new HashSet<>(Arrays.asList("1233925", "1233926")).contains(rt.getForm_data().getString(stockId)))
|
||||
.collect(Collectors.toList());
|
||||
if (ObjectUtils.isNotEmpty(filteredDetails)) {
|
||||
mainBill.addAll(filteredDetails);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
mainBill = formDataList;
|
||||
}
|
||||
//检查物料信息,如果不存在则新增物料
|
||||
Set<String> materials = mainBill.stream().filter(rd -> StringUtils.isBlank(rd.getCode())).map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
||||
List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new QueryWrapper<MdMeMaterialbase>().select("material_id").in("material_id", materials));
|
||||
Set<String> materialHas = materialList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
||||
for (String m : materials) {
|
||||
if (!materialHas.contains(m)) {
|
||||
Boolean materialSync = queryMaterialInfo(materialMappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), m, cloudApi);
|
||||
if (!materialSync) {
|
||||
continue 外部;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PmFormData f : mainBill) {
|
||||
if (exitFormDataList.contains(f.getId() + "$" + f.getForm_type())) {
|
||||
continue 外部;
|
||||
}
|
||||
//单据明细
|
||||
if (StringUtils.isBlank(f.getCode())) {
|
||||
f.setParent_id(mainId + "$" + formType);
|
||||
}
|
||||
f.setId(f.getId() + "$" + f.getForm_type());
|
||||
formDataService.save(f);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorMsg.put("result第"+i+1+"条解析异常:",e.getMessage());
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(errorMsg)){
|
||||
throw new BadRequestException("同步成功"+(result.size()-errorMsg.size())+"条,失败信息:"+errorMsg.toString());
|
||||
}else {
|
||||
return "同步成功,共计"+result.size()+"条";
|
||||
}
|
||||
}else {
|
||||
throw new BadRequestException("当前同步操作正在执行,稍后再试");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new BadRequestException(ex.getMessage());
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询物料信息
|
||||
*/
|
||||
public Boolean queryMaterialInfo(String mappingJson, String formType, Boolean dtlSplit, String id, K3CloudApi cloudApi) {
|
||||
try {
|
||||
{
|
||||
@@ -389,155 +438,15 @@ public class SyncErpBillsScheduleService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void syncData2(String mappingJson, String formType, Boolean dtlSplit) {
|
||||
boolean islock = lock.tryLock();
|
||||
try {
|
||||
if (islock) {
|
||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
String filterString = "FUseOrgId='750572'";
|
||||
//String filterString = BillOrg + "='750572' AND FDocumentStatus='C' AND FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59'";
|
||||
//构建查询条件
|
||||
// String BillOrg = BillOrg_Mapping.get(formType);
|
||||
// String filterString = BillOrg + "='750572' AND FDocumentStatus='C' ";
|
||||
// if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
||||
// filterString += " AND F_PMSY_StockOrgId='750572' AND F_PMSY_BillStatus ='A' AND F_PMSY_CreateDate >= '2024-11-01 00:00:00' and F_PMSY_CreateDate <= '2024-12-04 23:59:59' ";
|
||||
// }else{
|
||||
// filterString += " AND FCreateDate >= '2024-11-01 00:00:00' and FCreateDate <= '2024-12-04 23:59:59' ";
|
||||
// }
|
||||
ErpQuery query = new ErpQuery();
|
||||
query.setFilterString(filterString);
|
||||
query.setFormId(formType);
|
||||
query.setFieldKeys("FMATERIALID");
|
||||
query.setLimit(0);
|
||||
String jsonString = JSON.toJSONString(query);
|
||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||
// Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
||||
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(formType, param);
|
||||
RepoStatus status = view.getResult().getResponseStatus();
|
||||
if (status.isIsSuccess()) {
|
||||
List<Object> result = new ArrayList<>();
|
||||
result.add(view.getResult().getResult());
|
||||
// getData(mappingJson, formType, dtlSplit, result);
|
||||
} else {
|
||||
ArrayList<RepoError> errors = status.getErrors();
|
||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理ID [{}] 时出现异常: {}", fid, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void syncDataTest(String mappingJson, String formType, Boolean dtlSplit) {
|
||||
boolean islock = lock.tryLock();
|
||||
try {
|
||||
if (islock) {
|
||||
List<Object> result = new ArrayList<>();
|
||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
String filterString = "FDocumentStatus='C' AND FCreateDate >= '" + today + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59'";
|
||||
//String filterString = " FDocumentStatus='C' AND FCreateDate >= '2024-11-30 00:00:00' and FCreateDate <= '2024-11-30 23:59:59'";
|
||||
ErpQuery query = new ErpQuery();
|
||||
query.setFilterString(filterString);
|
||||
query.setFormId(formType);
|
||||
query.setFieldKeys("FID");
|
||||
query.setLimit(0);
|
||||
String jsonString = JSON.toJSONString(query);
|
||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||
//log.info("同步ERP结果" + lists.size());
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (List<Object> list : lists) {
|
||||
for (Object r : list) {
|
||||
String fid = r.toString();
|
||||
if (StringUtils.isEmpty(fid)) {
|
||||
log.error("单据同步失败,没有找到FID");
|
||||
continue;
|
||||
}
|
||||
ids.add(fid);
|
||||
}
|
||||
}
|
||||
OperateParam param = new OperateParam();
|
||||
Map<String, String> error = new HashMap<>();
|
||||
for (String id : ids) {
|
||||
param.setId(id);
|
||||
OperatorResult view = cloudApi.view(formType, param);
|
||||
RepoStatus status = view.getResult().getResponseStatus();
|
||||
if (status.isIsSuccess()) {
|
||||
result.add(view.getResult().getResult());
|
||||
} else {
|
||||
ArrayList<RepoError> errors = status.getErrors();
|
||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
||||
error.put(id, errorMsg);
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(error)) {
|
||||
log.error("ERP单据同步同步失败:{}", error);
|
||||
}
|
||||
List<PmFormData> pmFormDataAll = new ArrayList<>();
|
||||
for (Object r : result) {
|
||||
//log.info(JSON.toJSONString(r));
|
||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||
formDataService.saveBatch(formDataList);
|
||||
if (ObjectUtils.isNotEmpty(formDataList)) {
|
||||
pmFormDataAll.addAll(formDataList);
|
||||
}
|
||||
}
|
||||
//数据库已存在的数据
|
||||
Set<String> existFormDataList = pmFormDataMapper.existFormDataList();
|
||||
List<PmFormData> newFormDataList = pmFormDataAll.stream()
|
||||
.filter(data -> !existFormDataList.contains(data.getId()))
|
||||
.collect(Collectors.toList());
|
||||
if (!newFormDataList.isEmpty()) {
|
||||
formDataService.saveBatch(newFormDataList);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理物料信息
|
||||
*/
|
||||
private void getData(String mappingJson, String formType, Boolean dtlSplit, List<Object> result) {
|
||||
String jsonString;
|
||||
外部:
|
||||
for (Object r : result) {
|
||||
try {
|
||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
||||
// for (String id : formDataList.stream().map(PmFormData::getId).collect(Collectors.toList())) {
|
||||
// if (exitFormDataList.contains(id)) {
|
||||
// continue 外部;
|
||||
// }
|
||||
// }
|
||||
if (formDataList != null) {
|
||||
PmFormData mainFormData = formDataList.stream().filter(rs1 -> "BD_MATERIAL".equals(rs1.getForm_type())).collect(Collectors.toList()).get(0);
|
||||
JSONObject object = mainFormData.getForm_data();
|
||||
@@ -562,4 +471,68 @@ public class SyncErpBillsScheduleService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 物料信息同步
|
||||
*/
|
||||
public void syncMateralData(String mappingJson, String formType, Boolean dtlSplit) {
|
||||
boolean islock = lock.tryLock();
|
||||
try {
|
||||
if (islock) {
|
||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
||||
String filterString = "FUseOrgId='750572'";
|
||||
ErpQuery query = new ErpQuery();
|
||||
query.setFilterString(filterString);
|
||||
query.setFormId(formType);
|
||||
query.setFieldKeys("FMATERIALID");
|
||||
query.setLimit(0);
|
||||
String jsonString = JSON.toJSONString(query);
|
||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
||||
//log.info("同步ERP结果" + lists.size());
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (List<Object> list : lists) {
|
||||
for (Object r : list) {
|
||||
String fid = r.toString();
|
||||
if (StringUtils.isEmpty(fid)) {
|
||||
log.error("单据同步失败,没有找到FID");
|
||||
continue;
|
||||
}
|
||||
ids.add(fid);
|
||||
}
|
||||
}
|
||||
OperateParam param = new OperateParam();
|
||||
Map<String, String> error = new HashMap<>();
|
||||
List<PmFormData> formList = formDataService.list(new LambdaQueryWrapper<PmFormData>().eq(PmFormData::getForm_type, "BD_MATERIAL_1"));
|
||||
Set<String> idSet1 = formList.stream().map(PmFormData::getParent_id).collect(Collectors.toSet());
|
||||
Set<String> differenceSet = new HashSet<>(ids);
|
||||
differenceSet.removeAll(idSet1);
|
||||
//数据库已存在的数据
|
||||
// Set<String> existFormDataList = pmFormDataMapper.existFormDataList();
|
||||
for (String id : differenceSet) {
|
||||
param.setId(id);
|
||||
OperatorResult view = cloudApi.view(formType, param);
|
||||
RepoStatus status = view.getResult().getResponseStatus();
|
||||
if (status.isIsSuccess()) {
|
||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(view.getResult().getResult()));
|
||||
if (!formDataList.isEmpty()) {
|
||||
formDataService.saveBatch(formDataList);
|
||||
}
|
||||
} else {
|
||||
ArrayList<RepoError> errors = status.getErrors();
|
||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
||||
error.put(id, errorMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user