whycxzp
2025-04-01 55ac1354c8030edda8586ad758f23cfe6a1909db
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
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_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 java.util.Date;
import java.util.List;
 
@Service
public class WmsService {
 
    @Autowired
    private TaskService taskService;
 
    @Autowired
    private PageParamService paramService;
 
    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);
            //对下发的任务进行数据库存储
            Task task = new Task();
            task.setTaskNo(responseInside.getTask_no());
            task.setDes(palletDto.getDes());
            //将字符串列表转为1组字符串,每个元素用逗号分割
            List<String> pallets = palletDto.getPallets();
            task.setPallets(String.join(",", pallets));
 
            List<String> activateParameter = palletDto.getActivateParameter();
            task.setActivateParameter(String.join(",",activateParameter));
 
            Date date = new Date();
            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);
            List<WmsLocationDto> wmsLocationDtoList = JsonUtil.getGson().fromJson(dataStr, new TypeToken<List<WmsLocationDto>>(){}.getType());
            response.set(1,wmsLocationDtoList);
        }
        return response;
    }
 
    public Response getPalletList() {
        String httpUrl = "http://192.168.10.133:8051"+"/api/Wms_pallet/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);
            List<WmsPallet> wmsPalletList = JsonUtil.getGson().fromJson(dataStr, new TypeToken<List<WmsPallet>>(){}.getType());
            response.set(1,wmsPalletList);
        }
        return response;
    }
 
    public Response sendTaskStatus(TaskDto taskDto) {
        Task task = new Task();
        task.setTaskNo(taskDto.getTask_no());
        task.setTaskType(taskDto.getTask_type());
        //TODO 这个地方起始点的定义,运行过程中需要关注,以及编码对应的具体位置,需要他们提供
        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: {
                String pallet = task.getPallets();
                if(pallet == null){
                    pallet = taskService.getByTaskNo(taskNo).getPallets();
                }
                //更新电池编号
                PageParam pageParam = new PageParam();
                pageParam.setId(3);
                pageParam.setValue(Integer.valueOf(pallet));
                paramService.updateById(pageParam);
                //更新任务时间
                task.setPickUpStartTime(statusTime);
            }break;
            case 2:
            case 12:
            case 22: task.setPickUpTime(statusTime);break;
            case 13:
            case 23: 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);
    }
}