package com.zy.acs.manager.core.scheduler; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.acs.common.utils.GsonUtils; import com.zy.acs.manager.core.domain.MapWsAgvVo; import com.zy.acs.manager.core.domain.MapWsVo; import com.zy.acs.manager.manager.entity.Agv; import com.zy.acs.manager.manager.entity.AgvDetail; import com.zy.acs.manager.manager.entity.Code; import com.zy.acs.manager.manager.service.AgvDetailService; import com.zy.acs.manager.manager.service.AgvService; import com.zy.acs.manager.manager.service.CodeService; import com.zy.acs.manager.manager.websocket.MapWebSocket; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; /** * Created by vincent on 10/14/2024 */ @Component public class MapDataWsScheduler { @Autowired private AgvService agvService; @Autowired private AgvDetailService agvDetailService; @Autowired private CodeService codeService; @Scheduled(cron = "0/1 * * * * ? ") public void broadcast() { MapWsVo mapWsVo = new MapWsVo(); mapWsVo.setAgvVos(syncAgv()); MapWebSocket.broadcast(GsonUtils.toJson(mapWsVo)); } private List syncAgv() { List agvVos = new ArrayList<>(); List agvList = agvService.list(new LambdaQueryWrapper().eq(Agv::getStatus, 1)); for (Agv agv : agvList) { AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); if (null == agvDetail) { continue; } Long recentCode = agvDetail.getRecentCode(); if (null == recentCode) { continue; } Code code = codeService.getById(recentCode); MapWsAgvVo vo = new MapWsAgvVo(); vo.setAgvNo(agv.getUuid()); vo.setCode(code.getData()); vo.setDirection(agvDetail.getAgvAngle()); vo.setBackpack(agvDetail.getTempQua()); vo.setBattery(vo.getBattery()); agvVos.add(vo); } return agvVos; } }