| New file |
| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.model.protocol.StationTaskBufferItem; |
| | | import com.zy.core.thread.StationThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("/openapi/temp") |
| | | public class TempStationBufferCheckController { |
| | | |
| | | @Autowired |
| | | private DeviceConfigService deviceConfigService; |
| | | |
| | | @GetMapping("/stationEmptyAutoBufferCheck") |
| | | public R stationEmptyAutoBufferCheck() { |
| | | List<Map<String, Object>> itemList = new ArrayList<>(); |
| | | |
| | | List<DeviceConfig> stationDeviceList = deviceConfigService.list(new QueryWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Devp))); |
| | | for (DeviceConfig deviceConfig : stationDeviceList) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, deviceConfig.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | List<StationProtocol> statusList = stationThread.getStatus(); |
| | | if (statusList == null || statusList.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | for (StationProtocol stationProtocol : statusList) { |
| | | if (stationProtocol == null || !stationProtocol.isAutoing() || stationProtocol.isLoading()) { |
| | | continue; |
| | | } |
| | | |
| | | List<Map<String, Object>> bufferItemList = buildNonEmptyTaskBufferItemList(stationProtocol.getTaskBufferItems()); |
| | | if (bufferItemList.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | Map<String, Object> item = new LinkedHashMap<>(); |
| | | item.put("deviceNo", deviceConfig.getDeviceNo()); |
| | | item.put("stationId", stationProtocol.getStationId()); |
| | | item.put("taskNo", stationProtocol.getTaskNo()); |
| | | item.put("targetStaNo", stationProtocol.getTargetStaNo()); |
| | | item.put("taskWriteIdx", stationProtocol.getTaskWriteIdx()); |
| | | item.put("systemWarning", stationProtocol.getSystemWarning()); |
| | | item.put("taskBufferItems", bufferItemList); |
| | | itemList.add(item); |
| | | } |
| | | } |
| | | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("scanTime", new Date()); |
| | | result.put("total", itemList.size()); |
| | | result.put("items", itemList); |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | private List<Map<String, Object>> buildNonEmptyTaskBufferItemList(List<StationTaskBufferItem> taskBufferItems) { |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | if (taskBufferItems == null || taskBufferItems.isEmpty()) { |
| | | return result; |
| | | } |
| | | |
| | | for (StationTaskBufferItem taskBufferItem : taskBufferItems) { |
| | | if (!hasTaskBufferValue(taskBufferItem)) { |
| | | continue; |
| | | } |
| | | Map<String, Object> item = new LinkedHashMap<>(); |
| | | item.put("slotIdx", taskBufferItem.getSlotIdx()); |
| | | item.put("taskNo", taskBufferItem.getTaskNo()); |
| | | item.put("targetStaNo", taskBufferItem.getTargetStaNo()); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private boolean hasTaskBufferValue(StationTaskBufferItem taskBufferItem) { |
| | | if (taskBufferItem == null) { |
| | | return false; |
| | | } |
| | | Integer taskNo = taskBufferItem.getTaskNo(); |
| | | if (taskNo != null && taskNo > 0) { |
| | | return true; |
| | | } |
| | | Integer targetStaNo = taskBufferItem.getTargetStaNo(); |
| | | return targetStaNo != null && targetStaNo > 0; |
| | | } |
| | | } |