Blame view

src/main/java/com/huaheng/api/wcs/service/taskAssignService/TaskAssignServiceImpl.java 3.64 KB
pengcheng authored
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
package com.huaheng.api.wcs.service.taskAssignService;


import com.alibaba.fastjson.JSON;
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;
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;

/**
 * 任务下发接口ServiceImpl
 * @author ricard
 * @date    2019/10/11
 *
 */

@Service
public class TaskAssignServiceImpl implements TaskAssignService {

    @Autowired
    private AddressService addressService;


    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任务中容器为空");
        }
mahuandong authored
60
61
62
        if(StringUtils.isEmpty(taskHeader.getRecvDock())){
            throw new ServiceException("wms站台为空");
        }
pengcheng authored
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

        //入库性质的任务源库位不能为空
        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());
        wcsTask.setTaskType(taskHeader.getTaskType().toString());
86
        wcsTask.setStation(taskHeader.getRecvDock());
87
        wcsTask.setContainerCode(taskHeader.getContainerCode());
pengcheng authored
88
89
90
91
92
93
94
95
        wcsTask.setFromLocationCode(taskHeader.getFromLocation());
        wcsTask.setToLocationCode(taskHeader.getToLocation());
        wcsTask.setPlatform(platform);

        //4、发送数据
        String param="wcs";
        String url=addressService.selectAddress(param)+"TaskAssign";
        String JsonParam = JSON.toJSONString(wcsTask);
mahuandong authored
96
        System.out.println(JsonParam);
pengcheng authored
97
98
99
100
101
102
103
104
        String result = HttpUtils.bodypost(url, JsonParam);
        if(StringUtils.isEmpty(result)){
            throw new ServiceException("接口地址错误");
        }
        AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
        return ajaxResult;
    }
}