自动化立体仓库 - WMS系统
skyouc
4 天以前 08915b05c42b2ba97a8bb0809aeb48802ae63b46
src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
@@ -1,6 +1,7 @@
package com.zy.asrs.task.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
@@ -19,8 +20,7 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.enums.OrderTypeEnum;
import com.zy.asrs.service.*;
import com.zy.asrs.service.impl.TaskDetlLogServiceImpl;
import com.zy.asrs.service.impl.TaskDetlServiceImpl;
import com.zy.asrs.service.impl.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.utils.OrderInAndOutUtil;
@@ -73,6 +73,14 @@
    CheckOrderDetlService checkOrderDetlService;
    @Autowired
    private TaskDetlLogService taskDetlLogService;
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private OrderDetlPakoutService orderDetlPakoutService;
    @Autowired
    private OrderPakoutService orderPakoutService;
    @Transactional
@@ -144,6 +152,7 @@
                orderDetlList.add(detail);
            }
        }
        for (OrderDetl orderDetl : orderDetlList) {
            orderDetl.setWorkQty(0D);
            OrderInAndOutUtil.insertOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl);
@@ -165,17 +174,22 @@
    @Transactional(rollbackFor = Exception.class)
    public void ifTransfetInsertStockIn(Order order, OrderDetl orderDetl) {
        OrderPakin orderPakin = new OrderPakin();
        BeanUtils.copyProperties(order, orderPakin);
        orderPakin.setDocType(OrderTypeEnum.STOCK_IN.type.longValue());
        if (!orderPakinService.insert(orderPakin)) {
            throw new CoolException("插入备货入库单失败");
        OrderPakin pakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>()
                .eq("order_no", order.getOrderNo())
                .eq("doc_type", OrderTypeEnum.STOCK_IN.type.longValue()));
        if (Objects.isNull(pakin)) {
            OrderPakin orderPakin = new OrderPakin();
            BeanUtils.copyProperties(order, orderPakin);
            orderPakin.setDocType(OrderTypeEnum.STOCK_IN.type.longValue());
            if (!orderPakinService.insert(orderPakin)) {
                throw new CoolException("插入备货入库单失败");
            }
            pakin = orderPakin;
        }
        OrderDetlPakin orderDetlPakin = new OrderDetlPakin();
        BeanUtils.copyProperties(orderDetl, orderDetlPakin);
        orderDetlPakin.setOrderId(orderPakin.getId());
        orderDetlPakin.setOrderId(pakin.getId());
        if (!orderDetlPakinService.insert(orderDetlPakin)) {
            throw new CoolException("插入备货入库单失败");
        }
@@ -270,41 +284,62 @@
            orderDetls.forEach(detl -> {
                Mat material = matService.selectByMatnr(detl.getMatnr());
                if (Objects.isNull(material)) {
                    throw new CoolException("物料不存在");
                    throw new CoolException(material.getMatnr() + "物料不存在");
                }
                ReportOrderParams itemParam = new ReportOrderParams();
                LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>()
                List<WrkDetlLog> wrkDetls = wrkDetlLogService.selectList(new EntityWrapper<WrkDetlLog>()
                        .eq("matnr", detl.getMatnr())
                        .eq("three_code", detl.getThreeCode())
                        .eq("supp_code", detl.getSuppCode())
                        .eq("order_no", detl.getOrderNo()));
                if (Objects.isNull(locDetl)) {
                    throw new CoolException("库存明细不存在 ,请检查单据是否完成!!");
                if (Objects.isNull(wrkDetls) || wrkDetls.isEmpty()) {
                    ReportOrderParams itemParam = new ReportOrderParams();
                    // BS Code
                    itemParam.setTotal_serial(detl.getThreeCode())
                            // 上报时,默认产品类型是null
                            .setPro_type(material.getProType())
                            // 上报时,默认产品编码
                            .setPro_komcode(detl.getMatnr())
                            // 上报时,默认产品id是供应商编码
                            .setPro_id(detl.getSuppCode())
                            .setLocation_no("LX000000000")
                            .setSj_emp("9527")
                            .setLocation_type(MatLocType.getMatTag(material.getTagId() + ""))
                            // 上报时,默认上报时间是更新时间
                            .setSj_date(Utils.dateToStr(order.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"))
                            // 上报时,如果为空默认上报 0
                            .setPick_qty(0)
                            // 上报时,默认损坏数量是0
                            .setDamage_qty(0)
                            // 上报时,默认差异数量是0
                            .setDiff_qty(0);
                    reportOrderParams.add(itemParam);
                } else {
                    wrkDetls.forEach(wrkDetl -> {
                        ReportOrderParams itemParam = new ReportOrderParams();
                        // BS Code
                        itemParam.setTotal_serial(detl.getThreeCode())
                                // 上报时,默认产品类型是null
                                .setPro_type(material.getProType())
                                // 上报时,默认产品编码
                                .setPro_komcode(detl.getMatnr())
                                // 上报时,默认产品id是供应商编码
                                .setPro_id(detl.getSuppCode())
                                .setLocation_no(wrkDetl.getZpallet())
                                .setSj_emp(wrkDetl.getModiUser$())
                                .setLocation_type(MatLocType.getMatTag(material.getTagId() + ""))
                                // 上报时,默认上报时间是更新时间
                                .setSj_date(Utils.dateToStr(order.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"))
                                // 上报时,默认上报数量是订单数量
                                .setPick_qty(wrkDetl.getAnfme().intValue())
//                                .setPick_qty(detl.getQty().intValue())
                                // 上报时,默认损坏数量是0
                                .setDamage_qty(0)
                                // 上报时,默认差异数量是0
                                .setDiff_qty(0);
                        reportOrderParams.add(itemParam);
                    });
                }
                // BS Code
                itemParam.setTotal_serial(detl.getThreeCode())
                        // 上报时,默认产品类型是null
                        .setPro_type(material.getProType())
                        // 上报时,默认产品编码
                        .setPro_komcode(detl.getMatnr())
                        // 上报时,默认产品id是供应商编码
                        .setPro_id(detl.getSuppCode())
                        .setLocation_no(locDetl.getZpallet())
                        .setSj_emp(locDetl.getModiUser$())
                        .setLocation_type(MatLocType.getMatTag(material.getTagId() + ""))
                        // 上报时,默认上报时间是更新时间
                        .setSj_date(Utils.dateToStr(order.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"))
                        // 上报时,默认上报数量是订单数量
                        .setPick_qty(detl.getQty().intValue())
                        // 上报时,默认损坏数量是0
                        .setDamage_qty(0)
                        // 上报时,默认差异数量是0
                        .setDiff_qty(0);
                reportOrderParams.add(itemParam);
            });
            orderParam.setDetails(reportOrderParams);
            XSR response = null;
@@ -363,33 +398,48 @@
            orderDetls.forEach(detl -> {
                Mat material = matService.selectByMatnr(detl.getMatnr());
                if (Objects.isNull(material)) {
                    throw new CoolException("物料不存在");
                    throw new CoolException(material.getMatnr() + "物料不存在");
                }
                TaskDetlLog detlLog = taskDetlLogService.selectOne(new EntityWrapper<TaskDetlLog>()
                TaskDetlLog taskDetlLog = taskDetlLogService.selectOne(new EntityWrapper<TaskDetlLog>()
                        .eq("matnr", detl.getMatnr())
                        .eq("supp_code", detl.getStandby1())
                        .eq("order_no", detl.getOrderNo()));
                if (Objects.isNull(detlLog)) {
                    throw new CoolException("数据错误 ,请检查AGV任务档是否已完成!!");
                if (Objects.isNull(taskDetlLog) || Objects.isNull(taskDetlLog.getAreaType())) {
                    orderParam.setTarget_location("2");
//                    throw new CoolException("数据错误 ,请检查AGV任务档是否已完成!!");
                } else {
                    orderParam.setTarget_location(taskDetlLog.getAreaType());
                }
                //目标库区
                orderParam.setTarget_location(detlLog.getAreaType());
                OrderItemsParam itemParam = new OrderItemsParam();
                // BS Code
                itemParam
                        // 上报时,默认产品类型是null
                        .setPro_type(material.getProType())
                        // 上报时,默认产品编码
                        .setPro_komcode(detl.getMatnr())
                        // 上报时,默认产品id是供应商编码
                        .setPro_id(detl.getSuppCode())
                List<WrkDetlLog> detlLog = wrkDetlLogService.selectList(new EntityWrapper<WrkDetlLog>()
                        .eq("matnr", detl.getMatnr())
                        .eq("supp_code", detl.getStandby1())
                        .eq("order_no", detl.getOrderNo()));
                detlLog.forEach(item -> {
                    OrderItemsParam itemParam = new OrderItemsParam();
                    if (Objects.isNull(item)) {
                        itemParam.setLocation_no("LX99999999");
                    } else {
                        itemParam.setLocation_no(item.getZpallet());
                    }
                    itemParam
                            // 上报时,默认产品类型是null
                            .setPro_type(material.getProType())
                            // 上报时,默认产品编码
                            .setPro_komcode(detl.getMatnr())
                            // 上报时,默认产品id是供应商编码
                            .setPro_id(detl.getSuppCode())
//                        // 上报时,默认来源位置是null
                        .setLocation_no(detlLog.getZpallet())
                        // 上报时,默认上报数量是订单数量
                        .setPick_qty(detl.getQty().intValue());
                reportOrderParams.add(itemParam);
//                              .setLocation_no(detlLog.getZpallet())
                            // 上报时,默认上报数量是订单数量
                            .setPick_qty(item.getAnfme().intValue());
//                            .setPick_qty(Objects.isNull(detl.getQty()) ? 0 : detl.getQty().intValue());
                    reportOrderParams.add(itemParam);
                });
            });
            //目标库区
//          orderParam.setTarget_location("2");
            // BS Code
            if (orderParam.getTarget_location().equals("2")) {
                orderParam.setType("11");
            } else if (orderParam.getTarget_location().equals("3")) {
@@ -404,26 +454,29 @@
            try {
                List<ReportOrderParam> orderParams = new ArrayList<>();
                orderParams.add(orderParam);
                log.info("派工单入参---------->{}", JSONArray.toJSONString(orderParams));
                if (order.getReportOnce() < 4) {
                    response = kopenApiService.reportOutDetailsResult(orderParams, order);
                } else {
                    return FAIL;
                }
                if (response.getSuccess()) {
                    success = true;
                    // 修改订单状态 4.完成 ===>> 6.已上报
                    if (!orderService.updateSettle(order.getId(), settle, null)) {
                        throw new CoolException("服务器内部错误,请联系管理员");
                    if (!Objects.isNull(response)) {
                        if (response.getSuccess()) {
                            success = true;
                            // 修改订单状态 4.完成 ===>> 6.已上报
                            if (!orderService.updateSettle(order.getId(), settle, null)) {
                                throw new CoolException("服务器内部错误,请联系管理员");
                            }
                        } else {
                            log.error("请求接口失败!!!url:{};request:{};response:{}",
                                    MesConstant.URL + MesConstant.OUT_DETAILS_RESULT,
                                    JSON.toJSONString(orderParams), JSON.toJSONString(response));
                            throw new CoolException("上报KOPEN系统失败");
                        }
                    } else {
//                            return SUCCESS;
                    }
                } else {
                    log.error("请求接口失败!!!url:{};request:{};response:{}",
                            MesConstant.URL + MesConstant.OUT_DETAILS_RESULT,
                            JSON.toJSONString(orderParams), JSON.toJSONString(response));
                    throw new CoolException("上报KOPEN系统失败");
                }
            } catch (Exception e) {
                log.error("fail", e);
                return FAIL.setMsg(e.getMessage());
//                        return FAIL.setMsg(e.getMessage());
            } finally {
                try {
                    // 保存接口日志
@@ -456,20 +509,30 @@
            orderDetls.forEach(detl -> {
                Mat material = matService.selectByMatnr(detl.getMatnr());
                if (Objects.isNull(material)) {
                    throw new CoolException("物料不存在");
                    throw new CoolException(material.getMatnr() + "物料不存在");
                }
                OrderItemsParam itemParam = new OrderItemsParam();
                // 上报时,默认产品类型是null
                itemParam.setPro_type(material.getProType());
                // 上报时,默认产品编码
                itemParam.setPro_komcode(material.getMatnr());
                // 上报时,默认产品id是供应商编码
                itemParam.setPro_id(detl.getSuppCode());
                //todo 台车编码
                itemParam.setTruck_no("TC310080014");
                // 上报时,默认上报时间是更新时间
                itemParam.setPick_qty(detl.getQty().intValue());
                reportOrderParams.add(itemParam);
                List<TaskDetlLog> detlLogs = taskDetlLogService.selectList(new EntityWrapper<TaskDetlLog>()
                        .eq("matnr", detl.getMatnr())
                        .eq("supp_code", detl.getStandby1())
                        .eq("order_no", detl.getOrderNo()));
                if (Objects.isNull(detlLogs) || detlLogs.isEmpty()) {
                    throw new CoolException("数据错误 ,请检查AGV任务档是否已完成!!");
                }
                detlLogs.forEach(detlLog -> {
                    OrderItemsParam itemParam = new OrderItemsParam();
                    // 上报时,默认产品类型是null
                    itemParam.setPro_type(material.getProType());
                    // 上报时,默认产品编码
                    itemParam.setPro_komcode(material.getMatnr());
                    // 上报时,默认产品id是供应商编码
                    itemParam.setPro_id(detl.getSuppCode());
                    //todo 台车编码
                    itemParam.setTruck_no(detlLog.getZpallet());
                    // 上报时,默认上报时间是更新时间
                    itemParam.setPick_qty(detlLog.getAnfme().intValue());
                    reportOrderParams.add(itemParam);
                });
            });
            pubOrderParams.setPartList(reportOrderParams);
@@ -564,7 +627,7 @@
        detls.forEach(detl -> {
            Mat material = matService.selectByMatnr(detl.getMatnr());
            if (Objects.isNull(material)) {
                throw new CoolException("物料不存在");
                throw new CoolException(material.getMatnr() + "物料不存在");
            }
            OrderItemsParam itemParam = new OrderItemsParam();
            itemParam.setLocation_no(detl.getZpallet())
@@ -591,4 +654,38 @@
    }
    @Transactional(rollbackFor = Exception.class)
    public ReturnT<String> startConvertOrders(OrderPakout orderPakout) {
        if (orderPakout.getSettle() != 4) {
            return FAIL;
        }
        List<OrderDetlPakout> detlPakins = orderDetlPakoutService.selectList(new EntityWrapper<OrderDetlPakout>().eq("order_no", orderPakout.getOrderNo()));
        if (!Objects.isNull(detlPakins) && !detlPakins.isEmpty()) {
            detlPakins.forEach(detl -> {
                OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>()
                        .eq("matnr", detl.getMatnr())
                        .eq("supp_code", detl.getSuppCode())
                        .eq("order_no", detl.getOrderNo()));
                if (!Objects.isNull(orderDetl)) {
                    orderDetl.setQty(detl.getQty());
                    orderDetl.setWorkQty(detl.getWorkQty());
                    if (!orderDetlService.update(orderDetl, new EntityWrapper<OrderDetl>()
                            .eq("matnr", detl.getMatnr())
                            .eq("supp_code", detl.getSuppCode())
                            .eq("order_no", detl.getOrderNo()))) {
                        throw new CoolException("订单信息更新失败!!");
                    }
                }
            });
            Order orderNo = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderPakout.getOrderNo()));
            if (!Objects.isNull(orderNo)) {
                orderNo.setSettle(4L);
                if (!orderService.update(orderNo, new EntityWrapper<Order>().eq("order_no", orderPakout.getOrderNo()))) {
                    throw new CoolException("单据状态更新失败!!");
                }
            }
        }
        return SUCCESS;
    }
}