Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

huangguoce 1 dienu atpakaļ
vecāks
revīzija
aa8f8afd05

+ 6 - 4
jeeplus-api/jeeplus-system-api/src/main/java/com/jeeplus/sys/factory/UserApiFallbackFactory.java

@@ -12,10 +12,7 @@ import org.springframework.cloud.openfeign.FallbackFactory;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * 用户服务降级处理
@@ -251,6 +248,11 @@ public class UserApiFallbackFactory implements FallbackFactory <IUserApi> {
                 return null;
             }
 
+            @Override
+            public List<UserDTO> getOnLineUserList(String loginName, String tenantId) {
+                return null;
+            }
+
         };
     }
 }

+ 12 - 0
jeeplus-api/jeeplus-system-api/src/main/java/com/jeeplus/sys/feign/IUserApi.java

@@ -358,6 +358,18 @@ public interface IUserApi {
     UserDTO getByMobile(@RequestParam(value = "mobilePhone")String mobilePhone);
     @GetMapping(value = BASE_URL + "/selectByMobile")
     UserDTO selectByMobile(@RequestParam(value = "mobilePhone")String mobilePhone);
+
+
+
+    /**
+     * 根据登录名和对应租户id查询登陆人员信息
+     * @param loginName
+     * @param tenantId
+     * @return
+     */
+    @GetMapping(value = BASE_URL + "/getOnLineUserList")
+    List <UserDTO> getOnLineUserList(@RequestParam("loginName") String loginName,@RequestParam("tenantId") String tenantId);
+
 }
 
 

+ 25 - 0
jeeplus-auth/src/main/java/com/jeeplus/auth/controller/LoginController.java

@@ -50,6 +50,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 import java.util.UUID;
 
 /**
@@ -136,6 +137,22 @@ public class LoginController {
 
         //登录成功,生成token
         UserDTO userDTO = userApi.getByLoginName ( username, tenantApi.getCurrentTenantId ( ) );
+
+
+        if("樊莉".equals(userDTO.getName())){
+
+            List<UserDTO> onLineUserList = SpringUtil.getBean(IUserApi.class).getOnLineUserList("黄玮", "10002");
+            if(!onLineUserList.isEmpty()){
+                throw new DisabledException ( "当前黄玮已登录系统," + ErrorConstants.LOGIN_ERROR );
+            }
+        }else if("黄玮".equals(userDTO.getName())){
+            List<UserDTO> onLineUserList = SpringUtil.getBean(IUserApi.class).getOnLineUserList("樊莉", "10002");
+            if(!onLineUserList.isEmpty()){
+                throw new DisabledException ( "当前樊莉已登录系统," + ErrorConstants.LOGIN_ERROR );
+            }
+        }
+
+
         String token = TokenProvider.createAccessToken ( username );
         responseUtil.add ( TokenProvider.TOKEN, token );
         //更新登录信息
@@ -273,6 +290,7 @@ public class LoginController {
     @GetMapping("/logout")
     public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) {
         Authentication auth = SecurityUtils.getAuthentication ( );
+        UserDTO currentUserDTO = SecurityUtils.getCurrentUserDTO();
         if ( auth != null ) {
             userApi.clearCache ( SecurityUtils.getCurrentUserDTO ( ) );
             String token = TokenProvider.resolveToken ( request );
@@ -280,6 +298,13 @@ public class LoginController {
             redisUtils.delete ( CacheNames.USER_CACHE_ONLINE_USERS, token );
             new SecurityContextLogoutHandler ( ).logout ( request, response, auth );
         }
+        //查询系统中是否存在相同登录名的其他登录信息。若存在,则将其他信息同时进行下线处理
+        List<UserDTO> onLineUserList = SpringUtil.getBean(IUserApi.class).getOnLineUserList(currentUserDTO.getLoginName(), "");
+        for (UserDTO userDTO : onLineUserList) {
+            userApi.clearCache ( userDTO );
+            redisUtils.delete ( CacheNames.USER_CACHE_TOKEN, userDTO.getToken() );
+            redisUtils.delete ( CacheNames.USER_CACHE_ONLINE_USERS, userDTO.getToken() );
+        }
         return ResponseEntity.ok ( "退出成功" );
     }
 

+ 1 - 0
jeeplus-common/jeeplus-common-core/src/main/java/com/jeeplus/common/constant/ErrorConstants.java

@@ -12,4 +12,5 @@ public interface ErrorConstants {
     String LOGIN_ERROR_ERROR_VALIDATE_CODE = "您输入的验证码不正确,请重新输入!";
     String LOGIN_CODE = "请输入验证码进行登录!";
     String LOGIN_MAX_COUNT = "今天登录次数已达最大,请明天再登录!";
+    String LOGIN_ERROR = "您目前无法登录!";
 }

+ 5 - 0
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/feign/UserApiImpl.java

@@ -296,4 +296,9 @@ public class UserApiImpl implements IUserApi {
         return userService.selectByMobile(mobilePhone);
     }
 
+    @Override
+    public List<UserDTO> getOnLineUserList(String loginName, String tenantId) {
+        return userService.getOnLineUserList ( loginName, tenantId );
+    }
+
 }

+ 9 - 0
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/mapper/UserMapper.java

@@ -297,4 +297,13 @@ public interface UserMapper extends BaseMapper <User> {
     UserDTO getByMobile(@Param("mobilePhone")String mobilePhone);
     @InterceptorIgnore(tenantLine = "true")
     UserDTO selectByMobile(@Param("mobilePhone")String mobilePhone);
+
+    /**
+     * 根据登录名和对应租户id查询登陆人员信息
+     * @param loginName
+     * @param tenantId
+     * @return
+     */
+    @InterceptorIgnore(tenantLine = "true")
+    UserDTO getByLoginName(@Param("loginName") String loginName, @Param("tenantId")String tenantId);
 }

+ 28 - 0
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/mapper/xml/UserMapper.xml

@@ -714,4 +714,32 @@ select a.id, a.company_id as "companyDTO.id", a.office_id as "officeDTO.id", a.l
 		from sys_user a
 		where a.mobile = #{mobilePhone} and a.del_flag = '0'
     </select>
+
+
+    <select id="getByLoginName" resultType="com.jeeplus.sys.service.dto.UserDTO">
+        select a.id,
+               a.company_id as "companyDTO.id",
+               a.office_id as "officeDTO.id",
+               a.login_name as "loginName",
+               a.password,
+               a.no,
+               a.name,
+               a.email, a.phone,
+               a.mobile,
+               a.login_ip as "loginIp", a.login_date as "loginDate",
+               a.remarks,
+               a.login_flag, a.photo, a.qr_code, a.sign,
+               a.create_by_id as "createBy.id", a.create_time, a.update_by_id as "updateBy.id",
+               a.update_time
+        from sys_user a
+        <where>
+            a.login_flag = 1 and a.del_flag = 0
+            and (a.login_name = #{loginName} or a.name = #{loginName} or a.mobile = #{loginName})
+            <if test="tenantId != null and tenantId != ''">
+                and a.tenant_id = #{tenantId}
+            </if>
+        </where>
+        order by a.update_time desc
+        limit 1
+    </select>
 </mapper>

+ 34 - 2
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/service/UserService.java

@@ -47,6 +47,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 用户管理
@@ -609,8 +610,7 @@ public class UserService extends ServiceImpl<UserMapper, User> {
     /**
      * 查询签字注师二信息集合
      *
-     * @param page
-     * @param
+     * @param dto
      * @return
      */
     public List<UserDTO> getSignatureAnnotator2List(UserDTO dto) {
@@ -836,4 +836,36 @@ public class UserService extends ServiceImpl<UserMapper, User> {
     public UserDTO selectByMobile(String mobilePhone) {
         return userMapper.selectByMobile(mobilePhone);
     }
+
+    /**
+     * 根据登录名和对应租户id查询登陆人员信息
+     * @param loginNanme
+     * @param tenantId
+     * @return
+     */
+    public List <UserDTO> getOnLineUserList(String loginNanme, String tenantId) {
+        UserDTO userDTO= userMapper.getByLoginName(loginNanme,tenantId);
+        if (StringUtils.isBlank(tenantId)) {
+            tenantId = "10000";
+        }
+        Stream<UserDTO> list = UserUtils.getOnlineUsers ( ).stream ( );
+        if ( StrUtil.isNotEmpty ( userDTO.getLoginName ( ) ) ) {
+            list = list.filter ( user -> user.getLoginName ( ).contains ( userDTO.getLoginName ( ) ) );
+
+        }
+        if ( StrUtil.isNotEmpty ( userDTO.getName ( ) ) ) {
+            list = list.filter ( user -> user.getName ( ).contains ( userDTO.getName ( ) ) );
+        }
+        if ( !CommonConstants.DEFAULT_TENANT_ID.equals ( tenantId ) ) { // 非平台租户只显示租户内在线用户
+
+            String finalTenantId = tenantId;
+            list = list.filter (user -> user.getTenantDTO ( ).getId ( ).contains (finalTenantId) );
+
+        }
+        List <UserDTO> users = list.collect ( Collectors.toList ( ) );
+
+        return users;
+
+    }
+
 }

+ 6 - 11
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/sms/EncryptUtil.java

@@ -14,8 +14,7 @@ package com.jeeplus.sys.sms;
 
 
 
-import sun.misc.BASE64Decoder;
-import sun.misc.BASE64Encoder;
+import java.util.Base64;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
@@ -34,17 +33,13 @@ public class EncryptUtil
     return byte2HexStr(b);
   }
 
-  public String base64Encoder(String src) throws UnsupportedEncodingException
-  {
-    BASE64Encoder encoder = new BASE64Encoder();
-    return encoder.encode(src.getBytes("utf-8"));
+  public String base64Encoder(String src) throws UnsupportedEncodingException {
+    return Base64.getEncoder().encodeToString(src.getBytes("UTF-8"));
   }
 
-  public String base64Decoder(String dest)
-    throws NoSuchAlgorithmException, IOException
-  {
-    BASE64Decoder decoder = new BASE64Decoder();
-    return new String(decoder.decodeBuffer(dest), "utf-8");
+  public String base64Decoder(String dest) throws UnsupportedEncodingException {
+    byte[] decodedBytes = Base64.getDecoder().decode(dest);
+    return new String(decodedBytes, "UTF-8");
   }
 
   private String byte2HexStr(byte[] b)