add:配盘出库方案修改

This commit is contained in:
zhaoyf
2026-10-20 11:13:16 +08:00
parent a0d32fba1e
commit b0061d8eab
21 changed files with 810 additions and 122 deletions

View File

@@ -9,8 +9,9 @@ public class RegionConstant {
* 一次配盘区编码
*/
public static final String FIRST_MEAL = "EB1";
public static final String EA2 = "EA2";
public static final String EB2 = "EB2";
public static final String EA2 = "EA2";//原料区
public static final String EB2 = "EB2";//配盘完成存放区
public static final String EB1 = "EB1";//配盘缓存区,用于配盘
/**
* 机加工二次配盘区,原料线边库

View File

@@ -55,7 +55,7 @@ public class FIFORuleHandler extends Decisioner<StrategyStructMaterialVO, Strate
}
List<StrategyStructMaterialVO> divStruct = new ArrayList<>();
for (StructattrVechielDto vechielDto : vechielDtos) {
if (planQty.intValue()<=0){
if (planQty.signum()<=0){
break;
}
BigDecimal qty = vechielDto.getQty();

View File

@@ -54,7 +54,7 @@ public class FIFO2RuleHandler extends Decisioner<StrategyStructMaterialVO, Strat
}
List<StrategyStructMaterialVO> divStruct = new ArrayList<>();
for (StructattrVechielDto vechielDto : vechielDtos) {
if (planQty.intValue()<=0){
if (planQty.signum()<=0){
break;
}
BigDecimal qty = vechielDto.getQty();

View File

@@ -54,7 +54,7 @@ public class FIFONoStorHandler extends Decisioner<StrategyStructMaterialVO, Stra
}
List<StrategyStructMaterialVO> divStruct = new ArrayList<>();
for (StructattrVechielDto vechielDto : vechielDtos) {
if (planQty.intValue()<=0){
if (planQty.signum()<=0){
break;
}
BigDecimal qty = vechielDto.getQty();

View File

@@ -84,7 +84,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
}
catch (Exception ex){
SchBaseTask failed = iSchBaseTaskService.getByCode(task_code);
if (failed != null && "PlatingDeliveryTask".equals(failed.getConfig_code())) {
if (failed != null && ("PlatingDeliveryTask".equals(failed.getConfig_code()) || "PlatingTransferTask".equals(failed.getConfig_code()))) {
throw new org.nl.common.exception.BadRequestException("配盘配送回调失败:" + ex.getMessage());
}
log.error("ACS任务回调失败:{}", task_code, ex);

View File

@@ -0,0 +1,40 @@
package org.nl.wms.pda_manage.demand.controller;
import com.alibaba.fastjson.JSONObject;
import org.nl.common.base.ResponseData;
import org.nl.common.exception.BadRequestException;
import org.nl.wms.pm_manage.demand.service.impl.PlatingBufferService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.core.tasks.PlatingTransferTask;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@RestController
@RequestMapping("/api/pda/platingBuffer")
public class PdaPlatingBufferController {
@Resource private PlatingBufferService service;
@Resource private PlatingTransferTask transfer;
@Resource private ISchBaseTaskService tasks;
private ResponseEntity<Object> ok(Object value) { return ResponseData.build(value, HttpStatus.OK); }
@PostMapping("/bind") public ResponseEntity<Object> bind(@RequestBody JSONObject p) { service.bind(p); return ok("绑定成功"); }
@PostMapping("/fetch") public ResponseEntity<Object> fetch(@RequestBody JSONObject p) { return ok(service.fetch(p)); }
@PostMapping("/ignore") public ResponseEntity<Object> ignore(@RequestBody JSONObject p) { service.ignore(p); return ok("已排除非本仓物料"); }
@GetMapping("/source") public ResponseEntity<Object> source(@RequestParam String pallet) { return ok(service.source(pallet)); }
@PostMapping("/pick") public ResponseEntity<Object> pick(@RequestBody JSONObject p) { service.pick(p); return ok("换托成功"); }
@PostMapping("/putB") public ResponseEntity<Object> putB(@RequestBody JSONObject p) { return ok(service.put(p, true)); }
@PostMapping("/return") public ResponseEntity<Object> returnA(@RequestBody JSONObject p) { return ok(service.put(p, false)); }
@PostMapping("/empty") public ResponseEntity<Object> empty(@RequestBody JSONObject p) { service.removeEmpty(p); return ok("空托已移走"); }
@GetMapping("/tasks") public ResponseEntity<Object> list(@RequestParam(required = false) String search,
@RequestParam(defaultValue = "false") boolean history) { return ok(service.taskList(search, history)); }
@PostMapping("/finish") public ResponseEntity<Object> finish(@RequestBody JSONObject p) {
transfer.manualFinish(p.getString("taskCode"), p.getString("palletCode"), p.getString("structCode"), p.getBooleanValue("acsStopped"));
return ok("任务已完成");
}
@PostMapping("/cancel") public ResponseEntity<Object> cancel(@RequestBody JSONObject p) {
transfer.manualCancel(p.getString("taskCode"), p.getString("palletCode"), p.getString("structCode"), p.getBooleanValue("acsStopped"));
return ok("任务已取消");
}
}

View File

@@ -44,7 +44,7 @@ public class PdaPlatingDemandController {
@PostMapping("/allocate")
@Log("PDA按上料口完成配盘预分配")
public ResponseEntity<Object> allocate(@RequestBody PlatingDemandCompleteParam param) {
return ResponseData.build(workflow.allocate(param), HttpStatus.OK);
throw new org.nl.common.exception.BadRequestException("请使用配盘缓存区取料与换托功能");
}
@GetMapping

View File

@@ -0,0 +1,258 @@
package org.nl.wms.pm_manage.demand.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.nl.common.domain.constant.RegionConstant;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.IdUtil;
import org.nl.wms.basedata_manage.service.IStructattrService;
import org.nl.wms.basedata_manage.service.dao.Structattr;
import org.nl.wms.basedata_manage.service.dto.*;
import org.nl.wms.pm_manage.demand.service.dao.*;
import org.nl.wms.pm_manage.demand.service.dao.mapper.*;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.sch_manage.service.core.tasks.PlatingTransferTask;
import org.nl.wms.warehouse_manage.enums.IOSEnum;
import org.nl.wms.warehouse_manage.service.IMdPbGroupplateService;
import org.nl.wms.warehouse_manage.service.dao.GroupPlate;
import org.nl.wms.warehouse_manage.record.service.IStIvtStructivtflowService;
import org.nl.wms.warehouse_manage.record.service.dao.StIvtStructivtflow;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/** EA2整托取料、EB1实际换托、EB2入库;搬运直接使用调度任务台账。 */
@Service
public class PlatingBufferService {
public static final String BUFFER_SOURCE = "PLATING_BUFFER";
@Resource private IStructattrService structs;
@Resource private IMdPbGroupplateService groups;
@Resource private PlatingWorkflowService workflow;
@Resource private PlatingTransferTask transfer;
@Resource private ISchBaseTaskService tasks;
@Resource private PmPlatingDemandMapper demands;
@Resource private PmPlatingDemandItemMapper items;
@Resource private PlatingAllocationMapper allocations;
@Resource private IStIvtStructivtflowService flows;
@Resource private org.nl.wms.basedata_manage.service.IMdPbStoragevehicleinfoService vehicles;
// 固定顺序锁定配盘库位,串行化空位分配、扫码绑定与换托,避免重复占位。
private void lockLocations() {
structs.list(new LambdaQueryWrapper<Structattr>().in(Structattr::getSect_code,
Arrays.asList(RegionConstant.EA2, RegionConstant.EB1, RegionConstant.EB2))
.orderByAsc(Structattr::getStruct_code).last("for update"));
}
private String text(JSONObject p, String key) {
String s = p.getString(key);
if (s == null || s.trim().isEmpty()) throw new BadRequestException("缺少参数:" + key);
return s.trim();
}
private BigDecimal zero(BigDecimal n) { return n == null ? BigDecimal.ZERO : n; }
private Structattr location(String pallet) {
List<Structattr> rows = structs.list(new LambdaQueryWrapper<Structattr>().eq(Structattr::getStoragevehicle_code, pallet));
if (rows.size() != 1) throw new BadRequestException("托盘必须唯一绑定库位:" + pallet);
Structattr s = rows.get(0); available(s); return s;
}
private void available(Structattr s) {
if (s == null || !Boolean.TRUE.equals(s.getIs_used()) || !IOSEnum.LOCK_TYPE.code("未锁定").equals(s.getLock_type()))
throw new BadRequestException("库位未启用或已有任务占用");
}
private List<GroupPlate> stock(String pallet) {
return groups.list(new LambdaQueryWrapper<GroupPlate>().eq(GroupPlate::getStoragevehicle_code, pallet)
.gt(GroupPlate::getQty, BigDecimal.ZERO).orderByAsc(GroupPlate::getGroup_id).last("for update"));
}
private Structattr empty(String area, Structattr from, String pallet) {
StrategyStructParam p = new StrategyStructParam(); p.setSect_code(area); p.setStoragevehicle_code(pallet);
p.setStrategyMaters(stock(pallet).stream().map(g -> {
StrategyMater m = new StrategyMater(); m.setMaterial_code(g.getMaterial_code()); m.setQty(g.getQty());
m.setPcsn(g.getPcsn()); m.setQty_unit_id(g.getQty_unit_id()); return m;
}).collect(Collectors.toList()));
return structs.inBoundSectDiv(p).stream().filter(s -> from.getStor_code().equals(s.getStor_code())
&& (s.getStoragevehicle_code() == null || s.getStoragevehicle_code().isEmpty())
&& IOSEnum.LOCK_TYPE.code("未锁定").equals(s.getLock_type())).findFirst()
.orElseThrow(() -> new BadRequestException(area + "无可用空货位"));
}
private String move(Structattr from, String area, String kind, String port) {
String pallet = from.getStoragevehicle_code();
Structattr to = empty(area, from, pallet);
JSONObject p = new JSONObject(); p.put("point_code1", from.getStruct_code()); p.put("point_code2", to.getStruct_code());
p.put("vehicle_code", pallet); p.put("kind", kind); p.put("loadPort", port); p.put("Priority", "1");
return transfer.create(p);
}
@Transactional(rollbackFor = Exception.class)
public void bind(JSONObject p) {
lockLocations();
String pallet = text(p, "palletCode"), code = text(p, "structCode");
Structattr s = structs.getByCode(code); available(s);
if (!RegionConstant.EB1.equals(s.getSect_code())) throw new BadRequestException("目标托盘必须放在EB1配盘缓存区");
if (s.getStoragevehicle_code() != null && !s.getStoragevehicle_code().isEmpty() && !pallet.equals(s.getStoragevehicle_code()))
throw new BadRequestException("目标库位已被其他托盘占用");
List<Structattr> bound = structs.list(new LambdaQueryWrapper<Structattr>().eq(Structattr::getStoragevehicle_code, pallet));
if (!bound.isEmpty() && (bound.size() != 1 || !code.equals(bound.get(0).getStruct_code()))) throw new BadRequestException("托盘已绑定其他库位");
if (bound.isEmpty() && !stock(pallet).isEmpty()) throw new BadRequestException("请使用空目标托盘");
if (stock(pallet).stream().anyMatch(g -> !PlatingWorkflowService.SOURCE_TYPE.equals(g.getExt_type())))
throw new BadRequestException("原料托盘不能作为配盘目标托盘");
vehicles.chackAndInsert(pallet);
structs.update(new LambdaUpdateWrapper<Structattr>().eq(Structattr::getStruct_id, s.getStruct_id())
.set(Structattr::getStoragevehicle_code, pallet).set(Structattr::getStoragevehicle_qty, 1));
}
@Transactional(rollbackFor = Exception.class)
public void ignore(JSONObject p) {
lockLocations();
Structattr target = location(text(p, "palletCode"));
if (!RegionConstant.EB1.equals(target.getSect_code())) throw new BadRequestException("请先绑定缓存区目标托盘");
List<PmPlatingDemandItem> rows = workflow.byPort(text(p, "loadPort"), true).stream()
.flatMap(d -> workflow.demandItems(d.getId()).stream()).filter(i -> text(p, "materialCode").equals(i.getMaterial_code()))
.collect(Collectors.toList());
if (rows.isEmpty() || rows.stream().anyMatch(i -> i.getWarehouse_code() == null || i.getWarehouse_code().isEmpty()
|| target.getStor_code().equals(i.getWarehouse_code())))
throw new BadRequestException("只有明确属于其他仓库的物料才能忽略;本仓缺料不能忽略");
for (PmPlatingDemandItem i : rows) { i.setIs_ignored(1); items.updateById(i); }
}
@Transactional(rollbackFor = Exception.class)
public List<String> fetch(JSONObject p) {
lockLocations();
String port = text(p, "loadPort");
String batch = text(p, "requestId");
if (batch.length() > 40) throw new BadRequestException("请求号过长");
List<SchBaseTask> previous = tasks.list(new LambdaQueryWrapper<SchBaseTask>()
.eq(SchBaseTask::getConfig_code, "PlatingTransferTask").eq(SchBaseTask::getExt_group_data, batch));
if (!previous.isEmpty()) return previous.stream().map(SchBaseTask::getTask_id).collect(Collectors.toList());
Structattr target = location(text(p, "palletCode"));
if (!RegionConstant.EB1.equals(target.getSect_code()) || !target.getStruct_code().equals(text(p, "structCode")))
throw new BadRequestException("请先扫描绑定目标托盘及EB1库位");
List<PmPlatingDemand> pending = workflow.byPort(port, true);
Set<String> valid = pending.stream().flatMap(d -> workflow.demandItems(d.getId()).stream())
.filter(i -> !Objects.equals(i.getIs_ignored(), 1) && (i.getWarehouse_code() == null || i.getWarehouse_code().isEmpty()
|| target.getStor_code().equals(i.getWarehouse_code())))
.map(PmPlatingDemandItem::getMaterial_code).collect(Collectors.toSet());
if (p.getJSONArray("items") == null || p.getJSONArray("items").isEmpty()) throw new BadRequestException("请填写取料数量");
Map<String, Structattr> sources = new LinkedHashMap<>();
Set<String> seen = new HashSet<>();
for (Object obj : p.getJSONArray("items")) {
JSONObject row = (JSONObject) obj; String material = text(row, "materialCode"); BigDecimal qty = row.getBigDecimal("qty");
if (qty == null || qty.signum() <= 0 || qty.scale() > 8 || !valid.contains(material) || !seen.add(material))
throw new BadRequestException("取料物料或数量无效");
StrategyMater m = new StrategyMater(); m.setMaterial_code(material); m.setQty(qty);
StrategyStructParam param = new StrategyStructParam(); param.setSect_code(RegionConstant.EA2);
param.setStrategyMaters(Collections.singletonList(m));
BigDecimal found = BigDecimal.ZERO;
for (StrategyStructMaterialVO v : structs.outBoundSectDiv(param)) {
if (!material.equals(v.getMaterial_code())) continue;
Structattr s = location(v.getStoragevehicle_code());
if (!RegionConstant.EA2.equals(s.getSect_code()) || !target.getStor_code().equals(s.getStor_code())) throw new BadRequestException("原料必须来自同仓库EA2");
List<GroupPlate> full = stock(v.getStoragevehicle_code());
if (full.stream().anyMatch(g -> zero(g.getFrozen_qty()).signum() != 0)) throw new BadRequestException("原料整托已有库存预占,请重新分配");
GroupPlate g = full.stream().filter(a -> a.getGroup_id().equals(v.getGroup_id())).findFirst()
.orElseThrow(() -> new BadRequestException("分配库存已变化"));
if (!IOSEnum.GROUP_PLATE_STATUS.code("入库").equals(g.getStatus())) throw new BadRequestException("原料尚未入库");
found = found.add(g.getQty()); sources.put(s.getStruct_code(), s);
if (found.compareTo(qty) >= 0) break;
}
if (found.compareTo(qty) < 0) throw new BadRequestException("A区原料库存不足:" + material);
}
List<String> ids = new ArrayList<>();
for (Structattr s : sources.values()) {
String id = move(s, RegionConstant.EB1, "FETCH", port); ids.add(id);
tasks.update(new LambdaUpdateWrapper<SchBaseTask>().eq(SchBaseTask::getTask_id, id).set(SchBaseTask::getExt_group_data, batch));
}
return ids;
}
@Transactional(rollbackFor = Exception.class)
public List<GroupPlate> source(String pallet) {
lockLocations(); Structattr s = location(pallet);
if (!RegionConstant.EB1.equals(s.getSect_code())) throw new BadRequestException("原料尚未到达EB1");
return stock(pallet);
}
@Transactional(rollbackFor = Exception.class)
public void pick(JSONObject p) {
lockLocations();
String requestId = text(p, "requestId"), port = text(p, "loadPort"), pallet = text(p, "palletCode");
if (requestId.length() > 40) throw new BadRequestException("请求号过长");
if (flows.count(new LambdaQueryWrapper<StIvtStructivtflow>().eq(StIvtStructivtflow::getSource_form_id, requestId)) > 0) return;
Structattr to = location(pallet), from = location(text(p, "sourcePallet"));
if (!RegionConstant.EB1.equals(to.getSect_code()) || !RegionConstant.EB1.equals(from.getSect_code())
|| !text(p, "structCode").equals(to.getStruct_code()) || !to.getStor_code().equals(from.getStor_code())
|| pallet.equals(from.getStoragevehicle_code())) throw new BadRequestException("请核对缓存区原料托盘及目标托盘库位");
GroupPlate original = stock(from.getStoragevehicle_code()).stream().filter(g -> g.getGroup_id().equals(text(p, "groupId")))
.findFirst().orElseThrow(() -> new BadRequestException("原料批次不存在"));
BigDecimal qty = p.getBigDecimal("qty");
if (qty == null || qty.signum() <= 0 || qty.scale() > 8 || qty.compareTo(original.getQty().subtract(zero(original.getFrozen_qty()))) > 0
|| PlatingWorkflowService.SOURCE_TYPE.equals(original.getExt_type()) || !IOSEnum.GROUP_PLATE_STATUS.code("入库").equals(original.getStatus()))
throw new BadRequestException("原料状态或换托数量无效");
if (stock(pallet).stream().anyMatch(g -> !PlatingWorkflowService.SOURCE_TYPE.equals(g.getExt_type()) || !port.equals(g.getLoad_port())))
throw new BadRequestException("目标托盘已有其他用途或上料口的物料");
List<PmPlatingDemand> pending = workflow.byPort(port, true);
List<PmPlatingDemandItem> rows = pending.stream().flatMap(d -> workflow.demandItems(d.getId()).stream())
.filter(i -> original.getMaterial_code().equals(i.getMaterial_code()) && !Objects.equals(i.getIs_ignored(), 1)
&& (i.getWarehouse_code() == null || i.getWarehouse_code().isEmpty() || to.getStor_code().equals(i.getWarehouse_code())))
.collect(Collectors.toList());
if (rows.isEmpty()) throw new BadRequestException("物料无有效需求");
BigDecimal left = qty;
for (int n = 0; n < rows.size() && left.signum() > 0; n++) {
PmPlatingDemandItem item = rows.get(n);
BigDecimal take = n == rows.size() - 1 ? left : item.getDemand_qty().subtract(zero(item.getAllocated_qty())).max(BigDecimal.ZERO).min(left);
if (take.signum() == 0) continue;
PmPlatingDemand d = pending.stream().filter(a -> a.getId().equals(item.getDemand_id())).findFirst().get();
PlatingAllocation a = new PlatingAllocation(); a.setId(IdUtil.getStringId()); a.setDemand_id(d.getId()); a.setItem_id(item.getId());
a.setPallet_code(pallet); a.setWarehouse_code(to.getStor_code()); a.setOutbound_id(BUFFER_SOURCE); a.setQty(take); a.setDelivered(0); allocations.insert(a);
GroupPlate target = GroupPlate.builder().group_id(IdUtil.getStringId()).storagevehicle_code(pallet).material_code(original.getMaterial_code())
.pcsn(original.getPcsn()).qty(take).frozen_qty(BigDecimal.ZERO).qty_unit_id(original.getQty_unit_id()).qty_unit_name(original.getQty_unit_name())
.status(original.getStatus()).ext_type(PlatingWorkflowService.SOURCE_TYPE).ext_code(d.getDemand_code()).ext_dtl_code(a.getId())
.load_port(port).create_time(DateUtil.now()).build();
groups.save(target); record(target, to, take, true, requestId);
item.setAllocated_qty(zero(item.getAllocated_qty()).add(take)); items.updateById(item);
d.setStatus(1); demands.updateById(d); left = left.subtract(take);
}
original.setQty(original.getQty().subtract(qty)); groups.updateById(original);
record(original, from, qty, false, requestId);
for (PmPlatingDemand d : pending) workflow.refreshStatus(d);
}
private void record(GroupPlate g, Structattr s, BigDecimal qty, boolean growth, String request) {
StIvtStructivtflow f = new StIvtStructivtflow(); f.setId(IdUtil.getStringId()); f.setUpdate_time(DateUtil.now());
f.setVehicle_code(g.getStoragevehicle_code()); f.setMaterial_id(g.getMaterial_code()); f.setPcsn(g.getPcsn());
f.setQty(g.getQty()); f.setChange_qty(qty); f.setFrozen_qty(zero(g.getFrozen_qty())); f.setGrowth(growth);
f.setStruct_code(s.getStruct_code()); f.setSect_code(s.getSect_code()); f.setStor_code(s.getStor_code());
f.setSource_form_id(request); f.setTask_type("配盘换托"); f.setUnit_id(g.getQty_unit_id()); flows.save(f);
}
@Transactional(rollbackFor = Exception.class)
public String put(JSONObject p, boolean finished) {
lockLocations(); Structattr s = location(text(p, "palletCode"));
if (!RegionConstant.EB1.equals(s.getSect_code())) throw new BadRequestException("托盘不在配盘缓存区");
List<GroupPlate> list = stock(s.getStoragevehicle_code());
if (list.isEmpty()) throw new BadRequestException("托盘无物料,请使用空托移走");
if (list.stream().anyMatch(g -> zero(g.getFrozen_qty()).signum() > 0 || finished != PlatingWorkflowService.SOURCE_TYPE.equals(g.getExt_type())))
throw new BadRequestException("托盘物料用途不匹配或已被冻结");
return move(s, finished ? RegionConstant.EB2 : RegionConstant.EA2, finished ? "PUT_B" : "RETURN", list.get(0).getLoad_port());
}
@Transactional(rollbackFor = Exception.class)
public void removeEmpty(JSONObject p) {
lockLocations(); Structattr s = location(text(p, "palletCode"));
if (!RegionConstant.EB1.equals(s.getSect_code()) || !s.getStruct_code().equals(text(p, "structCode")) || !stock(s.getStoragevehicle_code()).isEmpty())
throw new BadRequestException("请确认空托盘和EB1库位");
groups.remove(new LambdaQueryWrapper<GroupPlate>().eq(GroupPlate::getStoragevehicle_code, s.getStoragevehicle_code()).eq(GroupPlate::getQty, BigDecimal.ZERO));
structs.update(new LambdaUpdateWrapper<Structattr>().eq(Structattr::getStruct_id, s.getStruct_id())
.set(Structattr::getStoragevehicle_code, null).set(Structattr::getStoragevehicle_qty, 0));
}
public List<SchBaseTask> taskList(String search, boolean history) {
LambdaQueryWrapper<SchBaseTask> q = new LambdaQueryWrapper<SchBaseTask>().eq(SchBaseTask::getConfig_code, "PlatingTransferTask");
if (!history) q.notIn(SchBaseTask::getTask_status, Arrays.asList("5", "6"));
if (search != null && !search.trim().isEmpty()) q.and(w -> w.like(SchBaseTask::getTask_code, search.trim()).or().like(SchBaseTask::getVehicle_code, search.trim()));
return tasks.list(q.orderByDesc(SchBaseTask::getCreate_time).last("limit 200"));
}
}

View File

@@ -187,7 +187,7 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
@Override
public List<PlatingDemandDto> unfinished() {
return demandMapper.selectList(new LambdaQueryWrapper<PmPlatingDemand>().lt(PmPlatingDemand::getStatus, 2)
return demandMapper.selectList(new LambdaQueryWrapper<PmPlatingDemand>().in(PmPlatingDemand::getStatus, java.util.Arrays.asList(0, 1, 3))
.orderByAsc(PmPlatingDemand::getLoad_port)
.orderByAsc(PmPlatingDemand::getCreate_time)).stream().map(this::toDto).collect(Collectors.toList());
}

View File

@@ -97,7 +97,7 @@ public class PlatingWorkflowService {
public List<PmPlatingDemand> byPort(String port, boolean lock) {
final String code = text(port, "请扫描上料口");
LambdaQueryWrapper<PmPlatingDemand> query = new LambdaQueryWrapper<PmPlatingDemand>()
.lt(PmPlatingDemand::getStatus, 2)
.in(PmPlatingDemand::getStatus, Arrays.asList(0, 1, 3))
.and(q -> q.eq(PmPlatingDemand::getLoad_port, code)
.or().likeRight(PmPlatingDemand::getLoad_port, code + ":"))
.orderByAsc(PmPlatingDemand::getCreate_time).orderByAsc(PmPlatingDemand::getId);
@@ -272,7 +272,8 @@ public class PlatingWorkflowService {
allocation = allocations.selectOne(new LambdaQueryWrapper<PlatingAllocation>().eq(PlatingAllocation::getId, allocation.getId()).last("for update"));
if (allocation.getDelivered() == 1) continue;
IOStorInv bill = bills.selectById(allocation.getOutbound_id());
if (bill == null || !IOSEnum.BILL_STATUS.code("完成").equals(bill.getBill_status())) throw new BadRequestException("原料尚未完成出库");
if (!PlatingBufferService.BUFFER_SOURCE.equals(allocation.getOutbound_id())
&& (bill == null || !IOSEnum.BILL_STATUS.code("完成").equals(bill.getBill_status()))) throw new BadRequestException("原料尚未完成出库");
PmPlatingDemandItem item = items.selectById(allocation.getItem_id());
BigDecimal qty = allocation.getQty();
BigDecimal onPallet = groups.list(new LambdaQueryWrapper<GroupPlate>().eq(GroupPlate::getStoragevehicle_code, pallet)
@@ -326,11 +327,12 @@ public class PlatingWorkflowService {
.eq(PlatingAllocation::getDelivered, 0).orderByAsc(PlatingAllocation::getId));
}
private void refreshStatus(PmPlatingDemand demand) {
public void refreshStatus(PmPlatingDemand demand) {
List<PmPlatingDemandItem> rows = demandItems(demand.getId());
boolean finished = !rows.isEmpty() && rows.stream().allMatch(i -> zero(i.getOutbound_qty()).compareTo(
Objects.equals(i.getIs_ignored(), 1) ? zero(i.getAllocated_qty()) : i.getDemand_qty().max(zero(i.getAllocated_qty()))) >= 0);
demand.setStatus(finished ? 2 : rows.stream().anyMatch(i -> zero(i.getAllocated_qty()).signum() > 0 || Objects.equals(i.getIs_ignored(), 1)) ? 1 : 0);
i.getDemand_qty().max(zero(i.getAllocated_qty()))) >= 0);
boolean plated = !rows.isEmpty() && rows.stream().allMatch(i -> zero(i.getAllocated_qty()).compareTo(i.getDemand_qty()) >= 0);
demand.setStatus(finished ? 2 : plated ? 3 : rows.stream().anyMatch(i -> zero(i.getAllocated_qty()).signum() > 0 || Objects.equals(i.getIs_ignored(), 1)) ? 1 : 0);
if (finished) demand.setFinish_time(DateUtil.now());
demands.updateById(demand);
}

View File

@@ -29,6 +29,7 @@ public class PlatingDeliveryTask extends Point2PointTask {
@Resource private org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDtlMapper inboundDetails;
@Resource private org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvMapper inboundBills;
@Resource private org.nl.wms.basedata_manage.service.IStructattrService structs;
@Resource private org.nl.wms.warehouse_manage.record.service.IStIvtStructivtflowService flows;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -66,6 +67,12 @@ public class PlatingDeliveryTask extends Point2PointTask {
if (qty.compareTo(allocation.getQty()) != 0) throw new BadRequestException("本托配盘物料尚未全部入库");
}
for (GroupPlate plate : plates) {
if (pending.stream().anyMatch(a -> a.getId().equals(plate.getExt_dtl_code())
&& org.nl.wms.pm_manage.demand.service.impl.PlatingBufferService.BUFFER_SOURCE.equals(a.getOutbound_id()))) {
if (!org.nl.common.domain.constant.RegionConstant.EB2.equals(start.getSect_code()))
throw new BadRequestException("配盘托盘尚未到达EB2");
continue;
}
boolean finished = inboundDetails.selectList(new LambdaQueryWrapper<org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDtl>()
.eq(org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDtl::getSource_billdtl_id, plate.getExt_dtl_code()))
.stream().anyMatch(d -> {
@@ -118,6 +125,15 @@ public class PlatingDeliveryTask extends Point2PointTask {
List<String> ids = JSONObject.parseObject(task.getRequest_param()).getJSONArray("groupIds").toJavaList(String.class);
if (ids.isEmpty()) throw new BadRequestException("配送任务缺少组盘数据");
workflow.deliveryFinished(task.getVehicle_code(), task.getPoint_code2());
Structattr origin = structs.getByCode(task.getPoint_code1());
for (GroupPlate g : groups.list(new LambdaQueryWrapper<GroupPlate>().in(GroupPlate::getGroup_id, ids))) {
org.nl.wms.warehouse_manage.record.service.dao.StIvtStructivtflow f = new org.nl.wms.warehouse_manage.record.service.dao.StIvtStructivtflow();
f.setId(org.nl.common.utils.IdUtil.getStringId()); f.setUpdate_time(cn.hutool.core.date.DateUtil.now());
f.setVehicle_code(g.getStoragevehicle_code()); f.setMaterial_id(g.getMaterial_code()); f.setPcsn(g.getPcsn());
f.setQty(java.math.BigDecimal.ZERO); f.setChange_qty(g.getQty()); f.setGrowth(false);
f.setStruct_code(origin.getStruct_code()); f.setSect_code(origin.getSect_code()); f.setStor_code(origin.getStor_code());
f.setSource_form_id(task.getTask_id()); f.setTask_type("配盘领料出库"); f.setUnit_id(g.getQty_unit_id()); flows.save(f);
}
releaseStart(task, true);
SchBasePoint end = points.getOne(new LambdaQueryWrapper<SchBasePoint>()
.eq(SchBasePoint::getPoint_code, task.getPoint_code2()).last("for update"));

View File

@@ -0,0 +1,137 @@
package org.nl.wms.sch_manage.service.core.tasks;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.wms.basedata_manage.service.IStructattrService;
import org.nl.wms.basedata_manage.service.dao.Structattr;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.core.TaskType;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.warehouse_manage.enums.IOSEnum;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.http.ResponseEntity;
import javax.annotation.Resource;
import java.util.Arrays;
/** 配盘三类整托移库共用现有调度任务,不改变组盘数量和状态。 */
@Component("PlatingTransferTask")
@TaskType("PlatingTransferTask")
public class PlatingTransferTask extends Point2PointTask {
@Resource private ISchBaseTaskService tasks;
@Resource private IStructattrService structs;
private Structattr location(String code) {
Structattr s = structs.getOne(new LambdaQueryWrapper<Structattr>().eq(Structattr::getStruct_code, code).last("for update"));
if (s == null || !Boolean.TRUE.equals(s.getIs_used())) throw new BadRequestException("库位不存在或未启用:" + code);
return s;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String create(JSONObject json) {
Structattr from = location(json.getString("point_code1")), to = location(json.getString("point_code2"));
String pallet = json.getString("vehicle_code");
if (pallet == null || !pallet.equals(from.getStoragevehicle_code()) || from.getStruct_code().equals(to.getStruct_code())
|| !from.getStor_code().equals(to.getStor_code()) || !free(from) || !free(to)
|| (to.getStoragevehicle_code() != null && !to.getStoragevehicle_code().isEmpty()))
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("托盘已有未完成任务");
json.put("config_code", "PlatingTransferTask");
String id = super.create(json);
SchBaseTask task = tasks.getById(id);
task.setIs_delete(false); tasks.updateById(task);
lockLocation(from, task.getTask_code(), "出库锁");
lockLocation(to, task.getTask_code(), "入库锁");
return id;
}
private boolean free(Structattr s) { return IOSEnum.LOCK_TYPE.code("未锁定").equals(s.getLock_type()); }
private void lockLocation(Structattr s, String code, String type) {
structs.update(new LambdaUpdateWrapper<Structattr>().eq(Structattr::getStruct_id, s.getStruct_id())
.set(Structattr::getTask_code, code).set(Structattr::getLock_type, IOSEnum.LOCK_TYPE.code(type)));
}
private SchBaseTask lock(String code) {
SchBaseTask t = tasks.getOne(new LambdaQueryWrapper<SchBaseTask>().eq(SchBaseTask::getTask_code, code)
.eq(SchBaseTask::getConfig_code, "PlatingTransferTask").last("for update"));
if (t == null) throw new BadRequestException("配盘搬运任务不存在");
return t;
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResponseEntity sendTaskOne(String id) {
SchBaseTask t = tasks.getById(id);
t = lock(t.getTask_code());
if (!TaskStatus.CREATE.getCode().equals(t.getTask_status())) return ResponseEntity.ok().build();
return super.sendTaskOne(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTaskStatus(String code, TaskStatus status) {
SchBaseTask t = lock(code);
if (Arrays.asList("5", "6").contains(t.getTask_status())) return;
super.updateTaskStatus(code, status);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void forceFinish(String code) { finishTask(lock(code)); }
@Transactional(rollbackFor = Exception.class)
public void manualFinish(String code, String pallet, String destination, boolean stopped) {
SchBaseTask t = lock(code);
if (!t.getVehicle_code().equals(pallet) || !t.getPoint_code2().equals(destination))
throw new BadRequestException("请扫描任务托盘和目标库位");
if (!TaskStatus.CREATE.getCode().equals(t.getTask_status()) && !stopped)
throw new BadRequestException("请确认ACS任务已结束或已停止");
finishTask(t);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void cancel(String code) {
// 现场撤回确认由专用PDA接口完成;通用取消仍遵循未下发限制。
lock(code); super.cancel(code);
}
@Transactional(rollbackFor = Exception.class)
public void manualCancel(String code, String pallet, String source, boolean stopped) {
SchBaseTask t = lock(code);
if (!t.getVehicle_code().equals(pallet) || !t.getPoint_code1().equals(source))
throw new BadRequestException("请扫描任务托盘和原始库位,确认实物已撤回");
if (!TaskStatus.CREATE.getCode().equals(t.getTask_status()) && !stopped)
throw new BadRequestException("请先在ACS停止任务并确认托盘已回原位");
cancelTask(t);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void finishTask(SchBaseTask input) { settle(lock(input.getTask_code()), true); }
@Override
@Transactional(rollbackFor = Exception.class)
public void cancelTask(SchBaseTask input) { settle(lock(input.getTask_code()), false); }
private void settle(SchBaseTask t, boolean finish) {
String targetStatus = finish ? "5" : "6";
if (targetStatus.equals(t.getTask_status())) return;
if (Arrays.asList("5", "6").contains(t.getTask_status())) throw new BadRequestException("任务已结束");
Structattr from = location(t.getPoint_code1()), to = location(t.getPoint_code2());
if (!t.getVehicle_code().equals(from.getStoragevehicle_code()) || !t.getTask_code().equals(from.getTask_code())
|| !t.getTask_code().equals(to.getTask_code()) || (to.getStoragevehicle_code() != null && !to.getStoragevehicle_code().isEmpty()))
throw new BadRequestException("搬运库位绑定或占用发生变化");
for (Structattr s : Arrays.asList(from, to)) {
LambdaUpdateWrapper<Structattr> u = new LambdaUpdateWrapper<Structattr>().eq(Structattr::getStruct_id, s.getStruct_id())
.set(Structattr::getTask_code, null).set(Structattr::getLock_type, IOSEnum.LOCK_TYPE.code("未锁定"));
if (finish) u.set(Structattr::getStoragevehicle_code, s == from ? null : t.getVehicle_code())
.set(Structattr::getStoragevehicle_qty, s == from ? 0 : 1);
structs.update(u);
}
t.setTask_status(targetStatus); t.setRemark(finish ? "已完成" : "已取消(实物在源位)"); tasks.updateById(t);
}
}