Commit 3478638a authored by Administrator's avatar Administrator

-

Signed-off-by: Administrator's avatarAdministrator <admin@example.com>
parent 9f042eac
...@@ -50,9 +50,9 @@ public class PushMonitorRules implements Serializable { ...@@ -50,9 +50,9 @@ public class PushMonitorRules implements Serializable {
private String timePeriodEnd; private String timePeriodEnd;
/** /**
* 接收方式 手机:0 PC:1 * 接收方式 开:0 关:1
*/ */
private String receiveMode; private Integer receiveMode;
/** /**
* 手机号码,多个逗号隔开 * 手机号码,多个逗号隔开
*/ */
......
package com.dsk.monitor.job; package com.dsk.monitor.job;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsk.common.tenant.helper.TenantHelper; import com.dsk.common.tenant.helper.TenantHelper;
import com.dsk.common.utils.DateUtils; import com.dsk.common.utils.DateUtils;
import com.dsk.common.utils.redis.RedisUtils;
import com.dsk.monitor.domain.dto.PushMonitorInfo; import com.dsk.monitor.domain.dto.PushMonitorInfo;
import com.dsk.monitor.domain.dto.PushMonitorRules; import com.dsk.monitor.domain.dto.PushMonitorRules;
import com.dsk.monitor.domain.vo.ConditionVo; import com.dsk.monitor.domain.vo.ConditionVo;
...@@ -18,10 +20,8 @@ import org.springframework.scheduling.annotation.Scheduled; ...@@ -18,10 +20,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays; import java.time.Duration;
import java.util.Date; import java.util.*;
import java.util.List;
import java.util.Map;
/** /**
* @ClassName PushScheduling * @ClassName PushScheduling
...@@ -42,9 +42,24 @@ public class PushScheduling { ...@@ -42,9 +42,24 @@ public class PushScheduling {
@Resource @Resource
private PushMonitorRulesMapper rulesMapper; private PushMonitorRulesMapper rulesMapper;
/**
* 关闭推动
*/
private static final Integer IS_SWITCH = 1;
// @Scheduled(cron = "0 0/2 * * * ?") // @Scheduled(cron = "0 0/2 * * * ?")
@Scheduled(cron = "0 0 * * * ?") @Scheduled(cron = "0 0 * * * ?")
public void receiveModePhone() throws Exception { public void receiveModePhone() throws Exception {
TenantHelper.setTenantId("1");
// 设置redisKey
String lockKey = "stockKey";
// 设置redisValue
String value = UUID.randomUUID().toString();
// 这里默认设置超时时间为30秒
boolean hasKey = RedisUtils.setObjectIfAbsent(lockKey, value, Duration.ofMillis(1000 * 30));
if (!hasKey) {
return ;
}
// 是否是周末 // 是否是周末
boolean isWeekend = DateUtil.isWeekend(new Date()); boolean isWeekend = DateUtil.isWeekend(new Date());
PushSettingHolidayVo holidayVo = new PushSettingHolidayVo(); PushSettingHolidayVo holidayVo = new PushSettingHolidayVo();
...@@ -55,23 +70,15 @@ public class PushScheduling { ...@@ -55,23 +70,15 @@ public class PushScheduling {
if (200 == settingHolidayCode) { if (200 == settingHolidayCode) {
isWeekend = !settingHolidayData; isWeekend = !settingHolidayData;
} }
TenantHelper.setTenantId("1");
// 获取当前整点时间 // 获取当前整点时间
Integer concurrentHour = DateUtils.getHour(); Integer concurrentHour = DateUtils.getHour();
QueryWrapper<PushMonitorRules> queryWrapper = new QueryWrapper(); QueryWrapper<PushMonitorRules> queryWrapper = new QueryWrapper();
List<PushMonitorRules> detailList = rulesMapper.selectList(queryWrapper); List<PushMonitorRules> detailList = rulesMapper.selectList(queryWrapper);
Integer timeStart = 0;
Integer timeEnd = 24;
for (PushMonitorRules detail : detailList) { for (PushMonitorRules detail : detailList) {
// 推送时段-起 if (IS_SWITCH.equals(detail.getReceiveMode())) {
String timePeriodStart = detail.getTimePeriodStart(); continue;
timePeriodStart = timePeriodStart.substring(0,2);
if (timePeriodStart.contains("0")) {
timePeriodStart = timePeriodStart.substring(1,2);
}
// 推送时段-止
String timePeriodEnd = detail.getTimePeriodEnd();
timePeriodEnd = timePeriodEnd.substring(0,2);
if (timePeriodEnd.contains("0")) {
timePeriodEnd = timePeriodEnd.substring(1,2);
} }
Integer pushFrequency = detail.getPushFrequency(); Integer pushFrequency = detail.getPushFrequency();
if (pushFrequency > 1) { if (pushFrequency > 1) {
...@@ -79,42 +86,101 @@ public class PushScheduling { ...@@ -79,42 +86,101 @@ public class PushScheduling {
continue; continue;
} }
} }
Integer timeStart = Integer.valueOf(timePeriodStart); // 推送时段-起
Integer timeEnd = Integer.valueOf(timePeriodEnd); String timePeriodStart = detail.getTimePeriodStart();
if (concurrentHour >= timeStart && concurrentHour <= timeEnd) { if (ObjectUtil.isNotEmpty(timePeriodStart)) {
PushMonitorDynamicPageVo pageVo = new PushMonitorDynamicPageVo(); timePeriodStart = timePeriodStart.substring(0,2);
pageVo.setUserId(detail.getUserId()); if (timePeriodStart.contains("0")) {
ConditionVo vo = new ConditionVo(); timePeriodStart = timePeriodStart.substring(1,2);
// 截止时间
vo.setEndTime(DateUtils.getDate());
vo.setBeginTime(DateUtils.format(DateUtils.addDays(new Date(),-1)));
// 监控维度
vo.setDimension(getParamList(detail.getDimension()));
vo.setUserId(detail.getUserId());
pageVo.setCondition(vo);;
Map<String, Object> resMap = monitorService.companyDynamicPageScheduled(pageVo);
Integer code = MapUtils.getInteger(resMap, "code", 300);
Map data = MapUtils.getMap(resMap, "data", null);
if (200 != code) {
continue;
} }
Integer count = MapUtils.getInteger(data, "totalCount", 0); timeStart = Integer.valueOf(timePeriodStart);
if (count > 0 ) { }
SendMessageUtil.sendMessage(detail.getPhones(), count.toString()); // 推送时段-止
String timePeriodEnd = detail.getTimePeriodEnd();
if (ObjectUtil.isNotEmpty(timePeriodEnd)) {
timePeriodEnd = timePeriodEnd.substring(0,2);
if (timePeriodEnd.contains("0")) {
timePeriodEnd = timePeriodEnd.substring(1,2);
} }
if (count > 0) { timeEnd = Integer.valueOf(timePeriodEnd);
PushMonitorInfo pushMonitorInfo = new PushMonitorInfo(); }
pushMonitorInfo.setUserId(detail.getUserId()); if (ObjectUtil.isNotEmpty(timePeriodStart) && ObjectUtil.isEmpty(timePeriodEnd)) {
pushMonitorInfo.setCount(count); if (concurrentHour >= timeStart) {
monitorInfoMapper.insert(pushMonitorInfo); savePushMonitorInfo(detail);
}
}
if (ObjectUtil.isEmpty(timePeriodStart) && ObjectUtil.isNotEmpty(timePeriodEnd)) {
if (concurrentHour <= timeEnd) {
savePushMonitorInfo(detail);
} }
} }
if (ObjectUtil.isEmpty(timePeriodStart) && ObjectUtil.isEmpty(timePeriodEnd)) {
savePushMonitorInfo(detail);
}
if (ObjectUtil.isNotEmpty(timePeriodStart) && ObjectUtil.isNotEmpty(timePeriodEnd)) {
if (concurrentHour >= timeStart && concurrentHour <= timeEnd) {
savePushMonitorInfo(detail);
}
}
}
}
/***
*@Description: 查询并保存动态信息
*@Param:
*@return: void
*@Author: Dgm
*@date: 2024/3/17 14:30
*/
private void savePushMonitorInfo (PushMonitorRules detail) throws Exception {
PushMonitorDynamicPageVo pageVo = new PushMonitorDynamicPageVo();
pageVo.setUserId(detail.getUserId());
ConditionVo vo = new ConditionVo();
// 截止时间
vo.setEndTime(DateUtils.getTime());
vo.setBeginTime(DateUtils.format(DateUtils.addDays(new Date(),-1)));
// 条件查询监控维度子级名称数组
vo.setDimension(getParamList(detail.getDimension()));
// 条件查询监控维度父级名称数组
vo.setParentDimension(getParamList((detail.getRiskType())));
vo.setUserId(detail.getUserId());
pageVo.setCondition(vo);;
Map<String, Object> resMap = monitorService.companyDynamicPageScheduled(pageVo);
Integer code = MapUtils.getInteger(resMap, "code", 300);
Map data = MapUtils.getMap(resMap, "data", null);
if (200 != code) {
return;
}
Integer count = MapUtils.getInteger(data, "totalCount", 0);
if (count > 0 ) {
SendMessageUtil.sendMessage(detail.getPhones(), count.toString());
// SendMessageUtil.sendMessage(detail.getPhones(), getContent(count));
}
if (count > 0) {
PushMonitorInfo pushMonitorInfo = new PushMonitorInfo();
pushMonitorInfo.setUserId(detail.getUserId());
pushMonitorInfo.setCount(count);
monitorInfoMapper.insert(pushMonitorInfo);
} }
} }
public List<String> getParamList(String dimension) { public static List<String> getParamList(String dimension) {
List<String> getParamList = Arrays.asList(dimension.split(",")); List<String> getParamList = new ArrayList<>();
if (ObjectUtil.isNotEmpty(dimension)) {
getParamList = Arrays.asList(dimension.split(","));
}
return getParamList; return getParamList;
} }
/**
*@Description: 组装推送信息
*@Param:
*@return: java.lang.String
*@Author: Dgm
*@date: 2024/3/16 14:05
*/
private String getContent (Integer number) {
return "您监控的企业发生".concat(number.toString()).concat("条风险动态。");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment