package com.zy.acs.manager.core.service; import com.zy.acs.framework.common.Cools; import com.zy.acs.manager.manager.entity.Loc; import com.zy.acs.manager.manager.entity.Sta; import com.zy.acs.manager.manager.entity.Task; import com.zy.acs.manager.manager.service.AreaAgvService; import com.zy.acs.manager.manager.service.LocService; import com.zy.acs.manager.manager.service.StaService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import java.util.Collections; import java.util.List; @Slf4j @Service public class AgvAreaDispatcher { @Autowired private LocService locService; @Autowired private StaService staService; @Autowired private AreaGovernService areaGovernService; @Autowired private AreaAgvService areaAgvService; @PostConstruct public void init() { } public List getAgvNosByTask(Task task) { if (null == task) { return null; } Loc oriLoc = null; Sta oriSta = null; Loc destLoc = null; Sta destSta = null; if (null != task.getOriLoc()) { oriLoc = locService.getById(task.getOriLoc()); return this.getAgvIdsByCode(oriLoc.getCode$()); } if (null != task.getOriSta()) { oriSta = staService.getById(task.getOriSta()); return this.getAgvIdsByCode(oriSta.getCode$()); } if (null != task.getDestLoc()) { destLoc = locService.getById(task.getDestLoc()); return this.getAgvIdsByCode(destLoc.getCode$()); } if (null != task.getDestSta()) { destSta = staService.getById(task.getDestSta()); return this.getAgvIdsByCode(destSta.getCode$()); } return null; } public List getAgvIdsByCode(String code) { if (Cools.isEmpty(code)) { return Collections.emptyList(); } List areaIds = areaGovernService.queryAreas(code); List agvIds = areaAgvService.queryAgvIdsByAreaIds(areaIds); List agvIdsWithoutAreaAgv = areaAgvService.findAgvIdsWithoutAreaAgv(); if (agvIdsWithoutAreaAgv.isEmpty()) { return agvIds; }else { if (agvIds.isEmpty()){ return agvIdsWithoutAreaAgv; } } agvIds.addAll(agvIdsWithoutAreaAgv); return agvIds; } public List getAgvNosByStaNo(String staNo) { return null; } // 如果都没有命中,就返回全部code public List getCodesByAgvId(Long agvId) { List areaIds = areaAgvService.queryAreaIdsByAgvId(agvId); return areaGovernService.queryCodes(areaIds); } // 判断车辆是否被area绑定,如果绑定返回 true, 如果没绑定返回 false public Boolean isAgvExistsInAnyArea(Long agvId) { List agvIdsWithoutAreaAgv = areaAgvService.findAgvIdsWithoutAreaAgv(); // 没有被绑定的车辆集合 if (Cools.isEmpty(agvIdsWithoutAreaAgv)) { return true; } return !agvIdsWithoutAreaAgv.contains(agvId); } }