Browse Source

fix: 完成用户推送模块

master
wangxiang 2 years ago
parent
commit
4a59b9ad62
  1. 3
      kicc-platform/kicc-platform-api/kicc-common-api/src/main/java/com/cloud/kicc/commonbiz/api/entity/PushChatMessage.java
  2. 8
      kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/controller/PushConcernFanController.java
  3. 8
      kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/service/IPushConcernFanService.java
  4. 10
      kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/service/impl/PushApplicationServiceImpl.java
  5. 151
      kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/service/impl/PushConcernFanServiceImpl.java

3
kicc-platform/kicc-platform-api/kicc-common-api/src/main/java/com/cloud/kicc/commonbiz/api/entity/PushChatMessage.java

@ -33,6 +33,9 @@ public class PushChatMessage extends CommonEntity { @@ -33,6 +33,9 @@ public class PushChatMessage extends CommonEntity {
@ApiModelProperty("推送方用户id")
private String userId;
@ApiModelProperty("关注粉丝状态")
private String concernFanStatus;
@ApiModelProperty("消息类型")
private String type;

8
kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/controller/PushConcernFanController.java

@ -242,5 +242,13 @@ public class PushConcernFanController { @@ -242,5 +242,13 @@ public class PushConcernFanController {
return R.ok();
}
@PostMapping("/concernFanSend")
@ApiOperation("关注粉丝双向推送消息")
public R concernFanMessageSend(@Valid @RequestBody PushChatMessage pushChatMessage) {
iPushConcernFanService.concernFanMessageSend(pushChatMessage);
return R.ok(true);
}
}

8
kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/service/IPushConcernFanService.java

@ -2,6 +2,7 @@ package com.cloud.kicc.commonbiz.service; @@ -2,6 +2,7 @@ package com.cloud.kicc.commonbiz.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cloud.kicc.commonbiz.api.entity.PushChatMessage;
import com.cloud.kicc.commonbiz.api.entity.PushConcernFan;
import java.util.Map;
@ -38,4 +39,11 @@ public interface IPushConcernFanService extends IService<PushConcernFan> { @@ -38,4 +39,11 @@ public interface IPushConcernFanService extends IService<PushConcernFan> {
*/
IPage<Map<String, Object>> selectPushFriendList(IPage<Map<String, Object>> page, Map<String, Object> map);
/**
* 针对关注粉丝双向消息推送接口
* @param pushChatMessage 推送消息
* @return void
*/
void concernFanMessageSend(PushChatMessage pushChatMessage);
}

10
kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/service/impl/PushApplicationServiceImpl.java

@ -99,8 +99,8 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe @@ -99,8 +99,8 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe
pushChatMessage.setAlias(pushConcernFanList.stream().map(item -> item.getConcernUserId()).collect(Collectors.joining()));
}
// 过滤黑名单用户
List<PushBlacklist> pushBlacklists = iPushBlacklistService.list(Wrappers.<PushBlacklist>lambdaQuery().eq(PushBlacklist::getConcernUserId, pushChatMessage.getUserId()));
// 过滤黑名单,根据谁拉黑了推送方用户进行过滤推送用户
List<PushBlacklist> pushBlacklists = iPushBlacklistService.list(Wrappers.<PushBlacklist>lambdaQuery().eq(PushBlacklist::getFanUserId, pushChatMessage.getUserId()));
pushBlacklists.forEach(item -> pushChatMessage.setAlias(pushChatMessage.getAlias().replaceAll(item.getConcernUserId() + ",|$", "")));
@ -112,8 +112,8 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe @@ -112,8 +112,8 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe
// 推送消息
StrUtil.split(pushChatMessage.getAlias(), ",").forEach(concernUserId -> {
Optional<PushConcernFanType> pushConcernFanTypeOptional = pushConcernFanTypeList.stream().filter(item -> item.getConcernUserId().equals(concernUserId)).findFirst();
StrUtil.split(pushChatMessage.getAlias(), ",").forEach(alias -> {
Optional<PushConcernFanType> pushConcernFanTypeOptional = pushConcernFanTypeList.stream().filter(item -> item.getFanUserId().equals(alias)).findFirst();
if (pushConcernFanTypeOptional.isPresent()) {
PushConcernFanType pushConcernFanType = pushConcernFanTypeOptional.get();
pushChatMessage.setPushTypeId(pushConcernFanType.getTypeId());
@ -128,7 +128,7 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe @@ -128,7 +128,7 @@ public class PushApplicationServiceImpl extends ServiceImpl<PushApplicationMappe
pushChatMessage.setType("customizedcast");
pushChatMessage.setDisplayType("notification");
pushChatMessage.setAliasType(PushClientUtil.uPushUserAliasType);
pushChatMessage.setAlias(concernUserId);
pushChatMessage.setAlias(alias);
JSONObject custom = new JSONObject();
custom.put("fanUserId", pushChatMessage.getUserId());
custom.put("offlineRingtone", pushChatMessage.getSound());

151
kicc-platform/kicc-platform-biz/kicc-common-biz/src/main/java/com/cloud/kicc/commonbiz/service/impl/PushConcernFanServiceImpl.java

@ -1,13 +1,35 @@ @@ -1,13 +1,35 @@
package com.cloud.kicc.commonbiz.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.kicc.common.core.exception.CheckedException;
import com.cloud.kicc.commonbiz.api.entity.PushBlacklist;
import com.cloud.kicc.commonbiz.api.entity.PushChatMessage;
import com.cloud.kicc.commonbiz.api.entity.PushConcernFan;
import com.cloud.kicc.commonbiz.api.entity.PushConcernFanType;
import com.cloud.kicc.commonbiz.api.enums.PushAuditStatusEnum;
import com.cloud.kicc.commonbiz.mapper.PushConcernFanMapper;
import com.cloud.kicc.commonbiz.service.IPushBlacklistService;
import com.cloud.kicc.commonbiz.service.IPushChatMessageService;
import com.cloud.kicc.commonbiz.service.IPushConcernFanService;
import com.cloud.kicc.commonbiz.service.IPushConcernFanTypeService;
import com.cloud.kicc.commonbiz.util.PushClientUtil;
import lombok.RequiredArgsConstructor;
import okhttp3.OkHttpClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* <p>
@ -18,8 +40,16 @@ import java.util.Map; @@ -18,8 +40,16 @@ import java.util.Map;
* @since 2023-03-24
*/
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class PushConcernFanServiceImpl extends ServiceImpl<PushConcernFanMapper, PushConcernFan> implements IPushConcernFanService {
private final OkHttpClient okHttpClient;
private final IPushConcernFanService iPushConcernFanService;
private final IPushBlacklistService iPushBlacklistService;
private final IPushChatMessageService iPushChatMessageService;
private final IPushConcernFanTypeService iPushConcernFanTypeService;
@Override
public IPage<Map<String, Object>> selectPushConcernFanList(IPage<Map<String, Object>> page, Map<String, Object> map) {
return baseMapper.selectPushConcernFanList(page, map);
@ -34,4 +64,125 @@ public class PushConcernFanServiceImpl extends ServiceImpl<PushConcernFanMapper, @@ -34,4 +64,125 @@ public class PushConcernFanServiceImpl extends ServiceImpl<PushConcernFanMapper,
public IPage<Map<String, Object>> selectPushFriendList(IPage<Map<String, Object>> page, Map<String, Object> map) {
return baseMapper.selectPushFriendList(page, map);
}
@Override
public void concernFanMessageSend(PushChatMessage pushChatMessage) {
if (StrUtil.isBlank(pushChatMessage.getUserId())) {
throw new CheckedException("当前推送方用户ID必填!");
}
List<PushConcernFanType> pushConcernFanTypeList;
// 是否为关注推送
if (StrUtil.equals(pushChatMessage.getConcernFanStatus(), "1")) {
if (StrUtil.isBlank(pushChatMessage.getAlias())) throw new CheckedException("当前推送用户别名ID必填!");
// 查询对方是否有关注推送用户
PushConcernFan pushConcernFan = iPushConcernFanService.getOne(Wrappers.<PushConcernFan>lambdaQuery()
.eq(PushConcernFan::getConcernUserId, pushChatMessage.getUserId())
.eq(PushConcernFan::getFanUserId, pushChatMessage.getAlias())
.eq(PushConcernFan::getStatus, PushAuditStatusEnum.APPROVED));
// 推送限制关注用户只能推送一条消息,需要双向关注后才能解锁限制
if (ObjectUtil.isEmpty(pushConcernFan)) {
Optional<PushChatMessage> optionalPushChatMessage = iPushChatMessageService.list(Wrappers.<PushChatMessage>lambdaQuery()
.eq(PushChatMessage::getConcernFanStatus, "1")
.eq(PushChatMessage::getUserId, pushChatMessage.getUserId())
.eq(PushChatMessage::getAlias, pushChatMessage.getAlias())).stream().findFirst();
optionalPushChatMessage.ifPresent(value -> { throw new CheckedException("对方还未关注你,你只能发送一条消息,发送失败!"); });
}
// 查询关注设置的推送类型,如果参数中没有指定则采用默认的推送类型
pushConcernFanTypeList = iPushConcernFanTypeService.list(Wrappers.<PushConcernFanType>lambdaQuery()
.eq(PushConcernFanType::getFanUserId, pushChatMessage.getUserId())
.eq(StrUtil.isNotBlank(pushChatMessage.getPushTypeId()), PushConcernFanType::getTypeId, pushChatMessage.getPushTypeId())
.eq(StrUtil.isBlank(pushChatMessage.getPushTypeId()), PushConcernFanType::getDefaultType, "1"));
} else {
// 配置推送用户,针对粉丝支持多人推送
if (StrUtil.isBlank(pushChatMessage.getAlias())) {
List<PushConcernFan> pushConcernFanList = iPushConcernFanService.list(Wrappers.<PushConcernFan>lambdaQuery()
.eq(PushConcernFan::getConcernUserId, pushChatMessage.getUserId())
.eq(PushConcernFan::getStatus, PushAuditStatusEnum.APPROVED));
pushChatMessage.setAlias(pushConcernFanList.stream().map(item -> item.getConcernUserId()).collect(Collectors.joining()));
}
// 查询粉丝设置的推送类型,如果参数中没有指定则采用默认的推送类型
pushConcernFanTypeList = iPushConcernFanTypeService.list(Wrappers.<PushConcernFanType>lambdaQuery()
.eq(PushConcernFanType::getConcernFanId, pushChatMessage.getUserId())
.eq(StrUtil.isNotBlank(pushChatMessage.getPushTypeId()), PushConcernFanType::getTypeId, pushChatMessage.getPushTypeId())
.eq(StrUtil.isBlank(pushChatMessage.getPushTypeId()), PushConcernFanType::getDefaultType, "1"));
}
// 过滤黑名单,根据谁拉黑了推送方用户进行过滤推送用户
List<PushBlacklist> pushBlacklists = iPushBlacklistService.list(Wrappers.<PushBlacklist>lambdaQuery().eq(PushBlacklist::getFanUserId, pushChatMessage.getUserId()));
pushBlacklists.forEach(item -> pushChatMessage.setAlias(pushChatMessage.getAlias().replaceAll(item.getConcernUserId() + ",|$", "")));
// 推送消息
StrUtil.split(pushChatMessage.getAlias(), ",").forEach(alias -> {
Optional<PushConcernFanType> pushConcernFanTypeOptional = pushConcernFanTypeList.stream().filter(item ->
StrUtil.equals(pushChatMessage.getConcernFanStatus(), "1") ? item.getConcernUserId().equals(alias) : item.getFanUserId().equals(alias)).findFirst();
if (pushConcernFanTypeOptional.isPresent()) {
PushConcernFanType pushConcernFanType = pushConcernFanTypeOptional.get();
pushChatMessage.setPushTypeId(pushConcernFanType.getTypeId());
pushChatMessage.setPlayLights(pushConcernFanType.getPlayLights());
pushChatMessage.setPlaySound(pushConcernFanType.getPlaySound());
pushChatMessage.setPlayVibrate(pushConcernFanType.getPlayVibrate());
pushChatMessage.setPlayToText(pushConcernFanType.getPlayToText());
pushChatMessage.setSound(pushConcernFanType.getOfflineRingtone());
pushChatMessage.setOnlineRingtone(pushConcernFanType.getOnlineRingtone());
}
pushChatMessage.setType("customizedcast");
pushChatMessage.setDisplayType("notification");
pushChatMessage.setAliasType(PushClientUtil.uPushUserAliasType);
pushChatMessage.setAlias(alias);
JSONObject custom = new JSONObject();
custom.put("fanUserId", pushChatMessage.getUserId());
custom.put("offlineRingtone", pushChatMessage.getSound());
custom.put("onlineRingtone", pushChatMessage.getOnlineRingtone());
custom.put("playToText", BooleanUtil.toBoolean(pushChatMessage.getPlayToText()));
custom.put("playSound", BooleanUtil.toBoolean(pushChatMessage.getPlaySound()));
custom.put("playVibrate", BooleanUtil.toBoolean(pushChatMessage.getPlayVibrate()));
custom.put("playLights", BooleanUtil.toBoolean(pushChatMessage.getPlayLights()));
pushChatMessage.setCustom(custom.toString());
JSONObject jsonObject = new JSONObject();
jsonObject.put("production_mode", PushClientUtil.PRODUCTION_MODE);
jsonObject.put("type", pushChatMessage.getType());
jsonObject.put("description", pushChatMessage.getRemarks());
jsonObject.put("alias_type", pushChatMessage.getAliasType());
jsonObject.put("alias", pushChatMessage.getAlias());
JSONObject payload = new JSONObject();
payload.put("display_type", pushChatMessage.getDisplayType());
JSONObject body = new JSONObject();
body.put("ticker", pushChatMessage.getTitle());
body.put("text", pushChatMessage.getText());
body.put("title", pushChatMessage.getTitle());
body.put("sound", pushChatMessage.getSound());
body.put("after_open", "go_custom");
body.put("custom", pushChatMessage.getCustom());
if (BooleanUtil.toBoolean(pushChatMessage.getPlaySound())) {
body.put("play_sound", true);
}
if (BooleanUtil.toBoolean(pushChatMessage.getPlayVibrate())) {
body.put("play_vibrate", true);
}
if (BooleanUtil.toBoolean(pushChatMessage.getPlayLights())) {
body.put("play_lights", true);
}
payload.put("body", body);
jsonObject.put("payload", payload);
JSONObject policy = new JSONObject();
policy.put("expire_time", LocalDateTimeUtil.now().plusDays(3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
policy.put("out_biz_no", LocalDateTimeUtil.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
jsonObject.put("policy", policy);
try {
PushClientUtil pushClientUtil = new PushClientUtil(okHttpClient);
pushClientUtil.send(jsonObject);
iPushChatMessageService.save(pushChatMessage);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

Loading…
Cancel
Save