1.change findAllById to orderByField

main
Gary 10 months ago
parent 54c7f42cdd
commit 43b25f1b5b

@ -102,7 +102,7 @@ public class ManageAdminController {
@GetMapping("/ids/{ids}") @GetMapping("/ids/{ids}")
public Result<List<Admin>> findAllById(@PathVariable @VerifyParam(required=true) String ids){ public Result<List<Admin>> findAllById(@PathVariable @VerifyParam(required=true) String ids){
List<String> idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList()); List<String> idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList());
return Result.success(adminService.findAllById(idList)); return Result.success(adminService.orderByField(idList));
} }

@ -142,8 +142,8 @@ public class ManageUserController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "多个id以','分隔", required = true) }) @ApiImplicitParam(name = "ids", value = "多个id以','分隔", required = true) })
@GetMapping("/ids/{ids}") @GetMapping("/ids/{ids}")
public Result<List<UserInfo>> findAllById(@PathVariable @VerifyParam(required=true) String ids){ public Result<List<UserInfo>> orderByField(@PathVariable @VerifyParam(required=true) String ids){
List<String> idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList()); List<String> idList=Arrays.stream(ids.split(",")).map(String::trim).collect(Collectors.toList());
return Result.success(userInfoService.findAllById(idList)); return Result.success(userInfoService.orderByField(idList));
} }
} }

@ -1,7 +1,10 @@
package com.luoo.user.dao; package com.luoo.user.dao;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import com.luoo.user.pojo.Admin; import com.luoo.user.pojo.Admin;
/** /**
@ -12,4 +15,6 @@ import com.luoo.user.pojo.Admin;
public interface AdminDao extends JpaRepository<Admin,String>,JpaSpecificationExecutor<Admin>{ public interface AdminDao extends JpaRepository<Admin,String>,JpaSpecificationExecutor<Admin>{
public Admin findByLoginname(String loginname); public Admin findByLoginname(String loginname);
@Query(value = "select * from tb_admin where id in ?1 order by field(id,?1)", nativeQuery = true)
public List<Admin> orderByField(List<String> idList);
} }

@ -1,11 +1,14 @@
package com.luoo.user.dao; package com.luoo.user.dao;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import com.luoo.user.pojo.Admin;
import com.luoo.user.pojo.UserInfo; import com.luoo.user.pojo.UserInfo;
public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecificationExecutor<UserInfo> { public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecificationExecutor<UserInfo> {
@ -20,4 +23,7 @@ public interface UserInfoDao extends JpaRepository<UserInfo, String>, JpaSpecifi
void updatefanscount(int x, String friendid); void updatefanscount(int x, String friendid);
public long countByNickName(String nickName); 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<UserInfo> orderByField(List<String> idList);
} }

@ -22,6 +22,8 @@ import util.IdWorker;
import com.luoo.user.dao.AdminDao; import com.luoo.user.dao.AdminDao;
import com.luoo.user.pojo.Admin; 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()])); return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
} }
}; };
} }
public List<Admin> findAllById(List<String> idList) { public List<Admin> orderByField(List<String> idList) {
return adminDao.findAllById(idList); return adminDao.orderByField(idList);
} }
} }

@ -305,7 +305,7 @@ public class UserInfoService {
return jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER); return jwtUtil.createJWT(user.getId(),user.getNickName(),Constants.TOKEN_ROLE_APP_USER);
} }
public List<UserInfo> findAllById(List<String> idList) { public List<UserInfo> orderByField(List<String> idList) {
return userInfoDao.findAllById(idList); return userInfoDao.orderByField(idList);
} }
} }

Loading…
Cancel
Save