Browse Source

发送客服消息

Eric 2 years ago
parent
commit
fd1ec76c24

+ 5 - 0
cooleshow-common/pom.xml

@@ -49,6 +49,11 @@
 			<groupId>org.springframework.cloud</groupId>
 			<artifactId>spring-cloud-starter-oauth2</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework.security.oauth</groupId>
+			<artifactId>spring-security-oauth2</artifactId>
+			<version>2.3.3.RELEASE</version>
+		</dependency>
 
 		<dependency>
 			<groupId>com.baomidou</groupId>

+ 7 - 2
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/io/request/im/IMNotifyMessageVO.java

@@ -1,16 +1,15 @@
 package com.yonge.cooleshow.admin.io.request.im;
 
 import com.alibaba.fastjson.JSON;
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.Serializable;
 import java.util.List;
-import java.util.Optional;
 
 /**
  * 系统IM通知信息
@@ -39,6 +38,12 @@ public class IMNotifyMessageVO implements Serializable {
     @ApiModelProperty(value = "图片文件地址")
     private String imgUrl;
 
+    @ApiModelProperty("用户身份")
+    private ClientEnum clientType;
+
+    @ApiModelProperty("声部ID")
+    private String subjectId;
+
     public String jsonString() {
 
         return JSON.toJSONString(this);

+ 11 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/SysUserMapper.java

@@ -1,11 +1,12 @@
 package com.yonge.cooleshow.biz.dal.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
 import com.yonge.cooleshow.biz.dal.entity.SysUser;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.vo.CouponIssueUserVo;
+import com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -30,8 +31,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
      * @param keyword 查询条件
      * @return
      */
-    List<CouponIssueUserVo> queryCouponIssueUser(@Param("iPage") IPage<CouponIssueUserVo> iPage, @Param(
-            "client") ClientEnum client, @Param("keyword") String keyword);
+    List<CouponIssueUserVo> queryCouponIssueUser(@Param("iPage") IPage<CouponIssueUserVo> iPage,
+                                                 @Param("client") ClientEnum client, @Param("keyword") String keyword);
 
 
     /***
@@ -42,4 +43,11 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
      * @return: java.lang.Integer
      */
     Integer updateUserCard(@Param("param") RealnameAuthReq param);
+
+    /**
+     * 客服消息接收者
+     * @param message 客服消息
+     * @return List<CustomerService.MessageReceives>
+     */
+    List<CustomerService.MessageReceives> selectMessageReceives(@Param("param") CustomerService.NotifyMessage message);
 }

+ 28 - 14
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImUserFriendServiceImpl.java

@@ -269,14 +269,34 @@ public class ImUserFriendServiceImpl extends ServiceImpl<ImUserFriendDao, ImUser
             throw new BizException("无效的客服联系方式");
         }
 
-        LambdaQueryWrapper<com.yonge.cooleshow.biz.dal.entity.SysUser> wrapper = Wrappers.<com.yonge.cooleshow.biz.dal.entity.SysUser>lambdaQuery()
-                .select(com.yonge.cooleshow.biz.dal.entity.SysUser::getId,
-                        com.yonge.cooleshow.biz.dal.entity.SysUser::getUsername)
-                .in(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone, info.getReceives());
-
-        wrapper.last("LIMIT 1000");
-        // 接收者信息
-        List<com.yonge.cooleshow.biz.dal.entity.SysUser> sysUsers = sysUserMapper.selectList(wrapper);
+        List<String> receiveUserIds;
+        if (Objects.nonNull(info.getClientType())) {
+
+            receiveUserIds = sysUserMapper.selectMessageReceives(info).stream()
+                    .map(x -> String.valueOf(x.getUserId()))
+                    .collect(Collectors.toList());
+            if (ClientEnum.STUDENT == info.getClientType()) {
+                receiveUserIds = receiveUserIds.stream()
+                        .map(x -> MessageFormat.format("{0}:STUDENT", x))
+                        .collect(Collectors.toList());
+            }
+        } else {
+
+            LambdaQueryWrapper<com.yonge.cooleshow.biz.dal.entity.SysUser> wrapper = Wrappers.<com.yonge.cooleshow.biz.dal.entity.SysUser>lambdaQuery()
+                    .select(com.yonge.cooleshow.biz.dal.entity.SysUser::getId,
+                            com.yonge.cooleshow.biz.dal.entity.SysUser::getUsername)
+                    .in(com.yonge.cooleshow.biz.dal.entity.SysUser::getPhone, info.getReceives());
+
+            wrapper.last("LIMIT 1500");
+            // 接收者信息
+            List<com.yonge.cooleshow.biz.dal.entity.SysUser> sysUsers = sysUserMapper.selectList(wrapper);
+
+            // 分批次发送用户消息
+            receiveUserIds = sysUsers.stream()
+                    .map(com.yonge.cooleshow.biz.dal.entity.SysUser::getId)
+                    .map(String::valueOf)
+                    .collect(Collectors.toList());
+        }
 
         // 发送图片消息
         ImgMessage imgMessage = new ImgMessage(imageToBase64(info.getImgMessage(), "png"), "", info.getImgUrl());
@@ -292,12 +312,6 @@ public class ImUserFriendServiceImpl extends ServiceImpl<ImUserFriendDao, ImUser
                 new PushExt.APNs("", ""),
                 new PushExt.OPPO(""));
 
-        // 分批次发送用户消息
-        List<String> receiveUserIds = sysUsers.stream()
-                .map(com.yonge.cooleshow.biz.dal.entity.SysUser::getId)
-                .map(String::valueOf)
-                .collect(Collectors.toList());
-
         String senderId = String.valueOf(senderUser.getId());
         PrivateMessage privateMessage;
         ResponseResult privateResult;

+ 21 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/im/CustomerService.java

@@ -1,10 +1,12 @@
 package com.yonge.cooleshow.biz.dal.wrapper.im;
 
 import com.alibaba.fastjson.JSON;
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
 
 import java.io.Serializable;
 import java.util.List;
@@ -25,6 +27,8 @@ public class CustomerService {
     public static class NotifyMessage implements Serializable {
 
         private List<String> receives;
+        private ClientEnum clientType;
+        private String subjectId;
 
         private String title;
         private String txtMessage;
@@ -35,5 +39,22 @@ public class CustomerService {
 
             return JSON.parseObject(recv, NotifyMessage.class);
         }
+
+        public List<String> getReceives() {
+            if (CollectionUtils.isEmpty(receives)) {
+                return null;
+            }
+            return receives;
+        }
+    }
+
+    /**
+     * 消息接收者
+     */
+    @Data
+    public static class MessageReceives implements Serializable {
+
+        private Long userId;
+        private String nickname;
     }
 }

+ 20 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/SysUserMapper.xml

@@ -85,4 +85,24 @@
         update_time_ = now()
         WHERE del_flag_ = 0 and id_ = #{param.userId}
     </update>
+
+    <!--客服消息接收者-->
+    <select id="selectMessageReceives"
+            resultType="com.yonge.cooleshow.biz.dal.wrapper.im.CustomerService$MessageReceives">
+        SELECT t1.id_ AS userId, t1.username_ FROM sys_user t1
+        <if test="param.clientType != null">
+            <if test="param.clientType.code == 'TEACHER'"> LEFT JOIN teacher t2 ON (t1.id_ = t2.user_id_)</if>
+            <if test="param.clientType.code == 'STUDENT'"> LEFT JOIN student t2 ON (t1.id_ = t2.user_id_)</if>
+        </if>
+        <where>
+            <if test="param.receives != null">
+                AND t1.phone_ IN (<foreach collection="param.receives" separator="," item="item">#{item}</foreach>)
+            </if>
+            <if test="param.subjectId != null">
+                AND FIND_IN_SET(#{param.subjectId}, t2.subject_id_)
+            </if>
+        </where>
+        LIMIT 1500
+    </select>
+    <!--客服消息接收者-->
 </mapper>