自动化立体仓库 - WMS系统
lsh
17 小时以前 891f521b76049f9b013971cc4e3399300fd1082f
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -13,9 +13,11 @@
import com.zy.asrs.service.*;
import com.zy.asrs.utils.MatUtils;
import com.zy.asrs.utils.OrderInAndOutUtil;
import com.zy.asrs.utils.Utils;
import com.zy.common.constant.MesConstant;
import com.zy.common.entity.Parameter;
import com.zy.common.model.DetlDto;
import com.zy.common.model.LocDto;
import com.zy.common.model.MesCombParam;
import com.zy.common.model.enums.WorkNoType;
import com.zy.common.service.CommonService;
@@ -553,8 +555,8 @@
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
        if(param.getBarcode().length()!=8){
            throw new CoolException("条码长度不是8位===>>" + param.getBarcode());
        if(param.getBarcode().length()!=6){
            throw new CoolException("条码长度不是6位===>>" + param.getBarcode());
        }
//        if (param.getCombMats().size()>1){
//            throw new CoolException("不允许混料===>>" + param.getBarcode());
@@ -603,6 +605,12 @@
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setModiTime(now);
                waitPakin.setStandby1(detlDto.getStandby1());
                waitPakin.setStandby2(detlDto.getStandby2());
                waitPakin.setStandby3(detlDto.getStandby3());
                waitPakin.setBoxType1(detlDto.getBoxType1());
                waitPakin.setBoxType2(detlDto.getBoxType2());
                waitPakin.setBoxType3(detlDto.getBoxType3());
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
@@ -658,6 +666,12 @@
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setModiTime(now);
                waitPakin.setStandby1(detlDto.getStandby1());
                waitPakin.setStandby2(detlDto.getStandby2());
                waitPakin.setStandby3(detlDto.getStandby3());
                waitPakin.setBoxType1(detlDto.getBoxType1());
                waitPakin.setBoxType2(detlDto.getBoxType2());
                waitPakin.setBoxType3(detlDto.getBoxType3());
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
@@ -668,6 +682,323 @@
    }
    @Override
    @Transactional
    public void combAuto(CombParam param, Long userId) {
        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
            throw new CoolException(BaseRes.PARAM);
        }
//        if(param.getCombMats().size()>1){
//            throw new CoolException("请提取一个商品,或者刷新重新组托!");
//        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
        if(param.getBarcode().length()!=6){
            throw new CoolException("条码长度不是6位===>>" + param.getBarcode());
        }
//        if (param.getCombMats().size()>1){
//            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()));
        int countwait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getBarcode()));
        if (countLoc > 0 || countWrk > 0 || countwait > 0) {
            throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + param.getBarcode());
        }
        Date now = new Date();
        String orderNo = null;
        for (CombParam.CombMat combMat : param.getCombMats()) {
            List<OrderDetlPakin> orderDetlPakins = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>()
                    .eq("matnr", combMat.getMatnr()).eq("boxType3", combMat.getOrderNo())
                    .eq("standby1", combMat.getStandby1()).eq("standby2", combMat.getStandby2())
                    .eq("standby3", combMat.getStandby3()));
            if (orderDetlPakins.size() > 0) {
                orderNo = orderDetlPakins.get(0).getOrderNo();
                combMat.setBoxType1(orderDetlPakins.get(0).getBoxType1());
                combMat.setBoxType2(orderDetlPakins.get(0).getBoxType2());
                combMat.setBoxType3(orderDetlPakins.get(0).getBoxType3());
            } else {
                throw new CoolException("未查询到相关订单===>>" + param.getBarcode());
            }
        }
//        Order order = orderService.selectByNo(param.getOrderNo());
        Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, orderNo);
        if (Cools.isEmpty(order) || order.getSettle() > 2) {
            throw new CoolException("单据编号已过期");
        }
        // 生成入库通知档
        List<DetlDto> detlDtos = new ArrayList<>();
        param.getCombMats().forEach(elem -> {
            // 订单明细数量校验
//                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch());
            OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(),elem.getBrand(),elem.getStandby1(),elem.getStandby2(),elem.getStandby3(),
                    elem.getBoxType1(),elem.getBoxType2(),elem.getBoxType3());
            if (elem.getAnfme() > orderDetl.getEnableQty()) {
                throw new CoolException(orderDetl.getMatnr() + "入库数量不合法");
            }
            // 修改订单作业数量
//                if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) {
//                    throw new CoolException("修改单据作业数量失败");
//                }
            OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE,order.getId(), elem.getMatnr(), elem.getBatch(),elem.getBrand(),elem.getStandby1(),elem.getStandby2(),elem.getStandby3(),
                    elem.getBoxType1(),elem.getBoxType2(),elem.getBoxType3(), elem.getAnfme());
            DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(),elem.getBrand(),elem.getStandby1(),elem.getStandby2(),elem.getStandby3(),
                    elem.getBoxType1(),elem.getBoxType2(),elem.getBoxType3(),  elem.getAnfme());
            if (DetlDto.has(detlDtos, detlDto)) {
                DetlDto one = DetlDto.findDto(detlDtos, detlDto);
                assert one != null;
                one.setAnfme(one.getAnfme() + detlDto.getAnfme());
            } else {
                detlDtos.add(detlDto);
            }
        });
        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);
            waitPakin.setOrderNo(orderNo);   // 单据编号
            waitPakin.setBatch(detlDto.getBatch());     // 序列码
            waitPakin.setZpallet(param.getBarcode());   // 托盘码
            waitPakin.setIoStatus("N");     // 入出状态
            waitPakin.setAnfme(detlDto.getAnfme());  // 数量
            waitPakin.setStatus("Y");    // 状态
            waitPakin.setAppeUser(userId);
            waitPakin.setAppeTime(now);
            waitPakin.setModiUser(userId);
            waitPakin.setModiTime(now);
            waitPakin.setStandby1(detlDto.getStandby1());
            waitPakin.setStandby2(detlDto.getStandby2());
            waitPakin.setStandby3(detlDto.getStandby3());
            waitPakin.setBoxType1(detlDto.getBoxType1());
            waitPakin.setBoxType2(detlDto.getBoxType2());
            waitPakin.setBoxType3(detlDto.getBoxType3());
            if (!waitPakinService.insert(waitPakin)) {
                throw new CoolException("保存入库通知档失败");
            }
        }
//            orderService.updateSettle(order.getId(), 2L, userId);
        OrderInAndOutUtil.updateOrder(Boolean.TRUE,order.getId(), 2L, userId);
    }
    @Override
    @Transactional
    public R kittingQuery(CombParam combParam, Long userId) {
        List<Map<String, Object>> result = new ArrayList<>();
        List<LocDetl> locDetlResultList = new ArrayList<>();
        List<LocDetl> locDetlResultListHalf = new ArrayList<>();
        List<CombParam.CombMat> combMats = combParam.getCombMats();
        for (CombParam.CombMat combMat : combMats){
            Wrapper<LocDetl> wrapper = new EntityWrapper<LocDetl>()
                    .eq("matnr", combMat.getMatnr())
                    .eq("specs", combMat.getSpecs())
                    .eq("sku", combMat.getSku())
                    .eq("origin", "不在库");
            List<LocDetl> locDetlList = locDetlService.selectList(wrapper);
            for (LocDetl locDetl : locDetlList){
                LocDetlFusion locDetlFusion = getLocDetlFusion(combParam, locDetl.getLocNo());
                if (locDetlFusion.sign != 0 && locDetlFusion.sign != 9999){
                    if (locDetlFusion.sign == combMats.size()){
                        locDetlResultList.add(locDetlFusion.locDetl);
                    } else {
                        locDetlResultListHalf.add(locDetlFusion.locDetl);
                    }
                }
            }
        }
        for (LocDetl locDetl : locDetlResultList){
            Map<String, Object> map = new HashMap<>();
            map.put("locNo", locDetl.getLocNo());
            map.put("matnr", locDetl.getMatnr());
            map.put("sku", locDetl.getSku());
            map.put("anfme", locDetl.getAnfme());
            map.put("memo", locDetl.getMemo());
            result.add(map);
        }
        for (LocDetl locDetl : locDetlResultListHalf){
            Map<String, Object> map = new HashMap<>();
            map.put("locNo", locDetl.getLocNo());
            map.put("matnr", locDetl.getMatnr());
            map.put("sku", locDetl.getSku());
            map.put("anfme", locDetl.getAnfme());
            map.put("memo", locDetl.getMemo());
            result.add(map);
        }
        return R.ok().add(result);
    }
    public class LocDetlFusion{
        public Integer sign;
        public LocDetl locDetl;
        public LocDetlFusion(Integer sign, LocDetl locDetl) {
            this.sign = sign;
            this.locDetl = locDetl;
        }
    }
    public LocDetlFusion getLocDetlFusion(CombParam combParam,String locNo){
        LocDetl locDetl = new LocDetl();
        locDetl.setLocNo(locNo);
        locDetl.setAnfme(0D);
        Integer sign = 0;
        Map<Integer, LocDetl> map = new HashMap<>();
        List<LocDetl> locDetls= new ArrayList<>();
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo));
        if (locMast.getLocSts().equals("F")){
            List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo));
            for (CombParam.CombMat combMatNow : combParam.getCombMats()){
                boolean flag = true;
                while (flag){
                    flag = false;
                    for (LocDetl locDetlNow : locDetlList){
                        if (locDetlNow.getOrigin().equals("不在库")){
                            if (combMatNow.getMatnr().equals(locDetlNow.getMatnr())){
                                if (combMatNow.getAnfme().equals(locDetlNow.getAnfme())){
                                    LocDetl locDetlAdd = new LocDetl();
                                    locDetlAdd.sync(locDetlNow);
                                    locDetls.add(locDetlAdd);
                                    locDetlList.remove(locDetlNow);
                                    sign++;
                                    combMatNow.setMemo("完全匹配");
                                    break;
                                } else if (combMatNow.getAnfme()>locDetlNow.getAnfme()){
                                    double anfme = combMatNow.getAnfme() - locDetlNow.getAnfme();
                                    combMatNow.setAnfme(anfme);
                                    LocDetl locDetlAdd = new LocDetl();
                                    locDetlAdd.sync(locDetlNow);
                                    locDetls.add(locDetlAdd);
                                    locDetlList.remove(locDetlNow);
                                    flag = true;
                                    break;
                                } else if (combMatNow.getAnfme()<locDetlNow.getAnfme()){
                                    double anfme = locDetlNow.getAnfme() - combMatNow.getAnfme();
                                    locDetlNow.setAnfme(combMatNow.getAnfme());
                                    LocDetl locDetlAdd = new LocDetl();
                                    locDetlAdd.sync(locDetlNow);
                                    locDetls.add(locDetlAdd);
                                    locDetlNow.setAnfme(anfme);
                                    sign++;
                                    combMatNow.setMemo("完全匹配");
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (sign == combParam.getCombMats().size()){
                if (locDetlList.size() == 0 ){
                    locDetl.setMemo("完全匹配");
                } else {
                    locDetl.setMemo("溢出匹配");
                }
            } else if (locDetls.size() != 0 ){
                locDetl.setMemo("未完全匹配");
                sign = 99999999;
            }
        }
        for (LocDetl locDetlNow : locDetls){
            if (Cools.isEmpty(locDetl.getMatnr())){
                locDetl.setMatnr(locDetlNow.getMatnr());
            } else {
                locDetl.setMatnr(locDetl.getMatnr() + "," + locDetlNow.getMatnr());
            }
            if (Cools.isEmpty(locDetl.getSku())){
                locDetl.setSku(locDetlNow.getSku());
            } else {
                locDetl.setSku(locDetl.getSku() + "," + locDetlNow.getSku());
            }
            locDetl.setAnfme(locDetlNow.getAnfme() + locDetl.getAnfme());
        }
        return new LocDetlFusion(sign,locDetl);
    }
    @Override
    @Transactional
    public void kittingCall(String locNo, Long userId) {
        try{
            List<StockOutParam.LocDetl> locDetls = new ArrayList<>();
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo));
            if (locMast.getLocSts().equals("F")){
                List<LocDetl> locDetlList = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo));
                for (LocDetl locDetl:locDetlList){
                    StockOutParam.LocDetl locDto = new StockOutParam.LocDetl();
                    locDto.setLocNo(locDetl.getLocNo());
                    locDto.setMatnr(locDetl.getMatnr());
                    locDto.setBatch(locDetl.getBatch());
                    locDto.setBrand(locDetl.getBrand());
                    locDto.setCount(locDetl.getAnfme());
                    locDto.setStandby1(locDetl.getStandby1());
                    locDto.setStandby2(locDetl.getStandby2());
                    locDto.setStandby3(locDetl.getStandby3());
                    locDto.setBoxType1(locDetl.getBoxType1());
                    locDto.setBoxType2(locDetl.getBoxType2());
                    locDto.setBoxType3(locDetl.getBoxType3());
                    locDetls.add(locDto);
                }
            }
            StockOutParam param = new StockOutParam();
            param.setOutSite(101);
            param.setLocDetls(locDetls);
            WorkService workService = SpringUtils.getBean(WorkService.class);
            workService.locCheckOut(param,userId);
        } catch (Exception e){
            throw new CoolException("盘点启动失败!!!");
        }
    }
    @Override
    @Transactional
    public R locOriginInOut(LocDetl locDetl, Long userId) {
        try{
            Wrapper<LocDetl> wrapper = new EntityWrapper<LocDetl>()
                    .eq("loc_no", locDetl.getLocNo())
                    .eq("zpallet", locDetl.getZpallet())
                    .eq("matnr", locDetl.getMatnr())
                    .eq("specs", locDetl.getSpecs())
                    .eq("batch", locDetl.getBatch())
                    .eq("origin", locDetl.getOrigin());
            LocDetl locDetl1 = locDetlService.selectOne(wrapper);
            if (Cools.isEmpty(locDetl1)){
                return R.error();
            } else if (locDetl1.getOrigin().equals("不在库")){
                locDetl1.setOrigin("在库");
            }else{
                locDetl1.setOrigin("不在库");
            }
            if (locDetlService.update(locDetl1,wrapper)){
                return R.ok();
            }
        } catch (Exception e){
        }
        return R.error();
    }
    // 商品上架
    @Override
    public void onSale(CombParam param) {