| | |
| | | package com.zy.ai.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.ai.entity.DeviceConfigsData; |
| | | import com.zy.ai.entity.DeviceRealTimeData; |
| | | import com.zy.ai.entity.ChatCompletionRequest; |
| | | import com.zy.ai.entity.WcsDiagnosisRequest; |
| | | import com.zy.ai.entity.WcsDiagnosisResponse; |
| | | import com.zy.ai.log.AiLogAppender; |
| | | import com.zy.ai.service.WcsDiagnosisService; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.zy.ai.utils.AiUtils; |
| | | import com.zy.common.web.BaseController; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.StationObjModel; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.CrnThread; |
| | | import com.zy.core.thread.StationThread; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Autowired |
| | | private WcsDiagnosisService wcsDiagnosisService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | private AiUtils aiUtils; |
| | | |
| | | @GetMapping("/runAi") |
| | | public WcsDiagnosisResponse runAi() { |
| | | WcsDiagnosisRequest request = new WcsDiagnosisRequest(); |
| | | |
| | | request.setAlarmMessage("系统不执行任务"); |
| | | |
| | | List<String> logs = AiLogAppender.getRecentLogs(100); |
| | | request.setLogs(logs); |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>()); |
| | | request.setTasks(wrkMasts); |
| | | |
| | | List<DeviceRealTimeData> deviceRealTimeDataList = new ArrayList<>(); |
| | | List<DeviceConfigsData> deviceConfigsDataList = new ArrayList<>(); |
| | | |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | CrnProtocol protocol = crnThread.getStatus(); |
| | | |
| | | for (StationObjModel stationObjModel : basCrnp.getInStationList$()) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> map = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = map.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | DeviceRealTimeData stationData = new DeviceRealTimeData(); |
| | | stationData.setDeviceNo(stationObjModel.getDeviceNo()); |
| | | stationData.setDeviceType(String.valueOf(SlaveType.Devp)); |
| | | stationData.setDeviceData(stationProtocol); |
| | | deviceRealTimeDataList.add(stationData); |
| | | } |
| | | |
| | | |
| | | DeviceRealTimeData deviceRealTimeData = new DeviceRealTimeData(); |
| | | deviceRealTimeData.setDeviceNo(basCrnp.getCrnNo()); |
| | | deviceRealTimeData.setDeviceType(String.valueOf(SlaveType.Crn)); |
| | | deviceRealTimeData.setDeviceData(protocol); |
| | | deviceRealTimeDataList.add(deviceRealTimeData); |
| | | |
| | | DeviceConfigsData deviceConfigsData = new DeviceConfigsData(); |
| | | deviceConfigsData.setDeviceNo(basCrnp.getCrnNo()); |
| | | deviceConfigsData.setDeviceType(String.valueOf(SlaveType.Crn)); |
| | | deviceConfigsData.setDeviceData(basCrnp); |
| | | deviceConfigsDataList.add(deviceConfigsData); |
| | | } |
| | | |
| | | request.setDeviceRealtimeData(deviceRealTimeDataList); |
| | | request.setDeviceConfigs(deviceConfigsDataList); |
| | | WcsDiagnosisRequest request = aiUtils.makeAiRequest(1000, "系统当前不执行任务,但具体原因不明,请根据以下信息帮助判断。\n\n"); |
| | | WcsDiagnosisResponse response = diagnose(request); |
| | | return response; |
| | | } |
| | |
| | | |
| | | new Thread(() -> { |
| | | try { |
| | | WcsDiagnosisRequest request = new WcsDiagnosisRequest(); |
| | | request.setAlarmMessage("系统不执行任务"); |
| | | |
| | | List<String> logs = AiLogAppender.getRecentLogs(100); |
| | | request.setLogs(logs); |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>()); |
| | | request.setTasks(wrkMasts); |
| | | |
| | | List<DeviceRealTimeData> deviceRealTimeDataList = new ArrayList<>(); |
| | | List<DeviceConfigsData> deviceConfigsDataList = new ArrayList<>(); |
| | | |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | CrnProtocol protocol = crnThread.getStatus(); |
| | | |
| | | for (StationObjModel stationObjModel : basCrnp.getInStationList$()) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> map = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = map.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | DeviceRealTimeData stationData = new DeviceRealTimeData(); |
| | | stationData.setDeviceNo(stationObjModel.getDeviceNo()); |
| | | stationData.setDeviceType(String.valueOf(SlaveType.Devp)); |
| | | stationData.setDeviceData(stationProtocol); |
| | | deviceRealTimeDataList.add(stationData); |
| | | } |
| | | |
| | | |
| | | DeviceRealTimeData deviceRealTimeData = new DeviceRealTimeData(); |
| | | deviceRealTimeData.setDeviceNo(basCrnp.getCrnNo()); |
| | | deviceRealTimeData.setDeviceType(String.valueOf(SlaveType.Crn)); |
| | | deviceRealTimeData.setDeviceData(protocol); |
| | | deviceRealTimeDataList.add(deviceRealTimeData); |
| | | |
| | | DeviceConfigsData deviceConfigsData = new DeviceConfigsData(); |
| | | deviceConfigsData.setDeviceNo(basCrnp.getCrnNo()); |
| | | deviceConfigsData.setDeviceType(String.valueOf(SlaveType.Crn)); |
| | | deviceConfigsData.setDeviceData(basCrnp); |
| | | deviceConfigsDataList.add(deviceConfigsData); |
| | | } |
| | | |
| | | request.setDeviceRealtimeData(deviceRealTimeDataList); |
| | | request.setDeviceConfigs(deviceConfigsDataList); |
| | | |
| | | WcsDiagnosisRequest request = aiUtils.makeAiRequest(1000, "系统当前不执行任务,但具体原因不明,请根据以下信息帮助判断。\n\n"); |
| | | wcsDiagnosisService.diagnoseStream(request, emitter); |
| | | } catch (Exception e) { |
| | | emitter.completeWithError(e); |
| | |
| | | SseEmitter emitter = new SseEmitter(0L); |
| | | new Thread(() -> { |
| | | try { |
| | | WcsDiagnosisRequest request = new WcsDiagnosisRequest(); |
| | | |
| | | List<String> logs = AiLogAppender.getRecentLogs(100); |
| | | request.setLogs(logs); |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>()); |
| | | request.setTasks(wrkMasts); |
| | | |
| | | List<DeviceRealTimeData> deviceRealTimeDataList = new ArrayList<>(); |
| | | List<DeviceConfigsData> deviceConfigsDataList = new ArrayList<>(); |
| | | |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | CrnProtocol protocol = crnThread.getStatus(); |
| | | |
| | | for (StationObjModel stationObjModel : basCrnp.getInStationList$()) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> map = stationThread.getStatusMap(); |
| | | StationProtocol stationProtocol = map.get(stationObjModel.getStationId()); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | DeviceRealTimeData stationData = new DeviceRealTimeData(); |
| | | stationData.setDeviceNo(stationObjModel.getDeviceNo()); |
| | | stationData.setDeviceType(String.valueOf(SlaveType.Devp)); |
| | | stationData.setDeviceData(stationProtocol); |
| | | deviceRealTimeDataList.add(stationData); |
| | | } |
| | | |
| | | DeviceRealTimeData deviceRealTimeData = new DeviceRealTimeData(); |
| | | deviceRealTimeData.setDeviceNo(basCrnp.getCrnNo()); |
| | | deviceRealTimeData.setDeviceType(String.valueOf(SlaveType.Crn)); |
| | | deviceRealTimeData.setDeviceData(protocol); |
| | | deviceRealTimeDataList.add(deviceRealTimeData); |
| | | |
| | | DeviceConfigsData deviceConfigsData = new DeviceConfigsData(); |
| | | deviceConfigsData.setDeviceNo(basCrnp.getCrnNo()); |
| | | deviceConfigsData.setDeviceType(String.valueOf(SlaveType.Crn)); |
| | | deviceConfigsData.setDeviceData(basCrnp); |
| | | deviceConfigsDataList.add(deviceConfigsData); |
| | | } |
| | | |
| | | request.setDeviceRealtimeData(deviceRealTimeDataList); |
| | | request.setDeviceConfigs(deviceConfigsDataList); |
| | | |
| | | WcsDiagnosisRequest request = aiUtils.makeAiRequest(100, null); |
| | | wcsDiagnosisService.askStream(request, prompt, chatId, reset, emitter); |
| | | } catch (Exception e) { |
| | | emitter.completeWithError(e); |