Browse Source

feat(sys): 优化后台用户登录及公海客户数据权限处理

- 后台用户登录使用RPC调用改进用户信息获取逻辑
- 登录验证码发送功能添加发送频率限制日志注释
- 公海客户联系人手机号及办公电话脱敏处理,非Admin角色隐藏部分信息
- 调整公海客户数据权限校验相关方法的代码格式和注释
- 解决部分代码风格统一问题,增加代码可读性
- 增加SysUserService中通过pin获取用户信息的新接口getUserInfoByPin
zhangxf 3 weeks ago
parent
commit
92a9f2fa66

+ 7 - 4
src/main/java/com/jtzx/crm/module/api/web/auth/AdminAuthController.java

@@ -32,6 +32,7 @@ import com.jtzx.crm.module.sys.annotation.SysLog;
 import com.jtzx.crm.module.sys.model.request.SysUserAccountLoginDTO;
 import com.jtzx.crm.module.sys.model.request.SysUserSmsCodeDTO;
 import com.jtzx.crm.module.sys.model.request.SysUserSmsCodeLoginDTO;
+import com.jtzx.crm.module.sys.model.response.SysUserBO;
 import com.jtzx.crm.module.sys.model.response.SysUserLoginBO;
 import com.jtzx.crm.module.sys.model.response.SysUserLoginVO;
 import com.jtzx.crm.module.sys.service.SysUserService;
@@ -67,6 +68,7 @@ public class AdminAuthController {
     /**
      * 账号密码登陆,输错5次,账号封禁 1800秒(半个小时),目前测试用 300 秒-5分钟,输错超3次,需要填写动态验证码
      * 这一步的登陆,不会返回token,登陆信息会存入redis 中 半个小时,半小时之内没有后续操作,就自动失效,后续其它操作都不能进行
+     *
      * @param dto
      * @return
      */
@@ -104,7 +106,7 @@ public class AdminAuthController {
         if (userInfo == null || StrUtil.isEmpty(userInfo.getPhoneNo())) {
             resultData.setStatus(false);
 
-            if(userInfo == null){
+            if (userInfo == null) {
                 return ApiResult.data("账号或密码错误", resultData).setCode(401);
             }
             if (StrUtil.isEmpty(userInfo.getPhoneNo())) {
@@ -122,6 +124,7 @@ public class AdminAuthController {
 
     /**
      * 发送登陆验证码,5分钟最多发3次
+     *
      * @return
      */
     @SysLog(value = "第二步后台用户登录发送登录短信验证码", extension = SysLogAspectExtensionForSmsCodeLogin.class, queryIPLocation = true)
@@ -155,7 +158,8 @@ public class AdminAuthController {
         }
         //账号密码查询用户信息
 //        SysUserLoginBO userInfo = this.getLoginUserInfo(dto.getMobile());
-        SysUserLoginBO userInfo = sysUserService.adminLogin(dto.getUsername(), dto.getPassword());
+        // RPC调用, 失败抛异常, 成功返回用户信息
+        SysUserBO userInfo = sysUserService.getUserInfoByPin(dto.getUsername());
         if (userInfo == null || StrUtil.isEmpty(userInfo.getPhoneNo()) || !userInfo.getPhoneNo().equals(dto.getMobile())) {
             resultData.setStatus(false);
             if (userInfo == null) {
@@ -182,7 +186,6 @@ public class AdminAuthController {
             resultData.setCaptchaVO(null);
             return ApiResult.data("发送成功", resultData);
         }
-
         return ApiResult.data("发送失败", resultData).setCode(406);
 
     }
@@ -235,7 +238,7 @@ public class AdminAuthController {
             }
         }
 
-        if(dto.getRememberMe()==null){
+        if (dto.getRememberMe() == null) {
             dto.setRememberMe(Boolean.FALSE);
         }
 

+ 33 - 15
src/main/java/com/jtzx/crm/module/sys/service/SysCustomerDataPublicService.java

@@ -8,6 +8,8 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.CharSequenceUtil;
+import cn.hutool.core.util.PhoneUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
@@ -63,7 +65,7 @@ public class SysCustomerDataPublicService {
      *
      * @return
      */
-    public SysCustomerPublicSelectBO queryHeadSelectData() throws BusinessException{
+    public SysCustomerPublicSelectBO queryHeadSelectData() throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         //返回数据对象
         SysCustomerPublicSelectBO resultData = SysCustomerPublicSelectBO.builder().build();
@@ -111,18 +113,19 @@ public class SysCustomerDataPublicService {
      * @param dto
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminInsertCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminInsertCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) throws BusinessException {
         permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.adminInsert(dto);
     }
 
     /**
      * 批量新增公海客户
+     *
      * @param dtoList
      * @throws BusinessException
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminInsertCustomerData(List<AdminSysCustomerDataInsertOrUpdateDTO> dtoList) throws BusinessException{
+    public void adminInsertCustomerData(List<AdminSysCustomerDataInsertOrUpdateDTO> dtoList) throws BusinessException {
         permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.importData(dtoList);
     }
@@ -134,7 +137,7 @@ public class SysCustomerDataPublicService {
      * @param dto
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) throws BusinessException {
         permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.adminUpdate(dto);
     }
@@ -145,7 +148,7 @@ public class SysCustomerDataPublicService {
      * @param id
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminDeleteCustomerData(Long id) throws BusinessException{
+    public void adminDeleteCustomerData(Long id) throws BusinessException {
         permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.adminDelete(id);
     }
@@ -156,7 +159,7 @@ public class SysCustomerDataPublicService {
      * @param customerId
      */
     @Transactional(rollbackFor = Exception.class)
-    public void claimCustomer(Long customerId) throws BusinessException{
+    public void claimCustomer(Long customerId) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
         sysCustomerDataService.claimCustomer(customerId);
     }
@@ -169,7 +172,7 @@ public class SysCustomerDataPublicService {
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException {
         permissionService.publicPrivateCustomerPermission();
         sysCustomerPersonService.adminInsert(dto);
     }
@@ -181,7 +184,7 @@ public class SysCustomerDataPublicService {
      * @param dto
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException{
+    public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) throws BusinessException {
         sysCustomerPersonService.adminUpdate(dto);
     }
 
@@ -191,16 +194,31 @@ public class SysCustomerDataPublicService {
      * @param id
      */
     @Transactional(rollbackFor = Exception.class)
-    public void adminDeleteCustomerPerson(Long id) throws BusinessException{
+    public void adminDeleteCustomerPerson(Long id) throws BusinessException {
         sysCustomerPersonService.adminDelete(id);
     }
 
     /**
      * 查询公海客户联系人
      */
-    public List<SysCustomerPersonBO> adminListCustomerPerson(CustomerPersonReqDTO dto) throws BusinessException{
+    public List<SysCustomerPersonBO> adminListCustomerPerson(CustomerPersonReqDTO dto) throws BusinessException {
 //        permissionService.publicPrivateCustomerPermission();
-        return sysCustomerPersonService.adminList(dto);
+        List<SysCustomerPersonBO> sysCustomerPersonBOS = sysCustomerPersonService.adminList(dto);
+
+        if (CollUtil.isNotEmpty(sysCustomerPersonBOS)) {
+            sysCustomerPersonBOS.forEach(bo -> {
+                if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
+                    //手机号脱敏
+                    bo.setPhoneNo(PhoneUtil.hideBetween(bo.getPhoneNo()).toString());
+                    if (StrUtil.isNotEmpty(bo.getOfficePhoneNo())) {
+                        String start = bo.getOfficePhoneNo().substring(0, 2);
+                        String end = bo.getOfficePhoneNo().substring(bo.getOfficePhoneNo().length() - 2);
+                        bo.setOfficePhoneNo(start + "****" + end);
+                    }
+                }
+            });
+        }
+        return sysCustomerPersonBOS;
     }
 
 
@@ -219,7 +237,7 @@ public class SysCustomerDataPublicService {
         dto.setUserId(null);
 
         detailBO.setHistoryFollowStatus(sysUserEntity.getHistoryFollowStatus() == null ? 0 : sysUserEntity.getHistoryFollowStatus());
-        if(UserContextHolder.getUserContext().getRoles().contains("Admin")){
+        if (UserContextHolder.getUserContext().getRoles().contains("Admin")) {
             detailBO.setHistoryFollowStatus(1);
         }
         //历史跟进总览开关
@@ -242,13 +260,13 @@ public class SysCustomerDataPublicService {
     /**
      * 操作日志列表查询
      */
-    public SysCustomerOperLogDataBO queryOperLogData(AdminSysCustomerOperLogListDTO dto) throws BusinessException{
+    public SysCustomerOperLogDataBO queryOperLogData(AdminSysCustomerOperLogListDTO dto) throws BusinessException {
         permissionService.publicPrivateCustomerPermission();
         List<Long> userIds = Lists.newArrayList();
         if (dto.getOperUserId() != null) {
             userIds.add(dto.getOperUserId());
-        }else {
-            if(!UserContextHolder.getUserContext().getRoles().contains("Admin")){
+        } else {
+            if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
                 userIds.add(UserContextHolder.getUserId());
             }
         }

+ 6 - 0
src/main/java/com/jtzx/crm/module/sys/service/SysUserService.java

@@ -301,6 +301,12 @@ public class SysUserService {
     }
 
 
+    public SysUserBO getUserInfoByPin(String pin) {
+
+        // 取账号完整信息
+        return this.entity2BO(this.getUserByPin(pin));
+    }
+
     /*
     ----------------------------------------------------------------
                         私有方法 private methods