|
@@ -9,7 +9,9 @@ import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.xy.consumer.MqttConsumer;
|
|
import com.xy.consumer.MqttConsumer;
|
|
|
|
+import com.xy.dto.MsgConfigDto;
|
|
import com.xy.dto.MsgConfigTestDto;
|
|
import com.xy.dto.MsgConfigTestDto;
|
|
|
|
+import com.xy.dto.MsgSysMonitorNoticeDto;
|
|
import com.xy.dto.UserInfoDto;
|
|
import com.xy.dto.UserInfoDto;
|
|
import com.xy.dto.be.MercDto;
|
|
import com.xy.dto.be.MercDto;
|
|
import com.xy.dto.be.MercUserDeviceDto;
|
|
import com.xy.dto.be.MercUserDeviceDto;
|
|
@@ -17,9 +19,8 @@ import com.xy.entity.DeviceEventMsg;
|
|
import com.xy.entity.DeviceInfo;
|
|
import com.xy.entity.DeviceInfo;
|
|
import com.xy.entity.SysCodeConfigureRedis;
|
|
import com.xy.entity.SysCodeConfigureRedis;
|
|
import com.xy.enums.ChannelType;
|
|
import com.xy.enums.ChannelType;
|
|
-import com.xy.service.DeviceInfoServiceImpl;
|
|
|
|
-import com.xy.service.MsgSendApiService;
|
|
|
|
-import com.xy.service.UserInfoService;
|
|
|
|
|
|
+import com.xy.enums.MsgType;
|
|
|
|
+import com.xy.service.*;
|
|
import com.xy.service.be.MercFeignService;
|
|
import com.xy.service.be.MercFeignService;
|
|
import com.xy.utils.R;
|
|
import com.xy.utils.R;
|
|
import com.xy.utils.SysCodeConfigureUtils;
|
|
import com.xy.utils.SysCodeConfigureUtils;
|
|
@@ -28,7 +29,10 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@@ -47,6 +51,8 @@ public class DevicePushMsgConsumer implements MqttConsumer {
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
private MercFeignService mercFeignService;
|
|
private MercFeignService mercFeignService;
|
|
private UserInfoService userInfoService;
|
|
private UserInfoService userInfoService;
|
|
|
|
+ private MsgSysMonitorNoticeService msgSysMonitorNoticeService;
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean message(String topic, String payload) {
|
|
public boolean message(String topic, String payload) {
|
|
@@ -58,54 +64,75 @@ public class DevicePushMsgConsumer implements MqttConsumer {
|
|
LocalDateTime createTime = deviceEventMsg.getCreateTime();
|
|
LocalDateTime createTime = deviceEventMsg.getCreateTime();
|
|
String msg = deviceEventMsg.getMsg();
|
|
String msg = deviceEventMsg.getMsg();
|
|
SysCodeConfigureRedis sysCodeConfigureRedis = SysCodeConfigureUtils.get(deviceEventMsg.getCode());
|
|
SysCodeConfigureRedis sysCodeConfigureRedis = SysCodeConfigureUtils.get(deviceEventMsg.getCode());
|
|
-
|
|
|
|
Long configId = 12L;
|
|
Long configId = 12L;
|
|
|
|
+ MsgConfigDto.Vo msgConfig = R.feignCheckData(msgSendApiService.getMsgConfig(new MsgConfigDto.Vo().setId(configId)));
|
|
List<MsgConfigTestDto.BizParam> bizParams = R.feignCheckData(msgSendApiService.getBizParamByMsgConfig(new MsgConfigTestDto.MsgConfig().setConfigId(configId)));
|
|
List<MsgConfigTestDto.BizParam> bizParams = R.feignCheckData(msgSendApiService.getBizParamByMsgConfig(new MsgConfigTestDto.MsgConfig().setConfigId(configId)));
|
|
- if (CollUtil.isNotEmpty(bizParams)) {
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(bizParams) && msgConfig != null) {
|
|
List<MsgConfigTestDto.BizData> bizDataList = BeanUtil.copyToList(bizParams, MsgConfigTestDto.BizData.class);
|
|
List<MsgConfigTestDto.BizData> bizDataList = BeanUtil.copyToList(bizParams, MsgConfigTestDto.BizData.class);
|
|
List<MsgConfigTestDto.BizData> sendList = new ArrayList<>();
|
|
List<MsgConfigTestDto.BizData> sendList = new ArrayList<>();
|
|
|
|
+ /**
|
|
|
|
+ * {{first.DATA}}
|
|
|
|
+ * 设备名称:{{keyword1.DATA}}
|
|
|
|
+ * 告警内容:{{keyword2.DATA}}
|
|
|
|
+ * 发生时间:{{keyword3.DATA}}
|
|
|
|
+ * {{remark.DATA}}
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(deviceId);
|
|
|
|
+ String deviceName = deviceInfo.getDeviceName();
|
|
|
|
+ if (StrUtil.isEmpty(deviceName)) {
|
|
|
|
+ deviceName = deviceId + "";
|
|
|
|
+ } else {
|
|
|
|
+ deviceName = deviceName + "(" + deviceId + ")";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ MercDto.Vo merc = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setId(mercId)));
|
|
|
|
+ Long userInfoId = merc.getUserInfoId();
|
|
|
|
+ List<Long> userInfoIdList = new ArrayList<>();
|
|
|
|
+ userInfoIdList.add(userInfoId);
|
|
|
|
+ List<MercUserDeviceDto.Vo> mercUserDevices = R.feignCheckData(mercFeignService.mercDeviceUsers(
|
|
|
|
+ new MercUserDeviceDto.Vo().setMercId(mercId).setDeviceId(deviceId)));
|
|
|
|
+ if (CollUtil.isNotEmpty(mercUserDevices)) {
|
|
|
|
+ List<Long> uids = mercUserDevices.stream().map(MercUserDeviceDto.Vo::getUserId).collect(Collectors.toList());
|
|
|
|
+ if (CollUtil.isNotEmpty(uids)) {
|
|
|
|
+ userInfoIdList.addAll(uids);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ StringBuilder sbMsg = StrUtil.builder().append("设备")
|
|
|
|
+ .append("【")
|
|
|
|
+ .append(deviceName)
|
|
|
|
+ .append("】")
|
|
|
|
+ .append("发生故障:").append(msg).append(",发生时间:")
|
|
|
|
+ .append(DateUtil.format(createTime, DatePattern.NORM_DATETIME_PATTERN));
|
|
|
|
+ //查询userinfo表的mpOpenId
|
|
|
|
+ List<UserInfoDto.Vo> userInfoList = R.feignCheckData(userInfoService.list(new UserInfoDto.SelectListDto().setUserIds(userInfoIdList)));
|
|
|
|
+ userInfoList.forEach(u -> {
|
|
|
|
+ String name = u.getName();
|
|
|
|
+ //系统消息
|
|
|
|
+ MsgSysMonitorNoticeDto.Save msgSys = new MsgSysMonitorNoticeDto.Save();
|
|
|
|
+ msgSys.setUserId(u.getAuthorizeUserId());
|
|
|
|
+ msgSys.setMsgType(MsgType.TYPE6.getCode()).setContent(sbMsg.toString())
|
|
|
|
+ .setPubTime(LocalDateTime.now()).setPubState(2)
|
|
|
|
+ .setSendTargets(name)
|
|
|
|
+ .setPriority(msgConfig.getPriority())
|
|
|
|
+ .setTitle(msgConfig.getTitle())
|
|
|
|
+ .setPubUserId(-1).setTitle(MsgType.TYPE6.getDescription());
|
|
|
|
+ msgSysMonitorNoticeService.save(msgSys);
|
|
|
|
+ });
|
|
|
|
+
|
|
for (MsgConfigTestDto.BizData b : bizDataList) {
|
|
for (MsgConfigTestDto.BizData b : bizDataList) {
|
|
String channelType = b.getChannelType();
|
|
String channelType = b.getChannelType();
|
|
if (Integer.valueOf(channelType).intValue() == ChannelType.OFFICIAL_ACCOUNT.getCode().intValue()) {
|
|
if (Integer.valueOf(channelType).intValue() == ChannelType.OFFICIAL_ACCOUNT.getCode().intValue()) {
|
|
//TODO: 暂无订阅功能。给商户管理员、以及有此设备权限的人推送消息, 查询微信公众号openID
|
|
//TODO: 暂无订阅功能。给商户管理员、以及有此设备权限的人推送消息, 查询微信公众号openID
|
|
- MercDto.Vo merc = R.feignCheckData(mercFeignService.obj(new MercDto.ListDTO().setId(mercId)));
|
|
|
|
- Long userInfoId = merc.getUserInfoId();
|
|
|
|
- List<Long> userInfoIdList = new ArrayList<>();
|
|
|
|
- userInfoIdList.add(userInfoId);
|
|
|
|
- List<MercUserDeviceDto.Vo> mercUserDevices = R.feignCheckData(mercFeignService.mercDeviceUsers(
|
|
|
|
- new MercUserDeviceDto.Vo().setMercId(mercId).setDeviceId(deviceId)));
|
|
|
|
- if (CollUtil.isNotEmpty(mercUserDevices)) {
|
|
|
|
- List<Long> uids = mercUserDevices.stream().map(MercUserDeviceDto.Vo::getUserId).collect(Collectors.toList());
|
|
|
|
- if (CollUtil.isNotEmpty(uids)) {
|
|
|
|
- userInfoIdList.addAll(uids);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //查询userinfo表的mpOpenId
|
|
|
|
- List<UserInfoDto.Vo> userInfoList = R.feignCheckData(userInfoService.list(new UserInfoDto.SelectListDto().setUserIds(userInfoIdList)));
|
|
|
|
|
|
|
|
- Set<String> mpOpenIds = userInfoList.stream().filter(Objects::nonNull)
|
|
|
|
|
|
+ Set<String> mpOpenIds = userInfoList.stream().filter(u -> ObjectUtil.isNotEmpty(u.getMpOpenid()))
|
|
.map(UserInfoDto.Vo::getMpOpenid)
|
|
.map(UserInfoDto.Vo::getMpOpenid)
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
|
+
|
|
if (CollUtil.isEmpty(mpOpenIds)) {
|
|
if (CollUtil.isEmpty(mpOpenIds)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * {{first.DATA}}
|
|
|
|
- * 设备名称:{{keyword1.DATA}}
|
|
|
|
- * 告警内容:{{keyword2.DATA}}
|
|
|
|
- * 发生时间:{{keyword3.DATA}}
|
|
|
|
- * {{remark.DATA}}
|
|
|
|
- *
|
|
|
|
- */
|
|
|
|
- DeviceInfo deviceInfo = deviceInfoService.getById(deviceId);
|
|
|
|
- String deviceName = deviceInfo.getDeviceName();
|
|
|
|
- if (StrUtil.isEmpty(deviceName)) {
|
|
|
|
- deviceName = deviceId + "";
|
|
|
|
- } else {
|
|
|
|
- deviceName = deviceName + "(" + deviceId + ")";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//微信公众号
|
|
//微信公众号
|
|
//扩展参数
|
|
//扩展参数
|
|
MsgConfigTestDto.BizExtraParam bizExtraParam = new MsgConfigTestDto.BizExtraParam();
|
|
MsgConfigTestDto.BizExtraParam bizExtraParam = new MsgConfigTestDto.BizExtraParam();
|