package com.zy.asrs.wms.asrs.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.wms.asrs.entity.*; import com.zy.asrs.wms.asrs.entity.enums.*; import com.zy.asrs.wms.asrs.entity.enums.OrderType; import com.zy.asrs.wms.asrs.entity.param.BatchMergeOrdersParam; import com.zy.asrs.wms.asrs.entity.param.GeneratePakInParam; import com.zy.asrs.wms.asrs.entity.param.PakinOnShelvesParams; import com.zy.asrs.wms.asrs.service.*; import com.zy.asrs.wms.system.entity.Host; import com.zy.asrs.wms.system.service.HostService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @Service public class MobileServiceImpl implements MobileService { @Autowired private WaitPakinService waitPakinService; @Autowired private WaitPakinLogService waitPakinLogService; @Autowired private WorkService workService; @Autowired private HostService hostService; @Autowired private OrderService orderService; @Autowired private OrderLogService orderLogService; @Autowired private LocService locService; @Autowired private LocDetlService locDetlService; @Autowired private LocAreaService locAreaService; @Autowired private LocAreaTypeService locAreaTypeService; @Override @Transactional(rollbackFor = Exception.class) public boolean batchMergeOrders(BatchMergeOrdersParam ordersParam) { Order order = orderService.getOne(new LambdaQueryWrapper().eq(Order::getOrderNo, ordersParam.getOrderNo())); if (Objects.isNull(order)) { throw new CoolException("订单不存在!!"); } ArrayList waitPakins = new ArrayList<>(); ordersParam.getOrderDetls().forEach(orderdetl -> { WaitPakin waitPakin = new WaitPakin(); waitPakin.setBatch(orderdetl.getBatch()) .setAnfme(orderdetl.getMergeNum()) .setBarcode(ordersParam.getMergeNo()) .setMatnr(orderdetl.getMatnr()) .setDetlId(orderdetl.getDetlId()) .setIoStatus(0) .setOrderNo(orderdetl.getOrderNo()).setOrderId(orderdetl.getOrderId()).setStatus(1); waitPakins.add(waitPakin); }); //组拖通知档 waitPakins.forEach(pakin -> { waitPakinService.comb(pakin); }); // UTC入库单据(非平库入库单据) if (order.getOrderType() != OrderType.PK_IN_ORDER.id) { /*** 项目下发流程 * 1. PDA组拖通知档* 2. 生成任务档* 3. 通过定时任务下发至ESS** */ //生成任务档 GeneratePakInParam generatePakInParam = new GeneratePakInParam(); //当前没有起始站点,默认101, 高低位默认传低库位 generatePakInParam.setBarcode(ordersParam.getMergeNo()) .setOriginSite("101") .setTaskType(TaskStsType.GENERATE_IN.id).setLocTypeHeight(LocTypeHeightType.LOW.id); if (workService.generatePakIn(generatePakInParam)) { return true; } } else { //fixme 平库是否需要预约入库 } return false; } @Override public List getHosts() { return hostService.list(); } @Override @Transactional(rollbackFor = Exception.class) public boolean pakinToStock(PakinOnShelvesParams shelvesParams) { Loc loc = locService.getOne(new LambdaQueryWrapper().eq(Loc::getLocNo, shelvesParams.getLoc())); if (Objects.isNull(loc)) { throw new CoolException("库位不存在!!"); } if (loc.getLocStsId() != LocStsType.O.val()) { throw new CoolException("当前库位状态不是空库状态." + LocStsType.O.val()); } //判断当前仓库是否为平库位 List locAreas = locAreaService.list(new LambdaQueryWrapper().eq(LocArea::getLocId, loc.getId())); if (locAreas.isEmpty()) { throw new CoolException("库位没有分配所属仓库区域!!"); } locAreas.forEach(locArea -> { LocAreaType typeServiceOne = locAreaTypeService.getOne(new LambdaQueryWrapper().eq(LocAreaType::getId, locArea.getTypeId()), false); if (typeServiceOne.getParentId() != LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id && typeServiceOne.getId() != LocAreaTypeSts.LOC_AREA_TYPE_FLAT.id) { throw new CoolException("请选择平库区库位,再操作!!"); } }); loc.setBarcode(shelvesParams.getBarcode()); loc.setUpdateTime(new Date()); //库存状态修改为在库状态 loc.setLocStsId(LocStsType.F.val()); if (!locService.updateById(loc)) { throw new CoolException("库位更新失败!!"); } List waitPakins = waitPakinService.list(new LambdaQueryWrapper().eq(WaitPakin::getBarcode, shelvesParams.getBarcode())); waitPakins.forEach(pakin -> { LocDetl locDetl = new LocDetl(); locDetl.setAnfme(pakin.getAnfme()); locDetl.setBatch(pakin.getBatch()); locDetl.setMatId(pakin.getMatnrId$());; locDetl.setCreateTime(new Date()); locDetl.setOrderNo(pakin.getOrderNo()); locDetl.setLocNo(loc.getLocNo()); locDetl.setLocId(loc.getId()); locDetl.setMatnr(pakin.getMatnr()); locDetl.setMemo(pakin.getMemo()); locDetl.setUpdateTime(new Date()); if (!locDetlService.saveOrUpdate(locDetl)) { throw new CoolException("库存明细更新失败!!"); } //修改状态为入库中 pakin.setIoStatus(1); }); //删除组拖档,加入历史组拖档 waitPakins.forEach(waitPakin -> { WaitPakinLog pakinLog = new WaitPakinLog(); BeanUtils.copyProperties(waitPakin, pakinLog); if (!waitPakinLogService.saveOrUpdate(pakinLog)) { throw new CoolException("组拖历史档更新失败"); } }); if (!waitPakinService.removeBatchByIds(waitPakins)) { throw new CoolException("组拖档删除失败!!"); } //通过组拖订单ID获取订单,并删除原单据,加入单据历史档 List list = waitPakins.stream().map(WaitPakin::getOrderId).collect(Collectors.toList()); List orders = orderService.list(new LambdaQueryWrapper().in(Order::getId, list)); orders.forEach(order -> { OrderLog orderLog = new OrderLog(); BeanUtils.copyProperties(order, orderLog); if (!orderLogService.save(orderLog)) { throw new CoolException("历史单据更新失败!!"); } }); if (!orderService.removeBatchByIds(orders)) { throw new CoolException("订单删除失败!!"); } return true; } // /** // * 获取当前库位是否存在 // * @param shelvesParams // * @return // */ // @Override // public Loc selectPakinLocs(PakinOnShelvesParams shelvesParams) { // return locService.getOne(new LambdaQueryWrapper().eq(Loc::getLocNo, shelvesParams.getLoc())); // } }