自动化立体仓库 - WMS系统
#
LSH
2023-02-13 3ebfab49d440f6069fb29ec1a26f76cfa8a15cae
src/main/java/com/zy/asrs/task/handler/WorkMastHandler.java
@@ -1,13 +1,20 @@
package com.zy.asrs.task.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -32,9 +39,16 @@
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private WaitPakinService waitPakinService;
    private TestMastService testMastService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${mes.url}")
    private String mesUrl;
    @Value("${mes.inPath}")
    private String inpath;
    public ReturnT<String> start(WrkMast wrkMast) {
        // 4.入库完成
@@ -278,6 +292,7 @@
                    }
                    // 修改源库位状态 ==> O
                    LocMast sourceLoc = locMastService.selectById(wrkMast.getSourceLocNo());
                    Integer packStatus =sourceLoc.getPackStatus();
                    if (null != sourceLoc) {
                        sourceLoc.setBarcode("");
                        sourceLoc.setLocSts("O");
@@ -297,7 +312,29 @@
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    locMast.setFireStatus(0);
                    locMast.setPackStatus(4); //4:静置中
                    if (locMast.getLocType1()==sourceLoc.getLocType1()){
                        locMast.setPackStatus(packStatus);
                    }else {
                        locMast.setPackStatus(5); //5:静置中
                        if (locMast.getLocType1()==1 && sourceLoc.getLocType1()==2){
                            TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                    .eq("loc_no",sourceLoc.getLocNo())
                                    .eq("barcode",locMast.getBarcode())
                                    .eq("status",4)
                            );
                            testMast.setStatus(5);
                            testMast.setModiTime(new Date());
                            if (!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("loc_no",sourceLoc.getLocNo()).eq("barcode",locMast.getBarcode()).eq("status",4))){
                                throw new CoolException("更改测试状态失败");
                            }
                        }
                        CombParam combParam = new CombParam();
                        combParam.setPackNo(locMast.getBarcode());
                        combParam.setLocNo(locMast.getLocNo());
                        combParam.setPackSts(5);
                        combParam.setRequestTime(DateUtils.convert(new Date()));
                        postMesData(inpath,combParam);
                    }
                    if (!locMastService.updateById(locMast)) {
//                        exceptionHandle("库位移转 ===>> 修改目标库位状态失败;[workNo={0}],[locNo={1}]", wrkMast.getWrkNo(), wrkMast.getLocNo());
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -418,5 +455,44 @@
        }
        return SUCCESS;
    }
    private ReturnT<String> postMesData(String mesPath,Object combParam){
        if(combParam != null){
            String response = "";
            boolean success = false;
            try {
                response = new HttpHandler.Builder()
                        .setUri(mesUrl)
                        .setPath(mesPath)
                        .setJson(JSON.toJSONString(combParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.getInteger("code").equals(200)) {
                    success = true;
                } else {
                    log.error("请求接口失败!!!url:{};request:{};response:{}", mesUrl+mesPath, JSON.toJSONString(combParam), response);
                    throw new CoolException("上报mes系统失败");
                }
            } catch (Exception e) {
                log.error("fail", e);
//                      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return FAIL.setMsg(e.getMessage());
            } finally {
                try {
                    // 保存接口日志
                    apiLogService.save(
                            "上报mes系统",
                            mesUrl + mesPath,
                            null,
                            "127.0.0.1",
                            JSON.toJSONString(combParam),
                            response,
                            success
                    );
                } catch (Exception e) { log.error("", e); }
            }
        }
        return SUCCESS;
    }
}