#
Junjie
2025-05-23 3c02e5919ab81c3710bab8b0cc0e229c8f95d92b
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
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.exception.CoolException;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.TaskWrkLog;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.TaskWrkService;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
 
@Slf4j
@Component
public class AssignTasksRCSScheduler {
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${wcs.urlWcs}")
    private String wcsUrl;
    @Value("${wcs.movePathWcs}")
    private String wcsmovePath;
    @Value("${wcs.outboundTaskRequest}")
    private String wcsoutboundTaskRequest;
    @Value("${wcs.inboundTaskApplyPathWcs}")
    private String wcsInboundTaskApplyPathWcs;
    @Value("${wms.TaskExecCallback}")
    private String TaskExecCallback;
    @Value("${wms.taskStatusFeedbackPath}")
    private String taskStatusFeedbackPath;
 
    /**
     * 自动派发移库任务给RCS
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void executeMove() {
        List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("wrk_sts", 1).eq("io_type", 3));
        for (TaskWrk taskWrk : taskWrks) {
            HashMap<String, Object> headParam = new HashMap<>();
            String response = "";
            boolean bool = false;
            try {
                headParam.put("taskNo", taskWrk.getTaskNo());
                headParam.put("sourceLocNo", taskWrk.getStartPoint());//源库位
                headParam.put("locNo", taskWrk.getTargetPoint());//目标库位
                log.info("wcs派发任务给RCS移库={}", taskWrk);
                response = new HttpHandler.Builder()
                        // .setHeaders(headParam)
                        .setUri(wcsUrl)
                        .setPath(wcsmovePath)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if (jsonObject.get("code").equals(200)) {
                    //派发出库任务给RCS==>成功下发移库任务
                    taskWrk.setWrkSts(2);
                    taskWrkService.updateById(taskWrk);
                    bool = true;
                }
            } catch (Exception e) {
                log.error("wcs派发任务给RCS移库失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs派发任务给RCS移库"
                        , wcsUrl + wcsmovePath
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            }
        }
    }
 
    /**
     * 自动派发出库任务给RCS
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void executeOut() {
        List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("wrk_sts", 11).eq("io_type", 2));
        for(TaskWrk taskWrk:taskWrks){
            HashMap<String, Object> headParam = new HashMap<>();
            String response = "";
            boolean bool = false;
            try {
                headParam.put("taskNo", taskWrk.getTaskNo());
                headParam.put("sourceLocNo",taskWrk.getStartPoint());//源库位
                headParam.put("staNo",taskWrk.getTargetPoint());//目标站
                log.info("wcs派发任务给RCS出库={}", taskWrk);
                response = new HttpHandler.Builder()
                        .setUri(wcsUrl)
                        .setPath(wcsoutboundTaskRequest)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if(jsonObject.get("code").equals(200)){
                    //派发出库任务给RCS==>成功下发出库任务
                    taskWrk.setWrkSts(12);
                    taskWrkService.updateById(taskWrk);
                    bool = true;
                }
            } catch (Exception e) {
                log.error("wcs派发任务给RCS出库失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs派发任务给RCS出库"
                        , wcsUrl + wcsoutboundTaskRequest
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            }
        }
    }
 
    /**
     * 自动派发入库任务给RCS
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void executeIn() {
        List<TaskWrk> taskWrks = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
                .eq("wrk_sts", 1).eq("io_type", 2));
        for(TaskWrk taskWrk:taskWrks){
            HashMap<String, Object> headParam = new HashMap<>();
            String response = "";
            boolean bool = false;
            try {
                headParam.put("taskNo", taskWrk.getTaskNo());
                headParam.put("sourceStaNo",taskWrk.getOriginStartPoint());//源站
                headParam.put("staNo",taskWrk.getOriginTargetPoint());//目标站
                headParam.put("locNo",taskWrk.getTargetPoint());//目标库位
 
                log.info("wcs派发任务给RCS入库={}", taskWrk);
                response = new HttpHandler.Builder()
                        .setUri(wcsUrl)
                        .setPath(wcsInboundTaskApplyPathWcs)
                        .setJson(JSON.toJSONString(headParam))
                        .build()
                        .doPost();
                JSONObject jsonObject = JSON.parseObject(response);
                if(jsonObject.get("code").equals(200)){
                    //派发出库任务给RCS==>成功下发入库任务
                    taskWrk.setWrkSts(2);
                    taskWrkService.updateById(taskWrk);
                    bool = true;
                }
            } catch (Exception e) {
                log.error("wcs派发任务给RCS入库失败{},返回值={}", taskWrk, response);
            } finally {
                apiLogService.save("wcs派发任务给RCS入库"
                        , wcsUrl + wcsInboundTaskApplyPathWcs
                        , null
                        , "127.0.0.1"
                        , JSON.toJSONString(headParam)
                        , response
                        , bool
                );
            }
        }
    }
 
}