Blame view

src/main/java/com/huaheng/api/wcs/service/taskCancel/TaskCancelServiceImpl.java 2.65 KB
pengcheng authored
1
2
3
package com.huaheng.api.wcs.service.taskCancel;

import com.alibaba.fastjson.JSON;
肖超群 authored
4
import com.alibaba.fastjson.JSONObject;
pengcheng authored
5
import com.huaheng.api.wcs.domain.WcsTask;
肖超群 authored
6
import com.huaheng.common.constant.HttpConstant;
7
import com.huaheng.common.constant.QuantityConstant;
pengcheng authored
8
9
10
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
tongzhonghao authored
11
import com.huaheng.common.utils.http.OkHttpUtils;
肖超群 authored
12
import com.huaheng.common.utils.restful.RestUtil;
13
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
pengcheng authored
14
import com.huaheng.framework.web.domain.AjaxResult;
周鸿 authored
15
import com.huaheng.framework.web.domain.AjaxResultWCS;
16
import com.huaheng.framework.web.service.ConfigService;
pengcheng authored
17
18
import com.huaheng.pc.config.address.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
肖超群 authored
19
import org.springframework.http.ResponseEntity;
pengcheng authored
20
21
import org.springframework.stereotype.Service;
22
23
import javax.annotation.Resource;
pengcheng authored
24
25
26
27
28
29
@Service
public class TaskCancelServiceImpl implements TaskCancelService {


    @Autowired
    private AddressService addressService;
30
31
    @Resource
    private ConfigService configService;
pengcheng authored
32
33
34
35
36
37
38
39
40

    /**取消任务
     * 1、判断参数是否为空
     * 2、转换实体
     * 3、发送数据
     * @param id
     * @return
     */
    @Override
41
    public AjaxResult cancelTask(String id, String warehouseCode, String area) {
pengcheng authored
42
43
44
45
46

        //1、判断参数是否为空
        if(id == null){
            throw new ServiceException("任务号为空");
        }
pengcheng authored
47
周鸿 authored
48
pengcheng authored
49
        //2、转换实体
50
        WcsTask wcsTask = new WcsTask();
51
        wcsTask.setTaskNo(id);
pengcheng authored
52
53

        //3、发送数据
54
        String value = configService.getKey(QuantityConstant.RULE_CONNECT_WCS,warehouseCode);
55
56
        int connectWCS = Integer.parseInt(value);
        if(connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
周鸿 authored
57
            String url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_ASSIGN, warehouseCode, area);
58
            String jsonParam = JSON.toJSONString(wcsTask);
周鸿 authored
59
            url=url+"TaskCancel";
tongzhonghao authored
60
            String result = OkHttpUtils.bodypost(url, jsonParam,warehouseCode);
tongzhonghao authored
61
            if(StringUtils.isEmpty(result)) {
肖超群 authored
62
                throw new ServiceException("接口地址错误或返回为空");
63
            }
周鸿 authored
64
            AjaxResultWCS ajaxResult = JSON.parseObject(result, AjaxResultWCS.class);
tongzhonghao authored
65
            if(ajaxResult.getCode() != HttpConstant.OK) {
周鸿 authored
66
                return AjaxResult.error(ajaxResult.getMessage());
tongzhonghao authored
67
68
            }
            return AjaxResult.success("取消任务成功");
69
70
        } else {
            return AjaxResult.success("取消任务成功");
pengcheng authored
71
72
73
        }
    }
}