自动化立体仓库 - WMS系统
#
LSH
2023-10-23 880b14b0be176882182f8d48cd8f5e80c1d9febe
src/main/java/com/zy/asrs/task/handler/WorkLogHandler.java
@@ -3,30 +3,25 @@
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.entity.param.Review;
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.asrs.utils.PostMesDataUtils;
import com.zy.common.constant.MesConstant;
import com.zy.common.model.MesPakinParam;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.parser.JJTCCJSqlParserState;
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.Date;
import java.util.Iterator;
import java.util.List;
import java.util.*;
/**
 * Created by vincent on 2020/7/6
@@ -44,17 +39,13 @@
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private LocMastService locMastService;
    private MobileServiceImpl mobileService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    @Value("${mes.url}")
    private String mesUrl;
@@ -65,54 +56,50 @@
    @Value("${mes.outPath}")
    private String outPath;
    @Value("${mes.startUpTestPACK}")
    private String startUpTestPACK;
    @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) {
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getLocNo()));
                locMast.setFireStatus(0);
                locMast.setPackStatus(1);
                if (!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getLocNo()))){
                    throw new CoolException("消防状态/产品状态更新失败");
                }
                WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                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,1,combParam);
//                    CombParam combParam = new CombParam();
//                    combParam.setPackNo(wrkDetl.getMatnr());
////                    combParam.setPackName(wrkDetl.getMaktx());
//                    combParam.setLocNo(wrkMast.getLocNo());
//                    combParam.setPackSts(1);
//                    combParam.setRequestTime(DateUtils.convert(new Date()));
//                    result = new PostMesDataUtils().postMesData("MES系统",mesUrl,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){
                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getSourceLocNo()));
                locMast.setFireStatus(0);
                locMast.setPackStatus(0);
                if (!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getSourceLocNo()))){
                    throw new CoolException("消防状态/产品状态更新失败");
                }
                WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                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(outPath,2,combParam);
                }
//                if(wrkDetl != null){
//                    CombParam combParam = new CombParam();
//                    combParam.setPackNo(wrkDetl.getMatnr());
////                    combParam.setPackName(wrkDetl.getMatnr());
//                    combParam.setLocNo(wrkMast.getSourceLocNo());
////                    combParam.setPackSts(0);
//                    combParam.setRequestTime(DateUtils.convert(new Date()));
//                    result = new PostMesDataUtils().postMesData("MES系统",mesUrl,outPath,combParam);
//                }
            }
            if(null != result && !result.isSuccess()){
                return result;
            }
//            if(null != result && !result.isSuccess()){
//                return result;
//            }
            /*...........................赣州新增..............以上.............赣州新增...........................*/
            // 保存工作主档历史档
@@ -128,7 +115,7 @@
//                exceptionHandle("保存工作明细历史档[workNo={0}]失败", wrkMast.getWrkNo());
            }
            // 删除工作明细档
            if (!wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()))) {
            if (!wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("zpallet", wrkMast.getBarcode()))) {
//                exceptionHandle("删除工作明细档[workNo={0}]失败", wrkMast.getWrkNo());
            }
        } catch (Exception e) {
@@ -139,89 +126,4 @@
        }
        return SUCCESS;
    }
    /*...........................赣州新增..............以下.............赣州新增...........................*/
    private ReturnT<String> postMesData(String mesPath,int a,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)) {
                    if (a==4 && a==3){
                        if (jsonObject.getDate("isComplete").equals(true)){
                            success = true;
                        }else if (jsonObject.getDate("isComplete").equals(false)){
                            success = false;
                        }else {
                            log.error("返回值出错!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PAKIN_URL, JSON.toJSONString(combParam), response);
                            throw new CoolException("返回值出错");
                        }
                    }else {
                        success = true;
                    }
                } else {
                    log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL+MesConstant.PAKIN_URL, 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(
                            "成品库入库上报",
                            MesConstant.URL + MesConstant.PAKIN_URL,
                            null,
                            "127.0.0.1",
                            JSON.toJSONString(combParam),
                            response,
                            success
                    );
                } catch (Exception e) { log.error("", e); }
            }
        }
        return SUCCESS;
    }
    @Transactional
    public ReturnT<String> startUpTestPACK(TestMast testMast){
        try {
            CombParam combParam = new CombParam();
            combParam.setPackNo(testMast.getLocNo());
            combParam.setPackName(testMast.getUserId());
            combParam.setLocno(testMast.getBarcode());
            combParam.setRequestTime(DateUtils.convert(new Date()));
            return postMesData(outPath,3,combParam);
        }catch (Exception e) {
            log.error("fail", e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        }
    }
    @Transactional
    public ReturnT<String> suspendTestPACK(){
        try {
            Review review=new Review();
            review.setPause(true);
            review.setRequestTime(DateUtils.convert(new Date()));
            return postMesData(outPath,4,review);
        }catch (Exception e) {
            log.error("fail", e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        }
    }
    /*...........................赣州新增..............以上.............赣州新增...........................*/
}