feat(自主发布逻辑):

This commit is contained in:
fuhao 2024-09-11 14:01:52 +08:00
parent 21a17709ff
commit 9f2fd917ef
No known key found for this signature in database
18 changed files with 134 additions and 110 deletions

View File

@ -18,7 +18,6 @@ public class AlertPlanAndPlanTypeDTO {
private String typeName; private String typeName;
/** /**
* 等级 * 等级
*/ */

View File

@ -1,7 +1,24 @@
package com.ruoyi.board.domain.enums; package com.ruoyi.board.domain.enums;
import com.ruoyi.board.domain.PlanType;
import com.ruoyi.board.service.IPlanTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class AlertPlanType { public class AlertPlanType {
static Map<String, Long> typeNameIDMap = new HashMap<>();
@Autowired
private IPlanTypeService planTypeService;
public static int getPlanTypeByName(String planTypeName) { public static int getPlanTypeByName(String planTypeName) {
// 0:1:2: // 0:1:2:
switch (planTypeName) { switch (planTypeName) {
@ -15,4 +32,17 @@ public class AlertPlanType {
return -1; return -1;
} }
} }
public void setTypeNameIDMap() {
typeNameIDMap.clear();
List<PlanType> planTypeList = planTypeService.list();
typeNameIDMap.putAll(planTypeList.stream()
.collect(Collectors.toMap(
PlanType::getTypeName,
PlanType::getId
)));
}
} }

View File

@ -10,7 +10,9 @@ public interface IAlertPlanService extends MPJBaseService<AlertPlan> {
List<AlertPlanAndPlanTypeDTO> listPage(AlertPlan alertPlan); List<AlertPlanAndPlanTypeDTO> listPage(AlertPlan alertPlan);
AlertPlan getOneByTypeAndValue(Integer type, Double value); AlertPlan getOneByTypeAndValue(Long type, Double value);
AlertPlanAndPlanTypeDTO getDTOById(Long id); AlertPlanAndPlanTypeDTO getDTOById(Long id);
AlertPlan getOneByPresetContentId(Integer id, Integer typeId);
} }

View File

@ -8,7 +8,7 @@ import java.util.List;
public interface IBoardInfoService extends MPJBaseService<BoardInfo> { public interface IBoardInfoService extends MPJBaseService<BoardInfo> {
BoardInfo getOneByIP(String ip); BoardInfoAndRoadDTO getOneByIP(String ip);
List<BoardInfoAndRoadDTO> listBoardInfoDTO(BoardInfo boardInfo); List<BoardInfoAndRoadDTO> listBoardInfoDTO(BoardInfo boardInfo);
} }

View File

@ -8,7 +8,7 @@ import java.util.List;
public interface IPresetContentService extends MPJBaseService<PresetContent> { public interface IPresetContentService extends MPJBaseService<PresetContent> {
PresetContent getOneByContentAndBoardSize(String content, String boardSize, Integer type); PresetContent getOneByContentAndBoardSize(String content, String boardSize, Long type);
List<PresetContentDTO> listDTO(PresetContent presetContent); List<PresetContentDTO> listDTO(PresetContent presetContent);
} }

View File

@ -7,8 +7,5 @@ import com.ruoyi.board.domain.dto.ReleaseRecordAndPresetContentDTO;
import java.util.List; import java.util.List;
public interface IReleaseRecordService extends MPJBaseService<ReleaseRecord> { public interface IReleaseRecordService extends MPJBaseService<ReleaseRecord> {
List<ReleaseRecordAndPresetContentDTO> listLatest2minRecordDtoByBoardId(Integer boardId);
List<ReleaseRecord> listLatest2minRecordByBoardId(Integer boardId); List<ReleaseRecord> listLatest2minRecordByBoardId(Integer boardId);
} }

View File

@ -34,7 +34,7 @@ public class AlertPlanServiceImpl extends MPJBaseServiceImpl<AlertPlanMapper, Al
} }
@Override @Override
public AlertPlan getOneByTypeAndValue(Integer planType, Double value) { public AlertPlan getOneByTypeAndValue(Long planType, Double value) {
if (planType < 0) { if (planType < 0) {
return null; return null;
} }
@ -56,4 +56,12 @@ public class AlertPlanServiceImpl extends MPJBaseServiceImpl<AlertPlanMapper, Al
return selectJoinOne(AlertPlanAndPlanTypeDTO.class, eq); return selectJoinOne(AlertPlanAndPlanTypeDTO.class, eq);
} }
@Override
public AlertPlan getOneByPresetContentId(Integer id, Integer typeId) {
LambdaQueryWrapper<AlertPlan> alertPlanLambdaQueryWrapper = new LambdaQueryWrapper<>();
alertPlanLambdaQueryWrapper.eq(AlertPlan::getPresetContentId, id);
alertPlanLambdaQueryWrapper.eq(AlertPlan::getType, typeId);
return getOne(alertPlanLambdaQueryWrapper);
}
} }

View File

@ -1,6 +1,5 @@
package com.ruoyi.board.service.impl; package com.ruoyi.board.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl; import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ruoyi.board.domain.BoardInfo; import com.ruoyi.board.domain.BoardInfo;
@ -19,15 +18,24 @@ import java.util.List;
public class BoardInfoServiceImpl extends MPJBaseServiceImpl<BoardInfoMapper, BoardInfo> implements IBoardInfoService { public class BoardInfoServiceImpl extends MPJBaseServiceImpl<BoardInfoMapper, BoardInfo> implements IBoardInfoService {
@Override @Override
public BoardInfo getOneByIP(String ip) { public BoardInfoAndRoadDTO getOneByIP(String ip) {
LambdaQueryWrapper<BoardInfo> boardInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); MPJLambdaWrapper<BoardInfo> eq = condition()
boardInfoLambdaQueryWrapper.eq(BoardInfo::getBoardIp, ip); .eq(StringUtils.isNotEmpty(ip), BoardInfo::getBoardIp, ip);
return getOne(boardInfoLambdaQueryWrapper); return selectJoinOne(BoardInfoAndRoadDTO.class, eq);
} }
@Override @Override
public List<BoardInfoAndRoadDTO> listBoardInfoDTO(BoardInfo boardInfo) { public List<BoardInfoAndRoadDTO> listBoardInfoDTO(BoardInfo boardInfo) {
MPJLambdaWrapper<BoardInfo> eq = new MPJLambdaWrapper<BoardInfo>() MPJLambdaWrapper<BoardInfo> eq = condition()
.likeRight(StringUtils.isNotEmpty(boardInfo.getBoardName()), BoardInfo::getBoardName, boardInfo.getBoardName())
.likeRight(StringUtils.isNotEmpty(boardInfo.getBoardMileage()), BoardInfo::getBoardMileage, boardInfo.getBoardMileage())
.eq(StringUtils.isNotEmpty(boardInfo.getBoardRoadSection()), BoardInfo::getBoardRoadSection, boardInfo.getBoardRoadSection());
return selectJoinList(BoardInfoAndRoadDTO.class, eq);
}
private MPJLambdaWrapper<BoardInfo> condition() {
return new MPJLambdaWrapper<BoardInfo>()
.selectAll(BoardInfo.class) .selectAll(BoardInfo.class)
.select(RoadGroup::getRoadName) .select(RoadGroup::getRoadName)
.selectAs(BoardType::getName, "board_size_name") .selectAs(BoardType::getName, "board_size_name")
@ -36,10 +44,6 @@ public class BoardInfoServiceImpl extends MPJBaseServiceImpl<BoardInfoMapper, Bo
.selectAs(BoardProtocol::getProtocol, "board_protocol_name") .selectAs(BoardProtocol::getProtocol, "board_protocol_name")
.leftJoin(RoadGroup.class, RoadGroup::getId, BoardInfo::getBoardRoadSection) .leftJoin(RoadGroup.class, RoadGroup::getId, BoardInfo::getBoardRoadSection)
.leftJoin(BoardType.class, BoardType::getId, BoardInfo::getBoardSizeType) .leftJoin(BoardType.class, BoardType::getId, BoardInfo::getBoardSizeType)
.leftJoin(BoardProtocol.class, BoardProtocol::getId, BoardInfo::getBoardBrandProtocol) .leftJoin(BoardProtocol.class, BoardProtocol::getId, BoardInfo::getBoardBrandProtocol);
.likeRight(StringUtils.isNotEmpty(boardInfo.getBoardName()), BoardInfo::getBoardName, boardInfo.getBoardName())
.likeRight(StringUtils.isNotEmpty(boardInfo.getBoardMileage()), BoardInfo::getBoardMileage, boardInfo.getBoardMileage())
.eq(StringUtils.isNotEmpty(boardInfo.getBoardRoadSection()), BoardInfo::getBoardRoadSection, boardInfo.getBoardRoadSection());
return selectJoinList(BoardInfoAndRoadDTO.class, eq);
} }
} }

View File

@ -16,7 +16,7 @@ import java.util.List;
@Service @Service
public class PresetContentServiceImpl extends MPJBaseServiceImpl<PresetContentMapper, PresetContent> implements IPresetContentService { public class PresetContentServiceImpl extends MPJBaseServiceImpl<PresetContentMapper, PresetContent> implements IPresetContentService {
@Override @Override
public PresetContent getOneByContentAndBoardSize(String content, String boardSize, Integer type) { public PresetContent getOneByContentAndBoardSize(String content, String boardSize, Long type) {
LambdaQueryWrapper<PresetContent> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PresetContent> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper queryWrapper
.eq(PresetContent::getContent, content) .eq(PresetContent::getContent, content)

View File

@ -20,23 +20,9 @@ import java.util.List;
public class ReleaseRecordServiceImpl extends MPJBaseServiceImpl<ReleaseRecordMapper, ReleaseRecord> implements IReleaseRecordService { public class ReleaseRecordServiceImpl extends MPJBaseServiceImpl<ReleaseRecordMapper, ReleaseRecord> implements IReleaseRecordService {
private static final Logger log = LoggerFactory.getLogger(ReleaseRecordServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(ReleaseRecordServiceImpl.class);
@Override
public List<ReleaseRecordAndPresetContentDTO> listLatest2minRecordDtoByBoardId(Integer boardId) {
Date before2min = new Date(System.currentTimeMillis() - 30 * 60 * 1000);
return selectJoinList(ReleaseRecordAndPresetContentDTO.class,
new MPJLambdaWrapper<ReleaseRecord>()
.selectAll(ReleaseRecord.class)
.select(PresetContent::getInfoType)
.leftJoin(PresetContent.class, PresetContent::getId, ReleaseRecord::getPresetContentId)
.eq(ReleaseRecord::getBoardId, boardId)
.gt(ReleaseRecord::getCreateTime, before2min)
.eq(PresetContent::getPresetType, 0)
);
}
@Override @Override
public List<ReleaseRecord> listLatest2minRecordByBoardId(Integer boardId) { public List<ReleaseRecord> listLatest2minRecordByBoardId(Integer boardId) {
Date before2min = new Date(System.currentTimeMillis() - 30 * 60 * 1000); Date before2min = new Date(System.currentTimeMillis() - 2 * 60 * 1000);
LambdaQueryWrapper<ReleaseRecord> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ReleaseRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ReleaseRecord::getBoardId, boardId) queryWrapper.eq(ReleaseRecord::getBoardId, boardId)
.gt(ReleaseRecord::getCreateTime, before2min); .gt(ReleaseRecord::getCreateTime, before2min);

View File

@ -4,7 +4,7 @@ import lombok.Getter;
@Getter @Getter
public enum ProtocolDefault { public enum ProtocolDefault {
SanSi(1, "SanSi", 2929),; SanSi(1, "三思", 2929),;
private final Integer id; private final Integer id;
private final String name; private final String name;
private final Integer port; private final Integer port;

View File

@ -1,8 +1,8 @@
package com.ruoyi.protocol.sansi; package com.ruoyi.protocol.sansi;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.ruoyi.board.domain.BoardInfo;
import com.ruoyi.board.domain.PresetContent; import com.ruoyi.board.domain.PresetContent;
import com.ruoyi.board.domain.dto.BoardInfoAndRoadDTO;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.protocol.enums.ProtocolDefault; import com.ruoyi.protocol.enums.ProtocolDefault;
@ -32,7 +32,7 @@ public class SanSiProtocol implements IProtocolService {
private static final Logger log = LoggerFactory.getLogger(SanSiProtocol.class); private static final Logger log = LoggerFactory.getLogger(SanSiProtocol.class);
Integer deviceId = 0; Integer deviceId = 0;
private String createTextItem(List<PresetContent> presetContentList, BoardInfo boardInfo) { private String createTextItem(List<PresetContent> presetContentList, BoardInfoAndRoadDTO boardInfo) {
Animation animation = new Animation(); Animation animation = new Animation();
animation.setInAnimation(0); animation.setInAnimation(0);
animation.setInAnimationSpeed(200); animation.setInAnimationSpeed(200);
@ -41,8 +41,8 @@ public class SanSiProtocol implements IProtocolService {
int index = 1; int index = 1;
presetContentList.forEach(i -> { presetContentList.forEach(i -> {
TextBase textBase = new TextBase(0, i.getContent()); TextBase textBase = new TextBase(0, i.getContent());
textBase.setFontSize(i.getFontSize()+","+i.getFontSize()); textBase.setFontSize(i.getFontSize() + "," + i.getFontSize());
textBase.setFontName(SanSiFontStyle.getStyleValueByName(i.getFontStyle())); textBase.setFontName(SanSiFontStyle.getStyleValueByName(i.getFontFamily()));
textBase.setWordSpace(i.getLetterSpacing()); textBase.setWordSpace(i.getLetterSpacing());
BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(i.getFontColor()); BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(i.getFontColor());
if (null == fontColour) { if (null == fontColour) {
@ -56,7 +56,6 @@ public class SanSiProtocol implements IProtocolService {
textPlayItem.setY(i.getFontPositionY()); textPlayItem.setY(i.getFontPositionY());
playItemList.add(textPlayItem); playItemList.add(textPlayItem);
}); });
String boardSize = boardInfo.getBoardSize(); String boardSize = boardInfo.getBoardSize();
String[] split = StringUtils.split(boardSize, "*"); String[] split = StringUtils.split(boardSize, "*");
if (split.length < 2) { if (split.length < 2) {
@ -67,12 +66,12 @@ public class SanSiProtocol implements IProtocolService {
int width = Integer.parseInt(split[1]); int width = Integer.parseInt(split[1]);
AreaPositon areaPositon = new AreaPositon(0, 0, height, width, 0); AreaPositon areaPositon = new AreaPositon(0, 0, height, width, 0);
AreaItem areaItem = new AreaItem("1", "areaItem", areaPositon, playItemList); AreaItem areaItem = new AreaItem("2", "areaItem", areaPositon, playItemList);
List<AreaItem> areaItemList = new ArrayList<>(); List<AreaItem> areaItemList = new ArrayList<>();
areaItemList.add(areaItem); areaItemList.add(areaItem);
PageItem pageItem = new PageItem("1", "pageItem", areaItemList); PageItem pageItem = new PageItem("2", "pageItem", areaItemList);
PlayListFcms plf = new PlayListFcms(); PlayListFcms plf = new PlayListFcms();
String path = "./protocolFile/SanSi/" + DateUtils.dateTimeNow(); String path = "./protocolFile/SanSi/" + DateUtils.dateTimeNow();
@ -93,19 +92,16 @@ public class SanSiProtocol implements IProtocolService {
@Override @Override
public boolean protocolSupport(String protocolName) { public boolean protocolSupport(String protocolName) {
return StringUtils.equals(ProtocolDefault.SanSi.getName(), protocolName); return StringUtils.contains(protocolName, ProtocolDefault.SanSi.getName());
} }
@Override @Override
public void loginDevice(BoardInfo boardInfo) { public void loginDevice(BoardInfoAndRoadDTO boardInfo) {
if (deviceId > 10) { if (deviceId > 10) {
deviceId = 0; deviceId = 0;
} }
deviceId++; deviceId++;
if (boardInfo.getBoardPort()<1) { DeviceVar.deviceInforInit(Integer.toString(deviceId), 1, boardInfo.getBoardIp(), ProtocolDefault.SanSi.getPort(), 2048);
boardInfo.setBoardPort(ProtocolDefault.SanSi.getPort());
}
DeviceVar.deviceInforInit(Integer.toString(deviceId), 1, boardInfo.getBoardIp(), boardInfo.getBoardPort(), 2048);
} }
@Override @Override
@ -114,7 +110,7 @@ public class SanSiProtocol implements IProtocolService {
} }
@Override @Override
public void publishContent(BoardInfo boardInfo, List<PresetContent> presetContentList) { public void publishContent(BoardInfoAndRoadDTO boardInfo, List<PresetContent> presetContentList) {
String path = createTextItem(presetContentList, boardInfo); String path = createTextItem(presetContentList, boardInfo);
uploadAndStartPlayList(path); uploadAndStartPlayList(path);
} }

View File

@ -6,7 +6,9 @@ import java.util.stream.Stream;
@Getter @Getter
public enum SanSiFontStyle { public enum SanSiFontStyle {
SongTi("宋体", "s"); SongTi("SimSun", "s"),
HeiTi("SimHei", "h"),
KaiTi("KaiTi", "k");
private final String name; private final String name;
private final String value; private final String value;

View File

@ -1,7 +1,7 @@
package com.ruoyi.protocol.service; package com.ruoyi.protocol.service;
import com.ruoyi.board.domain.BoardInfo;
import com.ruoyi.board.domain.PresetContent; import com.ruoyi.board.domain.PresetContent;
import com.ruoyi.board.domain.dto.BoardInfoAndRoadDTO;
import java.util.List; import java.util.List;
@ -9,13 +9,13 @@ public interface IProtocolService {
boolean protocolSupport(String protocolName); boolean protocolSupport(String protocolName);
void loginDevice(BoardInfo boardInfo); void loginDevice(BoardInfoAndRoadDTO boardInfo);
void logoutDevice(); void logoutDevice();
void publishContent(BoardInfo boardInfo, List<PresetContent> presetContentList); void publishContent(BoardInfoAndRoadDTO boardInfo, List<PresetContent> presetContentList);
default void publishInformation(BoardInfo boardInfo, List<PresetContent> presetContentList){ default void publishInformation(BoardInfoAndRoadDTO boardInfo, List<PresetContent> presetContentList){
// 登录 // 登录
loginDevice(boardInfo); loginDevice(boardInfo);
// 发布 // 发布

View File

@ -1,7 +1,7 @@
package com.ruoyi.protocol.service.impl; package com.ruoyi.protocol.service.impl;
import com.ruoyi.board.domain.BoardInfo;
import com.ruoyi.board.domain.PresetContent; import com.ruoyi.board.domain.PresetContent;
import com.ruoyi.board.domain.dto.BoardInfoAndRoadDTO;
import com.ruoyi.protocol.service.IProtocolService; import com.ruoyi.protocol.service.IProtocolService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,8 +16,8 @@ public class ContentPublishingService {
@Autowired @Autowired
List<IProtocolService> protocolServiceList; List<IProtocolService> protocolServiceList;
public void contentPublish(BoardInfo boardInfo, List<PresetContent> presetContentList) { public void contentPublish(BoardInfoAndRoadDTO boardInfo, List<PresetContent> presetContentList) {
IProtocolService iProtocolService = protocolServiceList.stream().filter(i -> i.protocolSupport(boardInfo.getBoardCommunicationProtocol())).findFirst().orElse(null); IProtocolService iProtocolService = protocolServiceList.stream().filter(i -> i.protocolSupport(boardInfo.getBoardProtocolName())).findFirst().orElse(null);
if (iProtocolService ==null) { if (iProtocolService ==null) {
log.error("协议不支持"); log.error("协议不支持");
return; return;

View File

@ -9,4 +9,6 @@ public interface ISensorDataService {
void putPerceptionParamsToMap(PerceptionParams perceptionParams); void putPerceptionParamsToMap(PerceptionParams perceptionParams);
void handlerPerceptionMap(); void handlerPerceptionMap();
void setPlanTypeNameIdMap();
} }

View File

@ -1,14 +1,8 @@
package com.ruoyi.sensor.service.impl; package com.ruoyi.sensor.service.impl;
import com.ruoyi.board.domain.AlertPlan; import com.ruoyi.board.domain.*;
import com.ruoyi.board.domain.BoardInfo; import com.ruoyi.board.domain.dto.BoardInfoAndRoadDTO;
import com.ruoyi.board.domain.PresetContent; import com.ruoyi.board.service.*;
import com.ruoyi.board.domain.ReleaseRecord;
import com.ruoyi.board.domain.enums.AlertPlanType;
import com.ruoyi.board.service.IAlertPlanService;
import com.ruoyi.board.service.IBoardInfoService;
import com.ruoyi.board.service.IPresetContentService;
import com.ruoyi.board.service.IReleaseRecordService;
import com.ruoyi.protocol.service.impl.ContentPublishingService; import com.ruoyi.protocol.service.impl.ContentPublishingService;
import com.ruoyi.sensor.common.PerceptionHandlerMap; import com.ruoyi.sensor.common.PerceptionHandlerMap;
import com.ruoyi.sensor.domain.PerceptionParams; import com.ruoyi.sensor.domain.PerceptionParams;
@ -19,7 +13,6 @@ import com.ruoyi.sensor.domain.dto.PerceptionHandlerDTO;
import com.ruoyi.sensor.enums.PrintColor; import com.ruoyi.sensor.enums.PrintColor;
import com.ruoyi.sensor.merchants.MerchantsHttp; import com.ruoyi.sensor.merchants.MerchantsHttp;
import com.ruoyi.sensor.service.ISensorDataService; import com.ruoyi.sensor.service.ISensorDataService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -47,11 +40,19 @@ public class SensorDataServiceImpl implements ISensorDataService {
private IReleaseRecordService releaseRecordService; private IReleaseRecordService releaseRecordService;
@Autowired @Autowired
private ContentPublishingService contentPublishingService; private ContentPublishingService contentPublishingService;
@Autowired
private IPlanTypeService planTypeService;
private static final Map<String, Long> planTypeNameIdMap = new HashMap<>();
@Override @Override
@Async @Async
public void perceptionParamsHandler(PerceptionParams params) { public void perceptionParamsHandler(PerceptionParams params) {
int currentContentPlanType = AlertPlanType.getPlanTypeByName(params.getPerceptionType()); long currentContentPlanType = planTypeNameIdMap.getOrDefault(params.getPerceptionType(), (long) -1);
if (currentContentPlanType == -1) {
log.error("没有这个预警的类型");
return;
}
// 找到符合计划的预警 // 找到符合计划的预警
AlertPlan currentAlertPlan = alertPlanService.getOneByTypeAndValue(currentContentPlanType, params.getPerceptionValue()); AlertPlan currentAlertPlan = alertPlanService.getOneByTypeAndValue(currentContentPlanType, params.getPerceptionValue());
if (null == currentAlertPlan) { if (null == currentAlertPlan) {
@ -59,13 +60,13 @@ public class SensorDataServiceImpl implements ISensorDataService {
return; return;
} }
// 情报板设备信息 // 情报板设备信息
BoardInfo boardInfo = boardInfoService.getOneByIP(params.getBoardIp()); BoardInfoAndRoadDTO boardInfo = boardInfoService.getOneByIP(params.getBoardIp());
if (null == boardInfo) { if (null == boardInfo) {
log.error("找不到情报板信息"); log.error("找不到情报板信息");
return; return;
} }
// 预置发布的信息 // 预置发布的信息
PresetContent currentContent = presetContentService.getOneByContentAndBoardSize(currentAlertPlan.getDisplayContent(), boardInfo.getBoardSize(), currentContentPlanType); PresetContent currentContent = presetContentService.getById(currentAlertPlan.getPresetContentId());
if (null == currentContent) { if (null == currentContent) {
log.error("找不到预置发布的信息"); log.error("找不到预置发布的信息");
return; return;
@ -80,7 +81,7 @@ public class SensorDataServiceImpl implements ISensorDataService {
informationToBeReleasedList.add(currentContent); informationToBeReleasedList.add(currentContent);
} else { } else {
// 如果不为空说明 2 分钟内是发布了内容的查询所有的发布内容 // 如果不为空说明 2 分钟内是发布了内容的查询所有的发布内容
List<Integer> presetContentIdList = releaseRecordList.stream().map(ReleaseRecord::getPresetContentId).collect(Collectors.toList()); Set<Integer> presetContentIdList = releaseRecordList.stream().map(ReleaseRecord::getPresetContentId).collect(Collectors.toSet());
List<PresetContent> existPresetContentList = presetContentService.listByIds(presetContentIdList); List<PresetContent> existPresetContentList = presetContentService.listByIds(presetContentIdList);
// 先把已经存在的都加入进去 // 先把已经存在的都加入进去
informationToBeReleasedList.addAll(existPresetContentList); informationToBeReleasedList.addAll(existPresetContentList);
@ -93,36 +94,24 @@ public class SensorDataServiceImpl implements ISensorDataService {
// 说明这是一个已有的类型需要获取预警等级然后进行判断 // 说明这是一个已有的类型需要获取预警等级然后进行判断
// 判断已有类型是否和现在的一样然后再替换掉 // 判断已有类型是否和现在的一样然后再替换掉
// 现在需要知道这个同类型的属于是哪个级别的 // 现在需要知道这个同类型的属于是哪个级别的
int foundPlanId = releaseRecordList.stream() AlertPlan existContentAlertPlan = alertPlanService.getOneByPresetContentId(isExistsPresetContent.getId(), currentAlertPlan.getType());
.filter(i -> Objects.equals(i.getPresetContentId(), isExistsPresetContent.getId())) if (existContentAlertPlan != null) {
.mapToInt(ReleaseRecord::getPlanId) switch (currentAlertPlan.getMinValue().compareTo(existContentAlertPlan.getMinValue())) {
.findFirst().orElse(-1); case 0:
AlertPlan byId = alertPlanService.getById(foundPlanId); presetStatus = "预警持续";
int compare = NumberUtils.compare(byId.getLevel(), break;
currentAlertPlan.getLevel()); case 1:
switch (compare) { presetStatus = "预警加强";
case 0: break;
// 两个一样等级 case -1:
// 这时候就不需要替换也不需要重新发布 presetStatus = "预警减弱";
presetStatus = "预警持续"; break;
break; }
case 1: // 替换同类型的预警信息
// getPresetContentLevel > alertPlan.getLevel() for (int i = 0; i < informationToBeReleasedList.size(); i++) {
// 预警减弱 if (informationToBeReleasedList.get(i).getInfoType() == currentContentPlanType) {
// 此时需要将同类型的信息给替换掉并重新发布 informationToBeReleasedList.set(i, currentContent);
presetStatus = "预警减弱"; }
break;
case -1:
// getPresetContentLevel < alertPlan.getLevel()
// 预警加强
// 此时需要将同类型的信息给替换掉并重新发布
presetStatus = "预警加强";
break;
}
// 替换同类型的预警信息
for (int i = 0; i < existPresetContentList.size(); i++) {
if (existPresetContentList.get(i).getInfoType() == currentContentPlanType) {
existPresetContentList.set(i, currentContent);
} }
} }
} }
@ -133,9 +122,11 @@ public class SensorDataServiceImpl implements ISensorDataService {
// 发布之后记录发布内容 ReleaseRecord // 发布之后记录发布内容 ReleaseRecord
this.saveRecord(boardInfo.getId(), currentContent.getId(), currentAlertPlan.getId()); this.saveRecord(boardInfo.getId(), currentContent.getId(), currentAlertPlan.getId());
// 记录完了之后就需要向对方发送状态日志记录 // 记录完了之后就需要向对方发送状态日志记录
this.sendStatus(presetStatus, boardInfo.getBoardIp(), params.getPerceptionType(), currentContent.getContent(), params.getPerceptionValue(), currentAlertPlan.getLevel()); // this.sendStatus(presetStatus, boardInfo.getBoardIp(), params.getPerceptionType(), currentContent.getContent(), params.getPerceptionValue(), currentAlertPlan.getLevel());
this.sendStatus(presetStatus, boardInfo.getBoardIp(), params.getPerceptionType(), currentContent.getContent(), params.getPerceptionValue(), 1);
// 发送情报板发布信息日志记录 // 发送情报板发布信息日志记录
this.sendPublicLog(boardInfo.getBoardIp(), params.getPerceptionType(), currentAlertPlan.getLevel(), currentContent.getContent(), informationToBeReleasedList); // this.sendPublicLog(boardInfo.getBoardIp(), params.getPerceptionType(), currentAlertPlan.getLevel(), currentContent.getContent(), informationToBeReleasedList);
this.sendPublicLog(boardInfo.getBoardIp(), params.getPerceptionType(), 1, currentContent.getContent(), informationToBeReleasedList);
} }
@Override @Override
@ -149,10 +140,8 @@ public class SensorDataServiceImpl implements ISensorDataService {
PerceptionHandlerMap.perceptionHandlerMap.put(key, orDefault); PerceptionHandlerMap.perceptionHandlerMap.put(key, orDefault);
} }
@Override @Override
public void handlerPerceptionMap(){ public void handlerPerceptionMap() {
List<PerceptionParams> publishList = new ArrayList<>(); List<PerceptionParams> publishList = new ArrayList<>();
List<PerceptionParams> cancelList = new ArrayList<>(); List<PerceptionParams> cancelList = new ArrayList<>();
List<String> delList = new ArrayList<>(); List<String> delList = new ArrayList<>();
@ -163,7 +152,7 @@ public class SensorDataServiceImpl implements ISensorDataService {
// 最后的接收时间大于 1 分钟 // 最后的接收时间大于 1 分钟
if (now - lastUpdateTime > 60 * 1000) { if (now - lastUpdateTime > 60 * 1000) {
delList.add(key); delList.add(key);
if (value.getAllReceiveTimes() > ALL_TIMES_THRESHOLD ) { if (value.getAllReceiveTimes() > ALL_TIMES_THRESHOLD) {
cancelList.add(value.getPerceptionParams()); cancelList.add(value.getPerceptionParams());
} }
} else { } else {
@ -194,9 +183,10 @@ public class SensorDataServiceImpl implements ISensorDataService {
releaseLogReport.setReleaseStatus("发布成功"); releaseLogReport.setReleaseStatus("发布成功");
List<PresetContentStyle> presetContentStyles = new ArrayList<>(); List<PresetContentStyle> presetContentStyles = new ArrayList<>();
informationToBeReleasedList.forEach(i -> { informationToBeReleasedList.forEach(i -> {
String[] split = StringUtils.split(i.getBoardSize(), "*"); // String[] split = StringUtils.split(i.getBoardSize(), "*");
String[] split = null;
PresetContentStyle p = new PresetContentStyle(); PresetContentStyle p = new PresetContentStyle();
p.setFont(i.getFontStyle()); p.setFont(i.getFontFamily());
p.setFontSize(i.getFontSize()); p.setFontSize(i.getFontSize());
p.setFontColor(PrintColor.getBitColor(i.getFontColor())); p.setFontColor(PrintColor.getBitColor(i.getFontColor()));
p.setContent(i.getContent()); p.setContent(i.getContent());
@ -247,4 +237,11 @@ public class SensorDataServiceImpl implements ISensorDataService {
releaseRecord.setCreatedBy(1); releaseRecord.setCreatedBy(1);
releaseRecordService.save(releaseRecord); releaseRecordService.save(releaseRecord);
} }
@Override
public void setPlanTypeNameIdMap() {
planTypeNameIdMap.clear();
Map<String, Long> collect = planTypeService.list().stream().collect(Collectors.toMap(PlanType::getTypeName, PlanType::getId));
planTypeNameIdMap.putAll(collect);
}
} }

View File

@ -15,6 +15,7 @@ public class ClearPerceptionTask {
private static final Logger log = LoggerFactory.getLogger(ClearPerceptionTask.class); private static final Logger log = LoggerFactory.getLogger(ClearPerceptionTask.class);
public void clearPerception(){ public void clearPerception(){
sensorDataService.setPlanTypeNameIdMap();
sensorDataService.handlerPerceptionMap(); sensorDataService.handlerPerceptionMap();
log.info("handlerPerceptionMap 处理完了"); log.info("handlerPerceptionMap 处理完了");
} }