|
@@ -0,0 +1,70 @@
|
|
|
|
+package com.xy.consumer.device.push.msg;
|
|
|
|
+
|
|
|
|
+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.json.JSONUtil;
|
|
|
|
+import com.xy.consumer.MqttConsumer;
|
|
|
|
+import com.xy.dto.MsgConfigTestDto;
|
|
|
|
+import com.xy.entity.DeviceEventMsg;
|
|
|
|
+import com.xy.enums.ChannelType;
|
|
|
|
+import com.xy.service.MsgSendApiService;
|
|
|
|
+import com.xy.utils.R;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 设备消息推送消费者
|
|
|
|
+ *
|
|
|
|
+ * @author 谭斌
|
|
|
|
+ * @date 2023/06/06
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+@AllArgsConstructor
|
|
|
|
+public class DevicePushMsgConsumer implements MqttConsumer {
|
|
|
|
+
|
|
|
|
+ private MsgSendApiService msgSendApiService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean message(String topic, String payload) {
|
|
|
|
+ DeviceEventMsg deviceEventMsg = JSONUtil.toBean(payload, DeviceEventMsg.class);
|
|
|
|
+ if (deviceEventMsg != null) {
|
|
|
|
+ Long deviceId = deviceEventMsg.getDeviceId();
|
|
|
|
+ Long mercId = deviceEventMsg.getMercId();
|
|
|
|
+ LocalDateTime createTime = deviceEventMsg.getCreateTime();
|
|
|
|
+ String msg = deviceEventMsg.getMsg();
|
|
|
|
+ Long configId = 12L;
|
|
|
|
+ List<MsgConfigTestDto.BizParam> bizParams = R.feignCheckData(msgSendApiService.getBizParamByMsgConfig(new MsgConfigTestDto.MsgConfig().setConfigId(configId)));
|
|
|
|
+ if (CollUtil.isNotEmpty(bizParams)) {
|
|
|
|
+ List<MsgConfigTestDto.BizData> bizDataList = BeanUtil.copyToList(bizParams, MsgConfigTestDto.BizData.class);
|
|
|
|
+ bizDataList.forEach(b -> {
|
|
|
|
+ String channelType = b.getChannelType();
|
|
|
|
+ if (Integer.valueOf(channelType).intValue() == ChannelType.OFFICIAL_ACCOUNT.getCode().intValue()) {
|
|
|
|
+ //微信公众号
|
|
|
|
+ Map<String, Object> params = b.getTemplateParams();
|
|
|
|
+ params.put("device", deviceId);
|
|
|
|
+ params.put("type", msg);
|
|
|
|
+ params.put("time", DateUtil.format(createTime, DatePattern.NORM_DATETIME_PATTERN));
|
|
|
|
+ Set<String> receivers = new HashSet<>();
|
|
|
|
+ //TODO: 无正式公众号 , 接收人 暂时写死测试
|
|
|
|
+ receivers.add("oT7m45tN1msid-HJ0i8I5WDCpDXE");
|
|
|
|
+ b.setReceivers(receivers);
|
|
|
|
+ b.setTemplateParams(params);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ msgSendApiService.sendByMsgConfig(new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(bizDataList));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+}
|