From 43b25f1b5b08510af8ce13b8e0ba7e981b4df1f8 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 22 Jan 2024 14:01:52 +0800 Subject: [PATCH] 1.change findAllById to orderByField --- .../com/luoo/user/controller/ManageAdminController.java | 2 +- .../com/luoo/user/controller/ManageUserController.java | 4 ++-- luoo_user/src/main/java/com/luoo/user/dao/AdminDao.java | 5 +++++ .../src/main/java/com/luoo/user/dao/UserInfoDao.java | 6 ++++++ .../src/main/java/com/luoo/user/service/AdminService.java | 8 ++++---- .../main/java/com/luoo/user/service/UserInfoService.java | 4 ++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/ManageAdminController.java b/luoo_user/src/main/java/com/luoo/user/controller/ManageAdminController.java index d7ae12d..4c7f888 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/ManageAdminController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/ManageAdminController.java @@ -102,7 +102,7 @@ public class ManageAdminController { @GetMapping("/ids/{ids}") public Result> findAllById(@PathVariable @VerifyParam(required=true) String ids){ List idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList()); - return Result.success(adminService.findAllById(idList)); + return Result.success(adminService.orderByField(idList)); } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/ManageUserController.java b/luoo_user/src/main/java/com/luoo/user/controller/ManageUserController.java index 1ef832d..772a429 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/ManageUserController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/ManageUserController.java @@ -142,8 +142,8 @@ public class ManageUserController { @ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "多个id以','分隔", required = true) }) @GetMapping("/ids/{ids}") - public Result> findAllById(@PathVariable @VerifyParam(required=true) String ids){ + public Result> orderByField(@PathVariable @VerifyParam(required=true) String ids){ List idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList()); - return Result.success(userInfoService.findAllById(idList)); + return Result.success(userInfoService.orderByField(idList)); } } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/AdminDao.java b/luoo_user/src/main/java/com/luoo/user/dao/AdminDao.java index aba42d6..c7f4c2c 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/AdminDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/AdminDao.java @@ -1,7 +1,10 @@ package com.luoo.user.dao; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; import com.luoo.user.pojo.Admin; /** @@ -12,4 +15,6 @@ import com.luoo.user.pojo.Admin; public interface AdminDao extends JpaRepository,JpaSpecificationExecutor{ public Admin findByLoginname(String loginname); + @Query(value = "select * from tb_admin where id in ?1 order by field(id,?1)", nativeQuery = true) + public List orderByField(List idList); } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java index b77e0a3..a68949d 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java @@ -1,11 +1,14 @@ package com.luoo.user.dao; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import com.luoo.user.pojo.Admin; import com.luoo.user.pojo.UserInfo; public interface UserInfoDao extends JpaRepository, JpaSpecificationExecutor { @@ -20,4 +23,7 @@ public interface UserInfoDao extends JpaRepository, JpaSpecifi void updatefanscount(int x, String friendid); public long countByNickName(String nickName); + + @Query(value = "select * from tb_user_info where id in ?1 order by field(id,?1)", nativeQuery = true) + public List orderByField(List idList); } diff --git a/luoo_user/src/main/java/com/luoo/user/service/AdminService.java b/luoo_user/src/main/java/com/luoo/user/service/AdminService.java index 0027ff7..f5471d2 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/AdminService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/AdminService.java @@ -22,6 +22,8 @@ import util.IdWorker; import com.luoo.user.dao.AdminDao; import com.luoo.user.pojo.Admin; +import api.Result; + /** * 服务层 * @@ -153,14 +155,12 @@ public class AdminService { } return cb.and( predicateList.toArray(new Predicate[predicateList.size()])); - } }; - } - public List findAllById(List idList) { - return adminDao.findAllById(idList); + public List orderByField(List idList) { + return adminDao.orderByField(idList); } } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index 03a80ee..9165481 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -305,7 +305,7 @@ public class UserInfoService { return jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER); } - public List findAllById(List idList) { - return userInfoDao.findAllById(idList); + public List orderByField(List idList) { + return userInfoDao.orderByField(idList); } }