自动化立体仓库 - WMS系统
lty
11 小时以前 178d30a9b69598e82489d24b1da18b3b3ab0766b
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package com.zy.asrs.task.handler;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.exception.CoolException;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.entity.result.WorkIssuedResult;
import com.zy.asrs.entity.result.WrkPriority;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.utils.Utils;
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 java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Slf4j
@Service
@Transactional
public class WCSReportHandler extends AbstractHandler<String> {
    @Value("${wcs-slave.url}")
    private String url;
    @Value("${wcs-slave.workIssued}")
    private String workIssued;
    @Value("${wcs-slave.priority}")
    private String priority;
    @Value("${wcs-slave.inDevp}")
    private String inDevp;
    @Value("${wcs-slave.outDevp}")
    private String outDevp;
    @Value("${wcs-slave.warehouse}")
    private String warehouse;
    static String namespace = null;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private WrkMastService wrkMastService;
 
    public ReturnT<String> start(WrkMast wrkMast,int i) {
        WorkIssuedResult workIssuedResult = new WorkIssuedResult();
 
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String groupId = dateFormat.format(date)+"-"+i;
        workIssuedResult.setGroupId(groupId);//组号
        workIssuedResult.setMsgTime(dateFormat.format(date));
        workIssuedResult.setWarehouse("ZYNMG");
 
        List<WorkIssuedResult.Tasks> tasks = new ArrayList<>();
        WorkIssuedResult.Tasks task = new WorkIssuedResult.Tasks();
        task.setTaskId(wrkMast.getWrkNo().toString());
        task.setBarCode(wrkMast.getBarcode());
//        task.setOrder(i);
        task.setOrder(wrkMast.getIoPri().intValue());
        String LocNo = null;
        String sourceLocNo = null;
        //优先级排序 15.出库>14.入库>13.空板出库>12.空板入库>11.移库
        if(wrkMast.getIoType() == 1 || wrkMast.getIoType() == 53 || wrkMast.getIoType() == 57){//入库
            workIssuedResult.setPriorityCode(14);//优先级
            task.setTaskType(0);//入库
            task.setStartNode(inDevp);
            LocNo = Utils.getLocNoToWcs(Utils.getRow(wrkMast.getLocNo()),Utils.getBay(wrkMast.getLocNo()),Utils.getLev(wrkMast.getLocNo()));
            task.setEndNode(LocNo);//目标库位
            task.setCargoSize(null);
            switch (wrkMast.getIoType()){
                case 1: namespace= "全板入库下发";break;
                case 53: namespace= "拣料再入库下发";break;
                case 57: namespace= "盘点再入库下发";break;
            }
 
        }else if(wrkMast.getIoType() == 10 ){//空板入库
            workIssuedResult.setPriorityCode(12);//优先级
            task.setTaskType(0);//入库
            task.setStartNode(inDevp);
            LocNo = Utils.getLocNoToWcs(Utils.getRow(wrkMast.getLocNo()),Utils.getBay(wrkMast.getLocNo()),Utils.getLev(wrkMast.getLocNo()));
            task.setEndNode(LocNo);//目标库位
            task.setCargoSize(null);
            namespace = "空板入库";
 
        }else if(wrkMast.getIoType() == 101 || wrkMast.getIoType() == 103 || wrkMast.getIoType() == 107){//出库
            workIssuedResult.setPriorityCode(15);//优先级
            task.setTaskType(1);//出库
            sourceLocNo = Utils.getLocNoToWcs(Utils.getRow(wrkMast.getSourceLocNo()),Utils.getBay(wrkMast.getSourceLocNo()),Utils.getLev(wrkMast.getSourceLocNo()));
            task.setStartNode(sourceLocNo);//源库位
            task.setEndNode(outDevp);
            task.setCargoSize(null);
            switch (wrkMast.getIoType()){
                case 101: namespace= "全板出库下发";break;
                case 103: namespace= "拣料出库下发";break;
                case 107: namespace= "盘点出库下发";break;
            }
 
        }else if(wrkMast.getIoType() == 11){//移库
            workIssuedResult.setPriorityCode(11);//优先级
            task.setTaskType(2);//移库
            sourceLocNo = Utils.getLocNoToWcs(Utils.getRow(wrkMast.getSourceLocNo()),Utils.getBay(wrkMast.getSourceLocNo()),Utils.getLev(wrkMast.getSourceLocNo()));
            LocNo = Utils.getLocNoToWcs(Utils.getRow(wrkMast.getLocNo()),Utils.getBay(wrkMast.getLocNo()),Utils.getLev(wrkMast.getLocNo()));
            task.setStartNode(sourceLocNo);//源库位
            task.setEndNode(LocNo);//目标库位
            task.setCargoSize(null);
            namespace = "移库下发";
        } else {//空板出库
            workIssuedResult.setPriorityCode(13);//优先级
            task.setTaskType(1);//出库
            sourceLocNo = Utils.getLocNoToWcs(Utils.getRow(wrkMast.getSourceLocNo()),Utils.getBay(wrkMast.getSourceLocNo()),Utils.getLev(wrkMast.getSourceLocNo()));
            task.setStartNode(sourceLocNo);//源库位
            task.setEndNode(outDevp);
            task.setCargoSize(null);
            namespace = "空板出库下发";
        }
        tasks.add(task);
        workIssuedResult.setTasks(tasks);
        String response = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri(url)
                    .setPath(workIssued)
                    .setJson(JSON.toJSONString(workIssuedResult))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("returnStatus").equals(0)) {
                success = true;
                wrkMast.setWrkSts(1L);
                wrkMastService.updateById(wrkMast);
            } else {
                log.error("{}}下发任务给wcs失败!!!url:{};request:{};response:{}",namespace, url+"/"+workIssued, JSON.toJSONString(workIssuedResult), response);
                throw new CoolException("wms下发任务给wcs失败");
            }
        } catch (Exception e) {
            log.error("fail", e);
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        namespace,
                        url+"/"+workIssued,
                        null,
                        "127.0.0.1",
                        JSON.toJSONString(workIssuedResult),
                        response,
                        success
                );
            } catch (Exception e) { log.error("", e); }
        }
 
        return null;
    }
 
    //任务优先级调整 调用wcs接口 通知wcs
    public ReturnT<String> notice(WrkMast wrkMast) {
        WrkPriority wrkPriority = new WrkPriority();
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        wrkPriority.setTaskId(wrkMast.getWrkNo().toString()); // 任务号
        wrkPriority.setWarehouse(warehouse); // 仓库编码
        wrkPriority.setPriorityCode(wrkMast.getIoPri().intValue()); // 优先级
        wrkPriority.setMsgTime(dateFormat.format(date)); // 调整时间
 
        String response = "";
        boolean success = false;
        try {
            response = new HttpHandler.Builder()
                    .setUri(url)
                    .setPath(priority)
                    .setJson(JSON.toJSONString(wrkPriority))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger("returnStatus").equals(0)) {
                success = true;
                wrkMast.setWrkSts(1L);
                wrkMastService.updateById(wrkMast);
            } else {
                log.error("wms调整优先级下发给wcs失败!!!url:{};request:{};response:{}", url + "/" + workIssued, JSON.toJSONString(wrkPriority), response);
                throw new CoolException("wms调整优先级下发给wcs失败");
            }
        } catch (Exception e) {
            log.error("fail", e);
            return FAIL.setMsg(e.getMessage());
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "wms调整优先级下发给wcs",
                        url + "/" + workIssued,
                        null,
                        "127.0.0.1",
                        JSON.toJSONString(wrkPriority),
                        response,
                        success
                );
            } catch (Exception e) {
                log.error("", e);
            }
        }
        return null;
    }
}