自动化立体仓库 - WMS系统
13
zhang
15 小时以前 10d7b3239e4baec952b9ee8a3e948399916d336c
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -7,13 +7,12 @@
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.entity.param.ForwardAGVTaskParam;
import com.zy.asrs.entity.param.MobileAdjustParam;
import com.zy.asrs.entity.param.OpenOrderPakinParam;
import com.zy.asrs.mapper.BasDevpMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.third.CodeDataParam;
import com.zy.asrs.third.CodeParam;
import com.zy.asrs.third.MesResponse;
import com.zy.asrs.third.TokenUtils;
import com.zy.asrs.utils.MatUtils;
import com.zy.common.constant.AgvSiteConstant;
import com.zy.common.constant.ApiInterfaceConstant;
@@ -29,9 +28,6 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -137,12 +133,7 @@
        String message = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri(ApiInterfaceConstant.AGV_IP)
                    .setPath(ApiInterfaceConstant.AGV_CALL_IN_PATH)
                    .setJson(body)
                    .build()
                    .doPost();
            response = new HttpHandler.Builder().setUri(ApiInterfaceConstant.AGV_IP).setPath(ApiInterfaceConstant.AGV_CALL_IN_PATH).setJson(body).build().doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("code").equals(0)) {
                success = true;
@@ -158,15 +149,7 @@
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "入库呼叫agv",
                        ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_CALL_IN_PATH,
                        null,
                        "127.0.0.1",
                        body,
                        response,
                        success
                );
                apiLogService.save("入库呼叫agv", ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_CALL_IN_PATH, null, "127.0.0.1", body, response, success);
            } catch (Exception e) {
                log.error("", e);
            }
@@ -192,12 +175,7 @@
        String message = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri(ApiInterfaceConstant.AGV_IP)
                    .setPath(ApiInterfaceConstant.AGV_BIND_PATH)
                    .setJson(body)
                    .build()
                    .doPost();
            response = new HttpHandler.Builder().setUri(ApiInterfaceConstant.AGV_IP).setPath(ApiInterfaceConstant.AGV_BIND_PATH).setJson(body).build().doPost();
            JSONObject res = JSON.parseObject(response);
            message = jsonObject.getString("message");
            if (res.getInteger("code").equals(0)) {
@@ -210,15 +188,7 @@
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "调用agv解绑暂存位",
                        ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_BIND_PATH,
                        null,
                        "127.0.0.1",
                        body,
                        response,
                        success
                );
                apiLogService.save("调用agv解绑暂存位", ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_BIND_PATH, null, "127.0.0.1", body, response, success);
            } catch (Exception e) {
                log.error("", e);
            }
@@ -242,12 +212,7 @@
        String response = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri(ApiInterfaceConstant.AGV_IP)
                    .setPath(ApiInterfaceConstant.AGV_BIND_PATH)
                    .setJson(body)
                    .build()
                    .doPost();
            response = new HttpHandler.Builder().setUri(ApiInterfaceConstant.AGV_IP).setPath(ApiInterfaceConstant.AGV_BIND_PATH).setJson(body).build().doPost();
            JSONObject res = JSON.parseObject(response);
            if (res.getInteger("code").equals(0)) {
                success = true;
@@ -259,15 +224,7 @@
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "调用agv绑定仓位",
                        ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_BIND_PATH,
                        null,
                        "127.0.0.1",
                        body,
                        response,
                        success
                );
                apiLogService.save("调用agv绑定仓位", ApiInterfaceConstant.AGV_IP + ApiInterfaceConstant.AGV_BIND_PATH, null, "127.0.0.1", body, response, success);
            } catch (Exception e) {
                log.error("", e);
            }
@@ -281,32 +238,26 @@
        if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) {
            throw new CoolException(BaseRes.PARAM);
        }
        HashMap<String, Object> comData = new HashMap<>();
        param.getCombMats().forEach(elem -> {
            // 判断是否有相同条码的数据
            if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                    eq("zpallet", param.getBarcode())
                    .eq("io_status", "N")
                    .eq("matnr", elem.getMatnr()).eq("batch", elem.getBatch())) > 0) {
                throw new CoolException(param.getBarcode() + "已有相同数据");
            }
            if (comData.get(elem.getThreeCode()) == null) {
                comData.put(elem.getThreeCode(), elem);
            } else {
                throw new CoolException(elem.getThreeCode() + "该条码扫码了多次");
            }
        });
//        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() != 8) {
            throw new CoolException("条码长度不是8位===>>" + 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) {
            throw new CoolException("工作档/库存条码数据已存在===>>" + 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();
@@ -317,15 +268,6 @@
            // 生成入库通知档
            List<DetlDto> detlDtos = new ArrayList<>();
            param.getCombMats().forEach(elem -> {
                // 判断是否有相同条码的数据
                if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                        eq("zpallet", param.getBarcode())
                        .eq("io_status", "N")
                        .eq("matnr", elem.getMatnr()).eq("three_code", elem.getThreeCode())) > 0) {
                    throw new CoolException(param.getBarcode() + "已有相同数据");
                }
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
@@ -344,8 +286,8 @@
                }
                WaitPakin waitPakin = new WaitPakin();
                waitPakin.sync(mat);
                waitPakin.setSku(detlDto.getBatch());
                //waitPakin.setBatch(detlDto.getBatch());
                waitPakin.setTemp2(detlDto.getTemp2());
                waitPakin.setBatch(detlDto.getBatch());
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
@@ -360,135 +302,53 @@
            }
            // 关联组托
        } else {
            Order order = orderService.selectByNo(param.getOrderNo());
            Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", param.getOrderNo()));
            if (Cools.isEmpty(order) || order.getSettle() > 2) {
                throw new CoolException("单据编号已过期");
            }
            // 生成入库通知档
            List<DetlDto> detlDtos = new ArrayList<>();
            List<String> codes = new ArrayList<>();
            for (CombParam.CombMat elem : param.getCombMats()) {
                codes.add(elem.getThreeCode());
            }
            List<CodeDataParam> data = getData(TokenUtils.getToken(url), new CodeParam(codes));
            List<CombParam.CombMat> combMats = param.getCombMats();
            for (int i = 0; i < data.size(); i++) {
                //}
                //for (CombParam.CombMat elem : param.getCombMats()) {
                CombParam.CombMat elem = combMats.get(i);
                CodeDataParam codeDataParam = data.get(i);
                elem.setTemp1(codeDataParam.getQuality());
                elem.setAnfme(codeDataParam.getQty());
                //elem.setBatch(codeDataParam.getBatchNum());
                elem.setThreeCode(codeDataParam.getBarcode());
                elem.setMatnr(codeDataParam.getProductionCode());
                elem.setMaktx(codeDataParam.getProductionName());
//            param.getCombMats().forEach(elem -> {
            param.getCombMats().forEach(elem -> {
                // 订单明细数量校验
                OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch());
                if (Cools.isEmpty(orderDetl)) {
                     orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), null);
                    if (Cools.isEmpty(orderDetl)){
                        throw new CoolException("该单据中未找到对应物料明细");
                    }
                }
                if (Cools.isEmpty(codeDataParam.getQuality())) {
                    throw new CoolException("条码未返回质量状态");
                }
                if (Integer.parseInt(codeDataParam.getQuality()) != orderDetl.getInspect()) {
                    throw new CoolException("单据质量状态和组托物料不匹配");
                }
                OrderDetl orderDetl = orderDetlService.selectById(elem.getDetlId());
                if (elem.getAnfme() > orderDetl.getEnableQty()) {
                    throw new CoolException(orderDetl.getMatnr() + "入库数量不合法");
                }
                // 修改订单作业数量
                if (!orderDetlService.increaseWorkQty2(orderDetl.getId(),  elem.getAnfme())) {
                if (!orderDetlService.increaseWorkQtyById(orderDetl.getId(), elem.getAnfme())) {
                    throw new CoolException("修改单据作业数量失败");
                }
//                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(),orderDetl.getManu());
                DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme(), elem.getThreeCode()
                        , orderDetl.getManu(), codeDataParam.getBatchNum(), orderDetl.getSupp(), orderDetl.getTemp1(), orderDetl.getTemp2(), orderDetl.getTemp3(), orderDetl.getTemp4());
                detlDto.setTemp1(codeDataParam.getQuality());
                detlDto.setFromOrderNo(codeDataParam.getBarcode());
                if (DetlDto.has(detlDtos, detlDto)) {
                    DetlDto one = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch(), detlDto.getFromOrderNo());
                    assert one != null;
                    one.setAnfme(one.getAnfme() + detlDto.getAnfme());
                } else {
                    detlDtos.add(detlDto);
                }
//            });
            }
            for (DetlDto detlDto : detlDtos) {
                Mat mat = matService.selectByMatnr(detlDto.getMatnr());
                Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
                if (Cools.isEmpty(mat)) {
                    throw new CoolException(detlDto.getMatnr() + "商品档案不存在");
                    throw new CoolException(orderDetl.getMatnr() + "商品档案不存在");
                }
                WaitPakin waitPakin = new WaitPakin();
                waitPakin.sync(mat);
                waitPakin.setSku(detlDto.getBatch());
                waitPakin.setOrderNo(order.getOrderNo());   // 单据编号
                //waitPakin.setBatch(detlDto.getBatch());     // 序列码
                waitPakin.setBatch(orderDetl.getBatch());     // 序列码
                waitPakin.setZpallet(param.getBarcode());   // 托盘码
                waitPakin.setIoStatus("N");     // 入出状态
                waitPakin.setAnfme(detlDto.getAnfme());  // 数量
                waitPakin.setAnfme(elem.getAnfme());  // 数量
                waitPakin.setStatus("Y");    // 状态
                waitPakin.setAppeUser(userId);
                waitPakin.setAppeTime(now);
                waitPakin.setModiUser(userId);
                waitPakin.setModiTime(now);
                waitPakin.setDanger(detlDto.getDanger());
                waitPakin.setManu(detlDto.getMark()); //标记
                waitPakin.setOrigin(order.getItemName());//仓库
                waitPakin.setSupp(detlDto.getSuppName()); //供应商
                waitPakin.setSku(detlDto.getCustomer()); //客户名称
                waitPakin.setThreeCode(detlDto.getFromOrderNo()); //条码
                waitPakin.setTemp1(detlDto.getTemp1());
                waitPakin.setTemp2(detlDto.getTemp2());
                waitPakin.setTemp3(detlDto.getTemp3());
                waitPakin.setTemp4(detlDto.getTemp4());
                int countWrk2 = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet", param.getBarcode()));
                if (countWrk2 > 0) {
                    throw new CoolException("工作档条码数据已存在===>>" + param.getBarcode());
                }
                waitPakin.setBatch(orderDetl.getBatch());
                if (!waitPakinService.insert(waitPakin)) {
                    throw new CoolException("保存入库通知档失败");
                }
            }
            });
            orderService.updateSettle(order.getId(), 2L, userId);
        }
    }
    public List<CodeDataParam> getData(Map<String, Object> token, CodeParam codeParam) {
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setHeaders(token)
                    .setUri(url)
                    .setPath(code)
                    .setJson(JSON.toJSONString(codeParam))
                    .build()
                    .doPost();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        log.info("getData:{}", response);
        MesResponse jsonObject = JSON.parseObject(response, MesResponse.class);
        if (jsonObject.getCode().equals(200)) {
            JSONObject jsonObject1 = JSON.parseObject(jsonObject.getData());
            if (jsonObject1.getString("barcodeList") != null) {
                return JSON.parseArray(jsonObject1.getString("barcodeList"), CodeDataParam.class);
            }
        }
        throw new CoolException(jsonObject.getMessage());
    }
    @Override
    @Transactional
@@ -506,8 +366,7 @@
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
@@ -563,7 +422,6 @@
    }
    // 查找商品
@@ -656,8 +514,7 @@
            throw new CoolException(BaseRes.PARAM);
        }
        // 判断是否有相同条码的数据
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().
                eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
        if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
            throw new CoolException(param.getBarcode() + "数据正在进行入库");
        }
        Date now = new Date();
@@ -829,13 +686,11 @@
            }
            for (LocDetl locDetl : locDetls) {
                //如果该库位出库路线所用的堆垛机out_enable不为Y,跳过该循环
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_no", locDetl.getLocNo()));
                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()));
                BasCrnp crn_no = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", locMast.getCrnNo()));
                if (Cools.isEmpty(crn_no) || !crn_no.getOutEnable().equals("Y")) {
                    continue;
                }
@@ -860,8 +715,7 @@
                orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
                orderDetl.setUpdateBy(userId);
                orderDetl.setUpdateTime(now);
                Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo)
                        .eq("matnr", orderDetl.getMatnr());
                Wrapper wrapper = new EntityWrapper<OrderDetl>().eq("order_no", orderNo).eq("matnr", orderDetl.getMatnr());
                if (!Cools.isEmpty(orderDetl.getBatch())) {
                    wrapper.eq("batch", orderDetl.getBatch());
                }
@@ -937,19 +791,13 @@
    }
    @Override
    @Transactional
    public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
                         Double curOutQty, Integer ioType, Long userId, Date now) {
    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());
        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)) {