opt:入库页面优化

This commit is contained in:
2025-12-01 17:45:45 +08:00
parent eb4f82025a
commit 8d84f85025
3 changed files with 297 additions and 121 deletions

View File

@@ -27,14 +27,16 @@ import org.nl.wms.warehouse_manage.service.IMdPbGroupplateDtlService;
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateService;
import org.nl.wms.warehouse_manage.service.dao.GroupPlate;
import org.nl.wms.warehouse_manage.service.dao.GroupPlateDtl;
import org.nl.wms.warehouse_manage.service.dao.mapper.MdPbGroupplateDtlMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -132,6 +134,34 @@ public class ErpToWmsServiceImpl implements ErpToWmsService {
.collect(Collectors.toList()))
);
if(CollectionUtil.isEmpty(unitDaoList)){
throw new BadRequestException("物料单位不存在");
}
// 查询已存在的托盘编码对应的合并单据带H-前缀且New_merge_flag=1
List<String> palletSns = dto.stream().map(ErpGroupplateDto::getPallet_sn).collect(Collectors.toList());
List<GroupPlate> existingPlates = iMdPbGroupplateService.list(
new QueryWrapper<GroupPlate>().lambda()
.in(GroupPlate::getStoragevehicle_code, palletSns)
);
Map<String, GroupPlate> existingPlateMap = existingPlates.stream()
.collect(Collectors.toMap(GroupPlate::getStoragevehicle_code, plate -> plate, (old, new_) -> old));
// 获取已存在的合并单据信息
List<String> existingExtIds = existingPlates.stream()
.map(GroupPlate::getExt_id)
.collect(Collectors.toList());
Map<String, PmFormData> existingFormDataMap = new HashMap<>();
if (CollectionUtil.isNotEmpty(existingExtIds)) {
List<PmFormData> existingFormDataList = iPmFormDataService.list(
new QueryWrapper<PmFormData>().lambda()
.in(PmFormData::getId, existingExtIds)
.eq(PmFormData::getNew_merge_flag, "1")
);
existingFormDataMap = existingFormDataList.stream()
.collect(Collectors.toMap(PmFormData::getId, formData -> formData, (old, new_) -> old));
}
// 明细集合
List<PmFormData> dtlArr = new ArrayList<>();
// 明细集合
@@ -140,135 +170,244 @@ public class ErpToWmsServiceImpl implements ErpToWmsService {
//将list通过托盘号进行分组
Map<String, List<ErpGroupplateDto>> dtoByPallet = dto.stream().collect(Collectors.groupingBy(ErpGroupplateDto::getPallet_sn));
dtoByPallet.forEach((key,value)->{
Map<String, PmFormData> finalExistingFormDataMap = existingFormDataMap;
dtoByPallet.forEach((palletSn, value)->{
// 检查托盘编码是否已存在
if (existingPlateMap.containsKey(palletSn)) {
// 托盘编码已存在,需要合并到老单据
GroupPlate existingPlate = existingPlateMap.get(palletSn);
PmFormData existingFormData = finalExistingFormDataMap.get(existingPlate.getExt_id());
PmFormData jsonDtl = new PmFormData();
MdMeMaterialbase materDao = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(value.get(0).getMater_code()))
.findFirst().orElse(null);
jsonDtl.setId(IdUtil.getStringId());
jsonDtl.setStatus(IOSEnum.BILL_STATUS.code("生成"));
jsonDtl.setStor_id(storDao.getStor_id());
jsonDtl.setStor_name(storDao.getStor_name());
jsonDtl.setForm_type("0001");
jsonDtl.setSource_form_date(DateUtil.today());
jsonDtl.setMaterial_code(value.get(0).getMater_code());
jsonDtl.setMaterial_id(materDao.getMaterial_id());
MdPbMeasureunit unitDao = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(value.get(0).getUnit_code()))
.findFirst().orElse(null);
jsonDtl.setUnit_id(unitDao.getMeasure_unit_id());
jsonDtl.setUnit_name(unitDao.getUnit_name());
jsonDtl.setVehicle_code(value.get(0).getPallet_sn());
jsonDtl.setVehicle_code2(value.get(0).getMater_frame());
jsonDtl.setCreate_name("ERP");
jsonDtl.setCreate_time(DateUtil.now());
if (existingFormData != null && "1".equals(existingFormData.getNew_merge_flag()) && existingFormData.getCode().startsWith("H-")) {
// 找到老的合并单据进行数量合并和merge_codes更新
for (ErpGroupplateDto groupplateDto : value) {
// 创建普通单据
PmFormData jsonDtl2 = new PmFormData();
MdMeMaterialbase materDaoDtl = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(groupplateDto.getMater_code()))
.findFirst().orElse(null);
jsonDtl2.setId(IdUtil.getStringId());
jsonDtl2.setStatus(IOSEnum.BILL_STATUS.code("生成"));
jsonDtl2.setStor_id(storDao.getStor_id());
jsonDtl2.setStor_name(storDao.getStor_name());
jsonDtl2.setForm_type("0001");
jsonDtl2.setSource_form_date(DateUtil.today());
jsonDtl2.setMaterial_code(groupplateDto.getMater_code());
jsonDtl2.setMaterial_id(materDaoDtl.getMaterial_id());
jsonDtl2.setQty(groupplateDto.getQty());
jsonDtl2.setPlan_qty(groupplateDto.getQty());
MdPbMeasureunit unitDaoDtl = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(groupplateDto.getUnit_code()))
.findFirst().orElse(null);
jsonDtl2.setUnit_id(unitDaoDtl.getMeasure_unit_id());
jsonDtl2.setUnit_name(unitDaoDtl.getUnit_name());
jsonDtl2.setVehicle_code(groupplateDto.getPallet_sn());
jsonDtl2.setVehicle_code2(groupplateDto.getMater_frame());
jsonDtl2.setCreate_name("ERP");
jsonDtl2.setCreate_time(DateUtil.now());
jsonDtl2.setCode(groupplateDto.getOrder_code());
jsonDtl2.setNew_merge_flag("0");
jsonDtl2.setIs_merge("1");
dtlArr.add(jsonDtl2);
//单据编号使用合单号
jsonDtl.setCode("H-"+value.get(0).getOrder_code());
jsonDtl.setNew_merge_flag("1");
// 更新合并单据的merge_codes和数量
String orderCode = groupplateDto.getOrder_code();
String mergeCodes = existingFormData.getMerge_codes();
if (StringUtils.isBlank(mergeCodes)) {
existingFormData.setMerge_codes(orderCode);
} else if (!mergeCodes.contains(orderCode)) {
existingFormData.setMerge_codes(mergeCodes + "," + orderCode);
}
// 累加数量
existingFormData.setQty(existingFormData.getQty().add(groupplateDto.getQty()));
existingFormData.setPlan_qty(existingFormData.getPlan_qty().add(groupplateDto.getQty()));
StringBuilder mergeCodes = new StringBuilder();
BigDecimal qty = new BigDecimal("0");
for(ErpGroupplateDto groupplateDto:value){
// 创建新的组盘明细,挂在老的组盘下面
MdMeMaterialbase materDaoDtl2 = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(groupplateDto.getMater_code()))
.findFirst().orElse(null);
MdPbMeasureunit unitDaoDtl2 = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(groupplateDto.getUnit_code()))
.findFirst().orElse(null);
PmFormData jsonDtl2 = new PmFormData();
MdMeMaterialbase materDaoDtl = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(groupplateDto.getMater_code()))
GroupPlateDtl plateDtl = new GroupPlateDtl();
plateDtl.setGroup_id(existingPlate.getGroup_id());
plateDtl.setGroupdtl_id(IdUtil.getStringId());
plateDtl.setStoragevehicle_code(groupplateDto.getPallet_sn());
plateDtl.setMaterial_id(materDaoDtl2.getMaterial_id());
plateDtl.setQty_unit_id(unitDaoDtl2.getMeasure_unit_id());
plateDtl.setQty_unit_name(unitDaoDtl2.getUnit_name());
plateDtl.setQty(groupplateDto.getQty());
plateDtl.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("组盘"));
plateDtl.setExt_code(existingFormData.getCode());
plateDtl.setExt_type("0001");
plateDtl.setExt_id(existingFormData.getId());
plateDtl.setMater_frame(groupplateDto.getMater_frame());
plateDtl.setCreate_name("ERP");
plateDtl.setCreate_time(DateUtil.now());
plateDtl.setCreate_id("ERP");
plateDtls.add(plateDtl);
}
// 更新老的组盘表的数量
BigDecimal totalQty = new BigDecimal("0");
for (ErpGroupplateDto groupplateDto : value) {
totalQty = totalQty.add(groupplateDto.getQty());
}
existingPlate.setQty(existingPlate.getQty().add(totalQty));
plates.add(existingPlate); // 添加到更新列表
}
} else {
// 托盘编码不存在,按照原逻辑创建新单据
PmFormData jsonDtl = new PmFormData();
MdMeMaterialbase materDao = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(value.get(0).getMater_code()))
.findFirst().orElse(null);
jsonDtl2.setId(IdUtil.getStringId());
jsonDtl2.setStatus(IOSEnum.BILL_STATUS.code("生成"));
jsonDtl2.setStor_id(storDao.getStor_id());
jsonDtl2.setStor_name(storDao.getStor_name());
jsonDtl2.setForm_type("0001");
jsonDtl2.setSource_form_date(DateUtil.today());
jsonDtl2.setMaterial_code(groupplateDto.getMater_code());
jsonDtl2.setMaterial_id(materDaoDtl.getMaterial_id());
jsonDtl2.setQty(groupplateDto.getQty());
jsonDtl2.setPlan_qty(groupplateDto.getQty());
MdPbMeasureunit unitDaoDtl = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(groupplateDto.getUnit_code()))
jsonDtl.setId(IdUtil.getStringId());
jsonDtl.setStatus(IOSEnum.BILL_STATUS.code("生成"));
jsonDtl.setStor_id(storDao.getStor_id());
jsonDtl.setStor_name(storDao.getStor_name());
jsonDtl.setForm_type("0001");
jsonDtl.setSource_form_date(DateUtil.today());
jsonDtl.setMaterial_code(value.get(0).getMater_code());
jsonDtl.setMaterial_id(materDao.getMaterial_id());
MdPbMeasureunit unitDao = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(value.get(0).getUnit_code()))
.findFirst().orElse(null);
jsonDtl2.setUnit_id(unitDaoDtl.getMeasure_unit_id());
jsonDtl2.setUnit_name(unitDaoDtl.getUnit_name());
jsonDtl2.setVehicle_code(groupplateDto.getPallet_sn());
jsonDtl2.setVehicle_code2(groupplateDto.getMater_frame());
jsonDtl2.setCreate_name("ERP");
jsonDtl2.setCreate_time(DateUtil.now());
jsonDtl.setUnit_id(unitDao.getMeasure_unit_id());
jsonDtl.setUnit_name(unitDao.getUnit_name());
jsonDtl.setVehicle_code(value.get(0).getPallet_sn());
jsonDtl.setVehicle_code2(value.get(0).getMater_frame());
jsonDtl.setCreate_name("ERP");
jsonDtl.setCreate_time(DateUtil.now());
jsonDtl2.setCode(groupplateDto.getOrder_code());
jsonDtl2.setNew_merge_flag("0");
jsonDtl2.setIs_merge("1");
dtlArr.add(jsonDtl2);
//单据编号使用合单号
jsonDtl.setCode("H-"+value.get(0).getOrder_code());
jsonDtl.setNew_merge_flag("1");
mergeCodes.append(groupplateDto.getOrder_code()).append(",");
qty = qty.add(groupplateDto.getQty());
StringBuilder mergeCodes = new StringBuilder();
BigDecimal qty = new BigDecimal("0");
for(ErpGroupplateDto groupplateDto:value){
PmFormData jsonDtl2 = new PmFormData();
MdMeMaterialbase materDaoDtl = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(groupplateDto.getMater_code()))
.findFirst().orElse(null);
jsonDtl2.setId(IdUtil.getStringId());
jsonDtl2.setStatus(IOSEnum.BILL_STATUS.code("生成"));
jsonDtl2.setStor_id(storDao.getStor_id());
jsonDtl2.setStor_name(storDao.getStor_name());
jsonDtl2.setForm_type("0001");
jsonDtl2.setSource_form_date(DateUtil.today());
jsonDtl2.setMaterial_code(groupplateDto.getMater_code());
jsonDtl2.setMaterial_id(materDaoDtl.getMaterial_id());
jsonDtl2.setQty(groupplateDto.getQty());
jsonDtl2.setPlan_qty(groupplateDto.getQty());
MdPbMeasureunit unitDaoDtl = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(groupplateDto.getUnit_code()))
.findFirst().orElse(null);
jsonDtl2.setUnit_id(unitDaoDtl.getMeasure_unit_id());
jsonDtl2.setUnit_name(unitDaoDtl.getUnit_name());
jsonDtl2.setVehicle_code(groupplateDto.getPallet_sn());
jsonDtl2.setVehicle_code2(groupplateDto.getMater_frame());
jsonDtl2.setCreate_name("ERP");
jsonDtl2.setCreate_time(DateUtil.now());
jsonDtl2.setCode(groupplateDto.getOrder_code());
jsonDtl2.setNew_merge_flag("0");
jsonDtl2.setIs_merge("1");
dtlArr.add(jsonDtl2);
mergeCodes.append(groupplateDto.getOrder_code()).append(",");
qty = qty.add(groupplateDto.getQty());
}
if(mergeCodes.length()>0){
mergeCodes.deleteCharAt(mergeCodes.length() - 1);
}
jsonDtl.setMerge_codes(mergeCodes.toString());
jsonDtl.setQty(qty);
jsonDtl.setPlan_qty(qty);
dtlArr.add(jsonDtl);
GroupPlate plate = new GroupPlate();
plate.setGroup_id(IdUtil.getStringId());
for(ErpGroupplateDto groupplateDto:value) {
MdMeMaterialbase materDaoDtl = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(groupplateDto.getMater_code()))
.findFirst().orElse(null);
MdPbMeasureunit unitDaoDtl = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(groupplateDto.getUnit_code()))
.findFirst().orElse(null);
GroupPlateDtl plate2 = new GroupPlateDtl();
plate2.setGroup_id(plate.getGroup_id());
plate2.setGroupdtl_id(IdUtil.getStringId());
plate2.setStoragevehicle_code(groupplateDto.getPallet_sn());
plate2.setMaterial_id(materDaoDtl.getMaterial_id());
plate2.setQty_unit_id(unitDaoDtl.getMeasure_unit_id());
plate2.setQty_unit_name(unitDaoDtl.getUnit_name());
plate2.setQty(groupplateDto.getQty());
plate2.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("组盘"));
plate2.setExt_code(jsonDtl.getCode());
plate2.setExt_type("0001");
plate2.setExt_id(jsonDtl.getId());
plate2.setMater_frame(groupplateDto.getMater_frame());
plate2.setCreate_name("ERP");
plate2.setCreate_time(DateUtil.now());
plate2.setCreate_id("ERP");
plateDtls.add(plate2);
}
plate.setStoragevehicle_code(value.get(0).getPallet_sn());
plate.setMaterial_id(materDao.getMaterial_id());
plate.setQty_unit_id(unitDao.getMeasure_unit_id());
plate.setQty_unit_name(unitDao.getUnit_name());
plate.setQty(qty);
plate.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("组盘"));
plate.setExt_code("H-"+value.get(0).getOrder_code());
plate.setExt_type("0001");
plate.setExt_id(jsonDtl.getId());
plate.setCreate_name("ERP");
plate.setCreate_time(DateUtil.now());
plate.setCreate_id("ERP");
plates.add(plate);
}
if(mergeCodes.length()>0){
mergeCodes.deleteCharAt(mergeCodes.length() - 1);
}
jsonDtl.setMerge_codes(mergeCodes.toString());
jsonDtl.setQty(qty);
jsonDtl.setPlan_qty(qty);
dtlArr.add(jsonDtl);
GroupPlate plate = new GroupPlate();
plate.setGroup_id(IdUtil.getStringId());
for(ErpGroupplateDto groupplateDto:value) {
MdMeMaterialbase materDaoDtl = materDaoList.stream()
.filter(row -> row.getMaterial_code().equals(groupplateDto.getMater_code()))
.findFirst().orElse(null);
MdPbMeasureunit unitDaoDtl = unitDaoList.stream()
.filter(row -> row.getUnit_name().equals(groupplateDto.getUnit_code()))
.findFirst().orElse(null);
GroupPlateDtl plate2 = new GroupPlateDtl();
plate2.setGroup_id(plate.getGroup_id());
plate2.setGroupdtl_id(IdUtil.getStringId());
plate2.setStoragevehicle_code(groupplateDto.getPallet_sn());
plate2.setMaterial_id(materDaoDtl.getMaterial_id());
plate2.setQty_unit_id(unitDaoDtl.getMeasure_unit_id());
plate2.setQty_unit_name(unitDaoDtl.getUnit_name());
plate2.setQty(groupplateDto.getQty());
plate2.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("组盘"));
plate2.setExt_code(jsonDtl.getCode());
plate2.setExt_type("0001");
plate2.setExt_id(jsonDtl.getId());
plate2.setMater_frame(groupplateDto.getMater_frame());
plate2.setCreate_name("ERP");
plate2.setCreate_time(DateUtil.now());
plate2.setCreate_id("ERP");
plateDtls.add(plate2);
}
plate.setStoragevehicle_code(value.get(0).getPallet_sn());
plate.setMaterial_id(materDao.getMaterial_id());
plate.setQty_unit_id(unitDao.getMeasure_unit_id());
plate.setQty_unit_name(unitDao.getUnit_name());
plate.setQty(qty);
plate.setStatus(IOSEnum.GROUP_PLATE_STATUS.code("组盘"));
plate.setExt_code("H-"+value.get(0).getOrder_code());
plate.setExt_type("0001");
plate.setExt_id(jsonDtl.getId());
plate.setCreate_name("ERP");
plate.setCreate_time(DateUtil.now());
plate.setCreate_id("ERP");
plates.add(plate);
});
//保存组盘记录到单据表
iPmFormDataService.saveBatch(dtlArr);
//保存组盘记录到组盘表
iMdPbGroupplateService.saveBatch(plates);
//保存组盘明细
iMdPbGroupplateDtlService.saveBatch(plateDtls);
// 保存新增的单据
if (CollectionUtil.isNotEmpty(dtlArr)) {
iPmFormDataService.saveBatch(dtlArr);
}
// 处理组盘表:需要更新已存在的,保存新的
List<GroupPlate> platesToUpdate = new ArrayList<>();
List<GroupPlate> platesToSave = new ArrayList<>();
for (GroupPlate plate : plates) {
if (existingPlateMap.containsKey(plate.getStoragevehicle_code())) {
platesToUpdate.add(plate);
} else {
platesToSave.add(plate);
}
}
if (CollectionUtil.isNotEmpty(platesToUpdate)) {
iMdPbGroupplateService.updateBatchById(platesToUpdate);
}
if (CollectionUtil.isNotEmpty(platesToSave)) {
iMdPbGroupplateService.saveBatch(platesToSave);
}
// 处理合并单据的更新
if (CollectionUtil.isNotEmpty(existingFormDataMap.values())) {
iPmFormDataService.updateBatchById(existingFormDataMap.values());
}
// 保存组盘明细
if (CollectionUtil.isNotEmpty(plateDtls)) {
iMdPbGroupplateDtlService.saveBatch(plateDtls);
}
log.info("sendGroupplate下发组盘接口输出参数为-------------------" + ErpResponse.requestOk().toString());

View File

@@ -163,7 +163,42 @@
</select>
<select id="queryOutBillPage" resultType="org.nl.wms.warehouse_manage.service.dto.IOStorInvDto">
SELECT DISTINCT ios.* ,m.material_code,m.material_name FROM st_ivt_iostorinv ios
SELECT DISTINCT
ios.iostorinv_id,
ios.bill_code,
ios.io_type,
ios.bill_type,
ios.stor_id,
ios.biz_date,
ios.stor_code,
ios.stor_name,
ios.source_id,
ios.source_name,
ios.source_type,
ios.total_qty,
ios.total_weight,
ios.detail_count,
ios.remark,
ios.bill_status,
ios.create_mode,
ios.input_optid,
ios.input_optname,
ios.input_time,
ios.update_optid,
ios.update_optname,
ios.update_time,
ios.dis_optid,
ios.dis_optname,
ios.dis_time,
ios.confirm_optid,
ios.confirm_optname,
ios.confirm_time,
ios.sysdeptid,
ios.syscompanyid,
ios.is_delete,
ios.is_upload,
ios.upload_optid,
ios.upload_time,dis.storagevehicle_code vehicle_code,dis.struct_code struct_code,m.material_code,m.material_name FROM st_ivt_iostorinv ios
LEFT JOIN st_ivt_iostorinvdtl dtl ON ios.iostorinv_id = dtl.iostorinv_id
LEFT JOIN st_ivt_iostorinvdis dis ON dtl.iostorinvdtl_id = dis.iostorinvdtl_id
LEFT JOIN md_me_materialbase m on dtl.material_id = m.material_id

View File

@@ -189,6 +189,8 @@
</el-table-column>
<el-table-column show-overflow-tooltip :formatter="stateFormat" width="80" prop="bill_status" :label="$t('wms.st.outbill.bill_status')" />
<el-table-column show-overflow-tooltip prop="stor_name" :label="$t('wms.st.outbill.warehouse')" width="80" />
<el-table-column prop="struct_code" :label="$t('wms.st.outbill.warehouse_location')" width="100px;" />
<el-table-column prop="vehicle_code" :label="$t('wms.st.outbill.vehicle_code')" width="100px;" />
<el-table-column show-overflow-tooltip prop="bill_type" :formatter="bill_typeFormat" :label="$t('wms.st.outbill.bill_type')" />
<el-table-column show-overflow-tooltip width="100" prop="biz_date" :label="$t('wms.st.outbill.business_date')" />
<el-table-column show-overflow-tooltip :label="$t('wms.st.outbill.detail_count')" align="center" prop="detail_count" width="60" />