TaskAssignServiceImpl.java
6.29 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
package com.huaheng.api.wcs.service.taskAssignService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.TaskDetails;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* 任务下发接口ServiceImpl层
* @author ricard
* @date 2019/10/11
*
*/
@Service
public class TaskAssignServiceImpl implements TaskAssignService {
@Autowired
private AddressService addressService;
@Autowired
private TaskDetailService taskDetailService;
@Resource
private LocationService locationService;
public static String platform = "wms";
//wms下发任务给wcs
/**
* 1、判断taskHeader是否为空
* 2、判断必填字段是否满足
* 3、转换实体
* 4、发送数据
*
* @param taskHeader
* @return
*/
@Override
@Transactional
public AjaxResult wcsTaskAssign(TaskHeader taskHeader) {
//1、判断taskHeader是否为空
if(taskHeader == null){
throw new ServiceException("wms任务为空");
}
//2、判断必填字段是否满足
if(taskHeader.getId() == null){
throw new ServiceException("wms任务号Id为空");
}
if(taskHeader.getTaskType() == null){
throw new ServiceException("wms任务类型为空");
}
if(StringUtils.isEmpty(taskHeader.getContainerCode())){
throw new ServiceException("wms任务中容器为空");
}
//入库性质的任务源库位不能为空
if(taskHeader.getTaskType()==100 || taskHeader.getTaskType()==200
|| taskHeader.getTaskType()==500 || taskHeader.getTaskType()==800) {
if (taskHeader.getFromLocation() == null) {
throw new ServiceException("源库位为空");
}
}
// 出库性质的任务目的库位不能为空
if(taskHeader.getTaskType()==300 || taskHeader.getTaskType()==400
|| taskHeader.getTaskType()==600 || taskHeader.getTaskType()==700
|| taskHeader.getTaskType()==800 || taskHeader.getTaskType()==900)
{
if (taskHeader.getToLocation() == null) {
throw new ServiceException("目的库位为空");
}
}
//3、转换实体,初始化wcs任务实体
WcsTask wcsTask = new WcsTask();
// wcsTask.setWarehouseCode(ShiroUtils.getWarehouseCode());
wcsTask.setTaskNo(taskHeader.getId().toString());
wcsTask.setWarehouseCode(ShiroUtils.getWarehouseCode());
wcsTask.setPreTaskNo("0");
wcsTask.setTaskType(taskHeader.getTaskType().toString());
wcsTask.setFromPort("1000");
wcsTask.setContainerCode(taskHeader.getContainerCode());
Location location;
if ("300".equals(wcsTask.getTaskType()) || "400".equals(wcsTask.getTaskType()) || "600".equals(wcsTask.getTaskType())){
location = locationService.findLocationByCode(taskHeader.getFromLocation());
} else {
location = locationService.findLocationByCode(taskHeader.getToLocation());
}
wcsTask.setStation(location.getRoadway());
wcsTask.setDestination(location.getRoadway());
wcsTask.setToPort(location.getRoadway());
if(StringUtils.isEmpty(taskHeader.getFromLocation())){
wcsTask.setFromLocationCode("0");
}else {
wcsTask.setFromLocationCode(taskHeader.getFromLocation());
}
if(StringUtils.isEmpty(taskHeader.getToLocation())){
wcsTask.setToLocationCode("0");
}else {
wcsTask.setToLocationCode(taskHeader.getToLocation());
}
wcsTask.setPriority(100);
wcsTask.setRemark("0");
wcsTask.setPlatform(platform);
//找到任务明细
LambdaQueryWrapper<TaskDetail> taskDetailLam = Wrappers.lambdaQuery();
taskDetailLam.eq(TaskDetail::getTaskId,taskHeader.getId());
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLam);
if(taskDetailList == null){
throw new ServiceException("没有子任务");
}
List<TaskDetails> taskDetails =new ArrayList<>();
for(TaskDetail item : taskDetailList){
TaskDetails details = new TaskDetails();
details.setMaterialCode(item.getMaterialCode());
details.setMaterialName(item.getMaterialName());
if(StringUtils.isEmpty(item.getMaterialUnit())){
details.setUnit("PCS");
}else {
details.setUnit(item.getMaterialUnit());
}
details.setQty(item.getQty());
details.setReferLineNo(item.getId().toString());
taskDetails.add(details);
}
wcsTask.setTaskDetails(taskDetails);
//4、发送数据
String param="wcs";
String url=addressService.selectAddress(param)+"TaskAssign";
String JsonParam = JSON.toJSONString(wcsTask);
System.out.println(JsonParam);
String result = HttpUtils.bodypost(url, JsonParam);
if(StringUtils.isEmpty(result)){
throw new ServiceException("接口地址错误或返回为空");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if(ajaxResult.getCode()!=200){
throw new ServiceException(ajaxResult.getMsg());
}
return ajaxResult;
}
}