package com.prolog.eis.service.feign.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.prolog.eis.common.util.JsonHelper;
import com.prolog.eis.common.util.PrologStringUtils;
import com.prolog.eis.common.util.location.LocationConstants;
import com.prolog.eis.core.dto.area.PortInfoAreaDto;
import com.prolog.eis.core.dto.inboundallot.InboundAllotAreaParamDto;
import com.prolog.eis.core.dto.route.*;
import com.prolog.eis.core.model.base.area.WhArea;
import com.prolog.eis.core.model.base.locator.WhLocator;
import com.prolog.eis.core.model.biz.carry.CarryTask;
import com.prolog.eis.core.model.biz.carry.CarryTaskCallback;
import com.prolog.eis.core.model.biz.route.ContainerLocation;
import com.prolog.eis.dao.out.*;
import com.prolog.eis.dao.shelves.BizInboundTaskMapper;
import com.prolog.eis.dto.route.AreaCarryTaskDto;
import com.prolog.eis.feign.PlgFeignRouteClient;
import com.prolog.eis.feign.WarehouseFeignService;
import com.prolog.eis.model.container.ContainerInfo;
import com.prolog.eis.model.container.ContainerInfoDetail;
import com.prolog.eis.model.container.ContainerTask;
import com.prolog.eis.model.inbound.BizInboundTask;
import com.prolog.eis.model.outbound.BizOutboundTaskDetail;
import com.prolog.eis.router.dto.AreaTaskDto;
import com.prolog.eis.router.vo.ContainerLocationVo;
import com.prolog.eis.service.feign.RouteFeignService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
import com.prolog.framework.core.exception.PrologException;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.utils.*;
import com.prolog.fx.inf.core.InterfaceType;
import com.prolog.fx.inf.core.annotation.InterfaceMethod;
import io.jsonwebtoken.lang.Assert;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;


/**
 * @author dengj
 * @version 1.0
 * @date 2022/10/19 18:04
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class RouteFeignServiceImpl implements RouteFeignService {

    private final ContainerInfoMapper containerInfoMapper;
    private final ContainerInfoDetailMapper containerInfoDetailMapper;

    private final ContainerTaskMapper containerTaskService;
    private final BizOutboundTaskMapper outboundTaskMapper;
    private final BizOutboundTaskDetailMapper bizOutboundTaskDetailMapper;
    private final PlgFeignRouteClient plgFeignRouteService;

    private final WarehouseFeignService plgFeignWarehouseService;
    private final BizInboundTaskMapper bizInboundTaskMapper;

    @Value("${spring.profiles.active}")
    private String env;


    /**
     * 发送搬运任务
     */
    private static final String SAVE_PATH = "savePath";
    /**
     * 创建容器点位
     */
    private static final String CREATE_ITEM_CONTAINER = "createItemContainer";

    /**
     * 容器点位清除
     */
    private static final String CONTAINER_OFF_SHELF = "containerOffShelf";

    /**
     * 区域任务数
     */
    private static final String TOTAL_COUNT_BY_AREA = "findTotalCountByAreaNo";

    /**
     * 区域任务数
     */
    private static final String getAreaByAreaNos = "getAreaByAreaNos";


    /**
     * 查待分区域详情
     */
    private static final String QUERY_DSW_AREA_LIST = "queryDswAreaList";

    /**
     * 检查1个区域是否有空货位可以入
     */
    private static final String CHECK_AREA_IN = "checkAreaIn";

    /**
     * 获取所有任务回告
     */
    private static final String ALL_CALL_BACK = "findAllCallback";


    /**
     * 通过区域查询容器任务
     */
    private static final String AREA_CONTAINER_COUNT = "areaContainerCount";

    /**
     * 任务完成转历史
     */
    private static final String CALL_BACK_TO_HIS = "toCallbackHis";


    /**
     * 入库找区域
     */
    private static final String GET_AllOT_AREA = "getAllotAreaNew";


    /**
     * 根据容器编号查询点位
     */
    private static final String SEARCH_LOCATION_NO = "seachLocationNo";

    /**
     * 根据容器查位置
     */
    private static final String FIND_LOCATION_BY_CONTAINER_LIST = "findLocationByContainerList";


    /**
     * 根据容器查位置
     */
    private static final String FIND_CONTAINER_LOCATION_LIST_BY_ONTAINER_LIST = "findContainerLocationListByContainerList";

    /**
     * 根据点位获取任务数量
     */
    private static final String GET_LOC_NUM = "getLocNum";

    /**
     * 根据区域查询任务数
     */
    private static final String GET_SXKTASK_BY_AREANOS = "getSxkTaskByAreaNos";

    /**
     * 搬运任务接口批量生成
     */
    private static final String CREAT_BATCH_CARRY = "createBatchCarry";

    /**
     * 搬运任务接口批量生成
     */
    private static final String creatCarryTaskAndExecuteNotTx = "creatCarryTaskAndExecuteNotTx";

    /**
     * 根据起点/终点区域查询容器
     */
    private static final String FIND_CONTAINER_LOC_BY_TARGET_AREANOS = "findContainerLocationByTargetAreaNos";
    private static final String findContainerLocationByAreaNos = "findContainerLocationByAreaNos";

    /**
     * 条件查询搬运任务
     */
    private static final String LIST_CARRY_TASK_BY_PARAM = "listCarryTaskByParam";

    /**
     *根据点位查询位置信息
     */
    private static final String LOCATION_INFO = "locationInfo";

    /**
     *判断当前点位是否有容器
     */
    private static final String CHECK_CONTAINER = "checkContainer";

    /**
     *根据点位坐标查询容器信息
     */
    private static final String findContainerInfoByLocation = "findContainerInfoByLocation";

    /**
     *判断有无结束点位为传入点位的任务
     */
    private static final String CHECK_CARRY_TASK = "checkCarryTask";
    //判断当前点位是否有容器
    private static final String checkContainerNew = "checkContainerNew";

    /**
     * 根据托盘号修改点位（CTU)
     */
    private static final String UPDATE_LOC_BY_PALLETNO = "updateLocByPalletNo";

    /**
     * 根据托盘查找搬运任务
     */
    private static final String FIND_CARRY_TASK_LIST_BY_CONYAINER_LIST = "findCarryTaskListByContainerList";


    /**
     * 查询区域托盘数
     */
    private static final String findAreaNoAndContainerCountMap = "findAreaNoAndContainerCountMap";

    /**
     * 根据区域获取可用货位数
     */
    private static final String queryAreaLocationCountDtoList = "queryAreaLocationCountDtoList";


    /**
     * 查询区域[{}]的空闲托盘
     */
    private static final String findFreeContainerByAreaNo = "findFreeContainerByAreaNo";

    /**
     * 容器【{}】下架
     */
    private static final String containerOffShelfNoStore = "containerOffShelfNoStore";

    /**
     * 根据区域【{}】查询出、入数量
     */
    private static final String queryAreaInOutCount = "queryAreaInOutCount";

    /**
     * route重新分配巷道
     */
    private static final String areachange = "areachange";

    private static final String getAreaDetail = "getAreaDetail";
    private static final String queryAreaCarryTask = "queryAreaCarryTask";

    private static final String checkDirectionIsReachable = "checkDirectionIsReachable";

    private static final String updateWorkStatus = "updateWorkStatus";

    private static final String getLocatorByLocation = "getLocatorByLocation";



    /**
     * 创建搬运任务
     * @param descri 任务描述
     * @param carryTask 搬运参数
     * @throws Exception
     */
    @Override
    @InterfaceMethod(key="savePath", name="创建搬运任务", type = InterfaceType.Send)
    public void savePath(String descri, CarryTask carryTask) throws Exception {
        plgFeignRequest(carryTask, SAVE_PATH, descri);
    }


    @Override
    public void containerOffShelfNoStore(String containerNo) throws Exception {
        Map<String, Object> containerMap = new HashMap<>();
        containerMap.put("containerNo",containerNo);
        RestMessage<String> restMessage =  plgFeignRequest(containerMap, containerOffShelfNoStore, "容器【{}】下架（不管库存）");
        if (!restMessage.isSuccess()){
            log.error("feignRouteService -> containerOffShelfNoStore 容器【{}】下架（不管库存）"+restMessage.getMessage(),containerNo);
            throw new PrologException(String.format("feignRouteService -> containerOffShelfNoStore 容器【%s】下架（不管库存）"+restMessage.getMessage(),containerNo));
        }
    }


    @Override
    public List<ContainerLocation> findFreeContainerByAreaNo(String areaNos) throws Exception{
        if (StringUtils.isEmpty(areaNos)){
            throw new PrologException("查询区域空闲托盘集合不能为空");
        }
        RestMessage<List<ContainerLocation>> restMessage = plgFeignRequest(areaNos, findFreeContainerByAreaNo, "查询区域空闲托盘集合");
        if (!restMessage.isSuccess()){
            log.error("feignRouteService -> findFreeContainerByAreaNo  查询区域[{}]的空闲托盘失败"+restMessage.getMessage(),JsonUtils.toString(areaNos));
            throw new PrologException(String.format("feignRouteService -> findFreeContainerByAreaNo  查询区域[%s]的空闲托盘失败"+restMessage.getMessage(),JsonUtils.toString(areaNos)));
        }
        return restMessage.getData();
    }


    @Override
    public List<AreaInOutCountDto> queryAreaInOutCount(List<String> areaNoList) throws Exception {
        RestMessage<List<AreaInOutCountDto>> restMessage = plgFeignRequest(areaNoList, queryAreaInOutCount, "根据区域【{}】查询出、入数量");
        if (!restMessage.isSuccess()){
            log.error("feignRouteService -> queryAreaInOutCount 根据区域【{}】查询出、入数量失败:"+restMessage.getMessage(),areaNoList);
            throw new PrologException(String.format("feignRouteService -> queryAreaInOutCount 根据区域【%s】查询出、入数量:"+restMessage.getMessage(),areaNoList));
        }
        List<AreaInOutCountDto> data = restMessage.getData();
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(data)){
            log.error("feignRouteService -> queryAreaInOutCount 根据区域【{}】查询出、入数量为空",areaNoList);
            throw new PrologException(String.format("feignRouteService -> queryAreaInOutCount 根据区域【%s】查询出、入数量为空",areaNoList));
        }
        return data;
    }


    @Override
    @InterfaceMethod(key="savePath", name="创建搬运任务", type = InterfaceType.Send)
    public void createCarryTask(String containerNo, Integer taskType, String startRegion, String startLocation, String endRegion,String endLocation, String businessType,Integer height,String describe,String businessProperty) throws Exception {
        CarryTask carryTask = setCarryTask(containerNo, taskType, startRegion, startLocation, endRegion, endLocation, businessType, height, describe, businessProperty, null,null,null);
        plgFeignRequest(carryTask, SAVE_PATH,"创建搬运任务");
    }
    @Override
    @InterfaceMethod(key="savePath", name="创建搬运任务", type = InterfaceType.Send)
    public void createCarryTask(String containerNo, Integer taskType, String startRegion, String startLocation, String endRegion,String endLocation, String businessType,Integer height,String describe,String businessProperty,String expand1,String expand2,String expand3) throws Exception {
        CarryTask carryTask = setCarryTask(containerNo, taskType, startRegion, startLocation, endRegion, endLocation, businessType, height, describe, businessProperty, expand1,expand2,expand3);
        plgFeignRequest(carryTask, SAVE_PATH,"创建搬运任务");
    }
    @Override
    public CarryTask setCarryTask(String containerNo, Integer taskType, String startRegion, String startLocation, String endRegion, String endLocation, String businessType, Integer height, String describe, String businessProperty,String expand1,String expand2,String expand3) throws Exception {
        CarryTask carryTask = new CarryTask();
        carryTask.setTaskType(LocationConstants.PATH_TASK_TYPE_CARRY);
        if (Objects.nonNull(taskType)) {
            //20清点位
            carryTask.setTaskType(taskType);
        }
        carryTask.setExtend1(expand1);
        carryTask.setExtend2(expand2);
        carryTask.setExtend3(expand3);
        carryTask.setId(PrologStringUtils.newGUID());
        carryTask.setContainerNo(containerNo);
        carryTask.setPalletNo(containerNo);
        carryTask.setStartRegion(startRegion);
        carryTask.setStartLocation(startLocation);
        if (StringUtils.isBlank(startRegion) || StringUtils.isBlank(startLocation)) {
            ContainerLocation containerLocation = seachLocationNo(MapUtils.put("containerNo", containerNo).getMap());
            carryTask.setStartRegion(containerLocation.getCurrentArea());
            carryTask.setStartLocation(containerLocation.getCurrentLocation());
        }
        carryTask.setEndRegion(endRegion);
        if (org.apache.commons.lang.StringUtils.isNotEmpty(endLocation)) {
            carryTask.setEndLocation(endLocation);
        }
        if (Objects.nonNull(height)){
            carryTask.setHeight(height);
        }

        if(StringUtils.isEmpty(businessProperty)){
            businessProperty = "EMPTY";
            ContainerInfo containerInfo = containerInfoMapper.findByMap(MapUtils.put("containerNo",containerNo).getMap(),ContainerInfo.class).stream().findFirst().orElse(null);
            if(containerInfo != null && "3".equals(containerInfo.getContainerType())){
                List<ContainerInfoDetail> containerInfoDetailDtos = containerInfoDetailMapper.findByMap(MapUtils.put("containerNo",containerInfo.getContainerNo()).getMap(),ContainerInfoDetail.class);
                if(CollectionUtils.isNotEmpty(containerInfoDetailDtos)){
                    StringBuilder businessTypeBuilder = new StringBuilder();
                    for (ContainerInfoDetail containerInfoDetailDto : containerInfoDetailDtos) {
                        //businessProperty
                        businessTypeBuilder.append(containerInfoDetailDto.getItemId() + "@@" + containerInfoDetailDto.getLotId() + "&");
                    }
                    //设置BusinessType
                    businessProperty = businessTypeBuilder.deleteCharAt(businessTypeBuilder.length() - 1).toString();
                }
            }
        }


        carryTask.setBusinessProperty(businessProperty);
        carryTask.setBusinessType(String.valueOf(businessType));
        carryTask.setBusinessDescribe(describe);
        carryTask.setPriority(99);
        return carryTask;
    }

    @Override
    public List<CarryTask> findCarryTaskListByContainerList(List<String> containerList) throws Exception {
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(containerList)){
            throw new PrologException("根据托盘集合查询搬运任务入参不能为空");
        }
        RestMessage<List<CarryTask>> rest = plgFeignRequest(containerList,FIND_CARRY_TASK_LIST_BY_CONYAINER_LIST,"根据托盘集合查询搬运任务");
        if (!rest.isSuccess()){
            log.error("feignRouteService -> findCarryTaskListByContainerList  根据托盘集合[{}]查询搬运任务失败"+rest.getMessage(),JsonUtils.toString(containerList));
            throw new PrologException(String.format("feignRouteService -> findCarryTaskListByContainerList  根据托盘集合[%s]查询搬运任务失败"+rest.getMessage(),JsonUtils.toString(containerList)));

        }
        return rest.getData();
    }




    @Override
    public List<AreaLocationCountDto> queryAreaLocationCountDtoList(List<String> areaList) throws Exception {
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(areaList)){
            throw new PrologException("feignRouteService -> queryAreaLocationCountDtoList 根据区域集合查询可用货位入参不能为空");
        }
        RestMessage<List<AreaLocationCountDto>> rest = plgFeignRequest(areaList,queryAreaLocationCountDtoList,"据区域集合查询可用货位");
        if (!rest.isSuccess()){
            log.error("feignRouteService -> queryAreaLocationCountDtoList  根据区域【{}】集合查询可用货位失败"+rest.getMessage(),JsonUtils.toString(areaList));
            throw new PrologException(String.format("feignRouteService -> queryAreaLocationCountDtoList  根据区域【%s】集合查询可用货位失败"+rest.getMessage(),JsonUtils.toString(areaList)));
        }
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(rest.getData())){
            log.error("feignRouteService -> queryAreaLocationCountDtoList  根据区域【{}】集合查询可用货位结果为空",JsonUtils.toString(areaList));
            throw new PrologException(String.format("feignRouteService -> queryAreaLocationCountDtoList  根据区域【%s】集合查询可用货位结果为空",JsonUtils.toString(areaList)));
        }
        List<AreaLocationCountDto> data = rest.getData();
        Iterator<AreaLocationCountDto> iterator = data.iterator();
        while (iterator.hasNext()){
            AreaLocationCountDto next = iterator.next();
            if (!areaList.contains(next.getAreaNo())){
                iterator.remove();
            }
        }
        return data;
    }


    /**
     * 根据货位查询货位信息
     * @return
     */
    @Override
    public List<WhLocator> getLocatorByLocation(List<String> locationList) {
        try {
            RestMessage<List<WhLocator>> restMessage = plgFeignRequest(locationList,getLocatorByLocation,"根据货位查询货位信息");
            AssertUtils.isTrue(restMessage.isSuccess(), restMessage.getMessage());
            return Optional.ofNullable(restMessage.getData()).orElse(new ArrayList<>());
        } catch (Exception e) {
            throw new PrologException(String.format("调用warehouse服务[getLocatorByLocation]接口异常:%s", e.getMessage()));
        }
    }


    @Override
    @InterfaceMethod(key="createBatchCarry", name="搬运任务接口批量生成", type = InterfaceType.Send)
    public void createBatchCarry(List<CarryTask> carryTasks) throws Exception {
        List<String> contaienrList = carryTasks.stream().map(CarryTask::getContainerNo).collect(Collectors.toList());
        List<ContainerLocationVo> rest = this.findLocationByContainerList(contaienrList);

        for (CarryTask carryTask : carryTasks) {
            ContainerLocationVo location = rest.stream()
                    .filter(x -> x.getContainerNo().equals(carryTask.getContainerNo())).findFirst()
                    .orElseThrow(() -> new PrologException("托盘【" + carryTask.getContainerNo() + "】查询不到点位信息"));

            if (StrUtil.isBlank(location.getTargetLocation()) ||
                    StrUtil.isBlank(location.getSourceLocation()) ||
                    !location.getTargetLocation().equals(location.getSourceLocation())) {
                throw new PrologException(String.format("托盘【%s】点位处于移动状态", carryTask.getContainerNo()));
            }
            carryTask.setStartLocation(location.getTargetLocation());
            carryTask.setStartRegion(location.getTargetArea());
        }
        RestMessage<String> result = plgFeignRequest(carryTasks, CREAT_BATCH_CARRY, "搬运任务接口批量生成");
        AssertUtils.isTrue(result.isSuccess(), "搬运任务接口批量生成调用失败:" + result.getMessage());
    }


    @Override
    @InterfaceMethod(key="creatCarryTaskAndExecuteNotTx", name="搬运任务接口生成并执行", type = InterfaceType.Send)
    public RestMessage<String> creatCarryTaskAndExecuteNotTx(CarryTask carryTask) throws Exception {
        List<ContainerLocationVo> rest = this.findLocationByContainerList(Arrays.asList(carryTask.getContainerNo()));
        ContainerLocationVo location = rest.stream()
                .filter(x -> x.getContainerNo().equals(carryTask.getContainerNo())).findFirst()
                .orElseThrow(() -> new PrologException("托盘【" + carryTask.getContainerNo() + "】查询不到点位信息"));

        if (StrUtil.isBlank(location.getTargetLocation()) ||
                StrUtil.isBlank(location.getSourceLocation()) ||
                !location.getTargetLocation().equals(location.getSourceLocation())) {
            throw new PrologException(String.format("托盘【%s】点位处于移动状态", carryTask.getContainerNo()));
        }
        carryTask.setStartLocation(location.getTargetLocation());
        carryTask.setStartRegion(location.getTargetArea());
        RestMessage<String> result = plgFeignRequest(carryTask, creatCarryTaskAndExecuteNotTx, "搬运任务接口生成并执行");
        return result;
    }

    /**
     * 创建容器点位信息.
     * @param itemContainerReqDto 容器号
     */
    @Override
    @InterfaceMethod(key="createItemContainer", name="创建容器点位信息", type = InterfaceType.Send)
    public void createItemContainer(ItemContainerReqDto itemContainerReqDto) throws Exception {
        RestMessage result = plgFeignRequest(itemContainerReqDto, CREATE_ITEM_CONTAINER, "创建容器点位信息");
        if(!result.isSuccess()){
            throw new Exception("创建容器点位信息失败："+result.getMessage());
        }
    }

    @Override
    public void createItemContainer(String locationNo, String containerNo, String containerType, String businessProperty) throws Exception {
        ItemContainerReqDto itemContainerReqDto = new ItemContainerReqDto();
        itemContainerReqDto.setLocationNo(locationNo);
        itemContainerReqDto.setContainerNo(containerNo);
        itemContainerReqDto.setContainerType(containerType);
        itemContainerReqDto.setBusinessProperty(businessProperty);
        createItemContainer(itemContainerReqDto);
    }

    @Override
    public List<ContainerLocation> findContainerLocationListByContainerList(List<String> containerList) throws Exception {
        if(containerList == null || containerList.size() == 0) {
            throw new Exception("查到容器点位信息错误，容器参数为空");
        }
        RestMessage<List<ContainerLocation>> result =  plgFeignRequest(containerList, FIND_CONTAINER_LOCATION_LIST_BY_ONTAINER_LIST, "根据容器集合查询位置以及货位");
        if(!result.isSuccess()){
            throw new Exception("根据容器查位置信息失败："+result.getMessage());
        }
        /*if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到容器点位信息");
        }*/
        return result.getData();
    }


    /**
     * 入库找区域
     *
     * @param inboundAllotAreaParamDto
     * @return
     * @throws Exception
     */
    @Override
    @InterfaceMethod(key="getAllotArea", name="入库找区域", type = InterfaceType.Send)
    public List<PortInfoAreaDto> getAllotAreaNew(InboundAllotAreaParamDto inboundAllotAreaParamDto) throws Exception {
        inboundAllotAreaParamDto.setWeight(0);
        RestMessage<List<PortInfoAreaDto>> result = plgFeignRequest(inboundAllotAreaParamDto, GET_AllOT_AREA, "入库找区域");
        return result.getData();
    }

    /**
     * 清除容器点位信息.
     * @param containerNo
     */
    @Override
    @InterfaceMethod(key="containerOffShelf", name="清除容器点位信息", type = InterfaceType.Send)
    public void containerOffShelf(String containerNo) throws Exception {
        plgFeignRequest(MapUtils.put("containerNo", containerNo).getMap(), CONTAINER_OFF_SHELF, "清除容器点位信息");
    }

    @Override
    public List<AreaContainerCountDto> areaContainerCount(List<AreaOrJointPointDto> areaOrJointPointDto) throws Exception {
        RestMessage<List<AreaContainerCountDto>> result = plgFeignRequest(areaOrJointPointDto, AREA_CONTAINER_COUNT, "通过区域查询容器任务");
        if(!result.isSuccess()){
            throw new Exception("根据容器查位置信息失败："+result.getMessage());
        }
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到容器点位信息");
        }
        return result.getData();
    }


    /**
     * 获取区域总货位数.
     * @param areaNo 区域传空，获取所有
     * @return
     */
    @Override
    @InterfaceMethod(key="findTotalCountByAreaNo", name="获取区域总货位数", type = InterfaceType.Send)
    public Map<String, Integer> findTotalCountByAreaNo(String areaNo) throws Exception {
        if(areaNo == null) {
            areaNo = "";
        }
        RestMessage<Map<String, Integer>> result = plgFeignRequest(areaNo, TOTAL_COUNT_BY_AREA, "获取区域总货位数");
        return result.getData();
    }

    /**
     * 通过区域批量查询
     * @param areaNos
     * @return
     * @throws Exception
     */
    @Override
    public List<WhArea> getAreaByAreaNos(List<String> areaNos) throws Exception {
        RestMessage<List<WhArea>> result = plgFeignRequest(areaNos, getAreaByAreaNos, "通过区域批量查询");
        if(!result.isSuccess()){
            throw new Exception("获取区域信息失败："+result.getMessage());
        }
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到区域信息");
        }
        return result.getData();
    }

    /**
     * 获取所有搬运任务回告.
     * @return
     */
    @Override
    public List<CarryTaskCallbackDto> getAllCallBack() throws Exception {
        RestMessage<List<CarryTaskCallbackDto>> result = plgFeignRequest(null, ALL_CALL_BACK, "查询所有搬运任务回告数据");
        return result.getData();
    }



    /**
     * 搬运任务转历史.
     */
    @Override
    @InterfaceMethod(key="toCallbackHis", name="搬运任务转历史", type = InterfaceType.Send)
    public void toCallbackHis(String carryTaskId) throws Exception {
        if(StringUtils.isEmpty(carryTaskId)) {
            return;
        }
        CarryTaskCallback carryTaskCallback = new CarryTaskCallback();
        carryTaskCallback.setId(carryTaskId);
        plgFeignRequest(carryTaskCallback, CALL_BACK_TO_HIS, "搬运任务转历史");
    }


    /*  *//**
     * 根据参数获取出入口资料
     *
     * @param param
     * @return
     *//*
    @Override
    @InterfaceMethod(key="getPortByParam", name="获取出入口资料", type = InterfaceType.Send)
    public List<PortInfo> getPortByParam(Map<String, Object> param) throws Exception {
        if(param == null) {
            param = new HashMap<>();
        }
        RestMessage<List<PortInfo>> result = plgFeignRequest(param, GET_PORT_BY_PARAM, "获取出入口资料");
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未配置出入口");
        }
        return result.getData();
    }*/

    /**
     * 查待分区域详情
     * @param dswRequestDto
     * @return
     */
    @Override
    public List<DswAreaDto> queryDswAreaList(DswRequestDto dswRequestDto) throws Exception {
        RestMessage<List<DswAreaDto>> result = plgFeignRequest(dswRequestDto, QUERY_DSW_AREA_LIST, "查待分区域详情");
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("无可入库区域");
        }
        return result.getData();
    }

    @Override
    public Boolean checkAreaIn(String areaNo) throws Exception {
        RestMessage<Boolean> result = plgFeignRequest(areaNo, CHECK_AREA_IN, "检查1个区域是否有空货位可以入");
        if(!result.isSuccess()){
            throw new Exception("检查1个区域是否有空货位可以入失败："+result.getMessage());
        }
        if(Objects.isNull(result.getData())) {
            throw new Exception("未查到区域是否有空货位可以入信息");
        }
        return result.getData();
    }


    @Override
    public ContainerLocation seachLocationNo(Map<String, Object> containerMap) throws Exception {
        if(containerMap == null || containerMap.size() == 0) {
            throw new Exception("根据容器编号查询点位错误，容器参数为空");
        }
        RestMessage<List<ContainerLocation>> result = plgFeignRequest(containerMap, SEARCH_LOCATION_NO, "根据容器编号查询点位");
        if(!result.isSuccess()) {
            throw new Exception("根据容器编号查询点位异常");
        }
        if(ObjectUtils.isEmpty(result.getData())){
            throw new Exception("根据容器编号查询点位异常：数据未查询到");
        }
        return result.getData().get(0);
    }

    @Override
    @InterfaceMethod(key="findLocationDeptByContainerList", name="根据容器集合查询移位数", type = InterfaceType.Send)
    public Map<String, Integer> findLocationDeptByContainerList(List<String> containerNos) throws Exception {
        if(containerNos == null || containerNos.size() == 0) {
            throw new Exception("查到容器点位信息错误，容器参数为空");
        }
        RestMessage<List<ContainerLocationVo>> result =  plgFeignRequest(containerNos, FIND_LOCATION_BY_CONTAINER_LIST, "根据容器集合查询移位数");
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到容器点位信息");
        }
        return result.getData().stream().collect(Collectors.toMap(ContainerLocationVo :: getContainerNo, ContainerLocationVo :: getDeptNum));
    }

    @Override
    //@InterfaceMethod(key="findLocationDeptByContainerList", name="按容器号批量查询容器信息", type = InterfaceType.Send)
    public Map<String, ContainerLocationVo> findLocationByContainerListNew(List<String> containerNos) throws Exception {
        if(containerNos == null || containerNos.size() == 0) {
            throw new Exception("查到容器点位信息错误，容器参数为空");
        }
        RestMessage<List<ContainerLocationVo>> result =  plgFeignRequest(containerNos, FIND_LOCATION_BY_CONTAINER_LIST, "根据容器集合查询位置以及货位");
        if(!result.isSuccess()){
            throw new Exception("根据容器查位置信息失败："+result.getMessage());
        }
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到容器点位信息");
        }
        return result.getData().stream().collect(Collectors.toMap(ContainerLocationVo :: getContainerNo, v -> v));
    }


    @Override
    public List<ContainerLocationVo> findLocationByContainerList(List<String> containerNos) throws Exception {
        if(containerNos == null || containerNos.size() == 0) {
            throw new Exception("查到容器点位信息错误，容器参数为空");
        }
        RestMessage<List<ContainerLocationVo>> result =  plgFeignRequest(containerNos, FIND_LOCATION_BY_CONTAINER_LIST, "根据容器集合查询位置以及货位");
        if(!result.isSuccess()){
            throw new Exception("根据容器查位置信息失败："+result.getMessage());
        }
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到容器点位信息");
        }
        return result.getData();
    }
    @Override
    public List<ContainerLocationVo> findLocationByContainerListNotVail(List<String> containerNos) throws Exception {
        if(containerNos == null || containerNos.size() == 0) {
            throw new Exception("查到容器点位信息错误，容器参数为空");
        }
        RestMessage<List<ContainerLocationVo>> result =  plgFeignRequest(containerNos, FIND_LOCATION_BY_CONTAINER_LIST, "根据容器集合查询位置以及货位");
        if(!result.isSuccess()){
            throw new Exception("根据容器查位置信息失败："+result.getMessage());
        }
        return result.getData();
    }

    @Override
    @InterfaceMethod(key="getLocNum", name="根据点位获取任务数量", type = InterfaceType.Send)
    public Map<String, Integer> getLocNum(List<String> list) throws Exception {
        if(list == null || list.size() == 0) {
            throw new Exception("查到根据点位获取任务数量错误，容器参数为空");
        }
        RestMessage<List<AreaTaskRespDto>> result =  plgFeignRequest(list, GET_LOC_NUM, "根据点位获取任务数量");
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查根据点位获取任务数量信息");
        }
        return result.getData().stream().collect(Collectors.toMap(AreaTaskRespDto :: getAreaNo, AreaTaskRespDto :: getTaskCount));
    }

    @Override
    @InterfaceMethod(key="getSxkTaskByAreaNos", name="根据区域查询任务数", type = InterfaceType.Send)
    public Map<String, Integer> getSxkTaskByAreaNos(AreaTaskReqDto areaNos) throws Exception {
        if(areaNos == null || areaNos.getAreaNos() == null || areaNos.getAreaNos().size() == 0) {
            throw new Exception("查到根据区域查询任务数错误，容器参数为空");
        }
        RestMessage<List<AreaTaskRespDto>> result =  plgFeignRequest(areaNos, GET_SXKTASK_BY_AREANOS, "根据区域查询任务数");
        if(CollectionUtils.isEmpty(result.getData())) {
            throw new Exception("未查到根据区域查询任务数信息");
        }
        return result.getData().stream().collect(Collectors.toMap(AreaTaskRespDto :: getAreaNo, AreaTaskRespDto :: getTaskCount));
    }


    /**
     * 根据起点/终点区域查询容器
     * @param areaNos
     * @return
     */
    @Override
    @InterfaceMethod(key="findContainerLocationByTargetAreaNos", name="根据起点/终点区域查询容器", type = InterfaceType.Send)
    public List<ContainerLocation>  findContainerLocationByTargetAreaNos(List<String> areaNos) throws Exception {
        RestMessage<List<ContainerLocation>> result =  plgFeignRequest(areaNos, FIND_CONTAINER_LOC_BY_TARGET_AREANOS, "根据终点区域查询容器");
        AssertUtils.isNotTrue(!result.isSuccess(),"根据终点区域查询容器异常:"+result.getMessage());
        if(CollectionUtils.isEmpty(result.getData())) {
            return new ArrayList<>();
        }
        return result.getData();
    }

    @Override
    public List<ContainerLocation> findContainerLocationByAreaNos(List<String> areaNos) throws Exception {
        RestMessage<List<ContainerLocation>> result =  plgFeignRequest(areaNos, findContainerLocationByAreaNos, "根据区域查询容器任务");
        AssertUtils.isNotTrue(!result.isSuccess(),"根据区域查询容器异常:"+result.getMessage());
        if(CollectionUtils.isEmpty(result.getData())) {
            return new ArrayList<>();
        }
        return result.getData();
    }

    /**
     * 条件查询搬运任务
     * @param query
     * @return
     */
    @Override
    @InterfaceMethod(key="listCarryTaskByParam", name="按条件查询搬运任务", type = InterfaceType.Send)
    public List<CarryTask> listCarryTaskByParam(CarryTask query) throws Exception {
        RestMessage<List<CarryTask>> result =  plgFeignRequest(query, LIST_CARRY_TASK_BY_PARAM, "按条件查询搬运任务");
        if(CollectionUtils.isEmpty(result.getData())) {
            log.info("未查到按条件查询搬运任务信息");
            return null;
        }
        return result.getData();
    }

    /**
     * 根据点位查询位置信息
     * @param locationNo
     * @return
     */
    @Override
    @InterfaceMethod(key="locationInfo", name="根据点位查询位置信息", type = InterfaceType.Send)
    public LocationInfoDto locationInfo(String locationNo) throws Exception {
        Map<String, Object> locationNoMap = new HashMap<>();
        locationNoMap.put("locationNo", locationNo);
        RestMessage<String> result =  plgFeignRequest(locationNoMap, LOCATION_INFO, "根据点位查询位置信息");
        Assert.notNull(result.getData(), "根据点位查询位置信息，未查询到对应的点位信息：" + locationNo);
        LocationInfoDto locationInfoDto = JSONObject.parseObject(result.getData(), LocationInfoDto.class);
        return locationInfoDto;
    }

    @Override
    @InterfaceMethod(key="updateLocByPalletNo", name="根据容器号修改点位", type = InterfaceType.Send)
    public void updateLocByPalletNo(String containerNo, String currentAreaNo, String currentLoc) throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("palletNo", containerNo);
        Map<String, Object> locMap = MapUtils.put("sourceArea",currentAreaNo)
                .put("sourceLocation",currentLoc)
                .put("taskTargetArea",currentAreaNo)
                .put("taskTargetLocation",currentLoc)
                .put("targetArea",currentAreaNo)
                .put("targetLocation",currentLoc)
                .put("currentArea",currentAreaNo)
                .put("currentLocation",currentLoc).getMap();
        map.put("map", locMap);
        plgFeignRequest(map, UPDATE_LOC_BY_PALLETNO, "根据容器号修改点位");

    }

    @Override
    @InterfaceMethod(key="checkContainer", name="判断当前点位是否有容器", type = InterfaceType.Send)
    public RestMessage<String> checkContainer(Map<String, Object> param) throws Exception {
        RestMessage<String> result =  plgFeignRequest(param, CHECK_CONTAINER, "判断当前点位是否有容器");
        return result;
    }

    @Override
    @InterfaceMethod(key="findContainerInfoByLocation", name="根据点位坐标查询容器信息", type = InterfaceType.Send)
    public ContainerLocationDto findContainerInfoByLocation(Map<String, Object> param) throws Exception {
        RestMessage<String> result =  plgFeignRequest(param, findContainerInfoByLocation, "根据点位坐标查询容器信息");
        if(!result.isSuccess()){
            throw new Exception("根据点位坐标查询容器信息失败："+result.getMessage());
        }
        if(Objects.isNull(result.getData())) {
            throw new Exception("根据点位坐标查询容器信息为空");
        }
        ContainerLocationDto containerLocationDto = JSONObject.parseObject(result.getData(), ContainerLocationDto.class);
        return containerLocationDto;
    }



    @Override
    @InterfaceMethod(key="checkCarryTask", name="判断有无结束点位为传入点位的任务", type = InterfaceType.Send)
    public boolean checkCarryTask(String locationNo) throws Exception {
        RestMessage<String> result =  plgFeignRequest(MapUtils.put("locationNo",locationNo).getMap(), CHECK_CARRY_TASK, "判断有无结束点位为传入点位的任务");
        if (!result.isSuccess()) {
            throw new BizException("查询点位有无任务异常：" + result.getMessage());
        }
        String data = result.getData();// true:有；false:没有
        Boolean flag = JsonHelper.getObject(data, Boolean.class);
        return flag;
    }

    @Override
    @InterfaceMethod(key="checkContainer", name="判断当前点位是否有容器", type = InterfaceType.Send)
    public boolean checkContainer(String locationNo) throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("locationNo", locationNo);
        RestMessage<String> result =  plgFeignRequest(jsonObject.toString(), checkContainerNew, "判断当前点位是否有容器");
        if (!result.isSuccess()) {
            throw new BizException("路径服务查询托盘：" + result.getMessage());
        }
        String data = result.getData();// true:有；false:没有
        Boolean flag = JsonHelper.getObject(data, Boolean.class);
        return flag;
    }

    @Override
    @InterfaceMethod(key="getAreaDetail", name="根据区域查询小车数量", type = InterfaceType.Send)
    public List<AreaTaskDto> getAreaDetail(List<String> areaNos) throws Exception {
        RestMessage<List<AreaTaskDto>> result =  plgFeignRequest(areaNos, getAreaDetail, "根据区域查询小车数量");
        if(!result.isSuccess()){
            throw new Exception("根据区域查询小车数量失败："+result.getMessage());
        }
        if(Objects.isNull(result.getData())) {
            throw new Exception("根据区域查询小车数量信息为空");
        }
        return result.getData();
    }

    @Override
    public List<AreaCarryTaskDto> queryAreaCarryTask(List<String> areaNos) throws Exception {
        RestMessage<List<AreaCarryTaskDto>> result =  plgFeignRequest(areaNos, queryAreaCarryTask, "根据区域查询任务数量");
        if(!result.isSuccess()){
            throw new Exception("根据区域查询任务数量失败："+result.getMessage());
        }
        if(Objects.isNull(result.getData())) {
            throw new Exception("根据区域查询任务数量信息为空");
        }
        return result.getData();
    }

    @Override
    @InterfaceMethod(key="checkDirectionIsReachable", name="通过当前区域和目标区域查询路径是否可达", type = InterfaceType.Send)
    public boolean checkDirectionIsReachable(String sourceAreaNo, String targetAreaNo)throws Exception  {
        RestMessage<Boolean> result =  plgFeignRequest(MapUtils.put("sourceAreaNo",sourceAreaNo).put("targetAreaNo",targetAreaNo).getMap(), checkDirectionIsReachable, "通过当前区域和目标区域查询路径是否可达");
        if(!result.isSuccess()){
            throw new Exception("通过当前区域和目标区域查询路径是否可达查询失败："+result.getMessage());
        }
        if(Objects.isNull(result.getData())) {
            throw new Exception("通过当前区域和目标区域查询路径是否可达为空");
        }
        return result.getData();
    }

    @Override
    public boolean createTaskWithAngle(CreateCarryTaskDto carryTask) throws Exception {
        RestMessage<String> restMessage = plgFeignRouteService.createTaskWithAngle(carryTask);
        if(!restMessage.isSuccess()){
            throw new Exception("带角度搬运任务发送失败：" + restMessage.getMessage());
        }
        return true;
    }

    @Override
    public boolean creatCarryTaskWithAngleAndExecute(CreateCarryTaskDto createCarryTaskDto) throws Exception {
        RestMessage<String> restMessage = plgFeignRouteService.creatCarryTaskWithAngleAndExecute(createCarryTaskDto);
        if(!restMessage.isSuccess()){
            throw new Exception("旋转发送失败：" + restMessage.getMessage());
        }
        return true;
    }

    /**
     *
     * @param containerNo
     */
    @Override
    @InterfaceMethod(key="updateWorkStatus", name="更新容器位置表工作台状态，和空托业务属性清空", type = InterfaceType.Send)
    public void updateWorkStatus(String containerNo) throws Exception {
        RestMessage<String> result =  plgFeignRequest(MapUtils.put("containerNo",containerNo).put("emptyPalletNo",false).getMap(), updateWorkStatus, "更新容器位置表工作台状态");
        if(!result.isSuccess()){
            throw new Exception("更新容器位置表工作台状态失败："+result.getMessage());
        }
    }

    /**
     * Feign统一调用方法.
     * @param data
     * @param methodName
     * @param descri
     * @return
     * @throws Exception
     */
    private <T> RestMessage<T> plgFeignRequest(Object data, String methodName, String descri) throws Exception {
        //开发环境，组装模拟数据返回
//        if(isDev()) {
//            Thread.sleep(500);
//            return resultDevData(methodName, data, descri);
//        }
        try {
            RestMessage<T> result = null;
            switch(methodName){
                case SAVE_PATH:
                    result = (RestMessage<T>) plgFeignRouteService.createCarry((CarryTask)data);
                    break;
                case creatCarryTaskAndExecuteNotTx:
                    result = (RestMessage<T>) plgFeignRouteService.creatCarryTaskAndExecuteNotTx((CarryTask)data);
                    break;
                case CREATE_ITEM_CONTAINER:
                    result = (RestMessage<T>) plgFeignRouteService.createItemContainer((ItemContainerReqDto)data);
                    break;
                case FIND_CONTAINER_LOCATION_LIST_BY_ONTAINER_LIST:
                    result = (RestMessage<T>) plgFeignRouteService.findContainerLocationListByContainerList((List<String>) data);
                    break;
                case FIND_LOCATION_BY_CONTAINER_LIST:
                    result = (RestMessage<T>) plgFeignRouteService.findLocationByContainerList((List<String>) data);
                    break;
                case GET_AllOT_AREA:
                    result = (RestMessage<T>) plgFeignRouteService.getAllotAreaNew((InboundAllotAreaParamDto) data);
                    break;
                case CONTAINER_OFF_SHELF:
                    result = (RestMessage<T>) plgFeignRouteService.containerOffShelf((Map<String, Object>) data);
                    break;
                case QUERY_DSW_AREA_LIST:
                    result = (RestMessage<T>) plgFeignRouteService.queryDswAreaList((DswRequestDto) data);
                    break;
                case CREAT_BATCH_CARRY:
                    result = (RestMessage<T>) plgFeignRouteService.createBatchCarry((List<CarryTask>) data);
                    break;
                case TOTAL_COUNT_BY_AREA:
                    result = (RestMessage<T>) plgFeignWarehouseService.findTotalCountByAreaNo((String) data);
                    break;
                case getAreaByAreaNos:
                    result = (RestMessage<T>) plgFeignWarehouseService.getAreaByAreaNos((List<String>) data);
                    break;
                case ALL_CALL_BACK:
                    result = (RestMessage<T>) plgFeignRouteService.findAllCallback();
                    break;
                case CALL_BACK_TO_HIS:
                    result = (RestMessage<T>) plgFeignRouteService.toCallbackHis((CarryTaskCallback) data);
                    break;
                case SEARCH_LOCATION_NO:
                    result = (RestMessage<T>) plgFeignRouteService.seachLocationNo((Map<String, Object>) data);
                    break;
                case GET_LOC_NUM:
                    result = (RestMessage<T>) plgFeignRouteService.getLocNum((List<String>)data);
                    break;
                case GET_SXKTASK_BY_AREANOS:
                    result = (RestMessage<T>) plgFeignRouteService.getSxkTaskByAreaNos((AreaTaskReqDto) data);
                    break;
                case FIND_CONTAINER_LOC_BY_TARGET_AREANOS:
                    result = (RestMessage<T>) plgFeignRouteService.findContainerLocationByTargetAreaNos((List<String>) data);
                    break;
                case findContainerLocationByAreaNos:
                    result = (RestMessage<T>) plgFeignRouteService.findContainerLocationByAreaNos((List<String>) data);
                    break;
                case LIST_CARRY_TASK_BY_PARAM:
                    result = (RestMessage<T>) plgFeignRouteService.listCarryTaskByParam((CarryTask) data);
                    break;
                case LOCATION_INFO:
                    result = (RestMessage<T>) plgFeignRouteService.locationInfo((Map<String, Object>) data);
                    break;
                case UPDATE_LOC_BY_PALLETNO:
                    result = (RestMessage<T>) plgFeignRouteService.updateLocByPalletNo((Map<String, Object>) data);
                    break;
                case CHECK_CONTAINER:
                    result = (RestMessage<T>) plgFeignRouteService.checkContainer((Map<String, Object>) data);
                    break;
                case findContainerInfoByLocation:
                    result = (RestMessage<T>) plgFeignRouteService.findContainerInfoByLocation((Map<String, Object>) data);
                    break;
                case CHECK_CARRY_TASK:
                    result = (RestMessage<T>) plgFeignRouteService.checkCarryTask((Map<String, Object>) data);
                    break;
                case CHECK_AREA_IN:
                    result = (RestMessage<T>) plgFeignRouteService.checkAreaIn((String) data);
                    break;
                case AREA_CONTAINER_COUNT:
                    result = (RestMessage<T>) plgFeignRouteService.areaContainerCount((List<AreaOrJointPointDto>) data);
                    break;
                case FIND_CARRY_TASK_LIST_BY_CONYAINER_LIST:
                    result = (RestMessage<T>) plgFeignRouteService.findCarryTaskListByContainerList((List<String>) data);
                    break;
                case queryAreaLocationCountDtoList:
                    result = (RestMessage<T>) plgFeignRouteService.queryAreaLocationCountDtoList((List<String>) data);
                    break;
                case findAreaNoAndContainerCountMap:
                    result = (RestMessage<T>) plgFeignRouteService.findAreaNoAndContainerCountMap((String) data);
                    break;
                case findFreeContainerByAreaNo:
                    result = (RestMessage<T>) plgFeignRouteService.findFreeContainerByAreaNo((String) data);
                    break;
                case containerOffShelfNoStore:
                    result = (RestMessage<T>) plgFeignRouteService.containerOffShelfNoStore((Map<String, Object>) data);
                    break;
                case queryAreaInOutCount:
                    result = (RestMessage<T>) plgFeignRouteService.queryAreaInOutCount((List<String>) data);
                    break;
                case getAreaDetail:
                    result = (RestMessage<T>) plgFeignRouteService.getAreaDetail((List<String>) data);
                    break;
                case queryAreaCarryTask:
                    result = (RestMessage<T>) plgFeignRouteService.queryAreaCarryTask((List<String>) data);
                    break;
                case checkDirectionIsReachable:
                    result = (RestMessage<T>) plgFeignRouteService.checkDirectionIsReachable((Map<String, Object>) data);
                    break;
                case updateWorkStatus:
                    result = (RestMessage<T>) plgFeignRouteService.updateWorkStatus((Map<String, Object>) data);
                    break;
                case checkContainerNew:
                    result = (RestMessage<T>) plgFeignRouteService.checkContainerNew(data.toString());
                    break;
                case getLocatorByLocation:
                    result = (RestMessage<T>) plgFeignWarehouseService.getLocatorByLocation((List<String>) data);
                    break;

                default:
                    throw new Exception("未找到可调用服务");
            }
            if (!result.isSuccess()) {
                throw new Exception(descri + "调用失败：" + result.getMessage());
            }
            return result;
        } catch (Exception e) {
            throw new Exception(descri + "调用异常：" + e.getMessage());
        }

    }

    private <T> RestMessage<T> resultDevData(String methodName, Object data, String descri) throws Exception {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Random random = new Random();
        RestMessage result = null;
        List<Object> dataList = new ArrayList<>();
        try {
            switch(methodName){
                case TOTAL_COUNT_BY_AREA:
                    Map<String, Integer> totalCountMap = new HashMap<>();
                    totalCountMap.put("Z010102",3);
                    totalCountMap.put("Z010103",3);
                    result = RestMessage.newInstance(true, "请求成功", totalCountMap);
                    break;
                case GET_AllOT_AREA:
                    List<PortInfoAreaDto> infos = new ArrayList<>();
                    PortInfoAreaDto portInfo = new PortInfoAreaDto();
                    portInfo.setPortNo("");
                    portInfo.setAreaNo("SXK0101");
                    portInfo.setPriority(0);
                    portInfo.setTaskPower(0);
                    portInfo.setContainerCountPower(0);
                    portInfo.setAreaReserveCount(0);
                    portInfo.setMatchGroup(false);
                    portInfo.setTaskCount(0);
                    portInfo.setPropertyCount(0);
                    portInfo.setSubAreaLocatorCount(0);
                    portInfo.setCanInCount(0);
                    infos.add(portInfo);
                    result = RestMessage.newInstance(true, "请求成功", infos);
                    break;
                case ALL_CALL_BACK:
                    List<ContainerTask> all = containerTaskService.findByMap(null,ContainerTask.class);
                    all = all.stream().filter(item -> item.getStatus().intValue() == 1).collect(Collectors.toList());
                    List<CarryTaskCallbackDto> carryTaskCallbackDtos = new ArrayList<>();
                    for (ContainerTask containerTask : all) {

                        CarryTaskCallbackDto carryTaskCallbackDto = new CarryTaskCallbackDto();
                        carryTaskCallbackDto.setId(PrologStringUtils.newGUID());
                        carryTaskCallbackDto.setContainerNo(containerTask.getContainerNo());
                        carryTaskCallbackDto.setPalletNo(containerTask.getContainerNo());
                        if (containerTask.getContainerType() == 1) {
                            final BizOutboundTaskDetail byId = bizOutboundTaskDetailMapper.findById(containerTask.getOutboundDetailId(),BizOutboundTaskDetail.class);
                            carryTaskCallbackDto.setEndLocation(byId.getTargetArea());
                            carryTaskCallbackDto.setEndRegion(byId.getTargetArea());
                        } else {
                            carryTaskCallbackDto.setEndLocation("C010201");
                            carryTaskCallbackDto.setEndRegion("JXP0002");
                        }
                        carryTaskCallbackDto.setBusinessType("20");
                        carryTaskCallbackDtos.add(carryTaskCallbackDto);
                    }
                    Criteria criteria = new Criteria(BizInboundTask.class);
                    criteria.restrictionBuilder().eq(BizInboundTask::getStatus, 10).build();
                    List<BizInboundTask> bizInboundTasks = bizInboundTaskMapper.findByCriteria(criteria);
                    for (BizInboundTask bizInboundTask : bizInboundTasks) {
                        CarryTaskCallbackDto carryTaskCallbackDto = new CarryTaskCallbackDto();
                        carryTaskCallbackDto.setId(PrologStringUtils.newGUID());
                        carryTaskCallbackDto.setContainerNo(bizInboundTask.getContainerNo());
                        carryTaskCallbackDto.setPalletNo(bizInboundTask.getContainerNo());
                        carryTaskCallbackDto.setEndLocation("S"+bizInboundTask.getId());
                        carryTaskCallbackDto.setEndRegion(bizInboundTask.getTargetArea());
                        carryTaskCallbackDto.setBusinessType("10");
                        carryTaskCallbackDtos.add(carryTaskCallbackDto);
                    }
                    List<ContainerInfo> containerInfoList = containerInfoMapper.findByMap(null,ContainerInfo.class);
                    if (!containerInfoList.isEmpty()) {
                        for (ContainerInfo containerInfo : containerInfoList) {
                            if (containerInfo.getTaskType() == 0) {
                                continue;
                            }
                            CarryTaskCallbackDto carryTaskCallbackDto = new CarryTaskCallbackDto();
                            carryTaskCallbackDto.setId(PrologStringUtils.newGUID());
                            carryTaskCallbackDto.setContainerNo(containerInfo.getContainerNo());
                            carryTaskCallbackDto.setPalletNo(containerInfo.getContainerNo());
                            carryTaskCallbackDto.setEndLocation(random.nextInt(10000000) + "");
                            carryTaskCallbackDto.setBusinessType(containerInfo.getTaskType()+"");
                            carryTaskCallbackDtos.add(carryTaskCallbackDto);
                        }
                    }
                    result = RestMessage.newInstance(true, "请求成功", carryTaskCallbackDtos);
                    break;
                case SEARCH_LOCATION_NO:
                    List<ContainerLocation> containerLocations = new ArrayList<ContainerLocation>();
                    ContainerLocation containerLocation = new ContainerLocation();
                    containerLocation.setCurrentArea("T0102");
                    containerLocation.setTargetArea("T0102");
                    containerLocation.setSourceArea("T0102");
                    containerLocation.setTaskState(30);
                    containerLocations.add(containerLocation);
                    result = RestMessage.newInstance(true, "请求成功", containerLocations);
                    break;
                case FIND_LOCATION_BY_CONTAINER_LIST:
                    List<String> containerNos = (List<String>) data;
                    for(String containerNo : containerNos) {
                        ContainerLocationVo loc = new ContainerLocationVo();
                        loc.setContainerNo(containerNo);
                        loc.setSourceArea("BCR61");
                        loc.setCurrentArea("SPS01");
                        loc.setCurrentLocation("0200100010");
                        loc.setSourceArea("BCR61");
                        loc.setTargetArea("SPS04");
                        loc.setTargetLocation(containerNo);
                        loc.setSourceLocation(containerNo);
                        loc.setDeptNum(random.nextInt(5));
                        dataList.add(loc);
                    }
                    result = RestMessage.newInstance(true, "请求成功", dataList);
                    break;
                case FIND_CONTAINER_LOCATION_LIST_BY_ONTAINER_LIST:
                    List<String> containerNos1 = (List<String>) data;
                    for(String containerNo : containerNos1) {
                        ContainerLocation loc = new ContainerLocation();
                        loc.setContainerNo(containerNo);
                        loc.setSourceArea("BCR61");
                        loc.setCurrentArea("SPS01");
                        loc.setCurrentLocation("0200100010");
                        loc.setSourceArea("BCR61");
                        loc.setTargetArea("SPS04");
                        loc.setTargetLocation(containerNo);
                        loc.setSourceLocation(containerNo);
                        dataList.add(loc);
                    }
                    result = RestMessage.newInstance(true, "请求成功", dataList);
                    break;
                case GET_LOC_NUM:
                    List<String> loclist = (List<String>) data;
                    AreaTaskRespDto areadata = null;
                    for(String loc : loclist) {
                        areadata = new AreaTaskRespDto();
                        areadata.setAreaNo(loc);
                        areadata.setTaskCount(random.nextInt(10));
                        dataList.add(areadata);
                    }
                    result = RestMessage.newInstance(true, "请求成功", dataList);
                    break;
                case GET_SXKTASK_BY_AREANOS:
                    List<String> arealist = ((AreaTaskReqDto) data).getAreaNos();
                    for(String areaNo : arealist) {
                        areadata = new AreaTaskRespDto();
                        areadata.setAreaNo(areaNo);
                        areadata.setTaskCount(random.nextInt(10));
                        dataList.add(areadata);
                    }
                    result = RestMessage.newInstance(true, "请求成功", dataList);
                    break;
                case FIND_CONTAINER_LOC_BY_TARGET_AREANOS:
                    List<String> arealist1 = ((List<String>) data);
                    List<ContainerLocationVo> locList = new ArrayList<>();
                    for (String v : arealist1) {
                        ContainerLocationVo loc = new ContainerLocationVo();
                        for (int i = 0; i < random.nextInt(3); i++) {
                            loc = new ContainerLocationVo();
                            loc.setContainerNo("KK"+ random.nextInt(1000));
                            loc.setTargetArea(v);
                            locList.add(loc);
                        }
                    }
                    result = RestMessage.newInstance(true, "请求成功", locList);
                    break;
                case LIST_CARRY_TASK_BY_PARAM:
                    List<CarryTask> carryTaskList = null;
                    if(random.nextInt(10)%2 == 0) {
                        carryTaskList = new ArrayList<>();
                        carryTaskList.add((CarryTask)data);
                    }
                    result = RestMessage.newInstance(true, "请求成功", carryTaskList);
                    break;

                case QUERY_DSW_AREA_LIST:
                    List<DswAreaDto> areaList = new ArrayList<>();
                    arealist = ((DswRequestDto) data).getAreaNoList();
                    DswAreaDto dswArea = null;
                    for(String areaNo : arealist) {
                        dswArea = new DswAreaDto();
                        dswArea.setAreaNo("A0101");
                        dswArea.setFreeLocatorCount(random.nextInt(10));
                        dswArea.setContainerCount(random.nextInt(20));
                        dswArea.setBusinessPropertyCount(random.nextInt(5));
                        dswArea.setRkCount(random.nextInt(5));
                        dswArea.setCkCount(random.nextInt(5));
                        dswArea.setAreaNo(areaNo);
                        Map<String, Integer> map = new HashMap<>();
                        map.put("SPSR0101", 1);
                        map.put("SPSR0102", 1);
                        dswArea.setPortCountMap(map);
                        areaList.add(dswArea);
                    }
                    result = RestMessage.newInstance(true, "请求成功", areaList);
                    break;
                case LOCATION_INFO:
                    LocationInfoDto dto = new LocationInfoDto();
                    dto.setX(random.nextInt(20));
                    dto.setY(random.nextInt(20));
                    result = RestMessage.newInstance(true, "请求成功", dto);
                    break;
                case CHECK_CONTAINER:
                    result = RestMessage.newInstance(true, "请求成功", "true");
                    break;
                case queryAreaCarryTask:
                    result = RestMessage.newInstance(true, "请求成功", null);
                    break;
                case findContainerInfoByLocation:
                    ContainerLocationDto containerLocationDto = new ContainerLocationDto();
                    Map<String,Object> locationMap = (HashMap) data;
                    containerLocationDto.setContainerNo("PK" + locationMap.get("locationNo"));
                    result = RestMessage.newInstance(true, "请求成功", containerLocationDto);
                    break;
                case CHECK_CARRY_TASK:
                    result = RestMessage.newInstance(true, "请求成功", "false");
                    break;
                case CHECK_AREA_IN:
                    result = RestMessage.newInstance(true, "请求成功", true);
                    break;
                case AREA_CONTAINER_COUNT:
                    List<AreaContainerCountDto> areaContainerCountDtoList = new ArrayList<>();
                    List<AreaOrJointPointDto> areaOrJointPointDtos = (List<AreaOrJointPointDto>) data;
                    AreaContainerCountDto area = null;
                    for (AreaOrJointPointDto areaOrJointPointDto : areaOrJointPointDtos) {
                        area = new AreaContainerCountDto();
                        area.setAreaNo(areaOrJointPointDto.getAreaNo());
                        area.setTaskType(10);
                        area.setTaskCount(random.nextInt(10));
                        area.setHeight(random.nextInt(10));
                        area.setLocationNo(areaOrJointPointDto.getJointPoint());
                        areaContainerCountDtoList.add(area);
                    }
                    result = RestMessage.newInstance(true, "请求成功", areaContainerCountDtoList);
                    break;
                case FIND_CARRY_TASK_LIST_BY_CONYAINER_LIST:
                    List<CarryTask> carryTasks = new ArrayList<CarryTask>();
                    containerNos = (List<String>) data;
                    for (String containerNo : containerNos) {
                        CarryTask carryTask = new CarryTask();
                        carryTask.setContainerNo(containerNo);
                        carryTask.setPalletNo(containerNo);
                        carryTask.setTaskType(0);
                        carryTasks.add(carryTask);
                    }
                    result = RestMessage.newInstance(true, "请求成功", carryTasks);
                    break;
                case queryAreaLocationCountDtoList:
                    List<AreaLocationCountDto> areaLocationCountDtos = new ArrayList<>();
                    List<String> areas = (List<String>) data;
                    for (String areaNo : areas) {
                        AreaLocationCountDto countDto = new AreaLocationCountDto();
                        countDto.setAreaNo(areaNo);
                        countDto.setLocatorCount(2);
                        countDto.setFreeCount(1);
                        countDto.setUseCount(0);
                        areaLocationCountDtos.add(countDto);
                    }
                    result = RestMessage.newInstance(true, "请求成功", areaLocationCountDtos);
                    break;
                case findFreeContainerByAreaNo:
                    List<ContainerLocation> containerLocations1 = new ArrayList<>();
                    List<ContainerInfo> containerInfos = containerInfoMapper.findByMap(null,ContainerInfo.class).stream().filter(o -> o.getTaskType() == 0).collect(Collectors.toList());

                    String areaAttrStr1 = (String) data;
                    String[] areaAttrStr2 = areaAttrStr1.split(",");
                    ContainerLocation containerLocation1 = null;
                    for (ContainerInfo containerInfo : containerInfos) {
                        containerLocation1 = new ContainerLocation();
                        containerLocation1.setContainerNo(containerInfo.getContainerNo());
                        containerLocation1.setCurrentArea(areaAttrStr2[0]);
                        containerLocation1.setBusinessProperty("01010");
                        containerLocation1.setCurrentLocation(random.nextInt(100000) + "");
                        containerLocations1.add(containerLocation1);
                    }
                    result = RestMessage.newInstance(true, "请求成功", containerLocations1);
                    break;
                case containerOffShelfNoStore:
                    result = RestMessage.newInstance(true, "请求成功", null);
                    break;
                case queryAreaInOutCount:
                    List<AreaInOutCountDto> areaInOutCountDtoList = new ArrayList<>();
                    List<String> areaNoList =  (List<String>) data;
                    for (String areaNo : areaNoList) {
                        AreaInOutCountDto areaInOutCountDto = new AreaInOutCountDto();
                        areaInOutCountDto.setAreaNo(areaNo);
                        areaInOutCountDto.setInCount(0);
                        areaInOutCountDto.setOutCount(0);
                        areaInOutCountDtoList.add(areaInOutCountDto);
                    }
                    result = RestMessage.newInstance(true, "请求成功", areaInOutCountDtoList);
                    break;
                case areachange:
                    result = RestMessage.newInstance(true, "请求成功", null);
                    break;
                case getAreaDetail:
                    List<AreaTaskDto> resultList = new ArrayList<>();
                    List<String> list =  (List<String>) data;
                    for (String areaNo : list) {
                        AreaTaskDto entity = new AreaTaskDto();
                        entity.setAreaNo(areaNo);
                        entity.setCkCount(1);
                        entity.setRkCount(1);
                        entity.setCarCount(1);
                        entity.setCarryCount(1);
                        entity.setMaxCount(2);
                        resultList.add(entity);
                    }
                    result = RestMessage.newInstance(true, "请求成功", resultList);
                    break;
                case checkDirectionIsReachable:
                    RestMessage.success("查询成功",true);
                    break;
                case getLocatorByLocation:
                    List<WhLocator> whLocationList = new ArrayList<>();
                    List<String> locationList =  (List<String>) data;
                    for (String location : locationList) {
                        WhLocator entity = new WhLocator();
                        entity.setX(random.nextInt(100000));
                        entity.setY(random.nextInt(100000));
                        entity.setLocationNo(location);
                        whLocationList.add(entity);
                    }
                    result = RestMessage.newInstance(true, "请求成功", whLocationList);
                    break;
                case getAreaByAreaNos:
                    List<WhArea>  whAreas = new ArrayList<>();
                    List<String> areaLists =  (List<String>) data;
                    for (String areaNo : areaLists) {
                        WhArea entity = new WhArea();
                        entity.setX(random.nextInt(100000));
                        entity.setY(random.nextInt(100000));
                        entity.setAreaNo(areaNo);
                        whAreas.add(entity);
                    }
                    result = RestMessage.newInstance(true, "请求成功", whAreas);
                    break;
                default:
                    result = RestMessage.newInstance(true, "请求成功");
            }
            if (!result.isSuccess()) {
                throw new Exception(descri + "调用失败：" + result.getMessage());
            }
            return result;
        } catch (Exception e) {
            throw new Exception(descri + "调用异常：" + e.getMessage());
        }

    }

    /**
     * 验证环境.
     * @return
     */
    private boolean isDev() {
        if(!StringUtils.isEmpty(env) && "dev".equals(env)) {
            return true;
        }
        return false;
    }
}
