自动化立体仓库 - WMS系统
18516761980
2022-10-15 8eb1495d8551cd267e9ccae0508113bc969574be
src/main/java/com/zy/asrs/task/handler/WorkLogHandler.java
@@ -1,23 +1,33 @@
package com.zy.asrs.task.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.WrkDetl;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.WrkDetlLogService;
import com.zy.asrs.service.WrkDetlService;
import com.zy.asrs.service.WrkMastLogService;
import com.zy.asrs.service.WrkMastService;
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.service.impl.MobileServiceImpl;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.constant.MesConstant;
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;
import java.util.*;
/**
 * Created by vincent on 2020/7/6
 */
@Slf4j
@Service
@Transactional
public class WorkLogHandler extends AbstractHandler {
public class WorkLogHandler extends AbstractHandler<String> {
    @Autowired
    private WrkMastService wrkMastService;
@@ -27,28 +37,144 @@
    private WrkDetlService wrkDetlService;
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    public void start() {
        WrkMast wrkMast = wrkMastService.selectToBeHistoryData();
        if (null == wrkMast) {
            return;
    @Value("${mes.url}")
    private String mesUrl;
    @Value("${mes.inPath}")
    private String inpath;
    @Value("${mes.outPath}")
    private String outPath;
    @Transactional
    public ReturnT<String> start(WrkMast wrkMast) {
        try {
            /*...........................赣州新增..............以下.............赣州新增...........................*/
            ReturnT<String> result = null;
            WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
            if (wrkMast.getWrkSts() == 5 && wrkMast.getIoType() == 1) {
                if(wrkDetl != null){
                    CombParam combParam = new CombParam();
                    combParam.setPackNo(wrkDetl.getZpallet());
//                    combParam.setPackName(wrkDetl.getMatnr());
                    combParam.setLocNo(wrkMast.getLocNo());
                    combParam.setPackSts(1);
                    combParam.setRequestTime(DateUtils.convert(new Date()));
                    result = postMesData(inpath,combParam);
                    // 保存入库通知档历史档
                    WaitPakin pakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("zpallet", wrkMast.getBarcode()));
                    if (pakin!=null){
                        if (!waitPakinLogService.save(wrkMast.getBarcode())) {
                            exceptionHandle("保存入库通知档历史档[workNo={0}]失败", wrkMast.getWrkNo());
                        }
                        // 删除入库通知档
                        if (!waitPakinService.delete(new EntityWrapper<WaitPakin>().eq("zpallet", wrkMast.getBarcode()))) {
                            exceptionHandle("删除入库通知档[workNo={0}]失败", wrkMast.getWrkNo());
                        }
                    }
                }
            } else if (wrkMast.getWrkSts() == 15 && wrkMast.getIoType() == 101){
                if(wrkDetl != null){
                    CombParam combParam = new CombParam();
                    combParam.setPackNo(wrkDetl.getZpallet());
//                    combParam.setPackName(wrkDetl.getMatnr());
                    combParam.setLocNo(wrkMast.getSourceLocNo());
//                    combParam.setPackSts(0);
                    combParam.setRequestTime(DateUtils.convert(new Date()));
                    result = postMesData(outPath,combParam);
                }
            }else if(wrkMast.getWrkSts() == 4 && wrkMast.getIoType() == 11){
                if(wrkDetl != null){
                    CombParam combParam = new CombParam();
                    combParam.setPackNo(wrkDetl.getZpallet());
                    combParam.setLocNo(wrkMast.getLocNo());
                    combParam.setPackSts(5);
                    combParam.setRequestTime(DateUtils.convert(new Date()));
                    result = postMesData(inpath,combParam);
                }
            }
            if(null != result && !result.isSuccess()){
                return result;
            }
            /*...........................赣州新增..............以上.............赣州新增...........................*/
            // 保存工作主档历史档
            if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
                exceptionHandle("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
            }
            // 删除工作主档
            if (!wrkMastService.deleteById(wrkMast)) {
                exceptionHandle("删除工作主档[workNo={0}]失败", wrkMast.getWrkNo());
            }
            // 保存工作明细档历史档
            if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
//                exceptionHandle("保存工作明细历史档[workNo={0}]失败", wrkMast.getWrkNo());
            }
            // 删除工作明细档
            if (!wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()))) {
//                exceptionHandle("删除工作明细档[workNo={0}]失败", wrkMast.getWrkNo());
            }
        } catch (Exception e) {
            log.error("fail", e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        }
        // 保存工作主档历史档
        if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
            exceptionHandle(""); // todo
        }
        // 删除工作主档
        if (!wrkMastService.deleteById(wrkMast)) {
            exceptionHandle(""); // todo
        }
        // 保存工作明细档历史档
        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
            exceptionHandle(""); // todo
        }
        // 删除工作明细档
        if (!wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()))) {
            exceptionHandle(""); // todo
        }
        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;
    }
    /*...........................赣州新增..............以上.............赣州新增...........................*/
}