自动化立体仓库 - WMS系统
#
LSH
2023-02-14 c46f9c28f8d40d2a4efcc7ef6e528661d97a4be0
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -1,6 +1,8 @@
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.core.common.BaseRes;
@@ -102,7 +104,7 @@
        wrkMast.setIoType(1); // 入出库状态:1.入库
        Double ioPri = wrkMastService.getIoPri(1, dto.getLocNo());
        wrkMast.setIoPri(ioPri); // 优先级:13
        wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo(), true)?1:0);;
        wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo(), true) ? 1 : 0);
        wrkMast.setCrnNo(dto.getCrnNo());
        wrkMast.setSourceStaNo(dto.getSourceStaNo());
        wrkMast.setStaNo(dto.getStaNo());
@@ -138,20 +140,20 @@
        sourceStaNo.setWrkNo(workNo);
        sourceStaNo.setModiUser(userId);
        sourceStaNo.setModiTime(now);
        if (!basDevpService.updateById(sourceStaNo)){
        if (!basDevpService.updateById(sourceStaNo)) {
            throw new CoolException("更新源站失败");
        }
        // 更新目标库位状态
        LocMast locMast = locMastService.selectById(dto.getLocNo());
        if (locMast.getLocSts().equals("O")){
        if (locMast.getLocSts().equals("O")) {
            locMast.setLocSts("S"); // S.入库预约
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
            if (!locMastService.updateById(locMast)){
            if (!locMastService.updateById(locMast)) {
                throw new CoolException("改变库位状态失败");
            }
        } else {
            throw new CoolException(dto.getLocNo()+"目标库位已被占用");
            throw new CoolException(dto.getLocNo() + "目标库位已被占用");
        }
        return dto.getLocNo();
    }
@@ -170,8 +172,13 @@
            }
        }
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 101.出库
            stockOut(staNo, locDetlDtos, null, userId);
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo()));
            if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") ){
                // 启动出库开始 101.出库
                stockOut(staNo, locDetlDtos, null, userId);
            }else {
                throw new CoolException("所选库位存在状态不为F、D的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$());
            }
        } else {
            throw new CoolException("库存不存在");
        }
@@ -215,9 +222,9 @@
                ioType = dto.isAll() ? 101 : 103;
            } else if (ioWorkType.equals(IoWorkType.CHECK_OUT)) {
                ioType = 107;
                if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 107)) > 0) {
                    throw new CoolException("只能存在一笔盘点任务");
                }
                // if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 107)) > 0) {
                //     throw new CoolException("只能存在一笔盘点任务");
                // }
            }
            assert ioType != null;
            // 获取库位
@@ -233,8 +240,8 @@
            wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
            wrkMast.setIoType(ioType); // 入出库状态
            Double ioPri = wrkMastService.getIoPri(ioType, dto.getLocNo());
            wrkMast.setIoPri(ioPri); // 优先级:13
            wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo(), false)?1:0);;
            wrkMast.setIoPri(15D); // 优先级:13
            wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo(), false) ? 1 : 0);
            wrkMast.setCrnNo(locMast.getCrnNo());
            wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
            wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
@@ -250,22 +257,25 @@
            wrkMast.setModiUser(userId);
            wrkMast.setModiTime(now);
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,出库库位号:"+dto.getLocNo());
                throw new CoolException("保存工作档失败,出库库位号:" + dto.getLocNo());
            }
            // 生成工作档明细
            for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;}
                if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) {
                    continue;
                }
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.sync(detlDto.getLocDetl());
                wrkDetl.setOrderNo(""); // 手动出库不需要带出库存中的单据编号
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(now);
                Double anfme = ioType==101?detlDto.getLocDetl().getAnfme():detlDto.getCount();
                Double anfme = ioType == 101 ? detlDto.getLocDetl().getAnfme() : detlDto.getCount();
                wrkDetl.setAnfme(anfme); // 数量
                wrkDetl.setAppeTime(now);
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(now);
                wrkDetl.setModiUser(userId);
                wrkDetl.setSpecs(detlDto.getLocDetl().getSpecs());
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
@@ -273,16 +283,16 @@
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(dto.getLocNo());
            if (locMast.getLocSts().equals("F")) {
                locMast.setLocSts(ioType==101?"R":"P");
                locMast.setLocSts(ioType == 101 ? "R" : "P");
                locMast.setModiUser(userId);
                locMast.setModiTime(now);
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("预约库位状态失败,库位号:"+dto.getLocNo());
                    throw new CoolException("预约库位状态失败,库位号:" + dto.getLocNo());
                }
            } else {
                throw new CoolException(dto.getLocNo() + "库位不是在库状态");
            }
            locMastService.breakUp(dto.getLocNo(), excludeLocNos);
//            locMastService.breakUp(dto.getLocNo(), excludeLocNos);
        }
    }
@@ -311,7 +321,7 @@
        wrkMast.setIoType(ioType); // 入出库状态
        Double ioPri = wrkMastService.getIoPri(ioType, taskDto.getLocNo());
        wrkMast.setIoPri(ioPri); // 优先级:13
        wrkMast.setOutMost(locMastService.isOutMost(taskDto.getLocNo(), false)?1:0);;
        wrkMast.setOutMost(locMastService.isOutMost(taskDto.getLocNo(), false) ? 1 : 0);
        wrkMast.setCrnNo(locMast.getCrnNo());
        wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
        wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
@@ -327,11 +337,13 @@
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("保存工作档失败,出库库位号:"+taskDto.getLocNo());
            throw new CoolException("保存工作档失败,出库库位号:" + taskDto.getLocNo());
        }
        // 生成工作档明细
        for (LocDto locDto : taskDto.getLocDtos()) {
            if (locDto.getAnfme()==null || locDto.getAnfme() <= 0.0D) { continue; }
            if (locDto.getAnfme() == null || locDto.getAnfme() <= 0.0D) {
                continue;
            }
            LocDetl locDetl = locDetlService.selectItem(locDto.getLocNo(), locDto.getMatnr(), locDto.getBatch());
            if (locDetl == null || locDetl.getAnfme() < locDto.getAnfme()) {
                throw new CoolException(locDto.getLocNo() + "库位中" + locDto.getMatnr() + "商品库存不足!");
@@ -354,29 +366,41 @@
                throw new CoolException("保存工作档明细失败");
            }
            // 修改订单明细
            if (BaseController.isJSON(locDto.getOrderNo())) {
            if (!BaseController.isJSON(locDto.getOrderNo())) {
                String[] orderNos = GetOrderNo(locDto.getOrderNo());
                Double anfme = locDto.getAnfme();
                for (String orderNo:orderNos){
                    OrderDetl orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), locDto.getBatch());
                    if (orderDetl == null) {
                        orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), null);
                if (!Cools.isEmpty(orderNos)){
                    Double anfme = locDto.getAnfme();
                    for (String orderNo : orderNos) {
                        OrderDetl orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), locDto.getBatch());
                        if (orderDetl == null) {
                            orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), null);
                        }
                        if (orderDetl.getAnfme() <= anfme) {
                            if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getAnfme())) {
                                throw new CoolException("修改订单明细数量失败");
                            }
                            anfme = anfme - orderDetl.getAnfme();
                        } else {
                            if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), anfme)) {
                                throw new CoolException("修改订单明细数量失败");
                            }
                        }
                        orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
                    }
                    if (orderDetl.getAnfme()<=anfme){
                        if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(),orderDetl.getAnfme())) {
                            throw new CoolException("修改订单明细数量失败");
                        }
                        anfme=anfme-orderDetl.getAnfme();
                    }else{
                        if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(),anfme)) {
                            throw new CoolException("修改订单明细数量失败");
                        }
                }else {
                    OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
                    if (orderDetl == null) {
                        orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null);
                    }
                    if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) {
                        throw new CoolException("修改订单明细数量失败");
                    }
                    orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
                }
            } else {
                // 订单合并出库
                List<OrderDto> orderDtoList = JSON.parseArray(locDto.getOrderNo(), OrderDto.class);
                for (OrderDto orderDto : orderDtoList) {
                    OrderDetl orderDetl = orderDetlService.selectItem(orderDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
                    if (orderDetl == null) {
@@ -392,41 +416,46 @@
        // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
        locMast = locMastService.selectById(taskDto.getLocNo());
        if (locMast.getLocSts().equals("F")) {
            locMast.setLocSts(ioType==101?"R":"P");
            locMast.setLocSts(ioType == 101 ? "R" : "P");
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
            if (!locMastService.updateById(locMast)) {
                throw new CoolException("预约库位状态失败,库位号:"+taskDto.getLocNo());
                throw new CoolException("预约库位状态失败,库位号:" + taskDto.getLocNo());
            }
        } else {
            throw new CoolException(taskDto.getLocNo() + "库位不是在库状态");
        }
    }
    private String[] GetOrderNo(String orderNo){
        String[] s3= orderNo.split("\"");
        String[] s =new String[(s3.length-1)/6];
        int i=0;
        int j=0;
        for (String ss:s3){
            if (ss.equals("orderNo")){
                s[i]=s3[j+2];
                i++;
    private String[] GetOrderNo(String orderNo) {
        String[] s3 = orderNo.split("\"");
        String[] s = new String[(s3.length - 1) / 6];
        if (!Cools.isEmpty(s3)){
            int i = 0;
            int j = 0;
            for (String ss : s3) {
                if (ss.equals("orderNo")) {
                    s[i] = s3[j + 2];
                    i++;
                }
                j++;
            }
            j++;
        }else {
            s=null;
        }
        return s;
    }
    private String[] GetAnfme(String orderNo){
        String[] s3= orderNo.split("\"");
        String[] s =new String[(s3.length-1)/6];
        int i=0;
        int j=0;
        for (String ss:s3){
            if (ss.equals("anfme")){
    private String[] GetAnfme(String orderNo) {
        String[] s3 = orderNo.split("\"");
        String[] s = new String[(s3.length - 1) / 6];
        int i = 0;
        int j = 0;
        for (String ss : s3) {
            if (ss.equals("anfme")) {
                String[] s4 = s3[j + 1].split(":");
                String[] s5 = s4[1].split("\\.");
                s[i]=s5[0];
                s[i] = s5[0];
                i++;
            }
            j++;
@@ -451,7 +480,7 @@
        wrkMast.setIoType(10); // 入出库状态:10.空板入库
        Double ioPri = wrkMastService.getIoPri(10, dto.getLocNo());
        wrkMast.setIoPri(ioPri); // 优先级:10
        wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo(), true)?1:0);;
        wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo(), true) ? 1 : 0);
        wrkMast.setCrnNo(dto.getCrnNo());
        wrkMast.setSourceStaNo(dto.getSourceStaNo());
        wrkMast.setStaNo(dto.getStaNo());
@@ -475,20 +504,20 @@
        sourceStaNo.setWrkNo(workNo);
        sourceStaNo.setModiUser(userId);
        sourceStaNo.setModiTime(new Date());
        if (!basDevpService.updateById(sourceStaNo)){
        if (!basDevpService.updateById(sourceStaNo)) {
            throw new CoolException("更新源站失败");
        }
        // 更新目标库位状态
        LocMast locMast = locMastService.selectById(dto.getLocNo());
        if (locMast.getLocSts().equals("O")){
        if (locMast.getLocSts().equals("O")) {
            locMast.setLocSts("S"); // S.入库预约
            locMast.setModiUser(userId);
            locMast.setModiTime(new Date());
            if (!locMastService.updateById(locMast)){
            if (!locMastService.updateById(locMast)) {
                throw new CoolException("改变库位状态失败");
            }
        } else {
            throw new CoolException(dto.getLocNo()+"目标库位已被占用");
            throw new CoolException(dto.getLocNo() + "目标库位已被占用");
        }
        return dto.getLocNo();
    }
@@ -512,7 +541,10 @@
            // 获取库位
            LocMast locMast = locMastService.selectById(locNo);
            if (Cools.isEmpty(locMast)) {
                throw new CoolException(locNo+"库位不存在");
                throw new CoolException(locNo + "库位不存在");
            }
            if (!locMast.getLocSts().equals("D")){
                throw new CoolException("所选库位存在状态不为D的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$());
            }
            // 获取源站
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
@@ -537,7 +569,7 @@
            wrkMast.setIoPri(ioPri);
            wrkMast.setSourceStaNo(sourceStaNo); // 源站
            wrkMast.setStaNo(param.getOutSite()); // 目标站
            wrkMast.setOutMost(locMastService.isOutMost(locNo, false)?1:0);;
            wrkMast.setOutMost(locMastService.isOutMost(locNo, false) ? 1 : 0);
            wrkMast.setCrnNo(locMast.getCrnNo());
            wrkMast.setSourceLocNo(locNo); // 源库位
            wrkMast.setFullPlt("N"); // 满板:Y
@@ -554,7 +586,7 @@
                throw new CoolException("保存工作档失败");
            }
            // 更新库位状态 D.空板 -> R.出库预约
            if (locMast.getLocSts().equals("D")){
            if (locMast.getLocSts().equals("D")) {
                locMast.setLocSts("R");
                locMast.setModiUser(userId);
                locMast.setModiTime(new Date());
@@ -568,9 +600,9 @@
    @Override
    @Transactional
    public void locCheckOut(StockOutParam param, Long userId) {
        if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 107)) > 0) {
            throw new CoolException("只能存在一笔盘点任务");
        }
        // if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 107)) > 0) {
        //     throw new CoolException("只能存在一笔盘点任务");
        // }
        // 目标站点状态检测
        BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
        // 获取库位明细
@@ -582,8 +614,14 @@
            }
        }
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 107.盘点出库
            stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlDtos.get(0).getLocDetl().getLocNo()));
            if (locMast.getLocSts().equals("F")){
                // 启动出库开始 107.盘点出库
                stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
            }else {
                throw new CoolException("所选库位存在状态不为F的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$());
            }
        } else {
            throw new CoolException("库位物料不存在");
        }
@@ -594,12 +632,15 @@
    public void locMove(String sourceLocNo, String locNo, Long userId) {
        LocMast sourceLoc = locMastService.selectById(sourceLocNo);
        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
        if (Cools.isEmpty(sourceLoc)){
        if (Cools.isEmpty(sourceLoc)) {
            throw new CoolException("未找到库位");
        }
        LocMast loc = locMastService.selectById(locNo);
        if (Cools.isEmpty(loc)){
        if (Cools.isEmpty(loc)) {
            throw new CoolException("未找到库位");
        }
        if (!loc.getLocSts().equals("O")||(!sourceLoc.getLocSts().equals("F") && !sourceLoc.getLocSts().equals("D"))){
            throw new CoolException("库位状态已改变");
        }
        if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) {
//            throw new CoolException("移转库位属于不同堆垛机");   todo:luxiaotao
@@ -614,14 +655,14 @@
        wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
        wrkMast.setIoType(11); // 入出库状态: 11.库格移载
        wrkMast.setIoPri(10D);
        wrkMast.setOutMost(locMastService.isOutMost(locNo, false)?1:0);;
        wrkMast.setOutMost(locMastService.isOutMost(locNo, false) ? 1 : 0);
        wrkMast.setCrnNo(sourceLoc.getCrnNo());
        wrkMast.setSourceLocNo(sourceLocNo); // 源库位
        wrkMast.setLocNo(locNo); // 目标库位
        wrkMast.setFullPlt(Cools.isEmpty(locDetls)?"N":"Y"); // 满板:Y
        wrkMast.setFullPlt(Cools.isEmpty(locDetls) ? "N" : "Y"); // 满板:Y
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板
        wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
        wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码
        wrkMast.setLinkMis("N");
        wrkMast.setAppeUser(userId);
@@ -652,11 +693,11 @@
            sourceLoc.setLocSts("R"); // R.出库预约
            sourceLoc.setModiUser(userId);
            sourceLoc.setModiTime(now);
            if (!locMastService.updateById(sourceLoc)){
            if (!locMastService.updateById(sourceLoc)) {
                throw new CoolException("更新源库位状态失败");
            }
        } else {
            throw new CoolException(sourceLoc.getLocNo() + "源库位出库失败,状态:"+sourceLoc.getLocSts$());
            throw new CoolException(sourceLoc.getLocNo() + "源库位出库失败,状态:" + sourceLoc.getLocSts$());
        }
        // 修改目标库位状态
        if (loc.getLocSts().equals("O")) {
@@ -667,7 +708,7 @@
                throw new CoolException("更新目标库位状态失败");
            }
        } else {
            throw new CoolException("移转失败,目标库位状态:"+loc.getLocSts$());
            throw new CoolException("移转失败,目标库位状态:" + loc.getLocSts$());
        }
    }
@@ -675,17 +716,18 @@
    @Transactional
    public void completeWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){
            throw new CoolException(workNo+"工作档不存在");
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException(workNo + "工作档不存在");
        }
        if (wrkMast.getWrkSts() == 9 || wrkMast.getWrkSts() == 17) {
            throw new CoolException("当前工作档已完成");
        }
        // 入库 + 库位转移
        if (wrkMast.getWrkSts() < 9 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType()==11)) {
        if (wrkMast.getWrkSts() < 9 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType() == 11)) {
            wrkMast.setWrkSts(9L);
            // 出库
        } else if (wrkMast.getWrkSts() > 10) {
            wrkMast.setSteNo(0);
            wrkMast.setWrkSts(17L);
        }
        Date now = new Date();
@@ -725,7 +767,9 @@
            Iterator<LocDetlAdjustParam.LocDetlAdjust> iterator1 = list.iterator();
            while (iterator1.hasNext()) {
                LocDetlAdjustParam.LocDetlAdjust adjust = iterator1.next();
                if (adjust.getCount() == 0) { continue; }
                if (adjust.getCount() == 0) {
                    continue;
                }
                if (locDetl.getMatnr().equals(adjust.getMatnr()) && Cools.eq(locDetl.getBatch(), adjust.getBatch())) {
                    if (!locDetl.getAnfme().equals(adjust.getCount())) {
                        // todo 盘点记录
@@ -774,7 +818,9 @@
        // 添加库存
        for (LocDetlAdjustParam.LocDetlAdjust adjust : list) {
            if (adjust.getCount() == 0.0D) { continue; }
            if (adjust.getCount() == 0.0D) {
                continue;
            }
            Mat mat = matService.selectByMatnr(adjust.getMatnr());
            LocDetl locDetl = new LocDetl();
            locDetl.sync(mat);
@@ -825,8 +871,8 @@
    @Transactional
    public void cancelWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){
            throw new CoolException(workNo+"工作档不存在");
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException(workNo + "工作档不存在");
        }
        String locNo = ""; // 待修改目标库位
        String locSts = ""; // 待修改目标库位状态
@@ -840,29 +886,32 @@
                // 库位转移:源库位
                LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("取消库位转移失败,源库位不存在:"+ wrkMast.getSourceLocNo());
                    throw new CoolException("取消库位转移失败,源库位不存在:" + wrkMast.getSourceLocNo());
                }
                locMast.setLocSts("F");
                locMast.setModiTime(new Date());
                locMast.setModiUser(userId);
                locMastService.updateById(locMast);
            }
        // 出库取消(修改源库位)
            // 出库取消(修改源库位)
        } else if (wrkMast.getWrkSts() > 10 && wrkMast.getWrkSts() != 19) {
            locNo = wrkMast.getSourceLocNo();
            // 出库 ===>> F.在库
            if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) {
                locSts = "F";
            // 空板出库 ===>> D.空桶/空栈板
                // 空板出库 ===>> D.空桶/空栈板
            } else if (wrkMast.getIoType() == 110) {
                locSts = "D";
            // 库位转移 ===>> D.空桶/空栈板
                // 库位转移 ===>> D.空桶/空栈板
            } else if (wrkMast.getIoType() == 11) {
                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N")?"D":"F";
                if (wrkMast.getWrkSts() > 11){
                    throw new CoolException("移库任务已在执行中,不能取消");
                }
                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F";
                // 库位转移:目标库位
                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("取消库位转移失败,目标库位不存在:"+ wrkMast.getSourceLocNo());
                    throw new CoolException("取消库位转移失败,目标库位不存在:" + wrkMast.getSourceLocNo());
                }
                locMast.setLocSts("O");
                locMast.setModiTime(new Date());
@@ -875,15 +924,33 @@
        // 订单关联
        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
        for (WrkDetl wrkDetl : wrkDetls) {
            String[] orderNos = GetOrderNo(wrkDetl.getOrderNo());
            String[] anfmes = GetAnfme(wrkDetl.getOrderNo());
            int i=0;
            for (String orderNo:orderNos){
                if (!Cools.isEmpty(orderNo)) {
                    Double anfme=Integer.parseInt(anfmes[i])+0.0;
                    i++;
                    if (BaseController.isJSON(wrkDetl.getOrderNo())) {
                        if (!orderDetlService.decrease(orderNo, wrkDetl.getMatnr(), wrkDetl.getBatch(), anfme)) {
            if (!Cools.isEmpty(wrkDetl.getOrderNo())){
                String[] orderNos = GetOrderNo(wrkDetl.getOrderNo());
                if (!Cools.isEmpty(orderNos)){
                    String[] anfmes = GetAnfme(wrkDetl.getOrderNo());
                    int i = 0;
                    for (String orderNo : orderNos) {
                        if (!Cools.isEmpty(orderNo)) {
                            Double anfme = Integer.parseInt(anfmes[i]) + 0.0;
                            i++;
                            if (!BaseController.isJSON(wrkDetl.getOrderNo())) {
                                if (!orderDetlService.decrease(orderNo, wrkDetl.getMatnr(), wrkDetl.getBatch(), anfme)) {
                                    throw new CoolException("订单数据回滚失败");
                                }
                            } else {
                                // 订单合并出库
                                List<OrderDto> orderDtoList = JSON.parseArray(wrkDetl.getOrderNo(), OrderDto.class);
                                for (OrderDto orderDto : orderDtoList) {
                                    if (!orderDetlService.decrease(orderDto.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), orderDto.getAnfme())) {
                                        throw new CoolException("订单数据回滚失败");
                                    }
                                }
                            }
                        }
                    }
                }else {
                    if (!BaseController.isJSON(wrkDetl.getOrderNo())) {
                        if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) {
                            throw new CoolException("订单数据回滚失败");
                        }
                    } else {
@@ -924,7 +991,7 @@
        // 修改库位状态
        LocMast locMast = locMastService.selectById(locNo);
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("取消工作档失败,库位不存在:"+ locNo);
            throw new CoolException("取消工作档失败,库位不存在:" + locNo);
        }
        locMast.setLocSts(locSts);
        locMast.setModiTime(new Date());
@@ -939,8 +1006,8 @@
    @Transactional
    public void pickWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){
            throw new CoolException(workNo+"工作档不存在");
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException(workNo + "工作档不存在");
        }
        // 入出库类型判断
        if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107) {
@@ -1016,9 +1083,9 @@
        if (Cools.isEmpty(locNos)) {
            return;
        }
        if (true && !Cools.isEmpty(locNos)) {
            throw new CoolException("暂不支持移库任务");    // todo:luxiaotao 移库开关
        }
//        if (true && !Cools.isEmpty(locNos)) {
//            throw new CoolException("暂不支持移库任务");    // todo:luxiaotao 移库开关
//        }
        LocMast one = locMastService.selectById(locNos.get(0));
        List<Integer> rows = Utils.getGroupLoc(Integer.parseInt(locNos.get(0).substring(0, 2)));
        List<LocMast> locMasts = locMastService.queryFreeLocMast(rows, rows.size(), one.getLocType1());
@@ -1053,11 +1120,11 @@
            while (iterator.hasNext()) {
                LocMast sourceLoc = locMastService.selectById(sourceLocNo);
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
                if (Cools.isEmpty(sourceLoc)){
                if (Cools.isEmpty(sourceLoc)) {
                    throw new CoolException("未找到库位");
                }
                LocMast loc = iterator.next();
                if (Cools.isEmpty(loc)){
                if (Cools.isEmpty(loc)) {
                    throw new CoolException("未找到库位");
                }
                if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) {
@@ -1072,14 +1139,14 @@
                wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
                wrkMast.setIoType(11); // 入出库状态: 11.库格移载
                wrkMast.setIoPri(15D);
                wrkMast.setOutMost(locMastService.isOutMost(loc.getLocNo(), false)?1:0);;
                wrkMast.setOutMost(locMastService.isOutMost(loc.getLocNo(), false) ? 1 : 0);
                wrkMast.setCrnNo(sourceLoc.getCrnNo());
                wrkMast.setSourceLocNo(sourceLocNo); // 源库位
                wrkMast.setLocNo(loc.getLocNo()); // 目标库位
                wrkMast.setFullPlt(Cools.isEmpty(locDetls)?"N":"Y"); // 满板:Y
                wrkMast.setFullPlt(Cools.isEmpty(locDetls) ? "N" : "Y"); // 满板:Y
                wrkMast.setPicking("N"); // 拣料
                wrkMast.setExitMk("N"); // 退出
                wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板
                wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
                wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码
                wrkMast.setLinkMis("N");
                wrkMast.setAppeUser(9527L);
@@ -1110,11 +1177,11 @@
                    sourceLoc.setLocSts("R"); // R.出库预约
                    sourceLoc.setModiUser(9527L);
                    sourceLoc.setModiTime(now);
                    if (!locMastService.updateById(sourceLoc)){
                    if (!locMastService.updateById(sourceLoc)) {
                        throw new CoolException("更新源库位状态失败");
                    }
                } else {
                    throw new CoolException(sourceLoc.getLocNo() + "源库位出库失败,状态:"+sourceLoc.getLocSts$());
                    throw new CoolException(sourceLoc.getLocNo() + "源库位出库失败,状态:" + sourceLoc.getLocSts$());
                }
                // 修改目标库位状态
                if (loc.getLocSts().equals("O")) {
@@ -1125,7 +1192,7 @@
                        throw new CoolException("更新目标库位状态失败");
                    }
                } else {
                    throw new CoolException("移转失败,目标库位状态:"+loc.getLocSts$());
                    throw new CoolException("移转失败,目标库位状态:" + loc.getLocSts$());
                }
                iterator.remove();