add:配盘出库,工单下发根据产线修改bom仓库,点对点任务优化

This commit is contained in:
zhaoyf
2026-09-19 15:11:07 +08:00
parent ce020e98aa
commit 26552ec765
12 changed files with 274 additions and 148 deletions

View File

@@ -14,11 +14,9 @@ import org.nl.wms.ext_manage.mes.mq.producer.WorkReportProducer;
import org.nl.wms.ext_manage.mes.service.dto.WorkReportParam;
import org.nl.wms.ext_manage.service.MesToWmsService;
import org.nl.wms.ext_manage.service.WmsToZDWmdService;
import org.nl.wms.ext_manage.service.dto.FeedingRecordPushDto;
import org.nl.wms.ext_manage.service.dto.MesTaskParams;
import org.nl.wms.ext_manage.service.dto.ZDInventory;
import org.nl.wms.pm_manage.demand.service.IPmDemandPlatingService;
import org.nl.wms.ext_manage.service.dto.*;
import org.nl.wms.pm_manage.demand.service.IPlatingDemandService;
import org.nl.wms.pm_manage.demand.service.IPmDemandPlatingService;
import org.nl.wms.pm_manage.demand.service.IPmDemandService;
import org.nl.wms.pm_manage.demand.service.dto.PmDemandParam;
import org.nl.wms.pm_manage.pmreturn.service.IPmReturnService;
@@ -32,6 +30,7 @@ import org.nl.wms.welding_manage.service.work_order.IWorkOrderService;
import org.nl.wms.welding_manage.service.work_order.dto.WorkOrderDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -61,6 +60,8 @@ public class MesToWmsController {
private IPmDemandService iPmDemandService;
@Autowired
private IPmDemandPlatingService iPmDemandPlatingService;
@Autowired
private IPlatingDemandService platingDemandService;
@Autowired
private IStInventoryService iStInventoryService;
@@ -91,13 +92,27 @@ public class MesToWmsController {
@PostMapping("api/mes/subWorkOrder")
@SaIgnore
@Log("工单同步")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity subWorkOrder(@RequestBody List<WorkOrderDto.WorkOrderDataDto> dtos){
String[] filter = {};//过滤产线
String[] filterOnDemand = {"E317"};//下发需求产线过滤
List<String> orderCodes = new ArrayList<>();
for (WorkOrderDto.WorkOrderDataDto dto : dtos) {
if (!ArrayUtils.contains(filter, dto.getWorkArea())){
if (ArrayUtils.contains(filterOnDemand, dto.getWorkArea())){
orderCodes.add(dto.getOrderCode());
dto.getWorkOrderBomList().forEach(bom -> {
bom.setWarehouseCode("6.011.03");
bom.setWarehouseName("五期智能结构件仓库");
});
}
iWorkOrderService.insert(dto);
}
}
if (!orderCodes.isEmpty()) {
platingDemandService.issueFromMes(orderCodes);
}
return ResponseData.build();
}
@@ -251,4 +266,4 @@ public class MesToWmsController {
feedingRecordService.pushFeedingBill(param);
return ResponseData.build();
}
}
}

View File

@@ -143,7 +143,7 @@ public class MesToWmsServiceImpl implements MesToWmsService {
.eq(SchBasePoint::getPoint_type, "1"));
if (matPoints.isEmpty()) {
throw new BadRequestException("叫满任务失败,库存没有当前下料口的组盘物料");
throw new BadRequestException("叫满任务失败,缺少当前上料口配盘物料");
}
SchBasePoint start_point = matPoints.get(0);
String veh = start_point.getVehicle_code();

View File

@@ -17,8 +17,8 @@ public class PlatingDemandController {
@Resource private IPlatingDemandService platingDemandService;
@GetMapping
public ResponseEntity<Object> page(PageQuery page, String workOrderCode, Integer status) {
return ResponseData.build(platingDemandService.page(page.getPage() + 1L, page.getSize(), workOrderCode, status), HttpStatus.OK);
public ResponseEntity<Object> page(PageQuery page, String workOrderCode, String workArea, String loadPort, Integer status) {
return ResponseData.build(platingDemandService.page(page.getPage() + 1L, page.getSize(), workOrderCode, workArea, loadPort, status), HttpStatus.OK);
}
@PostMapping("/preview")

View File

@@ -9,7 +9,8 @@ import java.util.List;
public interface IPlatingDemandService {
List<PlatingDemandDto> preview(List<String> workOrderCodes);
void issue(List<String> workOrderCodes);
Page<PlatingDemandDto> page(long current, long size, String workOrderCode, Integer status);
void issueFromMes(List<String> workOrderCodes);
Page<PlatingDemandDto> page(long current, long size, String workOrderCode, String workArea, String loadPort, Integer status);
List<PlatingDemandDto> unfinished();
PlatingDemandDto detail(String id);
void complete(String id, PlatingDemandCompleteParam param);

View File

@@ -21,4 +21,6 @@ public class PmPlatingDemandItem {
private String warehouse_code;
private String warehouse_name;
private BigDecimal demand_qty;
private BigDecimal allocated_qty;
private Integer is_ignored;
}

View File

@@ -2,9 +2,21 @@ package org.nl.wms.pm_manage.demand.service.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class PlatingDemandCompleteParam {
private String palletCode;
private String storeCode;
private String pointCode;
private List<Item> items;
@Data
public static class Item {
private String itemId;
private String materialCode;
private BigDecimal qty;
private Boolean ignored;
}
}

View File

@@ -27,5 +27,7 @@ public class PlatingDemandDto {
private String warehouseCode;
private String warehouseName;
private BigDecimal demandQty;
private BigDecimal allocatedQty;
private Integer ignored;
}
}

View File

@@ -54,6 +54,8 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.nl.wms.warehouse_manage.enums.IOSEnum.GROUP_PLATE_STATUS;
@Service
public class PlatingDemandServiceImpl implements IPlatingDemandService {
@Resource
@@ -79,9 +81,9 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
@Resource
private IPmStockReturnService stockReturnService;
@Resource
private ISchBasePointService schBasePointService;
@Resource
private IMdPbStoragevehicleinfoService storagevehicleinfoService;
@Resource
private ISchBasePointService pointService;
@Override
public List<PlatingDemandDto> preview(List<String> workOrderCodes) {
@@ -116,37 +118,58 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
.eq(PmPlatingDemand::getLoad_port, preview.getLoadPort())) > 0) {
throw new BadRequestException("工单" + preview.getWorkOrderCode() + "上料口" + preview.getLoadPort() + "已下发需求单");
}
PmPlatingDemand demand = new PmPlatingDemand();
demand.setId(IdUtil.getStringId());
demand.setDemand_code("PD" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + UUID.randomUUID().toString().replace("-", "").substring(0, 6).toUpperCase());
demand.setWork_order_code(preview.getWorkOrderCode());
demand.setLoad_port(preview.getLoadPort());
demand.setWork_area(preview.getWorkArea());
demand.setStatus(0);
demand.setCreate_by(SecurityUtils.getCurrentNickName());
demand.setCreate_time(DateUtil.now());
demandMapper.insert(demand);
for (PlatingDemandDto.Item item : preview.getItems()) {
PmPlatingDemandItem entity = new PmPlatingDemandItem();
entity.setId(IdUtil.getStringId());
entity.setDemand_id(demand.getId());
entity.setBom_item_id(item.getId());
entity.setMaterial_code(item.getMaterialCode());
entity.setMaterial_name(item.getMaterialName());
entity.setSpec(item.getSpec());
entity.setUnit(item.getUnit());
entity.setWarehouse_code(item.getWarehouseCode());
entity.setWarehouse_name(item.getWarehouseName());
entity.setDemand_qty(item.getDemandQty());
itemMapper.insert(entity);
}
saveDemand(preview);
}
}
@Override
public Page<PlatingDemandDto> page(long current, long size, String workOrderCode, Integer status) {
@Transactional(rollbackFor = Exception.class)
public void issueFromMes(List<String> workOrderCodes) {
for (PlatingDemandDto preview : preview(workOrderCodes)) {
if (demandMapper.selectCount(new LambdaQueryWrapper<PmPlatingDemand>()
.eq(PmPlatingDemand::getWork_order_code, preview.getWorkOrderCode())
.eq(PmPlatingDemand::getLoad_port, preview.getLoadPort())) > 0) {
continue;
}
saveDemand(preview);
}
}
private void saveDemand(PlatingDemandDto preview) {
PmPlatingDemand demand = new PmPlatingDemand();
demand.setId(IdUtil.getStringId());
demand.setDemand_code("PD" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + UUID.randomUUID().toString().replace("-", "").substring(0, 6).toUpperCase());
demand.setWork_order_code(preview.getWorkOrderCode());
demand.setLoad_port(preview.getLoadPort());
demand.setWork_area(preview.getWorkArea());
demand.setStatus(0);
demand.setCreate_by(SecurityUtils.getCurrentNickName());
demand.setCreate_time(DateUtil.now());
demandMapper.insert(demand);
for (PlatingDemandDto.Item item : preview.getItems()) {
PmPlatingDemandItem entity = new PmPlatingDemandItem();
entity.setId(IdUtil.getStringId());
entity.setDemand_id(demand.getId());
entity.setBom_item_id(item.getId());
entity.setMaterial_code(item.getMaterialCode());
entity.setMaterial_name(item.getMaterialName());
entity.setSpec(item.getSpec());
entity.setUnit(item.getUnit());
entity.setWarehouse_code(item.getWarehouseCode());
entity.setWarehouse_name(item.getWarehouseName());
entity.setDemand_qty(item.getDemandQty());
entity.setAllocated_qty(BigDecimal.ZERO);
entity.setIs_ignored(0);
itemMapper.insert(entity);
}
}
@Override
public Page<PlatingDemandDto> page(long current, long size, String workOrderCode, String workArea, String loadPort, Integer status) {
Page<PmPlatingDemand> page = demandMapper.selectPage(new Page<PmPlatingDemand>(current, size), new LambdaQueryWrapper<PmPlatingDemand>()
.eq(workOrderCode != null && !workOrderCode.trim().isEmpty(), PmPlatingDemand::getWork_order_code, workOrderCode)
.eq(workArea != null && !workArea.trim().isEmpty(), PmPlatingDemand::getWork_area, workArea)
.like(loadPort != null && !loadPort.trim().isEmpty(), PmPlatingDemand::getLoad_port, loadPort)
.eq(status != null, PmPlatingDemand::getStatus, status).orderByDesc(PmPlatingDemand::getCreate_time));
Page<PlatingDemandDto> result = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
result.setRecords(page.getRecords().stream().map(this::toDto).collect(Collectors.toList()));
@@ -156,6 +179,7 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
@Override
public List<PlatingDemandDto> unfinished() {
return demandMapper.selectList(new LambdaQueryWrapper<PmPlatingDemand>().lt(PmPlatingDemand::getStatus, 2)
.orderByAsc(PmPlatingDemand::getLoad_port)
.orderByAsc(PmPlatingDemand::getCreate_time)).stream().map(this::toDto).collect(Collectors.toList());
}
@@ -174,26 +198,102 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
@Override
@Transactional(rollbackFor = Exception.class)
public void complete(String id, PlatingDemandCompleteParam param) {
SchBasePoint point = schBasePointService.selectByCode(param.getPointCode());
if (point == null) throw new BadRequestException("点位不存在:" + param.getPointCode());
PmPlatingDemand demand = demandMapper.selectById(id);
if (demand == null || demand.getStatus() == 2) throw new BadRequestException("需求单不存在或已完成");
if (param == null || param.getPalletCode() == null || param.getPalletCode().trim().isEmpty())
throw new BadRequestException("请输入托盘编码");
storagevehicleinfoService.chackAndInsert(param.getPalletCode());
if (param == null || CollectionUtils.isEmpty(param.getItems()))
throw new BadRequestException("请填写本次配盘物料");
List<PmPlatingDemandItem> items = items(id);
List<GroupPlate> plates = groupplateService.list(new LambdaQueryWrapper<GroupPlate>().eq(GroupPlate::getStoragevehicle_code, param.getPalletCode()).ne(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("出库")));
Map<String, BigDecimal> palletQty = plates.stream().collect(Collectors.groupingBy(GroupPlate::getMaterial_code, Collectors.mapping(GroupPlate::getQty, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
for (PmPlatingDemandItem item : items)
if (palletQty.getOrDefault(item.getMaterial_code(), BigDecimal.ZERO).compareTo(item.getDemand_qty()) < 0)
throw new BadRequestException("托盘物料不足:" + item.getMaterial_code());
Structattr struct = structattrService.getOne(new LambdaQueryWrapper<Structattr>().eq(Structattr::getSect_code, param.getStoreCode()).last("limit 1"));
if (struct == null) throw new BadRequestException("托盘未绑定库位:" + param.getPalletCode());
saveOutbound(demand, items, struct, param.getPalletCode());
demandMapper.update(null, new LambdaUpdateWrapper<PmPlatingDemand>().eq(PmPlatingDemand::getId, id).set(PmPlatingDemand::getStatus, 2).set(PmPlatingDemand::getPallet_code, param.getPalletCode()).set(PmPlatingDemand::getFinish_time, DateUtil.now()));
Map<String, PmPlatingDemandItem> itemMap = items.stream().collect(Collectors.toMap(PmPlatingDemandItem::getId, Function.identity()));
Map<PmPlatingDemandItem, BigDecimal> allocations = new LinkedHashMap<>();
boolean changed = false;
for (PlatingDemandCompleteParam.Item input : param.getItems()) {
PmPlatingDemandItem item = itemMap.get(input.getItemId());
if (item == null) throw new BadRequestException("需求单物料明细不存在:" + input.getItemId());
BigDecimal allocated = item.getAllocated_qty() == null ? BigDecimal.ZERO : item.getAllocated_qty();
BigDecimal qty = input.getQty() == null ? BigDecimal.ZERO : input.getQty();
if (qty.compareTo(BigDecimal.ZERO) < 0) throw new BadRequestException("配盘数量不能小于0");
if (Boolean.TRUE.equals(input.getIgnored())) {
if (qty.compareTo(BigDecimal.ZERO) > 0) throw new BadRequestException("忽略物料的本次配盘数量必须为0");
if (!Objects.equals(item.getIs_ignored(), 1)) changed = true;
itemMapper.update(null, new LambdaUpdateWrapper<PmPlatingDemandItem>()
.eq(PmPlatingDemandItem::getId, item.getId()).set(PmPlatingDemandItem::getIs_ignored, 1));
continue;
}
if (Objects.equals(item.getIs_ignored(), 1)) throw new BadRequestException("已忽略的物料不能继续配盘");
if (allocated.add(qty).compareTo(item.getDemand_qty()) > 0)
throw new BadRequestException("物料配盘数量超过剩余需求:" + item.getMaterial_code());
if (qty.compareTo(BigDecimal.ZERO) > 0) {
allocations.put(item, qty);
changed = true;
}
}
if (!changed) throw new BadRequestException("请填写配盘数量或选择需要忽略的物料");
if (!allocations.isEmpty()) {
if (param.getPalletCode() == null || param.getPalletCode().trim().isEmpty())
throw new BadRequestException("请输入托盘编码");
storagevehicleinfoService.chackAndInsert(param.getPalletCode());
// List<GroupPlate> plates = groupplateService.list(new LambdaQueryWrapper<GroupPlate>()
// .eq(GroupPlate::getStoragevehicle_code, param.getPalletCode())
// .ne(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("出库")));
// Map<String, BigDecimal> palletQty = plates.stream().collect(Collectors.groupingBy(GroupPlate::getMaterial_code,
// Collectors.mapping(GroupPlate::getQty, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
// Map<String, BigDecimal> requested = allocations.entrySet().stream().collect(Collectors.groupingBy(
// entry -> entry.getKey().getMaterial_code(), Collectors.mapping(Map.Entry::getValue, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
// for (Map.Entry<String, BigDecimal> entry : requested.entrySet()) {
// if (palletQty.getOrDefault(entry.getKey(), BigDecimal.ZERO).compareTo(entry.getValue()) < 0)
// throw new BadRequestException("托盘物料不足:" + entry.getKey());
// }
Structattr struct = structattrService.getOne(new LambdaQueryWrapper<Structattr>()
.eq(Structattr::getSect_code, param.getStoreCode()).last("limit 1"));
if (struct == null) {
throw new BadRequestException("仓库未创建库位:" + param.getStoreCode());
}
saveOutbound(demand, allocations, struct, struct.getStoragevehicle_code());
for (PlatingDemandCompleteParam.Item item : param.getItems()) {
MdMeMaterialbase materialbase = materialService.getByCode(item.getMaterialCode());
//组盘
GroupPlate plateDao = GroupPlate.builder()
.group_id(IdUtil.getStringId())
.material_code(materialbase.getMaterial_code())
.storagevehicle_code(param.getPalletCode())
.pcsn("1")
.qty_unit_id(materialbase.getQty_unit_id())
.qty_unit_name(materialbase.getQty_unit_name())
.qty(item.getQty())
.status(GROUP_PLATE_STATUS.code("出库"))
.load_port(demand.getLoad_port())
.ext_code("")
.ext_type("")
.ext_dtl_code("")
.create_id(SecurityUtils.getCurrentUserId())
.create_name(SecurityUtils.getCurrentNickName())
.create_time(DateUtil.now())
.build();
groupplateService.save(plateDao);
}
pointService.update(new LambdaUpdateWrapper<SchBasePoint>()
.set(SchBasePoint::getVehicle_code, param.getPalletCode())
.eq(SchBasePoint::getPoint_code, param.getPointCode()));//绑定点位
for (Map.Entry<PmPlatingDemandItem, BigDecimal> entry : allocations.entrySet()) {
BigDecimal allocated = entry.getKey().getAllocated_qty() == null ? BigDecimal.ZERO : entry.getKey().getAllocated_qty();
itemMapper.update(null, new LambdaUpdateWrapper<PmPlatingDemandItem>()
.eq(PmPlatingDemandItem::getId, entry.getKey().getId())
.set(PmPlatingDemandItem::getAllocated_qty, allocated.add(entry.getValue())));
}
}
List<PmPlatingDemandItem> currentItems = items(id);
boolean finished = currentItems.stream().allMatch(item -> Objects.equals(item.getIs_ignored(), 1)
|| (item.getAllocated_qty() != null && item.getAllocated_qty().compareTo(item.getDemand_qty()) >= 0));
LambdaUpdateWrapper<PmPlatingDemand> update = new LambdaUpdateWrapper<PmPlatingDemand>()
.eq(PmPlatingDemand::getId, id).set(PmPlatingDemand::getStatus, finished ? 2 : 1);
if (param.getPalletCode() != null && !param.getPalletCode().trim().isEmpty())
update.set(PmPlatingDemand::getPallet_code, param.getPalletCode());
if (finished) update.set(PmPlatingDemand::getFinish_time, DateUtil.now());
demandMapper.update(null, update);
}
private void saveOutbound(PmPlatingDemand demand, List<PmPlatingDemandItem> items, Structattr struct, String palletCode) {
private void saveOutbound(PmPlatingDemand demand, Map<PmPlatingDemandItem, BigDecimal> allocations, Structattr struct, String palletCode) {
List<PmPlatingDemandItem> items = new ArrayList<>(allocations.keySet());
Map<String, MdMeMaterialbase> materials = materialService.list(new LambdaQueryWrapper<MdMeMaterialbase>().in(MdMeMaterialbase::getMaterial_code, items.stream().map(PmPlatingDemandItem::getMaterial_code).collect(Collectors.toList()))).stream().collect(Collectors.toMap(MdMeMaterialbase::getMaterial_code, Function.identity()));
WorkOrderDao order = workOrderService.getWorkOrder(demand.getWork_order_code());
IOStorInv bill = new IOStorInv();
@@ -220,6 +320,7 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
int seq = 1;
Map<String, WorkOrderBomDao> boms = workOrderService.getOrderBomItem(demand.getWork_order_code()).stream().collect(Collectors.toMap(WorkOrderBomDao::getId, Function.identity()));
for (PmPlatingDemandItem item : items) {
BigDecimal qty = allocations.get(item);
MdMeMaterialbase material = materials.get(item.getMaterial_code());
if (material == null) throw new BadRequestException("物料不存在:" + item.getMaterial_code());
IOStorInvDtl detail = new IOStorInvDtl();
@@ -232,8 +333,8 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
detail.setQty_unit_name(material.getQty_unit_name());
detail.setPcsn("1");
detail.setBill_status(IOSEnum.BILL_STATUS.code("完成"));
detail.setPlan_qty(item.getDemand_qty());
detail.setAssign_qty(item.getDemand_qty());
detail.setPlan_qty(qty);
detail.setAssign_qty(qty);
detail.setUnassign_qty(BigDecimal.ZERO);
detail.setSource_bill_code(demand.getWork_order_code());
detail.setSource_bill_type("work_order");
@@ -253,16 +354,16 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
dis.setIs_issued(BaseDataEnum.IS_YES_NOT.code("是"));
dis.setQty_unit_id(material.getQty_unit_id());
dis.setQty_unit_name(material.getQty_unit_name());
dis.setPlan_qty(item.getDemand_qty());
dis.setReal_qty(item.getDemand_qty());
dis.setPlan_qty(qty);
dis.setReal_qty(qty);
distributions.add(dis);
changes.add(OutFinishParam.builder().storagevehicleCode(palletCode).sectCode(struct.getSect_code()).structCode(struct.getStruct_code()).materialCode(item.getMaterial_code()).changeQty(item.getDemand_qty()).build());
changes.add(OutFinishParam.builder().storagevehicleCode(palletCode).sectCode(struct.getSect_code()).structCode(struct.getStruct_code()).materialCode(item.getMaterial_code()).changeQty(qty).build());
WorkOrderBomDao bom = boms.get(item.getBom_item_id());
JSONObject entry = new JSONObject();
entry.put("srcbillno", demand.getWork_order_code());
entry.put("srcbillid", order.getOrder_id());
entry.put("srcbillentryid", bom == null ? null : bom.getItem_id());
entry.put("qty", item.getDemand_qty());
entry.put("qty", qty);
entries.add(entry);
}
ioStorInvMapper.insert(bill);
@@ -324,7 +425,7 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
private PlatingDemandDto.Item toItem(PmPlatingDemandItem item) {
PlatingDemandDto.Item dto = new PlatingDemandDto.Item();
dto.setId(item.getBom_item_id());
dto.setId(item.getId());
dto.setMaterialCode(item.getMaterial_code());
dto.setMaterialName(item.getMaterial_name());
dto.setSpec(item.getSpec());
@@ -332,6 +433,8 @@ public class PlatingDemandServiceImpl implements IPlatingDemandService {
dto.setWarehouseCode(item.getWarehouse_code());
dto.setWarehouseName(item.getWarehouse_name());
dto.setDemandQty(item.getDemand_qty());
dto.setAllocatedQty(item.getAllocated_qty() == null ? BigDecimal.ZERO : item.getAllocated_qty());
dto.setIgnored(item.getIs_ignored() == null ? 0 : item.getIs_ignored());
return dto;
}
}

View File

@@ -2,16 +2,13 @@ package org.nl.wms.sch_manage.service.core.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.nl.common.exception.BadRequestException;
import org.nl.common.utils.CodeUtil;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.wms.basedata_manage.service.IStructattrService;
import org.nl.wms.ext_manage.util.ErpUtil;
import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBasePointService;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
@@ -22,19 +19,12 @@ 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.service.IMdPbGroupplateService;
import org.nl.wms.warehouse_manage.service.dao.GroupPlate;
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.welding_manage.service.work_order.IWorkOrderService;
import org.nl.wms.welding_manage.service.work_order.dao.WorkOrderBomDao;
import org.nl.wms.welding_manage.service.work_order.dao.WorkOrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 点对点搬运任务
*/
@@ -172,64 +162,6 @@ public class Point2PointTask extends AbstractTask {
taskObj.setRemark("已完成");
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskService.updateById(taskObj);
//获取组盘信息
String workOrderCode = taskObj.getExt_group_data();
String vehicleCode = taskObj.getVehicle_code();
List<GroupPlate> groupList = iMdPbGroupplateService.list(new LambdaQueryWrapper<GroupPlate>()
.eq(GroupPlate::getStoragevehicle_code, vehicleCode)
.eq(GroupPlate::getExt_code, workOrderCode)
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("组盘")));
//获取工单信息
WorkOrderDao workOrder = iWorkOrderService.getWorkOrder(workOrderCode);
List<WorkOrderBomDao> orderBomItems = iWorkOrderService.getOrderBomItem(workOrderCode);
// 创建最外层的JSONObject
JSONObject root = new JSONObject();
root.put("method", "DealLLDBBill");
root.put("type", "WMS");
// 创建data对象
JSONObject data = new JSONObject();
data.put("billNo", taskObj.getTask_id());
data.put("bizTypeNo", "331");
data.put("issueStorageOrgUnitNo", workOrder.getOrg_code());
data.put("receiptStorageOrgUnitNo", workOrder.getOrg_code());
// 创建entrys数组
JSONArray entrys = new JSONArray();
for (GroupPlate plate : groupList) {
for (WorkOrderBomDao orderBomItem : orderBomItems) {
if (plate.getMaterial_code().equals(orderBomItem.getMaterial_code())){
JSONObject entry = new JSONObject();
entry.put("qty", plate.getQty());
entry.put("materialNo", orderBomItem.getMaterial_code());
entry.put("unitNo", "PCS");
entry.put("receiptWarehouseNo", workOrder.getDefault_warehouse_code());
entry.put("issueWarehouseNo", orderBomItem.getWarehouse_code());
// 将entry添加到数组中
entrys.add(entry);
}
}
}
// 将entrys数组设置到data中
data.put("entrys", entrys);
// 将data设置到根对象中
root.put("data", data);
// ErpUtil.create().login().audit(root.toJSONString());
//保存回传单
PmStockReturn stockReturn = new PmStockReturn();
stockReturn.setRequest_Id(workOrder.getOrder_id());
stockReturn.setRequest_type(IOSEnum.BILL_TYPE.code("库存调拨"));
stockReturn.setStatus(StockReturnStatusEnum.TODO.getCode()); // 0-处理中
stockReturn.setCreate_time(DateUtil.now());
stockReturn.setRequest_data(root.toJSONString());
//调erp业务接口
try {
ErpUtil.create().login().audit(root.toJSONString());
stockReturn.setStatus(StockReturnStatusEnum.SUCESS.getCode());
} catch (Exception e) {
stockReturn.setError_msg(e.getMessage());
stockReturn.setStatus(StockReturnStatusEnum.FAIL.getCode());
}
iPmStockReturnService.save(stockReturn);
}
@Transactional