Преглед на файлове

调整新用户客服好友流程

Eric преди 2 години
родител
ревизия
eb5ec6f1fd

+ 26 - 0
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/config/CustomerServiceConfig.java

@@ -0,0 +1,26 @@
+package com.yonge.cooleshow.auth.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+/**
+ * 系统客服配置
+ * Created by Eric.Shang on 2022/9/21.
+ */
+@Data
+@RefreshScope
+@Component
+public class CustomerServiceConfig implements Serializable {
+
+    @Value("${app.customer.service:17740683946}")
+    private String customerService;
+    @Value("${app.customer.message:}")
+    private String customerMessage;
+    @Value("${app.customer.title:}")
+    private String customerTitle;
+
+}

+ 1 - 1
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/AuthServerApplication.java

@@ -19,7 +19,7 @@ import com.spring4all.swagger.EnableSwagger2Doc;
 @EnableDiscoveryClient
 @EnableFeignClients("com.yonge.cooleshow")
 @MapperScan("com.yonge.cooleshow.auth.dal.dao")
-@ComponentScan(basePackages = {"com.yonge.cooleshow", "com.yonge.toolset"})
+@ComponentScan(basePackages = {"com.yonge.cooleshow", "com.yonge.toolset", "com.yonge.cooleshow.auth.config"})
 @Configuration
 @EnableSwagger2Doc
 @EnableAsync

+ 6 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/provider/PhoneAuthenticationProvider.java

@@ -1,6 +1,7 @@
 package com.yonge.cooleshow.auth.core.provider;
 
 import java.util.Date;
+import java.util.Objects;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.security.authentication.BadCredentialsException;
@@ -77,6 +78,11 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
 
             userInfo = sysUserService.registerUser(loginEntity.getPhone(), clientId, loginUserType);
 
+            if (Objects.nonNull(userInfo.getSysUser())) {
+                // 自动添加系统默认IM帐号为好友,并自动发送通知消息
+                sysUserService.sendSysCustomerServiceFriendMessage(userInfo.getSysUser());
+            }
+
             if (StringUtils.isNotBlank(deviceNum)) {
                 sysUserDeviceService.bindDevice(clientId, userInfo.getSysUser().getId(), deviceNum);
             }

+ 6 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/service/SysUserService.java

@@ -121,6 +121,12 @@ public interface SysUserService extends BaseService<Long, SysUser> {
     SysUserInfo registerUser(String phone, String clientId, String loginUserType);
 
     /**
+     * 添加系统客服好友消息
+     * @param sysUser SysUser
+     */
+    void sendSysCustomerServiceFriendMessage(SysUser sysUser);
+
+    /**
      * 刷新token
      *
      * @param sysUser

+ 18 - 18
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/service/impl/SysUserServiceImpl.java

@@ -11,6 +11,7 @@ import com.yonge.cooleshow.auth.api.dto.SysUserQueryInfo;
 import com.yonge.cooleshow.auth.api.dto.UserSetReq;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.auth.api.vo.UserSetVo;
+import com.yonge.cooleshow.auth.config.CustomerServiceConfig;
 import com.yonge.cooleshow.auth.config.RongCloudConfig;
 import com.yonge.cooleshow.auth.dal.dao.SysUserDao;
 import com.yonge.cooleshow.auth.service.SysConfigService;
@@ -32,19 +33,22 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 import java.util.Random;
 import java.util.stream.Collectors;
 
 @Slf4j
 @Service
+@RefreshScope
 public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implements SysUserService {
 
     @Autowired
@@ -59,10 +63,8 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
     private RedissonClient redissonClient;
     @Resource
     private AdminFeignService adminFeignService;
-
-    // 新用户注册,默认添加官方客服联系人配置
-    @Value("${app.customer.service:17740683946}")
-    private String customerService;
+    @Autowired
+    private CustomerServiceConfig customerServiceConfig;
 
     @Override
     public BaseDAO<Long, SysUser> getDAO() {
@@ -151,16 +153,19 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
     @Override
     @Transactional(rollbackFor = Exception.class)
     public SysUserInfo registerUser(String phone, String clientId, String loginUserType) {
+
+        SysUserInfo userInfo = null;
         if (StringUtils.equalsIgnoreCase(loginUserType, "TEACHER")) {
-            return registerTeacher(phone);
+            userInfo = registerTeacher(phone);
         } else if (StringUtils.equalsIgnoreCase(loginUserType, "STUDENT")) {
-            return registerStudent(phone);
+            userInfo = registerStudent(phone);
         } else if (StringUtils.equalsIgnoreCase(clientId, "TEACHER")) {
-            return registerTeacher(phone);
+            userInfo = registerTeacher(phone);
         } else if (StringUtils.equalsIgnoreCase(clientId, "STUDENT")) {
-            return registerStudent(phone);
+            userInfo = registerStudent(phone);
         }
-        return null;
+
+        return userInfo;
     }
 
     private SysUserInfo registerTeacher(String phone) {
@@ -177,9 +182,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
         sysUser.setUsername("游客" + sysUser.getId());
         sysUserDao.update(sysUser);
 
-        // 自动添加系统默认IM帐号为好友,并自动发送通知消息
-        sendSysCustomerServiceFriendMessage(sysUser);
-
         return queryUserInfoByPhone(phone);
     }
 
@@ -197,9 +199,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
         sysUser.setUsername("游客" + sysUser.getId());
         sysUserDao.update(sysUser);
 
-        // 自动添加系统默认IM帐号为好友,并自动发送通知消息
-        sendSysCustomerServiceFriendMessage(sysUser);
-
         return queryUserInfoByPhone(phone);
     }
 
@@ -207,12 +206,13 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
      * 添加系统客服好友消息
      * @param sysUser SysUser
      */
-    private void sendSysCustomerServiceFriendMessage(SysUser sysUser) {
+    public void sendSysCustomerServiceFriendMessage(SysUser sysUser) {
 
         try {
 
             ThreadPool.getExecutor().submit(() -> {
 
+                String customerService = customerServiceConfig.getCustomerService();
                 if (StringUtils.isNotEmpty(customerService)) {
 
                     List<String> collect = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
@@ -228,7 +228,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<Long, SysUser> implement
                             .userId(sysUser.getId())
                             .friendIds(Lists.newArrayList(friend.getId()))
                             .build());
-                    log.info("sendSysCustomerServiceFriendMessage ret={}", JSON.toJSONString(result));
+                    log.info("sendSysCustomerServiceFriendMessage mobile={}, ret={}", mobile, JSON.toJSONString(result));
                 }
 
             });

+ 1 - 1
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/AdminApplication.java

@@ -16,7 +16,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableDiscoveryClient
 @EnableFeignClients("com.yonge.cooleshow")
 @MapperScan(basePackages = {"com.yonge.cooleshow.biz.dal.dao", "com.yonge.cooleshow.biz.dal.mapper", "com.yonge.toolset.payment.core.dao"})
-@ComponentScan(basePackages = {"com.yonge.cooleshow", "com.yonge.toolset"})
+@ComponentScan(basePackages = {"com.yonge.cooleshow", "com.yonge.toolset", "com.yonge.cooleshow.auth.config"})
 @Configuration
 @EnableSwagger2Doc
 @EnableScheduling

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

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Sets;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
+import com.yonge.cooleshow.auth.config.CustomerServiceConfig;
 import com.yonge.cooleshow.biz.dal.config.RongCloudConfig;
 import com.yonge.cooleshow.biz.dal.dao.ImUserFriendDao;
 import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
@@ -18,7 +19,7 @@ import io.rong.models.response.ResponseResult;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -45,11 +46,8 @@ public class ImUserFriendServiceImpl extends ServiceImpl<ImUserFriendDao, ImUser
     private TeacherDao teacherDao;
     @Resource
     private SysUserFeignService sysUserFeignService;
-
-    @Value("${app.customer.message:}")
-    private String customerMessage;
-    @Value("${app.customer.title:}")
-    private String customerTitle;
+    @Autowired
+    private CustomerServiceConfig customerServiceConfig;
 
     @Override
     public ImUserFriendDao getDao() {
@@ -133,9 +131,12 @@ public class ImUserFriendServiceImpl extends ServiceImpl<ImUserFriendDao, ImUser
         try {
 
             // 设置默认值
+            String customerMessage = customerServiceConfig.getCustomerMessage();
             if (StringUtils.isEmpty(customerMessage)) {
                 customerMessage = MK.IM_SYS_FRIEND;
             }
+
+            String customerTitle = customerServiceConfig.getCustomerTitle();
             if (StringUtils.isEmpty(customerTitle)) {
                 customerTitle = MK.IM_SYS_TITLE;
             }