fix:退料兼容货架

This commit is contained in:
zhaoyf
2026-11-30 21:38:37 +08:00
parent 616f1ee81b
commit 7f4df2f738
4 changed files with 292 additions and 43 deletions

View File

@@ -53,6 +53,14 @@ public class InboundPdaController {
return ResponseData.build(list);
}
@GetMapping("/getStructInfo")
@Log("PDA根据库位编码查询库位及托盘信息")
@SaIgnore
public ResponseEntity getStructInfo(@RequestParam String struct_code) {
JSONObject result = inboundPdaService.getStructInfo(struct_code);
return ResponseData.build(result);
}
@PostMapping("/groupPlate")
@Log("PDA收货组盘")

View File

@@ -33,6 +33,12 @@ public interface InboundPdaService {
List<PurchaseMatInfoVo> getInfoByReturnBill(String code);
/**
* 退料入库-按库位编码查询库位及托盘信息,供 PDA 扫描库位时判断是否已有托盘。
* 返回字段:struct_code、struct_name、sect_code、stor_code、storagevehicle_code、lock_type、is_used。
*/
JSONObject getStructInfo(String struct_code);
void returnInbound(ReturnInboundDto returnInboundDto);
void manualGroupPlate(ManualGroupPlateDto dto);

View File

@@ -9,9 +9,26 @@ import java.util.List;
@Data
public class ReturnInboundDto {
/**
* 来源退料单号(pm_return.order_code)
*/
private String bill_id;
/**
* 仓库编码(bsrealstorattr.stor_code),原 sect_code 字段修正为 stor_code
*/
private String stor_code;
/**
* 库位编码(structattr.struct_code),可选:
* <ul>
* <li>为空 → 平库模式:按仓库定位虚拟库位(仓库编码与库区编码一致,单库位单托盘永久绑定);</li>
* <li>非空 → 货架立库模式:按库位定位,库位已有托盘则在原托盘上累加,库位为空则使用 vehicle_code 组盘入库。</li>
* </ul>
*/
private String struct_code;
/**
* 托盘/载具编码,立库模式下库位为空时必填;库位已有托盘时可省略(后端以库位绑定托盘为准)。
*/
private String vehicle_code;
private String sect_code;
private List<ReturnInboundDto.ReturnInboundDtlDto> detailList;
@Data
@@ -24,5 +41,9 @@ public class ReturnInboundDto {
private String sku_code;
private String batch_no;
private BigDecimal qty;
/**
* 退料单明细主键(pm_return.id),用于入库完成后按主键精确回调 SAP(SapReturnCallBack)
*/
private String source_billdtl_id;
}
}

View File

@@ -909,43 +909,94 @@ public class InboundPdaServiceImpl implements InboundPdaService {
}
@Override
@Transactional
public void returnInbound(ReturnInboundDto returnInboundDto) {
log.info("PDA提交退料入库 参数:{}", JSON.toJSONString(returnInboundDto));
// 查询库区
Sectattr sectDao = iSectattrService.findByCode(returnInboundDto.getSect_code());
if (sectDao == null){
throw new BadRequestException("仓库不存在");
public JSONObject getStructInfo(String struct_code) {
if (StrUtil.isEmptyIfStr(struct_code)) {
throw new BadRequestException("查询失败:库位编码不能为空");
}
//获取库位
Structattr struct = iStructattrService.findByCode(struct_code);
if (struct == null) {
throw new BadRequestException("查询失败:库位" + struct_code + "不存在");
}
JSONObject json = new JSONObject();
json.put("struct_id", struct.getStruct_id());
json.put("struct_code", struct.getStruct_code());
json.put("struct_name", struct.getStruct_name());
json.put("sect_id", struct.getSect_id());
json.put("sect_code", struct.getSect_code());
json.put("stor_id", struct.getStor_id());
json.put("stor_code", struct.getStor_code());
json.put("stor_name", struct.getStor_name());
json.put("storagevehicle_code", struct.getStoragevehicle_code());
json.put("lock_type", struct.getLock_type());
json.put("is_used", struct.getIs_used());
// 库位是否已有托盘:true=累加物料,false=组盘入库
json.put("has_vehicle", StrUtil.isNotBlank(struct.getStoragevehicle_code()));
return json;
}
/**
* 退料入库:
* <ul>
* <li>未传 struct_code → 平库模式:仓库编码与库区编码一致,单库位单托盘永久绑定,按仓库定位虚拟库位,沿用"按物料判断在库累加/组盘"逻辑;</li>
* <li>传入 struct_code → 货架立库模式:按库位定位。库位已有托盘则在原托盘上累加物料;库位为空则使用 vehicle_code 绑定托盘并组盘入库。</li>
* </ul>
* 注意:页面取自退料单 target_house_code 的值是仓库编码(stor_code),原代码误当作库区编码(sect_code)使用,
* 此处统一按仓库编码处理。
*/
@Override
@Transactional
public void returnInbound(ReturnInboundDto dto) {
log.info("PDA提交退料入库 参数:{}", JSON.toJSONString(dto));
String storCode = dto.getStor_code();
String structCode = dto.getStruct_code();
if (StrUtil.isBlank(storCode)) {
throw new BadRequestException("入库失败:仓库编码不能为空");
}
BsrealStorattr storDao = iSrealStorattrService.findByCode(storCode);
if (storDao == null) {
throw new BadRequestException("入库失败:仓库" + storCode + "不存在");
}
if (StrUtil.isNotBlank(structCode)) {
// 货架立库
returnInboundForRack(dto, storDao, structCode, dto.getVehicle_code());
} else {
// 平库
returnInboundForFlat(dto, storDao);
}
}
/**
* 平库退料入库:按仓库定位虚拟库位(单库位单托盘永久绑定),物料已在库则累加,否则组盘。
* 原逻辑沿用,仅将误用的 sect_code 修正为 stor_code。
*/
private void returnInboundForFlat(ReturnInboundDto dto, BsrealStorattr storDao) {
//获取虚拟库位(平库:仓库编码=库区编码,单库位且与单托盘永久绑定)
List<Structattr> structList = iStructattrService.lambdaQuery()
.eq(Structattr::getSect_id, sectDao.getSect_id())
.eq(Structattr::getStor_id, storDao.getStor_id())
.eq(Structattr::getLock_type, LOCK_TYPE.code("未锁定"))
.eq(Structattr::getIs_used, 1)
.isNotNull(Structattr::getStoragevehicle_code)
.orderByAsc(Structattr::getCreate_time).list();
if (structList.isEmpty()){
if (structList.isEmpty()) {
throw new BadRequestException("入库失败:未找到可用虚拟货位");
}
Structattr struct = structList.get(0);
log.info("平库入库:找到虚拟库位{}",JSON.toJSONString(struct));
log.info("平库退料入库:找到虚拟库位{}", JSON.toJSONString(struct));
String storagevehicleCode = struct.getStoragevehicle_code();//载具编码
boolean flag = false;
List<GroupPlate> gpList = new ArrayList<>();
List<AddInvParam> addInvParams = new ArrayList<>();
for (ReturnInboundDto.ReturnInboundDtlDto item : returnInboundDto.getDetailList()) {
//判断当前物料是否在库内
for (ReturnInboundDto.ReturnInboundDtlDto item : dto.getDetailList()) {
//判断当前物料是否在库内(按仓库编码过滤)
List<StructattrVechielDto> structattrVechielDtos = iStructattrService.collectVechicle(
MapOf.of("sect_code", returnInboundDto.getSect_code(), "material_code", item.getSku_code()));
if (!structattrVechielDtos.isEmpty()){
MapOf.of("stor_code", dto.getStor_code(), "material_code", item.getSku_code()));
if (!structattrVechielDtos.isEmpty()) {
StructattrVechielDto groupPlate = structattrVechielDtos.get(0);
Structattr structattr = iStructattrService.getOne(new LambdaQueryWrapper<Structattr>()
.eq(Structattr::getStoragevehicle_code, groupPlate.getStoragevehicle_code())
.eq(Structattr::getSect_code, returnInboundDto.getSect_code())
.eq(Structattr::getStor_code, dto.getStor_code())
.last("limit 1"));
if (Objects.equals(structattr.getSect_code(), returnInboundDto.getSect_code())){
if (structattr != null && Objects.equals(structattr.getStor_code(), dto.getStor_code())) {
//已在库,增加库存
flag = true;
AddInvParam addParam = new AddInvParam();
@@ -954,9 +1005,9 @@ public class InboundPdaServiceImpl implements InboundPdaService {
addParam.setStoragevehicleCode(groupPlate.getStoragevehicle_code());
addParam.setUnitName(groupPlate.getQty_unit_name());
addParam.setUnitId(groupPlate.getQty_unit_id());
addParam.setExtCode(returnInboundDto.getBill_id());
addParam.setExtCode(dto.getBill_id());
addParam.setExtType(BILL_TYPE.code("MES生产退货入库"));
addParam.setSectCode(returnInboundDto.getSect_code());
addParam.setSectCode(structattr.getSect_code());
addParam.setStructCode(structattr.getStruct_code());
addParam.setStorCode(structattr.getStor_code());
addParam.setQty(item.getQty());
@@ -975,35 +1026,34 @@ public class InboundPdaServiceImpl implements InboundPdaService {
.qty_unit_name(unitDao.getUnit_name())
.qty(item.getQty())
.status(GROUP_PLATE_STATUS.code("组盘"))
.ext_code(returnInboundDto.getBill_id())
.ext_code(dto.getBill_id())
.ext_type(BILL_TYPE.code("MES生产退货入库"))
.ext_dtl_code(item.getItem_no())
.ext_dtl_code(StrUtil.blankToDefault(item.getSource_billdtl_id(), item.getItem_no()))
.create_id(SecurityUtils.getCurrentUserId())
.create_name(SecurityUtils.getCurrentNickName())
.create_time(DateUtil.now())
.build();
if (flag){
if (flag) {
gpList.add(plateDao);
}else{
} else {
iMdPbGroupplateService.save(plateDao);
}
}
if (flag) iStInventoryService.changeInventory(InventoryChangeType.ADD_INV, addInvParams);
GroupPlateInboundDto groupPlateInboundDto = new GroupPlateInboundDto();
groupPlateInboundDto.setSect_code(sectDao.getSect_code());
groupPlateInboundDto.setSect_code(struct.getSect_code());
groupPlateInboundDto.setVehicle_code(storagevehicleCode);
groupPlateInboundDto.setGroupPlateList(gpList);
// this.submitGroupPlateInbound(groupPlateInboundDto, false);
// 查询组盘明细
List<GroupPlate> plateDaoList;
if (groupPlateInboundDto.getGroupPlateList().isEmpty()){
if (groupPlateInboundDto.getGroupPlateList().isEmpty()) {
plateDaoList = iMdPbGroupplateService.list(
new QueryWrapper<GroupPlate>().lambda()
.eq(GroupPlate::getStoragevehicle_code, groupPlateInboundDto.getVehicle_code())
.eq(GroupPlate::getStatus, GROUP_PLATE_STATUS.code("组盘"))
);
}else {
} else {
plateDaoList = groupPlateInboundDto.getGroupPlateList();
}
@@ -1015,11 +1065,9 @@ public class InboundPdaServiceImpl implements InboundPdaService {
.map(row -> row.getQty().doubleValue())
.reduce(Double::sum).orElse(0.0);
// 查询库区
// Sectattr sectDao = iSectattrService.findByCode(groupPlateInboundDto.getSect_code());
// 组织主表数据
// 组织主表数据(仓库、库区信息取自定位到的虚拟库位)
Map<String, Object> jsonMst = new HashMap<>();
jsonMst.put("stor_id", sectDao.getStor_id());
jsonMst.put("stor_id", struct.getStor_id());
jsonMst.put("bill_status", IOSEnum.BILL_STATUS.code("生成"));
jsonMst.put("total_qty", total_qty);
jsonMst.put("detail_count", 1);
@@ -1027,7 +1075,6 @@ public class InboundPdaServiceImpl implements InboundPdaService {
jsonMst.put("biz_date", DateUtil.now());
// 组织明细数据
ArrayList<HashMap> tableData = new ArrayList<>();
// GroupPlate plateDao = plateDaoList.get(0);
for (GroupPlate plateDao : plateDaoList) {
HashMap<String, Object> dtl = new HashMap<>();
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(plateDao.getMaterial_code());
@@ -1044,21 +1091,18 @@ public class InboundPdaServiceImpl implements InboundPdaService {
dtl.put("ext_type", plateDao.getExt_type());
dtl.put("source_billdtl_id", plateDao.getExt_dtl_code());
dtl.put("callback_strategy", "SapReturnCallBack");
// 调用新增
tableData.add(dtl);
}
jsonMst.put("tableData",tableData);
jsonMst.put("tableData", tableData);
String iostorinv_id = iRawAssistIStorService.insertDtl(jsonMst);
// 查询仓库
BsrealStorattr storeDao = iSrealStorattrService.getById(sectDao.getStor_id());
// 组织主数据
Map<String, Object> jsonMst1 = new HashMap<>();
jsonMst1.put("checked", true);
jsonMst1.put("sect_id", sectDao.getSect_id());
jsonMst1.put("stor_id", sectDao.getStor_id());
jsonMst1.put("sect_code", sectDao.getSect_code());
jsonMst1.put("stor_code", storeDao.getStor_code());
jsonMst1.put("sect_id", struct.getSect_id());
jsonMst1.put("stor_id", struct.getStor_id());
jsonMst1.put("sect_code", struct.getSect_code());
jsonMst1.put("stor_code", struct.getStor_code());
jsonMst1.put("storagevehicle_code", groupPlateInboundDto.getVehicle_code());
// 组织明细数据
List<IOStorInvDtl> ioStorInvDtls = ioStorInvDtlMapper.selectList(
@@ -1081,6 +1125,172 @@ public class InboundPdaServiceImpl implements InboundPdaService {
iRawAssistIStorService.disFinish(ioStorInvDis);
}
/**
* 货架立库退料入库:按库位定位。
* <ul>
* <li>库位已有托盘:在原托盘上累加物料(ADD_INV 维护组盘表数量);</li>
* <li>库位为空:使用传入托盘号绑定到库位并入库。</li>
* </ul>
* 入库单明细分配到指定库位(非自动分配),单据直接完成,回传策略 SapReturnCallBack。
*/
private void returnInboundForRack(ReturnInboundDto dto, BsrealStorattr storDao,
String structCode, String vehicleCode) {
Structattr struct = iStructattrService.findByCode(structCode);
if (struct == null) {
throw new BadRequestException("入库失败:库位" + structCode + "不存在");
}
if (!Objects.equals(struct.getStor_id(), storDao.getStor_id())) {
throw new BadRequestException("入库失败:库位" + structCode + "不属于仓库" + storDao.getStor_code());
}
if (struct.getIs_used() == null || !struct.getIs_used()) {
throw new BadRequestException("入库失败:库位" + structCode + "未启用");
}
if (!LOCK_TYPE.code("未锁定").equals(struct.getLock_type())) {
throw new BadRequestException("入库失败:库位" + structCode + "已锁定");
}
boolean hasVehicle = StrUtil.isNotBlank(struct.getStoragevehicle_code());
String storagevehicleCode;
if (hasVehicle) {
// 库位已有托盘:在原托盘上累加物料;若用户同时传了托盘号需与原托盘一致
storagevehicleCode = struct.getStoragevehicle_code();
if (StrUtil.isNotBlank(vehicleCode) && !Objects.equals(storagevehicleCode, vehicleCode.trim())) {
throw new BadRequestException("入库失败:库位" + structCode + "已绑定托盘"
+ storagevehicleCode + ",与扫描托盘" + vehicleCode + "不一致");
}
} else {
// 库位为空:组盘入库,必须提供托盘号
if (StrUtil.isBlank(vehicleCode)) {
throw new BadRequestException("入库失败:库位" + structCode + "为空,请扫描或输入托盘号");
}
storagevehicleCode = vehicleCode.trim();
// 校验该托盘未在其它库位上
long vehicleUsed = iStructattrService.count(new LambdaQueryWrapper<Structattr>()
.eq(Structattr::getStoragevehicle_code, storagevehicleCode));
if (vehicleUsed > 0) {
throw new BadRequestException("入库失败:托盘" + storagevehicleCode + "已在库内其它库位,请核实");
}
iMdPbStoragevehicleinfoService.chackAndInsert(storagevehicleCode);
// 将托盘绑定到当前空库位
struct.setStoragevehicle_code(storagevehicleCode);
iStructattrService.update(struct);
}
final String now = DateUtil.now();
String currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
final List<IOStorInvDtl> ioStorInvDtls = new ArrayList<>();
final List<IOStorInvDis> ioStorInvDiss = new ArrayList<>();
List<AddInvParam> addInvParams = new ArrayList<>();
List<InFinishParam> inFinishParams = new ArrayList<>();
// 生成入库单(直接完成态,分配到指定库位)
IOStorInv ioStorInvIn = new IOStorInv();
ioStorInvIn.setIostorinv_id(IdUtil.getStringId());
ioStorInvIn.setBill_code(CodeUtil.getNewCode("IN_STORE_CODE"));
ioStorInvIn.setIo_type(IOSEnum.IO_TYPE.code("入库"));
ioStorInvIn.setBill_type(IOSEnum.BILL_TYPE.code("退货入库"));
ioStorInvIn.setBiz_date(DateUtil.today());
ioStorInvIn.setStor_code(storDao.getStor_code());
ioStorInvIn.setStor_name(storDao.getStor_name());
ioStorInvIn.setStor_id(storDao.getStor_id());
ioStorInvIn.setDetail_count(1);
ioStorInvIn.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
ioStorInvIn.setCreate_mode(IOSEnum.CREATE_MODE.code("终端产生"));
ioStorInvIn.setInput_optid(currentUserId);
ioStorInvIn.setInput_optname(nickName);
ioStorInvIn.setInput_time(now);
ioStorInvIn.setIs_delete(BaseDataEnum.IS_YES_NOT.code("否"));
ioStorInvIn.setIs_upload(BaseDataEnum.IS_YES_NOT.code("是"));
int seq = 1;
for (ReturnInboundDto.ReturnInboundDtlDto item : dto.getDetailList()) {
MdMeMaterialbase material = iMdMeMaterialbaseService.getByCode(item.getSku_code());
String pcsn = Optional.ofNullable(item.getBatch_no()).filter(s -> !s.isEmpty()).orElse("1");
final IOStorInvDtl ioStorInvDtl = new IOStorInvDtl();
ioStorInvDtl.setIostorinv_id(ioStorInvIn.getIostorinv_id());
ioStorInvDtl.setIostorinvdtl_id(IdUtil.getStringId());
ioStorInvDtl.setSeq_no(String.valueOf(seq));
ioStorInvDtl.setMaterial_code(material.getMaterial_code());
ioStorInvDtl.setMaterial_id(material.getMaterial_id());
ioStorInvDtl.setQty_unit_id(material.getQty_unit_id());
ioStorInvDtl.setQty_unit_name(material.getQty_unit_name());
ioStorInvDtl.setPcsn(pcsn);
ioStorInvDtl.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
ioStorInvDtl.setAssign_qty(item.getQty());
ioStorInvDtl.setPlan_qty(item.getQty());
ioStorInvDtl.setUnassign_qty(BigDecimal.ZERO);
ioStorInvDtl.setReal_qty(item.getQty());
// 来源单据信息:source_bill_code=退料单号,insertDtl 与回调 SapReturnCallBack 均按此查退料单
ioStorInvDtl.setSource_bill_code(dto.getBill_id());
ioStorInvDtl.setSource_bill_type(BILL_TYPE.code("MES生产退货入库"));
ioStorInvDtl.setSource_billdtl_id(StrUtil.blankToDefault(item.getSource_billdtl_id(), item.getItem_no()));
ioStorInvDtl.setCallback_strategy("SapReturnCallBack");
ioStorInvDtls.add(ioStorInvDtl);
// 分配明细:直接分配到指定库位
final IOStorInvDis ioStorInvDis = new IOStorInvDis();
ioStorInvDis.setIostorinvdis_id(IdUtil.getStringId());
ioStorInvDis.setIostorinv_id(ioStorInvIn.getIostorinv_id());
ioStorInvDis.setIostorinvdtl_id(ioStorInvDtl.getIostorinvdtl_id());
ioStorInvDis.setSeq_no("1");
ioStorInvDis.setMaterial_id(material.getMaterial_id());
ioStorInvDis.setMaterial_code(material.getMaterial_code());
ioStorInvDis.setSect_code(struct.getSect_code());
ioStorInvDis.setStruct_code(struct.getStruct_code());
ioStorInvDis.setPcsn(pcsn);
ioStorInvDis.setStoragevehicle_code(storagevehicleCode);
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(item.getQty());
ioStorInvDis.setReal_qty(item.getQty());
ioStorInvDiss.add(ioStorInvDis);
AddInvParam addParam = new AddInvParam();
addParam.setPcsn(pcsn);
addParam.setMaterialCode(material.getMaterial_code());
addParam.setStoragevehicleCode(storagevehicleCode);
addParam.setUnitName(material.getQty_unit_name());
addParam.setUnitId(material.getQty_unit_id());
addParam.setExtCode(dto.getBill_id());
addParam.setExtType(BILL_TYPE.code("MES生产退货入库"));
addParam.setSectCode(struct.getSect_code());
addParam.setStorCode(storDao.getStor_code());
addParam.setStructCode(struct.getStruct_code());
addParam.setQty(item.getQty());
addInvParams.add(addParam);
InFinishParam inFinishParam = new InFinishParam();
inFinishParam.setPcsn(pcsn);
inFinishParam.setMaterialCode(material.getMaterial_code());
inFinishParam.setStoragevehicleCode(storagevehicleCode);
inFinishParam.setUnitName(material.getQty_unit_name());
inFinishParam.setUnitId(material.getQty_unit_id());
inFinishParam.setQty(item.getQty());
inFinishParam.setExtCode(ioStorInvIn.getBill_code());
inFinishParam.setExtType(ioStorInvIn.getBill_type());
inFinishParam.setStorCode(storDao.getStor_code());
inFinishParam.setSectCode(struct.getSect_code());
inFinishParam.setStructCode(struct.getStruct_code());
inFinishParams.add(inFinishParam);
seq++;
}
ioStorInvMapper.insert(ioStorInvIn);
ioStorInvDtlMapper.batchInsert(ioStorInvDtls);
ioStorInvDisMapper.batchSave(ioStorInvDiss);
// ADD_INV 维护组盘表数量(累加/新建 status=入库 记录),IN_FINISH 写库存变动流水
iStInventoryService.changeInventory(InventoryChangeType.ADD_INV, addInvParams);
iStInventoryService.changeInventory(InventoryChangeType.IN_FINISH, inFinishParams);
// 完成后回传 SAP(与平库 disFinish 触发的回调一致)
for (IOStorInvDtl dtl : ioStorInvDtls) {
callbackStrategyPublish.callbackStrategy(dtl.getCallback_strategy(), dtl);
}
}
/**
* 生产组盘入库
* @param dto
@@ -1091,6 +1301,10 @@ public class InboundPdaServiceImpl implements InboundPdaService {
if (dto.getItems().isEmpty()){
throw new BadRequestException("组盘物料为空");
}
List<Structattr> listByVeh = iStructattrService.list(new LambdaQueryWrapper<Structattr>()
.eq(Structattr::getStoragevehicle_code, dto.getVehicle_code()));
if (listByVeh.stream().anyMatch(item -> !Objects.equals(item.getStruct_code(), dto.getLocation_code())))
throw new BadRequestException("当前托盘已存在其他库位!");
iMdPbStoragevehicleinfoService.chackAndInsert(dto.getVehicle_code());
Structattr structattr = iStructattrService.getByCode(dto.getLocation_code());
BsrealStorattr storattrIn = storattrService.findByCode(structattr.getStor_code());