whycxzp
2025-04-14 8e85ad8e022d2885c410d0654bce08e2a392b08f
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
213
214
215
216
217
218
package com.whyc.service;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.reflect.TypeToken;
import com.whyc.dto.*;
import com.whyc.pojo.db_abe_ram.AbeInf;
import com.whyc.pojo.db_param.PageParam;
import com.whyc.pojo.db_wms.Task;
import com.whyc.util.HttpUtil;
import com.whyc.util.JsonUtil;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.applet.Main;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class WmsService {
 
    @Autowired
    private TaskService taskService;
 
    @Autowired
    private AbeInfService abeInfService;
 
    public Response getMaterialList() {
        String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_material/get_all";
        Response response = HttpUtil.doGet(httpUrl, (String) null);
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            //WmsMaterialDto wmsMaterialDto = JsonUtil.getGson().fromJson(dataStr, WmsMaterialDto.class);
            List<WmsMaterialDto> wmsMaterialDtoList = JsonUtil.getGson().fromJson(dataStr, new TypeToken<List<WmsMaterialDto>>(){}.getType());
            response.set(1,wmsMaterialDtoList);
        }
        return response;
    }
 
    /**
     *
     * @param palletDto
     * @return
     * 响应报文
     * 实例    {
     *   "code": 0,
     *   "message": "string"
     * }
     * 参数说明    字段名称    参数类型    字段描述
     *     code    Int    接口通信返回编码详细信息, 0:成功
     *     message    String    详细信息
     * 会自动根据返回编码Code在信息前增加Code详情
     */
 
    public Response sendTask(WmsPalletDto palletDto) {
        String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_pallet/WmsOutTask";
        Response response = HttpUtil.doPost(httpUrl, JsonUtil.getGson().toJson(palletDto));
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            WmsResponse responseInside = JsonUtil.getGson().fromJson(dataStr, WmsResponse.class);
            response.set(1,responseInside);
            if(responseInside.getCode() ==0) {
                //对下发的任务进行数据库存储
                Date date = new Date();
                List<String> pallets = palletDto.getPallets();
                List<String> taskNos = responseInside.getTask_no();
                for (int i = 0; i < pallets.size(); i++) {
                    String pallet = pallets.get(i);
                    String taskNo = taskNos.get(i);
                    Task task = new Task();
                    task.setTaskNo(taskNo);
                    task.setPallets(pallet);
                    task.setDes(palletDto.getDes());
 
                    if (palletDto.getDes() == 3) { //活化,填入活化参数
                        List<String> activateParameter = palletDto.getActivateParameter();
                        task.setActivateParameter(String.join(",", activateParameter));
                    }
                    task.setCreateTime(date);
 
                    taskService.add(task);
 
 
                }
            }
        }
        return response;
    }
 
    public Response getLocationList() {
        String httpUrl = "http://192.168.10.133:8051"+"/api/wms_location/get_all";
        Response response = HttpUtil.doGet(httpUrl, (String) null);
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            /*//截取dataStr中"data:"后的字符串
            int index = dataStr.indexOf("data");
            dataStr = dataStr.substring(index+6, dataStr.length()-3);
            //WmsLocationDto wmsLocationDto = JsonUtil.getGson().fromJson(dataStr, WmsLocationDto.class);*/
            WmsResponse<List<WmsLocationDto>> wmsResponse = JsonUtil.getGson().fromJson(dataStr, new TypeToken<WmsResponse<List<WmsLocationDto>>>(){}.getType());
            List<WmsLocationDto> wmsLocationDtoList = wmsResponse.getData();
            response.set(1,wmsLocationDtoList);
        }
        return response;
    }
 
    public Response getPalletList(int MaterialType, int PalletStatus) {
        String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_pallet/get_all";
 
        Map<String,Integer> queryMap = new HashMap<>();
        queryMap.put("MaterialType",MaterialType);
        queryMap.put("PalletStatus",PalletStatus);
        Response response = HttpUtil.doGet(httpUrl, HttpUtil.urlEncode(queryMap));
        //对结果进行处理
        if(response.getCode() == 1){ //请求成功,data有正常数据
            String dataStr = (String) response.getData();
            /*
            //截取dataStr中"data:"后的字符串
            int index = dataStr.indexOf("data");
            dataStr = dataStr.substring(index+6, dataStr.length()-3);
            List<WmsPallet> wmsPalletList = JsonUtil.getGson().fromJson(dataStr, new TypeToken<List<WmsPallet>>(){}.getType());*/
            WmsResponse<List<WmsPallet>> wmsResponse = JsonUtil.getGson().fromJson(dataStr, new TypeToken<WmsResponse<List<WmsPallet>>>(){}.getType());
            List<WmsPallet> wmsPalletList = wmsResponse.getData();
            response.set(1,wmsPalletList);
        }
        return response;
    }
 
    public Response sendTaskStatus(TaskDto taskDto) {
        String taskNo = taskDto.getTask_no();
        //通过taskNo从数据库查找对应的记录
        Task taskInDB = taskService.getByTaskNo(taskNo);
        if(taskInDB == null){
            return new Response<>().setII(1,"任务上报失败,无法定位到任务,任务可能不是通过监控平台下发");
        }
        Task task = new Task();
        task.setTaskNo(taskNo);
        task.setTaskType(taskDto.getTask_type());
        //这个地方起始点的定义,运行过程中需要关注,以及编码对应的具体位置,需要他们提供
        task.setStartLocationCode(taskDto.getStart_location_code());
        task.setEndLocationCode(taskDto.getEnd_location_code());
 
        task.setStatus(taskDto.getStatus());
        task.setStatusTime(ThreadLocalUtil.parse(taskDto.getStatus_time(),1));
 
        //对接收到的任务进行逻辑判断和数据存储
        //String taskNo = task.getTaskNo();
        //taskType=4,入库测压任务,这个为仓储自动触发的任务,非主动平台下达,
        // 需要手动添加任务类型,和电池组编号
        Integer taskType = task.getTaskType();
        if(taskType == 4){
            task.setDes(2);
            task.setPallets(taskDto.getPallet());
        }
        Integer status = task.getStatus();
        Date statusTime = task.getStatusTime();
        switch (status){
            case 1:
            case 11:
            case 21: {
                task.setPickUpStartTime(statusTime);
            }break;
            case 2:
            case 12:
            case 22: task.setPickUpTime(statusTime);break;
            case 13:
            case 23: {
                /*String pallet = task.getPallets();
                if(pallet == null){
                    pallet = taskService.getByTaskNo(taskNo).getPallets();
                }*/
                String pallet = taskInDB.getPallets();
                //更新电池单体编号和任务编号
                AbeInf abeInf = abeInfService.get();
                abeInf.setAbeMonId(Integer.valueOf(pallet));
                abeInf.setTaskNo(taskNo);
                abeInfService.updateById(abeInf);
                //设置放置到活化仓的开始时间
                task.setActivationChamberStartTime(statusTime);
            }break;
            case 14:
            case 24:
                task.setActivationChamberPickUpTime(statusTime);break;
            case 15:
            case 25:
                task.setActivationChamberEndTime(statusTime);break;
            case 4:
            case 16:
            case 26:
                task.setBackFinishTime(statusTime);
                task.setEndTime(new Date());
                break;
            default:
                throw new IllegalArgumentException("status字段未定义,无法被识别: " + status);
        }
        taskService.update(task);
 
        return new Response().setII(1,"上报状态完成");
    }
 
    public Response getFinishedPage(int pageNum, int pageSize) {
        PageHelper helper = new PageHelper();
        helper.startPage(pageNum,pageSize);
        List<Task> tasks = taskService.getFinishedList();
        PageInfo<Task> pageInfo = new PageInfo<>(tasks);
        return new Response().set(1,pageInfo);
    }
 
    public Response getOngoingList() {
        List<Task> taskList = taskService.getOngoingList();
        return new Response().set(1,taskList);
    }
}