瀏覽代碼

更新极光推送通知

Yangzw 2 月之前
父節點
當前提交
55d17d7f31

+ 34 - 5
feifan-module-mall/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/module/sale/service/merchantapply/MerchantApplyServiceImpl.java

@@ -64,7 +64,7 @@ public class MerchantApplyServiceImpl implements MerchantApplyService {
         MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId());
         List<MemberUserRespDTO> users = memberUserApi.getUsersByMobile(user.getMobile());
         List<MerchantApplyDO> merchantApplyDOS = merchantApplyMapper.selectList(MerchantApplyDO::getApplyMemberUserId, users.stream().map(MemberUserRespDTO::getId).collect(Collectors.toList()));
-        if(merchantApplyDOS != null && merchantApplyDOS.size() >= 1){
+        if (merchantApplyDOS != null && merchantApplyDOS.size() >= 1) {
             ErrorCode ERROR = new ErrorCode(1_002_029_003, "当前手机号已存在商户账号");
             throw exception(ERROR);
         }
@@ -89,7 +89,10 @@ public class MerchantApplyServiceImpl implements MerchantApplyService {
         merchantApplyMapper.insert(merchantApply);
 
         // 发送微信信息到系统用户
-        sentWxChantMessageToThSystemUser(merchantApply,MerchantApplyCheckPersonStatusEnum.ONE.getUserid());
+        sentWxChantMessageToThSystemUser(merchantApply, MerchantApplyCheckPersonStatusEnum.ONE.getUserid());
+
+        // 推送极光消息
+        jPush(merchantApply, MerchantApplyCheckPersonStatusEnum.ONE.getUserid());
 
         // 返回
         return merchantApply.getId();
@@ -97,9 +100,10 @@ public class MerchantApplyServiceImpl implements MerchantApplyService {
 
     /**
      * 发送微信信息到系统用户
+     *
      * @param merchantApply 入驻申请
      */
-    private void sentWxChantMessageToThSystemUser(MerchantApplyDO merchantApply, Long sentSystemUserId){
+    private void sentWxChantMessageToThSystemUser(MerchantApplyDO merchantApply, Long sentSystemUserId) {
         List<String> params = new ArrayList<>();
 
         params.add(merchantApply.getName());
@@ -112,7 +116,29 @@ public class MerchantApplyServiceImpl implements MerchantApplyService {
                 params, sentSystemUserId, merchantApply.getId());
     }
 
-    private String getAreaById(Integer id){
+    private void jPush(MerchantApplyDO merchantApply, Long sentSystemUserId) {
+        String title = WcChatMessageTemplateIdEnum.MERCHANT_APPLY_CHECK.getName();
+
+        String alert = "商户名称: " + merchantApply.getName();
+        alert += "\n负责人: " + merchantApply.getContact();
+        alert += "\n负责人手机号: " + merchantApply.getContactNumber();
+
+        alert += "\n办公地址: " + (merchantApply.getAddress() == null || merchantApply.getAddress().isEmpty() ? "-" : merchantApply.getAddress());
+        alert += "\n所在地: " + getAreaById(merchantApply.getAreaId().intValue());
+
+        // 如果没有权限就不用发送了
+        Boolean havePermission = wcChatMessageUtilsApi.isHavePermission(sentSystemUserId, title);
+        if(!havePermission){
+            return;
+        }
+        List<String> userRsgIds = memberUserApi.getUserRsgIds(sentSystemUserId, null);
+        if (userRsgIds != null) {
+            String url = wcChatMessageUtilsApi.getUrl(title, merchantApply.getId(), sentSystemUserId);
+            wcChatMessageUtilsApi.jPush(userRsgIds, alert, title, url, merchantApply.getApplyMemberUserId(), sentSystemUserId, merchantApply.getId());
+        }
+    }
+
+    private String getAreaById(Integer id) {
         Area area = AreaUtils.getArea(Area.ID_CHINA);
         Assert.notNull(area, "获取不到中国");
         List<AreaNodeRespVO> bean = BeanUtils.toBean(area.getChildren(), AreaNodeRespVO.class);
@@ -174,7 +200,10 @@ public class MerchantApplyServiceImpl implements MerchantApplyService {
         merchantApplyMapper.updateById(updateObj);
 
         // 发送微信信息到系统用户
-        sentWxChantMessageToThSystemUser(updateObj,MerchantApplyCheckPersonStatusEnum.ONE.getUserid());
+        sentWxChantMessageToThSystemUser(updateObj, MerchantApplyCheckPersonStatusEnum.ONE.getUserid());
+
+        // 推送极光消息
+        jPush(updateObj, MerchantApplyCheckPersonStatusEnum.ONE.getUserid());
     }
 
     @Override

+ 30 - 1
feifan-module-mall/feifan-module-trade-api/src/main/java/cn/newfeifan/mall/module/trade/api/wechat/WcChatMessageUtilsApi.java

@@ -15,5 +15,34 @@ public interface WcChatMessageUtilsApi {
      * @param systemUserId 系统用户id
      * @param objectId     对象id
      */
-    public void sendWcChatMessage(String templateId, List<String> params, Long systemUserId, Long objectId) ;
+    void sendWcChatMessage(String templateId, List<String> params, Long systemUserId, Long objectId) ;
+
+    /**
+     * 极光推送
+     * @param rsgIds 注册id
+     * @param alert 推送内容
+     * @param title 标题
+     * @param url 地址
+     * @param memberUserId 用户id
+     * @param systemUserId 系统用户id
+     * @param objectId 对象id
+     */
+    void jPush(List<String> rsgIds, String alert, String title, String url, Long memberUserId, Long systemUserId, Long objectId);
+
+    /**
+     * 获取url
+     * @param title 标题
+     * @param objectId 对象id
+     * @param systemUserId 系统用户id
+     * @return 地址
+     */
+    String getUrl(String title, Long objectId, Long systemUserId);
+
+    /**
+     * 判断是否有权限
+     * @param userId 系统用户id
+     * @param messageName 消息名称
+     * @return 是否有权限
+     */
+    Boolean isHavePermission(Long userId, String messageName);
 }

+ 29 - 10
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/utils/push/JPushUtils.java

@@ -3,10 +3,14 @@ package cn.newfeifan.mall.module.trade.utils.push;
 import cn.hutool.core.codec.Base64;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
-import cn.newfeifan.mall.module.member.service.user.MemberUserService;
+import cn.newfeifan.mall.module.system.controller.admin.auth.vo.AuthLoginRespVO;
 import cn.newfeifan.mall.module.system.dal.dataobject.config.SystemConfigDO;
+import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
+import cn.newfeifan.mall.module.system.enums.logger.LoginLogTypeEnum;
+import cn.newfeifan.mall.module.system.service.auth.AdminAuthService;
 import cn.newfeifan.mall.module.system.service.config.SystemConfigService;
 import cn.newfeifan.mall.module.system.service.permission.PermissionService;
+import cn.newfeifan.mall.module.system.service.user.AdminUserService;
 import cn.newfeifan.mall.module.trade.controller.admin.jpushmessagelog.vo.JPushMessageLogSaveReqVO;
 import cn.newfeifan.mall.module.trade.enums.wxmessage.WcChatMessageTemplateIdEnum;
 import cn.newfeifan.mall.module.trade.service.jpushmessagelog.JPushMessageLogService;
@@ -45,9 +49,11 @@ public class JPushUtils {
     @Resource
     private SystemConfigService configService;
     @Resource
-    private MemberUserService memberUserService;
-    @Resource
     private PermissionService permissionService;
+    @Resource
+    private AdminAuthService authService;
+    @Resource
+    private AdminUserService adminUserService;
 
     /**
      * 获取请求体
@@ -89,25 +95,38 @@ public class JPushUtils {
     /**
      * 获取url
      * @param title 标题
-     * @param memberUserId 用户id
+     * @param systemUserId 系统用户id
      * @param objectId 对象id
      * @return url
      */
-    public String getUrl(String title, Long memberUserId, Long objectId){
+    public String getUrl(String title, Long objectId, Long systemUserId){
         SystemConfigDO redisConfig = configService.getRedisConfig();
-        String username = memberUserService.getUsernameByUserId(memberUserId);
         if (title.equals(WcChatMessageTemplateIdEnum.ORDER_DELIVERY2.getName())) {
             //订单已发货
-            return redisConfig.getMallDomain() + "/#/pages/order/detail?id=" + objectId + "&username=" + username;
+            return redisConfig.getMallDomain() + "/#/pages/order/detail?id=" + objectId;
         } else if (title.equals(WcChatMessageTemplateIdEnum.AFTER_SALE_CHECK2.getName())) {
             //售后订单审核完成
-            return redisConfig.getMallDomain() + "/#/pages/order/aftersale/detail?id=" + objectId + "&username=" + username;
+            return redisConfig.getMallDomain() + "/#/pages/order/aftersale/detail?id=" + objectId;
         } else if (title.equals(WcChatMessageTemplateIdEnum.AFTER_SALE_NO_CHECK2.getName())) {
             //售后订单待审核
-            return redisConfig.getMerchantDomain() + "/after-sale";
+            AdminUserDO systemUser = adminUserService.getUser(systemUserId);
+            AuthLoginRespVO token = authService.createTokenAfterLoginSuccess(systemUser.getId(), systemUser.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
+//            return redisConfig.getMerchantDomain() + "/after-sale";
+            return redisConfig.getMerchantDomain() + "/login" + "?accessToken=" + token.getAccessToken() + "&refreshToken=" + token.getRefreshToken();
         } else if (title.equals(WcChatMessageTemplateIdEnum.ORDER_NO_DELIVERY2.getName())) {
             //订单待发货
-            return redisConfig.getMerchantDomain() + "/order";
+            AdminUserDO systemUser = adminUserService.getUser(systemUserId);
+            AuthLoginRespVO token = authService.createTokenAfterLoginSuccess(systemUser.getId(), systemUser.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
+//            return redisConfig.getMerchantDomain() + "/order";
+            return redisConfig.getMerchantDomain() + "/login" + "?accessToken=" + token.getAccessToken() + "&refreshToken=" + token.getRefreshToken();
+        } else if(title.equals(WcChatMessageTemplateIdEnum.MERCHANT_APPLY_CHECK.getName())){
+            // 商户入驻申请审批通知
+            AdminUserDO systemUser = adminUserService.getUser(systemUserId);
+            AuthLoginRespVO token = authService.createTokenAfterLoginSuccess(systemUser.getId(), systemUser.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
+            return redisConfig.getPlatformDomain() + "/login" + "?accessToken=" + token.getAccessToken() + "&refreshToken=" + token.getRefreshToken();
+        } else if(title.equals(WcChatMessageTemplateIdEnum.MERCHANT_APPLY_CHECK_RESULT.getName())){
+            // 商户入驻审核结果通知
+            return redisConfig.getMallDomain() + "/#/pages/public/merchant";
         }
         return null;
     }

+ 20 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/utils/wechat/WcChatMessageUtilsApiImpl.java

@@ -1,6 +1,8 @@
 package cn.newfeifan.mall.module.trade.utils.wechat;
 
 import cn.newfeifan.mall.module.trade.api.wechat.WcChatMessageUtilsApi;
+import cn.newfeifan.mall.module.trade.utils.push.JPushUtils;
+import cn.newfeifan.mall.module.trade.utils.push.pojo.RequestBody;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
@@ -13,9 +15,27 @@ public class WcChatMessageUtilsApiImpl implements WcChatMessageUtilsApi {
 
     @Resource
     private WcChatMessageUtils wcChatMessageUtils;
+    @Resource
+    private JPushUtils jPushUtils;
 
     @Override
     public void sendWcChatMessage(String templateId, List<String> params, Long systemUserId, Long objectId) {
         wcChatMessageUtils.sendWcChatMessage(templateId, params, systemUserId, objectId);
     }
+
+    @Override
+    public void jPush(List<String> rsgIds, String alert, String title, String url, Long memberUserId, Long systemUserId, Long objectId){
+        RequestBody requestBody = jPushUtils.getRequestBody(rsgIds, alert, title, url);
+        jPushUtils.jPush(requestBody, memberUserId, systemUserId, objectId);
+    }
+
+    @Override
+    public String getUrl(String title, Long objectId, Long systemUserId) {
+        return jPushUtils.getUrl(title, objectId, systemUserId);
+    }
+
+    @Override
+    public Boolean isHavePermission(Long userId, String messageName) {
+        return jPushUtils.isHavePermission(userId, messageName);
+    }
 }

+ 8 - 0
feifan-module-member/feifan-module-member-api/src/main/java/cn/newfeifan/mall/module/member/api/user/MemberUserApi.java

@@ -65,4 +65,12 @@ public interface MemberUserApi {
      * @return 用户信息的列表
      */
     List<MemberUserRespDTO> getUsersByMobile(String mobile);
+
+    /**
+     * 通过系统用户或者会员用户来获取对应的rsgId
+     * @param systemUserIds 系统用户
+     * @param userId 会员用固话
+     * @return rsgId列表
+     */
+    List<String> getUserRsgIds(Long systemUserIds, Long userId);
 }

+ 21 - 0
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/api/user/MemberUserApiImpl.java

@@ -3,13 +3,16 @@ package cn.newfeifan.mall.module.member.api.user;
 import cn.newfeifan.mall.module.member.api.user.dto.MemberUserRespDTO;
 import cn.newfeifan.mall.module.member.convert.user.MemberUserConvert;
 import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
+import cn.newfeifan.mall.module.member.dal.mysql.user.MemberUserMapper;
 import cn.newfeifan.mall.module.member.service.user.MemberUserService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 import java.util.Collection;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 会员用户的 API 实现类
@@ -22,6 +25,8 @@ public class MemberUserApiImpl implements MemberUserApi {
 
     @Resource
     private MemberUserService userService;
+    @Resource
+    private MemberUserMapper memberUserMapper;
 
     @Override
     public MemberUserRespDTO getUser(Long id) {
@@ -49,4 +54,20 @@ public class MemberUserApiImpl implements MemberUserApi {
         return MemberUserConvert.INSTANCE.convertList2(userService. selectListByMobile(mobile));
     }
 
+    @Override
+    public List<String> getUserRsgIds(Long systemUserId, Long userId) {
+        List<MemberUserDO> memberUserDOS;
+        if (systemUserId != null) {
+            memberUserDOS = memberUserMapper.selectList(new LambdaQueryWrapper<MemberUserDO>()
+                    .eq(MemberUserDO::getSystemUsersId, systemUserId)
+                    .isNotNull(MemberUserDO::getAndroidRegisterId));
+        } else {
+            memberUserDOS = memberUserMapper.selectList(new LambdaQueryWrapper<MemberUserDO>()
+                    .eq(MemberUserDO::getId, userId)
+                    .isNotNull(MemberUserDO::getAndroidRegisterId));
+
+        }
+        return memberUserDOS.stream().map(MemberUserDO::getAndroidRegisterId).collect(Collectors.toList());
+    }
+
 }