TvControllerV1.java
4.01 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
package com.huaheng.api.tv.controller;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.task.TaskDomain;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderTvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* @ClassName TVController
* @Description TODO
* @Author Administrator
* @Date 2020/2/2217:16
*/
@RestController
@RequestMapping("/api/TV")
@Api(tags = {"TV"}, description = "TV接口")
public class TvControllerV1 extends BaseController {
@Resource
private MaterialService materialService;
@Resource
private TaskHeaderTvService taskHeaderTvService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private ContainerService containerService;
@PostMapping("/gettvView")
public AjaxResult<List<TaskDomain>> getTvView(String port){
List<TaskDomain> taskDomainList = new ArrayList<>();
//port多个站台用,分隔,查出所有头表
List<TaskHeader> taskList = new ArrayList<>();
for(String p : port.split(",")) {
List<TaskHeader> tmpTaskList = taskHeaderTvService.getTaskByTvPort(p);
taskList.addAll(tmpTaskList);
}
for(TaskHeader task : taskList){
TaskDomain taskDomain = new TaskDomain();
List<TaskDetail> taskDetails = taskDetailService.findByTaskId(task.getId());
taskDomain.setTaskHeader(task);
checkSpec(taskDetails);
taskDomain.setTaskDetails(taskDetails);
taskDomainList.add(taskDomain);
}
taskDomainList.sort(new Comparator<TaskDomain>() {
@Override
public int compare(TaskDomain o1, TaskDomain o2) {
TaskHeader task1 = o1.getTaskHeader();
TaskHeader task2 = o2.getTaskHeader();
int ret = task2.getStatus() - task1.getStatus();
if(ret == 0){
ret = (int) (task2.getLastUpdated().getTime() - task1.getLastUpdated().getTime());
}
return ret;
}
});
return AjaxResult.success(taskDomainList);
}
/**
* 查检任务明细中是否有规格型号,没有的话主动查一下
* @param taskDetails
*/
public void checkSpec(List<TaskDetail> taskDetails){
try {
for (TaskDetail detail : taskDetails) {
if (StringUtils.isEmpty(detail.getMaterialSpec())) {
Material material = materialService.getMaterialByCode(detail.getMaterialCode());
detail.setMaterialSpec(material.getSpec());
}
}
}catch (Exception e){
}
}
@PostMapping("/getStatusByContainer")
public AjaxResult getStatusByContainer(String containerCode,String warehouseCode){
Container container=containerService.getContainerByCode(containerCode,warehouseCode);
if(container==null){
return AjaxResult.error("未找到对应的容器");
}
return AjaxResult.success().setData(container.getStatus());
}
}