自动化立体仓库 - WMS系统
#
野心家
2023-04-24 a1ef18396310daa93074c648eb1adbcb7867ac95
src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -1,19 +1,25 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.common.SnowflakeIdWorker;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.entity.result.InOutCountDto;
import com.zy.asrs.entity.result.OpenOrderCompeteResult;
import com.zy.asrs.entity.result.StockVo;
import com.zy.asrs.mapper.TagMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.MatUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.DetlDto;
import com.zy.common.utils.NodeUtils;
import com.zy.common.utils.Synchro;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -48,6 +54,12 @@
    private TagService tagService;
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private NodeService nodeService;
    @Autowired
    private ManLocDetlService manLocDetlService;
    @Override
    @Transactional
@@ -110,6 +122,7 @@
            } else {
                list.add(dto);
            }
            dto.setWeight(detail.getWeight());
        }
        for (DetlDto detlDto : list) {
            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
@@ -122,7 +135,7 @@
            //批号为空会出现问题,设置一个默认值
            if (detlDto.getBatch() == null) {
                orderDetl.setBatch("");
            }else {
            } else {
                orderDetl.setBatch(detlDto.getBatch());
            }
@@ -135,6 +148,7 @@
            orderDetl.setUpdateTime(now);
            orderDetl.setStatus(1);
            orderDetl.setQty(0.0D);
            orderDetl.setWeight(detlDto.getWeight());
            if (!orderDetlService.insert(orderDetl)) {
                throw new CoolException("生成单据明细失败,请联系管理员");
            }
@@ -252,6 +266,7 @@
            } else {
                list.add(dto);
            }
            dto.setWeight(detail.getWeight());
        }
        for (DetlDto detlDto : list) {
            Mat mat = matService.selectByMatnr(detlDto.getMatnr());
@@ -270,6 +285,7 @@
            orderDetl.setUpdateTime(now);
            orderDetl.setStatus(1);
            orderDetl.setQty(0.0D);
            orderDetl.setWeight(detlDto.getWeight());
            if (!orderDetlService.insert(orderDetl)) {
                throw new CoolException("生成单据明细失败,请联系管理员");
            }
@@ -323,8 +339,8 @@
    @Override
    @Transactional
    public List<StockVo> queryStock() {
        return locDetlService.queryStockTotal();
    public List<StockVo> queryStock(StockVo stockVo) {
        return locDetlService.queryStockTotal(stockVo);
    }
    @Override
@@ -445,12 +461,12 @@
    @Override
    @Transactional
    public void syncMat(MatSyncParam param) {
        if (Cools.isEmpty(param.getMatDetails()) || param.getMatDetails().size() <=0 ) {
        if (Cools.isEmpty(param.getMatDetails()) || param.getMatDetails().size() <= 0) {
            throw new CoolException("商品数据为空");
        }
        for(MatSyncParam.MatParam matParam : param.getMatDetails()){
            if(Cools.isEmpty(matParam.getMatnr())){
        for (MatSyncParam.MatParam matParam : param.getMatDetails()) {
            if (Cools.isEmpty(matParam.getMatnr())) {
                throw new CoolException("商品编码不能为空");
            }
@@ -536,6 +552,9 @@
                mat.setStatus(1);
                mat.setCreateTime(now);
                mat.setUpdateTime(now);
                if (Cools.isEmpty(matParam.getLength()) || matParam.getLength() == 0) {
                    mat.setLength(null);
                }
                if (!matService.insert(mat)) {
                    throw new CoolException("服务器内部错误,请联系管理员");
                } else {
@@ -543,7 +562,7 @@
                }
            } else {
                mat.sync(param);
                if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr",matParam.getMatnr()))) {
                if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", matParam.getMatnr()))) {
                    throw new CoolException("更新已存在商品信息失败,请联系管理员");
                }
            }
@@ -551,4 +570,124 @@
    }
    @Override
    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("参数为空");
        }
        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 (orderDetl.getAnfme() - (jsonOrderDetl.getAnfme() + orderDetl.getQty()) < 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(orderDetl.getMaktx());
                manLocDetl.setAnfme(orderDetl.getAnfme());
                manLocDetl.setModiTime(date);
                manLocDetl.setCreateTime(date);
                manLocDetlService.insert(manLocDetl);
            } else {
                checkManLocDetl.setAnfme(checkManLocDetl.getAnfme() + orderDetl.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.setUpdateTime(date);
            orderDetlService.updateById(orderDetl);
        }
        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));
        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.getQty())) {
                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.setUpdateTime(date);
            orderDetlService.updateById(orderDetl);
            orderService.checkComplete(order.getOrderNo());
        }
        return R.ok("下架完成");
    }
}