package com.zy.acs.manager.core.integrate.conveyor; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.acs.framework.common.Cools; import com.zy.acs.framework.common.R; import com.zy.acs.manager.common.annotation.IntegrationAuth; import com.zy.acs.manager.core.domain.TaskPosDto; import com.zy.acs.manager.core.domain.type.NamespaceType; import com.zy.acs.manager.core.integrate.dto.ConveyorQueryParam; import com.zy.acs.manager.core.integrate.dto.ConveyorQueryResult; import com.zy.acs.manager.manager.entity.Segment; import com.zy.acs.manager.manager.entity.Sta; import com.zy.acs.manager.manager.entity.Task; import com.zy.acs.manager.manager.enums.SegmentStateType; import com.zy.acs.manager.manager.enums.StatusType; import com.zy.acs.manager.manager.service.SegmentService; import com.zy.acs.manager.manager.service.StaService; import com.zy.acs.manager.manager.service.TaskService; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; @Api(tags = "Open Api") @RestController @RequestMapping("/api/open") public class ConveyorController { @Autowired private StaService staService; @Autowired private TaskService taskService; @Autowired private SegmentService segmentService; @PostMapping("/station/convey") @IntegrationAuth(name = NamespaceType.RCS_STA_QUERY) public R save(@RequestBody ConveyorQueryParam param) { List resultList = new ArrayList<>(); List staNos = param.getStaNos(); if (Cools.isEmpty(staNos)) { List list = staService.list(new LambdaQueryWrapper() .eq(Sta::getStatus, StatusType.ENABLE.val) .orderByAsc(Sta::getStaNo) ); for (Sta sta : list) { Long staId = sta.getId(); boolean conveyable = !staService.hasWorkingAgv(staId); String taskNo = null; if (conveyable) { Task task = staService.checkoutTask(staId); if (null != task) { taskNo = task.getSeqNum(); } } resultList.add(new ConveyorQueryResult(sta.getStaNo(), conveyable, taskNo)); } } else { for (String staNo : staNos) { Sta sta = staService.selectByStaNo(staNo); if (null == sta || !sta.getStatus().equals(StatusType.ENABLE.val)) { resultList.add(new ConveyorQueryResult(staNo, Boolean.FALSE)); continue; } Long staId = sta.getId(); boolean conveyable = !staService.hasWorkingAgv(staId); String taskNo = null; if (conveyable) { Task task = staService.checkoutTask(staId); if (null != task) { taskNo = task.getSeqNum(); } } resultList.add(new ConveyorQueryResult(staNo, conveyable, taskNo)); } } return R.ok().add(resultList); } @PostMapping("/station/checkTakeComplete") @IntegrationAuth(name = NamespaceType.RCS_STA_QUERY) public R checkTakeComplete(@RequestBody ConveyorQueryParam param) { String seqNum = param.getSeqNum(); Task task = taskService.selectBySeqNum(null, seqNum); if (null == task) { return R.error("task not found"); } List list = segmentService.list(new LambdaQueryWrapper().eq(Segment::getTaskId, task.getId()).eq(Segment::getPosType, TaskPosDto.PosType.ORI_STA.toString())); for (Segment segment : list){ if (segment.getState().equals(SegmentStateType.FINISH.toString())){ return R.ok().add(true); } } return R.ok().add(false); } }