package com.mes.job; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.mes.md.entity.*; import com.mes.md.mapper.GlassInfoMapper; import com.mes.md.mapper.MachineMapper; import com.mes.md.mapper.TaskingMapper; import com.mes.md.service.*; import com.mes.websocket.WebSocketServer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * 自动打标机 * * @Author : yanzhxiin * @Date: 2024/8/20 11:19 * @Description: */ @Component @Slf4j public class MachineTask { public static String engineerId = ""; @Autowired TaskingMapper taskingMapper; @Autowired MachineMapper machineMapper; @Autowired TaskingService taskingService; @Autowired ProjectService projectService; @Autowired PrimitiveTaskService primitiveTaskService; @Autowired KBBTJPDrawingBPService kBBTJPDrawingBPService; @Autowired LineConfigurationService lineConfigurationService; @Resource WebSocketServer webSocketServer; @Autowired private GlassInfoMapper glassInfoMapper; public List sendRecords = new ArrayList<>(); private List machineListLoad; private List machineListEdging; private List machineListFlipSlice; private List machineListMarking; private List machineListSilkScreen; private List machineListRotate; private List machineListGlueDispenser; private List machineListScanQrCode; private List machineListLamination; //机械手 //@Scheduled(fixedDelay = 500) public void loadTasks() { try { machineListLoad = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "上片")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "loadTask"); for (Machine machine : machineListLoad) { JSONObject jsonObjectItem = new JSONObject(); //标准模式 找已领取未完成的第一条任务 LineConfiguration lineConfiguration = lineConfigurationService.machineLineConfiguration(machine); //此线路已领取的任务 List findPrimitiveTasking = primitiveTaskService.findPrimitiveTasking(machine, lineConfiguration.getLineId()); //此线路未领取的任务 本地 //List findPrimitiveTask=primitiveTaskService.findPrimitiveTaskNotFinish(); //此线路未领取的任务 客户数据库 List list = kBBTJPDrawingBPService.notReceiveKBBTJPDrawingBP(); jsonObjectItem.append("findPrimitiveTask", list); jsonObjectItem.append("findPrimitiveTasking", findPrimitiveTasking); //jsonObject.append("findPrimitiveTask", findPrimitiveTask); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("MarkingTasks:{}", exception.getMessage()); } } //磨边机 //@Scheduled(fixedDelay = 500) public void edgingTasks() { try { machineListEdging = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "磨边")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "edgingTask"); for (Machine machine : machineListEdging) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("edgingTasks:{}", exception.getMessage()); } } //翻片台 //@Scheduled(fixedDelay = 500) public void flipSliceTasks() { try { machineListFlipSlice = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "翻片")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "flipSlice"); for (Machine machine : machineListFlipSlice) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("flipSliceTasks:{}", exception.getMessage()); } } //打标机 //@Scheduled(fixedDelay = 500) public void markingTasks() { try { machineListMarking = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "自动打标机")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "marking"); for (Machine machine : machineListMarking) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("markingTasks:{}", exception.getMessage()); } } //丝印机 //@Scheduled(fixedDelay = 500) public void silkScreenTasks() { try { machineListSilkScreen = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "自动丝印机")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "silkScreenTask"); for (Machine machine : machineListSilkScreen) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("silkScreenTasks:{}", exception.getMessage()); } } //点胶机 //@Scheduled(fixedDelay = 500) public void glueDispenserTasks() { try { machineListGlueDispenser = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "自动点胶机")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "glueDispenser"); for (Machine machine : machineListGlueDispenser) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("glueDispenserTasks:{}", exception.getMessage()); } } //旋转台 //@Scheduled(fixedDelay = 500) public void rotateTasks() { try { machineListRotate = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "旋转台")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "rotate"); for (Machine machine : machineListRotate) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("rotateTasks:{}", exception.getMessage()); } } //贴膜机 //@Scheduled(fixedDelay = 500) public void laminationTasks() { try { machineListLamination = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "自动贴膜机")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "lamination"); for (Machine machine : machineListLamination) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingService.findMachineTask(machine); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObjectItem.append("sendRecords", sendRecords); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("laminationTasks:{}", exception.getMessage()); } } //报工页面查询 //@Scheduled(fixedDelay = 1000) public void manualReporting() { try { machineListScanQrCode = machineMapper.selectList(new QueryWrapper().lambda().eq(Machine::getName, "识别报工")); JSONObject jsonObject = new JSONObject(); jsonObject.append("sessionMapName", "manualReporting"); for (Machine machine : machineListScanQrCode) { JSONObject jsonObjectItem = new JSONObject(); List taskingList = taskingMapper.selectJoinList(Tasking.class, new MPJLambdaWrapper() .selectAll(Tasking.class) .innerJoin(LineConfiguration.class, LineConfiguration::getId, Tasking::getLineConfigurationId) .innerJoin(Machine.class, Machine::getId, LineConfiguration::getMachineId) .eq(LineConfiguration::getMachineId, machine.getId()) .eq(Tasking::getGlassState, "正常") .eq(Tasking::getState, "线上") .ne(Tasking::getWorkState, "完工") .orderByDesc(Tasking::getOperationRecordTime)); jsonObjectItem.append("taskingList", taskingList); jsonObjectItem.append("machine", machine); jsonObject.append(machine.getId().toString(), jsonObjectItem); } this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("manualReporting:{}", exception.getMessage()); } } //线下玻璃查询 //@Scheduled(fixedDelay = 1000) public void downLineTask() { try { JSONObject jsonObject = new JSONObject(); List downLineTask = taskingService.findDownLineTask(); jsonObject.append("sessionMapName", "downLineTask"); jsonObject.append("downLineTask", downLineTask); this.webSocketServer(jsonObject); } catch (Exception exception) { log.info("downLineTask:{}", exception.getMessage()); } } public void webSocketServer(JSONObject jsonObject) { try { log.info("发送数据:{}", jsonObject.getJSONArray("sessionMapName").get(0).toString()); String sessionMapName = jsonObject.getJSONArray("sessionMapName").get(0).toString(); webSocketServer.sendToWeb(sessionMapName, jsonObject.toString()); } catch (Exception ex) { log.info("{}发送数据失败:{}", "rawGlassStorage", ex.getMessage()); } } // public void webSocketServer(JSONObject jsonObject) { // try { // String sessionMapName=jsonObject.getJSONArray("sessionMapName").get(0).toString(); // ArrayList sendwServer = WebSocketServer.sessionMap.get(sessionMapName); // if (sendwServer != null) { // for (WebSocketServer webserver : sendwServer) { // try { // webserver.sendMessage(jsonObject.toString()); // List messages = webserver.getMessages(); // if (!messages.isEmpty()) { // // // 将最后一个消息转换为整数类型的列表 // webserver.clearMessages(); // } // }catch (Exception e) { // if (webserver != null) { // // } else { // log.info("Home is closed"); // } // } // // } // } // }catch (Exception e) { // // } // // } }