| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | |
| | | import com.zy.common.model.MesCombParam; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.Synchro; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private ManLocDetlService manLocDetlService; |
| | | @Autowired |
| | | private ManLocDetlMapper manLocDetlMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private MatV2Service matV2Service; |
| | | @Override |
| | | @Transactional |
| | | public void comb(CombParam param, Long userId) { |
| | |
| | | Date now = new Date(); |
| | | |
| | | // 无单组托 |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | if (Cools.isEmpty(param.getCombMats().get(0).getOrderNo())) { |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | |
| | | |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | if (Cools.isEmpty(mat)) { |
| | | MatV2 matV2 = matV2Service.selectOne(new EntityWrapper<MatV2>().eq("matnr", detlDto.getMatnr())); |
| | | if(Cools.isEmpty(matV2)){ |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | waitPakin.sync(matV2); |
| | | } else { |
| | | waitPakin.sync(mat); |
| | | } |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | // 生成入库通知档 |
| | | Order order = orderService.selectByNo(param.getOrderNo()); |
| | | if (order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | } |
| | | for (CombParam.CombMat combMat : param.getCombMats()) { |
| | | OrderDetl orderDetl = orderDetlService.selectItem(param.getOrderNo(), combMat.getMatnr(), combMat.getBatch()); |
| | | // 生成入库通知档 |
| | | Order order = orderService.selectByNo(combMat.getOrderNo()); |
| | | |
| | | //判断订单类型是否是入库 |
| | | DocType docType=docTypeService.selectById(order.getDocType()); |
| | | if(docType.getPakin()!=1 || docType.getStatus()!=1){ |
| | | throw new CoolException("订单为出库订单,不能组托!"); |
| | | } |
| | | |
| | | if (order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(combMat.getOrderNo(), combMat.getMatnr(), combMat.getBatch()); |
| | | if (orderDetl == null) { |
| | | throw new CoolException("找不到组托的单据明细"); |
| | | } |
| | |
| | | // one.setAnfme(one.getAnfme() + detlDto.getAnfme()); |
| | | // } else { |
| | | // } |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | } |
| | | orderService.updateSettle(order.getId(), 2L, userId); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | throw new CoolException(locDetl.getLocNo() + "库位不是在库状态"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Override |
| | | public R manDetlIn(JSONObject json) { |
| | | Date date = new Date(); |
| | | String jsonLocNo = (String) json.get("locNo"); |
| | | Node node = nodeService.selectOne(new EntityWrapper<Node>() |
| | | .eq("name", jsonLocNo)); |
| | | JSONArray combMats = json.getJSONArray("combMats"); |
| | | for (int i = 0; i < combMats.size(); i++) { |
| | | OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class); |
| | | |
| | | //查订单 |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>() |
| | | .eq("order_no", jsonOrderDetl.getOrderNo())); |
| | | if (Cools.isEmpty(node, order)) { |
| | | return R.error("参数为空"); |
| | | } |
| | | |
| | | //判断订单类型是否是入库 |
| | | DocType docType=docTypeService.selectById(order.getDocType()); |
| | | if(docType.getPakin()!=1 || docType.getStatus()!=1){ |
| | | return R.error("该订单是出库订单,无法入库"); |
| | | } |
| | | |
| | | OrderDetl orderDetl = orderDetlService.selectItem(jsonOrderDetl.getOrderNo(),jsonOrderDetl.getMatnr(),jsonOrderDetl.getBatch()); |
| | | if (Cools.isEmpty(orderDetl)) { |
| | | return R.error("单据明细有误,请检查"); |
| | | } |
| | | if (orderDetl.getAnfme() - (jsonOrderDetl.getAnfme() + orderDetl.getWorkQty()) < 0) { |
| | | return R.error("入库数量大于可入数量"); |
| | | } |
| | | //查询平库中是否有一样的物料号,有的话直接增加数量 |
| | | ManLocDetl checkManLocDetl = manLocDetlService.selectInventory(jsonLocNo,orderDetl.getMatnr(),jsonOrderDetl.getBatch()); |
| | | if (checkManLocDetl == null) { |
| | | ManLocDetl manLocDetl = new ManLocDetl(); |
| | | Synchro.Copy(orderDetl, manLocDetl); |
| | | manLocDetl.setLocNo(node.getName()); |
| | | manLocDetl.setNodeId(node.getId()); |
| | | manLocDetl.setMatnr(orderDetl.getMatnr()); |
| | | manLocDetl.setMaktx(jsonOrderDetl.getMaktx()); |
| | | manLocDetl.setAnfme(jsonOrderDetl.getAnfme()); |
| | | manLocDetl.setModiTime(date); |
| | | manLocDetl.setCreateTime(date); |
| | | manLocDetl.setBatch(jsonOrderDetl.getBatch()); |
| | | if(!manLocDetlService.insert(manLocDetl)){ |
| | | return R.error("修改平库物料失败!"); |
| | | } |
| | | } else { |
| | | if(manLocDetlService.increase(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme(), jsonOrderDetl.getOrderNo(), jsonOrderDetl.getMaktx(), jsonOrderDetl.getBatch())<=0){ |
| | | return R.error("修改平库物料失败!"); |
| | | } |
| | | } |
| | | orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setUpdateTime(date); |
| | | orderDetlService.updateById(orderDetl); |
| | | //更新订单状态 |
| | | List<OrderDetl> orderDetls=orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no",order.getOrderNo())); |
| | | order.setSettle(2L); |
| | | boolean log=true; |
| | | for (OrderDetl orderDetl1: orderDetls) { |
| | | //工作中的数量小于总订单数时,订单状态改为2,作业中 |
| | | if(orderDetl1.getQty() < orderDetl.getAnfme()){ |
| | | log=false; |
| | | } |
| | | } |
| | | if(log){ |
| | | order.setSettle(4L); |
| | | } |
| | | if(!orderService.updateById(order)){ |
| | | return R.error("更新订单状态失败"); |
| | | } |
| | | orderService.checkComplete(order.getOrderNo()); |
| | | } |
| | | return R.ok("上架完成"); |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public R manDetlOut(JSONObject json) { |
| | | Date date = new Date(); |
| | | String jsonLocNo = (String) json.get("locNo"); |
| | | Node node = nodeService.selectOne(new EntityWrapper<Node>() |
| | | .eq("name", jsonLocNo)); |
| | | JSONArray combMats = json.getJSONArray("combMats"); |
| | | for (int i = 0; i < combMats.size(); i++) { |
| | | OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class); |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>() |
| | | .eq("order_no", jsonOrderDetl.getOrderNo())); |
| | | |
| | | //判断订单类型是否是出库 |
| | | DocType docType=docTypeService.selectById(order.getDocType()); |
| | | if(docType.getPakout()!=1 || docType.getStatus()!=1){ |
| | | return R.error("该订单是入库订单,无法出库"); |
| | | } |
| | | if (Cools.isEmpty(node, order)) { |
| | | return R.error("参数为空"); |
| | | } |
| | | OrderDetl orderDetl = orderDetlService.selectItem(jsonOrderDetl.getOrderNo(),jsonOrderDetl.getMatnr(),jsonOrderDetl.getBatch()); |
| | | if (Cools.isEmpty(orderDetl)) { |
| | | return R.error("单据明细有误,请检查"); |
| | | } |
| | | if (jsonOrderDetl.getAnfme() > (orderDetl.getAnfme() - orderDetl.getWorkQty())) { |
| | | return R.error("出库数量大于单据可出数量"); |
| | | } |
| | | //查询平库中是否有一样的物料号 |
| | | ManLocDetl checkManLocDetl = manLocDetlService.selectInventory(jsonLocNo,orderDetl.getMatnr(),orderDetl.getBatch()); |
| | | if (checkManLocDetl == null) { |
| | | return R.error("该库位没有出库的物料信息"); |
| | | } |
| | | if (jsonOrderDetl.getAnfme() > checkManLocDetl.getAnfme()) { |
| | | return R.error("出库数量大于可出数量"); |
| | | } |
| | | Double finalQty = checkManLocDetl.getAnfme() - jsonOrderDetl.getAnfme(); |
| | | if (finalQty <= 0){ |
| | | if(manLocDetlService.deleteDatailed(jsonLocNo, jsonOrderDetl.getMatnr(), jsonOrderDetl.getBatch())<=0){ |
| | | return R.error("修改平库物料失败!"); |
| | | } |
| | | }else { |
| | | if(manLocDetlService.increase(finalQty, jsonLocNo, jsonOrderDetl.getMatnr(), jsonOrderDetl.getBatch())<=0){ |
| | | return R.error("修改平库物料失败!"); |
| | | } |
| | | } |
| | | orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setUpdateTime(date); |
| | | orderDetlService.updateById(orderDetl); |
| | | //更新订单状态 |
| | | List<OrderDetl> orderDetls=orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no",order.getOrderNo())); |
| | | order.setSettle(2L); |
| | | boolean log=true; |
| | | for (OrderDetl orderDetl1: orderDetls) { |
| | | //工作中的数量小于总订单数时,订单状态改为2,作业中 |
| | | if(orderDetl1.getQty() < orderDetl.getAnfme()){ |
| | | log=false; |
| | | } |
| | | } |
| | | if(log){ |
| | | order.setSettle(4L); |
| | | } |
| | | if(!orderService.updateById(order)){ |
| | | return R.error("更新订单状态失败"); |
| | | } |
| | | orderService.checkComplete(order.getOrderNo()); |
| | | } |
| | | return R.ok("下架完成"); |
| | | } |
| | | |
| | | |
| | | } |