自动化立体仓库 - WMS系统
#
lsh
2024-12-17 949ebb08ec84f8ec7c59f4a955ccb882a136cc2e
src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
@@ -14,8 +14,10 @@
import com.zy.asrs.service.OrderService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.utils.OrderInAndOutUtil;
import com.zy.common.constant.MesConstant;
import com.zy.common.model.MesPakinParam;
import com.zy.common.model.MesPakoutParam;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,9 +44,25 @@
    private ApiLogService apiLogService;
    @Autowired
    private DocTypeService docTypeService;
    @Transactional
    public ReturnT<String> start(Order order) {
    public ReturnT<String> startOrderInAndOutUtil(Order order) {
        DocType docType = docTypeService.selectById(order.getDocType());
        if (null == docType) {
            return SUCCESS;
        }
        List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(order.getPakinPakoutStatus$(), order.getId());
        Order orderNew = new Order(order);
        orderService.insert(orderNew);
        for (OrderDetl orderDetl : orderDetls){
            OrderDetl orderDetlNew = new OrderDetl(orderDetl);
            orderDetlService.insert(orderDetlNew);
        }
        // 修改订单状态 4.完成 ===>> 6.已上报
        OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(),order.getId(),6L,null);
        return SUCCESS;
    }
    @Transactional
    public ReturnT<String> startOrder(Order order) {
        DocType docType = docTypeService.selectById(order.getDocType());
        if (null == docType) {
            return SUCCESS;
@@ -101,7 +119,57 @@
        }
        // 出库完成上报
        if (docType.getPakout() == 1) {
            // todo
            MesPakoutParam pakoutParam = new MesPakoutParam();
            pakoutParam.setTag(!order.getDocType$().equalsIgnoreCase("手动出库单"));
            pakoutParam.setPakoutTime(DateUtils.convert(order.getUpdateTime()));
            pakoutParam.setLgortFrom("5006");
            pakoutParam.setLgortTo("1111");
            if (!pakoutParam.isTag()) {
                pakoutParam.setKunnr("C1000");
            }
            pakoutParam.setOrderNo(order.getOrderNo());
            for (OrderDetl orderDetl : orderDetls) {
                String serial = Cools.isEmpty(orderDetl.getBatch()) ? "" : orderDetl.getBatch();
                pakoutParam.getList().add(new MesPakoutParam.Detl(orderDetl.getMatnr() + (Cools.isEmpty(serial) ? "" : "-" + serial), orderDetl.getAnfme()));
            }
            String response = "";
            boolean success = false;
            try {
                response = new HttpHandler.Builder()
                        .setUri(MesConstant.URL)
                        .setPath(MesConstant.PAKOUT_URL)
                        .setJson(JSON.toJSONString(pakoutParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code").equals(200)) {
                    success = true;
                    // 修改订单状态 4.完成 ===>> 6.已上报
                    if (!orderService.updateSettle(order.getId(), 6L, null)) {
                        throw new CoolException("服务器内部错误,请联系管理员");
                    }
                } else {
                    log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PAKOUT_URL, JSON.toJSONString(pakoutParam), response);
                    throw new CoolException("上报mes系统失败");
                }
            } catch (Exception e) {
                log.error("fail", e);
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return FAIL.setMsg(e.getMessage());
            } finally {
                try {
                    // 保存接口日志
                    apiLogService.save(
                            "成品库出库上报",
                            MesConstant.URL + MesConstant.PAKOUT_URL,
                            null,
                            "127.0.0.1",
                            JSON.toJSONString(pakoutParam),
                            response,
                            success
                    );
                } catch (Exception e) { log.error("", e); }
            }
        }
        return SUCCESS;
    }