| | |
| | | import com.zy.asrs.entity.param.OffSaleParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakinParam; |
| | | import com.zy.asrs.mapper.ManLocDetlMapper; |
| | | import com.zy.asrs.mapper.OrderDetlMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.asrs.utils.SaasUtils; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.common.model.DetlDto; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | |
| | | private MatService matService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | |
| | | @Resource |
| | | private WaitPakinLogService waitPakinLogService; |
| | | |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private ManLocDetlMapper manLocDetlMapper; |
| | | |
| | | @Resource |
| | | private OrderDetlMapper orderDetlMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseOut(CombParam combParam, Long userId) { |
| | | |
| | | //查询库存数据 |
| | | for (CombParam.CombMat combMat : combParam.getCombMats()) { |
| | | ManLocDetl locDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", combParam.getLocno()) |
| | | .eq("zpallet", combMat.getZpallet()) |
| | | .eq("matnr", 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()); |
| | | if (Cools.isEmpty(order)) { |
| | | continue; |
| | | } |
| | | if (order.getSettle() == 1) { |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), combMat.getMatnr(), combMat.getBatch()); |
| | | if (Cools.isEmpty(orderDetl)) { |
| | | continue; |
| | | } |
| | | if (orderDetl.getAnfme() < orderDetl.getWorkQty() + combMat.getAnfme()) { |
| | | combMat.setAnfme(orderDetl.getAnfme() - orderDetl.getWorkQty()); |
| | | } |
| | | // 修改订单明细作业数量 |
| | | if (orderDetlMapper.increaseWorkQtyByOrderNo(combParam.getOrderNo(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme()) <= 0) { |
| | | throw new CoolException("修改单据明细工作数量失败"); |
| | | } |
| | | // 修改订单明细完成数量 |
| | | if (!orderDetlService.increase(order.getId(), combMat.getMatnr(), combMat.getBatch(), combMat.getAnfme())) { |
| | | throw new CoolException("修改单据明细完成数量失败"); |
| | | } |
| | | // 修改订单状态 作业中 ===>> 已完成 |
| | | orderService.checkComplete(combParam.getOrderNo()); |
| | | } |
| | | try { |
| | | double i = 0.0; |
| | | double j = locDetl.getAnfme(); |
| | | //处理库存信息 |
| | | if (combMat.getAnfme().equals(locDetl.getAnfme())) { |
| | | //库存相等删除数据 |
| | | manLocDetlMapper.deleteLocNo0(combParam.getLocno(), combMat.getMatnr()); |
| | | int count = manLocDetlMapper.selectCount(new EntityWrapper<ManLocDetl>().eq("loc_no", combParam.getLocno())); |
| | | if (count == 0) { |
| | | Node node = nodeService.selectByUuid(combParam.getLocno()); |
| | | node.setUpdateTime(new Date()); |
| | | node.setUpdateBy(userId); |
| | | node.setBarcode(""); |
| | | nodeService.updateById(node); |
| | | } |
| | | } else { |
| | | BigDecimal subtract = BigDecimal.valueOf(locDetl.getAnfme()).subtract(BigDecimal.valueOf(combMat.getAnfme())); |
| | | i = subtract.byteValue(); |
| | | locDetl.setAnfme(subtract.doubleValue()); |
| | | // 更新库存 |
| | | manLocDetlMapper.updateAnfme(subtract.doubleValue(), combParam.getLocno(), combMat.getMatnr(), combMat.getBatch()); |
| | | } |
| | | // 记录日志 |
| | | SaasUtils.insertLog(1, combParam.getLocno(), combMat.getMatnr(), combMat.getAnfme(), userId,combMat.getBatch()); |
| | | } catch (Exception e) { |
| | | throw new CoolException("更新库存数据出错" + e.getMessage()); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseIn(String locNo, String barcode, Long userId) { |
| | | |
| | | //查询组托数据 |
| | | List<WaitPakin> list = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (Cools.isEmpty(list)) { |
| | | return R.error("未找到组托信息"); |
| | | } |
| | | Date now = new Date(); |
| | | |
| | | //插入库存数据 |
| | | for (WaitPakin waitPakin : list) { |
| | | |
| | | Mat mat = matService.selectOne(new EntityWrapper<Mat>() |
| | | .eq("matnr", waitPakin.getMatnr())); |
| | | |
| | | ManLocDetl locDetl1 = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr", waitPakin.getMatnr()). |
| | | eq("batch", waitPakin.getBatch())); |
| | | |
| | | Node node = nodeService.selectByUuid(locNo); |
| | | if (Cools.isEmpty(node)) { |
| | | throw new CoolException(locNo + ":库位不存在"); |
| | | } |
| | | if (!Cools.isEmpty(locDetl1)) { |
| | | locDetl1.setAnfme(waitPakin.getAnfme() + waitPakin.getAnfme()); |
| | | locDetl1.setUpdateBy(userId); |
| | | locDetl1.setModiTime(now); |
| | | manLocDetlService.update(locDetl1, new EntityWrapper<ManLocDetl>().eq("loc_no", locNo).eq("matnr", waitPakin.getMatnr()). |
| | | eq("batch", waitPakin.getBatch())); |
| | | } else { |
| | | ManLocDetl manLocDetl = new ManLocDetl(); |
| | | manLocDetl.setLocNo(locNo); |
| | | // manLocDetl.setBarcode(barcode); |
| | | manLocDetl.setZpallet(barcode); |
| | | manLocDetl.setNodeId(node.getId()); |
| | | manLocDetl.setMaktx(mat.getMaktx()); |
| | | manLocDetl.setMatnr(mat.getMatnr()); |
| | | manLocDetl.setSpecs(mat.getSpecs()); |
| | | manLocDetl.setBatch(Cools.isEmpty(waitPakin.getBatch()) ? "" : waitPakin.getBatch()); |
| | | manLocDetl.setAnfme(waitPakin.getAnfme()); |
| | | manLocDetl.setCreateBy(userId); |
| | | manLocDetl.setCreateTime(now); |
| | | manLocDetl.setUpdateBy(userId); |
| | | manLocDetl.setModiTime(now); |
| | | if (!manLocDetlService.insert(manLocDetl)) { |
| | | throw new CoolException("商品上架失败!"); |
| | | } |
| | | |
| | | // 更新库位条码 |
| | | node.setBarcode(barcode); |
| | | node.setUpdateBy(userId); |
| | | node.setUpdateTime(now); |
| | | nodeService.updateById(node); |
| | | } |
| | | |
| | | // 记录日志 |
| | | SaasUtils.insertLog(0, locNo, waitPakin.getMatnr(), waitPakin.getAnfme(), userId,waitPakin.getBatch()); |
| | | |
| | | //是否属于订单数据 |
| | | //是否属于订单数据 |
| | | if (!Cools.isEmpty(waitPakin.getOrderNo())){ |
| | | Order order = orderService.selectByNo(waitPakin.getOrderNo()); |
| | | if (Cools.isEmpty(order)){ |
| | | throw new CoolException("平库上架查询订单失败"); |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), waitPakin.getMatnr(), waitPakin.getBatch()); |
| | | if (Cools.isEmpty(orderDetl)){ |
| | | throw new CoolException("平库上架查询订单明细失败"); |
| | | } |
| | | // 修改订单明细完成数量 |
| | | if (!orderDetlService.increase(order.getId(),waitPakin.getMatnr(), waitPakin.getBatch(), waitPakin.getAnfme())) { |
| | | throw new CoolException("修改单据明细数量失败"); |
| | | } |
| | | // 修改订单状态 作业中 ===>> 已完成 |
| | | orderService.checkComplete(waitPakin.getOrderNo()); |
| | | |
| | | } |
| | | |
| | | // 更新入库工作档 |
| | | waitPakin.setLocNo(locNo); |
| | | waitPakin.setIoStatus("Y"); |
| | | waitPakin.setModiUser(userId); |
| | | waitPakin.setModiTime(now); |
| | | waitPakinService.update(waitPakin,new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("matnr",waitPakin.getMatnr()) |
| | | .eq("batch",waitPakin.getBatch())); |
| | | |
| | | // 保存入库通知档历史档 |
| | | if (!waitPakinLogService.save(barcode)) { |
| | | throw new CoolException("保存组托数据失败"); |
| | | } |
| | | // 删除入库通知档 |
| | | if (!waitPakinService.delete(new EntityWrapper<WaitPakin>().eq("zpallet", barcode))) { |
| | | throw new CoolException("删除组托数据失败"); |
| | | } |
| | | } |
| | | |
| | | return R.ok("上架成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | if(param.getCombMats().size()>1){ |
| | | throw new CoolException("请提取一个商品,或者刷新重新组托!"); |
| | | } |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | } |
| | | |
| | | if(param.getBarcode().length()!=8){ |
| | | throw new CoolException("条码长度不是8位===>>" + param.getBarcode()); |
| | | } |
| | | if (param.getCombMats().size()>1){ |
| | | throw new CoolException("不允许混料===>>" + param.getBarcode()); |
| | | } |
| | | |
| | | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode())); |
| | | int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode())); |
| | | if (countLoc > 0 || countWrk > 0) { |
| | | throw new CoolException("工作档/库存条码数据已存在===>>" + param.getBarcode()); |
| | | int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getBarcode())); |
| | | if (countLoc > 0 || countWrk > 0 || countwait > 0) { |
| | | throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode()); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | |
| | | // 无单组托 |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | if (Cools.isEmpty(param.getCombMats().get(0).getOrderNo())) { |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | | if (order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | } |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | |
| | | Order order = orderService.selectByNo(elem.getOrderNo()); |
| | | if (order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已完成:" + elem.getOrderNo()); |
| | | } |
| | | // 订单明细数量校验 |
| | | OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); |
| | | if (elem.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单作业数量 |
| | | // 修改订单明细数量 |
| | | if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { |
| | | throw new CoolException("修改单据作业数量失败"); |
| | | throw new CoolException("修改单据明细数量失败"); |
| | | } |
| | | |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme()); |
| | |
| | | assert one != null; |
| | | one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | } else { |
| | | detlDto.setOrderNo(order.getOrderNo()); |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | |
| | | Order order = orderService.selectByNo(detlDto.getOrderNo()); |
| | | |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(order.getOrderNo()); // 单据编号 |
| | |
| | | if (!waitPakinService.insert(waitPakin)) { |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | } |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 商品上架 |
| | | @Override |
| | | public void onSale(CombParam param) { |
| | | public void onSale(CombParam param, Long userId) { |
| | | |
| | | Date now = new Date(); |
| | | // 获取库位号 |
| | | String locno = param.getLocno(); |
| | | Node node = nodeService.selectByUuid(locno); |
| | | if (Cools.isEmpty(node)) { |
| | | throw new CoolException(param.getLocno() + ":库位不存在"); |
| | | } |
| | | |
| | | String barcode = param.getBarcode(); |
| | | if (Cools.isEmpty(barcode)) { |
| | | throw new CoolException("条码不能为空!"); |
| | | } |
| | | |
| | | // 获取商品列表 |
| | |
| | | if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme()==0){ |
| | | throw new CoolException(combMat.getMatnr() + ":商品数量有误!"); |
| | | } |
| | | if (Cools.isEmpty(combMat.getBatch())){ |
| | | throw new CoolException(combMat.getMatnr() + ":商品批号有误!"); |
| | | } |
| | | |
| | | ManLocDetl manLocDetl = new ManLocDetl(); |
| | | manLocDetl.setLocNo(locno); |
| | | // manLocDetl.setBarcode(barcode); |
| | | manLocDetl.setZpallet(barcode); |
| | | manLocDetl.setNodeId(node.getId()); |
| | | manLocDetl.setMaktx(mat.getMaktx()); |
| | | manLocDetl.setMatnr(mat.getMatnr()); |
| | | manLocDetl.setBatch(combMat.getBatch()); |
| | | manLocDetl.setSpecs(mat.getSpecs()); |
| | | manLocDetl.setBatch(Cools.isEmpty(combMat.getBatch()) ? "" : combMat.getBatch()); |
| | | manLocDetl.setAnfme(combMat.getAnfme()); |
| | | manLocDetl.setCreateBy(userId); |
| | | manLocDetl.setCreateTime(now); |
| | | manLocDetl.setUpdateBy(userId); |
| | | manLocDetl.setModiTime(now); |
| | | if (!manLocDetlService.insert(manLocDetl)) { |
| | | throw new CoolException("商品上架失败!"); |
| | | } |
| | | |
| | | // 更新库位条码 |
| | | node.setBarcode(barcode); |
| | | node.setUpdateBy(userId); |
| | | node.setUpdateTime(now); |
| | | nodeService.updateById(node); |
| | | SaasUtils.insertLog(0,manLocDetl.getLocNo(), manLocDetl.getMatnr(),combMat.getAnfme(),userId,manLocDetl.getBatch()); |
| | | |
| | | } |
| | | } |
| | | |
| | | // 商品下架 |
| | | @Override |
| | | public void offSale(OffSaleParam offSaleParam) { |
| | | List<ManLocDetl> manLocDetls = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); |
| | | if (Cools.isEmpty(manLocDetls)){ |
| | | throw new CoolException("商品下架失败!"); |
| | | public void offSale(OffSaleParam offSaleParam, Long userId) { |
| | | ManLocDetl manLocDetl = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); |
| | | if (Cools.isEmpty(manLocDetl)){ |
| | | throw new CoolException("无此商品!"); |
| | | } |
| | | int i = manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); |
| | | System.out.println(i); |
| | | double anfme = manLocDetl.getAnfme() - offSaleParam.getAnfme(); |
| | | if (anfme < 0) { |
| | | throw new CoolException("商品库存不足!"); |
| | | } else if (anfme == 0){ |
| | | SaasUtils.insertLog(1,manLocDetl.getLocNo(), manLocDetl.getMatnr(),offSaleParam.getAnfme(),userId,manLocDetl.getBatch()); |
| | | manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr()); |
| | | // 清空库位条码 |
| | | Node node = nodeService.selectByUuid(offSaleParam.getLocNo()); |
| | | node.setUpdateTime(new Date()); |
| | | node.setUpdateBy(userId); |
| | | node.setBarcode(""); |
| | | } |
| | | manLocDetlMapper.updateAnfme0(anfme,manLocDetl.getNodeId()); |
| | | } |
| | | |
| | | // 查找商品 |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void adjust(MobileAdjustParam param, Long userId) { |