MobileTaskForASRSController.java
14.3 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package com.huaheng.mobile.shipment;
import com.alibaba.fastjson.JSONException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.receipt.ReceiptBill;
import com.huaheng.pc.general.location.domain.Location;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentAutoCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.IShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.service.IShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.IShipmentHeaderService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.task.task.domain.ShipmentTaskCreateModel;
import com.huaheng.pc.task.task.domain.Task;
import com.huaheng.pc.task.task.service.ITaskService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.domain.TaskWithDetailsModel;
import com.huaheng.pc.task.taskDetail.service.ITaskDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/mobile/task/taskForASRS")
@Api(tags = {"MobileTaskForASRSController"}, description = "手机立体库任务拣货相关")
public class MobileTaskForASRSController {
@Resource
private ITaskService taskService;
@Resource
private ITaskDetailService taskDetailService;
@Resource
private IMaterialService materialService;
@Resource
IDictDataService dictDataService;
@Resource
private IShipmentHeaderService shipmentHeaderService;
@Resource
private IShipmentDetailService shipmentDetailService;
@Resource
private IShipmentContainerHeaderService shipmentContainerHeaderService;
/**
* 根据任务号或者托盘号,获取任务明细
*
* @return
*/
@GetMapping("/taskAndDetails")
@ApiOperation("移动端扫描容器号(托盘)或者任务号")
@Log(title = "手机扫描容器收货上架", action = BusinessType.OTHER)
public AjaxResult getAllTaskDetails(@Param("code") @ApiParam(value = "容器号或任务号") String code) {
//先检查是不是任务号
int taskId;
TaskWithDetailsModel taskWithDetailsModel = new TaskWithDetailsModel();
try {
taskId = Integer.parseInt(code);
} catch (Throwable throwable) {
taskId = -1;
}
if (taskId != -1) {
//说明可以顺利转成int型,查找对应任务
Task task = taskService.selectEntityById(taskId);
if (task != null) {
//就算是已完成的任务,也可以查看
// if(task.getStatus()>=40){
// return RetResponse.makeErrRsp("任务已完成");
// }
if(task.getType() != 300 && task.getType() != 400) {
return AjaxResult.error("不是出库任务");
}
//获取明细
TaskDetail condition = new TaskDetail();
condition.setTaskId(task.getId());
List<TaskDetail> taskDetails = taskDetailService.selectListEntityByEqual(condition);
if (taskDetails == null || taskDetails.size() == 0) {
return AjaxResult.error("任务没有明细");
}
if (taskDetails.stream().anyMatch(x -> x.getStatus() < 40)) {
taskWithDetailsModel.setTask(task);
taskWithDetailsModel.setTaskDetails(taskDetails);
} else {
return AjaxResult.error("任务已完成");
}
}
}
if (taskWithDetailsModel.getTask() == null) {
//说明按照任务号并没有查找到,则再按照容器号来查找
Task task = null;
Task condition = new Task();
condition.setContainerCode(code);
condition.setWarehouseId(ShiroUtils.getWarehouseId());
List<Task> tasks = taskService.selectListEntityByEqual(condition);
if (tasks == null || tasks.size() == 0) {
return AjaxResult.error("任务未找到");
}
for (Task item : tasks) {
if (item.getFirstStatus()> 20 && item.getFirstStatus()< 40) {
task = item;
break;
}
}
if (task != null) {
//查找明细
TaskDetail condition2 = new TaskDetail();
condition2.setTaskId(task.getId());
List<TaskDetail> taskDetails = taskDetailService.selectListEntityByEqual(condition2);
if (taskDetails == null || taskDetails.size() == 0) {
return AjaxResult.error("任务没有明细");
}
if(task.getType() != 300 && task.getType() != 400) {
return AjaxResult.error("不是出库任务");
}
taskWithDetailsModel.setTask(task);
taskWithDetailsModel.setTaskDetails(taskDetails);
} else {
task = tasks.stream().min((a, b) -> a.getCreated().compareTo(b.getCreated()) > 0 ? -1 : 1).get();
//检查子任务是否都完成
TaskDetail condition2 = new TaskDetail();
condition2.setTaskId(task.getId());
List<TaskDetail> taskDetails = taskDetailService.selectListEntityByEqual(condition2);
if (taskDetails == null || taskDetails.size() == 0) {
return AjaxResult.error("任务没有明细");
}
for(TaskDetail taskDetail : taskDetails) {
Material materialCondition = new Material();
materialCondition.setCode(taskDetail.getMaterialCode());
Material material = materialService.selectFirstEntity(materialCondition);
taskDetail.setMaterialName(material.getName());
}
if(task.getType() != 300 && task.getType() != 400) {
return AjaxResult.error("不是出库任务");
}
if (taskDetails.stream().anyMatch(x -> x.getStatus() < 40)) {
taskWithDetailsModel.setTask(task);
taskWithDetailsModel.setTaskDetails(taskDetails);
} else {
return AjaxResult.error("任务已完成");
}
}
}
//添加config
List<DictData> result = dictDataService.selectDictDataByType("taskStatus");
if (result.size() < 1) {
taskWithDetailsModel.setTaskStatusConfig(null);
} else {
taskWithDetailsModel.setTaskStatusConfig(result);
}
result = dictDataService.selectDictDataByType("taskDetailStatus");
if (result.size() < 1) {
taskWithDetailsModel.setTaskDetailStatusConfig(null);
} else {
taskWithDetailsModel.setTaskDetailStatusConfig(result);
}
return AjaxResult.success(taskWithDetailsModel);
}
@PostMapping("/completeTaskDetails")
@ApiOperation("完成立体库子任务")
@Log(title = "完成立体库子任务", action = BusinessType.OTHER)
public AjaxResult completeTaskDetails(@RequestBody int[] taskDetailIds) {
return taskService.completeTaskDetailsForMobile(taskDetailIds);
}
@PostMapping("/autoShipment")
@ApiOperation("生成立体库出库任务")
@Log(title = "生成立体库出库任务", action = BusinessType.OTHER)
public AjaxResult autoShipment(@RequestBody @ApiParam(value="收货单") List<ShipmentBill> shipmentBills) {
int shipmentHeaderId = shipmentHeaderService.createTodayShipmentHeader(shipmentBills.get(0).getCompanyId(), shipmentBills.get(0).getCompanyCode());
ShipmentHeader shipmentHeader = shipmentHeaderService.selectEntityById(shipmentHeaderId);
List<Integer> shipmentDetailIds = shipmentDetailService.insertTodayShipmentDetail(shipmentHeader, shipmentBills,
shipmentBills.get(0).getCompanyId(), shipmentBills.get(0).getCompanyCode());
List<ShipmentAutoCombinationModel> shipmentAutoCombinationModels = new ArrayList<>();
for(int i=0; i< shipmentDetailIds.size(); i++) {
int shipmentDetailId = shipmentDetailIds.get(i);
ShipmentAutoCombinationModel shipmentAutoCombinationModel = new ShipmentAutoCombinationModel();
shipmentAutoCombinationModel.setShipmentDetailId(shipmentDetailId);
shipmentAutoCombinationModel.setType((short)100);
shipmentAutoCombinationModel.setCompanyId(shipmentBills.get(0).getCompanyId());
shipmentAutoCombinationModel.setCompanyCode(shipmentBills.get(0).getCompanyCode());
shipmentAutoCombinationModel.setLocation(shipmentBills.get(i).getLocation());
shipmentAutoCombinationModels.add(shipmentAutoCombinationModel);
}
return shipmentContainerHeaderService.autoCombination(shipmentAutoCombinationModels);
}
@PostMapping("/autoSortShipment")
@ApiOperation("生成立体库出库任务")
@Log(title = "生成立体库出库任务", action = BusinessType.OTHER)
public AjaxResult autoSortShipment(@RequestBody @ApiParam(value="收货单") List<ShipmentBill> shipmentBills) {
int shipmentHeaderId = shipmentHeaderService.createTodayShipmentHeader(shipmentBills.get(0).getCompanyId(), shipmentBills.get(0).getCompanyCode());
ShipmentHeader shipmentHeader = shipmentHeaderService.selectEntityById(shipmentHeaderId);
List<Integer> shipmentDetailIds = shipmentDetailService.insertTodayShipmentDetail(shipmentHeader, shipmentBills,
shipmentBills.get(0).getCompanyId(), shipmentBills.get(0).getCompanyCode());
List<ShipmentAutoCombinationModel> shipmentAutoCombinationModels = new ArrayList<>();
for(int i=0; i< shipmentDetailIds.size(); i++) {
int shipmentDetailId = shipmentDetailIds.get(i);
ShipmentAutoCombinationModel shipmentAutoCombinationModel = new ShipmentAutoCombinationModel();
shipmentAutoCombinationModel.setShipmentDetailId(shipmentDetailId);
shipmentAutoCombinationModel.setType((short)100);
shipmentAutoCombinationModel.setCompanyId(shipmentBills.get(0).getCompanyId());
shipmentAutoCombinationModel.setCompanyCode(shipmentBills.get(0).getCompanyCode());
shipmentAutoCombinationModel.setLocation(shipmentBills.get(i).getLocation());
shipmentAutoCombinationModels.add(shipmentAutoCombinationModel);
}
return shipmentContainerHeaderService.autoCombination(shipmentAutoCombinationModels);
}
@PostMapping("/getMaterialForecast")
@ApiOperation("获得物料联想词")
@Log(title = "获得物料联想词", action = BusinessType.OTHER)
public AjaxResult getMaterialForecast(@RequestBody @ApiParam(value="物料号") Map<String, String> param) {
if (param.get("code") == null || param.get("code").trim().length() < 1) {
throw new JSONException("容器号(code)不能为空");
}
List<Materialforecast> forecasts = materialService.getMaterialForecast(param.get("code"));
return AjaxResult.success(forecasts);
}
@PostMapping("/createShipTask")
@ApiOperation("移动端生成出库任务")
@Log(title = "移动端扫描出库单", action = BusinessType.OTHER)
public AjaxResult createShipTask(@RequestBody @ApiParam(value = "出库任务") ShipmentTaskModel shipmentTaskModel) {
int[] shipmentContainerHeaderIds = shipmentTaskModel.getShipmentContainerHeaderIds();
AjaxResult result = null;
List<Integer> taskIds = new ArrayList<>();
for(int shipmentContainerHeaderId : shipmentContainerHeaderIds) {
ShipmentTaskCreateModel shipmentTaskCreateModel = new ShipmentTaskCreateModel();
shipmentTaskCreateModel.setShipmentContainerHeaderIds(shipmentContainerHeaderId);
shipmentTaskCreateModel.setTaskType(shipmentTaskModel.getTaskType());
shipmentTaskCreateModel.setPriority(shipmentTaskModel.getPriority());
result = taskService.createTaskFromShipmentContainers(shipmentTaskCreateModel);
if(result.hasErr()) {
return result;
} else {
int taskId = (int)result.getData();
taskIds.add(taskId);
}
}
return AjaxResult.success(taskIds);
}
@PostMapping("/createSortShipTask")
@ApiOperation("移动端生成出库任务")
@Log(title = "移动端扫描出库单", action = BusinessType.OTHER)
public AjaxResult createSortShipTask(@RequestBody @ApiParam(value = "出库任务") ShipmentTaskModel shipmentTaskModel) {
int[] shipmentContainerHeaderIds = shipmentTaskModel.getShipmentContainerHeaderIds();
AjaxResult result = null;
List<Integer> taskIds = new ArrayList<>();
for(int shipmentContainerHeaderId : shipmentContainerHeaderIds) {
ShipmentTaskCreateModel shipmentTaskCreateModel = new ShipmentTaskCreateModel();
shipmentTaskCreateModel.setShipmentContainerHeaderIds(shipmentContainerHeaderId);
shipmentTaskCreateModel.setTaskType(shipmentTaskModel.getTaskType());
shipmentTaskCreateModel.setPriority(shipmentTaskModel.getPriority());
result = taskService.createSortShipTask(shipmentTaskCreateModel);
if(result.hasErr()) {
return result;
} else {
int taskId = (int)result.getData();
taskIds.add(taskId);
}
}
return AjaxResult.success(taskIds);
}
}