| | |
| | | import com.zy.asrs.common.domain.param.MobileAdjustParam; |
| | | import com.zy.asrs.common.openapi.entity.param.CombParam; |
| | | import com.zy.asrs.common.wms.entity.*; |
| | | import com.zy.asrs.common.wms.mapper.LocDetlMapper; |
| | | import com.zy.asrs.common.wms.service.*; |
| | | import com.zy.asrs.framework.common.BaseRes; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.session.ExecutorType; |
| | | import org.apache.ibatis.session.SqlSession; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private WaitPakinLogService waitPakinLogService; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | } |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | } else { |
| | | Order order = orderService.selectByNo(param.getOrderNo(), hostId); |
| | | if (order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | |
| | | param.getCombMats().forEach(elem -> { |
| | | |
| | | // 订单明细数量校验 |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch(),hostId); |
| | | if (elem.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单明细数量 |
| | | if (!orderDetlService.increase(order.getId(), hostId, elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { |
| | | if (!orderDetlService.increaseWorkQtyByOrderNo(order.getOrderNo(), elem.getMatnr(), elem.getBatch(), elem.getAnfme(), hostId)) { |
| | | throw new CoolException("修改单据明细数量失败"); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseIn(String locNo, String barcode,Long hostId) { |
| | | //判断库位状态 |
| | | LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locNo).eq(LocMast::getHostId,hostId)); |
| | | if (Cools.isEmpty(locMast)){ |
| | | return R.error("该库位不存在"); |
| | | } |
| | | if (!locMast.getLocSts().equals("O")){ |
| | | return R.error("该库位状态为:"+locMast.getLocSts()+",禁止入库"); |
| | | } |
| | | //查询组托数据 |
| | | List<WaitPakin> list = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getZpallet, barcode).eq(WaitPakin::getHostId, hostId)); |
| | | if (Cools.isEmpty(list)){ |
| | | return R.error("未找到组托信息"); |
| | | } |
| | | Date now = new Date(); |
| | | //插入库存数据 |
| | | for (WaitPakin waitPakin: list){ |
| | | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, waitPakin.getMatnr()).eq(Mat::getHostId, hostId)); |
| | | LocDetl locDetl = new LocDetl(); |
| | | locDetl.sync(mat); |
| | | locDetl.setLocNo(locNo); |
| | | // locDetl.setBarcode(waitPakin.getBarcode()); |
| | | locDetl.setZpallet(waitPakin.getZpallet()); |
| | | locDetl.setAnfme(waitPakin.getAnfme()); |
| | | locDetl.setBatch(waitPakin.getBatch()); |
| | | // locDetl.setWeight(waitPakin.getWeight()); |
| | | locDetl.setHostId(hostId); |
| | | locDetl.setModiTime(now); |
| | | locDetl.setAppeTime(now); |
| | | locDetlService.save(locDetl); |
| | | //是否属于订单数据 |
| | | if (!Cools.isEmpty(waitPakin.getOrderNo())){ |
| | | Order order = orderService.selectByNo(waitPakin.getOrderNo(), hostId); |
| | | if (Cools.isEmpty(order)){ |
| | | continue; |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), waitPakin.getMatnr(), waitPakin.getBatch(),hostId); |
| | | if (Cools.isEmpty(orderDetl)){ |
| | | continue; |
| | | } |
| | | // 修改订单明细完成数量 |
| | | if (!orderDetlService.increase(order.getId(), hostId, waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getAnfme())) { |
| | | throw new CoolException("修改单据明细数量失败"); |
| | | } |
| | | // 修改订单状态 作业中 ===>> 已完成 |
| | | orderService.checkComplete(waitPakin.getOrderNo(), hostId); |
| | | |
| | | } |
| | | } |
| | | //修改库位状态 |
| | | locMast.setLocSts("F"); |
| | | locMast.setModiTime(now); |
| | | locMastService.updateById(locMast); |
| | | |
| | | |
| | | |
| | | // 保存入库通知档历史档 |
| | | if (!waitPakinLogService.saveToHistory(barcode, hostId)) { |
| | | throw new CoolException("保存组托数据失败"); |
| | | } |
| | | // 删除入库通知档 |
| | | if (!waitPakinService.remove(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getZpallet, barcode).eq(WaitPakin::getHostId, hostId))) { |
| | | throw new CoolException("删除组托数据失败"); |
| | | } |
| | | return R.ok("上架成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseOut(CombParam combParam, Long hostId) { |
| | | //判断库位状态 |
| | | LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId,hostId)); |
| | | if (Cools.isEmpty(locMast)){ |
| | | return R.error("该库位不存在"); |
| | | } |
| | | if (!locMast.getLocSts().equals("F")){ |
| | | return R.error("该库位状态为:"+locMast.getLocSts()+",禁止出库"); |
| | | } |
| | | //查询库存数据 |
| | | for (CombParam.CombMat combMat :combParam.getCombMats()){ |
| | | LocDetl locDetl = locDetlService.getOne(new LambdaQueryWrapper<LocDetl>() |
| | | .eq(LocDetl::getLocNo, combParam.getLocno()) |
| | | .eq(LocDetl::getHostId, hostId) |
| | | .eq(LocDetl::getZpallet, combMat.getZpallet()) |
| | | .eq(LocDetl::getMatnr, combMat.getMatnr()) |
| | | .eq(LocDetl::getBatch, combMat.getBatch()) |
| | | ); |
| | | if (Cools.isEmpty(locDetl)){ |
| | | return R.error("未查询到库存数据"); |
| | | } |
| | | if (combMat.getAnfme() > locDetl.getAnfme()){ |
| | | return R.error("下架数量错误,超出库存数量"); |
| | | } |
| | | if (!Cools.isEmpty(combParam.getOrderNo())){ |
| | | Order order = orderService.selectByNo(combParam.getOrderNo(), hostId); |
| | | if (Cools.isEmpty(order)){ |
| | | continue; |
| | | } |
| | | if (order.getSettle() == 1){ |
| | | orderService.updateSettle(order.getId(), 2L, 9527L, hostId); |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch(),hostId); |
| | | if (Cools.isEmpty(orderDetl)){ |
| | | continue; |
| | | } |
| | | if (orderDetl.getAnfme() < orderDetl.getWorkQty()+combMat.getAnfme()){ |
| | | throw new CoolException("下架数量出错"); |
| | | } |
| | | // 修改订单明细作业数量 |
| | | if (!orderDetlService.increaseWorkQtyByOrderNo(combParam.getOrderNo(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme(), hostId)) { |
| | | throw new CoolException("修改单据明细工作数量失败"); |
| | | } |
| | | // 修改订单明细完成数量 |
| | | if (!orderDetlService.increase(order.getId(), hostId, combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) { |
| | | throw new CoolException("修改单据明细完成数量失败"); |
| | | } |
| | | // 修改订单状态 作业中 ===>> 已完成 |
| | | orderService.checkComplete(combParam.getOrderNo(), hostId); |
| | | } |
| | | try { |
| | | //处理库存信息 |
| | | if (combMat.getAnfme().equals(locDetl.getAnfme())){ |
| | | //库存相等删除数据 |
| | | locDetlService.removeById(locDetl); |
| | | int count = locDetlService.count(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo,combParam.getLocno()).eq(LocDetl::getHostId, hostId)); |
| | | if (count == 0){ |
| | | LocMast locMast1 = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, combParam.getLocno()).eq(LocMast::getHostId, hostId)); |
| | | locMast1.setLocSts("O"); |
| | | locMastService.updateById(locMast1); |
| | | } |
| | | }else { |
| | | BigDecimal subtract = BigDecimal.valueOf(locDetl.getAnfme()).subtract(BigDecimal.valueOf(combMat.getAnfme())); |
| | | locDetl.setAnfme(subtract.doubleValue()); |
| | | locDetlService.updateById(locDetl); |
| | | } |
| | | }catch (Exception e){ |
| | | throw new CoolException("更新库存数据出错"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | } |