AcsGetPointService.java 2.92 KB
package com.huaheng.api.acs.service;

import com.alibaba.fastjson.JSON;
import com.huaheng.api.acs.domain.AcsPointStatus;
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.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.location.domain.AcsLocationStatus;
import com.huaheng.pc.config.location.service.AcsLocationStatusService;
import com.huaheng.pc.task.agvTask.service.AgvTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 长沙agv交互接口
 */
@Service
public class AcsGetPointService {

    private static final Logger logger = LoggerFactory.getLogger(AcsGetPointService.class);

    @Resource
    private AgvTaskService agvTaskService;
    @Resource
    private AddressService addressService;

    @Resource
    private AcsLocationStatusService acsLocationStatusService;

    public void autoGetAcsPointAll() {
        autoGetAcsPoint("3",2);
        autoGetAcsPoint("4",2);
    }


    @Transactional(rollbackFor = Exception.class)
    public void autoGetAcsPoint(String area,Integer layer) {
        String  url = addressService.selectAddress("AGV", QuantityConstant.WAREHOUSECODE, area, layer) + "PlaceholderTask";
        String JsonParam="";
        String result = OkHttpUtils.bodypost(url, JsonParam, "", "获取AGV占位");
        if (StringUtils.isEmpty(result)) {
            throw new ServiceException("ACS接口地址错误或服务器连接不到或返回为空");
        }
        AjaxResult ajaxResultACS = JSON.parseObject(result, AjaxResult.class);
        if (!ajaxResultACS.state) {
        }else{
            List<AcsPointStatus> acsPointStatusList=( List<AcsPointStatus>)ajaxResultACS.getData();
            if(acsPointStatusList==null){
                return;
            }
            String jsonString=JSON.toJSONString(acsPointStatusList);
            List<AcsPointStatus>  findlist=JSON.parseArray(jsonString,AcsPointStatus.class);

            if(findlist!=null&&findlist.size()>0){
                List<AcsLocationStatus> list=acsLocationStatusService.getAcsLocationStatusByArea(area);
                for (AcsLocationStatus acsLocationStatus:list){
                    for (AcsPointStatus acsPointStatus:findlist){
                        if(acsLocationStatus.getCode().equals(acsPointStatus.getStationCode())){
                            acsLocationStatus.setAcsStatus(acsPointStatus.getPlaceholder()==true?1:2);
                        }
                    }
                }
                acsLocationStatusService.updateBatchById(list);
            }
        }
        return;
    }

}