MobileTaskForASRSController.java
6.52 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
package com.huaheng.mobile.shipment;
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.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
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.List;
@CrossOrigin
@RestController
@RequestMapping("/mobile/task/taskForASRS")
@Api(tags = {"MobileTaskForASRSController"}, description = "手机立体库任务拣货相关")
public class MobileTaskForASRSController {
@Resource
private ITaskService taskService;
@Resource
private ITaskDetailService taskDetailService;
@Resource
IDictDataService dictDataService;
/**
* 根据任务号或者托盘号,获取任务明细
*
* @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.getStatus() > 20 && item.getStatus() < 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("任务没有明细");
}
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);
}
}