自动化立体仓库 - WMS系统
#
LSH
2022-08-12 e846633fef8654e346c0a82655abeb3411b3085c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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.LocDetl;
import com.zy.asrs.entity.WaitPakin;
import com.zy.asrs.entity.WrkDetl;
import com.zy.asrs.entity.WrkMast;
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.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;
 
/**
 * Created by vincent on 2020/7/6
 */
@Slf4j
@Service
public class WorkLogHandler extends AbstractHandler<String> {
 
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private WrkMastLogService wrkMastLogService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WaitPakinLogService waitPakinLogService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private ApiLogService apiLogService;
 
    @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;
//            if (wrkMast.getWrkSts() == 5 && wrkMast.getIoType() == 1) {
//                result = postMesData(wrkMast,inpath,1);
//            } else if (wrkMast.getWrkSts() == 15 && wrkMast.getIoType() == 101){
//                result = postMesData(wrkMast,outPath,2);
//            }
//            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());
        }
        return SUCCESS;
    }
 
    private ReturnT<String> postMesData(WrkMast wrkMast, String mesPath,int a){
        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()));
            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:{}", 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;
    }
}