1
zhang
17 小时以前 25650bd51704793cf78408d28853c89fda837c4c
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
package com.zy.acs.conveyor.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zy.acs.common.utils.News;
import com.zy.acs.conveyor.common.utils.HttpHandler;
import com.zy.acs.conveyor.controller.requestParam.StationRequestParam;
import com.zy.acs.conveyor.controller.vo.OpenBusSubmitParam;
import com.zy.acs.conveyor.controller.vo.StationStatus;
import com.zy.acs.conveyor.service.CtuMainService;
import com.zy.acs.framework.exception.CoolException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
/**
 * 立体仓库WCS系统主流程业务
 * Created by vincent on 2020/8/6
 */
@Slf4j
@Service
@Transactional
@Data
public class CtuMainServiceImpl implements CtuMainService {
 
 
    @Value("${ctu.url}")
    private String ctuUrl;
 
    @Value("${ctu.station}")
    private String station;
 
    @Value("${ctu.checkTakeComplete}")
    private String checkTakeComplete;
 
    @Value("${ctu.sendTask}")
    private String sendTask;
 
    private String code = "code";
 
    private String dataCode = "data";
 
    private Integer codeValue = 200;
 
    private Integer timeout = 10;
 
 
    @Transactional
    public boolean sendTask(OpenBusSubmitParam openBusSubmitParam) {
        String response = "";
        try {
            response = new HttpHandler.Builder()
                    .setUri(ctuUrl)
                    .setPath(sendTask)
                    .setTimeout(timeout, TimeUnit.SECONDS)
                    .setJson(JSON.toJSONString(openBusSubmitParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger(code).equals(codeValue)) {
                log.info("下发任务返回数据:{}", response);
                return true;
            }
        } catch (Exception e) {
            log.error("请求接口失败!!!url:{};request:{};response:{}", ctuUrl + sendTask, JSON.toJSONString(openBusSubmitParam), response);
        }
        return false;
    }
 
    /**
     * 检查站点状态
     *
     * @param staNo 站点编号
     * @return 站点是否可通行
     */
    public String checkStationStatus(Integer staNo) {
        StationRequestParam stationRequestParam = new StationRequestParam();
        List<String> staNos = new ArrayList<>();
        staNos.add(staNo + "");
        stationRequestParam.setStaNos(staNos);
        String response = "";
        try {
            response = new HttpHandler.Builder()
                    .setUri(ctuUrl)
                    .setPath(station)
                    .setTimeout(timeout, TimeUnit.SECONDS)
                    .setJson(JSON.toJSONString(stationRequestParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger(code).equals(codeValue)) {
                log.info("RCS返回数据:{}", response);
                JSONArray data = jsonObject.getJSONArray(dataCode);
                List<StationStatus> stationStatuses = JSONArray.parseArray(data.toString(), StationStatus.class);
                for (StationStatus object : stationStatuses) {
                    if (object.getStaNo().equals(staNo + "")) {
                        if (object.getConveyable()) {
                            return object.getTaskNo();
                        } else {
                            log.info("站点:{}状态不对", staNo);
                            return null;
                        }
                    }
                }
                log.info("未返回站点状态:{}", staNo);
            } else {
                log.error("调用下发任务接口报错,响应码:{},响应内容:{}", jsonObject.getInteger(code), response);
                //throw new CoolException("调用下发任务接口报错,响应码:" + jsonObject.getInteger(code));
            }
        } catch (CoolException e) {
            log.error("调用站点状态接口异常", e);
            //throw e;
        } catch (Exception e) {
            //log.error("检查站点状态失败,站点编号:{}", staNo, e);
        }
        return null;
    }
 
    /**
     * 检查站点状态
     *
     * @param seqNum 任务号
     * @return 站点是否可通行
     */
    public Boolean checkComplete(String seqNum) {
        StationRequestParam stationRequestParam = new StationRequestParam();
        stationRequestParam.setSeqNum(seqNum);
        String response = "";
        try {
            response = new HttpHandler.Builder()
                    .setUri(ctuUrl)
                    .setPath(checkTakeComplete)
                    .setTimeout(timeout, TimeUnit.SECONDS)
                    .setJson(JSON.toJSONString(stationRequestParam))
                    .build()
                    .doPost();
            News.info("RCS返回数据:{}", response);
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.getInteger(code).equals(codeValue)) {
                if (jsonObject.getBoolean(dataCode)) {
                    return true;
                }
            } else {
                log.error("调用下发任务接口报错,参数:{},响应内容:{}", seqNum, response);
                //throw new CoolException("调用下发任务接口报错,响应码:" + jsonObject.getInteger(code));
            }
        } catch (Exception e) {
            log.error("检查站点状态失败,任务编号:{},{}", seqNum,e.getMessage());
        }
        return false;
    }
}