opt:配盘直送,配盘出库调整修改,不关联工单,调拨到线边
This commit is contained in:
@@ -11,13 +11,11 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.nl.common.utils.ValidationUtil.assertNotBlankJson;
|
||||
|
||||
/**
|
||||
* 手持配盘直送管理
|
||||
* 组盘状态的托盘不入库直接配送至产线上料口区域
|
||||
* 组盘状态的托盘不入库,直接调拨出库到产线上料口
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -28,39 +26,25 @@ public class PdaDirectDeliveryController {
|
||||
|
||||
private final PdaDirectDeliveryService directDeliveryService;
|
||||
|
||||
@GetMapping("/regions")
|
||||
@Log("PDA直送-产线区域列表")
|
||||
@GetMapping("/sects")
|
||||
@Log("PDA直送-源库区列表")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> regions() {
|
||||
return ResponseData.build(directDeliveryService.listRegions(), HttpStatus.OK);
|
||||
public ResponseEntity<Object> sects() {
|
||||
return ResponseData.build(directDeliveryService.listSects(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/pallet")
|
||||
@Log("PDA直送-扫描托盘获取上料口与候选工单")
|
||||
@Log("PDA直送-扫描托盘获取上料口与物料")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> pallet(@RequestParam String vehicleCode) {
|
||||
return ResponseData.build(directDeliveryService.getPalletInfo(vehicleCode), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/workOrders")
|
||||
@Log("PDA直送-产线+上料口可直送工单")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> workOrders(@RequestParam String regionCode, @RequestParam String loadPort) {
|
||||
return ResponseData.build(directDeliveryService.listWorkOrders(regionCode, loadPort), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/bomMaterials")
|
||||
@Log("PDA直送-上料口BOM物料")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> bomMaterials(@RequestParam String loadPort, @RequestParam List<String> workOrders) {
|
||||
return ResponseData.build(directDeliveryService.listBomMaterials(loadPort, workOrders), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/deliver")
|
||||
@Log("PDA直送-提交配盘直送")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> deliver(@RequestBody JSONObject whereJson) {
|
||||
assertNotBlankJson(whereJson, "请求参数不能为空", "load_port", "vehicle_code");
|
||||
assertNotBlankJson(whereJson, "请求参数不能为空", "vehicle_code", "sect_code");
|
||||
return ResponseData.build(directDeliveryService.deliver(whereJson), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,44 +5,37 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 手持配盘直送服务
|
||||
* 手持配盘直送服务:组盘状态的托盘不入库,直接调拨出库到产线上料口
|
||||
*/
|
||||
public interface PdaDirectDeliveryService {
|
||||
|
||||
/**
|
||||
* 产线(区域)列表
|
||||
* 源库区列表(决定调出仓库)
|
||||
*/
|
||||
List<JSONObject> listRegions();
|
||||
List<JSONObject> listSects();
|
||||
|
||||
/**
|
||||
* 按产线+上料口查询可直送工单(work_area=产线,BOM左匹配上料口,最新50条)
|
||||
*/
|
||||
List<JSONObject> listWorkOrders(String regionCode, String loadPort);
|
||||
|
||||
/**
|
||||
* 扫描托盘:依据组盘信息取上料口,并返回该上料口的候选工单与托盘物料
|
||||
* 扫描托盘:依据组盘信息取上料口与托盘物料,并带出托盘当前所在点位
|
||||
*
|
||||
* @param vehicleCode 托盘编码
|
||||
* @return {pallet_code, load_port, port_name, current_point_code, materials[], work_orders[]}
|
||||
* @return {pallet_code, load_port, port_name, region_code, region_name, current_point_code, materials[]}
|
||||
*/
|
||||
JSONObject getPalletInfo(String vehicleCode);
|
||||
|
||||
/**
|
||||
* 按上料口(左匹配)查询所选工单BOM物料汇总
|
||||
*/
|
||||
List<JSONObject> listBomMaterials(String loadPort, List<String> orderCodes);
|
||||
|
||||
/**
|
||||
* 配盘直送确认
|
||||
* 配盘直送确认:生成库存调拨出库单
|
||||
* <ul>
|
||||
* <li>agv_delivery=true:生成点对点配送任务,任务送达完成后出库过账并回传 MM057</li>
|
||||
* <li>agv_delivery=false:提交即出库过账并回传 MM057</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param whereJson {
|
||||
* workOrders:工单号集合
|
||||
* vehicle_code:托盘编码
|
||||
* load_port:上料口(可不传,默认取托盘组盘上料口)
|
||||
* agv_delivery:是否AGV配送
|
||||
* site_code:地面站点(AGV配送时必传,作为任务起点)
|
||||
* vehicle_code:托盘编码(必传),
|
||||
* sect_code:源库区(必传),
|
||||
* agv_delivery:是否AGV配送,
|
||||
* site_code:起始点位(AGV配送时必传)
|
||||
* }
|
||||
* @return {bill_code, task_code, end_point_code}
|
||||
* @return {bill_code, task_code, start_point_code, end_point_code, load_port}
|
||||
*/
|
||||
JSONObject deliver(JSONObject whereJson);
|
||||
}
|
||||
|
||||
@@ -9,40 +9,37 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
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.IMdPbStoragevehicleinfoService;
|
||||
import org.nl.wms.basedata_manage.service.ISectattrService;
|
||||
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.MdPbStoragevehicleinfo;
|
||||
import org.nl.wms.basedata_manage.service.dao.Sectattr;
|
||||
import org.nl.wms.pda_manage.direct_manage.service.PdaDirectDeliveryService;
|
||||
import org.nl.wms.pm_manage.demand.service.IMaterialWarehouseMappingService;
|
||||
import org.nl.wms.pm_manage.delivery.service.impl.PlatingDirectOutSettlement;
|
||||
import org.nl.wms.pm_manage.demand.service.impl.PlatingDemandServiceImpl;
|
||||
import org.nl.wms.sch_manage.enums.TaskEnum;
|
||||
import org.nl.wms.sch_manage.enums.TaskStatus;
|
||||
import org.nl.wms.sch_manage.service.ISchBasePointService;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseRegionService;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch_manage.service.core.tasks.Point2PointTask;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseRegion;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.IOutBillService;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInv;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDtl;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDis;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDtlMapper;
|
||||
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.enums.IOSConstant;
|
||||
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.stockReturn.strategy.CallbackStrategyPublish;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.WorkOrderBomDao;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.WorkOrderDao;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.mapper.WorkOrderBomMapper;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.mapper.WorkOrderMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -54,27 +51,29 @@ import java.util.stream.Collectors;
|
||||
import static org.nl.wms.warehouse_manage.enums.IOSEnum.GROUP_PLATE_STATUS;
|
||||
|
||||
/**
|
||||
* 配盘直送实现:组盘状态托盘不入库直接配送
|
||||
* 出库单走 saveBill,LLCK 回传复用 sapWorkOrderLLCKCallback(SAP PP055),AGV 配送走 Point2PointTask
|
||||
* 配盘直送实现:组盘状态的托盘不入库,直接调拨出库到产线上料口。
|
||||
* <p>
|
||||
* 与生产工单解耦:不再按工单BOM分摊,出库单类型为「库存调拨」,明细回传策略为
|
||||
* {@code sapPlatingDeliveryMM057}(MM057 / 311 转储到线边库 X001,线边库存不由 WMS 维护)。
|
||||
* 生成点对点配送任务(PlatingDirectOutTask),送达完成后结算单据并触发回传。
|
||||
*/
|
||||
@Service
|
||||
public class PdaDirectDeliveryServiceImpl implements PdaDirectDeliveryService {
|
||||
|
||||
private static final String SOURCE_TYPE = "pda_direct_delivery";
|
||||
private static final String CALLBACK_STRATEGY = "sapWorkOrderLLCKCallback";
|
||||
private static final String CALLBACK_STRATEGY = "sapPlatingDeliveryMM057";
|
||||
private static final String TASK_BEAN = "PlatingDirectOutTask";
|
||||
|
||||
@Resource
|
||||
private WorkOrderMapper orders;
|
||||
private ISectattrService iSectattrService;
|
||||
@Resource
|
||||
private WorkOrderBomMapper boms;
|
||||
private IBsrealStorattrService iBsrealStorattrService;
|
||||
@Resource
|
||||
private ISchBaseRegionService iSchBaseRegionService;
|
||||
@Resource
|
||||
private ISchBasePointService iSchBasePointService;
|
||||
@Resource
|
||||
private ISchBaseTaskService iSchBaseTaskService;
|
||||
@Resource(name = "Point2PointTask")
|
||||
private Point2PointTask point2PointTask;
|
||||
@Resource
|
||||
private IMdPbGroupplateService iMdPbGroupplateService;
|
||||
@Resource
|
||||
@@ -82,8 +81,6 @@ public class PdaDirectDeliveryServiceImpl implements PdaDirectDeliveryService {
|
||||
@Resource
|
||||
private IMdPbStoragevehicleinfoService iMdPbStoragevehicleinfoService;
|
||||
@Resource
|
||||
private IBsrealStorattrService iBsrealStorattrService;
|
||||
@Resource
|
||||
private IOutBillService iOutBillService;
|
||||
@Resource
|
||||
private IOStorInvMapper ioStorInvMapper;
|
||||
@@ -92,47 +89,20 @@ public class PdaDirectDeliveryServiceImpl implements PdaDirectDeliveryService {
|
||||
@Resource
|
||||
private IOStorInvDisMapper ioStorInvDisMapper;
|
||||
@Resource
|
||||
private CallbackStrategyPublish callbackStrategyPublish;
|
||||
@Resource
|
||||
private IMaterialWarehouseMappingService iMaterialWarehouseMappingService;
|
||||
private PlatingDirectOutSettlement settlement;
|
||||
|
||||
@Override
|
||||
public List<JSONObject> listRegions() {
|
||||
List<SchBaseRegion> regions = iSchBaseRegionService.list(
|
||||
new LambdaQueryWrapper<SchBaseRegion>().orderByAsc(SchBaseRegion::getOrder_seq));
|
||||
public List<JSONObject> listSects() {
|
||||
List<Sectattr> sects = iSectattrService.list(new LambdaQueryWrapper<Sectattr>()
|
||||
.eq(Sectattr::getIs_delete, "0")
|
||||
.eq(Sectattr::getIs_used, "1")
|
||||
.orderByAsc(Sectattr::getSect_code));
|
||||
List<JSONObject> result = new ArrayList<>();
|
||||
for (SchBaseRegion region : regions) {
|
||||
for (Sectattr sect : sects) {
|
||||
JSONObject row = new JSONObject();
|
||||
row.put("region_code", region.getRegion_code());
|
||||
row.put("region_name", region.getRegion_name());
|
||||
row.put("is_has_workder", region.getIs_has_workder());
|
||||
result.add(row);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> listWorkOrders(String regionCode, String loadPort) {
|
||||
if (StringUtils.isBlank(regionCode)) {
|
||||
throw new BadRequestException("产线编码不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(loadPort)) {
|
||||
throw new BadRequestException("请先扫描上料口");
|
||||
}
|
||||
// 上料口归一化后左匹配BOM:属于该产线且BOM包含该上料口的工单
|
||||
String port = PlatingDemandServiceImpl.parseLoadPort(loadPort);
|
||||
List<WorkOrderDao> list = orders.selectDirectDeliveryOrders(regionCode, port);
|
||||
List<JSONObject> result = new ArrayList<>();
|
||||
for (WorkOrderDao order : list) {
|
||||
JSONObject row = new JSONObject();
|
||||
row.put("order_code", order.getOrder_code());
|
||||
row.put("order_id", order.getOrder_id());
|
||||
row.put("org_code", order.getOrg_code());
|
||||
row.put("product_code", order.getProduct_code());
|
||||
row.put("product_name", order.getProduct_name());
|
||||
row.put("order_qty", order.getOrder_qty());
|
||||
row.put("plan_started_on", order.getPlan_started_on());
|
||||
row.put("status", order.getStatus());
|
||||
row.put("sect_code", sect.getSect_code());
|
||||
row.put("sect_name", sect.getSect_name());
|
||||
row.put("stor_id", sect.getStor_id());
|
||||
result.add(row);
|
||||
}
|
||||
return result;
|
||||
@@ -148,57 +118,18 @@ public class PdaDirectDeliveryServiceImpl implements PdaDirectDeliveryService {
|
||||
if (ObjectUtil.isEmpty(vehicle)) {
|
||||
throw new BadRequestException("不存在该托盘信息,请检查");
|
||||
}
|
||||
List<GroupPlate> plates = iMdPbGroupplateService.list(new LambdaQueryWrapper<GroupPlate>()
|
||||
.eq(GroupPlate::getStoragevehicle_code, palletCode)
|
||||
.eq(GroupPlate::getStatus, GROUP_PLATE_STATUS.code("组盘"))
|
||||
.orderByAsc(GroupPlate::getGroup_id));
|
||||
if (plates.isEmpty()) {
|
||||
throw new BadRequestException("该托盘无组盘物料,无法直送");
|
||||
}
|
||||
// 上料口取自组盘信息,多上料口不允许直送
|
||||
Set<String> ports = plates.stream()
|
||||
.map(plate -> PlatingDemandServiceImpl.parseLoadPort(plate.getLoad_port()))
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (ports.isEmpty()) {
|
||||
throw new BadRequestException("托盘组盘信息缺少上料口,请检查");
|
||||
}
|
||||
if (ports.size() > 1) {
|
||||
throw new BadRequestException("托盘存在多个上料口:" + String.join(",", ports));
|
||||
}
|
||||
String loadPort = ports.iterator().next();
|
||||
List<GroupPlate> plates = listGroupPlates(palletCode, false);
|
||||
String loadPort = resolveLoadPort(plates);
|
||||
SchBasePoint portPoint = iSchBasePointService.getOne(
|
||||
new LambdaQueryWrapper<SchBasePoint>().eq(SchBasePoint::getPoint_code, loadPort));
|
||||
if (ObjectUtil.isEmpty(portPoint)) {
|
||||
throw new BadRequestException("上料口点位不存在:" + loadPort);
|
||||
}
|
||||
// 托盘当前所在点位(仅展示,AGV配送起点以扫描的地面站点为准)
|
||||
SchBaseRegion region = iSchBaseRegionService.getOne(new LambdaQueryWrapper<SchBaseRegion>()
|
||||
.eq(SchBaseRegion::getRegion_code, portPoint.getRegion_code()));
|
||||
// 托盘当前所在点位(配送起点)
|
||||
SchBasePoint current = iSchBasePointService.getOne(
|
||||
new LambdaQueryWrapper<SchBasePoint>().eq(SchBasePoint::getVehicle_code, palletCode));
|
||||
// 候选工单:BOM 左匹配该上料口的工单,状态待执行/执行中
|
||||
List<JSONObject> orderRows = new ArrayList<>();
|
||||
List<String> orderCodes = boms.selectWorkOrderCodesByPort(loadPort);
|
||||
if (!orderCodes.isEmpty()) {
|
||||
List<WorkOrderDao> orderList = orders.selectList(new LambdaQueryWrapper<WorkOrderDao>()
|
||||
.in(WorkOrderDao::getOrder_code, orderCodes)
|
||||
.in(WorkOrderDao::getStatus, Arrays.asList(1, 2))
|
||||
.orderByDesc(WorkOrderDao::getPlan_started_on)
|
||||
.last("limit 50"));
|
||||
for (WorkOrderDao order : orderList) {
|
||||
JSONObject row = new JSONObject();
|
||||
row.put("order_code", order.getOrder_code());
|
||||
row.put("order_id", order.getOrder_id());
|
||||
row.put("org_code", order.getOrg_code());
|
||||
row.put("product_code", order.getProduct_code());
|
||||
row.put("product_name", order.getProduct_name());
|
||||
row.put("order_qty", order.getOrder_qty());
|
||||
row.put("work_area", order.getWork_area());
|
||||
row.put("plan_started_on", order.getPlan_started_on());
|
||||
row.put("status", order.getStatus());
|
||||
orderRows.add(row);
|
||||
}
|
||||
}
|
||||
// 托盘物料明细
|
||||
JSONArray materials = new JSONArray();
|
||||
for (GroupPlate plate : plates) {
|
||||
MdMeMaterialbase material = iMdMeMaterialbaseService.getByCode(plate.getMaterial_code());
|
||||
@@ -215,357 +146,234 @@ public class PdaDirectDeliveryServiceImpl implements PdaDirectDeliveryService {
|
||||
result.put("load_port", loadPort);
|
||||
result.put("port_name", portPoint.getPoint_name());
|
||||
result.put("region_code", portPoint.getRegion_code());
|
||||
result.put("region_name", region == null ? portPoint.getRegion_code() : region.getRegion_name());
|
||||
result.put("current_point_code", current == null ? null : current.getPoint_code());
|
||||
result.put("materials", materials);
|
||||
result.put("work_orders", orderRows);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> listBomMaterials(String loadPort, List<String> orderCodes) {
|
||||
if (orderCodes == null || orderCodes.isEmpty()) {
|
||||
throw new BadRequestException("请先选择工单");
|
||||
}
|
||||
List<WorkOrderBomDao> bomList = selectBomByPort(loadPort, new LinkedHashSet<>(orderCodes));
|
||||
if (bomList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Map<String, WorkOrderDao> orderMap = lockOrders(orderCodes, false);
|
||||
// 按物料汇总需求
|
||||
Map<String, JSONObject> merged = new LinkedHashMap<>();
|
||||
for (WorkOrderBomDao bom : bomList) {
|
||||
WorkOrderDao order = orderMap.get(bom.getWork_order_code());
|
||||
int orderQty = order == null || order.getOrder_qty() == null ? 0 : order.getOrder_qty();
|
||||
BigDecimal need = (bom.getBom_qty() == null ? BigDecimal.ZERO : bom.getBom_qty())
|
||||
.multiply(BigDecimal.valueOf(orderQty));
|
||||
BigDecimal used = bom.getUse_bom_qty() == null ? BigDecimal.ZERO : bom.getUse_bom_qty();
|
||||
JSONObject row = merged.computeIfAbsent(bom.getMaterial_code(), k -> {
|
||||
JSONObject j = new JSONObject();
|
||||
j.put("material_code", k);
|
||||
j.put("material_name", bom.getMaterial_name());
|
||||
j.put("unit", bom.getUnit());
|
||||
j.put("need_qty", BigDecimal.ZERO);
|
||||
j.put("used_qty", BigDecimal.ZERO);
|
||||
j.put("orders", new JSONArray());
|
||||
return j;
|
||||
});
|
||||
row.put("need_qty", row.getBigDecimal("need_qty").add(need));
|
||||
row.put("used_qty", row.getBigDecimal("used_qty").add(used));
|
||||
JSONArray orderArr = row.getJSONArray("orders");
|
||||
if (!orderArr.contains(bom.getWork_order_code())) {
|
||||
orderArr.add(bom.getWork_order_code());
|
||||
}
|
||||
}
|
||||
List<JSONObject> result = new ArrayList<>(merged.values());
|
||||
for (JSONObject row : result) {
|
||||
row.put("remain_qty", row.getBigDecimal("need_qty")
|
||||
.subtract(row.getBigDecimal("used_qty")).max(BigDecimal.ZERO));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject deliver(JSONObject whereJson) {
|
||||
JSONArray orderArr = whereJson.getJSONArray("workOrders");
|
||||
if (orderArr == null || orderArr.isEmpty()) {
|
||||
throw new BadRequestException("请先选择工单");
|
||||
}
|
||||
List<String> orderCodes = orderArr.toJavaList(String.class).stream()
|
||||
.filter(StringUtils::isNotBlank).map(String::trim).distinct().collect(Collectors.toList());
|
||||
if (orderCodes.isEmpty()) {
|
||||
throw new BadRequestException("请先选择工单");
|
||||
}
|
||||
String vehicleCode = StringUtils.trimToNull(whereJson.getString("vehicle_code"));
|
||||
if (vehicleCode == null) {
|
||||
throw new BadRequestException("请扫描托盘码");
|
||||
}
|
||||
boolean agvDelivery = whereJson.getBooleanValue("agv_delivery");
|
||||
String siteCode = StringUtils.trimToNull(whereJson.getString("site_code"));
|
||||
if (agvDelivery && siteCode == null) {
|
||||
throw new BadRequestException("使用AGV配送请扫描地面站点");
|
||||
String sectCode = StringUtils.trimToNull(whereJson.getString("sect_code"));
|
||||
if (sectCode == null) {
|
||||
throw new BadRequestException("请选择源库区");
|
||||
}
|
||||
Sectattr sect = iSectattrService.findByCode(sectCode);
|
||||
if (sect == null) {
|
||||
throw new BadRequestException("源库区不存在:" + sectCode);
|
||||
}
|
||||
BsrealStorattr stor = iBsrealStorattrService.findById(sect.getStor_id());
|
||||
if (stor == null) {
|
||||
throw new BadRequestException("源库区未关联仓库:" + sectCode);
|
||||
}
|
||||
// 校验托盘
|
||||
MdPbStoragevehicleinfo vehicle = iMdPbStoragevehicleinfoService.getByCode(vehicleCode);
|
||||
if (ObjectUtil.isEmpty(vehicle)) {
|
||||
throw new BadRequestException("不存在该托盘信息,请检查");
|
||||
}
|
||||
iMdPbStoragevehicleinfoService.chackAndInsert(vehicleCode);
|
||||
// 防重复任务
|
||||
long activeTaskCount = iSchBaseTaskService.count(new LambdaQueryWrapper<SchBaseTask>()
|
||||
.eq(SchBaseTask::getVehicle_code, vehicleCode)
|
||||
.notIn(SchBaseTask::getTask_status, Arrays.asList(TaskStatus.FINISHED.getCode(), TaskStatus.CANCELED.getCode())));
|
||||
.notIn(SchBaseTask::getTask_status,
|
||||
Arrays.asList(TaskStatus.FINISHED.getCode(), TaskStatus.CANCELED.getCode())));
|
||||
if (activeTaskCount > 0) {
|
||||
throw new BadRequestException("该托盘存在未完成的搬运任务,请检查");
|
||||
}
|
||||
// 组盘明细(组盘状态)
|
||||
List<GroupPlate> plates = iMdPbGroupplateService.list(new LambdaQueryWrapper<GroupPlate>()
|
||||
.eq(GroupPlate::getStoragevehicle_code, vehicleCode)
|
||||
.eq(GroupPlate::getStatus, GROUP_PLATE_STATUS.code("组盘")).last("for update"));
|
||||
if (plates.isEmpty()) {
|
||||
throw new BadRequestException("该托盘无组盘物料,无法直送");
|
||||
// 组盘明细(组盘状态,未入库)
|
||||
List<GroupPlate> plates = listGroupPlates(vehicleCode, true);
|
||||
if (plates.stream().anyMatch(p -> p.getFrozen_qty() != null && p.getFrozen_qty().signum() != 0)) {
|
||||
throw new BadRequestException("该托盘已有出库单占用,请稍后重试");
|
||||
}
|
||||
// 上料口:未指定时取托盘组盘信息中的上料口
|
||||
String loadPort = PlatingDemandServiceImpl.parseLoadPort(whereJson.getString("load_port"));
|
||||
if (StringUtils.isBlank(loadPort)) {
|
||||
Set<String> ports = plates.stream()
|
||||
.map(plate -> PlatingDemandServiceImpl.parseLoadPort(plate.getLoad_port()))
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (ports.isEmpty()) {
|
||||
throw new BadRequestException("托盘组盘信息缺少上料口,请检查");
|
||||
}
|
||||
if (ports.size() > 1) {
|
||||
throw new BadRequestException("托盘存在多个上料口:" + String.join(",", ports));
|
||||
}
|
||||
loadPort = ports.iterator().next();
|
||||
}
|
||||
// 校验上料口
|
||||
String loadPort = resolveLoadPort(plates);
|
||||
SchBasePoint portPoint = iSchBasePointService.getOne(
|
||||
new LambdaQueryWrapper<SchBasePoint>().eq(SchBasePoint::getPoint_code, loadPort));
|
||||
if (ObjectUtil.isEmpty(portPoint)) {
|
||||
throw new BadRequestException("上料口不存在:" + loadPort);
|
||||
throw new BadRequestException("上料口点位不存在:" + loadPort);
|
||||
}
|
||||
// 校验地面站点(AGV配送起点)
|
||||
SchBasePoint sitePoint = null;
|
||||
// 配送方式:AGV配送需扫描起始点位,配送任务完成后出库过账;否则直接出库过账
|
||||
// 未传该字段时按AGV配送处理,兼容旧版终端
|
||||
boolean agvDelivery = !whereJson.containsKey("agv_delivery")
|
||||
|| whereJson.getBooleanValue("agv_delivery");
|
||||
String startCode = null;
|
||||
SchBasePoint end = null;
|
||||
if (agvDelivery) {
|
||||
sitePoint = iSchBasePointService.getOne(
|
||||
new LambdaQueryWrapper<SchBasePoint>().eq(SchBasePoint::getPoint_code, siteCode));
|
||||
if (ObjectUtil.isEmpty(sitePoint)) {
|
||||
throw new BadRequestException("地面站点不存在:" + siteCode);
|
||||
startCode = StringUtils.trimToNull(whereJson.getString("site_code"));
|
||||
if (startCode == null) {
|
||||
throw new BadRequestException("使用AGV配送请扫描起始点位");
|
||||
}
|
||||
if (StringUtils.isNotBlank(sitePoint.getVehicle_code()) && !vehicleCode.equals(sitePoint.getVehicle_code())) {
|
||||
throw new BadRequestException("地面站点上已有其他托盘,请检查");
|
||||
SchBasePoint startPoint = iSchBasePointService.getOne(
|
||||
new LambdaQueryWrapper<SchBasePoint>().eq(SchBasePoint::getPoint_code, startCode));
|
||||
if (ObjectUtil.isEmpty(startPoint)) {
|
||||
throw new BadRequestException("起始点位不存在:" + startCode);
|
||||
}
|
||||
if (loadPort.equals(startCode)) {
|
||||
throw new BadRequestException("托盘已在上料口" + loadPort + ",无需再次配送");
|
||||
}
|
||||
// 配送终点:上料口区域空闲点位
|
||||
end = selectIdlePoint(portPoint.getRegion_code(), startCode, loadPort);
|
||||
if (ObjectUtil.isEmpty(end)) {
|
||||
throw new BadRequestException("上料口区域无空闲点位,无法生成配送任务");
|
||||
}
|
||||
}
|
||||
// 锁定并校验工单
|
||||
Map<String, WorkOrderDao> orderMap = lockOrders(orderCodes, true);
|
||||
// BOM 左匹配上料口
|
||||
List<WorkOrderBomDao> bomList = selectBomByPort(loadPort, new LinkedHashSet<>(orderCodes));
|
||||
if (bomList.isEmpty()) {
|
||||
throw new BadRequestException("所选工单在该上料口无BOM物料");
|
||||
}
|
||||
// 每个所选工单都必须存在该上料口的BOM物料
|
||||
for (String code : orderCodes) {
|
||||
boolean matched = bomList.stream().anyMatch(bom -> code.equals(bom.getWork_order_code()));
|
||||
if (!matched) {
|
||||
throw new BadRequestException("工单" + code + "在该上料口无BOM物料");
|
||||
// 组织出库明细:按物料汇总
|
||||
Map<String, List<GroupPlate>> platesByMaterial = plates.stream()
|
||||
.collect(Collectors.groupingBy(GroupPlate::getMaterial_code, LinkedHashMap::new, Collectors.toList()));
|
||||
JSONArray tableData = new JSONArray();
|
||||
for (Map.Entry<String, List<GroupPlate>> entry : platesByMaterial.entrySet()) {
|
||||
String materialCode = entry.getKey();
|
||||
MdMeMaterialbase material = iMdMeMaterialbaseService.getByCode(materialCode);
|
||||
if (material == null) {
|
||||
throw new BadRequestException("物料不存在:" + materialCode);
|
||||
}
|
||||
BigDecimal totalQty = entry.getValue().stream().map(GroupPlate::getQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
JSONObject row = new JSONObject();
|
||||
row.put("material_id", material.getMaterial_id());
|
||||
row.put("material_code", materialCode);
|
||||
row.put("qty", totalQty);
|
||||
row.put("qty_unit_id", entry.getValue().get(0).getQty_unit_id());
|
||||
row.put("qty_unit_name", entry.getValue().get(0).getQty_unit_name());
|
||||
row.put("pcsn", entry.getValue().get(0).getPcsn());
|
||||
row.put("load_port", loadPort);
|
||||
row.put("source_bill_type", SOURCE_TYPE);
|
||||
row.put("callback_strategy", CALLBACK_STRATEGY);
|
||||
row.put("stor_code", stor.getStor_code());
|
||||
tableData.add(row);
|
||||
}
|
||||
// 托盘物料数量按BOM剩余需求分摊到工单
|
||||
JSONArray tableData = buildOutDetail(plates, bomList, orderMap, loadPort);
|
||||
// 生成出库单
|
||||
String storCode = tableData.getJSONObject(0).getString("stor_code");
|
||||
BsrealStorattr stor = iBsrealStorattrService.findByCode(storCode);
|
||||
if (stor == null) {
|
||||
throw new BadRequestException("仓库不存在:" + storCode);
|
||||
}
|
||||
// 生成库存调拨出库单
|
||||
JSONObject bill = new JSONObject();
|
||||
bill.put("stor_code", storCode);
|
||||
bill.put("stor_code", stor.getStor_code());
|
||||
bill.put("stor_id", stor.getStor_id());
|
||||
bill.put("biz_date", DateUtil.today());
|
||||
bill.put("bill_type", IOSEnum.BILL_TYPE.code("生产出库"));
|
||||
bill.put("remark", "PDA配盘直送:" + String.join(",", orderCodes));
|
||||
bill.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨"));
|
||||
bill.put("remark", "PDA配盘直送:" + vehicleCode + " 上料口" + loadPort);
|
||||
bill.put("tableData", tableData);
|
||||
String billId = iOutBillService.saveBill(bill);
|
||||
// 直送出库直接完成并触发LLCK回传
|
||||
completeDirectBill(billId, loadPort, vehicleCode);
|
||||
// 更新组盘状态:组盘→出库
|
||||
iMdPbGroupplateService.update(new LambdaUpdateWrapper<GroupPlate>()
|
||||
.set(GroupPlate::getStatus, GROUP_PLATE_STATUS.code("出库"))
|
||||
.eq(GroupPlate::getStoragevehicle_code, vehicleCode)
|
||||
.eq(GroupPlate::getStatus, GROUP_PLATE_STATUS.code("组盘")));
|
||||
JSONObject result = new JSONObject();
|
||||
IOStorInv inv = ioStorInvMapper.selectById(billId);
|
||||
result.put("bill_code", inv == null ? null : inv.getBill_code());
|
||||
// AGV点对点配送:扫描的地面站点 → 上料口区域空闲点位(point_type=1)
|
||||
if (agvDelivery) {
|
||||
SchBasePoint end = selectIdlePoint(portPoint.getRegion_code(), sitePoint.getPoint_code(), loadPort);
|
||||
if (ObjectUtil.isEmpty(end)) {
|
||||
throw new BadRequestException("上料口区域无空闲点位,无法生成AGV配送任务");
|
||||
IOStorInv billDao = ioStorInvMapper.selectById(billId);
|
||||
// 分配明细:一托一物料一条
|
||||
List<IOStorInvDtl> detailRows = ioStorInvDtlMapper.selectList(new LambdaQueryWrapper<IOStorInvDtl>()
|
||||
.eq(IOStorInvDtl::getIostorinv_id, billId));
|
||||
Map<String, IOStorInvDtl> detailByMaterial = new HashMap<>();
|
||||
for (IOStorInvDtl detail : detailRows) {
|
||||
detailByMaterial.put(detail.getMaterial_code(), detail);
|
||||
}
|
||||
int seq = 1;
|
||||
for (GroupPlate plate : plates) {
|
||||
IOStorInvDtl detail = detailByMaterial.get(plate.getMaterial_code());
|
||||
if (detail == null) {
|
||||
throw new BadRequestException("未匹配到出库明细:" + plate.getMaterial_code());
|
||||
}
|
||||
IOStorInvDis dis = new IOStorInvDis();
|
||||
dis.setIostorinvdis_id(IdUtil.getStringId());
|
||||
dis.setIostorinv_id(billId);
|
||||
dis.setIostorinvdtl_id(detail.getIostorinvdtl_id());
|
||||
dis.setSeq_no(String.valueOf(seq++));
|
||||
dis.setMaterial_id(detail.getMaterial_id());
|
||||
dis.setMaterial_code(plate.getMaterial_code());
|
||||
dis.setPcsn(plate.getPcsn());
|
||||
dis.setStoragevehicle_code(vehicleCode);
|
||||
dis.setQty_unit_id(plate.getQty_unit_id());
|
||||
dis.setQty_unit_name(plate.getQty_unit_name());
|
||||
dis.setPlan_qty(plate.getQty());
|
||||
dis.setWork_status(IOSEnum.INBILL_DIS_STATUS.code("未生成"));
|
||||
dis.setIs_issued(BaseDataEnum.IS_YES_NOT.code("否"));
|
||||
// AGV配送的终点为上料口区域点位,非AGV按上料口记账
|
||||
dis.setPoint_code(agvDelivery ? end.getPoint_code() : loadPort);
|
||||
ioStorInvDisMapper.insert(dis);
|
||||
// 冻结组盘数量,避免运输途中被重复直送
|
||||
plate.setFrozen_qty(plate.getQty());
|
||||
plate.setExt_code(dis.getIostorinvdtl_id());
|
||||
plate.setExt_type("ST_IVT_IOSTORINVDTL");
|
||||
iMdPbGroupplateService.updateById(plate);
|
||||
}
|
||||
// 回填明细分配数量与单据状态
|
||||
for (IOStorInvDtl detail : detailRows) {
|
||||
BigDecimal assigned = ioStorInvDisMapper.selectList(new LambdaQueryWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getIostorinvdtl_id, detail.getIostorinvdtl_id()))
|
||||
.stream().map(IOStorInvDis::getPlan_qty).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
detail.setAssign_qty(assigned);
|
||||
detail.setUnassign_qty(detail.getPlan_qty().subtract(assigned).max(BigDecimal.ZERO));
|
||||
detail.setBill_status(IOSEnum.BILL_STATUS.code(
|
||||
detail.getUnassign_qty().signum() > 0 ? "分配中" : "分配完"));
|
||||
ioStorInvDtlMapper.updateById(detail);
|
||||
}
|
||||
IOStorInv billUpdate = new IOStorInv();
|
||||
billUpdate.setIostorinv_id(billId);
|
||||
billUpdate.setBill_status(IOSEnum.BILL_STATUS.code("分配完"));
|
||||
ioStorInvMapper.updateById(billUpdate);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("bill_id", billId);
|
||||
result.put("bill_code", billDao == null ? null : billDao.getBill_code());
|
||||
result.put("load_port", loadPort);
|
||||
result.put("agv_delivery", agvDelivery);
|
||||
if (agvDelivery) {
|
||||
// 生成点对点配送任务:起始点位 -> 上料口区域空闲点位,送达后由任务结算过账
|
||||
JSONObject taskJson = new JSONObject();
|
||||
taskJson.put("config_code", "Point2PointTask");
|
||||
taskJson.put("point_code1", sitePoint.getPoint_code());
|
||||
taskJson.put("config_code", TASK_BEAN);
|
||||
taskJson.put("point_code1", startCode);
|
||||
taskJson.put("point_code2", end.getPoint_code());
|
||||
taskJson.put("vehicle_code", vehicleCode);
|
||||
taskJson.put("Priority", TaskEnum.ACS_PRIORITY.code("1"));
|
||||
taskJson.put("workOrderCode", String.join(",", orderCodes));
|
||||
String taskId = point2PointTask.create(taskJson);
|
||||
taskJson.put("bill_id", billId);
|
||||
String taskId = SpringContextHolder.<org.nl.wms.sch_manage.service.core.AbstractTask>getBean(TASK_BEAN)
|
||||
.create(taskJson);
|
||||
SchBaseTask task = iSchBaseTaskService.getById(taskId);
|
||||
ioStorInvDisMapper.update(null, new LambdaUpdateWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getIostorinv_id, billId)
|
||||
.eq(IOStorInvDis::getStoragevehicle_code, vehicleCode)
|
||||
.set(IOStorInvDis::getTask_id, taskId)
|
||||
.set(IOStorInvDis::getIs_issued, BaseDataEnum.IS_YES_NOT.code("是"))
|
||||
.set(IOStorInvDis::getWork_status, IOSEnum.INBILL_DIS_STATUS.code("生成")));
|
||||
iSchBasePointService.update(new LambdaUpdateWrapper<SchBasePoint>()
|
||||
.eq(SchBasePoint::getPoint_code, end.getPoint_code())
|
||||
.set(SchBasePoint::getIng_task_code, taskId));
|
||||
result.put("task_code", task == null ? null : task.getTask_code());
|
||||
result.put("start_point_code", sitePoint.getPoint_code());
|
||||
result.put("start_point_code", startCode);
|
||||
result.put("end_point_code", end.getPoint_code());
|
||||
} else {
|
||||
// 非AGV配送:直接出库过账并回传 MM057
|
||||
settlement.settleByBill(billId, loadPort);
|
||||
result.put("task_code", null);
|
||||
result.put("bill_status", IOSEnum.BILL_STATUS.code("完成"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 左匹配查询BOM:load_port 等值或以 "编码:" 为前缀
|
||||
* 组盘明细:仅组盘(01)状态,可选行锁
|
||||
*/
|
||||
private List<WorkOrderBomDao> selectBomByPort(String loadPort, Set<String> orderCodes) {
|
||||
String port = PlatingDemandServiceImpl.parseLoadPort(loadPort);
|
||||
if (StringUtils.isBlank(port) || orderCodes.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return boms.selectList(new LambdaQueryWrapper<WorkOrderBomDao>()
|
||||
.in(WorkOrderBomDao::getWork_order_code, orderCodes)
|
||||
.and(q -> q.eq(WorkOrderBomDao::getLoad_port, port)
|
||||
.or().likeRight(WorkOrderBomDao::getLoad_port, port + ":")));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验工单(lock=true 时加行锁并校验状态)
|
||||
*/
|
||||
private Map<String, WorkOrderDao> lockOrders(List<String> orderCodes, boolean lock) {
|
||||
Set<String> codes = new LinkedHashSet<>(orderCodes);
|
||||
LambdaQueryWrapper<WorkOrderDao> query = new LambdaQueryWrapper<WorkOrderDao>()
|
||||
.in(WorkOrderDao::getOrder_code, codes);
|
||||
private List<GroupPlate> listGroupPlates(String palletCode, boolean lock) {
|
||||
LambdaQueryWrapper<GroupPlate> query = new LambdaQueryWrapper<GroupPlate>()
|
||||
.eq(GroupPlate::getStoragevehicle_code, palletCode)
|
||||
.eq(GroupPlate::getStatus, GROUP_PLATE_STATUS.code("组盘"))
|
||||
.orderByAsc(GroupPlate::getGroup_id);
|
||||
if (lock) {
|
||||
query.last("for update");
|
||||
}
|
||||
List<WorkOrderDao> list = orders.selectList(query);
|
||||
if (list.size() != codes.size()) {
|
||||
throw new BadRequestException("存在无效工单,请刷新后重选");
|
||||
List<GroupPlate> plates = iMdPbGroupplateService.list(query);
|
||||
if (plates.isEmpty()) {
|
||||
throw new BadRequestException("该托盘无组盘物料,无法直送");
|
||||
}
|
||||
for (WorkOrderDao order : list) {
|
||||
if (order.getStatus() != 1 && order.getStatus() != 2) {
|
||||
throw new BadRequestException("工单状态不允许直送:" + order.getOrder_code());
|
||||
}
|
||||
}
|
||||
Map<String, WorkOrderDao> map = new LinkedHashMap<>();
|
||||
for (String code : codes) {
|
||||
for (WorkOrderDao order : list) {
|
||||
if (order.getOrder_code().equals(code)) {
|
||||
map.put(code, order);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
return plates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 托盘组盘数量按BOM剩余需求(bom_qty*order_qty-use_bom_qty)顺序分摊到工单,组织出库明细
|
||||
* 上料口:取自组盘信息,多上料口不允许直送
|
||||
*/
|
||||
private JSONArray buildOutDetail(List<GroupPlate> plates, List<WorkOrderBomDao> bomList,
|
||||
Map<String, WorkOrderDao> orderMap, String loadPort) {
|
||||
Map<String, List<GroupPlate>> platesByMaterial = plates.stream()
|
||||
.collect(Collectors.groupingBy(GroupPlate::getMaterial_code, LinkedHashMap::new, Collectors.toList()));
|
||||
Map<String, List<WorkOrderBomDao>> bomByMaterial = bomList.stream()
|
||||
.collect(Collectors.groupingBy(WorkOrderBomDao::getMaterial_code, LinkedHashMap::new, Collectors.toList()));
|
||||
List<String> orderSeq = new ArrayList<>(orderMap.keySet());
|
||||
String storCode = null;
|
||||
JSONArray tableData = new JSONArray();
|
||||
for (Map.Entry<String, List<GroupPlate>> entry : platesByMaterial.entrySet()) {
|
||||
String materialCode = entry.getKey();
|
||||
List<WorkOrderBomDao> bomOfMaterial = bomByMaterial.get(materialCode);
|
||||
if (bomOfMaterial == null || bomOfMaterial.isEmpty()) {
|
||||
throw new BadRequestException("托盘物料" + materialCode + "不属于所选工单在该上料口的BOM");
|
||||
}
|
||||
BigDecimal palletQty = entry.getValue().stream().map(GroupPlate::getQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// 按工单选择顺序、BOM行号排序分摊
|
||||
bomOfMaterial.sort(Comparator
|
||||
.comparing((WorkOrderBomDao b) -> orderSeq.indexOf(b.getWork_order_code()))
|
||||
.thenComparing(b -> b.getItem_no() == null ? Integer.MAX_VALUE : b.getItem_no()));
|
||||
JSONArray sources = new JSONArray();
|
||||
BigDecimal remaining = palletQty;
|
||||
for (WorkOrderBomDao bom : bomOfMaterial) {
|
||||
if (remaining.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
break;
|
||||
}
|
||||
WorkOrderDao order = orderMap.get(bom.getWork_order_code());
|
||||
int orderQty = order == null || order.getOrder_qty() == null ? 0 : order.getOrder_qty();
|
||||
BigDecimal need = (bom.getBom_qty() == null ? BigDecimal.ZERO : bom.getBom_qty())
|
||||
.multiply(BigDecimal.valueOf(orderQty));
|
||||
if (need.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
continue;
|
||||
}
|
||||
// 仓库/组织一致性
|
||||
String bomStor = iMaterialWarehouseMappingService.getOrDefault(bom.getMaterial_code(), bom.getWarehouse_code());
|
||||
if (StringUtils.isBlank(bomStor)) {
|
||||
throw new BadRequestException("BOM仓库编码为空:" + bom.getWork_order_code() + "-" + materialCode);
|
||||
}
|
||||
if (storCode == null) {
|
||||
storCode = bomStor;
|
||||
} else if (!storCode.equals(bomStor)) {
|
||||
throw new BadRequestException("一张出库单只能对应一个仓库,请选择相同仓库的工单");
|
||||
}
|
||||
String bomOrg = order == null ? null : order.getOrg_code();
|
||||
if (StringUtils.isBlank(bomOrg)) {
|
||||
throw new BadRequestException("工单组织编码为空:" + bom.getWork_order_code());
|
||||
}
|
||||
BigDecimal take = need.min(remaining);
|
||||
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", take);
|
||||
sources.add(source);
|
||||
remaining = remaining.subtract(take);
|
||||
}
|
||||
if (remaining.compareTo(BigDecimal.ZERO) > 0) {
|
||||
JSONObject lastJsonObject = sources.getJSONObject(sources.size() - 1);
|
||||
lastJsonObject.put("qty", lastJsonObject.getBigDecimal("qty").add(remaining));
|
||||
// throw new BadRequestException("托盘物料" + materialCode + "数量超出工单剩余需求" + remaining.stripTrailingZeros().toPlainString());
|
||||
}
|
||||
MdMeMaterialbase material = iMdMeMaterialbaseService.getByCode(materialCode);
|
||||
if (material == null) {
|
||||
throw new BadRequestException("物料不存在:" + materialCode);
|
||||
}
|
||||
JSONObject row = new JSONObject();
|
||||
row.put("material_id", material.getMaterial_id());
|
||||
row.put("material_code", materialCode);
|
||||
row.put("qty", palletQty);
|
||||
row.put("qty_unit_id", entry.getValue().get(0).getQty_unit_id());
|
||||
row.put("qty_unit_name", entry.getValue().get(0).getQty_unit_name());
|
||||
row.put("pcsn", "1");
|
||||
row.put("load_port", loadPort);
|
||||
row.put("source_bill_type", SOURCE_TYPE);
|
||||
row.put("callback_strategy", CALLBACK_STRATEGY);
|
||||
row.put("source_work_orders", sources);
|
||||
row.put("stor_code", storCode);
|
||||
tableData.add(row);
|
||||
private String resolveLoadPort(List<GroupPlate> plates) {
|
||||
Set<String> ports = plates.stream()
|
||||
.map(plate -> PlatingDemandServiceImpl.parseLoadPort(plate.getLoad_port()))
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (ports.isEmpty()) {
|
||||
throw new BadRequestException("托盘组盘信息缺少上料口,请检查");
|
||||
}
|
||||
return tableData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直送出库单直接完成:补完成态分配明细,触发LLCK回传生成
|
||||
*/
|
||||
private void completeDirectBill(String billId, String loadPort, String vehicleCode) {
|
||||
List<IOStorInvDtl> dtlList = ioStorInvDtlMapper.selectList(
|
||||
new LambdaQueryWrapper<IOStorInvDtl>().eq(IOStorInvDtl::getIostorinv_id, billId));
|
||||
for (IOStorInvDtl dtl : dtlList) {
|
||||
IOStorInvDis dis = new IOStorInvDis();
|
||||
dis.setIostorinvdis_id(IdUtil.getStringId());
|
||||
dis.setIostorinv_id(billId);
|
||||
dis.setIostorinvdtl_id(dtl.getIostorinvdtl_id());
|
||||
dis.setSeq_no("1");
|
||||
dis.setMaterial_id(dtl.getMaterial_id());
|
||||
dis.setMaterial_code(dtl.getMaterial_code());
|
||||
dis.setPcsn(dtl.getPcsn());
|
||||
dis.setStoragevehicle_code(vehicleCode);
|
||||
dis.setWork_status(IOSEnum.INBILL_DIS_STATUS.code("完成"));
|
||||
dis.setIs_issued(IOSConstant.IS_DELETE_NO);
|
||||
dis.setQty_unit_id(dtl.getQty_unit_id());
|
||||
dis.setQty_unit_name(dtl.getQty_unit_name());
|
||||
dis.setPlan_qty(dtl.getPlan_qty());
|
||||
dis.setReal_qty(dtl.getPlan_qty());
|
||||
dis.setPoint_code(loadPort);
|
||||
ioStorInvDisMapper.insert(dis);
|
||||
// 触发LLCK回传策略(生成pm_stock_return待回传记录并累计BOM领料数量)
|
||||
callbackStrategyPublish.callbackStrategy(dtl.getCallback_strategy(), dtl);
|
||||
// 回传策略内更新了real_qty,此处完成明细状态并保存
|
||||
dtl.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
|
||||
ioStorInvDtlMapper.updateById(dtl);
|
||||
if (ports.size() > 1) {
|
||||
throw new BadRequestException("托盘存在多个上料口:" + String.join(",", ports));
|
||||
}
|
||||
IOStorInv inv = new IOStorInv();
|
||||
inv.setIostorinv_id(billId);
|
||||
inv.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
|
||||
ioStorInvMapper.updateById(inv);
|
||||
return ports.iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -582,15 +390,17 @@ public class PdaDirectDeliveryServiceImpl implements PdaDirectDeliveryService {
|
||||
if (candidates.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 排除被未完成任务占用的点位(point_code1~4)
|
||||
Set<String> busy = iSchBaseTaskService.list(new LambdaQueryWrapper<SchBaseTask>()
|
||||
.notIn(SchBaseTask::getTask_status, Arrays.asList(TaskStatus.FINISHED.getCode(), TaskStatus.CANCELED.getCode())))
|
||||
.notIn(SchBaseTask::getTask_status,
|
||||
Arrays.asList(TaskStatus.FINISHED.getCode(), TaskStatus.CANCELED.getCode())))
|
||||
.stream()
|
||||
.flatMap(t -> Arrays.stream(new String[]{t.getPoint_code1(), t.getPoint_code2(), t.getPoint_code3(), t.getPoint_code4()}))
|
||||
.flatMap(t -> Arrays.stream(new String[]{t.getPoint_code1(), t.getPoint_code2(),
|
||||
t.getPoint_code3(), t.getPoint_code4()}))
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
return candidates.stream()
|
||||
.filter(p -> StringUtils.isBlank(p.getVehicle_code()))
|
||||
.filter(p -> StringUtils.isBlank(p.getIng_task_code()))
|
||||
.filter(p -> !busy.contains(p.getPoint_code()))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,10 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.nl.common.utils.ValidationUtil.assertNotBlankJson;
|
||||
|
||||
/**
|
||||
* PC 端配盘配送出库(批量)
|
||||
* PC 端配盘配送出库(批量):按配盘托盘直接调拨出库到产线
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -27,32 +25,6 @@ public class PlatingDeliveryController {
|
||||
|
||||
private final PlatingDeliveryService platingDeliveryService;
|
||||
|
||||
@GetMapping("/workOrders")
|
||||
@Log("配盘配送-可配送工单")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> workOrders(@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) String workArea,
|
||||
@RequestParam(required = false) String materialCode,
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "20") int size) {
|
||||
return ResponseData.build(platingDeliveryService.listWorkOrders(keyword, workArea, materialCode, page, size),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/workAreas")
|
||||
@Log("配盘配送-产线下拉")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> workAreas() {
|
||||
return ResponseData.build(platingDeliveryService.listWorkAreas(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/bomSummary")
|
||||
@Log("配盘配送-BOM汇总")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> bomSummary(@RequestParam List<String> workOrders) {
|
||||
return ResponseData.build(platingDeliveryService.bomSummary(workOrders), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/sects")
|
||||
@Log("配盘配送-库区列表")
|
||||
@SaIgnore
|
||||
@@ -64,8 +36,8 @@ public class PlatingDeliveryController {
|
||||
@Log("配盘配送-库区配盘数据")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> pallets(@RequestParam String sectCode,
|
||||
@RequestParam(required = false) List<String> loadPorts) {
|
||||
return ResponseData.build(platingDeliveryService.listPallets(sectCode, loadPorts), HttpStatus.OK);
|
||||
@RequestParam(required = false) String loadPort) {
|
||||
return ResponseData.build(platingDeliveryService.listPallets(sectCode, loadPort), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/deliver")
|
||||
|
||||
@@ -5,45 +5,28 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PC 端配盘配送出库(批量)
|
||||
* PC 端配盘配送出库(批量):按配盘托盘直接调拨出库到产线
|
||||
*/
|
||||
public interface PlatingDeliveryService {
|
||||
|
||||
/**
|
||||
* 可配送工单(状态待执行/执行中),支持产线、物料编码筛选并分页
|
||||
*
|
||||
* @return {total, records}
|
||||
*/
|
||||
JSONObject listWorkOrders(String keyword, String workArea, String materialCode, int page, int size);
|
||||
|
||||
/**
|
||||
* 产线下拉(工单 work_area 去重)
|
||||
*/
|
||||
List<String> listWorkAreas();
|
||||
|
||||
/**
|
||||
* 所选工单 BOM 按 上料口+物料 汇总
|
||||
*/
|
||||
List<JSONObject> bomSummary(List<String> orderCodes);
|
||||
|
||||
/**
|
||||
* 库区下拉
|
||||
* 库区下拉(源库区)
|
||||
*/
|
||||
List<JSONObject> listSects();
|
||||
|
||||
/**
|
||||
* 指定库区、指定上料口范围的配盘数据(已入库托盘)
|
||||
* 指定库区内已入库的配盘托盘,可按上料口过滤
|
||||
*/
|
||||
List<JSONObject> listPallets(String sectCode, List<String> loadPorts);
|
||||
List<JSONObject> listPallets(String sectCode, String loadPort);
|
||||
|
||||
/**
|
||||
* 批量配送出库:生成出库单、分配锁位冻结、逐托生成AGV出库任务
|
||||
* 批量配送出库:生成库存调拨出库单(回传 MM057 调拨到线边库 X001),逐托生成AGV出库任务,
|
||||
* 任务送达后由 STOutTask 完成单据并触发回传。
|
||||
*
|
||||
* @param request {
|
||||
* workOrders: [工单号],
|
||||
* sectCode: 库区编码,
|
||||
* pallets: [托盘码],
|
||||
* pointType: 终点类型(默认2)
|
||||
* pointType: 终点点位类型(默认1)
|
||||
* }
|
||||
* @return {bill_id, bill_code, task_count, tasks[]}
|
||||
*/
|
||||
|
||||
@@ -38,11 +38,6 @@ import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvMapper;
|
||||
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.mapper.MdPbGroupplateMapper;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.WorkOrderBomDao;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.WorkOrderDao;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.mapper.WorkOrderBomMapper;
|
||||
import org.nl.wms.welding_manage.service.work_order.dao.mapper.WorkOrderMapper;
|
||||
import org.nl.wms.welding_manage.service.work_order.impl.WorkOrderOutboundService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -52,22 +47,20 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* PC 端配盘配送出库(批量):选中库区内已入库的配盘托盘,批量生成出库单并逐托下发AGV出库任务。
|
||||
* 出库明细使用工单来源份额,任务完成后由 STOutTask -> OutBillService.taskFinish -> disFinish
|
||||
* 走「工单领料整托扣减」分支并触发 LLCK 回传。
|
||||
* PC 端配盘配送出库(批量):选中库区内已入库的配盘托盘,按托盘上料口批量调拨出库到产线。
|
||||
* <p>
|
||||
* 与生产工单解耦:不再按工单BOM分摊,出库单类型为「库存调拨」,明细回传策略为
|
||||
* {@code sapPlatingDeliveryMM057}(MM057 / 311 转储到线边库 X001,线边库存不由 WMS 维护)。
|
||||
* 逐托生成 STOutTask 出库搬运任务,任务送达完成后由 OutBillService.disFinish 扣减源库区库存并触发回传。
|
||||
*/
|
||||
@Service
|
||||
public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
|
||||
private static final String SOURCE = WorkOrderOutboundService.SOURCE;
|
||||
private static final String CALLBACK = "sapWorkOrderLLCKCallback";
|
||||
private static final String SOURCE_TYPE = "plating_delivery";
|
||||
private static final String CALLBACK = "sapPlatingDeliveryMM057";
|
||||
private static final String STATUS_FINISHED = TaskStatus.FINISHED.getCode();
|
||||
private static final String STATUS_CANCELED = TaskStatus.CANCELED.getCode();
|
||||
|
||||
@Resource
|
||||
private WorkOrderMapper orders;
|
||||
@Resource
|
||||
private WorkOrderBomMapper boms;
|
||||
@Resource
|
||||
private ISectattrService sectService;
|
||||
@Resource
|
||||
@@ -93,88 +86,6 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
@Resource
|
||||
private IOStorInvDisMapper disMapper;
|
||||
|
||||
@Override
|
||||
public JSONObject listWorkOrders(String keyword, String workArea, String materialCode, int page, int size) {
|
||||
int pageNo = page <= 0 ? 1 : page;
|
||||
int pageSize = size <= 0 || size > 200 ? 20 : size;
|
||||
String kw = StringUtils.trimToNull(keyword);
|
||||
String area = StringUtils.trimToNull(workArea);
|
||||
String material = StringUtils.trimToNull(materialCode);
|
||||
long total = orders.countDeliveryOrders(kw, area, material);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("total", total);
|
||||
List<JSONObject> records = new ArrayList<>();
|
||||
if (total > 0) {
|
||||
int offset = (pageNo - 1) * pageSize;
|
||||
for (WorkOrderDao order : orders.selectDeliveryOrders(kw, area, material, offset, pageSize)) {
|
||||
JSONObject row = new JSONObject();
|
||||
row.put("order_code", order.getOrder_code());
|
||||
row.put("order_id", order.getOrder_id());
|
||||
row.put("org_code", order.getOrg_code());
|
||||
row.put("product_code", order.getProduct_code());
|
||||
row.put("product_name", order.getProduct_name());
|
||||
row.put("order_qty", order.getOrder_qty());
|
||||
row.put("work_area", order.getWork_area());
|
||||
row.put("plan_started_on", order.getPlan_started_on());
|
||||
row.put("status", order.getStatus());
|
||||
records.add(row);
|
||||
}
|
||||
}
|
||||
result.put("records", records);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listWorkAreas() {
|
||||
return orders.selectWorkAreas();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> bomSummary(List<String> orderCodes) {
|
||||
List<String> codes = normalizeCodes(orderCodes);
|
||||
if (codes.isEmpty()) {
|
||||
throw new BadRequestException("请先选择工单");
|
||||
}
|
||||
Map<String, WorkOrderDao> orderMap = loadOrders(codes, false);
|
||||
Map<String, JSONObject> merged = new LinkedHashMap<>();
|
||||
for (WorkOrderBomDao bom : loadBom(codes, false)) {
|
||||
String port = PlatingDemandServiceImpl.parseLoadPort(bom.getLoad_port());
|
||||
if (StringUtils.isBlank(port)) {
|
||||
continue;
|
||||
}
|
||||
WorkOrderDao order = orderMap.get(bom.getWork_order_code());
|
||||
int orderQty = order == null || order.getOrder_qty() == null ? 0 : order.getOrder_qty();
|
||||
BigDecimal need = decimal(bom.getBom_qty()).multiply(BigDecimal.valueOf(orderQty));
|
||||
BigDecimal used = decimal(bom.getUse_bom_qty());
|
||||
String key = key(port, bom.getMaterial_code());
|
||||
JSONObject row = merged.computeIfAbsent(key, k -> {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("load_port", port);
|
||||
json.put("material_code", bom.getMaterial_code());
|
||||
json.put("material_name", bom.getMaterial_name());
|
||||
json.put("unit", bom.getUnit());
|
||||
json.put("need_qty", BigDecimal.ZERO);
|
||||
json.put("used_qty", BigDecimal.ZERO);
|
||||
json.put("orders", new JSONArray());
|
||||
return json;
|
||||
});
|
||||
row.put("need_qty", row.getBigDecimal("need_qty").add(need));
|
||||
row.put("used_qty", row.getBigDecimal("used_qty").add(used));
|
||||
JSONArray orderArr = row.getJSONArray("orders");
|
||||
if (!orderArr.contains(bom.getWork_order_code())) {
|
||||
orderArr.add(bom.getWork_order_code());
|
||||
}
|
||||
}
|
||||
List<JSONObject> result = new ArrayList<>(merged.values());
|
||||
for (JSONObject row : result) {
|
||||
row.put("remain_qty", row.getBigDecimal("need_qty")
|
||||
.subtract(row.getBigDecimal("used_qty")).max(BigDecimal.ZERO));
|
||||
}
|
||||
result.sort(Comparator.comparing((JSONObject r) -> r.getString("load_port"))
|
||||
.thenComparing(r -> r.getString("material_code")));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> listSects() {
|
||||
List<Sectattr> sects = sectService.list(new LambdaQueryWrapper<Sectattr>()
|
||||
@@ -194,15 +105,13 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JSONObject> listPallets(String sectCode, List<String> loadPorts) {
|
||||
public List<JSONObject> listPallets(String sectCode, String loadPort) {
|
||||
if (StringUtils.isBlank(sectCode)) {
|
||||
throw new BadRequestException("请先选择库区");
|
||||
}
|
||||
List<String> ports = normalizePorts(loadPorts);
|
||||
if (ports.isEmpty()) {
|
||||
// 未解析到上料口时不返回数据,避免展示与工单无关的配盘
|
||||
return new ArrayList<>();
|
||||
}
|
||||
String port = PlatingDemandServiceImpl.parseLoadPort(loadPort);
|
||||
List<String> ports = StringUtils.isBlank(port)
|
||||
? new ArrayList<>() : Collections.singletonList(port);
|
||||
List<JSONObject> rows = groupMapper.selectPlatingPallets(sectCode.trim(), ports);
|
||||
Map<String, JSONObject> pallets = new LinkedHashMap<>();
|
||||
for (JSONObject row : rows) {
|
||||
@@ -214,7 +123,7 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
json.put("sect_code", row.getString("sect_code"));
|
||||
json.put("sect_name", row.getString("sect_name"));
|
||||
json.put("stor_code", row.getString("stor_code"));
|
||||
json.put("load_port", row.getString("load_port"));
|
||||
json.put("load_port", PlatingDemandServiceImpl.parseLoadPort(row.getString("load_port")));
|
||||
json.put("total_qty", BigDecimal.ZERO);
|
||||
json.put("item_count", 0);
|
||||
json.put("conflict", false);
|
||||
@@ -223,7 +132,8 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
});
|
||||
// 同一托盘出现多个库位或多个上料口视为数据异常,前端禁用选择
|
||||
if (!Objects.equals(item.getString("struct_code"), row.getString("struct_code"))
|
||||
|| !Objects.equals(item.getString("load_port"), row.getString("load_port"))) {
|
||||
|| !Objects.equals(item.getString("load_port"),
|
||||
PlatingDemandServiceImpl.parseLoadPort(row.getString("load_port")))) {
|
||||
item.put("conflict", true);
|
||||
}
|
||||
item.put("total_qty", item.getBigDecimal("total_qty").add(decimal(row.getBigDecimal("qty"))));
|
||||
@@ -243,15 +153,10 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public JSONObject deliver(JSONObject request) {
|
||||
List<String> orderCodes = normalizeCodes(request.getJSONArray("workOrders") == null
|
||||
? null : request.getJSONArray("workOrders").toJavaList(String.class));
|
||||
List<String> palletCodes = normalizeCodes(request.getJSONArray("pallets") == null
|
||||
? null : request.getJSONArray("pallets").toJavaList(String.class));
|
||||
String sectCode = StringUtils.trimToEmpty(request.getString("sectCode"));
|
||||
String pointType = StringUtils.defaultIfBlank(request.getString("pointType"), "1");
|
||||
if (orderCodes.isEmpty()) {
|
||||
throw new BadRequestException("请先选择工单");
|
||||
}
|
||||
if (palletCodes.isEmpty()) {
|
||||
throw new BadRequestException("请勾选需要配送的配盘数据");
|
||||
}
|
||||
@@ -259,8 +164,6 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
if (sect == null) {
|
||||
throw new BadRequestException("库区不存在:" + sectCode);
|
||||
}
|
||||
// 工单行锁 + 状态校验
|
||||
Map<String, WorkOrderDao> orderMap = loadOrders(orderCodes, true);
|
||||
// 组盘数据行锁:必须已入库(02)、未冻结
|
||||
List<GroupPlate> plates = groupService.list(new LambdaQueryWrapper<GroupPlate>()
|
||||
.in(GroupPlate::getStoragevehicle_code, palletCodes)
|
||||
@@ -299,39 +202,38 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
throw new BadRequestException("托盘" + pallet + "不在所选库区:" + st.getSect_code());
|
||||
}
|
||||
}
|
||||
// 托盘上料口一致性
|
||||
// 上料口取自托盘组盘信息,多上料口不允许出库
|
||||
Map<String, String> portByPallet = new HashMap<>();
|
||||
for (GroupPlate plate : plates) {
|
||||
String port = PlatingDemandServiceImpl.parseLoadPort(plate.getLoad_port());
|
||||
if (StringUtils.isBlank(port)) {
|
||||
throw new BadRequestException("托盘组盘信息缺少上料口:" + plate.getStoragevehicle_code());
|
||||
}
|
||||
String exists = portByPallet.putIfAbsent(plate.getStoragevehicle_code(), port);
|
||||
if (exists != null && !exists.equals(port)) {
|
||||
throw new BadRequestException("托盘存在多个上料口,请核实:" + plate.getStoragevehicle_code());
|
||||
}
|
||||
}
|
||||
// BOM 行锁
|
||||
List<WorkOrderBomDao> bomList = loadBom(orderCodes, true);
|
||||
Map<String, List<WorkOrderBomDao>> bomByKey = bomList.stream()
|
||||
.filter(b -> StringUtils.isNotBlank(PlatingDemandServiceImpl.parseLoadPort(b.getLoad_port())))
|
||||
.collect(Collectors.groupingBy(b -> key(PlatingDemandServiceImpl.parseLoadPort(b.getLoad_port()),
|
||||
b.getMaterial_code()), LinkedHashMap::new, Collectors.toList()));
|
||||
// 托盘数量按 上料口+物料 汇总后分摊到工单BOM份额
|
||||
for (String port : new LinkedHashSet<>(portByPallet.values())) {
|
||||
if (pointService.selectByCode(port) == null) {
|
||||
throw new BadRequestException("上料口点位不存在:" + port);
|
||||
}
|
||||
}
|
||||
BsrealStorattr storattr = storeService.findById(sect.getStor_id());
|
||||
if (storattr == null) {
|
||||
throw new BadRequestException("库区未关联仓库:" + sectCode);
|
||||
}
|
||||
// 托盘数量按 上料口+物料 汇总组织出库明细(不再分摊到工单)
|
||||
Map<String, List<GroupPlate>> platesByKey = plates.stream().collect(Collectors.groupingBy(
|
||||
g -> key(portByPallet.get(g.getStoragevehicle_code()), g.getMaterial_code()),
|
||||
LinkedHashMap::new, Collectors.toList()));
|
||||
JSONArray tableData = new JSONArray();
|
||||
BsrealStorattr storattr = storeService.findById(sect.getStor_id());
|
||||
String storCode = storattr.getStor_code();
|
||||
for (Map.Entry<String, List<GroupPlate>> entry : platesByKey.entrySet()) {
|
||||
List<GroupPlate> stock = entry.getValue();
|
||||
String port = portByPallet.get(stock.get(0).getStoragevehicle_code());
|
||||
String materialCode = stock.get(0).getMaterial_code();
|
||||
BigDecimal totalQty = stock.stream().map(GroupPlate::getQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
List<WorkOrderBomDao> bomOfKey = bomByKey.get(entry.getKey());
|
||||
if (bomOfKey == null || bomOfKey.isEmpty()) {
|
||||
throw new BadRequestException("托盘物料" + materialCode + "不在所选工单上料口" + port + "的BOM中");
|
||||
}
|
||||
JSONArray sources = allocateSources(bomOfKey, orderMap, totalQty, materialCode, port);
|
||||
MdMeMaterialbase material = materialService.getByCode(materialCode);
|
||||
if (material == null) {
|
||||
throw new BadRequestException("物料不存在:" + materialCode);
|
||||
@@ -344,22 +246,22 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
row.put("qty_unit_name", stock.get(0).getQty_unit_name());
|
||||
row.put("pcsn", stock.get(0).getPcsn());
|
||||
row.put("load_port", port);
|
||||
row.put("source_bill_type", SOURCE);
|
||||
row.put("source_bill_type", SOURCE_TYPE);
|
||||
row.put("callback_strategy", CALLBACK);
|
||||
row.put("source_work_orders", sources);
|
||||
row.put("stor_code", storattr.getStor_code());
|
||||
tableData.add(row);
|
||||
}
|
||||
// 生成出库单
|
||||
// 生成库存调拨出库单
|
||||
JSONObject bill = new JSONObject();
|
||||
bill.put("stor_code", storattr.getStor_code());
|
||||
bill.put("stor_id", storattr.getStor_id());
|
||||
bill.put("biz_date", DateUtil.today());
|
||||
bill.put("bill_type", IOSEnum.BILL_TYPE.code("生产出库"));
|
||||
bill.put("remark", "配盘配送出库:" + String.join(",", orderCodes));
|
||||
bill.put("bill_type", IOSEnum.BILL_TYPE.code("库存调拨"));
|
||||
bill.put("remark", "配盘配送出库(调拨X001):" + palletCodes.size() + "托 " + String.join(",", palletCodes));
|
||||
bill.put("tableData", tableData);
|
||||
String billId = outBillService.saveBill(bill);
|
||||
IOStorInv billDao = billMapper.selectById(billId);
|
||||
// 分配明细:按 上料口+物料 关联出库明细
|
||||
// 分配明细:一托一物料一条分配记录
|
||||
List<IOStorInvDtl> detailRows = detailMapper.selectList(new LambdaQueryWrapper<IOStorInvDtl>()
|
||||
.eq(IOStorInvDtl::getIostorinv_id, billId));
|
||||
Map<String, IOStorInvDtl> detailByKey = new HashMap<>();
|
||||
@@ -396,7 +298,7 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
dis.setIs_issued(BaseDataEnum.IS_YES_NOT.code("否"));
|
||||
dis.setPoint_code(port);
|
||||
disMapper.insert(dis);
|
||||
// 冻结组盘数量
|
||||
// 冻结组盘数量,避免被其他单据重复占用
|
||||
plate.setFrozen_qty(plate.getQty());
|
||||
plate.setExt_code(dis.getIostorinvdtl_id());
|
||||
plate.setExt_type("ST_IVT_IOSTORINVDTL");
|
||||
@@ -427,16 +329,13 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
billUpdate.setIostorinv_id(billId);
|
||||
billUpdate.setBill_status(IOSEnum.BILL_STATUS.code("分配完"));
|
||||
billMapper.updateById(billUpdate);
|
||||
// 逐托生成AGV出库任务
|
||||
// 逐托生成AGV出库任务:库位 -> 上料口区域空闲点位
|
||||
List<JSONObject> tasks = new ArrayList<>();
|
||||
Set<String> usedPoints = new HashSet<>();
|
||||
for (String pallet : palletCodes) {
|
||||
Structattr st = structByPallet.get(pallet);
|
||||
String port = portByPallet.get(pallet);
|
||||
SchBasePoint portPoint = pointService.selectByCode(port);
|
||||
if (portPoint == null) {
|
||||
throw new BadRequestException("上料口点位不存在:" + port);
|
||||
}
|
||||
SchBasePoint end = selectIdlePoint(portPoint.getRegion_code(), port, pointType, usedPoints);
|
||||
if (end == null) {
|
||||
throw new BadRequestException("上料口" + port + "所在区域无空闲点位,无法生成配送任务");
|
||||
@@ -469,6 +368,7 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
taskRow.put("pallet_code", pallet);
|
||||
taskRow.put("task_code", task.getTask_code());
|
||||
taskRow.put("struct_code", st.getStruct_code());
|
||||
taskRow.put("load_port", port);
|
||||
taskRow.put("end_point_code", end.getPoint_code());
|
||||
tasks.add(taskRow);
|
||||
}
|
||||
@@ -480,115 +380,6 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工单查询(lock=true 时行锁并校验状态)
|
||||
*/
|
||||
private Map<String, WorkOrderDao> loadOrders(List<String> codes, boolean lock) {
|
||||
LambdaQueryWrapper<WorkOrderDao> query = new LambdaQueryWrapper<WorkOrderDao>()
|
||||
.in(WorkOrderDao::getOrder_code, codes);
|
||||
if (lock) {
|
||||
query.last("for update");
|
||||
}
|
||||
List<WorkOrderDao> list = orders.selectList(query);
|
||||
if (list.size() != codes.size()) {
|
||||
throw new BadRequestException("存在无效工单,请刷新后重选");
|
||||
}
|
||||
Map<String, WorkOrderDao> map = new LinkedHashMap<>();
|
||||
for (String code : codes) {
|
||||
for (WorkOrderDao order : list) {
|
||||
if (code.equals(order.getOrder_code())) {
|
||||
if (lock && order.getStatus() != 1 && order.getStatus() != 2) {
|
||||
throw new BadRequestException("工单状态不允许配送:" + code);
|
||||
}
|
||||
map.put(code, order);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private List<WorkOrderBomDao> loadBom(List<String> codes, boolean lock) {
|
||||
LambdaQueryWrapper<WorkOrderBomDao> query = new LambdaQueryWrapper<WorkOrderBomDao>()
|
||||
.in(WorkOrderBomDao::getWork_order_code, codes)
|
||||
.orderByAsc(WorkOrderBomDao::getItem_no);
|
||||
return boms.selectList(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 托盘数量按工单BOM剩余需求顺序分摊,超出剩余需求时报错
|
||||
*/
|
||||
private JSONArray allocateSources(List<WorkOrderBomDao> bomRows, Map<String, WorkOrderDao> orderMap,
|
||||
BigDecimal totalQty, String materialCode, String port) {
|
||||
JSONArray sources = new JSONArray();
|
||||
BigDecimal remaining = totalQty;
|
||||
for (WorkOrderBomDao bom : bomRows) {
|
||||
if (remaining.signum() <= 0) {
|
||||
break;
|
||||
}
|
||||
WorkOrderDao order = orderMap.get(bom.getWork_order_code());
|
||||
if (order == null) {
|
||||
continue;
|
||||
}
|
||||
int orderQty = order.getOrder_qty() == null ? 0 : order.getOrder_qty();
|
||||
BigDecimal need = decimal(bom.getBom_qty()).multiply(BigDecimal.valueOf(orderQty))
|
||||
.subtract(decimal(bom.getUse_bom_qty())).max(BigDecimal.ZERO);
|
||||
if (need.signum() <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isBlank(bom.getItem_id())) {
|
||||
throw new BadRequestException("工单BOM缺少EAS明细ID:" + bom.getWork_order_code());
|
||||
}
|
||||
BigDecimal take = need.min(remaining);
|
||||
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", take);
|
||||
sources.add(source);
|
||||
remaining = remaining.subtract(take);
|
||||
}
|
||||
if (remaining.signum() > 0) {
|
||||
JSONObject lastJsonObject = sources.getJSONObject(sources.size() - 1);
|
||||
lastJsonObject.put("qty", lastJsonObject.getBigDecimal("qty").add(remaining));
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
private String resolveBomWarehouse(List<WorkOrderBomDao> bomRows) {
|
||||
String warehouse = null;
|
||||
for (WorkOrderBomDao bom : bomRows) {
|
||||
String current = StringUtils.trimToNull(bom.getWarehouse_code());
|
||||
if (current == null) {
|
||||
throw new BadRequestException("工单BOM仓库编码为空:" + bom.getWork_order_code());
|
||||
}
|
||||
if (warehouse == null) {
|
||||
warehouse = current;
|
||||
} else if (!warehouse.equals(current)) {
|
||||
throw new BadRequestException("同一物料的BOM仓库不一致,请核对工单");
|
||||
}
|
||||
}
|
||||
return warehouse;
|
||||
}
|
||||
|
||||
/**
|
||||
* BOM warehouse_code 在库中为 decimal 类型,可能存在多余小数位,兼容归一化查询
|
||||
*/
|
||||
private BsrealStorattr resolveStore(String warehouseCode) {
|
||||
BsrealStorattr store = storeService.findByCode(warehouseCode);
|
||||
if (store != null) {
|
||||
return store;
|
||||
}
|
||||
try {
|
||||
String normalized = new BigDecimal(warehouseCode).stripTrailingZeros().toPlainString();
|
||||
return storeService.findByCode(normalized);
|
||||
} catch (NumberFormatException ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找上料口所在区域的空闲点位
|
||||
*/
|
||||
@@ -636,13 +427,4 @@ public class PlatingDeliveryServiceImpl implements PlatingDeliveryService {
|
||||
return codes.stream().filter(StringUtils::isNotBlank).map(String::trim).distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<String> normalizePorts(List<String> ports) {
|
||||
if (ports == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return ports.stream().filter(StringUtils::isNotBlank)
|
||||
.map(PlatingDemandServiceImpl::parseLoadPort)
|
||||
.filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package org.nl.wms.pm_manage.delivery.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
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.service.IMdPbGroupplateService;
|
||||
import org.nl.wms.warehouse_manage.service.dao.GroupPlate;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.strategy.CallbackStrategyPublish;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配盘直送出库结算:完成分配明细/出库明细/出库单并触发回传(MM057 调拨到线边库 X001),组盘转出库。
|
||||
* <p>
|
||||
* 两种触发场景共用:
|
||||
* <ul>
|
||||
* <li>AGV 配送:搬运任务送达完成后结算(PlatingDirectOutTask)</li>
|
||||
* <li>非 AGV:提交直送时直接出库过账</li>
|
||||
* </ul>
|
||||
* 组盘托盘尚未入库,WMS 侧不产生库存扣减。
|
||||
*/
|
||||
@Component
|
||||
public class PlatingDirectOutSettlement {
|
||||
|
||||
@Resource
|
||||
private IOStorInvDisMapper disMapper;
|
||||
@Resource
|
||||
private IOStorInvDtlMapper dtlMapper;
|
||||
@Resource
|
||||
private IOStorInvMapper billMapper;
|
||||
@Resource
|
||||
private IMdPbGroupplateService groups;
|
||||
@Resource
|
||||
private CallbackStrategyPublish callbackStrategyPublish;
|
||||
|
||||
/**
|
||||
* 按配送任务结算
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void settleByTask(String taskId, String endPointCode) {
|
||||
List<IOStorInvDis> disList = disMapper.selectList(new LambdaQueryWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getTask_id, taskId));
|
||||
settle(disList, endPointCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按出库单一次性结算(无AGV,直接出库过账)
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void settleByBill(String billId, String endPointCode) {
|
||||
List<IOStorInvDis> disList = disMapper.selectList(new LambdaQueryWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getIostorinv_id, billId));
|
||||
settle(disList, endPointCode);
|
||||
}
|
||||
|
||||
private void settle(List<IOStorInvDis> disList, String endPointCode) {
|
||||
if (disList == null || disList.isEmpty()) {
|
||||
throw new BadRequestException("未找到待结算的分配明细");
|
||||
}
|
||||
String billId = disList.get(0).getIostorinv_id();
|
||||
Set<String> detailIds = new LinkedHashSet<>();
|
||||
Set<String> pallets = new LinkedHashSet<>();
|
||||
for (IOStorInvDis dis : disList) {
|
||||
LambdaUpdateWrapper<IOStorInvDis> update = new LambdaUpdateWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getIostorinvdis_id, dis.getIostorinvdis_id())
|
||||
.set(IOStorInvDis::getWork_status, IOSEnum.INBILL_DIS_STATUS.code("完成"))
|
||||
.set(IOStorInvDis::getReal_qty, dis.getPlan_qty());
|
||||
if (StringUtils.isNotBlank(endPointCode)) {
|
||||
update.set(IOStorInvDis::getPoint_code, endPointCode);
|
||||
}
|
||||
disMapper.update(null, update);
|
||||
detailIds.add(dis.getIostorinvdtl_id());
|
||||
if (StringUtils.isNotBlank(dis.getStoragevehicle_code())) {
|
||||
pallets.add(dis.getStoragevehicle_code());
|
||||
}
|
||||
}
|
||||
for (String detailId : detailIds) {
|
||||
long unfinished = disMapper.selectCount(new LambdaQueryWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getIostorinvdtl_id, detailId)
|
||||
.ne(IOStorInvDis::getWork_status, IOSEnum.INBILL_DIS_STATUS.code("完成")));
|
||||
if (unfinished > 0) {
|
||||
continue;
|
||||
}
|
||||
IOStorInvDtl dtl = dtlMapper.selectById(detailId);
|
||||
if (dtl == null) {
|
||||
continue;
|
||||
}
|
||||
dtl.setReal_qty(dtl.getPlan_qty());
|
||||
dtl.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
|
||||
dtlMapper.updateById(dtl);
|
||||
// 调拨到线边库 X001,本地不维护线边库存
|
||||
callbackStrategyPublish.callbackStrategy(dtl.getCallback_strategy(), dtl);
|
||||
}
|
||||
long unfinishedDtl = dtlMapper.selectCount(new LambdaQueryWrapper<IOStorInvDtl>()
|
||||
.eq(IOStorInvDtl::getIostorinv_id, billId)
|
||||
.ne(IOStorInvDtl::getBill_status, IOSEnum.BILL_STATUS.code("完成")));
|
||||
if (unfinishedDtl == 0) {
|
||||
IOStorInv bill = new IOStorInv();
|
||||
bill.setIostorinv_id(billId);
|
||||
bill.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
|
||||
billMapper.updateById(bill);
|
||||
}
|
||||
// 组盘转出库
|
||||
if (!pallets.isEmpty()) {
|
||||
groups.update(new LambdaUpdateWrapper<GroupPlate>()
|
||||
.in(GroupPlate::getStoragevehicle_code, pallets)
|
||||
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("组盘"))
|
||||
.set(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("出库"))
|
||||
.set(GroupPlate::getFrozen_qty, BigDecimal.ZERO));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消/失败时解冻托盘,允许重新直送
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void releasePallets(Set<String> pallets) {
|
||||
if (pallets == null || pallets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
groups.update(new LambdaUpdateWrapper<GroupPlate>()
|
||||
.in(GroupPlate::getStoragevehicle_code, pallets)
|
||||
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("组盘"))
|
||||
.set(GroupPlate::getFrozen_qty, BigDecimal.ZERO));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
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.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.pm_manage.delivery.service.impl.PlatingDirectOutSettlement;
|
||||
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.core.TaskType;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
|
||||
import org.nl.wms.warehouse_manage.enums.IOSEnum;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.IOStorInvDis;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDisMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 配盘直送搬运任务(点对点):托盘处于组盘状态、尚未入库,因此没有库位绑定。
|
||||
* <p>
|
||||
* 起点为操作员扫描的起始点位(未扫则取托盘当前所在点位),终点为上料口区域的空闲点位。
|
||||
* 送达完成时结算关联的库存调拨出库单并触发 MM057 调拨到线边库 X001(出库过账);
|
||||
* 因托盘未入库,WMS 侧不产生库存扣减。
|
||||
*/
|
||||
@Component("PlatingDirectOutTask")
|
||||
@TaskType("PlatingDirectOutTask")
|
||||
public class PlatingDirectOutTask extends Point2PointTask {
|
||||
|
||||
@Resource
|
||||
private ISchBaseTaskService tasks;
|
||||
@Resource
|
||||
private ISchBasePointService points;
|
||||
@Resource
|
||||
private IOStorInvDisMapper disMapper;
|
||||
@Resource
|
||||
private PlatingDirectOutSettlement settlement;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String create(JSONObject json) {
|
||||
String startCode = json.getString("point_code1");
|
||||
String endCode = json.getString("point_code2");
|
||||
String pallet = json.getString("vehicle_code");
|
||||
if (StringUtils.isBlank(startCode) || StringUtils.isBlank(endCode) || StringUtils.isBlank(pallet)) {
|
||||
throw new BadRequestException("搬运起点、终点和托盘不能为空");
|
||||
}
|
||||
SchBasePoint end = points.getOne(new LambdaQueryWrapper<SchBasePoint>()
|
||||
.eq(SchBasePoint::getPoint_code, endCode).last("for update"));
|
||||
if (end == null || startCode.equals(endCode)
|
||||
|| (end.getVehicle_code() != null && !end.getVehicle_code().isEmpty())) {
|
||||
throw new BadRequestException("配送终点不可用");
|
||||
}
|
||||
long active = tasks.count(new LambdaQueryWrapper<SchBaseTask>()
|
||||
.eq(SchBaseTask::getVehicle_code, pallet)
|
||||
.notIn(SchBaseTask::getTask_status, Arrays.asList(TaskStatus.FINISHED.getCode(), TaskStatus.CANCELED.getCode())));
|
||||
if (active > 0) {
|
||||
throw new BadRequestException("该托盘存在未完成的搬运任务,请检查");
|
||||
}
|
||||
json.put("config_code", "PlatingDirectOutTask");
|
||||
String id = super.create(json);
|
||||
tasks.update(new LambdaUpdateWrapper<SchBaseTask>()
|
||||
.eq(SchBaseTask::getTask_id, id)
|
||||
.set(SchBaseTask::getIs_delete, false));
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateTaskStatus(String code, TaskStatus status) {
|
||||
SchBaseTask current = lock(code);
|
||||
if (TaskStatus.FINISHED.getCode().equals(current.getTask_status())
|
||||
|| TaskStatus.CANCELED.getCode().equals(current.getTask_status())) {
|
||||
return;
|
||||
}
|
||||
super.updateTaskStatus(code, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void forceFinish(String code) {
|
||||
finishTask(lock(code));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancel(String code) {
|
||||
lock(code);
|
||||
super.cancel(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void finishTask(SchBaseTask input) {
|
||||
SchBaseTask task = lock(input.getTask_code());
|
||||
if (TaskStatus.FINISHED.getCode().equals(task.getTask_status())) {
|
||||
return;
|
||||
}
|
||||
if (TaskStatus.CANCELED.getCode().equals(task.getTask_status())) {
|
||||
throw new BadRequestException("任务已取消");
|
||||
}
|
||||
super.finishTask(task);
|
||||
// 送达完成:出库过账并回传 MM057
|
||||
settlement.settleByTask(task.getTask_id(), task.getPoint_code2());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelTask(SchBaseTask input) {
|
||||
SchBaseTask task = lock(input.getTask_code());
|
||||
if (TaskStatus.CANCELED.getCode().equals(task.getTask_status())) {
|
||||
return;
|
||||
}
|
||||
if (TaskStatus.FINISHED.getCode().equals(task.getTask_status())) {
|
||||
throw new BadRequestException("已完成任务不能取消");
|
||||
}
|
||||
List<IOStorInvDis> disList = disMapper.selectList(new LambdaQueryWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getTask_id, task.getTask_id()));
|
||||
Set<String> pallets = new LinkedHashSet<>();
|
||||
for (IOStorInvDis dis : disList) {
|
||||
if (StringUtils.isNotBlank(dis.getStoragevehicle_code())) {
|
||||
pallets.add(dis.getStoragevehicle_code());
|
||||
}
|
||||
// 分配明细回退到未生成,允许重新直送
|
||||
disMapper.update(null, new LambdaUpdateWrapper<IOStorInvDis>()
|
||||
.eq(IOStorInvDis::getIostorinvdis_id, dis.getIostorinvdis_id())
|
||||
.set(IOStorInvDis::getTask_id, null)
|
||||
.set(IOStorInvDis::getWork_status, IOSEnum.INBILL_DIS_STATUS.code("未生成")));
|
||||
}
|
||||
settlement.releasePallets(pallets);
|
||||
super.cancelTask(task);
|
||||
}
|
||||
|
||||
private SchBaseTask lock(String code) {
|
||||
SchBaseTask task = tasks.getOne(new LambdaQueryWrapper<SchBaseTask>()
|
||||
.eq(SchBaseTask::getTask_code, code)
|
||||
.eq(SchBaseTask::getConfig_code, "PlatingDirectOutTask").last("for update"));
|
||||
if (task == null) {
|
||||
throw new BadRequestException("配盘直送任务不存在");
|
||||
}
|
||||
return task;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package org.nl.wms.warehouse_manage.stockReturn.strategy.core.impl.sap;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.MapOf;
|
||||
import org.nl.wms.ext_manage.sap.api.SapApi;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.MaterialTransferBody;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.MaterialTransferHeader;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.MaterialTransferItem;
|
||||
import org.nl.wms.ext_manage.sap.api.dto.MaterialTransferRequest;
|
||||
import org.nl.wms.ext_manage.sap.enums.SapConstant;
|
||||
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.IOStorInvDtl;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvDisMapper;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dao.mapper.IOStorInvMapper;
|
||||
import org.nl.wms.warehouse_manage.inAndOut.service.dto.IOStorInvDisDto;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.IPmStockReturnService;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.dao.PmStockReturn;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.service.enums.StockReturnStatusEnum;
|
||||
import org.nl.wms.warehouse_manage.stockReturn.strategy.core.CallbackStrategy;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配盘配送(PC 批量 / PDA 直送)送达完成回传 SAP MM057 物料转储。
|
||||
* <p>
|
||||
* 业务口径:配盘托盘出库到产线,SAP 侧使用 311 转储把物料从调出仓库调拨到线边库 X001。
|
||||
* 线边库库存由 SAP 管理,WMS 不再维护 X001 的本地库存,因此这里不做任何库存增加。
|
||||
*/
|
||||
@Service(value = "sapPlatingDeliveryMM057")
|
||||
@Slf4j
|
||||
public class SapPlatingDeliveryMM057 implements CallbackStrategy {
|
||||
|
||||
private static final DateTimeFormatter DATE_BASIC = DateTimeFormatter.BASIC_ISO_DATE;
|
||||
|
||||
/**
|
||||
* 线边库:SAP 库存地点
|
||||
*/
|
||||
public static final String LINE_SIDE_LGORT = "X001";
|
||||
|
||||
@Autowired
|
||||
private IPmStockReturnService iPmStockReturnService;
|
||||
@Resource
|
||||
private IOStorInvDisMapper ioStorInvDisMapper;
|
||||
@Autowired
|
||||
private IOStorInvMapper ioStorInvMapper;
|
||||
@Autowired
|
||||
private SapApi sapApi;
|
||||
|
||||
@Override
|
||||
public void buildCallback(IOStorInvDtl param) {
|
||||
if (param == null) {
|
||||
return;
|
||||
}
|
||||
List<IOStorInvDisDto> disSet = ioStorInvDisMapper.queryOutBillDisDtl(
|
||||
MapOf.of("iostorinvdtl_id", param.getIostorinvdtl_id()));
|
||||
IOStorInv storInv = loadStorInv(param);
|
||||
if (storInv == null || StrUtil.isBlank(storInv.getStor_code())) {
|
||||
throw new BadRequestException("配盘配送调拨回传失败:出库单缺少调出仓库");
|
||||
}
|
||||
MaterialTransferRequest request = buildMaterialTransferRequest(param, storInv, disSet);
|
||||
PmStockReturn stockReturn = new PmStockReturn();
|
||||
stockReturn.setRequest_Id(param.getIostorinv_id());
|
||||
stockReturn.setRequest_type(IOSEnum.BILL_TYPE.code("库存调拨"));
|
||||
stockReturn.setStatus(StockReturnStatusEnum.TODO.getCode());
|
||||
stockReturn.setCreate_time(DateUtil.now());
|
||||
stockReturn.setRequest_data(JSON.toJSONString(request));
|
||||
try {
|
||||
JSONObject sapResult = sapApi.materialTransfer(request);
|
||||
stockReturn.setStatus(StockReturnStatusEnum.SUCESS.getCode());
|
||||
stockReturn.setProcess_time(DateUtil.now());
|
||||
JSONObject record = new JSONObject();
|
||||
record.put("request", request);
|
||||
record.put("response", sapResult);
|
||||
stockReturn.setRequest_data(record.toJSONString());
|
||||
} catch (Exception e) {
|
||||
log.error("出库单{}配盘配送调拨回传SAP失败", param.getIostorinv_id(), e);
|
||||
stockReturn.setError_msg(e.getMessage());
|
||||
stockReturn.setStatus(StockReturnStatusEnum.FAIL.getCode());
|
||||
stockReturn.setProcess_time(DateUtil.now());
|
||||
}
|
||||
iPmStockReturnService.save(stockReturn);
|
||||
}
|
||||
|
||||
private MaterialTransferRequest buildMaterialTransferRequest(IOStorInvDtl param, IOStorInv storInv,
|
||||
List<IOStorInvDisDto> disSet) {
|
||||
String today = LocalDate.now().format(DATE_BASIC);
|
||||
MaterialTransferRequest request = new MaterialTransferRequest();
|
||||
|
||||
MaterialTransferHeader header = new MaterialTransferHeader();
|
||||
header.setIntfId(SapConstant.INTF_MM057);
|
||||
header.setSrcSystem(SapConstant.SRC_SYSTEM);
|
||||
header.setDestSystem(SapConstant.DEST_SYSTEM);
|
||||
header.setSrcMsgid("MSG" + System.currentTimeMillis());
|
||||
header.setRequesttime("");
|
||||
header.setBackup1("");
|
||||
header.setBackup2("");
|
||||
request.setHeader(header);
|
||||
|
||||
MaterialTransferBody body = new MaterialTransferBody();
|
||||
body.setBktxt(StrUtil.blankToDefault(param.getIostorinv_id(), param.getIostorinvdtl_id()));
|
||||
body.setBldat(today);
|
||||
body.setBudat(today);
|
||||
body.setItems(buildTransferItems(param, storInv, disSet));
|
||||
request.setBody(Collections.singletonList(body));
|
||||
return request;
|
||||
}
|
||||
|
||||
private List<MaterialTransferItem> buildTransferItems(IOStorInvDtl param, IOStorInv storInv,
|
||||
List<IOStorInvDisDto> disSet) {
|
||||
List<MaterialTransferItem> items = new ArrayList<>();
|
||||
if (disSet == null || disSet.isEmpty()) {
|
||||
items.add(toTransferItem(param, storInv, null));
|
||||
return items;
|
||||
}
|
||||
for (IOStorInvDisDto dis : disSet) {
|
||||
items.add(toTransferItem(param, storInv, dis));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private MaterialTransferItem toTransferItem(IOStorInvDtl param, IOStorInv storInv, IOStorInvDisDto dis) {
|
||||
MaterialTransferItem item = new MaterialTransferItem();
|
||||
String pcsn = dis != null ? dis.getPcsn() : param.getPcsn();
|
||||
item.setUmcha(isRealPcsn(pcsn) ? pcsn : "");
|
||||
item.setMatnr(StrUtil.blankToDefault(
|
||||
dis != null ? dis.getMaterial_code() : null, param.getMaterial_code()));
|
||||
item.setKdpos("");
|
||||
item.setUmmat(item.getMatnr());
|
||||
item.setMatKdpos(item.getMatnr());
|
||||
item.setMatKdauf("");
|
||||
item.setLifnr("");
|
||||
item.setWerks(SapConstant.WERKS);
|
||||
item.setZeile(StrUtil.blankToDefault(
|
||||
dis != null ? dis.getIostorinvdis_id() : null, param.getIostorinvdtl_id()));
|
||||
// 311:库存地点之间的转储
|
||||
item.setBwart(SapConstant.BWART_TRANSFER_311);
|
||||
item.setLgort(StrUtil.blankToDefault(
|
||||
storInv.getStor_code(),
|
||||
dis != null ? dis.getSect_code() : ""));
|
||||
item.setMeins(StrUtil.blankToDefault(
|
||||
dis != null ? dis.getQty_unit_name() : null, param.getQty_unit_name()));
|
||||
item.setMenge(resolveQty(param, dis).doubleValue());
|
||||
item.setUmwrk(SapConstant.WERKS);
|
||||
item.setSobkz("");
|
||||
// 目标:线边库 X001
|
||||
item.setUmlgo(LINE_SIDE_LGORT);
|
||||
return item;
|
||||
}
|
||||
|
||||
private IOStorInv loadStorInv(IOStorInvDtl param) {
|
||||
if (param == null || StrUtil.isBlank(param.getIostorinv_id())) {
|
||||
return null;
|
||||
}
|
||||
return ioStorInvMapper.selectOne(new LambdaQueryWrapper<IOStorInv>()
|
||||
.eq(IOStorInv::getIostorinv_id, param.getIostorinv_id())
|
||||
.select(IOStorInv::getStor_code));
|
||||
}
|
||||
|
||||
private BigDecimal resolveQty(IOStorInvDtl param, IOStorInvDisDto dis) {
|
||||
if (dis != null) {
|
||||
if (dis.getReal_qty() != null && dis.getReal_qty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return dis.getReal_qty();
|
||||
}
|
||||
if (dis.getPlan_qty() != null && dis.getPlan_qty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return dis.getPlan_qty();
|
||||
}
|
||||
}
|
||||
if (param.getReal_qty() != null && param.getReal_qty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return param.getReal_qty();
|
||||
}
|
||||
if (param.getAssign_qty() != null && param.getAssign_qty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return param.getAssign_qty();
|
||||
}
|
||||
if (param.getPlan_qty() != null && param.getPlan_qty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return param.getPlan_qty();
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private boolean isRealPcsn(String pcsn) {
|
||||
return StrUtil.isNotBlank(pcsn) && !"1".equals(pcsn);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user