Blame view

src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java 5.42 KB
pengcheng authored
1
2
3
4
package com.huaheng.api.wcs.service.taskAssignService;


import com.alibaba.fastjson.JSON;
pengcheng authored
5
6
7
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.TaskDetails;
pengcheng authored
8
9
10
11
12
13
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.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
pengcheng authored
14
15
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
pengcheng authored
16
17
18
19
20
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;
pengcheng authored
21
22
23
import java.util.ArrayList;
import java.util.List;
pengcheng authored
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * 任务下发接口ServiceImpl
 * @author ricard
 * @date    2019/10/11
 *
 */

@Service
public class TaskAssignServiceImpl implements TaskAssignService {

    @Autowired
    private AddressService addressService;
pengcheng authored
36
37
    @Autowired
    private TaskDetailService taskDetailService;
pengcheng authored
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


    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任务中容器为空");
        }
pengcheng authored
70
pengcheng authored
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

        //入库性质的任务源库位不能为空
        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.setTaskNo(taskHeader.getId().toString());
pengcheng authored
93
        wcsTask.setPreTaskNo("0");
pengcheng authored
94
        wcsTask.setTaskType(taskHeader.getTaskType().toString());
pengcheng authored
95
96
        wcsTask.setFromPort("0");
        wcsTask.setToPort("0");
97
        wcsTask.setContainerCode(taskHeader.getContainerCode());
pengcheng authored
98
99
100
101
102
103
104
105
106
107
        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());
        }
pengcheng authored
108
109
        wcsTask.setPriority(100);
        wcsTask.setRemark("0");
pengcheng authored
110
111
        wcsTask.setPlatform(platform);
pengcheng authored
112
113
114
115
116
117
118
119
120
121
122
123
        //找到任务明细
        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());
pengcheng authored
124
125
126
127
128
            if(StringUtils.isEmpty(item.getMaterialUnit())){
                details.setUnit("PCS");
            }else {
                details.setUnit(item.getMaterialUnit());
            }
pengcheng authored
129
130
131
132
133
134
135
            details.setQty(item.getQty());
            details.setReferLineNo(item.getId().toString());
            taskDetails.add(details);
        }

        wcsTask.setTaskDetails(taskDetails);
pengcheng authored
136
137
138
139
        //4、发送数据
        String param="wcs";
        String url=addressService.selectAddress(param)+"TaskAssign";
        String JsonParam = JSON.toJSONString(wcsTask);
mahuandong authored
140
        System.out.println(JsonParam);
pengcheng authored
141
142
143
144
145
        String result = HttpUtils.bodypost(url, JsonParam);
        if(StringUtils.isEmpty(result)){
            throw new ServiceException("接口地址错误");
        }
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
pengcheng authored
146
147
148
        if(ajaxResult.getCode()!=200){
            throw new ServiceException(ajaxResult.getMsg());
        }
pengcheng authored
149
150
151
        return ajaxResult;
    }
}