package com.zy.acs.manager.manager.service.impl; import com.zy.acs.common.utils.GsonUtils; import com.zy.acs.manager.core.domain.BackpackDto; import com.zy.acs.manager.manager.controller.param.OpenAgvParam; import com.zy.acs.manager.manager.controller.result.BackpackVo; import com.zy.acs.manager.manager.controller.result.OpenAgvInfo; import com.zy.acs.manager.manager.entity.*; import com.zy.acs.manager.manager.enums.SegmentStateType; import com.zy.acs.manager.manager.service.*; import com.zy.acs.manager.system.service.ConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Service("openAlgorithmService") public class OpenAlgorithmServiceImpl implements OpenAlgorithmService { @Autowired private AgvDetailService agvDetailService; @Autowired private TaskService taskService; @Autowired private AgvModelService agvModelService; @Autowired private AgvService agvService; @Autowired private SegmentService segmentService; @Autowired private ConfigService configService; @Override public List listAgv(OpenAgvParam param) { List agvList = agvService.list(); List result = new ArrayList<>(); AgvDetail agvDetail; AgvModel agvModel; for (Agv agv : agvList) { agvDetail = agvDetailService.getById(agv.getId()); List taskList = taskService.findTransportTasksByAgv(agvDetail.getId()); agvModel = agvModelService.getByAgvId(agv.getAgvModel()); OpenAgvInfo info = new OpenAgvInfo(); info.setAgvNo(agvDetail.getUuid()); info.setStatus(agvDetail.getStatus()); info.setPosition(agvDetail.getCode$()); info.setDirection(agvDetail.getAgvAngle()); info.setVol(agvDetail.getVol()); info.setEmpty(agvModel.getBackpack() - (taskList == null ? 0 : taskList.size())); info.setError(agvDetail.getError()); info.setLowVol(agvModel.getLowBattery()); info.setAutoCharge(agvModel.getQuaBattery()); List backpackVos = new ArrayList<>(); BackpackVo backpackVo; List taskIds = taskList.stream().map(Task::getId).collect(Collectors.toList()); List backpackDtos = GsonUtils.fromJsonToList(agvDetail.getBackpack(), BackpackDto.class); for (int i = 0; i < agvModel.getBackpack(); i++) { BackpackDto backpackDto = backpackDtos.get(i); backpackVo = new BackpackVo(); List segments = segmentService.getByAgvAndTaskAndBackpack(agvDetail.getAgvId(), taskIds, backpackVo.getIndex()); for (Segment segment : segments) { backpackVo.setTaskId(segment.getTaskId() + ""); } backpackVo.setIndex(i); backpackVo.setLoaded(backpackDto.getLoaded()); backpackVo.setExecute(segments.stream().anyMatch(segment -> segment.getState().equals(SegmentStateType.RUNNING.toString()))); backpackVos.add(backpackVo); } info.setBackpack(backpackVos); result.add(info); } return result; } }