Optimize search in user management api
This commit is contained in:
@@ -16,7 +16,7 @@ import top.fatweb.api.entity.permission.User
|
|||||||
interface UserMapper : BaseMapper<User> {
|
interface UserMapper : BaseMapper<User> {
|
||||||
fun selectOneWithPowerInfoByUsername(@Param("username")username: String): User?
|
fun selectOneWithPowerInfoByUsername(@Param("username")username: String): User?
|
||||||
|
|
||||||
fun selectPage(page: IPage<Long>, searchValue: String?, searchRegex: Boolean): IPage<Long>
|
fun selectPage(page: IPage<Long>, searchType: String, searchValue: String?, searchRegex: Boolean): IPage<Long>
|
||||||
|
|
||||||
fun selectListWithRoleInfoByIds(userIds: List<Long>): List<User>?
|
fun selectListWithRoleInfoByIds(userIds: List<Long>): List<User>?
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import top.fatweb.api.param.PageSortParam
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "用户查询请求参数")
|
@Schema(description = "用户查询请求参数")
|
||||||
data class UserGetParam(
|
data class UserGetParam(
|
||||||
|
@Schema(description = "搜索类型", allowableValues = ["ALL", "ID", "USERNAME", "NICKNAME", "EMAIL"], defaultValue = "ALL")
|
||||||
|
val searchType: String = "ALL",
|
||||||
|
|
||||||
@Schema(description = "查询内容")
|
@Schema(description = "查询内容")
|
||||||
val searchValue: String? = null,
|
val searchValue: String? = null,
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class UserServiceImpl(
|
|||||||
PageUtil.setPageSort(userGetParam, userIdsPage, OrderItem.asc("id"))
|
PageUtil.setPageSort(userGetParam, userIdsPage, OrderItem.asc("id"))
|
||||||
|
|
||||||
val userIdsIPage =
|
val userIdsIPage =
|
||||||
baseMapper.selectPage(userIdsPage, userGetParam?.searchValue, userGetParam?.searchRegex ?: false)
|
baseMapper.selectPage(userIdsPage,userGetParam?.searchType ?: "ALL", userGetParam?.searchValue, userGetParam?.searchRegex ?: false)
|
||||||
val userPage = Page<User>(userIdsIPage.current, userIdsIPage.size, userIdsIPage.total)
|
val userPage = Page<User>(userIdsIPage.current, userIdsIPage.size, userIdsIPage.total)
|
||||||
if (userIdsIPage.total > 0) {
|
if (userIdsIPage.total > 0) {
|
||||||
userPage.setRecords(baseMapper.selectListWithRoleInfoByIds(userIdsIPage.records))
|
userPage.setRecords(baseMapper.selectListWithRoleInfoByIds(userIdsIPage.records))
|
||||||
|
|||||||
@@ -59,13 +59,67 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectPage" resultType="long">
|
<select id="selectPage" resultType="long">
|
||||||
select id
|
select t_user.id
|
||||||
from t_user
|
from t_user
|
||||||
|
left join (select * from t_user_info where deleted = 0) as tui on t_user.id = tui.user_id
|
||||||
<where>
|
<where>
|
||||||
deleted = 0
|
t_user.deleted = 0
|
||||||
<if test="searchValue != null">
|
<if test="searchValue != null">
|
||||||
|
<choose>
|
||||||
</if>
|
<when test="searchType == 'ID'">
|
||||||
|
<choose>
|
||||||
|
<when test="searchRegex == true">
|
||||||
|
and t_user.id regexp #{searchValue}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and t_user.id like concat('%' ,#{searchValue}, '%')
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</when>
|
||||||
|
<when test="searchType == 'USERNAME'">
|
||||||
|
<choose>
|
||||||
|
<when test="searchRegex == true">
|
||||||
|
and t_user.username regexp #{searchValue}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and t_user.username like concat('%' ,#{searchValue}, '%')
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</when>
|
||||||
|
<when test="searchType == 'NICKNAME'">
|
||||||
|
<choose>
|
||||||
|
<when test="searchRegex == true">
|
||||||
|
and tui.nickname regexp #{searchValue}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and tui.nickname like concat('%' ,#{searchValue}, '%')
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</when>
|
||||||
|
<when test="searchType == 'EMAIL'">
|
||||||
|
<choose>
|
||||||
|
<when test="searchRegex == true">
|
||||||
|
and tui.email regexp #{searchValue}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and tui.email like concat('%' ,#{searchValue}, '%')
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
<choose>
|
||||||
|
<when test="searchRegex == true">
|
||||||
|
and ( t_user.username regexp #{searchValue} or tui.nickname regexp #{searchValue} or
|
||||||
|
tui.email regexp #{searchValue})
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and (t_user.username like concat('%' ,#{searchValue}, '%') or tui.nickname like
|
||||||
|
concat('%' ,#{searchValue}, '%') or tui.email like concat('%' ,#{searchValue}, '%'))
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user