opt:优化ERP同步代码
This commit is contained in:
@@ -35,7 +35,7 @@ public class ErpServiceUtils {
|
|||||||
/**
|
/**
|
||||||
* 构建api
|
* 构建api
|
||||||
*/
|
*/
|
||||||
private K3CloudApi getCloudApi() {
|
public K3CloudApi getCloudApi() {
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
BeanUtils.copyProperties(erpSec, identifyInfo);
|
||||||
return new K3CloudApi(identifyInfo);
|
return new K3CloudApi(identifyInfo);
|
||||||
|
|||||||
@@ -120,6 +120,12 @@ public class BmFormStruc implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String pcsn;
|
private String pcsn;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动同步
|
||||||
|
*/
|
||||||
|
private Boolean is_sync;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义表单字段存json:{"dept":"部门","empp":"员工"}
|
* 自定义表单字段存json:{"dept":"部门","empp":"员工"}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ public class BmFormStrucDto implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String pcsn;
|
private String pcsn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动同步
|
||||||
|
*/
|
||||||
|
private Boolean is_sync;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义表单字段存json:{"dept":"部门","empp":"员工"}
|
* 自定义表单字段存json:{"dept":"部门","empp":"员工"}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -135,8 +135,7 @@ public class SyncErpService {
|
|||||||
* 单据审核
|
* 单据审核
|
||||||
*/
|
*/
|
||||||
public JSONObject audit(JSONObject from) {
|
public JSONObject audit(JSONObject from) {
|
||||||
// return erpServiceUtils.audit(from);
|
return erpServiceUtils.audit(from);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.nl.wms.flow_manage.flow.service.classprocessimpl;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.github.javaparser.utils.Log;
|
import com.github.javaparser.utils.Log;
|
||||||
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
||||||
@@ -12,6 +13,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.nl.common.domain.exception.BadRequestException;
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
import org.nl.common.enums.StatusEnum;
|
import org.nl.common.enums.StatusEnum;
|
||||||
import org.nl.common.utils.ErpServiceUtils;
|
import org.nl.common.utils.ErpServiceUtils;
|
||||||
|
import org.nl.wms.base_manage.material.service.IMdMeMaterialbaseService;
|
||||||
|
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
import org.nl.wms.external_system.erp.dto.ErpSec;
|
||||||
import org.nl.wms.flow_manage.flow.framework.process.nodeType.excess.impl.process.classprocess.ClassProcess;
|
import org.nl.wms.flow_manage.flow.framework.process.nodeType.excess.impl.process.classprocess.ClassProcess;
|
||||||
@@ -22,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -36,9 +40,11 @@ public class SyncReceiptProcessHandler implements ClassProcess {
|
|||||||
IPmFormDataService iPmFormDataService;
|
IPmFormDataService iPmFormDataService;
|
||||||
@Autowired
|
@Autowired
|
||||||
ErpSec erpSec;
|
ErpSec erpSec;
|
||||||
|
@Autowired
|
||||||
|
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
||||||
@Resource
|
@Resource
|
||||||
private ErpServiceUtils erpServiceUtils;
|
private ErpServiceUtils erpServiceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回执单回传
|
* 回执单回传
|
||||||
*/
|
*/
|
||||||
@@ -58,16 +64,30 @@ public class SyncReceiptProcessHandler implements ClassProcess {
|
|||||||
throw new BadRequestException("回传失败:回传数据form_data中数据格式不是formid,data类型");
|
throw new BadRequestException("回传失败:回传数据form_data中数据格式不是formid,data类型");
|
||||||
}
|
}
|
||||||
//判断生产入库的手工录入与MRP生成方式需回传不同的源单信息
|
//判断生产入库的手工录入与MRP生成方式需回传不同的源单信息
|
||||||
if ("0".equals(formData.getString("FSrcEntryId")) && "PRD_INSTOCK".equals(formType)) {
|
// if ("0".equals(formData.getString("FSrcEntryId")) && "PRD_INSTOCK".equals(formType)) {
|
||||||
//查询工序汇报单
|
// //查询工序汇报单
|
||||||
ErpQuery reportQuery = new ErpQuery();
|
// ErpQuery reportQuery = new ErpQuery();
|
||||||
reportQuery.setFilterString("FMoNumber ='" + formData.getString("moNumber") + "'");
|
// reportQuery.setFilterString("FMoNumber ='" + formData.getString("moNumber") + "'");
|
||||||
reportQuery.setOrderString("FId desc");
|
// reportQuery.setOrderString("FId desc");
|
||||||
reportQuery.setFormId("SFC_OperationReport");
|
// reportQuery.setFormId("SFC_OperationReport");
|
||||||
JSONArray jsonArray = erpServiceUtils.queryBills(reportQuery);
|
// JSONArray jsonArray = erpServiceUtils.queryBills(reportQuery);
|
||||||
formData.remove("FSrcEntryId");
|
// formData.remove("FSrcEntryId");
|
||||||
formData.put("FSrcBillNo", jsonArray.getJSONObject(0).getString("BillNo"));
|
// formData.put("FSrcBillNo", jsonArray.getJSONObject(0).getString("BillNo"));
|
||||||
}
|
// }
|
||||||
|
// if ("PRD_PickMtrl".equals(formType)) {
|
||||||
|
// List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new LambdaQueryWrapper<MdMeMaterialbase>().eq(MdMeMaterialbase::getMaterial_id, formData.getString("material_id")));
|
||||||
|
// if (ObjectUtils.isNotEmpty(materialList)) {
|
||||||
|
// MdMeMaterialbase materialInfo = materialList.get(0);
|
||||||
|
// //没有启用批次号
|
||||||
|
// if ("0".equals(materialInfo.getPrint_no())) {
|
||||||
|
// formData.remove("FLot");
|
||||||
|
// }
|
||||||
|
// //辅助单位
|
||||||
|
// if (!"0".equals(materialInfo.getAssist_unit_id())) {
|
||||||
|
// formData.put("FSecUnitId", materialInfo.getAssist_unit_id());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
String json = formData.toJSONString();
|
String json = formData.toJSONString();
|
||||||
try {
|
try {
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
IdentifyInfo identifyInfo = new IdentifyInfo();
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|||||||
obj4.put("total", total4);
|
obj4.put("total", total4);
|
||||||
obj4.put("box", box4);
|
obj4.put("box", box4);
|
||||||
obj4.put("time", time4);
|
obj4.put("time", time4);
|
||||||
List<TaskInfo> taskList = cockpitMapper.getTaskListByDays(0);
|
List<TaskInfo> taskList = cockpitMapper.getTaskListByDays(7);
|
||||||
if (ObjectUtil.isNotEmpty(taskList)) {
|
if (ObjectUtil.isNotEmpty(taskList)) {
|
||||||
//料箱库入库
|
//料箱库入库
|
||||||
List<TaskInfo> stockList1 = taskList.stream()
|
List<TaskInfo> stockList1 = taskList.stream()
|
||||||
@@ -227,7 +227,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|||||||
JSONObject obj3 = new JSONObject();
|
JSONObject obj3 = new JSONObject();
|
||||||
List<MdMeMaterialbase> materList = cockpitMapper.getMaterInfos();
|
List<MdMeMaterialbase> materList = cockpitMapper.getMaterInfos();
|
||||||
if (ObjectUtil.isNotEmpty(materList)) {
|
if (ObjectUtil.isNotEmpty(materList)) {
|
||||||
List<MdMeMaterialbase> fstockList = materList.stream().filter(r -> "FStockId".equals(r.getProduct_area())).collect(Collectors.toList());
|
List<MdMeMaterialbase> fstockList = materList.stream().filter(r -> "FStockId".equals(r.getProduct_area())).collect(Collectors.toList());
|
||||||
List<MdMeMaterialbase> fstockPalletList = materList.stream().filter(r -> "FStockPallet".equals(r.getProduct_area())).collect(Collectors.toList());
|
List<MdMeMaterialbase> fstockPalletList = materList.stream().filter(r -> "FStockPallet".equals(r.getProduct_area())).collect(Collectors.toList());
|
||||||
if (ObjectUtil.isNotEmpty(fstockList)) {
|
if (ObjectUtil.isNotEmpty(fstockList)) {
|
||||||
getMaterialAnalysis(jsonArray1, obj0, obj1, fstockList);
|
getMaterialAnalysis(jsonArray1, obj0, obj1, fstockList);
|
||||||
@@ -384,6 +384,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|||||||
private static void getMaterialAnalysis(JSONArray jsonArray, JSONObject obj0, JSONObject obj1, List<MdMeMaterialbase> materList) {
|
private static void getMaterialAnalysis(JSONArray jsonArray, JSONObject obj0, JSONObject obj1, List<MdMeMaterialbase> materList) {
|
||||||
//物料分组
|
//物料分组
|
||||||
Map<String, BigDecimal> groupedMaterials = materList.stream()
|
Map<String, BigDecimal> groupedMaterials = materList.stream()
|
||||||
|
.filter(material -> material.getMaterial_name() != null)
|
||||||
.collect(Collectors.groupingBy(
|
.collect(Collectors.groupingBy(
|
||||||
MdMeMaterialbase::getMaterial_name,
|
MdMeMaterialbase::getMaterial_name,
|
||||||
Collectors.reducing(BigDecimal.ZERO, MdMeMaterialbase::getNet_weight, BigDecimal::add)
|
Collectors.reducing(BigDecimal.ZERO, MdMeMaterialbase::getNet_weight, BigDecimal::add)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.nl.wms.pm_manage.form_data.service.impl;
|
package org.nl.wms.pm_manage.form_data.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
|||||||
@@ -13,11 +13,14 @@ import org.apache.commons.lang3.ObjectUtils;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.nl.common.domain.exception.BadRequestException;
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
import org.nl.common.utils.BaseCode;
|
import org.nl.common.utils.BaseCode;
|
||||||
|
import org.nl.common.utils.ErpServiceUtils;
|
||||||
import org.nl.common.utils.IdUtil;
|
import org.nl.common.utils.IdUtil;
|
||||||
import org.nl.common.utils.MapOf;
|
import org.nl.common.utils.MapOf;
|
||||||
import org.nl.config.lucene.LuceneAppender;
|
import org.nl.config.lucene.LuceneAppender;
|
||||||
import org.nl.wms.base_manage.material.service.IMdMeMaterialbaseService;
|
import org.nl.wms.base_manage.material.service.IMdMeMaterialbaseService;
|
||||||
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
||||||
|
import org.nl.wms.config_manage.form_struc.service.dao.BmFormStruc;
|
||||||
|
import org.nl.wms.config_manage.form_struc.service.impl.BmFormStrucServiceImpl;
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
import org.nl.wms.external_system.erp.dto.ErpSec;
|
||||||
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
||||||
@@ -50,6 +53,10 @@ public class SyncErpBillsScheduleService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SyncFormMappingServiceImpl syncFormMappingServiceImpl;
|
private SyncFormMappingServiceImpl syncFormMappingServiceImpl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BmFormStrucServiceImpl bmFormStrucServiceImpl;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
||||||
|
|
||||||
@@ -58,6 +65,12 @@ public class SyncErpBillsScheduleService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PmFormDataMapper pmFormDataMapper;
|
private PmFormDataMapper pmFormDataMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ErpServiceUtils erpServiceUtils;
|
||||||
|
|
||||||
|
|
||||||
//组织机构
|
//组织机构
|
||||||
private static final Map<String, String> BILL_ORG_MAPPING = MapOf.of(
|
private static final Map<String, String> BILL_ORG_MAPPING = MapOf.of(
|
||||||
"PRD_PPBOM", "FPrdOrgId",
|
"PRD_PPBOM", "FPrdOrgId",
|
||||||
@@ -92,7 +105,9 @@ public class SyncErpBillsScheduleService {
|
|||||||
MDC.put("requestTime", DateUtil.now());
|
MDC.put("requestTime", DateUtil.now());
|
||||||
LuceneAppender.traceIdTL.set(BaseCode.intToChars(IdUtil.getLongId()));
|
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, "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<BmFormStruc> strucList = bmFormStrucServiceImpl.list(new LambdaQueryWrapper<BmFormStruc>().eq(BmFormStruc::getIs_sync, "1"));
|
||||||
|
Set<String> structSet = strucList.stream().map(BmFormStruc::getForm_type).collect(Collectors.toSet());
|
||||||
|
List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, structSet));
|
||||||
for (SyncFormMapping m : list) {
|
for (SyncFormMapping m : list) {
|
||||||
JSONArray mappingJson = m.getMapping_json();
|
JSONArray mappingJson = m.getMapping_json();
|
||||||
String mappingString = JSON.toJSONString(mappingJson);
|
String mappingString = JSON.toJSONString(mappingJson);
|
||||||
@@ -110,107 +125,22 @@ public class SyncErpBillsScheduleService {
|
|||||||
boolean islock = lock.tryLock();
|
boolean islock = lock.tryLock();
|
||||||
try {
|
try {
|
||||||
if (islock) {
|
if (islock) {
|
||||||
List<Object> result = new ArrayList<>();
|
JSONArray result;
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
Map errorMsg = new HashMap<>();
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
|
||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
|
||||||
// 获取当前日期
|
// 获取当前日期
|
||||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||||
String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
||||||
String filterString = BILL_ORG_MAPPING.get(formType) + " = '750572' AND FDocumentStatus = 'C' ";
|
String filterString = getFilterString(formType, "", sevenDaysAgo, today);
|
||||||
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)) {
|
|
||||||
filterString += " AND FCloseStatus ='A' AND FCreateDate >= '" + sevenDaysAgo + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59' ";
|
|
||||||
} else {
|
|
||||||
filterString += " AND FCreateDate >= '" + sevenDaysAgo + " 00:00:00' and FCreateDate <= '" + today + " 23:59:59' ";
|
|
||||||
}
|
|
||||||
// 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' ";
|
|
||||||
// }
|
|
||||||
//String filterString = "FUseOrgId='750572'";
|
|
||||||
ErpQuery query = new ErpQuery();
|
ErpQuery query = new ErpQuery();
|
||||||
query.setFilterString(filterString);
|
query.setFilterString(filterString);
|
||||||
query.setFormId(formType);
|
query.setFormId(formType);
|
||||||
query.setFieldKeys("FID");
|
query.setFieldKeys("FID");
|
||||||
query.setLimit(0);
|
query.setLimit(0);
|
||||||
String jsonString = JSON.toJSONString(query);
|
result = erpServiceUtils.queryBills(query);
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
|
||||||
Set<String> ids = new HashSet<>();
|
handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi);
|
||||||
for (List<Object> list : lists) {
|
|
||||||
for (Object r : list) {
|
|
||||||
String fid = r.toString();
|
|
||||||
if (StringUtils.isEmpty(fid)) {
|
|
||||||
log.error("单据同步失败,没有找到FID");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ids.add(fid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//物料同步
|
|
||||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
|
||||||
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
|
||||||
OperateParam param = new OperateParam();
|
|
||||||
Map<String, String> error = new HashMap<>();
|
|
||||||
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();
|
|
||||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
|
||||||
error.put(id, errorMsg);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理ID [{}] 时出现异常: {}", id, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!CollectionUtils.isEmpty(error)) {
|
|
||||||
log.error("ERP单据同步失败:{}", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
|
||||||
外部:
|
|
||||||
for (Object r : result) {
|
|
||||||
try {
|
|
||||||
jsonString = JSON.toJSONString(r);
|
|
||||||
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())) {
|
|
||||||
f.setParent_id(mainId + "$" + formType);
|
|
||||||
}
|
|
||||||
f.setId(f.getId() + "$" + f.getForm_type());
|
|
||||||
formDataService.save(f);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析数据 [{}]数据失败: {}", JSON.toJSONString(r), e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
log.error("同步数据时出现异常: {}", ex.getMessage());
|
||||||
@@ -245,7 +175,7 @@ public class SyncErpBillsScheduleService {
|
|||||||
try {
|
try {
|
||||||
if (islock) {
|
if (islock) {
|
||||||
//单据同步总数
|
//单据同步总数
|
||||||
List<Object> result = new ArrayList<>();
|
JSONArray result;
|
||||||
// 获取当前日期
|
// 获取当前日期
|
||||||
String timeEnd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
String timeEnd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
@@ -255,123 +185,15 @@ public class SyncErpBillsScheduleService {
|
|||||||
timeStart = start;
|
timeStart = start;
|
||||||
timeEnd = end;
|
timeEnd = end;
|
||||||
}
|
}
|
||||||
//String filterString = "FUseOrgId='750572'";
|
String filterString = getFilterString(formType, code, timeEnd, timeStart);
|
||||||
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();
|
ErpQuery query = new ErpQuery();
|
||||||
query.setFilterString(filterString);
|
query.setFilterString(filterString);
|
||||||
query.setFormId(formType);
|
query.setFormId(formType);
|
||||||
query.setFieldKeys("FID");
|
query.setFieldKeys("FID");
|
||||||
query.setLimit(0);
|
query.setLimit(0);
|
||||||
String jsonString = JSON.toJSONString(query);
|
result = erpServiceUtils.queryBills(query);
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi);
|
||||||
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)){
|
if (!CollectionUtils.isEmpty(errorMsg)){
|
||||||
throw new BadRequestException("同步成功"+(result.size()-errorMsg.size())+"条,失败信息:"+errorMsg.toString());
|
throw new BadRequestException("同步成功"+(result.size()-errorMsg.size())+"条,失败信息:"+errorMsg.toString());
|
||||||
}else {
|
}else {
|
||||||
@@ -389,6 +211,94 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getFilterString(String formType, String code, String timeEnd, String timeStart) {
|
||||||
|
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' ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filterString;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleBills(String mappingJson, String formType, Boolean dtlSplit, Map errorMsg, JSONArray result, K3CloudApi cloudApi) {
|
||||||
|
//物料同步
|
||||||
|
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)) {
|
||||||
|
if (false) {
|
||||||
|
//明细单据
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询物料信息
|
* 查询物料信息
|
||||||
@@ -504,8 +414,8 @@ public class SyncErpBillsScheduleService {
|
|||||||
}
|
}
|
||||||
OperateParam param = new OperateParam();
|
OperateParam param = new OperateParam();
|
||||||
Map<String, String> error = new HashMap<>();
|
Map<String, String> error = new HashMap<>();
|
||||||
List<PmFormData> formList = formDataService.list(new LambdaQueryWrapper<PmFormData>().eq(PmFormData::getForm_type, "BD_MATERIAL_1"));
|
List<MdMeMaterialbase> formList = iMdMeMaterialbaseService.list();
|
||||||
Set<String> idSet1 = formList.stream().map(PmFormData::getParent_id).collect(Collectors.toSet());
|
Set<String> idSet1 = formList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
||||||
Set<String> differenceSet = new HashSet<>(ids);
|
Set<String> differenceSet = new HashSet<>(ids);
|
||||||
differenceSet.removeAll(idSet1);
|
differenceSet.removeAll(idSet1);
|
||||||
//数据库已存在的数据
|
//数据库已存在的数据
|
||||||
@@ -517,8 +427,9 @@ public class SyncErpBillsScheduleService {
|
|||||||
if (status.isIsSuccess()) {
|
if (status.isIsSuccess()) {
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(view.getResult().getResult()));
|
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(view.getResult().getResult()));
|
||||||
if (!formDataList.isEmpty()) {
|
List<PmFormData> formData = formDataList.stream().filter(r -> StringUtils.isBlank(r.getCode())).collect(Collectors.toList());
|
||||||
formDataService.saveBatch(formDataList);
|
if (!formData.isEmpty()) {
|
||||||
|
formDataService.saveBatch(formData);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
ArrayList<RepoError> errors = status.getErrors();
|
||||||
|
|||||||
Reference in New Issue
Block a user