|
@@ -4,7 +4,6 @@ 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;
|
|
@@ -13,7 +12,6 @@ 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;
|
|
@@ -22,11 +20,9 @@ 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;
|
|
@@ -43,7 +39,6 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
@Api(tags = "设备消费者")
|
|
|
public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
- private AliSmsService aliSmsService;
|
|
|
|
|
|
private MsgSendApiService msgSendApiService;
|
|
|
|
|
@@ -58,8 +53,6 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
private DeviceFaultLogServiceImpl deviceFaultLogService;
|
|
|
|
|
|
private DeviceFaultInfoServiceImpl deviceFaultInfoService;
|
|
|
- private MercSmsSubscriptionService mercSmsSubscriptionService;
|
|
|
- private MercSmsPackageService mercSmsService;
|
|
|
|
|
|
@Override
|
|
|
@ApiOperation("设备在线")
|
|
@@ -80,7 +73,6 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
@Override
|
|
|
@ApiOperation("设备消息推送")
|
|
|
public void devicePushMsg(DeviceMqttDto.RequestParams requestParams) {
|
|
|
- log.info("设备消息推送MQTT:{}", JSONUtil.toJsonPrettyStr(requestParams));
|
|
|
DeviceEventMsg deviceEventMsg = JSONUtil.toBean(requestParams.getData(), DeviceEventMsg.class);
|
|
|
if (deviceEventMsg != null) {
|
|
|
Long deviceId = deviceEventMsg.getDeviceId();
|
|
@@ -110,7 +102,6 @@ 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) {
|
|
@@ -124,7 +115,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
* {{remark.DATA}}
|
|
|
*
|
|
|
*/
|
|
|
-
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(deviceId);
|
|
|
String deviceName = deviceInfo.getDeviceName();
|
|
|
if (StrUtil.isEmpty(deviceName)) {
|
|
|
deviceName = deviceId + "";
|
|
@@ -139,7 +130,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
if (CollUtil.isNotEmpty(mercUserDevices)) {
|
|
|
mercUserDevices.forEach(mud -> {
|
|
|
Long deviceIdUser = mud.getDeviceId();
|
|
|
- if (Objects.equals(deviceId, deviceIdUser)) {
|
|
|
+ if (deviceId == deviceIdUser) {
|
|
|
userInfoIdList.add(mud.getUserId());
|
|
|
}
|
|
|
});
|
|
@@ -217,88 +208,7 @@ public class DeviceMqttConsumerImpl implements DeviceMqttConsumer {
|
|
|
msgSendApiService.sendByMsgConfig(new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(sendList));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- //短信通知
|
|
|
- log.info("设备告警,短信通知处理开始。。。");
|
|
|
- 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)));
|
|
|
- log.info("设备告警,商户是否订阅短信通知:{},eventCode:{}",b,eventCode);
|
|
|
- boolean isSubscribed = BooleanUtil.isTrue(b);
|
|
|
- //商户是否订阅短信通知
|
|
|
- if(isSubscribed&&StrUtil.isNotEmpty(exceptionType)){
|
|
|
- MercSmsSubscriptionDto.SelectList selectList = new MercSmsSubscriptionDto.SelectList();
|
|
|
- selectList.setEventCode(eventCode).setMercId(merc.getId());
|
|
|
- List<MercSmsSubscriptionDto.Vo> mercSmsSubList = R.feignCheckData(mercSmsSubscriptionService.list(selectList));
|
|
|
- if(CollUtil.isNotEmpty(mercSmsSubList)){
|
|
|
- MercSmsSubscriptionDto.Vo mss = mercSmsSubList.get(0);
|
|
|
- String phones = mss.getPhones();
|
|
|
- if(StrUtil.isNotEmpty(phones)){
|
|
|
- List<String> telList = StrUtil.split(phones, ",");
|
|
|
- //短信推送 设备告警:设备${device_id}于${time}发生${exception_type}异常。请登录后台查看详情并及时处理。
|
|
|
- Long configId = MsgConfigId.SMS_NOTIFY_DEVICE.getId();
|
|
|
- String formatDate = LocalDateTimeUtil.format(createTime, DatePattern.NORM_DATETIME_PATTERN);
|
|
|
- Map<String, Object> templateParams = MapUtil.newHashMap();
|
|
|
- templateParams.put("device_id", String.valueOf(deviceId));
|
|
|
- templateParams.put("time", formatDate);
|
|
|
- templateParams.put("exception_type", exceptionType);
|
|
|
- log.info("商户设备告警短信通知:{}", JSONUtil.toJsonPrettyStr(templateParams));
|
|
|
- for (String tel : telList) {
|
|
|
- // 扣除商户短信资源包
|
|
|
- R deduct = mercSmsService.deduct(new MercSmsPackageDto.Deduct()
|
|
|
- .setMercId(merc.getId())
|
|
|
- .setMsg("设备告警短信通知,设备号:" + deviceId)
|
|
|
- );
|
|
|
- if (deduct.getCode() == R.Enum.SUCCESS.getCode()) {
|
|
|
- log.info("设备告警短信通知#商户{}:,短信资源包扣除成功,手机号:{}",merc.getId(),tel);
|
|
|
- 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(),tel);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|