自动化立体仓库 - WMS系统
#
whycq
2022-08-31 02ee94b7bee4a00c04cfdc7735e310ec45bdea18
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -3,21 +3,23 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.SnowflakeIdWorker;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.entity.param.MobileAdjustParam;
import com.zy.asrs.entity.param.OffSaleParam;
import com.zy.asrs.entity.param.OpenOrderPakinParam;
import com.zy.asrs.mapper.ManLocDetlMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.MatUtils;
import com.zy.common.CodeRes;
import com.zy.common.constant.MesConstant;
import com.zy.common.entity.Parameter;
import com.zy.common.model.DetlDto;
import com.zy.common.model.MesCombParam;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,6 +61,23 @@
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private StaDescService staDescService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private NodeService nodeService;
    @Autowired
    private ManLocDetlService manLocDetlService;
    @Autowired
    private ManLocDetlMapper manLocDetlMapper;
    @Override
    @Transactional
@@ -71,6 +90,13 @@
                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
            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());
        }
        Date now = new Date();
        // 无单组托
@@ -125,9 +151,9 @@
                if (elem.getAnfme() > orderDetl.getEnableQty()) {
                    throw new CoolException(orderDetl.getMatnr() + "入库数量不合法");
                }
                // 修改订单明细数量
                if (!orderDetlService.increase(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
                    throw new CoolException("修改单据明细数量失败");
                // 修改订单作业数量
                if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
                    throw new CoolException("修改单据作业数量失败");
                }
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
@@ -147,7 +173,7 @@
                WaitPakin waitPakin = new WaitPakin();
                waitPakin.sync(mat);
                waitPakin.setOrderNo(order.getOrderNo());   // 单据编号
                waitPakin.setBatch(detlDto.getBatch());     // 批号
                waitPakin.setBatch(detlDto.getBatch());     // 序列码
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
@@ -165,6 +191,51 @@
    }
    @Override
    public void onSale(CombParam param) {
        Date now = new Date();
        // 获取库位号
        String locno = param.getLocno();
        Node node = nodeService.selectByUuid(locno);
        if (Cools.isEmpty(node)) {
            throw new CoolException(param.getLocno() + ":库位不存在");
        }
        // 获取商品列表
        for(CombParam.CombMat combMat : param.getCombMats()){
            Mat mat = matService.selectByMatnr(combMat.getMatnr());
            if (Cools.isEmpty(mat)){
                throw new CoolException(combMat.getMatnr() + ":商品档案不存在!");
            }
            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.setNodeId(node.getId());
            manLocDetl.setMaktx(mat.getMaktx());
            manLocDetl.setMatnr(mat.getMatnr());
            manLocDetl.setBatch(combMat.getBatch());
            manLocDetl.setAnfme(combMat.getAnfme());
            manLocDetl.setModiTime(now);
            if (!manLocDetlService.insert(manLocDetl)) {
                throw new CoolException("商品上架失败!");
            }
        }
    }
    @Override
    public void offSale(OffSaleParam offSaleParam) {
        List<ManLocDetl> manLocDetls = manLocDetlMapper.selectLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
        if (Cools.isEmpty(manLocDetls)){
            throw new CoolException("商品下架失败!");
        }
        int i = manLocDetlMapper.deleteLocNo0(offSaleParam.getLocNo(), offSaleParam.getMatnr());
        System.out.println(i);
    }
    @Override
    @Transactional
    public void adjust(MobileAdjustParam param, Long userId) {
@@ -290,8 +361,11 @@
            if (packDown) {
                MesCombParam mesCombParam = new MesCombParam();
                mesCombParam.setZpallet(param.getBarcode());
                mesCombParam.setCombTime(DateUtils.convert(now));
                mesCombParam.setPakinTime(DateUtils.convert(now));
                mesCombParam.setLgort("5008");
                mesCombParam.setPlantCode("5000");
                mesCombParam.setFromCode("5012-20");
                mesCombParam.setStationCode("JJQ-PFZPDB-XX");
                for (DetlDto detlDto : detlDtos) {
                    mesCombParam.getList().add(new MesCombParam.Detl(detlDto.getOrderNo(), detlDto.getAnfme()));
                }
@@ -359,9 +433,9 @@
                if (detlDto.getAnfme() > orderDetl.getEnableQty()) {
                    throw new CoolException(orderDetl.getMatnr() + "入库数量不合法");
                }
                // 修改订单明细数量
                if (!orderDetlService.increase(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
                    throw new CoolException("修改单据明细数量失败");
                // 修改订单作业数量
                if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) {
                    throw new CoolException("修改单据作业数量失败");
                }
                // 保存入库通知档
@@ -397,4 +471,141 @@
        }
    }
    @Override
    @Transactional
    public void pakoutByOrder(JSONObject param, Long userId) {
        Integer staNo = param.containsKey("staNo") ? Integer.parseInt(param.get("staNo").toString()) : 0;
        String orderNo = param.containsKey("orderNo") ? param.get("orderNo").toString() : "";
        BasDevp sta = basDevpService.checkSiteStatus(staNo);
        //根据订单号生成出库任务工作档
        Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo));
        if (order.getSettle() != 1 && order.getSettle() != 2){
            throw new CoolException("该订单已处理");
        }
        List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo));
        Date now = new Date();
        for(OrderDetl orderDetl : orderDetls){
            //查询所有库位状态为F的库位信息
            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),null,null);
            if (locDetls.size() == 0) {
                throw new CoolException("库存中没有该物料");
            }
            for(LocDetl locDetl : locDetls){
                //如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_no", locDetl.getLocNo()));
                if (Cools.isEmpty(locMast)) {
                    continue;
                }
                BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>()
                        .eq("crn_no", locMast.getCrnNo()));
                if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")){
                    continue;
                }
                //可出库数量 = 订单数量 - 作业中数量
                Double outQty = orderDetl.getAnfme() - orderDetl.getWorkQty();
                if(outQty <= 0){
                    break;
                }
                // 判断入出库类型:101.全板出库 or 103.拣料出库
                Double sumCount = locDetlService.getLocDetlSumQty(locDetl.getLocNo());
                Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty;   //本次出库量
                int ioType = sumCount <= curOutQty ? 101 : 103;
                stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId, now);
                order.setSettle(2L);
                order.setUpdateBy(userId);
                order.setUpdateTime(now);
                if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
                    throw new CoolException("更新订单状态失败");
                }
                orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
                orderDetl.setUpdateBy(userId);
                orderDetl.setUpdateTime(now);
                Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo)
                        .eq("matnr",orderDetl.getMatnr());
                if(!Cools.isEmpty(orderDetl.getBatch())){
                    wrapper.eq("batch", orderDetl.getBatch());
                }
                if(!orderDetlService.update(orderDetl, wrapper)){
                    throw new CoolException("更新订单明细失败");
                }
            }
        }
    }
    @Override
    @Transactional
    public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
                         Double curOutQty, Integer ioType, Long userId, Date now) {
        // 获取库位
        LocMast locMast = locMastService.selectById(locDetl.getLocNo());
        // 获取路径
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                .eq("type_no", ioType)
                .eq("stn_no", staNo.getDevNo())
                .eq("crn_no", locMast.getCrnNo());
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            throw new CoolException("出库路径不存在");
        }
        // 生成工作号
        int workNo = commonService.getWorkNo(2);
        // 生成工作档
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(workNo);
        wrkMast.setIoTime(now);
        wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
        wrkMast.setIoType(ioType); // 入出库状态
        wrkMast.setIoPri(13D); // 优先级:13
        wrkMast.setCrnNo(locMast.getCrnNo());
        wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
        wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
        wrkMast.setSourceLocNo(locDetl.getLocNo()); // 源库位
        wrkMast.setFullPlt("Y"); // 满板:Y
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setEmptyMk("N"); // 空板
        wrkMast.setLinkMis("N");
        wrkMast.setAppeUser(userId); // 操作人员数据
        wrkMast.setAppeTime(now);
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        wrkMast.setBarcode(locMast.getBarcode());
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("保存工作档失败,出库库位号:" + locDetl.getLocNo());
        }
        WrkDetl wrkDetl = new WrkDetl();
        wrkDetl.sync(locDetl);
        wrkDetl.setWrkNo(workNo);
        wrkDetl.setIoTime(now);
        wrkDetl.setAnfme(curOutQty); // 数量
        wrkDetl.setOrderNo(orderDetl.getOrderNo());
        wrkDetl.setAppeTime(now);
        wrkDetl.setAppeUser(userId);
        wrkDetl.setModiTime(now);
        wrkDetl.setModiUser(userId);
        if (!wrkDetlService.insert(wrkDetl)) {
            throw new CoolException("保存工作档明细失败");
        }
        // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        locMast = locMastService.selectById(locDetl.getLocNo());
        if (locMast.getLocSts().equals("F")) {
            locMast.setLocSts(ioType == 101 ? "R" : "P");
            locMast.setModiUser(userId);
            locMast.setModiTime(new Date());
            if (!locMastService.updateById(locMast)) {
                throw new CoolException("预约库位状态失败,库位号:" + locDetl.getLocNo());
            }
        } else {
            throw new CoolException(locDetl.getLocNo() + "库位不是在库状态");
        }
    }
}