feat(各种业务开发):
This commit is contained in:
parent
cb78214dd6
commit
2a4525c2d7
|
@ -71,6 +71,7 @@
|
|||
<version>2.5.15</version>
|
||||
<configuration>
|
||||
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
|
@ -12,21 +13,12 @@ import org.springframework.cache.annotation.EnableCaching;
|
|||
*/
|
||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||
@EnableCaching
|
||||
@EnableAsync
|
||||
public class RuoYiApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||
SpringApplication.run(RuoYiApplication.class, args);
|
||||
// System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
// " .-------. ____ __ \n" +
|
||||
// " | _ _ \\ \\ \\ / / \n" +
|
||||
// " | ( ' ) | \\ _. / ' \n" +
|
||||
// " |(_ o _) / _( )_ .' \n" +
|
||||
// " | (_,_).' __ ___(_ o _)' \n" +
|
||||
// " | |\\ \\ | || |(_,_)' \n" +
|
||||
// " | | \\ `' /| `-' / \n" +
|
||||
// " | | \\ / \\ / \n" +
|
||||
// " ''-' `'-' `-..-' ");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.web.controller.board;
|
||||
|
||||
import com.ruoyi.board.domain.AlertPlan;
|
||||
import com.ruoyi.board.domain.dto.AlertPlanAndPlanTypeDTO;
|
||||
import com.ruoyi.board.service.IAlertPlanService;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
|
@ -34,7 +35,7 @@ public class AlertPlanController extends BaseController {
|
|||
@GetMapping("/list")
|
||||
public TableDataInfo list(AlertPlan alertPlan) {
|
||||
startPage();
|
||||
List<AlertPlan> list = alertPlanService.selectList(alertPlan);
|
||||
List<AlertPlanAndPlanTypeDTO> list = alertPlanService.listPage(alertPlan);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
@ -56,7 +57,7 @@ public class AlertPlanController extends BaseController {
|
|||
@PreAuthorize("@ss.hasPermi('alert:plan:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return success(alertPlanService.getById(id));
|
||||
return success(alertPlanService.getDTOById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,9 +33,9 @@ public class BoardInfoController extends BaseController {
|
|||
*/
|
||||
@PreAuthorize("@ss.hasPermi('board:info:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(BoardInfo BoardInfo) {
|
||||
public TableDataInfo list(BoardInfo boardInfo) {
|
||||
startPage();
|
||||
List<BoardInfo> list = boardInfoService.list();
|
||||
List<BoardInfo> list = boardInfoService.listPage(boardInfo);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class PresetContentController extends BaseController
|
|||
public TableDataInfo list(PresetContent presetContent)
|
||||
{
|
||||
startPage();
|
||||
List<PresetContent> list = presetContentService.list();
|
||||
List<PresetContent> list = presetContentService.listPage(presetContent);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,64 @@
|
|||
package com.ruoyi.web.controller.sensor;
|
||||
|
||||
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.sm4.SM4Utils;
|
||||
import com.ruoyi.sensor.domain.PerceptionParams;
|
||||
import com.ruoyi.sensor.service.ISensorDataService;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sensor/data")
|
||||
public class OpenSensorDataController {
|
||||
|
||||
private static final String SIGN_HEADER_NAME = "sign";
|
||||
private static final String SIGN_KEY_BASE64 = "RkYnZj5lcChmMSZQQHJFUg==";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OpenSensorDataController.class);
|
||||
|
||||
@Autowired
|
||||
private ISensorDataService sensorDataService;
|
||||
|
||||
@Value("${remote.sign}")
|
||||
private boolean signSwitch;
|
||||
|
||||
|
||||
@Anonymous
|
||||
@PostMapping("/judge")
|
||||
public void list(PerceptionParams perceptionParams) {
|
||||
sensorDataService.perceptionParamsHandler(perceptionParams);
|
||||
public AjaxResult list(HttpServletRequest request, @RequestBody PerceptionParams perceptionParams) {
|
||||
if (signSwitch) {
|
||||
if (!verifyRequest(request, perceptionParams.getStr())) {
|
||||
return AjaxResult.error("sign in error");
|
||||
}
|
||||
}
|
||||
sensorDataService.putPerceptionParamsToMap(perceptionParams);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
private boolean verifyRequest(HttpServletRequest request, String str) {
|
||||
byte[] keyByte = Base64.decodeBase64(SIGN_KEY_BASE64);
|
||||
String sign = request.getHeader(SIGN_HEADER_NAME);
|
||||
if (StringUtils.isEmpty(sign)) {
|
||||
log.error("Header 中没有 sign");
|
||||
return false;
|
||||
}
|
||||
// 验证是否正确
|
||||
try {
|
||||
byte[] bytes = SM4Utils.encryptData_ECB(str, keyByte);
|
||||
String base64String = Base64.encodeBase64String(bytes);
|
||||
log.info("sign:{}, base64String:{}", sign, base64String);
|
||||
return sign.equals(base64String);
|
||||
} catch (Exception e) {
|
||||
log.error("{}", e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ spring:
|
|||
druid:
|
||||
# 主库数据源
|
||||
master:
|
||||
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://192.168.2.137:33306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# url: jdbc:mysql://mdb:3306/ry_vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://192.168.2.137:33306/ry_vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: 1qaz@WSX
|
||||
# 从库数据源
|
||||
|
|
|
@ -107,15 +107,6 @@ token:
|
|||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
|
||||
## MyBatis配置
|
||||
#mybatis:
|
||||
# # 搜索指定包别名
|
||||
# typeAliasesPackage: com.ruoyi.**.domain
|
||||
# # 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
# mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||
# # 加载全局的配置文件
|
||||
# configLocation: classpath:mybatis/mybatis-config.xml
|
||||
|
||||
# MyBatis Plus配置
|
||||
mybatis-plus:
|
||||
# 搜索指定包别名
|
||||
|
@ -146,3 +137,11 @@ xss:
|
|||
excludes: /system/notice
|
||||
# 匹配链接
|
||||
urlPatterns: /system/*,/monitor/*,/tool/*
|
||||
|
||||
remote:
|
||||
# 签名验证开关
|
||||
sign: false
|
||||
# 状态上报地址
|
||||
statusReport: "http://192.166.1.246:8080/status"
|
||||
# 发布记录上报地址
|
||||
logReport: "http://192.166.1.246:8080/publish_log"
|
|
@ -42,4 +42,10 @@ public class ReleaseRecord {
|
|||
*/
|
||||
@TableField(value = "created_by")
|
||||
private Integer createdBy;
|
||||
|
||||
/**
|
||||
* 预警计划级别
|
||||
*/
|
||||
@TableField(value = "plan_id")
|
||||
private Integer planId;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.ruoyi.board.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class AlertPlanAndPlanTypeDTO {
|
||||
/**
|
||||
* 主键自增
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
private String typeName;
|
||||
|
||||
|
||||
/**
|
||||
* 等级
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 最大值
|
||||
*/
|
||||
private BigDecimal maxValue;
|
||||
|
||||
/**
|
||||
* 最小值
|
||||
*/
|
||||
private BigDecimal minValue;
|
||||
|
||||
/**
|
||||
* 显示内容
|
||||
*/
|
||||
private String displayContent;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.ruoyi.board.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ReleaseRecordAndPresetContentDTO {
|
||||
|
||||
/**
|
||||
* 主键自增
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 情报板ID
|
||||
*/
|
||||
private Integer boardId;
|
||||
|
||||
/**
|
||||
* 预置信息ID
|
||||
*/
|
||||
private Integer presetContentId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 信息类型
|
||||
*/
|
||||
private Integer infoType;
|
||||
|
||||
/**
|
||||
* 预警计划级别
|
||||
*/
|
||||
private Integer presetContentLevel;
|
||||
}
|
|
@ -2,12 +2,15 @@ package com.ruoyi.board.service;
|
|||
|
||||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.ruoyi.board.domain.AlertPlan;
|
||||
import com.ruoyi.board.domain.dto.AlertPlanAndPlanTypeDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IAlertPlanService extends MPJBaseService<AlertPlan> {
|
||||
|
||||
List<AlertPlan> selectList(AlertPlan alertPlan);
|
||||
List<AlertPlanAndPlanTypeDTO> listPage(AlertPlan alertPlan);
|
||||
|
||||
AlertPlan getOneByTypeAndValue(Integer type, Double value);
|
||||
|
||||
AlertPlanAndPlanTypeDTO getDTOById(Long id);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,11 @@ package com.ruoyi.board.service;
|
|||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.ruoyi.board.domain.BoardInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IBoardInfoService extends MPJBaseService<BoardInfo> {
|
||||
|
||||
BoardInfo getOneByIP(String ip);
|
||||
|
||||
List<BoardInfo> listPage(BoardInfo boardInfo);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,11 @@ package com.ruoyi.board.service;
|
|||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IPresetContentService extends MPJBaseService<PresetContent> {
|
||||
|
||||
PresetContent getOneByContentAndBoardSize(String content, String boardSize, Integer type);
|
||||
|
||||
List<PresetContent> listPage(PresetContent presetContent);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@ package com.ruoyi.board.service;
|
|||
|
||||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.ruoyi.board.domain.ReleaseRecord;
|
||||
import com.ruoyi.board.domain.dto.ReleaseRecordAndPresetContentDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IReleaseRecordService extends MPJBaseService<ReleaseRecord> {
|
||||
|
||||
ReleaseRecord getOneLatestByBoardId(String boardId, Integer type);
|
||||
List<ReleaseRecordAndPresetContentDTO> listLatest2minRecordDtoByBoardId(Integer boardId);
|
||||
|
||||
List<ReleaseRecord> listLatest2minRecordByBoardId(Integer boardId);
|
||||
}
|
||||
|
|
|
@ -2,23 +2,32 @@ package com.ruoyi.board.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.ruoyi.board.domain.AlertPlan;
|
||||
import com.ruoyi.board.domain.PlanType;
|
||||
import com.ruoyi.board.domain.dto.AlertPlanAndPlanTypeDTO;
|
||||
import com.ruoyi.board.mapper.AlertPlanMapper;
|
||||
import com.ruoyi.board.service.IAlertPlanService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AlertPlanServiceImpl extends MPJBaseServiceImpl<AlertPlanMapper, AlertPlan> implements IAlertPlanService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AlertPlanServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public List<AlertPlan> selectList(AlertPlan alertPlan) {
|
||||
LambdaQueryWrapper<AlertPlan> alertPlanLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
alertPlanLambdaQueryWrapper.eq(ObjectUtils.isNotEmpty(alertPlan.getType()), AlertPlan::getType, alertPlan.getType());
|
||||
alertPlanLambdaQueryWrapper.eq(ObjectUtils.isNotEmpty(alertPlan.getLevel()), AlertPlan::getLevel, alertPlan.getLevel());
|
||||
return list(alertPlanLambdaQueryWrapper);
|
||||
public List<AlertPlanAndPlanTypeDTO> listPage(AlertPlan alertPlan) {
|
||||
MPJLambdaWrapper<AlertPlan> eq = new MPJLambdaWrapper<AlertPlan>()
|
||||
.selectAll(AlertPlan.class)
|
||||
.select(PlanType::getTypeName)
|
||||
.leftJoin(PlanType.class, PlanType::getId, AlertPlan::getType)
|
||||
.eq(ObjectUtils.isNotEmpty(alertPlan.getType()), AlertPlan::getType, alertPlan.getType());
|
||||
return selectJoinList(AlertPlanAndPlanTypeDTO.class, eq);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,4 +42,15 @@ public class AlertPlanServiceImpl extends MPJBaseServiceImpl<AlertPlanMapper, Al
|
|||
.ge(AlertPlan::getMaxValue, value);
|
||||
return getOne(alertPlanLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertPlanAndPlanTypeDTO getDTOById(Long id) {
|
||||
MPJLambdaWrapper<AlertPlan> eq = new MPJLambdaWrapper<AlertPlan>()
|
||||
.selectAll(AlertPlan.class)
|
||||
.select(PlanType::getTypeName)
|
||||
.leftJoin(PlanType.class, PlanType::getId, AlertPlan::getType)
|
||||
.eq(AlertPlan::getId, id);
|
||||
return selectJoinOne(AlertPlanAndPlanTypeDTO.class, eq);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,14 @@ package com.ruoyi.board.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.board.mapper.BoardInfoMapper;
|
||||
import com.ruoyi.board.domain.BoardInfo;
|
||||
import com.ruoyi.board.service.IBoardInfoService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BoardInfoServiceImpl extends MPJBaseServiceImpl<BoardInfoMapper, BoardInfo> implements IBoardInfoService {
|
||||
|
||||
|
@ -16,4 +19,16 @@ public class BoardInfoServiceImpl extends MPJBaseServiceImpl<BoardInfoMapper, Bo
|
|||
boardInfoLambdaQueryWrapper.eq(BoardInfo::getBoardIp, ip);
|
||||
return getOne(boardInfoLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BoardInfo> listPage(BoardInfo boardInfo) {
|
||||
LambdaQueryWrapper<BoardInfo> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.likeRight(StringUtils.isNotEmpty(boardInfo.getBoardName()), BoardInfo::getBoardName, boardInfo.getBoardName());
|
||||
wrapper.likeRight(StringUtils.isNotEmpty(boardInfo.getBoardMileage()), BoardInfo::getBoardMileage, boardInfo.getBoardMileage());
|
||||
wrapper.eq(StringUtils.isNotEmpty(boardInfo.getBoardSize()), BoardInfo::getBoardSize, boardInfo.getBoardSize());
|
||||
wrapper.eq(StringUtils.isNotEmpty(boardInfo.getBoardBrand()), BoardInfo::getBoardBrand, boardInfo.getBoardBrand());
|
||||
wrapper.eq(StringUtils.isNotEmpty(boardInfo.getBoardCommunicationProtocol()), BoardInfo::getBoardCommunicationProtocol, boardInfo.getBoardCommunicationProtocol());
|
||||
wrapper.eq(StringUtils.isNotEmpty(boardInfo.getBoardRoadSection()), BoardInfo::getBoardRoadSection, boardInfo.getBoardRoadSection());
|
||||
return list(wrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,15 @@ package com.ruoyi.board.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.board.mapper.PresetContentMapper;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
import com.ruoyi.board.service.IPresetContentService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PresetContentServiceImpl extends MPJBaseServiceImpl<PresetContentMapper, PresetContent> implements IPresetContentService {
|
||||
@Override
|
||||
|
@ -18,4 +22,13 @@ public class PresetContentServiceImpl extends MPJBaseServiceImpl<PresetContentMa
|
|||
.eq(PresetContent::getInfoType, type);
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PresetContent> listPage(PresetContent presetContent) {
|
||||
LambdaQueryWrapper<PresetContent> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.likeRight(StringUtils.isNotEmpty(presetContent.getName()), PresetContent::getName, presetContent.getName());
|
||||
queryWrapper.eq(StringUtils.isNotEmpty(presetContent.getBoardSize()), PresetContent::getBoardSize, presetContent.getBoardSize());
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(presetContent.getInfoType()), PresetContent::getInfoType, presetContent.getInfoType());
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,36 +4,42 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.github.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
import com.ruoyi.board.domain.ReleaseRecordDto;
|
||||
import lombok.Data;
|
||||
import com.ruoyi.board.domain.dto.ReleaseRecordAndPresetContentDTO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.ruoyi.board.domain.ReleaseRecord;
|
||||
import com.ruoyi.board.mapper.ReleaseRecordMapper;
|
||||
import com.ruoyi.board.service.IReleaseRecordService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ReleaseRecordServiceImpl extends MPJBaseServiceImpl<ReleaseRecordMapper, ReleaseRecord> implements IReleaseRecordService {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReleaseRecordServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public ReleaseRecord getOneLatestByBoardId(String boardId, Integer type) {
|
||||
// LambdaQueryWrapper<ReleaseRecord> releaseRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// releaseRecordLambdaQueryWrapper
|
||||
// .eq(ReleaseRecord::getBoardId, boardId)
|
||||
// .orderByDesc(ReleaseRecord::getCreateTime)
|
||||
// .last("LIMIT 1");
|
||||
|
||||
ReleaseRecordDto releaseRecord = selectJoinOne(ReleaseRecordDto.class,
|
||||
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)
|
||||
.eq(PresetContent::getInfoType, type)
|
||||
.orderByDesc(ReleaseRecord::getCreateTime)
|
||||
.last("LIMIT 1")
|
||||
.gt(ReleaseRecord::getCreateTime, before2min)
|
||||
.eq(PresetContent::getPresetType, 0)
|
||||
);
|
||||
System.out.println(releaseRecord);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReleaseRecord> listLatest2minRecordByBoardId(Integer boardId) {
|
||||
Date before2min = new Date(System.currentTimeMillis() - 30 * 60 * 1000);
|
||||
LambdaQueryWrapper<ReleaseRecord> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ReleaseRecord::getBoardId, boardId)
|
||||
.gt(ReleaseRecord::getCreateTime, before2min);
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.ruoyi.protocol.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ProtocolDefault {
|
||||
SanSi(1, "SanSi", 2929),;
|
||||
private final Integer id;
|
||||
private final String name;
|
||||
private final Integer port;
|
||||
|
||||
ProtocolDefault(Integer id, String name, Integer port) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.port = port;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,18 @@
|
|||
package com.ruoyi.protocol.sansi;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.board.domain.BoardInfo;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
import com.ruoyi.protocol.enums.ProtocolDefault;
|
||||
import com.ruoyi.protocol.sansi.enums.SanSiFontColor;
|
||||
import com.ruoyi.protocol.sansi.enums.SanSiFontStyle;
|
||||
import com.ruoyi.protocol.service.IProtocolService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import zhishuang.wang.sansi.fcms.devinfor.DeviceControl;
|
||||
import zhishuang.wang.sansi.fcms.devinfor.DeviceVar;
|
||||
import zhishuang.wang.sansi.playlist.AreaItem;
|
||||
|
@ -17,38 +23,39 @@ import zhishuang.wang.sansi.playlist.fcms.PlayListFcms;
|
|||
import zhishuang.wang.sansi.tools.ReturnData;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SanSiProtocol {
|
||||
@Service
|
||||
public class SanSiProtocol implements IProtocolService {
|
||||
private static final Logger log = LoggerFactory.getLogger(SanSiProtocol.class);
|
||||
Integer deviceId = 0;
|
||||
|
||||
String deviceId = "1";
|
||||
|
||||
public String createTextItem(PresetContent presetContent, BoardInfo boardInfo) {
|
||||
private String createTextItem(List<PresetContent> presetContentList, BoardInfo boardInfo) {
|
||||
Animation animation = new Animation();
|
||||
animation.setInAnimation(0);
|
||||
animation.setInAnimationSpeed(200);
|
||||
|
||||
TextBase textBase = new TextBase(0, presetContent.getContent());
|
||||
textBase.setFontSize(presetContent.getFontSize()+","+presetContent.getFontSize());
|
||||
textBase.setFontName(presetContent.getFontStyle());
|
||||
textBase.setWordSpace(presetContent.getLetterSpacing());
|
||||
BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(presetContent.getFontColor());
|
||||
if (null == fontColour) {
|
||||
log.error("BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(presetContent.getFontColor()); 没有匹配到相应的字体颜色");
|
||||
return null;
|
||||
}
|
||||
textBase.setFontColour(fontColour);
|
||||
|
||||
PlayTimeBase textPlayTime = new PlayTimeBase(presetContent.getPlayTime());
|
||||
PlayItem textPlayItem = new PlayItem(1, "1", "test", textBase, textPlayTime);
|
||||
textPlayItem.setAnimation(animation);
|
||||
textPlayItem.setX(presetContent.getFontPositionX());
|
||||
textPlayItem.setY(presetContent.getFontPositionY());
|
||||
|
||||
List<PlayItem> playItemList = new ArrayList<>();
|
||||
playItemList.add(textPlayItem);
|
||||
|
||||
int index = 1;
|
||||
presetContentList.forEach(i -> {
|
||||
TextBase textBase = new TextBase(0, i.getContent());
|
||||
textBase.setFontSize(i.getFontSize()+","+i.getFontSize());
|
||||
textBase.setFontName(SanSiFontStyle.getStyleValueByName(i.getFontStyle()));
|
||||
textBase.setWordSpace(i.getLetterSpacing());
|
||||
BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(i.getFontColor());
|
||||
if (null == fontColour) {
|
||||
log.error("BaseColour fontColour = SanSiFontColor.getBaseColourByColorName(presetContent.getFontColor()); 没有匹配到相应的字体颜色");
|
||||
}
|
||||
textBase.setFontColour(fontColour);
|
||||
PlayTimeBase textPlayTime = new PlayTimeBase(i.getPlayTime() * 10);
|
||||
PlayItem textPlayItem = new PlayItem(index, Integer.toString(index), "test" + index, textBase, textPlayTime);
|
||||
textPlayItem.setAnimation(animation);
|
||||
textPlayItem.setX(i.getFontPositionX());
|
||||
textPlayItem.setY(i.getFontPositionY());
|
||||
playItemList.add(textPlayItem);
|
||||
});
|
||||
|
||||
String boardSize = boardInfo.getBoardSize();
|
||||
String[] split = StringUtils.split(boardSize, "*");
|
||||
|
@ -68,45 +75,58 @@ public class SanSiProtocol {
|
|||
PageItem pageItem = new PageItem("1", "pageItem", areaItemList);
|
||||
PlayListFcms plf = new PlayListFcms();
|
||||
|
||||
String path = "./sansi/" + UUID.fastUUID() + "/play.lst";
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
String path = "./protocolFile/SanSi/" + DateUtils.dateTimeNow();
|
||||
String file = path + "/play.lst";
|
||||
try {
|
||||
FileUtils.forceMkdir(new File(path));
|
||||
} catch (IOException e) {
|
||||
log.error("创建文件夹失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
ReturnData rd = plf.createFcmsPlayList(path, pageItem);
|
||||
System.out.println("====" + rd.getCode());
|
||||
System.out.println("====" + rd.getMessage());
|
||||
ReturnData rd = plf.createFcmsPlayList(file, pageItem);
|
||||
if (rd.getCode() != 0) {
|
||||
log.error("生成三思的上传文件出错了");
|
||||
return null;
|
||||
}
|
||||
return path;
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
private void loginDevice(BoardInfo boardInfo) {
|
||||
DeviceVar.deviceInforInit(deviceId, 1, boardInfo.getBoardIp(), boardInfo.getBoardPort(), 2048);
|
||||
@Override
|
||||
public boolean protocolSupport(String protocolName) {
|
||||
return StringUtils.equals(ProtocolDefault.SanSi.getName(), protocolName);
|
||||
}
|
||||
|
||||
private boolean uploadAndStartPlayList(String path) {
|
||||
ReturnData uploadPlayListRD = DeviceControl.fcmsUploadPlayList(deviceId, path);//上传播放表
|
||||
if (uploadPlayListRD.getCode() != 0) {
|
||||
log.error("上传错误");
|
||||
return false;
|
||||
@Override
|
||||
public void loginDevice(BoardInfo boardInfo) {
|
||||
if (deviceId > 10) {
|
||||
deviceId = 0;
|
||||
}
|
||||
ReturnData activePlayListRD = DeviceControl.fcmsActivePlayList(deviceId, "play.lst");
|
||||
if (activePlayListRD.getCode() != 0) {
|
||||
log.error("播放错误");
|
||||
return false;
|
||||
deviceId++;
|
||||
if (boardInfo.getBoardPort()<1) {
|
||||
boardInfo.setBoardPort(ProtocolDefault.SanSi.getPort());
|
||||
}
|
||||
return true;
|
||||
DeviceVar.deviceInforInit(Integer.toString(deviceId), 1, boardInfo.getBoardIp(), boardInfo.getBoardPort(), 2048);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logoutDevice() {
|
||||
DeviceVar.deviceInforDel(Integer.toString(deviceId));
|
||||
}
|
||||
|
||||
public boolean publishContent(BoardInfo boardInfo, PresetContent presetContent){
|
||||
loginDevice(boardInfo);
|
||||
String filePath = createTextItem(presetContent, boardInfo);
|
||||
return uploadAndStartPlayList(filePath);
|
||||
@Override
|
||||
public void publishContent(BoardInfo boardInfo, List<PresetContent> presetContentList) {
|
||||
String path = createTextItem(presetContentList, boardInfo);
|
||||
uploadAndStartPlayList(path);
|
||||
}
|
||||
|
||||
private void uploadAndStartPlayList(String path) {
|
||||
ReturnData uploadPlayListRD = DeviceControl.fcmsUploadPlayList(Integer.toString(deviceId), path);//上传播放表
|
||||
log.info("uploadPlayListRD:{}", JSON.toJSONString(uploadPlayListRD));
|
||||
// ReturnData activePlayListRD = DeviceControl.fcmsActivePlayList(Integer.toString(deviceId), "000");
|
||||
// if (activePlayListRD.getCode() != 0) {
|
||||
// log.error("播放错误");
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.protocol.sansi.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Getter
|
||||
public enum SanSiFontStyle {
|
||||
SongTi("宋体", "s");
|
||||
private final String name;
|
||||
private final String value;
|
||||
|
||||
SanSiFontStyle(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String getStyleValueByName(String name) {
|
||||
return Stream.of(SanSiFontStyle.values())
|
||||
.filter(fontColor -> fontColor.getName().equals(name))
|
||||
.map(SanSiFontStyle::getValue)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,30 @@
|
|||
package com.ruoyi.protocol.service;
|
||||
|
||||
import com.ruoyi.board.domain.BoardInfo;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IProtocolService {
|
||||
|
||||
boolean protocolSupport(String protocolName);
|
||||
|
||||
void loginDevice(BoardInfo boardInfo);
|
||||
|
||||
void logoutDevice();
|
||||
|
||||
void publishContent(BoardInfo boardInfo, List<PresetContent> presetContentList);
|
||||
|
||||
default void publishInformation(BoardInfo boardInfo, List<PresetContent> presetContentList){
|
||||
// 登录
|
||||
loginDevice(boardInfo);
|
||||
// 发布
|
||||
publishContent(boardInfo, presetContentList);
|
||||
// 登出
|
||||
logoutDevice();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.protocol.service.impl;
|
||||
|
||||
import com.ruoyi.board.domain.BoardInfo;
|
||||
import com.ruoyi.board.domain.PresetContent;
|
||||
import com.ruoyi.protocol.service.IProtocolService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ContentPublishingService {
|
||||
private static final Logger log = LoggerFactory.getLogger(ContentPublishingService.class);
|
||||
@Autowired
|
||||
List<IProtocolService> protocolServiceList;
|
||||
|
||||
public void contentPublish(BoardInfo boardInfo, List<PresetContent> presetContentList) {
|
||||
IProtocolService iProtocolService = protocolServiceList.stream().filter(i -> i.protocolSupport(boardInfo.getBoardCommunicationProtocol())).findFirst().orElse(null);
|
||||
if (iProtocolService ==null) {
|
||||
log.error("协议不支持");
|
||||
return;
|
||||
}
|
||||
iProtocolService.publishInformation(boardInfo, presetContentList);
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package com.ruoyi.protocol.service.impl;
|
||||
|
||||
import com.ruoyi.protocol.service.IProtocolService;
|
||||
|
||||
public class ProtocolServiceImpl implements IProtocolService {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.ruoyi.sensor.common;
|
||||
|
||||
import com.ruoyi.sensor.domain.dto.PerceptionHandlerDTO;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PerceptionHandlerMap {
|
||||
public static final HashMap<String, PerceptionHandlerDTO> perceptionHandlerMap = new HashMap<>();
|
||||
}
|
|
@ -20,8 +20,14 @@ public class PerceptionParams {
|
|||
*/
|
||||
private String boardIp;
|
||||
|
||||
/**
|
||||
* 情报板协议
|
||||
*/
|
||||
private String boardProtocol;
|
||||
// /**
|
||||
// * 情报板协议
|
||||
// */
|
||||
// private String boardProtocol;
|
||||
|
||||
public String getStr() {
|
||||
return "perceptionType=" + perceptionType +
|
||||
",perceptionValue=" + perceptionValue +
|
||||
",boardIp='" + boardIp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.ruoyi.sensor.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class PerceptionWarningStatusInfo {
|
||||
private String boardIp;
|
||||
private String perceptionType;
|
||||
private Double perceptionValue;
|
||||
private Integer perceptionLevel;
|
||||
private String perceptionStatus;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime perceptionTime;
|
||||
private String perceptionMsg;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.ruoyi.sensor.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PresetContentStyle {
|
||||
private String areaType;
|
||||
private String backgroundColor;
|
||||
private String bmpFileName;
|
||||
private String content;
|
||||
private String font;
|
||||
private String fontColor;
|
||||
private Integer fontSize;
|
||||
private Integer width;
|
||||
private Integer height;
|
||||
private String imageAddress;
|
||||
private Integer startX;
|
||||
private Integer startY;
|
||||
private Integer stay;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.ruoyi.sensor.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ReleaseLogReport {
|
||||
private String boardIp;
|
||||
private String perceptionType;
|
||||
private int perceptionLevel;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime releaseTime;
|
||||
private String releaseStatus;
|
||||
private String releaseContent;
|
||||
private List<PresetContentStyle> lines;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.ruoyi.sensor.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class WarningStatusInfo {
|
||||
private String infoBoardIP;
|
||||
private String warningType;
|
||||
private Double warningValue;
|
||||
private Integer currentWarningLevel;
|
||||
private String status;
|
||||
private Date triggerTime;
|
||||
private String warningMessage;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.ruoyi.sensor.domain.dto;
|
||||
|
||||
import com.ruoyi.sensor.domain.PerceptionParams;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class PerceptionHandlerDTO {
|
||||
private Date createTime = new Date();
|
||||
private Date updateTime = new Date();
|
||||
private Integer allReceiveTimes = 0;
|
||||
private Integer currentMinReceiveTimes = 0;
|
||||
private PerceptionParams perceptionParams;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.ruoyi.sensor.enums;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum PrintColor {
|
||||
|
||||
red("red", "255000000"),
|
||||
yellow("yellow", "255255000"),
|
||||
green("green", "000255000");
|
||||
|
||||
private final String colorName;
|
||||
private final String colourBitStr;
|
||||
|
||||
PrintColor(String colorName, String colourBitStr) {
|
||||
this.colorName = colorName;
|
||||
this.colourBitStr = colourBitStr;
|
||||
}
|
||||
|
||||
public static String getBitColor(String colorName) {
|
||||
return Stream.of(PrintColor.values())
|
||||
.filter(fontColor -> fontColor.colorName.equals(colorName))
|
||||
.map(fontColor -> fontColor.colourBitStr)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
|
@ -2,35 +2,54 @@ package com.ruoyi.sensor.merchants;
|
|||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.sensor.domain.WarningStatusInfo;
|
||||
import com.ruoyi.sensor.domain.PerceptionWarningStatusInfo;
|
||||
import com.ruoyi.sensor.domain.ReleaseLogReport;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class MerchantsHttp {
|
||||
private static final Logger log = LoggerFactory.getLogger(MerchantsHttp.class);
|
||||
|
||||
private static final String uri = "http://localhost:8080/merchants";
|
||||
private static String STATUS_URI;
|
||||
private static String PUBLICATION_LOG_URI;
|
||||
|
||||
public static void sendWarning(WarningStatusInfo warningStatusInfo){
|
||||
String jsonString = JSON.toJSONString(warningStatusInfo);
|
||||
@Value("${remote.statusReport}")
|
||||
public void setStatusUri(String statusUri) {
|
||||
STATUS_URI = statusUri;
|
||||
}
|
||||
|
||||
@Value("${remote.logReport}")
|
||||
public void setPublicationLogUri(String publicationLogUri) {
|
||||
PUBLICATION_LOG_URI = publicationLogUri;
|
||||
}
|
||||
|
||||
public static void sendWarningStatus(PerceptionWarningStatusInfo perceptionWarningStatusInfo){
|
||||
String jsonString = JSON.toJSONString(perceptionWarningStatusInfo);
|
||||
send(STATUS_URI, jsonString);
|
||||
}
|
||||
|
||||
public static void sendPublicationLog(ReleaseLogReport releaseLogReport){
|
||||
String jsonString = JSON.toJSONString(releaseLogReport);
|
||||
send(PUBLICATION_LOG_URI, jsonString);
|
||||
|
||||
}
|
||||
|
||||
private static void send(String URI, String jsonStr) {
|
||||
String result = null;
|
||||
Map<String, String> header = new HashMap<>();
|
||||
try {
|
||||
result = HttpUtils.postCall(uri, jsonString, header);
|
||||
result = HttpUtils.postCall(URI, jsonStr);
|
||||
} catch (Exception e) {
|
||||
log.error("send warning error", e);
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
log.error("send warning error");
|
||||
return;
|
||||
log.error("发送信息成功,但是没有接收到响应信息");
|
||||
} else {
|
||||
log.info(result);
|
||||
}
|
||||
// 记录上报结果
|
||||
log.info(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,4 +6,7 @@ public interface ISensorDataService {
|
|||
|
||||
void perceptionParamsHandler(PerceptionParams params);
|
||||
|
||||
void putPerceptionParamsToMap(PerceptionParams perceptionParams);
|
||||
|
||||
void handlerPerceptionMap();
|
||||
}
|
||||
|
|
|
@ -9,23 +9,34 @@ 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.common.utils.SecurityUtils;
|
||||
import com.ruoyi.protocol.sansi.SanSiProtocol;
|
||||
import com.ruoyi.protocol.service.impl.ContentPublishingService;
|
||||
import com.ruoyi.sensor.common.PerceptionHandlerMap;
|
||||
import com.ruoyi.sensor.domain.PerceptionParams;
|
||||
import com.ruoyi.sensor.domain.WarningStatusInfo;
|
||||
import com.ruoyi.sensor.domain.PerceptionWarningStatusInfo;
|
||||
import com.ruoyi.sensor.domain.PresetContentStyle;
|
||||
import com.ruoyi.sensor.domain.ReleaseLogReport;
|
||||
import com.ruoyi.sensor.domain.dto.PerceptionHandlerDTO;
|
||||
import com.ruoyi.sensor.enums.PrintColor;
|
||||
import com.ruoyi.sensor.merchants.MerchantsHttp;
|
||||
import com.ruoyi.sensor.service.ISensorDataService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class SensorDataServiceImpl implements ISensorDataService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SensorDataServiceImpl.class);
|
||||
private static final Integer ALL_TIMES_THRESHOLD = 5;
|
||||
private static final Integer MIN_TIMES_THRESHOLD = 4;
|
||||
@Autowired
|
||||
private IBoardInfoService boardInfoService;
|
||||
@Autowired
|
||||
|
@ -34,55 +45,206 @@ public class SensorDataServiceImpl implements ISensorDataService {
|
|||
private IPresetContentService presetContentService;
|
||||
@Autowired
|
||||
private IReleaseRecordService releaseRecordService;
|
||||
@Autowired
|
||||
private ContentPublishingService contentPublishingService;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void perceptionParamsHandler(PerceptionParams params) {
|
||||
int planTypeByName = AlertPlanType.getPlanTypeByName(params.getPerceptionType());
|
||||
int currentContentPlanType = AlertPlanType.getPlanTypeByName(params.getPerceptionType());
|
||||
// 找到符合计划的预警
|
||||
AlertPlan oneByTypeAndValue = alertPlanService.getOneByTypeAndValue(planTypeByName, params.getPerceptionValue());
|
||||
if (null == oneByTypeAndValue) {
|
||||
AlertPlan currentAlertPlan = alertPlanService.getOneByTypeAndValue(currentContentPlanType, params.getPerceptionValue());
|
||||
if (null == currentAlertPlan) {
|
||||
log.error("找不到预警计划");
|
||||
return;
|
||||
}
|
||||
// 情报板设备信息
|
||||
BoardInfo oneByIP = boardInfoService.getOneByIP(params.getBoardIp());
|
||||
if (null == oneByIP) {
|
||||
BoardInfo boardInfo = boardInfoService.getOneByIP(params.getBoardIp());
|
||||
if (null == boardInfo) {
|
||||
log.error("找不到情报板信息");
|
||||
return;
|
||||
}
|
||||
// 预置发布的信息
|
||||
PresetContent oneByContentAndBoardSize = presetContentService.getOneByContentAndBoardSize(oneByTypeAndValue.getDisplayContent(), oneByIP.getBoardSize(), planTypeByName);
|
||||
if (null == oneByContentAndBoardSize) {
|
||||
PresetContent currentContent = presetContentService.getOneByContentAndBoardSize(currentAlertPlan.getDisplayContent(), boardInfo.getBoardSize(), currentContentPlanType);
|
||||
if (null == currentContent) {
|
||||
log.error("找不到预置发布的信息");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取同类型最新的一条发布记录
|
||||
ReleaseRecord oneLatestByBoardId = releaseRecordService.getOneLatestByBoardId(oneByIP.getBoardIp(), 1);
|
||||
if (null == oneLatestByBoardId) {
|
||||
// 说明之前没有发布记录
|
||||
// 预警信息发布流程
|
||||
List<PresetContent> informationToBeReleasedList = new ArrayList<>();
|
||||
String presetStatus = "预警开始";
|
||||
// 查询这个情报板 2 分钟内所有发布内容
|
||||
List<ReleaseRecord> releaseRecordList = releaseRecordService.listLatest2minRecordByBoardId(boardInfo.getId());
|
||||
if (releaseRecordList.isEmpty()) {
|
||||
// 如果查到为空,说明 2 分钟内没有发布内容,这里是第一次发布,直接走发布逻辑
|
||||
informationToBeReleasedList.add(currentContent);
|
||||
} else {
|
||||
// 如果不为空,说明 2 分钟内是发布了内容的,查询所有的发布内容
|
||||
List<Integer> presetContentIdList = releaseRecordList.stream().map(ReleaseRecord::getPresetContentId).collect(Collectors.toList());
|
||||
List<PresetContent> existPresetContentList = presetContentService.listByIds(presetContentIdList);
|
||||
// 先把已经存在的都加入进去
|
||||
informationToBeReleasedList.addAll(existPresetContentList);
|
||||
// 判断所有发布内容中是否存在当前要发布的类型
|
||||
PresetContent isExistsPresetContent = existPresetContentList.stream().filter(i -> i.getInfoType() == currentContentPlanType).findFirst().orElse(null);
|
||||
if (isExistsPresetContent == null) {
|
||||
// 说明这是一个新发布的预警类型
|
||||
informationToBeReleasedList.add(currentContent);
|
||||
} else {
|
||||
// 说明这是一个已有的类型,需要获取预警等级,然后进行判断
|
||||
// 判断已有类型是否和现在的一样然后再替换掉
|
||||
// 现在需要知道这个同类型的属于是哪个级别的
|
||||
int foundPlanId = releaseRecordList.stream()
|
||||
.filter(i -> Objects.equals(i.getPresetContentId(), isExistsPresetContent.getId()))
|
||||
.mapToInt(ReleaseRecord::getPlanId)
|
||||
.findFirst().orElse(-1);
|
||||
AlertPlan byId = alertPlanService.getById(foundPlanId);
|
||||
int compare = NumberUtils.compare(byId.getLevel(),
|
||||
currentAlertPlan.getLevel());
|
||||
switch (compare) {
|
||||
case 0:
|
||||
// 两个一样等级
|
||||
// 这时候就不需要替换,也不需要重新发布
|
||||
presetStatus = "预警持续";
|
||||
break;
|
||||
case 1:
|
||||
// getPresetContentLevel > alertPlan.getLevel()
|
||||
// 预警减弱
|
||||
// 此时需要将同类型的信息给替换掉,并重新发布
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo 发布
|
||||
boolean sanSiProtocol = new SanSiProtocol().publishContent(oneByIP, oneByContentAndBoardSize);
|
||||
// todo 发布
|
||||
contentPublishingService.contentPublish(boardInfo, informationToBeReleasedList);
|
||||
// 经过主动发布之后就变成预置信息
|
||||
// 发布之后记录发布内容 ReleaseRecord
|
||||
this.saveRecord(boardInfo.getId(), currentContent.getId(), currentAlertPlan.getId());
|
||||
// 记录完了之后就需要向对方发送状态日志记录
|
||||
this.sendStatus(presetStatus, boardInfo.getBoardIp(), params.getPerceptionType(), currentContent.getContent(), params.getPerceptionValue(), currentAlertPlan.getLevel());
|
||||
// 发送情报板发布信息日志记录
|
||||
this.sendPublicLog(boardInfo.getBoardIp(), params.getPerceptionType(), currentAlertPlan.getLevel(), currentContent.getContent(), informationToBeReleasedList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putPerceptionParamsToMap(PerceptionParams perceptionParams) {
|
||||
String key = perceptionParams.getPerceptionType() + perceptionParams.getBoardIp();
|
||||
PerceptionHandlerDTO orDefault = PerceptionHandlerMap.perceptionHandlerMap.getOrDefault(key, new PerceptionHandlerDTO());
|
||||
orDefault.setPerceptionParams(perceptionParams);
|
||||
orDefault.setAllReceiveTimes(orDefault.getAllReceiveTimes() + 1);
|
||||
orDefault.setCurrentMinReceiveTimes(orDefault.getCurrentMinReceiveTimes() + 1);
|
||||
orDefault.setUpdateTime(new Date());
|
||||
PerceptionHandlerMap.perceptionHandlerMap.put(key, orDefault);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void handlerPerceptionMap(){
|
||||
List<PerceptionParams> publishList = new ArrayList<>();
|
||||
List<PerceptionParams> cancelList = new ArrayList<>();
|
||||
List<String> delList = new ArrayList<>();
|
||||
long now = new Date().getTime();
|
||||
log.info("{}", PerceptionHandlerMap.perceptionHandlerMap);
|
||||
PerceptionHandlerMap.perceptionHandlerMap.forEach((key, value) -> {
|
||||
long lastUpdateTime = value.getUpdateTime().getTime();
|
||||
// 最后的接收时间大于 1 分钟
|
||||
if (now - lastUpdateTime > 60 * 1000) {
|
||||
delList.add(key);
|
||||
if (value.getAllReceiveTimes() > ALL_TIMES_THRESHOLD ) {
|
||||
cancelList.add(value.getPerceptionParams());
|
||||
}
|
||||
} else {
|
||||
// 接收时间 < 1 分钟 && 接收次数 > 5
|
||||
// 要不要 + 个属性,当前分钟内接收的次数,以及接收的总次数
|
||||
if (value.getAllReceiveTimes() > ALL_TIMES_THRESHOLD && value.getCurrentMinReceiveTimes() > MIN_TIMES_THRESHOLD) {
|
||||
publishList.add(value.getPerceptionParams());
|
||||
}
|
||||
}
|
||||
value.setCurrentMinReceiveTimes(0);
|
||||
});
|
||||
// 需要删除的内容,有的是没有发布的浮动信息,有的是已经显示过了,需要取消显示的
|
||||
cancelList.forEach(this::cancelPublication);
|
||||
log.info("cancelPublication:{}", cancelList);
|
||||
delList.forEach(PerceptionHandlerMap.perceptionHandlerMap::remove);
|
||||
log.info("delList:{}", delList);
|
||||
publishList.forEach(this::perceptionParamsHandler);
|
||||
log.info("publishList:{}", publishList);
|
||||
}
|
||||
|
||||
private void sendPublicLog(String ip, String type, Integer level, String content, List<PresetContent> informationToBeReleasedList) {
|
||||
ReleaseLogReport releaseLogReport = new ReleaseLogReport();
|
||||
releaseLogReport.setBoardIp(ip);
|
||||
releaseLogReport.setPerceptionType(type);
|
||||
releaseLogReport.setPerceptionLevel(level);
|
||||
releaseLogReport.setReleaseContent(content);
|
||||
releaseLogReport.setReleaseTime(LocalDateTime.now());
|
||||
releaseLogReport.setReleaseStatus("发布成功");
|
||||
List<PresetContentStyle> presetContentStyles = new ArrayList<>();
|
||||
informationToBeReleasedList.forEach(i -> {
|
||||
String[] split = StringUtils.split(i.getBoardSize(), "*");
|
||||
PresetContentStyle p = new PresetContentStyle();
|
||||
p.setFont(i.getFontStyle());
|
||||
p.setFontSize(i.getFontSize());
|
||||
p.setFontColor(PrintColor.getBitColor(i.getFontColor()));
|
||||
p.setContent(i.getContent());
|
||||
p.setStartX(i.getFontPositionX());
|
||||
p.setStartY(i.getFontPositionY());
|
||||
p.setWidth(NumberUtils.toInt(split[1]));
|
||||
p.setHeight(NumberUtils.toInt(split[0]));
|
||||
p.setStay(i.getPlayTime());
|
||||
presetContentStyles.add(p);
|
||||
});
|
||||
releaseLogReport.setLines(presetContentStyles);
|
||||
MerchantsHttp.sendPublicationLog(releaseLogReport);
|
||||
}
|
||||
|
||||
private void sendStatus(String status, String ip, String type, String content, Double value, Integer level) {
|
||||
PerceptionWarningStatusInfo statusInfo = new PerceptionWarningStatusInfo();
|
||||
statusInfo.setPerceptionStatus(status);
|
||||
statusInfo.setBoardIp(ip);
|
||||
statusInfo.setPerceptionType(type);
|
||||
statusInfo.setPerceptionValue(value);
|
||||
statusInfo.setPerceptionMsg(content);
|
||||
statusInfo.setPerceptionLevel(level);
|
||||
statusInfo.setPerceptionTime(LocalDateTime.now());
|
||||
// // 开始发送状态记录
|
||||
MerchantsHttp.sendWarningStatus(statusInfo);
|
||||
}
|
||||
|
||||
@Async
|
||||
public void cancelPublication(PerceptionParams params) {
|
||||
PerceptionWarningStatusInfo statusInfo = new PerceptionWarningStatusInfo();
|
||||
statusInfo.setPerceptionStatus("预警结束");
|
||||
statusInfo.setBoardIp(params.getBoardIp());
|
||||
statusInfo.setPerceptionType(params.getPerceptionType());
|
||||
statusInfo.setPerceptionValue(params.getPerceptionValue());
|
||||
statusInfo.setPerceptionMsg("");
|
||||
statusInfo.setPerceptionLevel(1);
|
||||
statusInfo.setPerceptionTime(LocalDateTime.now());
|
||||
// // 开始发送状态记录
|
||||
MerchantsHttp.sendWarningStatus(statusInfo);
|
||||
}
|
||||
|
||||
private void saveRecord(Integer boardId, Integer presetContentId, Integer planId) {
|
||||
ReleaseRecord releaseRecord = new ReleaseRecord();
|
||||
releaseRecord.setBoardId(oneByIP.getId());
|
||||
releaseRecord.setPresetContentId(oneByContentAndBoardSize.getId());
|
||||
releaseRecord.setBoardId(boardId);
|
||||
releaseRecord.setPresetContentId(presetContentId);
|
||||
releaseRecord.setPlanId(planId);
|
||||
releaseRecord.setCreateTime(new Date());
|
||||
releaseRecord.setCreatedBy(SecurityUtils.getUserId().intValue());
|
||||
releaseRecord.setCreatedBy(1);
|
||||
releaseRecordService.save(releaseRecord);
|
||||
// 记录完了之后就需要向对方发送日志记录
|
||||
WarningStatusInfo statusInfo = new WarningStatusInfo();
|
||||
statusInfo.setStatus("");
|
||||
statusInfo.setInfoBoardIP(oneByIP.getBoardIp());
|
||||
statusInfo.setWarningType(params.getPerceptionType());
|
||||
statusInfo.setWarningMessage(oneByContentAndBoardSize.getContent());
|
||||
statusInfo.setWarningValue(params.getPerceptionValue());
|
||||
statusInfo.setCurrentWarningLevel(oneByTypeAndValue.getLevel());
|
||||
statusInfo.setTriggerTime(new Date());
|
||||
// 开始发送状态记录
|
||||
MerchantsHttp.sendWarning(new WarningStatusInfo());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.ruoyi.sensor.task;
|
||||
|
||||
import com.ruoyi.sensor.service.ISensorDataService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("clearPerceptionTask")
|
||||
public class ClearPerceptionTask {
|
||||
|
||||
@Autowired
|
||||
private ISensorDataService sensorDataService;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ClearPerceptionTask.class);
|
||||
|
||||
public void clearPerception(){
|
||||
sensorDataService.handlerPerceptionMap();
|
||||
log.info("handlerPerceptionMap 处理完了");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue