|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
@@ -12,6 +13,7 @@ import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.xy.config.DeviceThreadPoolConfig;
|
|
|
+import com.xy.consts.MercConstant;
|
|
|
import com.xy.device.EnumDeviceOnlineStatus;
|
|
|
import com.xy.dto.*;
|
|
|
import com.xy.dto.be.MercDto;
|
|
@@ -20,9 +22,11 @@ import com.xy.entity.*;
|
|
|
import com.xy.enums.ChannelType;
|
|
|
import com.xy.enums.MsgConfigId;
|
|
|
import com.xy.enums.MsgType;
|
|
|
+import com.xy.enums.SmsSceneEnum;
|
|
|
import com.xy.event.DeviceEvent;
|
|
|
import com.xy.service.be.MercFeignService;
|
|
|
import com.xy.utils.*;
|
|
|
+import com.xy.utils.enums.DeviceErrorRecordTypesEnum;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
@@ -39,6 +43,7 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
@Api(tags = "设备消费者")
|
|
|
public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
+ private AliSmsService aliSmsService;
|
|
|
|
|
|
private MsgSendApiService msgSendApiService;
|
|
|
|
|
@@ -53,6 +58,8 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
private DeviceFaultLogServiceImpl deviceFaultLogService;
|
|
|
|
|
|
private DeviceFaultInfoServiceImpl deviceFaultInfoService;
|
|
|
+ private MercSmsSubscriptionService mercSmsSubscriptionService;
|
|
|
+ private MercSmsPackageService mercSmsService;
|
|
|
|
|
|
@Override
|
|
|
@ApiOperation("设备在线")
|
|
@@ -102,6 +109,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
if (MercAuthUtils.sendMsgToCM(mercCode)) {
|
|
|
configId = MsgConfigId.CM_DEVICE_EXCEPTION.getId();
|
|
|
}
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(deviceId);
|
|
|
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)));
|
|
|
if (CollUtil.isNotEmpty(bizParams) && msgConfig != null) {
|
|
@@ -115,7 +123,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
* {{remark.DATA}}
|
|
|
*
|
|
|
*/
|
|
|
- DeviceInfo deviceInfo = deviceInfoService.getById(deviceId);
|
|
|
+
|
|
|
String deviceName = deviceInfo.getDeviceName();
|
|
|
if (StrUtil.isEmpty(deviceName)) {
|
|
|
deviceName = deviceId + "";
|
|
@@ -130,7 +138,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
if (CollUtil.isNotEmpty(mercUserDevices)) {
|
|
|
mercUserDevices.forEach(mud -> {
|
|
|
Long deviceIdUser = mud.getDeviceId();
|
|
|
- if (deviceId == deviceIdUser) {
|
|
|
+ if (Objects.equals(deviceId, deviceIdUser)) {
|
|
|
userInfoIdList.add(mud.getUserId());
|
|
|
}
|
|
|
});
|
|
@@ -204,9 +212,78 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
msgSendApiService.sendByMsgConfig(new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(sendList));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //短信通知
|
|
|
+ deviceSmsPushMsg(merc,deviceInfo,createTime,code);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 商户设备异常短信通知
|
|
|
+ * @param merc
|
|
|
+ * @param deviceInfo
|
|
|
+ * @param createTime
|
|
|
+ * @param eventCode
|
|
|
+ */
|
|
|
+ public void deviceSmsPushMsg(MercDto.Vo merc,DeviceInfo deviceInfo,LocalDateTime createTime,String eventCode) {
|
|
|
+
|
|
|
+ Long deviceId = deviceInfo.getDeviceId();
|
|
|
+ String deviceName = deviceInfo.getDeviceName();
|
|
|
+ if (StrUtil.isEmpty(deviceName)) {
|
|
|
+ deviceName = deviceId + "";
|
|
|
+ } else {
|
|
|
+ deviceName = deviceName + "(" + deviceId + ")";
|
|
|
+ }
|
|
|
+ String exceptionType="";
|
|
|
+ //商家是否订阅
|
|
|
+ if(DeviceErrorRecordTypesEnum.T.getCode().equals(eventCode)) {
|
|
|
+ exceptionType = "温度";
|
|
|
+ }else if(DeviceErrorRecordTypesEnum.NET.getCode().equals(eventCode)){
|
|
|
+ exceptionType="网络";
|
|
|
+ }else if(DeviceErrorRecordTypesEnum.DOOR_LOCK.getCode().equals(eventCode)){
|
|
|
+ exceptionType="门锁";
|
|
|
+ }else if(DeviceErrorRecordTypesEnum.LIGHT.getCode().equals(eventCode)){
|
|
|
+ exceptionType="灯光";
|
|
|
+ }else if(DeviceErrorRecordTypesEnum.CAMERA.getCode().equals(eventCode)){
|
|
|
+ exceptionType="摄像头";
|
|
|
+ }else if(DeviceErrorRecordTypesEnum.COMPRESSOR.getCode().equals(eventCode)){
|
|
|
+ exceptionType="压缩机";
|
|
|
+ }else{
|
|
|
+ log.info("设备告警短信通知:异常类型未配置,eventCode{}",eventCode);
|
|
|
+ }
|
|
|
+ //温度异常
|
|
|
+ Boolean b = R.feignCheckData(mercSmsSubscriptionService.isSubscribedByCode(new MercSmsSubscriptionDto.Vo().setMercId(merc.getId()).setEventCode(eventCode)));
|
|
|
+ boolean isSubscribed = BooleanUtil.isTrue(b);
|
|
|
+ //商户是否订阅短信通知
|
|
|
+ if(isSubscribed&&StrUtil.isNotEmpty(exceptionType)){
|
|
|
+ UserInfoDto.Vo userInfo = R.feignCheckData(userInfoService.obj(new UserInfoDto.Vo().setUserId(merc.getUserInfoId())));
|
|
|
+ if(userInfo!= null && StrUtil.isNotEmpty(userInfo.getTel())){
|
|
|
+ String tel = userInfo.getTel();
|
|
|
+ //短信推送 设备告警:设备${device_id}于${time}发生${exception_type}异常。请登录后台查看详情并及时处理。
|
|
|
+ Long configId = MsgConfigId.SMS_NOTIFY_DEVICE.getId();
|
|
|
+ String formatDate = LocalDateTimeUtil.format(createTime, DatePattern.NORM_DATE_PATTERN);
|
|
|
+ Map<String, Object> templateParams = MapUtil.newHashMap();
|
|
|
+ templateParams.put("device_id", deviceName);
|
|
|
+ templateParams.put("time", formatDate);
|
|
|
+ templateParams.put("exception_type", exceptionType);
|
|
|
+ log.info("商户设备告警短信通知:{}", JSONUtil.toJsonPrettyStr(templateParams));
|
|
|
+ // 扣除商户短信资源包
|
|
|
+ R deduct = mercSmsService.deduct(new MercSmsPackageDto.Deduct()
|
|
|
+ .setMercId(merc.getId())
|
|
|
+ .setMsg("设备告警短信通知,设备号:" + deviceId)
|
|
|
+ );
|
|
|
+ if (deduct.getCode() == R.Enum.SUCCESS.getCode()) {
|
|
|
+ R.feignCheck(aliSmsService.sendMsgCommon(new SmsSendCommonDTO().setSignName("").setMsgConfigId(configId).setMobile(tel).setTemplateParams(templateParams).setScene(SmsSceneEnum.B_DEVICE_ALARM_NOTIFY.getScene())));
|
|
|
+ }else{
|
|
|
+ log.info("设备告警短信通知#商户{}短信资源包不足,无法发送短信通知:{}",merc.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设备故障
|
|
|
*
|