diff --git a/src/main/java/com/zhgd/netty/tcp/constant/HighFormworkSupport.java b/src/main/java/com/zhgd/netty/tcp/constant/HighFormworkSupport.java index 40a983419..cecb5d905 100644 --- a/src/main/java/com/zhgd/netty/tcp/constant/HighFormworkSupport.java +++ b/src/main/java/com/zhgd/netty/tcp/constant/HighFormworkSupport.java @@ -120,6 +120,42 @@ public interface HighFormworkSupport { * 测点状态3 */ public static final String GZ_ZT3 = "GZ_ZT3"; + /** + * 测点编号4 + */ + public static final String GZ_CJ4 = "GZ_CJ4"; + /** + * 测点数据4 + */ + public static final String GZ_DS4 = "GZ_DS4"; + /** + * 测点状态4 + */ + public static final String GZ_ZT4 = "GZ_ZT4"; + /** + * 测点编号5 + */ + public static final String GZ_CJ5 = "GZ_CJ5"; + /** + * 测点数据5 + */ + public static final String GZ_DS5 = "GZ_DS5"; + /** + * 测点状态5 + */ + public static final String GZ_ZT5 = "GZ_ZT5"; + /** + * 测点编号6 + */ + public static final String GZ_CJ6 = "GZ_CJ6"; + /** + * 测点数据6 + */ + public static final String GZ_DS6 = "GZ_DS6"; + /** + * 测点状态6 + */ + public static final String GZ_ZT6 = "GZ_ZT6"; /** * 状态 */ diff --git a/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java b/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java index 04fdbd020..bf5abcc10 100644 --- a/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java +++ b/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java @@ -190,7 +190,10 @@ public class HighFormworkSupportService { String no = dataMap.get(HighFormworkSupport.GZ_CJ1); String no2 = dataMap.get(HighFormworkSupport.GZ_CJ2); String no3 = dataMap.get(HighFormworkSupport.GZ_CJ3); - List list = Stream.of(no, no2, no3).filter(Objects::nonNull).collect(Collectors.toList()); + String no4 = dataMap.get(HighFormworkSupport.GZ_CJ4); + String no5 = dataMap.get(HighFormworkSupport.GZ_CJ5); + String no6 = dataMap.get(HighFormworkSupport.GZ_CJ6); + List list = Stream.of(no, no2, no3, no4, no5, no6).filter(Objects::nonNull).collect(Collectors.toList()); //保存设备 Map noMap = list.stream().collect(Collectors.toMap(x -> x, x -> x)); if (noMap.size() != existDevices.size() || !existDevices.stream().allMatch(key -> { @@ -208,7 +211,7 @@ public class HighFormworkSupportService { } } - HighFormworkMeasureCurrentData currentData = getAndSaveHighFormworkMeasureCurrentData(dataMap, no, no2, no3, point); + HighFormworkMeasureCurrentData currentData = getAndSaveHighFormworkMeasureCurrentData(dataMap, no, no2, no3, no4, no5, no6, point); //插入报警/预警数据 addAlarmData(point, currentData); @@ -234,7 +237,7 @@ public class HighFormworkSupportService { return null; } - private HighFormworkMeasureCurrentData getAndSaveHighFormworkMeasureCurrentData(HashMap dataMap, String no, String no2, String no3, HighFormworkMeasurePoint point) { + private HighFormworkMeasureCurrentData getAndSaveHighFormworkMeasureCurrentData(HashMap dataMap, String no, String no2, String no3, String no4, String no5, String no6, HighFormworkMeasurePoint point) { //测点编号后缀为测点类型识别:F-立杆轴力(单位为牛)、H-水平位移(单位为mm)、V-模板沉降(单位为mm)、L-立杆倾斜(单位为°)、D-地基沉降;,例如测点 0001L表示测点类型为立杆倾斜; HighFormworkMeasureCurrentData currentData = new HighFormworkMeasureCurrentData(); currentData.setMeasurePointNumber(point.getMeasurePointNumber()); @@ -251,6 +254,9 @@ public class HighFormworkSupportService { //测点3类型 setCurrentData(no3, currentData, dataMap, HighFormworkSupport.GZ_DS3); + setCurrentData(no4, currentData, dataMap, HighFormworkSupport.GZ_DS4); + setCurrentData(no5, currentData, dataMap, HighFormworkSupport.GZ_DS5); + setCurrentData(no6, currentData, dataMap, HighFormworkSupport.GZ_DS6); //设置报警状态 setAlarmStatus(dataMap, currentData); diff --git a/src/main/java/com/zhgd/xmgl/async/AsyncAiAnalyse.java b/src/main/java/com/zhgd/xmgl/async/AsyncAiAnalyse.java index 72e9e3faf..53e9f7802 100644 --- a/src/main/java/com/zhgd/xmgl/async/AsyncAiAnalyse.java +++ b/src/main/java/com/zhgd/xmgl/async/AsyncAiAnalyse.java @@ -1,13 +1,8 @@ package com.zhgd.xmgl.async; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zhgd.mqtt.bean.PushPayload; import com.zhgd.mqtt.server.IMqttSender; -import com.zhgd.xmgl.call.TencentCloudMessageCall; -import com.zhgd.xmgl.call.YunPianMessageCall; import com.zhgd.xmgl.call.api.MessageManufacturer; import com.zhgd.xmgl.call.factory.MessageManufacturerFactory; import com.zhgd.xmgl.constant.Cts; @@ -21,9 +16,7 @@ import com.zhgd.xmgl.modules.basicdata.service.ICompanyConfigService; import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; import com.zhgd.xmgl.modules.basicdata.service.impl.DictionaryItemServiceImpl; import com.zhgd.xmgl.modules.basicdata.service.impl.NoticeServiceImpl; -import com.zhgd.xmgl.modules.project.service.IMessageConfigV2Service; import com.zhgd.xmgl.modules.video.entity.AiAnalyseHardWareAlarmRecord; -import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl; import com.zhgd.xmgl.push.service.UniPushService; import com.zhgd.xmgl.util.MapBuilder; @@ -129,7 +122,7 @@ public class AsyncAiAnalyse { templateParams.add(location); String text = StrUtil.format("【{}】AI警报!{},位置{}", messageManufacturer.getConfig().getSignature(), typeName, location); - messageManufacturer.sendMsgByConfig(phoneNums, 2, templateParams, text); + messageManufacturer.sendMsgByConfig(phoneNums, "", templateParams, text); } }, threadPoolTaskExecutor); } diff --git a/src/main/java/com/zhgd/xmgl/call/TencentCloudDevSmsCall.java b/src/main/java/com/zhgd/xmgl/call/TencentCloudDevSmsCall.java new file mode 100644 index 000000000..317dab6a7 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/call/TencentCloudDevSmsCall.java @@ -0,0 +1,68 @@ +package com.zhgd.xmgl.call; + +import com.gexin.fastjson.JSON; +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.exception.TencentCloudSDKException; +import com.tencentcloudapi.sms.v20210111.SmsClient; +import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; +import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; +import com.zhgd.xmgl.call.api.DevSmsManufacturer; +import com.zhgd.xmgl.modules.project.entity.DevMessageConfig; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 腾讯云短信 + */ +@Slf4j +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class TencentCloudDevSmsCall implements DevSmsManufacturer { + private DevMessageConfig config; + + @Override + public DevMessageConfig getConfig() { + return config; + } + + @Override + public void setConfig(DevMessageConfig config) { + this.config = config; + } + + + @Override + public void sendMsg(List phoneNums, String templateId, List templateParams, String text) { + try { + doSendMsg(phoneNums, templateId, templateParams.toArray(new String[]{})); + } catch (Exception e) { + log.error("按短信配置发送短信异常", e); + } + } + + /** + * 发送短信 + * + * @param phoneNums 手机号码 + * @param templateId 短信模板id + * @param templateParamSet 短信模板参数 + * @throws TencentCloudSDKException + */ + private void doSendMsg(List phoneNums, String templateId, String[] templateParamSet) throws TencentCloudSDKException { + Credential credential = new Credential(config.getSecretId(), config.getSecretKey()); + SmsClient smsClient = new SmsClient(credential, "ap-singapore"); + SendSmsRequest req = new SendSmsRequest(); + req.setPhoneNumberSet(phoneNums.stream().map(s -> "+86" + s).collect(Collectors.toList()).toArray(new String[]{})); + req.setSmsSdkAppId(config.getSmsSdkAppId()); + req.setTemplateId(templateId); + req.setTemplateParamSet(templateParamSet); + SendSmsResponse response = smsClient.SendSms(req); + log.info("腾讯云发送短信结果:{}", JSON.toJSONString(response)); + } + +} diff --git a/src/main/java/com/zhgd/xmgl/call/TencentCloudMessageCall.java b/src/main/java/com/zhgd/xmgl/call/TencentCloudMessageCall.java index a7358f235..911ce62d0 100644 --- a/src/main/java/com/zhgd/xmgl/call/TencentCloudMessageCall.java +++ b/src/main/java/com/zhgd/xmgl/call/TencentCloudMessageCall.java @@ -37,16 +37,9 @@ public class TencentCloudMessageCall implements MessageManufacturer { @Override - public void sendMsgByConfig(List phoneNums, int pushFunctionType, List templateParams, String text) { + public void sendMsgByConfig(List phoneNums, String templateId, List templateParams, String text) { try { -// if (pushFunctionType == 1 && config.getEnableDustSend() == 1) { - //报警类型,报警名称,设备名称,报警值,阈值,超标时间,超标量 -// doSendMsg(phoneNums, config.getDustTemplateId(), templateParams.toArray(new String[]{})); -// } else if (pushFunctionType == 2 && config.getEnableAiSend() == 1) { -// doSendMsg(phoneNums, config.getAiTemplateId(), templateParams.toArray(new String[]{})); -// } else if (pushFunctionType == 3 && config.getEnableLoginSend() == 1) { -// doSendMsg(phoneNums, config.getLoginTemplateId(), templateParams.toArray(new String[]{})); -// } + doSendMsg(phoneNums, templateId, templateParams.toArray(new String[]{})); } catch (Exception e) { log.error("按短信配置发送短信异常", e); } diff --git a/src/main/java/com/zhgd/xmgl/call/YunPianDevSmsCall.java b/src/main/java/com/zhgd/xmgl/call/YunPianDevSmsCall.java new file mode 100644 index 000000000..67f9b9e23 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/call/YunPianDevSmsCall.java @@ -0,0 +1,54 @@ +package com.zhgd.xmgl.call; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import com.gexin.fastjson.JSON; +import com.zhgd.xmgl.call.api.DevSmsManufacturer; +import com.zhgd.xmgl.modules.project.entity.DevMessageConfig; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; + +/** + * 云片短信 + */ +@Slf4j +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class YunPianDevSmsCall implements DevSmsManufacturer { + private DevMessageConfig config; + + @Override + public DevMessageConfig getConfig() { + return config; + } + + @Override + public void setConfig(DevMessageConfig config) { + this.config = config; + } + + @Override + public void sendMsg(List phoneNums, String templateId, List templateParams, String text) { + try { + for (String phoneNum : phoneNums) { + HashMap formMap = new HashMap<>(); + formMap.put("apikey", config.getApiKey()); + formMap.put("mobile", phoneNum); + formMap.put("text", StrUtil.format("【{}】{}", config.getSignature(), text)); + String url = "https://sms.yunpian.com/v2/sms/single_send.json"; + log.info("云片短信按短信配置发送短信,url:{},body:{}", url, JSON.toJSONString(formMap)); + String body = HttpRequest.post(url).form(formMap).execute().body(); + log.info("云片短信按短信配置发送短信,结果:{}", body); + } + } catch (Exception e) { + log.error("云片短信按短信配置发送短信异常", e); + } + } + + +} diff --git a/src/main/java/com/zhgd/xmgl/call/YunPianMessageCall.java b/src/main/java/com/zhgd/xmgl/call/YunPianMessageCall.java index 0e9bc1f4d..736af33a6 100644 --- a/src/main/java/com/zhgd/xmgl/call/YunPianMessageCall.java +++ b/src/main/java/com/zhgd/xmgl/call/YunPianMessageCall.java @@ -32,7 +32,7 @@ public class YunPianMessageCall implements MessageManufacturer { } @Override - public void sendMsgByConfig(List phoneNums, int pushFunctionType, List templateParams, String text) { + public void sendMsgByConfig(List phoneNums, String templateId, List templateParams, String text) { try { for (String phoneNum : phoneNums) { HashMap formMap = new HashMap<>(); diff --git a/src/main/java/com/zhgd/xmgl/call/api/DevSmsManufacturer.java b/src/main/java/com/zhgd/xmgl/call/api/DevSmsManufacturer.java new file mode 100644 index 000000000..e8af28704 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/call/api/DevSmsManufacturer.java @@ -0,0 +1,25 @@ +package com.zhgd.xmgl.call.api; + +import com.zhgd.xmgl.modules.project.entity.DevMessageConfig; + +import java.util.List; + +/** + * 短信接口 + */ +public interface DevSmsManufacturer { + + DevMessageConfig getConfig(); + + void setConfig(DevMessageConfig config); + + /** + * 发送短信 + * + * @param phoneNums 手机号码 + * @param templateId 模板ID(腾讯云) + * @param templateParams 模板参数(腾讯云) + * @param text 消息(云片) + */ + void sendMsg(List phoneNums, String templateId, List templateParams, String text); +} diff --git a/src/main/java/com/zhgd/xmgl/call/api/MessageManufacturer.java b/src/main/java/com/zhgd/xmgl/call/api/MessageManufacturer.java index ae0cabf47..6e33e68cd 100644 --- a/src/main/java/com/zhgd/xmgl/call/api/MessageManufacturer.java +++ b/src/main/java/com/zhgd/xmgl/call/api/MessageManufacturer.java @@ -1,10 +1,7 @@ package com.zhgd.xmgl.call.api; -import com.zhgd.xmgl.modules.car.entity.CarInfo; -import com.zhgd.xmgl.modules.car.entity.ProjectCarCameraConfig; import com.zhgd.xmgl.modules.project.entity.MessageConfigV2; -import java.util.Date; import java.util.List; /** @@ -15,12 +12,14 @@ public interface MessageManufacturer { MessageConfigV2 getConfig(); void setConfig(MessageConfigV2 config); + /** * 按配置发送短信 + * * @param phoneNums - * @param pushFunctionType 1:扬尘;2:AI报警;3:登录; - * @param templateParams - * @param text 消息(云片选择) + * @param templateId 模板ID(腾讯云) + * @param templateParams 模板参数(腾讯云) + * @param text 消息(云片) */ - void sendMsgByConfig(List phoneNums, int pushFunctionType, List templateParams, String text); + void sendMsgByConfig(List phoneNums, String templateId, List templateParams, String text); } diff --git a/src/main/java/com/zhgd/xmgl/call/factory/DevSmsManufacturerFactory.java b/src/main/java/com/zhgd/xmgl/call/factory/DevSmsManufacturerFactory.java new file mode 100644 index 000000000..afd24c4d3 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/call/factory/DevSmsManufacturerFactory.java @@ -0,0 +1,41 @@ +package com.zhgd.xmgl.call.factory; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.zhgd.jeecg.common.util.SpringContextUtils; +import com.zhgd.xmgl.call.TencentCloudDevSmsCall; +import com.zhgd.xmgl.call.YunPianDevSmsCall; +import com.zhgd.xmgl.call.api.DevSmsManufacturer; +import com.zhgd.xmgl.modules.project.entity.DevMessageConfig; +import com.zhgd.xmgl.modules.project.service.IDevMessageConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Slf4j +@Component +public class DevSmsManufacturerFactory { + @Lazy + @Autowired + private IDevMessageConfigService configService; + + public DevSmsManufacturer getMessageManufacturer(String projectSn) { + DevMessageConfig config = configService.getOne(new LambdaQueryWrapper() + .eq(DevMessageConfig::getProjectSn, projectSn) + ); + if (config == null) { + return null; + } + DevSmsManufacturer manufacturer = null; + if (Objects.equals(config.getMessageManufacturerType(), 1)) { + manufacturer = SpringContextUtils.getBean(TencentCloudDevSmsCall.class); + manufacturer.setConfig(config); + } else if (Objects.equals(config.getMessageManufacturerType(), 2)) { + manufacturer = SpringContextUtils.getBean(YunPianDevSmsCall.class); + manufacturer.setConfig(config); + } + return manufacturer; + } +} diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/LoginController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/LoginController.java index a91fd39de..cb988964f 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/LoginController.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/LoginController.java @@ -259,7 +259,7 @@ public class LoginController { messageManufacturer.getConfig().getSignature(), randomNum); List phoneNums = new ArrayList<>(); phoneNums.add(user.getUserTel()); - messageManufacturer.sendMsgByConfig(phoneNums, 3, templateParams, text); + messageManufacturer.sendMsgByConfig(phoneNums, messageManufacturer.getConfig().getSecretId(), templateParams, text); return Result.ok(); } else { throw new OpenAlertException("短信没配置或没启动短信登录"); @@ -288,7 +288,7 @@ public class LoginController { if (hashValue == null) { throw new OpenAlertException("短信验证码已过期"); } else { - if (!hashValue.get("num").toString().equals(MapUtils.getString(map,"verificationCode"))) { + if (!hashValue.get("num").toString().equals(MapUtils.getString(map, "verificationCode"))) { throw new OpenAlertException("短信验证码不正确"); } } diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/entity/bo/NoticeMessagePromptTone.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/entity/bo/NoticeMessagePromptTone.java new file mode 100644 index 000000000..8b854a8fb --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/entity/bo/NoticeMessagePromptTone.java @@ -0,0 +1,29 @@ +package com.zhgd.xmgl.modules.basicdata.entity.bo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 消息提示音 + */ +@Data +public class NoticeMessagePromptTone { + /** + * 消息提示音配置 + */ + @ApiModelProperty(value = "消息提示音配置") + private java.lang.String messagePromptToneConfig; + /** + * 播放频率 + */ + @ApiModelProperty(value = "播放频率") + private java.lang.Integer playbackFrequency; + + public NoticeMessagePromptTone() { + } + + public NoticeMessagePromptTone(String messagePromptToneConfig, Integer playbackFrequency) { + this.messagePromptToneConfig = messagePromptToneConfig; + this.playbackFrequency = playbackFrequency; + } +} diff --git a/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/EnvironmentAlarmServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/EnvironmentAlarmServiceImpl.java index 197c38291..c9573670b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/EnvironmentAlarmServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/EnvironmentAlarmServiceImpl.java @@ -831,7 +831,7 @@ public class EnvironmentAlarmServiceImpl extends ServiceImpl vos = BeanUtil.copyToList(ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(list)), "id", "parentId", "children"), MessageDevListVo.class); String name = MapUtils.getString(param, "name"); if (StrUtil.isNotBlank(name)) { - vos = vos.stream().filter(vo -> vo.getName().contains(name)).collect(Collectors.toList()); + list = list.stream().filter(vo -> vo.getName().contains(name)).collect(Collectors.toList()); } + List vos = BeanUtil.copyToList(ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(list)), "id", "parentId", "children"), MessageDevListVo.class); return Result.success(vos); } @@ -200,7 +200,7 @@ public class EnableMessageDevController { @ApiImplicitParam(name = "monitoringModule", value = "监测模块:1:扬尘监测;2:AI监测", paramType = "body", required = true, dataType = "String"), }) @PostMapping(value = "/editStatus") - @DistributedLock(keyPrefix = "enable_message_dev_controller:", key = "#param.projectSn", tryLok = true, lockTime = 0) + @DistributedLock(keyPrefix = "enable_message_dev_controller:", key = "#param['projectSn']", tryLok = true, lockTime = 0) public Result editStatus(@RequestBody Map param) { String projectSn = MapUtils.getString(param, "projectSn"); Integer isEnable = MapUtils.getInteger(param, "isEnable"); diff --git a/src/main/java/com/zhgd/xmgl/modules/project/controller/EnableMessageDevRuleController.java b/src/main/java/com/zhgd/xmgl/modules/project/controller/EnableMessageDevRuleController.java index c2ba5a5b4..dc682eba3 100644 --- a/src/main/java/com/zhgd/xmgl/modules/project/controller/EnableMessageDevRuleController.java +++ b/src/main/java/com/zhgd/xmgl/modules/project/controller/EnableMessageDevRuleController.java @@ -155,22 +155,22 @@ public class EnableMessageDevRuleController { Map>> module2param2levelMap = enableMessageDevRuleService.queryList(param).stream().collect(Collectors.groupingBy(EnableMessageDevRule::getMonitoringModuleName, Collectors.groupingBy(EnableMessageDevRule::getMonitoringParameterName, Collectors.toMap(EnableMessageDevRule::getMonitoringLevelName, Function.identity(), (existing, replacement) -> existing)))); - if (Objects.equals(monitoringModule, ParamEnum.MessageModuleNameEnum.YCJC.getValue() + "")) { + if (Objects.equals(monitoringModule, ParamEnum.MessageModuleNameEnum.YCJC.getValue())) { List alarmTypes = environmentAlarmTypeService.list(); for (EnvironmentAlarmType alarmType : alarmTypes) { String bj = "报警"; String yj = "预警"; - rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, "扬尘监测", alarmType.getAlarmType(), bj)); - rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, "扬尘监测", alarmType.getAlarmType(), yj)); + rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), alarmType.getAlarmType(), bj)); + rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), alarmType.getAlarmType(), yj)); } - } else if (Objects.equals(monitoringModule, ParamEnum.MessageModuleNameEnum.AIJC.getValue() + "")) { + } else if (Objects.equals(monitoringModule, ParamEnum.MessageModuleNameEnum.AIJC.getValue())) { List dictList = dictionaryItemService.getDictList(DictionaryConstant.AI_ANALYSE_HARD_WARE_ALARM_RECORD_TYPE, projectSn); for (DictionaryItem item : dictList) { //问题等级,1一级,2二级,3三级,4四级 - rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, "AI监测", item.getName(), "一级")); - rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, "AI监测", item.getName(), "二级")); - rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, "AI监测", item.getName(), "三级")); - rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, "AI监测", item.getName(), "四级")); + rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "一级")); + rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "二级")); + rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "三级")); + rtList.add(getEnableMessageDevRuleVo(module2param2levelMap, ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), item.getName(), "四级")); } } Integer enableSmsNotification = MapUtils.getInteger(param, "enableSmsNotification"); diff --git a/src/main/java/com/zhgd/xmgl/modules/project/entity/EnableMessageDevRule.java b/src/main/java/com/zhgd/xmgl/modules/project/entity/EnableMessageDevRule.java index 48b35d85a..4dacbf814 100644 --- a/src/main/java/com/zhgd/xmgl/modules/project/entity/EnableMessageDevRule.java +++ b/src/main/java/com/zhgd/xmgl/modules/project/entity/EnableMessageDevRule.java @@ -10,6 +10,7 @@ import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; +import java.time.LocalTime; /** * @Description: 通知设备规则 @@ -83,12 +84,12 @@ public class EnableMessageDevRule implements Serializable { * 短信推送时间开始 */ @ApiModelProperty(value = "短信推送时间开始") - private java.util.Date smsPushTimeBegin; + private LocalTime smsPushTimeBegin; /** * 短信推送时间结束 */ @ApiModelProperty(value = "短信推送时间结束") - private java.util.Date smsPushTimeEnd; + private LocalTime smsPushTimeEnd; /** * 是否启用系统站内消息推送,1是,0否 */ @@ -100,14 +101,19 @@ public class EnableMessageDevRule implements Serializable { @ApiModelProperty(value = "消息推送频率,0:实时,1:1小时") private java.lang.Integer messagePushFrequency; /** - * 消息推送时间 + * 系统消息推送时间开始 */ - @ApiModelProperty(value = "消息推送时间") - private java.util.Date messagePushTime; + @ApiModelProperty(value = "系统消息推送时间开始") + private LocalTime messagePushTimeBegin; /** - * 消息模板内容 + * 系统消息推送时间结束 */ - @ApiModelProperty(value = "消息模板内容") + @ApiModelProperty(value = "系统消息推送时间结束") + private LocalTime messagePushTimeEnd; + /** + * 系统消息模板内容 + */ + @ApiModelProperty(value = "系统消息模板内容") private java.lang.String messageTemplateContent; /** * 是否启用系统站内消息提示音,1是,0否 @@ -125,9 +131,9 @@ public class EnableMessageDevRule implements Serializable { @ApiModelProperty(value = "播放频率") private java.lang.Integer playbackFrequency; /** - * 告警接收人ids(多个,分割) + * 系统告警接收人ids(多个,分割) */ - @ApiModelProperty(value = "告警接收人ids(多个,分割)") + @ApiModelProperty(value = "系统告警接收人ids(多个,分割)") private java.lang.String alarmRecipientIds; /** * 是否启用现场智能广播通知,1是,0否 @@ -158,4 +164,9 @@ public class EnableMessageDevRule implements Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "更新时间") private java.util.Date updateTime; + /** + * 短信告警接收人ids(多个,分割) + */ + @ApiModelProperty(value = "短信告警接收人ids(多个,分割)") + private java.lang.String smsAlarmRecipientIds; } diff --git a/src/main/java/com/zhgd/xmgl/modules/project/entity/MessageConfigV2.java b/src/main/java/com/zhgd/xmgl/modules/project/entity/MessageConfigV2.java index 014342915..ebbc3f688 100644 --- a/src/main/java/com/zhgd/xmgl/modules/project/entity/MessageConfigV2.java +++ b/src/main/java/com/zhgd/xmgl/modules/project/entity/MessageConfigV2.java @@ -88,5 +88,9 @@ public class MessageConfigV2 implements Serializable { */ @ApiModelProperty(value = "1短信登录推送配置发送短信0不发送") private java.lang.Integer enableLoginSend; - + /** + * 登录短信模板id + */ + @ApiModelProperty(value = "登录短信模板id") + private java.lang.String loginTemplateId; } diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerInfoAuditRecordController.java b/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerInfoAuditRecordController.java index 07bce8451..f71d3e047 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerInfoAuditRecordController.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerInfoAuditRecordController.java @@ -134,11 +134,12 @@ public class WorkerInfoAuditRecordController { @OperLog(operModul = "劳务管理",operType = "劳务人员审核通过",operDesc = "劳务人员审核通过") @ApiOperation(value = "审核通过", notes = "审核通过" , httpMethod="POST") @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "劳务人员-审核表ID", paramType = "body", required = true, dataType = "Integer"), - @ApiImplicitParam(name = "registerType", value = "登记方式,1PC录入,2手机端录入", paramType = "body", required = false, dataType = "String"), - @ApiImplicitParam(name = "accountType", value = "账号类型,1管理,2普通人员", paramType = "body", required = false, dataType = "String"), - @ApiImplicitParam(name = "ufaceDevId", value = "人脸设备表ID", paramType = "body", required = false, dataType = "String"), - }) + @ApiImplicitParam(name = "id", value = "劳务人员-审核表ID", paramType = "body", required = true, dataType = "Integer"), + @ApiImplicitParam(name = "registerType", value = "登记方式,1PC录入,2手机端录入", paramType = "body", required = false, dataType = "String"), + @ApiImplicitParam(name = "accountType", value = "账号类型,1管理,2普通人员", paramType = "body", required = false, dataType = "String"), + @ApiImplicitParam(name = "ufaceDevId", value = "人脸设备表ID", paramType = "body", required = false, dataType = "String"), + @ApiImplicitParam(name = "attendanceGroupV2Id", value = "考勤组id", paramType = "body", required = false, dataType = "String"), + }) @PostMapping(value = "/adoptWorkerInfo") public Result adoptWorkerInfo(@RequestBody Map map) { workerInfoAuditRecordService.adoptWorkerInfo(map); diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/entity/WorkerAttendanceGroupV2.java b/src/main/java/com/zhgd/xmgl/modules/worker/entity/WorkerAttendanceGroupV2.java index 2418be4dc..8e2c27b30 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/entity/WorkerAttendanceGroupV2.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/entity/WorkerAttendanceGroupV2.java @@ -52,4 +52,10 @@ public class WorkerAttendanceGroupV2 implements Serializable { */ @ApiModelProperty(value = "更新时间") private java.util.Date updateDate; + /** + * 1默认0不默认 + */ + @ApiModelProperty(value = "1默认0不默认") + private Integer isDefault; + } diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/service/impl/WorkerAttendanceGroupV2ServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/worker/service/impl/WorkerAttendanceGroupV2ServiceImpl.java index e86afda01..198d94998 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/service/impl/WorkerAttendanceGroupV2ServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/service/impl/WorkerAttendanceGroupV2ServiceImpl.java @@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.jeecg.common.system.query.QueryGenerator; +import com.zhgd.redis.lock.redisson.DistributedLock; import com.zhgd.xmgl.modules.worker.entity.WorkerAttendanceGroupV2; import com.zhgd.xmgl.modules.worker.entity.WorkerAttendanceRuleV2; import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; @@ -28,6 +29,7 @@ import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -84,18 +86,31 @@ public class WorkerAttendanceGroupV2ServiceImpl extends ServiceImpl() + .set(WorkerAttendanceGroupV2::getIsDefault, 0) + .eq(WorkerAttendanceGroupV2::getProjectSn, dto.getProjectSn()) + ); + } } @Override - public void edit(WorkerAttendanceGroupV2Dto workerAttendanceGroupV2Dto) { - WorkerAttendanceGroupV2 oldWorkerAttendanceGroupV2 = baseMapper.selectById(workerAttendanceGroupV2Dto.getId()); + @DistributedLock(keyPrefix = "worker_attendance_group_v2_dto:", key = "#dto.projectSn", tryLok = true, lockTime = 0) + public void edit(WorkerAttendanceGroupV2Dto dto) { + WorkerAttendanceGroupV2 oldWorkerAttendanceGroupV2 = baseMapper.selectById(dto.getId()); if (oldWorkerAttendanceGroupV2 == null) { throw new OpenAlertException("未找到对应实体"); } - baseMapper.updateById(workerAttendanceGroupV2Dto); + setIsNotDefault(dto); + baseMapper.updateById(dto); } @Override @@ -123,7 +138,7 @@ public class WorkerAttendanceGroupV2ServiceImpl extends ServiceImpl countMyTodo(@RequestBody Map map) { + return Result.success(qualityInspectionRecordService.countMyTodo(map)); + } + @ApiOperation(value = "安全问题统计具体数量列表", notes = "安全问题统计具体数量列表", httpMethod = "POST") @ApiImplicitParams({ @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "body", required = true, dataType = "String"), diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/vo/XzSecurityQualityInspectionRecordCountMyTodoVo.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/vo/XzSecurityQualityInspectionRecordCountMyTodoVo.java new file mode 100644 index 000000000..b87cdfaa6 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/vo/XzSecurityQualityInspectionRecordCountMyTodoVo.java @@ -0,0 +1,14 @@ +package com.zhgd.xmgl.modules.xz.security.entity.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class XzSecurityQualityInspectionRecordCountMyTodoVo { + @ApiModelProperty("未(待)整改数") + private Integer rectificationNum; + @ApiModelProperty("待(未)复查") + private Integer reviewNum; + @ApiModelProperty("待(未)核验") + private Integer verificationNum; +} diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/XzSecurityQualityInspectionRecordMapper.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/XzSecurityQualityInspectionRecordMapper.java index b16c1355a..3f0b2f14d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/XzSecurityQualityInspectionRecordMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/XzSecurityQualityInspectionRecordMapper.java @@ -266,4 +266,6 @@ public interface XzSecurityQualityInspectionRecordMapper extends BaseMapper countBigByDutyMajor(Map map); List countSmallByMonth(Map map); + + XzSecurityQualityInspectionRecordCountMyTodoVo countMyTodo(@Param("param") Map map); } diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/xml/XzSecurityQualityInspectionRecordMapper.xml b/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/xml/XzSecurityQualityInspectionRecordMapper.xml index 0f49f4efa..f44fa2fc9 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/xml/XzSecurityQualityInspectionRecordMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/mapper/xml/XzSecurityQualityInspectionRecordMapper.xml @@ -1180,4 +1180,17 @@ group by x_name + + diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/IXzSecurityQualityInspectionRecordService.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/IXzSecurityQualityInspectionRecordService.java index 5ffbe3581..55b16451d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/IXzSecurityQualityInspectionRecordService.java +++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/IXzSecurityQualityInspectionRecordService.java @@ -340,4 +340,6 @@ public interface IXzSecurityQualityInspectionRecordService extends IService map); ChartDataVo countSmallByMonth(Map map); + + XzSecurityQualityInspectionRecordCountMyTodoVo countMyTodo(Map map); } diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityQualityInspectionRecordServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityQualityInspectionRecordServiceImpl.java index 87dbdcd0f..d4b9cfc03 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityQualityInspectionRecordServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityQualityInspectionRecordServiceImpl.java @@ -1379,6 +1379,12 @@ public class XzSecurityQualityInspectionRecordServiceImpl extends ServiceImpl map) { + map.put("userId", SecurityUtils.getUser().getUserId()); + return baseMapper.countMyTodo(map); + } + private void recoverScore(XzSecurityQualityInspectionRecord hiddenDangerInspectRecord) { if (hiddenDangerInspectRecord.getRecordType() == null || Objects.equals(hiddenDangerInspectRecord.getRecordType(), XzSecurityQualityInspectionRecordRecordTypeEnum.RECORD.getValue())) { return; diff --git a/src/main/java/com/zhgd/xmgl/task/MessageDevRuleTask.java b/src/main/java/com/zhgd/xmgl/task/MessageDevRuleTask.java index 6053ed3bd..1a5115af4 100644 --- a/src/main/java/com/zhgd/xmgl/task/MessageDevRuleTask.java +++ b/src/main/java/com/zhgd/xmgl/task/MessageDevRuleTask.java @@ -1,28 +1,235 @@ package com.zhgd.xmgl.task; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.zhgd.xmgl.call.api.DevSmsManufacturer; +import com.zhgd.xmgl.call.factory.DevSmsManufacturerFactory; +import com.zhgd.xmgl.enums.ParamEnum; +import com.zhgd.xmgl.modules.basicdata.constant.DictionaryConstant; +import com.zhgd.xmgl.modules.basicdata.entity.DictionaryItem; +import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; +import com.zhgd.xmgl.modules.basicdata.entity.bo.NoticeMessagePromptTone; +import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; +import com.zhgd.xmgl.modules.basicdata.service.impl.DictionaryItemServiceImpl; +import com.zhgd.xmgl.modules.basicdata.service.impl.NoticeServiceImpl; +import com.zhgd.xmgl.modules.environment.entity.EnvironmentAlarm; +import com.zhgd.xmgl.modules.environment.entity.EnvironmentAlarmType; +import com.zhgd.xmgl.modules.environment.service.IEnvironmentAlarmService; +import com.zhgd.xmgl.modules.environment.service.IEnvironmentAlarmTypeService; +import com.zhgd.xmgl.modules.project.entity.EnableMessageDevRule; +import com.zhgd.xmgl.modules.project.entity.Project; +import com.zhgd.xmgl.modules.project.service.IEnableMessageDevRuleService; +import com.zhgd.xmgl.modules.project.service.IProjectService; +import com.zhgd.xmgl.modules.video.entity.AiAnalyseHardWareAlarmRecord; +import com.zhgd.xmgl.modules.video.service.IAiAnalyseHardWareAlarmRecordService; +import com.zhgd.xmgl.modules.xz.entity.XzAiDeductRule; +import com.zhgd.xmgl.modules.xz.service.IXzAiDeductRuleService; import lombok.extern.slf4j.Slf4j; import net.javacrumbs.shedlock.core.SchedulerLock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + @Slf4j @Component @RestController @RequestMapping("xmgl/task") public class MessageDevRuleTask { + @Lazy + @Autowired + ISystemUserService systemUserService; + @Lazy + @Autowired + private DevSmsManufacturerFactory devSmsManufacturerFactory; + @Lazy + @Resource + private IEnvironmentAlarmService environmentAlarmService; + @Lazy + @Autowired + private IEnableMessageDevRuleService enableMessageDevRuleService; + @Lazy + @Autowired + private IEnvironmentAlarmTypeService environmentAlarmTypeService; + @Lazy + @Autowired + private NoticeServiceImpl noticeService; + @Lazy + @Autowired + private IAiAnalyseHardWareAlarmRecordService aiAnalyseHardWareAlarmRecordService; + @Lazy + @Autowired + private DictionaryItemServiceImpl dictionaryItemService; + @Lazy + @Autowired + private IProjectService projectService; + @Lazy + @Autowired + private IXzAiDeductRuleService xzAiDeductRuleService; + + /** + * 发送设备的报警通知 + */ + @SchedulerLock(name = "sendDevMessage", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5) + @Scheduled(cron = "0 0 */1 * * ?") + @RequestMapping("sendDevMessage") + public void sendDevMessage() { + try { + Map environmentTypeMap = environmentAlarmTypeService.list().stream().collect(Collectors.toMap(EnvironmentAlarmType::getId, Function.identity(), (o1, o2) -> o1)); + List projects = projectService.list(new LambdaQueryWrapper()); + Map>>> devSn2Parameter2LevelEnvironmentAlarmMap = environmentAlarmService.list(new LambdaQueryWrapper() + .ge(EnvironmentAlarm::getAlarmTime, DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -1))) + .le(EnvironmentAlarm::getAlarmTime, new Date()) + ).stream().collect(Collectors.groupingBy(EnvironmentAlarm::getDeviceId, + Collectors.groupingBy(ea -> environmentTypeMap.get(ea.getAlarmTypeId()).getAlarmType(), + Collectors.groupingBy(ea -> Objects.equals(ea.getType(), 0) ? "报警" : "预警")))); + List ruleList = enableMessageDevRuleService.list(new LambdaQueryWrapper().eq(EnableMessageDevRule::getIsEnabled, 1)); + Map userMap = systemUserService.list(new LambdaQueryWrapper()).stream().collect(Collectors.toMap(SystemUser::getUserId, Function.identity(), (o1, o2) -> o1)); + Map> moduleMap = ruleList.stream().collect(Collectors.groupingBy(EnableMessageDevRule::getMonitoringModuleName)); + for (Project project : projects) { + List dictList = dictionaryItemService.getDictList(DictionaryConstant.AI_ANALYSE_HARD_WARE_ALARM_RECORD_TYPE, project.getProjectSn()); + Map dictDataMap = dictList.stream().collect(Collectors.toMap(DictionaryItem::getData, Function.identity(), (o1, o2) -> o1)); + Map dicIdMap = xzAiDeductRuleService.list(new LambdaQueryWrapper() + .eq(XzAiDeductRule::getProjectSn, project.getProjectSn())).stream().collect(Collectors.toMap(XzAiDeductRule::getDictionaryItemId, Function.identity(), (o1, o2) -> o1)); + Map>>> devSn2Parameter2LevelAiMap = aiAnalyseHardWareAlarmRecordService.list(new LambdaQueryWrapper() + .ge(AiAnalyseHardWareAlarmRecord::getCreateTime, DateUtil.formatDateTime(DateUtil.offsetDay(new Date(), -1))) + .le(AiAnalyseHardWareAlarmRecord::getCreateTime, new Date()) + ).stream().filter(r -> { + return Objects.nonNull(Optional.ofNullable(dictDataMap.get(Convert.toStr(r.getAlarmType()))).map(m -> dicIdMap.get(m.getId())).map(XzAiDeductRule::getLevel).orElse(null)); + }).collect(Collectors.groupingBy(AiAnalyseHardWareAlarmRecord::getHardwareId, + Collectors.groupingBy(r1 -> dictDataMap.get(Convert.toStr(r1.getAlarmType())).getName(), + Collectors.groupingBy(r -> Optional.of(dictDataMap.get(Convert.toStr(r.getAlarmType()))).map(m -> dicIdMap.get(m.getId())).map(r1 -> { + if (Objects.equals(r1.getLevel(), 1)) { + return "一级"; + } else if (Objects.equals(r1.getLevel(), 2)) { + return "二级"; + } else if (Objects.equals(r1.getLevel(), 3)) { + return "三级"; + } else { + return "四级"; + } + }).orElse(null))))); + for (Map.Entry> moduleEntry : moduleMap.entrySet()) { + List entryRules = moduleEntry.getValue(); + for (EnableMessageDevRule rule : entryRules) { + //扬尘 + if (Objects.equals(ParamEnum.MessageModuleNameEnum.YCJC.getDesc(), moduleEntry.getKey())) { + List filterAlarms = Optional.ofNullable(devSn2Parameter2LevelEnvironmentAlarmMap.get(rule.getDevSn())) + .map(m -> m.get(rule.getMonitoringParameterName())).map(m -> m.get(rule.getMonitoringLevelName())).orElse(new ArrayList<>()); + filterAlarms = filterAlarms.stream().filter(alarm -> + DateUtil.compare(alarm.getAlarmTime(), DateUtil.offsetHour(new Date(), rule.getSmsPushFrequency() * -1)) >= 0 + && DateUtil.compare(alarm.getAlarmTime(), new Date()) <= 0).collect(Collectors.toList()); + //sms + if (CollUtil.isNotEmpty(filterAlarms)) { + sendNotice(rule, filterAlarms.size(), userMap, "7"); + } + } + + //AI + if (Objects.equals(ParamEnum.MessageModuleNameEnum.AIJC.getDesc(), moduleEntry.getKey())) { + List filterAlarms = Optional.ofNullable(devSn2Parameter2LevelAiMap.get(rule.getDevSn())) + .map(m -> m.get(rule.getMonitoringParameterName())).map(m -> m.get(rule.getMonitoringLevelName())).orElse(new ArrayList<>()); + filterAlarms = filterAlarms.stream().filter(alarm -> + DateUtil.compare(DateUtil.parse(alarm.getCreateTime()), DateUtil.offsetHour(new Date(), rule.getSmsPushFrequency() * -1)) >= 0 + && DateUtil.compare(DateUtil.parse(alarm.getCreateTime()), new Date()) <= 0).collect(Collectors.toList()); + //sms + if (CollUtil.isNotEmpty(filterAlarms)) { + sendNotice(rule, filterAlarms.size(), userMap, "8"); + } + } + } + } + } + } catch (Exception e) { + log.error("发送设备的报警通知", e); + } + } + /** * 发送通知 + * + * @param rule + * @param filterAlarms + * @param userMap + * @param type */ - @SchedulerLock(name = "sendMessage", lockAtMostFor = 1000 * 60 * 60, lockAtLeastFor = 1000 * 60 * 5) - @Scheduled(cron = "0 0 */1 * * ?") - @RequestMapping("sendMessage") - public void sendMessage() { -// List environmentAlarms; -// List ruleList; -// Map> moduleMap = ruleList.stream().collect(Collectors.groupingBy(EnableMessageDevRule::getMonitoringModuleName)); + private void sendNotice(EnableMessageDevRule rule, int filterAlarms, Map userMap, String type) { + if (Objects.equals(rule.getEnableSmsNotification(), 1) && isSmsSendTime(rule)) { + DevSmsManufacturer messageManufacturer = devSmsManufacturerFactory.getMessageManufacturer(rule.getProjectSn()); + if (messageManufacturer != null) { + String text = StrUtil.format("{}{}{}异常,近{}小时累计报警{}次!", + rule.getMonitoringModuleName(), rule.getMonitoringParameterName(), rule.getMonitoringLevelName(), rule.getSmsPushFrequency(), filterAlarms); + List phoneNums = getPhoneNums(rule.getSmsAlarmRecipientIds(), userMap); + if (CollUtil.isNotEmpty(phoneNums)) { + messageManufacturer.sendMsg(phoneNums, rule.getNotificationSmsTemplateId(), null, text); + } + } + } + //系统站内 + if (Objects.equals(rule.getEnableSystemMessagePush(), 1) && isSystemSendTime(rule)) { + if (StrUtil.isNotBlank(rule.getAlarmRecipientIds())) { + List ids = StrUtil.split(rule.getAlarmRecipientIds(), ",").stream().map(Convert::toLong).collect(Collectors.toList()); + NoticeMessagePromptTone tone = null; + //系统站内声音提示 + if (Objects.equals(rule.getEnableSystemMessagePromptTone(), 1)) { + tone = new NoticeMessagePromptTone(rule.getMessagePromptToneConfig(), rule.getPlaybackFrequency()); + } + for (Long id : ids) { + noticeService.addUserNoticeAndApp(id, "设备报警通知", rule.getMessageTemplateContent(), type, tone); + } + } + } + } + /** + * 是需要发送的时间了 + * + * @param rule + * @return + */ + private boolean isSystemSendTime(EnableMessageDevRule rule) { + int hour = DateUtil.hour(new Date(), true); + return Objects.nonNull(rule.getMessagePushFrequency()) && Objects.nonNull(rule.getMessagePushTimeBegin()) && Objects.nonNull(rule.getMessagePushTimeEnd()) + && !Objects.equals(rule.getMessagePushFrequency(), 0) && hour % rule.getMessagePushFrequency() == 0 + && rule.getMessagePushTimeBegin().getHour() <= hour && rule.getMessagePushTimeEnd().getHour() >= hour; + } + + /** + * 是需要发送的时间了 + * + * @param rule + * @return + */ + private boolean isSmsSendTime(EnableMessageDevRule rule) { + int hour = DateUtil.hour(new Date(), true); + return Objects.nonNull(rule.getSmsPushFrequency()) && Objects.nonNull(rule.getSmsPushTimeBegin()) && Objects.nonNull(rule.getSmsPushTimeEnd()) + && !Objects.equals(rule.getSmsPushFrequency(), 0) && hour % rule.getSmsPushFrequency() == 0 + && rule.getSmsPushTimeBegin().getHour() <= hour && rule.getSmsPushTimeEnd().getHour() >= hour; + } + + /** + * 获取发送短信的号码 + * + * @param smsAlarmRecipientIds + * @param userMap + * @return + */ + private List getPhoneNums(String smsAlarmRecipientIds, Map userMap) { + if (StrUtil.isBlank(smsAlarmRecipientIds)) { + return null; + } + return StrUtil.split(smsAlarmRecipientIds, ",").stream().filter(id -> userMap.containsKey(Convert.toLong(id))).map(id -> userMap.get(Convert.toLong(id)).getUserTel()) + .filter(StrUtil::isNotBlank).collect(Collectors.toList()); } }