add:如果本地无用料清单数据则在线同步数据

This commit is contained in:
2024-12-16 23:08:51 +08:00
parent 7d414eaf9f
commit 6b1a3d18cc
3 changed files with 81 additions and 39 deletions

View File

@@ -170,7 +170,7 @@ public class SyncReceiptProcessHandler implements ClassProcess {
JSONObject fStockId = new JSONObject(); JSONObject fStockId = new JSONObject();
//tofix 目前都入料箱库 //tofix 目前都入料箱库
fStockId.put("FNumber", "25"); fStockId.put("FNumber", "25");
linkedMap.put("FStockId", fStockId); tempMap.put("FStockId", fStockId);
} }
} }
fEntity.clear(); fEntity.clear();

View File

@@ -1,8 +1,10 @@
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.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
@@ -26,15 +28,16 @@ import org.nl.wms.stor_manage.struct.service.IStIvtStructattrService;
import org.nl.wms.stor_manage.struct.service.dao.StructAssignQty; import org.nl.wms.stor_manage.struct.service.dao.StructAssignQty;
import org.nl.wms.sync_manage.service.form_mapping.ISyncFormMappingService; import org.nl.wms.sync_manage.service.form_mapping.ISyncFormMappingService;
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping; import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
import org.nl.wms.system_manage.service.quartz.task.SyncErpBillsScheduleService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -61,11 +64,17 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
@Autowired @Autowired
private IBmFormStrucService formStrucService; private IBmFormStrucService formStrucService;
@Lazy
@Autowired @Autowired
private ISyncFormMappingService iSyncFormMappingService; private ISyncFormMappingService iSyncFormMappingService;
@Autowired @Autowired
private IStIvtStructattrService iStIvtStructattrService; private IStIvtStructattrService iStIvtStructattrService;
@Lazy
@Autowired
private SyncErpBillsScheduleService syncErpBillsScheduleService;
@Override @Override
public Integer syncFormData(String form_type, String dataString) { public Integer syncFormData(String form_type, String dataString) {
@@ -184,6 +193,30 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
page.setOrderBy("id DESC"); page.setOrderBy("id DESC");
List<PmFormDataDto> pmFormDataDtos = this.baseMapper.queryTree2(query); List<PmFormDataDto> pmFormDataDtos = this.baseMapper.queryTree2(query);
if (!CollectionUtils.isEmpty(pmFormDataDtos)) { if (!CollectionUtils.isEmpty(pmFormDataDtos)) {
handleFormDatas(pmFormDataDtos);
} else {
//根据单据编号同步ERP用料清单单据
if ("PRD_PPBOM".equals(query.getForm_type())) {
List<SyncFormMapping> list = iSyncFormMappingService.list(new LambdaQueryWrapper<SyncFormMapping>().eq(SyncFormMapping::getForm_type, "PRD_PPBOM"));
JSONArray mappingJson = list.get(0).getMapping_json();
String mappingString = JSON.toJSONString(mappingJson);
syncErpBillsScheduleService.syncData(mappingString, list.get(0).getForm_type(), list.get(0).getDtl_split(), query.getCode());
List<PmFormDataDto> pmFormData = this.baseMapper.queryTree2(query);
if (!CollectionUtils.isEmpty(pmFormData)) {
handleFormDatas(pmFormData);
}
com.baomidou.mybatisplus.extension.plugins.pagination.Page<PmFormDataDto> dtoPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page.getPages(), page.getPageSize(), page.getTotal());
dtoPage.setRecords(pmFormData);
dtoPage.setTotal(pmFormData.size());
return dtoPage;
}
}
com.baomidou.mybatisplus.extension.plugins.pagination.Page<PmFormDataDto> dtoPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page.getPages(), page.getPageSize(), page.getTotal());
dtoPage.setRecords(pmFormDataDtos);
return dtoPage;
}
private void handleFormDatas(List<PmFormDataDto> pmFormDataDtos) {
List<String> parents = pmFormDataDtos.stream().map(PmFormDataDto::getId).collect(Collectors.toList()); List<String> parents = pmFormDataDtos.stream().map(PmFormDataDto::getId).collect(Collectors.toList());
List<PmFormDataDto> childs = this.baseMapper.selectChilds(parents); List<PmFormDataDto> childs = this.baseMapper.selectChilds(parents);
if (!CollectionUtils.isEmpty(childs)) { if (!CollectionUtils.isEmpty(childs)) {
@@ -202,10 +235,6 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
} }
} }
} }
com.baomidou.mybatisplus.extension.plugins.pagination.Page<PmFormDataDto> dtoPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page.getPages(), page.getPageSize(), page.getTotal());
dtoPage.setRecords(pmFormDataDtos);
return dtoPage;
}
@Override @Override
public PmFormDataDto queryErpCode(String code, String stor_code) { public PmFormDataDto queryErpCode(String code, String stor_code) {
@@ -228,6 +257,7 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
//TODO:指定仓库 //TODO:指定仓库
List<StructAssignQty> structMaterials = iStIvtStructattrService.getStructIvtAssign(collect, stor_code); List<StructAssignQty> structMaterials = iStIvtStructattrService.getStructIvtAssign(collect, stor_code);
Map<String, List<StructAssignQty>> materialMap = structMaterials.stream().collect(Collectors.groupingBy(StructAssignQty::getMaterial_id)); Map<String, List<StructAssignQty>> materialMap = structMaterials.stream().collect(Collectors.groupingBy(StructAssignQty::getMaterial_id));
child:
for (PmFormDataDto child : childs) { for (PmFormDataDto child : childs) {
String childProductArea = child.getForm_data().getString("product_area"); String childProductArea = child.getForm_data().getString("product_area");
child.setProduct_area(childProductArea); child.setProduct_area(childProductArea);
@@ -237,9 +267,10 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
child.setPcsn(""); child.setPcsn("");
} else { } else {
for (StructAssignQty assignQty : maps) { for (StructAssignQty assignQty : maps) {
if (child.getPcsn().equals(assignQty.getPcsn())){ if (assignQty.getPcsn().equals(child.getPcsn())) {
child.setSto_qty(assignQty.getSto_qty()); child.setSto_qty(assignQty.getSto_qty());
child.setPcsn(assignQty.getPcsn()); child.setPcsn(assignQty.getPcsn());
continue child;
} }
} }
child.setSto_qty(BigDecimal.valueOf(maps.stream().mapToInt(a -> a.getSto_qty().intValue()).sum())); child.setSto_qty(BigDecimal.valueOf(maps.stream().mapToInt(a -> a.getSto_qty().intValue()).sum()));

View File

@@ -31,6 +31,7 @@ import org.nl.wms.sync_manage.service.form_mapping.impl.SyncFormMappingServiceIm
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -60,6 +61,7 @@ public class SyncErpBillsScheduleService {
@Autowired @Autowired
private IMdMeMaterialbaseService iMdMeMaterialbaseService; private IMdMeMaterialbaseService iMdMeMaterialbaseService;
@Lazy
@Autowired @Autowired
private IPmFormDataService formDataService; private IPmFormDataService formDataService;
@@ -111,7 +113,7 @@ public class SyncErpBillsScheduleService {
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);
syncData(mappingString, m.getForm_type(), m.getDtl_split()); syncData(mappingString, m.getForm_type(), m.getDtl_split(), "");
} }
} finally { } finally {
LuceneAppender.traceIdTL.remove(); LuceneAppender.traceIdTL.remove();
@@ -121,10 +123,11 @@ public class SyncErpBillsScheduleService {
/** /**
* 自动同步 * 自动同步
*/ */
public void syncData(String mappingJson, String formType, Boolean dtlSplit) { public void syncData(String mappingJson, String formType, Boolean dtlSplit, String billCode) {
boolean islock = lock.tryLock(); boolean islock = lock.tryLock();
try { try {
if (islock) { if (islock) {
ErpQuery query = new ErpQuery();
JSONArray result; JSONArray result;
Map errorMsg = new HashMap<>(); Map errorMsg = new HashMap<>();
// 获取当前日期 // 获取当前日期
@@ -132,16 +135,22 @@ public class SyncErpBillsScheduleService {
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 = getFilterString(formType, "", sevenDaysAgo, today); String filterString;
ErpQuery query = new ErpQuery(); if (StringUtils.isNotBlank(billCode)) {
filterString = "FBillNo = '" + billCode + "'";
} else {
filterString = getFilterString(formType, "", sevenDaysAgo, today);
}
query.setFilterString(filterString); query.setFilterString(filterString);
query.setFormId(formType); query.setFormId(formType);
query.setFieldKeys("FID"); query.setFieldKeys("FID");
query.setLimit(0); query.setLimit(0);
result = erpServiceUtils.queryBills(query); result = erpServiceUtils.queryBills(query);
if (ObjectUtils.isNotEmpty(result)) {
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi(); K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi); handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi);
} }
}
} catch (Exception ex) { } catch (Exception ex) {
log.error("同步数据时出现异常: {}", ex.getMessage()); log.error("同步数据时出现异常: {}", ex.getMessage());
} finally { } finally {
@@ -192,8 +201,10 @@ public class SyncErpBillsScheduleService {
query.setFieldKeys("FID"); query.setFieldKeys("FID");
query.setLimit(0); query.setLimit(0);
result = erpServiceUtils.queryBills(query); result = erpServiceUtils.queryBills(query);
if (ObjectUtils.isNotEmpty(result)) {
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi(); K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi); handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi);
}
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 {