TaskCancelServiceImpl.java 2.71 KB
package com.huaheng.api.wcs.service.taskCancel;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.constant.HttpConstant;
import com.huaheng.common.constant.QuantityConstant;
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.restful.RestUtil;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TaskCancelServiceImpl implements TaskCancelService {


    @Autowired
    private AddressService addressService;
    @Resource
    private ConfigService configService;

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

        //1、判断参数是否为空
        if(id == null){
            throw new ServiceException("任务号为空");
        }

        //2、转换实体
        WcsTask wcsTask = new WcsTask();
        wcsTask.setTaskNo(id);

        //3、发送数据
        String value = configService.getKey(QuantityConstant.RULE_CONNECT_WCS);
        int connectWCS = Integer.parseInt(value);
        if(connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
            String url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_CANCEL, warehouseCode, area);
            String jsonParam = JSON.toJSONString(wcsTask);
            ResponseEntity<JSONObject> result = RestUtil.request_post(url, warehouseCode, jsonParam);
            if (result != null && result.getBody() != null) {
                String code = result.getBody().getString("code");
                String msg = result.getBody().getString("msg");
                if (!HttpConstant.isSuccess(Integer.parseInt(code))) {
                    return AjaxResult.error(msg);
                }
            } else {
                throw new ServiceException("接口地址错误或返回为空");
            }
            String data = result.getBody().getString("data");
            AjaxResult ajaxResult = JSON.parseObject(data, AjaxResult.class);
            return ajaxResult;
        } else {
            return AjaxResult.success("取消任务成功");
        }
    }
}