|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.txz.mall.configurer.AsyncConfig;
|
|
|
import com.txz.mall.dao.NoticeMapper;
|
|
|
import com.txz.mall.enums.NoticeEnum;
|
|
|
import com.txz.mall.model.Notice;
|
|
@@ -12,6 +13,7 @@ import com.txz.mall.service.NoticeService;
|
|
|
import com.txz.mall.service.UserJPushService;
|
|
|
import com.txz.mall.util.NoticeI18nUtil;
|
|
|
import dto.NoticeDTO;
|
|
|
+import io.github.engagelab.api.PushApi;
|
|
|
import io.github.engagelab.bean.push.PushParam;
|
|
|
import io.github.engagelab.bean.push.PushResult;
|
|
|
import io.github.engagelab.bean.push.message.notification.NotificationMessage;
|
|
@@ -36,10 +38,12 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
|
|
|
|
|
|
- private final io.github.engagelab.api.PushApi pushApi;
|
|
|
+ private final PushApi pushApi;
|
|
|
|
|
|
private final UserJPushService userJPushService;
|
|
|
|
|
|
+ private final AsyncConfig asyncConfig;
|
|
|
+
|
|
|
@Override
|
|
|
public void addNotice(NoticeDTO notice, Long... uids) {
|
|
|
if (CollectionUtil.isEmpty(Arrays.asList(uids))) {
|
|
@@ -56,131 +60,135 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
|
|
});
|
|
|
this.saveBatch(saveBatch);
|
|
|
|
|
|
-
|
|
|
- // 极光推送
|
|
|
- List<UserJPush> pushList = userJPushService.list(Wrappers.<UserJPush>lambdaQuery()
|
|
|
- .in(UserJPush::getUserId, Arrays.asList(uids))
|
|
|
- );
|
|
|
-
|
|
|
- PushParam param = new PushParam();
|
|
|
- PushParam.Body body = new PushParam.Body();
|
|
|
-
|
|
|
- Map<String, List<UserJPush>> languages = pushList.stream().collect(Collectors.groupingBy(UserJPush::getUserLanguage));
|
|
|
-
|
|
|
- // 单独处理孟加拉区域
|
|
|
- List<UserJPush> bns = languages.get("bn");
|
|
|
- if (CollectionUtil.isNotEmpty(bns)) {
|
|
|
- // android 通知内容
|
|
|
- NotificationMessage.Android android = new NotificationMessage.Android();
|
|
|
- // ios 通知内容
|
|
|
- NotificationMessage.IOS ios = new NotificationMessage.IOS();
|
|
|
- switch (notice.getNoticeType()) {
|
|
|
- default:
|
|
|
- android.setTitle(NoticeI18nUtil.get("bn", notice.getNoticeType().getTitle()));
|
|
|
- android.setAlert(String.format(NoticeI18nUtil.get("bn", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
- ios.setAlert(NoticeI18nUtil.get("bn", notice.getNoticeType().getTitle()) + "," + String.format(NoticeI18nUtil.get("bn", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
- break;
|
|
|
- case OTHER:
|
|
|
- android.setTitle(notice.getNoticeTitle());
|
|
|
- android.setAlert(notice.getNoticeMessage());
|
|
|
- ios.setAlert(notice.getNoticeTitle() + "," + notice.getNoticeMessage());
|
|
|
- break;
|
|
|
- }
|
|
|
- NotificationMessage notificationMessage = new NotificationMessage();
|
|
|
- notificationMessage.setAlert(NoticeI18nUtil.get("bn", notice.getNoticeType().getTitle()));
|
|
|
- notificationMessage.setAndroid(android);
|
|
|
- notificationMessage.setIos(ios);
|
|
|
- body.setNotification(notificationMessage);
|
|
|
- // 目标人群
|
|
|
- To to = new To();
|
|
|
- to.setRegistrationIdList(bns.stream().map(UserJPush::getJpushDeviceId).collect(Collectors.toList()));
|
|
|
- // 指定目标
|
|
|
- param.setTo(to);
|
|
|
-
|
|
|
- // 指定平台
|
|
|
- body.setPlatform(Arrays.asList(Platform.android, Platform.ios));
|
|
|
-
|
|
|
- // 发送
|
|
|
- param.setBody(body);
|
|
|
- PushResult result = pushApi.push(param);
|
|
|
- log.info("孟加拉极光推送结果:{}", result);
|
|
|
- }
|
|
|
-
|
|
|
- List<UserJPush> ens = languages.get("en");
|
|
|
- if (CollectionUtil.isNotEmpty(ens)) {
|
|
|
- // android 通知内容
|
|
|
- NotificationMessage.Android android = new NotificationMessage.Android();
|
|
|
- // ios 通知内容
|
|
|
- NotificationMessage.IOS ios = new NotificationMessage.IOS();
|
|
|
- switch (notice.getNoticeType()) {
|
|
|
- default:
|
|
|
- android.setTitle(NoticeI18nUtil.get("en", notice.getNoticeType().getTitle()));
|
|
|
- android.setAlert(String.format(NoticeI18nUtil.get("en", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
- ios.setAlert(NoticeI18nUtil.get("en", notice.getNoticeType().getTitle()) + "," + String.format(NoticeI18nUtil.get("en", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
- break;
|
|
|
- case OTHER:
|
|
|
- android.setTitle(notice.getNoticeTitle());
|
|
|
- android.setAlert(notice.getNoticeMessage());
|
|
|
- ios.setAlert(notice.getNoticeTitle() + "," + notice.getNoticeMessage());
|
|
|
- break;
|
|
|
+ asyncConfig.taskExecutor().execute(() -> {
|
|
|
+ try {
|
|
|
+ // 极光推送
|
|
|
+ List<UserJPush> pushList = userJPushService.list(Wrappers.<UserJPush>lambdaQuery()
|
|
|
+ .in(UserJPush::getUserId, Arrays.asList(uids))
|
|
|
+ );
|
|
|
+
|
|
|
+ PushParam param = new PushParam();
|
|
|
+ PushParam.Body body = new PushParam.Body();
|
|
|
+
|
|
|
+ Map<String, List<UserJPush>> languages = pushList.stream().collect(Collectors.groupingBy(UserJPush::getUserLanguage));
|
|
|
+
|
|
|
+ // 单独处理孟加拉区域
|
|
|
+ List<UserJPush> bns = languages.get("bn");
|
|
|
+ if (CollectionUtil.isNotEmpty(bns)) {
|
|
|
+ // android 通知内容
|
|
|
+ NotificationMessage.Android android = new NotificationMessage.Android();
|
|
|
+ // ios 通知内容
|
|
|
+ NotificationMessage.IOS ios = new NotificationMessage.IOS();
|
|
|
+ switch (notice.getNoticeType()) {
|
|
|
+ default:
|
|
|
+ android.setTitle(NoticeI18nUtil.get("bn", notice.getNoticeType().getTitle()));
|
|
|
+ android.setAlert(String.format(NoticeI18nUtil.get("bn", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
+ ios.setAlert(NoticeI18nUtil.get("bn", notice.getNoticeType().getTitle()) + "," + String.format(NoticeI18nUtil.get("bn", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
+ break;
|
|
|
+ case OTHER:
|
|
|
+ android.setTitle(notice.getNoticeTitle());
|
|
|
+ android.setAlert(notice.getNoticeMessage());
|
|
|
+ ios.setAlert(notice.getNoticeTitle() + "," + notice.getNoticeMessage());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ NotificationMessage notificationMessage = new NotificationMessage();
|
|
|
+ notificationMessage.setAlert(NoticeI18nUtil.get("bn", notice.getNoticeType().getTitle()));
|
|
|
+ notificationMessage.setAndroid(android);
|
|
|
+ notificationMessage.setIos(ios);
|
|
|
+ body.setNotification(notificationMessage);
|
|
|
+ // 目标人群
|
|
|
+ To to = new To();
|
|
|
+ to.setRegistrationIdList(bns.stream().map(UserJPush::getJpushDeviceId).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ // 指定平台
|
|
|
+ body.setPlatform(Arrays.asList(Platform.android, Platform.ios));
|
|
|
+
|
|
|
+ // 发送
|
|
|
+ param.setBody(body);
|
|
|
+ PushResult result = pushApi.push(param);
|
|
|
+ log.info("孟加拉极光推送结果:{}", result);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<UserJPush> ens = languages.get("en");
|
|
|
+ if (CollectionUtil.isNotEmpty(ens)) {
|
|
|
+ // android 通知内容
|
|
|
+ NotificationMessage.Android android = new NotificationMessage.Android();
|
|
|
+ // ios 通知内容
|
|
|
+ NotificationMessage.IOS ios = new NotificationMessage.IOS();
|
|
|
+ switch (notice.getNoticeType()) {
|
|
|
+ default:
|
|
|
+ android.setTitle(NoticeI18nUtil.get("en", notice.getNoticeType().getTitle()));
|
|
|
+ android.setAlert(String.format(NoticeI18nUtil.get("en", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
+ ios.setAlert(NoticeI18nUtil.get("en", notice.getNoticeType().getTitle()) + "," + String.format(NoticeI18nUtil.get("en", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
+ break;
|
|
|
+ case OTHER:
|
|
|
+ android.setTitle(notice.getNoticeTitle());
|
|
|
+ android.setAlert(notice.getNoticeMessage());
|
|
|
+ ios.setAlert(notice.getNoticeTitle() + "," + notice.getNoticeMessage());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ NotificationMessage notificationMessage = new NotificationMessage();
|
|
|
+ notificationMessage.setAlert(NoticeI18nUtil.get("en", notice.getNoticeType().getTitle()));
|
|
|
+ notificationMessage.setAndroid(android);
|
|
|
+ notificationMessage.setIos(ios);
|
|
|
+ body.setNotification(notificationMessage);
|
|
|
+ // 目标人群
|
|
|
+ To to = new To();
|
|
|
+ to.setRegistrationIdList(ens.stream().map(UserJPush::getJpushDeviceId).collect(Collectors.toList()));
|
|
|
+ // 指定目标
|
|
|
+ param.setTo(to);
|
|
|
+
|
|
|
+ // 指定平台
|
|
|
+ body.setPlatform(Arrays.asList(Platform.android, Platform.ios));
|
|
|
+
|
|
|
+ // 发送
|
|
|
+ param.setBody(body);
|
|
|
+ PushResult result = pushApi.push(param);
|
|
|
+ log.info("英文极光推送结果:{}", result);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<UserJPush> zhs = languages.get("zh");
|
|
|
+ if (CollectionUtil.isNotEmpty(zhs)) {
|
|
|
+ // android 通知内容
|
|
|
+ NotificationMessage.Android android = new NotificationMessage.Android();
|
|
|
+ // ios 通知内容
|
|
|
+ NotificationMessage.IOS ios = new NotificationMessage.IOS();
|
|
|
+ switch (notice.getNoticeType()) {
|
|
|
+ default:
|
|
|
+ android.setTitle(NoticeI18nUtil.get("zh", notice.getNoticeType().getTitle()));
|
|
|
+ android.setAlert(String.format(NoticeI18nUtil.get("zh", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
+ ios.setAlert(NoticeI18nUtil.get("zh", notice.getNoticeType().getTitle()) + "," + String.format(NoticeI18nUtil.get("zh", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
+ break;
|
|
|
+ case OTHER:
|
|
|
+ android.setTitle(notice.getNoticeTitle());
|
|
|
+ android.setAlert(notice.getNoticeMessage());
|
|
|
+ ios.setAlert(notice.getNoticeTitle() + "," + notice.getNoticeMessage());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ NotificationMessage notificationMessage = new NotificationMessage();
|
|
|
+ notificationMessage.setAlert(NoticeI18nUtil.get("zh", notice.getNoticeType().getTitle()));
|
|
|
+ notificationMessage.setAndroid(android);
|
|
|
+ notificationMessage.setIos(ios);
|
|
|
+ body.setNotification(notificationMessage);
|
|
|
+ // 目标人群
|
|
|
+ To to = new To();
|
|
|
+ to.setRegistrationIdList(zhs.stream().map(UserJPush::getJpushDeviceId).collect(Collectors.toList()));
|
|
|
+ // 指定目标
|
|
|
+ param.setTo(to);
|
|
|
+
|
|
|
+ // 指定平台
|
|
|
+ body.setPlatform(Arrays.asList(Platform.android, Platform.ios));
|
|
|
+
|
|
|
+ // 发送
|
|
|
+ param.setBody(body);
|
|
|
+ PushResult result = pushApi.push(param);
|
|
|
+ log.info("中文极光推送结果:{}", result);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("极光推送失败:{}", e.getMessage());
|
|
|
}
|
|
|
- NotificationMessage notificationMessage = new NotificationMessage();
|
|
|
- notificationMessage.setAlert(NoticeI18nUtil.get("en", notice.getNoticeType().getTitle()));
|
|
|
- notificationMessage.setAndroid(android);
|
|
|
- notificationMessage.setIos(ios);
|
|
|
- body.setNotification(notificationMessage);
|
|
|
- // 目标人群
|
|
|
- To to = new To();
|
|
|
- to.setRegistrationIdList(ens.stream().map(UserJPush::getJpushDeviceId).collect(Collectors.toList()));
|
|
|
- // 指定目标
|
|
|
- param.setTo(to);
|
|
|
-
|
|
|
- // 指定平台
|
|
|
- body.setPlatform(Arrays.asList(Platform.android, Platform.ios));
|
|
|
-
|
|
|
- // 发送
|
|
|
- param.setBody(body);
|
|
|
- PushResult result = pushApi.push(param);
|
|
|
- log.info("英文极光推送结果:{}", result);
|
|
|
- }
|
|
|
-
|
|
|
- List<UserJPush> zhs = languages.get("zh");
|
|
|
- if (CollectionUtil.isNotEmpty(zhs)) {
|
|
|
- // android 通知内容
|
|
|
- NotificationMessage.Android android = new NotificationMessage.Android();
|
|
|
- // ios 通知内容
|
|
|
- NotificationMessage.IOS ios = new NotificationMessage.IOS();
|
|
|
- switch (notice.getNoticeType()) {
|
|
|
- default:
|
|
|
- android.setTitle(NoticeI18nUtil.get("zh", notice.getNoticeType().getTitle()));
|
|
|
- android.setAlert(String.format(NoticeI18nUtil.get("zh", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
- ios.setAlert(NoticeI18nUtil.get("zh", notice.getNoticeType().getTitle()) + "," + String.format(NoticeI18nUtil.get("zh", notice.getNoticeType().getContent()), notice.getNoticeMessage()));
|
|
|
- break;
|
|
|
- case OTHER:
|
|
|
- android.setTitle(notice.getNoticeTitle());
|
|
|
- android.setAlert(notice.getNoticeMessage());
|
|
|
- ios.setAlert(notice.getNoticeTitle() + "," + notice.getNoticeMessage());
|
|
|
- break;
|
|
|
- }
|
|
|
- NotificationMessage notificationMessage = new NotificationMessage();
|
|
|
- notificationMessage.setAlert(NoticeI18nUtil.get("zh", notice.getNoticeType().getTitle()));
|
|
|
- notificationMessage.setAndroid(android);
|
|
|
- notificationMessage.setIos(ios);
|
|
|
- body.setNotification(notificationMessage);
|
|
|
- // 目标人群
|
|
|
- To to = new To();
|
|
|
- to.setRegistrationIdList(zhs.stream().map(UserJPush::getJpushDeviceId).collect(Collectors.toList()));
|
|
|
- // 指定目标
|
|
|
- param.setTo(to);
|
|
|
-
|
|
|
- // 指定平台
|
|
|
- body.setPlatform(Arrays.asList(Platform.android, Platform.ios));
|
|
|
-
|
|
|
- // 发送
|
|
|
- param.setBody(body);
|
|
|
- PushResult result = pushApi.push(param);
|
|
|
- log.info("中文极光推送结果:{}", result);
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
|