Quellcode durchsuchen

增加查询在线用户人数接口

zhoupeng vor 2 Jahren
Ursprung
Commit
ad7f2a6c7f

+ 13 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/UserController.java

@@ -432,4 +432,17 @@ public class UserController {
         return userService.queryManagerUserNum();
     }
 
+    /**
+     * 在线用户人数
+     * @param loginType
+     * @return
+     */
+    @GetMapping("/getOnlineUser")
+    public Result getOnlineUser(String loginType){
+        if (Blank.isEmpty(loginType)){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return userService.getOnlineUser(loginType);
+    }
+
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/UserDao.java

@@ -143,4 +143,6 @@ public interface UserDao {
     Integer deleteUserDepartment(String userId, List<Department> departmentList);
 
     List<Department> getNoShareOldDepartmentList(String userId, List<Department> departmentList);
+
+    List<String> getAllUserIdByType(Integer userType);
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/UserService.java

@@ -123,4 +123,6 @@ public interface UserService {
 
 
     Result phoneUserLogin(User user);
+
+    Result getOnlineUser(String loginType);
 }

+ 20 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/UserServiceImpl.java

@@ -654,6 +654,26 @@ public class UserServiceImpl implements UserService {
         }
     }
 
+    @Override
+    public Result getOnlineUser(String loginType) {
+        if (loginType.equals(ConstantStr.FRONT_USER_String)) {
+            List<String> userIdList = userDao.getAllUserIdByType(ConstantStr.FRONT_USER);
+            if (Blank.isEmpty(userIdList)) {
+                return Result.ok(0);
+            } else {
+                int count = 0;
+                for (String userId : userIdList) {
+                    if (Blank.isNotEmpty(redisUtil.get(ConstantStr.FRONT_USER_String + userId))) {
+                        count += 1;
+                    }
+                }
+                return Result.ok(count);
+            }
+        } else {
+            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "当前只支持查看客户端在线用户人数");
+        }
+    }
+
 
     @Override
     public synchronized Result updateUser(User user) {

+ 6 - 0
chaunyi_opc/opc_da/src/main/resources/mapper/UserDao.xml

@@ -444,5 +444,11 @@
         )) sur on sr.id=sur.department_id
     </select>
 
+    <select id="getAllUserIdByType" resultType="java.lang.String">
+        select user_id
+        from sys_user
+        where user_type = #{userType}
+    </select>
+
 
 </mapper>