zhoushihao
2025-10-13 83f738105416c9b11e3b7c5246a0980e41b6650e
hangzhoumesParent/moduleService/GlassStorageModule/src/main/java/com/mes/job/RawGlassPushMessage.java
@@ -2,14 +2,21 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.mes.common.config.Const;
import com.mes.order.entity.dto.OrderDTO;
import com.mes.order.service.OrdersService;
import com.mes.rawglassdetails.entity.RawGlassStorageDetails;
import com.mes.rawglassdetails.service.RawGlassStorageDetailsService;
import com.mes.rawglassstation.entity.RawGlassStorageStation;
import com.mes.rawglassstation.service.RawGlassStorageStationService;
import com.mes.rawglasstask.entity.RawGlassStorageTask;
import com.mes.rawglasstask.service.RawGlassStorageTaskService;
import com.mes.tools.WebSocketServer;
import com.mes.tools.WebSocketUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -33,6 +40,12 @@
    @Resource
    private RawGlassStorageDetailsService rawGlassStorageDetailsService;
    @Resource
    private OrdersService ordersService;
    @Resource
    private WebSocketUtils webSocketUtils;
    @Scheduled(fixedDelay = 2000)
    public void sendRawGlassMessage() {
        log.info("发送任务信息和架子信息");
@@ -42,28 +55,24 @@
        List<RawGlassStorageTask> tasks = rawGlassStorageTaskService.listRawGlassTask();
        jsonObject.append("rawStationDetailsList", rawStationDetailsList);
        jsonObject.append("tasks", tasks);
        List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("rawGlass");
        if (CollectionUtil.isNotEmpty(sendwServer)) {
            sendwServer.stream().forEach(e -> {
                e.sendMessage(String.valueOf(jsonObject));
            });
        }
        webSocketUtils.sendToWeb("rawGlass", jsonObject);
    }
    @Scheduled(fixedDelay = 1000)
    public void largenScreen() {
        log.info("发送任务信息和架子信息");
        JSONObject jsonObject = new JSONObject();
        List<RawGlassStorageDetails> rawGlassStorageDetailList = rawGlassStorageDetailsService.list(
                new LambdaUpdateWrapper<RawGlassStorageDetails>()
                        .eq(RawGlassStorageDetails::getState, Const.RAW_GLASS_STATE_IN)
        );
        MPJLambdaWrapper<RawGlassStorageDetails> wrapper = new MPJLambdaWrapper<>();
        wrapper.select(RawGlassStorageStation::getSlot)
                .select("ifnull(remain_quantity, 0) as remain_quantity")
                .rightJoin(RawGlassStorageStation.class, on -> on.eq(RawGlassStorageStation::getSlot, RawGlassStorageDetails::getSlot)
                        .eq(RawGlassStorageDetails::getState, Const.RAW_GLASS_STATE_IN))
                .orderByAsc(RawGlassStorageStation::getSlot);
        List<RawGlassStorageDetails> rawGlassStorageDetailList = rawGlassStorageDetailsService.list(wrapper);
        jsonObject.append("rawGlassStorageDetailList", rawGlassStorageDetailList);
        List<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("largenScreen");
        if (CollectionUtil.isNotEmpty(sendwServer)) {
            sendwServer.stream().forEach(e -> {
                e.sendMessage(String.valueOf(jsonObject));
            });
        }
        List<OrderDTO> orderDTOS = ordersService.selectOrderPercent();
        jsonObject.append("orderDTOS", orderDTOS);
        webSocketUtils.sendToWeb("largenScreen", jsonObject);
    }
}