自动化立体仓库 - WMS系统
#
whycq
2024-01-12 ef106c9a6002872892de9db355ef7cd37512dba5
src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -60,6 +60,8 @@
    private NodeService nodeService;
    @Autowired
    private ManLocDetlService manLocDetlService;
    @Autowired
    private MatV2Service matV2Service;
    @Override
    @Transactional
@@ -125,11 +127,16 @@
        }
        for (DetlDto detlDto : list) {
            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
            if (Cools.isEmpty(mat)) {
                throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品");
            }
            OrderDetl orderDetl = new OrderDetl();
            orderDetl.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() + "编号商品检索失败,请先添加商品");
                }
                orderDetl.sync(matV2);
            } else {
                orderDetl.sync(mat);
            }
            //批号为空会出现问题,设置一个默认值
            if (detlDto.getBatch() == null) {
@@ -267,11 +274,16 @@
        }
        for (DetlDto detlDto : list) {
            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
            if (Cools.isEmpty(mat)) {
                throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品");
            }
            OrderDetl orderDetl = new OrderDetl();
            orderDetl.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() + "编号商品检索失败,请先添加商品");
                }
                orderDetl.sync(matV2);
            } else {
                orderDetl.sync(mat);
            }
            orderDetl.setBatch(detlDto.getBatch() == null ? "" : detlDto.getBatch());
            orderDetl.setAnfme(detlDto.getAnfme());
            orderDetl.setOrderId(order.getId());
@@ -567,159 +579,6 @@
    public R getInOutDetl() {
        List<InOutCountDto> top100 = wrkMastService.selectTop100();
        return R.ok().add(top100);
    }
    @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));
       //查订单
        String jsonOrderNo = (String) json.get("orderNo");
        Order order = orderService.selectOne(new EntityWrapper<Order>()
                .eq("order_no", jsonOrderNo));
        if (Cools.isEmpty(node, order)) {
            return R.error("参数为空");
        }
        //判断订单类型是否是入库
        DocType docType=docTypeService.selectById(order.getDocType());
        if(docType.getPakin()!=1 || docType.getStatus()!=1){
            return R.error("该订单是出库订单,无法入库");
        }
        JSONArray combMats = json.getJSONArray("combMats");
        for (int i = 0; i < combMats.size(); i++) {
            OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class);
            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
                    .eq("order_no", jsonOrderNo)
                    .and()
                    .eq("maktx",jsonOrderDetl.getMaktx()));
            if (Cools.isEmpty(orderDetl)) {
                return R.error("单据明细有误,请检查");
            }
            if (orderDetl.getAnfme() - (jsonOrderDetl.getAnfme() + orderDetl.getWorkQty()) < 0) {
                return R.error("入库数量大于可入数量");
            }
            ManLocDetl checkManLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>()
                    .eq("loc_no", jsonLocNo)
                    .eq("matnr", orderDetl.getMatnr()));
            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);
                manLocDetlService.insert(manLocDetl);
            } else {
                checkManLocDetl.setAnfme(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme());
                checkManLocDetl.setModiTime(date);
                manLocDetlService.update(checkManLocDetl, new EntityWrapper<ManLocDetl>()
                        .eq("loc_no", jsonLocNo)
                        .eq("matnr", orderDetl.getMatnr()));
            }
            orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme());
            orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme());
            orderDetl.setUpdateTime(date);
            orderDetlService.updateById(orderDetl);
            //更新订单状态
            //工作中的数量小于总订单数时,订单状态改为2,作业中
            if(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme() < orderDetl.getAnfme()){
                order.setSettle(2L);
            }else{
                //工作中的数量等于总订单数时,订单状态改为4,完成
                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));
        String jsonOrderNo = (String) json.get("orderNo");
        Order order = orderService.selectOne(new EntityWrapper<Order>()
                .eq("order_no", jsonOrderNo));
        //判断订单类型是否是入库
        DocType docType=docTypeService.selectById(order.getDocType());
        if(docType.getPakout()!=1 || docType.getStatus()!=1){
            return R.error("该订单是出库订单,无法入库");
        }
        if (Cools.isEmpty(node, order)) {
            return R.error("参数为空");
        }
        JSONArray combMats = json.getJSONArray("combMats");
        for (int i = 0; i < combMats.size(); i++) {
            OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class);
            OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
                    .eq("order_no", jsonOrderNo));
            if (Cools.isEmpty(orderDetl)) {
                return R.error("单据明细有误,请检查");
            }
            if (jsonOrderDetl.getAnfme() > (orderDetl.getAnfme() - orderDetl.getWorkQty())) {
                return R.error("出库数量大于单据可出数量");
            }
            ManLocDetl manLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>()
                    .eq("loc_no", jsonLocNo)
                    .eq("matnr", orderDetl.getMatnr()));
            if (manLocDetl == null) {
                return R.error("该库位没有出库的物料信息");
            }
            if (jsonOrderDetl.getAnfme() > manLocDetl.getAnfme()) {
                return R.error("出库数量大于可出数量");
            }
            Double finalQty = manLocDetl.getAnfme() - jsonOrderDetl.getAnfme();
            if (finalQty <= 0){
                manLocDetlService.delete(new EntityWrapper<ManLocDetl>()
                        .eq("loc_no", jsonLocNo)
                        .eq("matnr", orderDetl.getMatnr()));
            }else {
                manLocDetl.setAnfme(finalQty);
                manLocDetl.setModiTime(date);
                manLocDetlService.update(manLocDetl,new EntityWrapper<ManLocDetl>()
                        .eq("loc_no", jsonLocNo)
                        .eq("matnr", orderDetl.getMatnr()));
            }
            orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme());
            orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme());
            orderDetl.setUpdateTime(date);
            orderDetlService.updateById(orderDetl);
            //更新订单状态
            //工作中的数量小于总订单数时,订单状态改为2,作业中
            if(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme() < orderDetl.getAnfme()){
                order.setSettle(2L);
            }else{
                //工作中的数量等于总订单数时,订单状态改为4,完成
                order.setSettle(4L);
            }
            if(!orderService.updateById(order)){
                return R.error("更新订单状态失败");
            }
            orderService.checkComplete(order.getOrderNo());
        }
        return R.ok("下架完成");
    }
}