package com.zy.acs.manager.manager.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.zy.acs.common.constant.RedisConstant; import com.zy.acs.common.enums.AgvStatusType; import com.zy.acs.common.utils.JudgeSupport; import com.zy.acs.common.utils.RedisSupport; import com.zy.acs.manager.core.domain.VehicleDto; import com.zy.acs.manager.manager.entity.*; import com.zy.acs.manager.manager.enums.SegmentStateType; import com.zy.acs.manager.manager.mapper.AgvMapper; import com.zy.acs.manager.manager.service.*; import com.zy.acs.manager.system.service.ConfigService; import com.zy.acs.framework.common.Cools; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * 字典数据Service实现 * * @author vincent * @since 2020-03-14 11:29:04 */ @Slf4j @Service public class AgvServiceImpl extends ServiceImpl implements AgvService { private final RedisSupport redis = RedisSupport.defaultRedisSupport; @Autowired private AgvDetailService agvDetailService; @Autowired private AgvModelService agvModelService; @Autowired private ConfigService configService; @Autowired private CodeService codeService; @Autowired private SegmentService segmentService; @Override public Agv selectByUuid(String uuid) { return this.getOne(new LambdaQueryWrapper().eq(Agv::getUuid, uuid)); } @Override public Agv queryIdle(Task task) { if (Cools.isEmpty(task)) { return null; } return null; } @Override public Boolean judgeEnable(Long agvId) { return this.judgeEnable(agvId, null); } @Override public Boolean judgeEnable(Long agvId, JudgeSupport support) { Agv agv = this.getById(agvId); AgvModel agvModel = agvModelService.getById(agv.getAgvModel()); if (segmentService.count(new LambdaQueryWrapper() .eq(Segment::getAgvId, agvId) .and( i -> { // i.eq(Segment::getState, SegmentStateType.WAITING.toString()).or() i.eq(Segment::getState, SegmentStateType.RUNNING.toString()); }) ) > 0) { return false; } if (!this.judgeOnline(agv.getId())) { log.warn("[{}]号Agv不是在线状态......", agv.getUuid()); return false; } AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); if (null == agvDetail) { log.warn("[{}]号Agv未收到状态包......", agv.getUuid()); return false; } if (agvDetail.getVol() == 0) { return false; } if (!agvDetail.getAgvStatus().equals(AgvStatusType.IDLE) && !agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { log.warn("[{}]号Agv不是空闲状态......", agv.getUuid()); return false; } if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { if (agvDetail.getVol() <= agvModel.getQuaBattery()) { return false; } } if (support != null) { if (!support.execute(agvDetail)) { return false; } } if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { if (agvDetail.getPos() != 1) { log.warn("[{}]号Agv请移动到定位......", agv.getUuid()); return false; } } return true; } @Override public Boolean judgeOnline(Long agvId) { Agv agv = this.getById(agvId); return redis.getObject(RedisConstant.AGV_ONLINE_FLAG, agv.getUuid()) != null; } @Override public List getVehicleDtoList(List noIncluded) { List res = new ArrayList<>(); List list = this.list(new LambdaQueryWrapper()); for (Agv agv : list) { if (!Cools.isEmpty(noIncluded)) { if (noIncluded.contains(agv.getUuid())) { continue; } } AgvDetail detail = agvDetailService.selectByAgvId(agv.getId()); VehicleDto dto = new VehicleDto(); dto.setVehicle(agv.getUuid()); dto.setPosCode(codeService.getById(detail.getRecentCode()).getData()); res.add(dto); } return res; } }