|
@@ -10,12 +10,17 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.xy.consumer.MqttConsumer;
|
|
|
import com.xy.dto.MsgConfigTestDto;
|
|
|
+import com.xy.dto.UserInfoDto;
|
|
|
+import com.xy.dto.be.MercDto;
|
|
|
+import com.xy.dto.be.MercUserDeviceDto;
|
|
|
import com.xy.entity.DeviceEventMsg;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.SysCodeConfigureRedis;
|
|
|
import com.xy.enums.ChannelType;
|
|
|
import com.xy.service.DeviceInfoServiceImpl;
|
|
|
import com.xy.service.MsgSendApiService;
|
|
|
+import com.xy.service.UserInfoService;
|
|
|
+import com.xy.service.be.MercFeignService;
|
|
|
import com.xy.utils.R;
|
|
|
import com.xy.utils.SysCodeConfigureUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
@@ -23,10 +28,8 @@ 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;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -42,6 +45,8 @@ public class DevicePushMsgConsumer implements MqttConsumer {
|
|
|
|
|
|
private MsgSendApiService msgSendApiService;
|
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
|
+ private MercFeignService mercFeignService;
|
|
|
+ private UserInfoService userInfoService;
|
|
|
|
|
|
@Override
|
|
|
public boolean message(String topic, String payload) {
|
|
@@ -58,9 +63,33 @@ public class DevicePushMsgConsumer implements MqttConsumer {
|
|
|
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 -> {
|
|
|
+ List<MsgConfigTestDto.BizData> sendList = new ArrayList<>();
|
|
|
+ for (MsgConfigTestDto.BizData b : bizDataList) {
|
|
|
String channelType = b.getChannelType();
|
|
|
if (Integer.valueOf(channelType).intValue() == ChannelType.OFFICIAL_ACCOUNT.getCode().intValue()) {
|
|
|
+ //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)
|
|
|
+ .map(UserInfoDto.Vo::getMpOpenid)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ if (CollUtil.isEmpty(mpOpenIds)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {{first.DATA}}
|
|
|
* 设备名称:{{keyword1.DATA}}
|
|
@@ -90,17 +119,18 @@ public class DevicePushMsgConsumer implements MqttConsumer {
|
|
|
params.put("keyword1", deviceName);
|
|
|
params.put("keyword2", msg);
|
|
|
params.put("keyword3", DateUtil.format(createTime, DatePattern.NORM_DATETIME_PATTERN));
|
|
|
- Set<String> receivers = new HashSet<>();
|
|
|
- //TODO: 接收人 暂时写死测试, 还未做绑定微信公众号openID
|
|
|
- receivers.add("oIJ5O5n_7sxDusGJNsr_LScXvX5c");
|
|
|
- b.setReceivers(receivers);
|
|
|
+
|
|
|
+ //商户管理员发
|
|
|
+ b.setReceivers(mpOpenIds);
|
|
|
b.setTemplateParams(params);
|
|
|
b.setExtraParam(bizExtraParam);
|
|
|
-
|
|
|
+ sendList.add(b);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(sendList)) {
|
|
|
+ msgSendApiService.sendByMsgConfig(new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(sendList));
|
|
|
+ }
|
|
|
|
|
|
- msgSendApiService.sendByMsgConfig(new MsgConfigTestDto.SendByMsgConfig().setConfigId(configId).setBizDataList(bizDataList));
|
|
|
}
|
|
|
}
|
|
|
return true;
|