fix:投料扣料

This commit is contained in:
zhaoyf
2026-09-08 19:28:26 +08:00
parent fe26043fba
commit 9583e503c6
2 changed files with 131 additions and 4 deletions

View File

@@ -21,9 +21,9 @@ public class RegionConstant {
public static final String WELDING_RAW_MATERIAL_SIDE = "E317";
/**
* 喷涂二次配盘区,原料线边库
* 装配线边库
*/
public static final String SPRAYING_RAW_MATERIAL_SIDE = "6.008";
public static final String ASSEMBLY_LINE_STORE_CODE = "6.007";
/**
* 机加工半成品

View File

@@ -1,11 +1,33 @@
package org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.domain.constant.RegionConstant;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
import org.nl.wms.basedata_manage.service.IBsrealStorattrService;
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
import org.nl.wms.basedata_manage.service.IStructattrService;
import org.nl.wms.basedata_manage.service.dao.BsrealStorattr;
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
import org.nl.wms.basedata_manage.service.dao.Structattr;
import org.nl.wms.ext_manage.service.dto.FeedingRecordPushDto;
import org.nl.wms.warehouse_manage.enums.IOSEnum;
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInv;
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDis;
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDtl;
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDisMapper;
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDtlMapper;
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvMapper;
import org.nl.wms.warehouse_manage.inventory.IStInventoryService;
import org.nl.wms.warehouse_manage.inventory.core.enums.InventoryChangeType;
import org.nl.wms.warehouse_manage.inventory.core.param.impl.OutFinishParam;
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.dao.FeedingRecord;
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.dao.FeedingRecordBom;
import org.nl.wms.warehouse_manage.stockReturn.receiveOutRetur.mapper.FeedingRecordBomMapper;
@@ -16,6 +38,8 @@ 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.ArrayList;
import java.util.List;
@Service
@@ -24,6 +48,28 @@ public class FeedingRecordServiceImpl extends ServiceImpl<FeedingRecordMapper, F
@Autowired
private FeedingRecordBomMapper feedingRecordBomMapper;
@Autowired
private IStructattrService iStructattrService;
@Autowired
private IBsrealStorattrService storattrService;
@Autowired
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
/**
* 出入库单明细mapper
*/
@Autowired
private IOStorInvDtlMapper ioStorInvDtlMapper;
/**
* 出入库单主表
*/
@Autowired
private IOStorInvMapper ioStorInvMapper; /**
* 出入库单主表
*/
@Autowired
private IOStorInvDisMapper ioStorInvDisMapper;
@Autowired
private IStInventoryService iStInventoryService;
@Override
@Transactional
@@ -32,14 +78,95 @@ public class FeedingRecordServiceImpl extends ServiceImpl<FeedingRecordMapper, F
FeedingRecord feedingRecord = new FeedingRecord();
BeanUtils.copyProperties(param,feedingRecord);
this.saveOrUpdate(feedingRecord);
//出库 从线边库扣料
String storCode = RegionConstant.ASSEMBLY_LINE_STORE_CODE;
final String now = DateUtil.now();
BsrealStorattr storattrOut = storattrService.findByCode(storCode);
Structattr structattrOut = iStructattrService.getOne(new LambdaQueryWrapper<Structattr>()
.eq(Structattr::getSect_code, storCode)
.last("limit 1"));
int seq = 1;
String currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
IOStorInv ioStorInvOut = new IOStorInv();
ioStorInvOut.setIostorinv_id(IdUtil.getStringId());
ioStorInvOut.setBill_code(CodeUtil.getNewCode("OUT_STORE_CODE"));
ioStorInvOut.setIo_type(IOSEnum.IO_TYPE.code("出库"));
ioStorInvOut.setBill_type(IOSEnum.BILL_TYPE.code("生产出库"));
ioStorInvOut.setBiz_date(DateUtil.today());
ioStorInvOut.setStor_code(storattrOut.getStor_code());
ioStorInvOut.setStor_name(storattrOut.getStor_name());
ioStorInvOut.setStor_id(storattrOut.getStor_id());
ioStorInvOut.setDetail_count(1);
ioStorInvOut.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
ioStorInvOut.setCreate_mode(IOSEnum.CREATE_MODE.code("外部接口产生"));
ioStorInvOut.setInput_optid(currentUserId);
ioStorInvOut.setInput_optname(nickName);
ioStorInvOut.setInput_time(now);
ioStorInvOut.setIs_delete(BaseDataEnum.IS_YES_NOT.code("否"));
ioStorInvOut.setIs_upload(BaseDataEnum.IS_YES_NOT.code("是"));
final List<IOStorInvDtl> ioStorInvDtls = new ArrayList<>();
final List<IOStorInvDis> iOStorInvDiss = new ArrayList<>();
List<OutFinishParam> outFinsParams = new ArrayList<>();
List<FeedingRecordPushDto.FeedingRecordPushBomDto> bom = param.getBom();
for (FeedingRecordPushDto.FeedingRecordPushBomDto bomDto : bom) {
for (FeedingRecordPushDto.FeedingRecordPushBomDto bomItem : bom) {
FeedingRecordBom feedingRecordBom = new FeedingRecordBom();
BeanUtils.copyProperties(bomDto,feedingRecordBom);
BeanUtils.copyProperties(bomItem,feedingRecordBom);
if (StringUtils.isEmpty(feedingRecordBom.getId())){
feedingRecordBom.setId(IdUtil.getStringId());
}
BigDecimal qty = bomItem.getBomQty();
final String materialCode = bomItem.getMaterialCode();
MdMeMaterialbase material = iMdMeMaterialbaseService.getByCode(materialCode);
final IOStorInvDtl ioStorInvDtl = new IOStorInvDtl();
ioStorInvDtl.setIostorinv_id(ioStorInvOut.getIostorinv_id());
ioStorInvDtl.setIostorinvdtl_id(IdUtil.getStringId());
ioStorInvDtl.setSeq_no(String.valueOf(seq));
ioStorInvDtl.setMaterial_code(materialCode);
ioStorInvDtl.setMaterial_id(material.getMaterial_id());
ioStorInvDtl.setQty_unit_id(material.getQty_unit_id());
ioStorInvDtl.setQty_unit_name(material.getQty_unit_name());
ioStorInvDtl.setPcsn("1");
ioStorInvDtl.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
ioStorInvDtl.setAssign_qty(qty);
ioStorInvDtl.setPlan_qty(qty);
ioStorInvDtl.setUnassign_qty(BigDecimal.ZERO);
ioStorInvDtl.setSource_bill_code(param.getOrderCode());
ioStorInvDtl.setSource_bill_type("work_order");
ioStorInvDtls.add(ioStorInvDtl);
// 分配
final IOStorInvDis ioStorInvDis = new IOStorInvDis();
ioStorInvDis.setIostorinvdis_id(IdUtil.getStringId());
ioStorInvDis.setIostorinv_id(ioStorInvOut.getIostorinv_id()); // 修正变量名
ioStorInvDis.setIostorinvdtl_id(ioStorInvDtl.getIostorinvdtl_id()); // 从对象获取,而不是从 JSON
ioStorInvDis.setSeq_no("1"); // 直接用 int,不需要 String
ioStorInvDis.setMaterial_id(material.getMaterial_id());
ioStorInvDis.setMaterial_code(materialCode); // 直接使用变量
ioStorInvDis.setSect_code(storCode);
ioStorInvDis.setStruct_code(structattrOut.getStruct_code());
ioStorInvDis.setPcsn("1");
ioStorInvDis.setStoragevehicle_code(structattrOut.getStoragevehicle_code());
ioStorInvDis.setWork_status(IOSEnum.INBILL_DIS_STATUS.code("完成"));
ioStorInvDis.setIs_issued(BaseDataEnum.IS_YES_NOT.code("是"));
ioStorInvDis.setQty_unit_id(material.getQty_unit_id());
ioStorInvDis.setQty_unit_name(material.getQty_unit_name());
ioStorInvDis.setPlan_qty(qty); // 直接使用 qty 变量
ioStorInvDis.setReal_qty(qty);
iOStorInvDiss.add(ioStorInvDis);
//更新组盘记录表
outFinsParams.add(OutFinishParam.builder()
.storagevehicleCode(structattrOut.getStoragevehicle_code())
.changeQty(qty)
.sectCode(storCode)
.structCode(structattrOut.getStruct_code())
.materialCode(materialCode)
.build());
feedingRecordBomMapper.insert(feedingRecordBom);
}
ioStorInvMapper.insert(ioStorInvOut);
ioStorInvDtlMapper.batchInsert(ioStorInvDtls);
ioStorInvDisMapper.batchSave(iOStorInvDiss);
iStInventoryService.changeInventory(InventoryChangeType.OUT_FINS, outFinsParams);
}
}