opt:配盘出库分配测试优化,任务优化

This commit is contained in:
zhaoyf
2026-10-21 22:05:23 +08:00
parent 14c24c1254
commit cda808df3e
14 changed files with 238 additions and 43 deletions

View File

@@ -31,6 +31,18 @@ public class PdaPlatingBufferController {
return ok("绑定成功");
}
@PostMapping("/group")
public ResponseEntity<Object> group(@RequestBody JSONObject p) {
service.scanGroup(p, true);
return ok("配盘组盘成功");
}
@PostMapping("/normalGroup")
public ResponseEntity<Object> normalGroup(@RequestBody JSONObject p) {
service.scanGroup(p, false);
return ok("普通组盘成功");
}
@PostMapping("/fetch")
public ResponseEntity<Object> fetch(@RequestBody JSONObject p) {
return ok(service.fetch(p));

View File

@@ -57,11 +57,64 @@ public class PlatingBufferService {
public MdMeMaterialbase material(String code) {
if (code == null || code.trim().isEmpty()) throw new BadRequestException("请扫描物料编码");
MdMeMaterialbase result = materials.getByCode(code.trim());
MdMeMaterialbase result = materials.getByCode(parseMaterialCode(code));
if (result == null) throw new BadRequestException("物料不存在");
return result;
}
public static String parseMaterialCode(String code) {
if (code == null || code.trim().isEmpty()) throw new BadRequestException("请扫描物料编码");
String value = code.trim().split(":", -1)[0].trim();
if (value.isEmpty() || value.contains(",")) throw new BadRequestException("物料编码无效");
return value;
}
/** 独立扫码组盘,不产生库存入库、搬运或生产领料单据。 */
@Transactional(rollbackFor = Exception.class)
public void scanGroup(JSONObject p, boolean plating) {
String pallet = text(p, "palletCode"), requestId = text(p, "requestId");
String port = plating ? text(p, "loadPort") : null;
lockLocations();
MdPbStoragevehicleinfo vehicle = vehicles.getOne(new LambdaQueryWrapper<MdPbStoragevehicleinfo>()
.eq(MdPbStoragevehicleinfo::getStoragevehicle_code, pallet).last("for update"));
if (vehicle == null) throw new BadRequestException("托盘不存在:" + pallet);
String source = plating ? PALLET_SOURCE : "PDA_NORMAL_GROUP";
if (groups.count(new LambdaQueryWrapper<GroupPlate>().eq(GroupPlate::getStoragevehicle_code, pallet)
.eq(GroupPlate::getExt_code, requestId).eq(GroupPlate::getExt_type, source)) > 0) return;
if (plating && points.selectByCode(port) == null) throw new BadRequestException("上料口不存在:" + port);
if (plating && vehicle.getLoad_port() != null && !vehicle.getLoad_port().isEmpty() && !port.equals(vehicle.getLoad_port()))
throw new BadRequestException("上料口与托盘绑定信息不一致");
if (!plating && vehicle.getLoad_port() != null && !vehicle.getLoad_port().isEmpty())
throw new BadRequestException("该托盘已绑定配盘上料口,请使用配盘组盘");
for (Structattr slot : structs.list(new LambdaQueryWrapper<Structattr>().eq(Structattr::getStoragevehicle_code, pallet))) available(slot);
List<GroupPlate> existing = stock(pallet);
if (existing.stream().anyMatch(g -> !IOSEnum.GROUP_PLATE_STATUS.code("组盘").equals(g.getStatus())
|| zero(g.getFrozen_qty()).signum() != 0 || !source.equals(g.getExt_type()) || !Objects.equals(port, g.getLoad_port())))
throw new BadRequestException("托盘存在已入库、冻结或其他用途物料,不能直接扫码追加组盘");
if (tasks.count(new LambdaQueryWrapper<SchBaseTask>().eq(SchBaseTask::getVehicle_code, pallet)
.notIn(SchBaseTask::getTask_status, Arrays.asList("5", "6"))) > 0)
throw new BadRequestException("托盘存在任务,请先处理任务后组盘");
com.alibaba.fastjson.JSONArray items = p.getJSONArray("items");
if (items == null || items.isEmpty()) throw new BadRequestException("请扫描至少一种物料并填写数量");
String codes = vehicle.getMaterial_code();
for (int i = 0; i < items.size(); i++) {
JSONObject item = items.getJSONObject(i);
MdMeMaterialbase m = material(item.getString("materialCode"));
BigDecimal qty = item.getBigDecimal("qty");
if (qty == null || qty.signum() <= 0) throw new BadRequestException("组盘数量必须大于0");
GroupPlate g = GroupPlate.builder().group_id(IdUtil.getStringId()).storagevehicle_code(pallet)
.material_code(m.getMaterial_code()).qty(qty).frozen_qty(BigDecimal.ZERO)
.qty_unit_id(m.getQty_unit_id()).qty_unit_name(m.getQty_unit_name()).status(IOSEnum.GROUP_PLATE_STATUS.code("组盘"))
.pcsn("1").load_port(port).ext_type(source).ext_code(requestId)
.create_id(SecurityUtils.getCurrentUserId()).create_name(SecurityUtils.getCurrentNickName()).create_time(DateUtil.now()).build();
groups.save(g);
if (plating) codes = appendMaterial(codes, m.getMaterial_code());
}
if (plating) vehicles.update(new LambdaUpdateWrapper<MdPbStoragevehicleinfo>()
.eq(MdPbStoragevehicleinfo::getStoragevehicle_code, pallet)
.set(MdPbStoragevehicleinfo::getMaterial_code, codes).set(MdPbStoragevehicleinfo::getLoad_port, port));
}
public JSONObject pallet(String code) {
MdPbStoragevehicleinfo v = vehicles.getByCode(code);
JSONObject result = new JSONObject();

View File

@@ -9,7 +9,9 @@ import org.nl.common.utils.SecurityUtils;
import org.nl.common.utils.IdUtil;;
import org.nl.wms.basedata_manage.enums.BaseDataEnum;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.core.AbstractTask;
import org.nl.wms.sch_manage.service.core.AcsTaskDto;
@@ -41,6 +43,9 @@ public class StOutTask extends AbstractTask {
@Resource
private IOStorInvDisMapper ioStorInvDisMapper;
@Resource
private ISchBasePointService schBasePointService;
@Override
public String create(JSONObject json) {
SchBaseTask task = new SchBaseTask();
@@ -97,10 +102,10 @@ public class StOutTask extends AbstractTask {
taskService.updateById(taskObj);
}
if (status.equals(TaskStatus.FINISHED)) {
this.finishTask(taskObj);
this.finishTask(taskObj);
}
if (status.equals(TaskStatus.CANCELED)) {
this.cancelTask(taskObj);
this.cancelTask(taskObj);
}
}
@@ -110,7 +115,8 @@ public class StOutTask extends AbstractTask {
SchBaseTask current = taskService.getOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SchBaseTask>()
.eq(SchBaseTask::getTask_code, code).last("for update"));
if (current == null) throw new BadRequestException("任务不存在");
if (TaskStatus.FINISHED.getCode().equals(current.getTask_status()) || TaskStatus.CANCELED.getCode().equals(current.getTask_status())) return;
if (TaskStatus.FINISHED.getCode().equals(current.getTask_status()) || TaskStatus.CANCELED.getCode().equals(current.getTask_status()))
return;
super.updateTaskStatus(code, status);
}
@@ -121,7 +127,7 @@ public class StOutTask extends AbstractTask {
if (ObjectUtil.isEmpty(taskObj)) {
throw new BadRequestException("该任务不存在");
}
this.finishTask(taskObj);
this.finishTask(taskObj);
}
@Override
@@ -136,7 +142,6 @@ public class StOutTask extends AbstractTask {
this.cancelTask(taskObj);
}
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask taskObj) {
@@ -148,6 +153,10 @@ public class StOutTask extends AbstractTask {
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setRemark("已完成");
taskService.updateById(taskObj);
schBasePointService.update(new LambdaUpdateWrapper<SchBasePoint>()
.set(SchBasePoint::getIng_task_code, null)
.set(SchBasePoint::getVehicle_code, taskObj.getVehicle_code())
.eq(SchBasePoint::getPoint_code, taskObj.getPoint_code2()));
outBillService.taskFinish(taskObj);
}
@@ -158,17 +167,17 @@ public class StOutTask extends AbstractTask {
taskService.update(new LambdaUpdateWrapper<SchBaseTask>()
.set(SchBaseTask::getIs_delete, BaseDataEnum.IS_YES_NOT.code("是"))
.set(SchBaseTask::getTask_status, TaskStatus.CANCELED.getCode())
.set(SchBaseTask::getRemark,"已取消")
.eq(SchBaseTask::getTask_id,taskObj.getTask_id())
.set(SchBaseTask::getRemark, "已取消")
.eq(SchBaseTask::getTask_id, taskObj.getTask_id())
);
//分配表清除任务
ioStorInvDisMapper.update(new IOStorInvDis(),new LambdaUpdateWrapper<>(IOStorInvDis.class)
.set(IOStorInvDis::getTask_id,null)
.set(IOStorInvDis::getPoint_code,null)
.set(IOStorInvDis::getIs_issued,0)
ioStorInvDisMapper.update(new IOStorInvDis(), new LambdaUpdateWrapper<>(IOStorInvDis.class)
.set(IOStorInvDis::getTask_id, null)
.set(IOStorInvDis::getPoint_code, null)
.set(IOStorInvDis::getIs_issued, 0)
.set(IOStorInvDis::getWork_status, IOSEnum.INBILL_DIS_STATUS.code("未生成"))
.eq(IOStorInvDis::getTask_id,taskObj.getTask_id())
.eq(IOStorInvDis::getTask_id, taskObj.getTask_id())
);
// 更新任务状态

View File

@@ -463,6 +463,7 @@ public class OutBillServiceImpl extends ServiceImpl<IOStorInvMapper, IOStorInv>
dis.setIostorinv_id(bill.getIostorinv_id());
dis.setIostorinvdtl_id(detail.getIostorinvdtl_id());
dis.setSeq_no(String.valueOf(seq++));
dis.setIs_issued(BaseDataEnum.IS_YES_NOT.code("否"));
dis.setPlan_qty(row.getFrozen_qty());
dis.setPoint_code(row.getLoad_port());
dis.setWork_status(IOSEnum.INBILL_DIS_STATUS.code("生成"));
@@ -475,6 +476,7 @@ public class OutBillServiceImpl extends ServiceImpl<IOStorInvMapper, IOStorInv>
ioStorInvDtlMapper.updateById(detail);
}
lockStructs(bill, Collections.singleton(first.getStruct_code()));
ioStorInvDisMapper.batchSave(allocations);
// JSONObject p = new JSONObject();
// p.put("task_type", "STOutTask");
// p.put("TaskCode", CodeUtil.getNewCode("TASK_CODE"));
@@ -726,8 +728,8 @@ public class OutBillServiceImpl extends ServiceImpl<IOStorInvMapper, IOStorInv>
.eq(SchBasePoint::getRegion_code, regionCode)
.eq(SchBasePoint::getIs_used, true)
.eq(SchBasePoint::getPoint_type, "1")//普通站点
.and(wrapper -> wrapper.isNotNull(SchBasePoint::getVehicle_code).ne(SchBasePoint::getVehicle_code, ""))
.and(wrapper -> wrapper.isNotNull(SchBasePoint::getIng_task_code).ne(SchBasePoint::getIng_task_code, ""))
.and(wrapper -> wrapper.isNull(SchBasePoint::getVehicle_code).or().eq(SchBasePoint::getVehicle_code, ""))
.and(wrapper -> wrapper.isNull(SchBasePoint::getIng_task_code).or().eq(SchBasePoint::getIng_task_code, ""))
);
if (CollectionUtils.isEmpty(pointList)) {
throw new BadRequestException("当前库区" + regionCode + "无可用点位");

View File

@@ -51,33 +51,38 @@ public class WorkOrderLLCKCallback implements CallbackStrategy {
WorkOrderBomDao bom = boms.selectById(detail.getSource_billdtl_id());
if (order == null || bom == null) throw new BadRequestException("工单或BOM已不存在,无法回传LLCK");
JSONObject source = new JSONObject();
source.put("order_code", order.getOrder_code()); source.put("order_id", order.getOrder_id()); source.put("org_code", order.getOrg_code());
source.put("bom_id", bom.getId()); source.put("item_id", bom.getItem_id()); source.put("qty", detail.getPlan_qty());
sources = new JSONArray(); sources.add(source);
source.put("order_code", order.getOrder_code());
source.put("order_id", order.getOrder_id());
source.put("org_code", order.getOrg_code());
source.put("bom_id", bom.getId());
source.put("item_id", bom.getItem_id());
source.put("qty", detail.getPlan_qty());
sources = new JSONArray();
sources.add(source);
}
JSONArray entries = new JSONArray();
BigDecimal offset = BigDecimal.ZERO;
for (int i = 0; i < sources.size(); i++) {
JSONObject source = sources.getJSONObject(i);
BigDecimal end = offset.add(source.getBigDecimal("qty"));
// 顺序归属来源份额,超计划整托数量归到最后一个来源BOM。
BigDecimal current = i == sources.size() - 1 ? total.subtract(offset).max(BigDecimal.ZERO) : total.min(end).subtract(offset).max(BigDecimal.ZERO);
BigDecimal previous = i == sources.size() - 1 ? reported.subtract(offset).max(BigDecimal.ZERO) : reported.min(end).subtract(offset).max(BigDecimal.ZERO);
BigDecimal delta = current.subtract(previous);
offset = end;
if (delta.signum() <= 0) continue;
JSONObject entry = new JSONObject();
entry.put("srcbillno", source.getString("order_code"));
entry.put("srcbillid", source.getString("order_id"));
entry.put("srcbillentryid", source.getString("item_id"));
entry.put("qty", delta);
entry.put("warehouseno", bill.getStor_code());
entry.put("materialno", detail.getMaterial_code());
entries.add(entry);
WorkOrderBomDao bom = boms.selectOne(new LambdaQueryWrapper<WorkOrderBomDao>().eq(WorkOrderBomDao::getId, source.getString("bom_id")).last("for update"));
if (bom == null) throw new BadRequestException("来源BOM已变更,无法累计领料数量");
bom.setUse_bom_qty((bom.getUse_bom_qty() == null ? BigDecimal.ZERO : bom.getUse_bom_qty()).add(delta));
boms.updateById(bom);
JSONObject source = sources.getJSONObject(i);
BigDecimal end = offset.add(source.getBigDecimal("qty"));
// 顺序归属来源份额,超计划整托数量归到最后一个来源BOM。
BigDecimal current = i == sources.size() - 1 ? total.subtract(offset).max(BigDecimal.ZERO) : total.min(end).subtract(offset).max(BigDecimal.ZERO);
BigDecimal previous = i == sources.size() - 1 ? reported.subtract(offset).max(BigDecimal.ZERO) : reported.min(end).subtract(offset).max(BigDecimal.ZERO);
BigDecimal delta = current.subtract(previous);
offset = end;
if (delta.signum() <= 0) continue;
JSONObject entry = new JSONObject();
entry.put("srcbillno", source.getString("order_code"));
entry.put("srcbillid", source.getString("order_id"));
entry.put("srcbillentryid", source.getString("item_id"));
entry.put("qty", delta);
entry.put("warehouseno", bill.getStor_code());
entry.put("materialno", detail.getMaterial_code());
entries.add(entry);
WorkOrderBomDao bom = boms.selectOne(new LambdaQueryWrapper<WorkOrderBomDao>().eq(WorkOrderBomDao::getId, source.getString("bom_id")).last("for update"));
if (bom == null) throw new BadRequestException("来源BOM已变更,无法累计领料数量");
bom.setUse_bom_qty((bom.getUse_bom_qty() == null ? BigDecimal.ZERO : bom.getUse_bom_qty()).add(delta));
boms.updateById(bom);
}
JSONObject data = new JSONObject();
data.put("orgno", sources.getJSONObject(0).getString("org_code"));

View File

@@ -81,11 +81,11 @@ public class WorkOrderOutboundService {
if (existingBills.size() == 1 && existingCodes.equals(selected))
throw new BadRequestException("选中工单已部分下推或属于其他合并单,请勿重复合并");
}
Map<List<String>, JSONObject> merged = new LinkedHashMap<>();
String warehouse = null, org = null;
Map<String, List<WorkOrderDao>> collectByProductLine = locked.stream().collect(Collectors.groupingBy(WorkOrderDao::getProduct_code));
ArrayList<String> billIds = new ArrayList<>();
for (List<WorkOrderDao> orders : collectByProductLine.values()) {
Map<List<String>, JSONObject> merged = new LinkedHashMap<>();
for (WorkOrderDao order : orders) {
required(order.getOrder_id(), "EAS工单ID");
String orderOrg = required(order.getOrg_code(), "工单组织编码");