mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 20:42:42 +08:00
fixed: 学员的多部门查询
This commit is contained in:
parent
08cad48fa4
commit
669e4fe47b
@ -16,6 +16,7 @@
|
|||||||
package xyz.playedu.api.controller.backend;
|
package xyz.playedu.api.controller.backend;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -49,6 +50,7 @@ import java.util.stream.Collectors;
|
|||||||
* @create 2023/3/24 16:08
|
* @create 2023/3/24 16:08
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@Slf4j
|
||||||
@RequestMapping("/backend/v1/course/{courseId}/user")
|
@RequestMapping("/backend/v1/course/{courseId}/user")
|
||||||
public class CourseUserController {
|
public class CourseUserController {
|
||||||
|
|
||||||
@ -86,8 +88,7 @@ public class CourseUserController {
|
|||||||
// 所属部门
|
// 所属部门
|
||||||
List<Integer> depIds = courseService.getDepIdsByCourseId(courseId);
|
List<Integer> depIds = courseService.getDepIdsByCourseId(courseId);
|
||||||
if (depIds != null && depIds.size() > 0) {
|
if (depIds != null && depIds.size() > 0) {
|
||||||
filter.setDepIds(
|
filter.setDepIds(depIds);
|
||||||
depIds.stream().map(String::valueOf).collect(Collectors.joining(",", "", "")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PaginationResult<User> result = userService.paginate(page, size, filter);
|
PaginationResult<User> result = userService.paginate(page, size, filter);
|
||||||
|
@ -188,7 +188,12 @@ public class DepartmentController {
|
|||||||
String name = MapUtils.getString(params, "name");
|
String name = MapUtils.getString(params, "name");
|
||||||
String email = MapUtils.getString(params, "email");
|
String email = MapUtils.getString(params, "email");
|
||||||
String idCard = MapUtils.getString(params, "id_card");
|
String idCard = MapUtils.getString(params, "id_card");
|
||||||
String depIds = String.valueOf(id);
|
List<Integer> depIds =
|
||||||
|
new ArrayList<>() {
|
||||||
|
{
|
||||||
|
add(id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
String courseIdsStr = MapUtils.getString(params, "course_ids");
|
String courseIdsStr = MapUtils.getString(params, "course_ids");
|
||||||
String showMode = MapUtils.getString(params, "show_mode");
|
String showMode = MapUtils.getString(params, "show_mode");
|
||||||
|
@ -99,8 +99,17 @@ public class UserController {
|
|||||||
Integer isVerify = MapUtils.getInteger(params, "is_verify");
|
Integer isVerify = MapUtils.getInteger(params, "is_verify");
|
||||||
Integer isSetPassword = MapUtils.getInteger(params, "is_set_password");
|
Integer isSetPassword = MapUtils.getInteger(params, "is_set_password");
|
||||||
String createdAt = MapUtils.getString(params, "created_at");
|
String createdAt = MapUtils.getString(params, "created_at");
|
||||||
String depIds = MapUtils.getString(params, "dep_ids");
|
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
||||||
|
List<Integer> depIds = null;
|
||||||
|
if (depIdsStr != null && depIdsStr.trim().length() > 0) {
|
||||||
|
if ("0".equals(depIdsStr)) {
|
||||||
|
depIds = new ArrayList<>();
|
||||||
|
} else {
|
||||||
|
depIds = Arrays.stream(depIdsStr.split(",")).map(Integer::valueOf).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> finalDepIds = depIds;
|
||||||
UserPaginateFilter filter =
|
UserPaginateFilter filter =
|
||||||
new UserPaginateFilter() {
|
new UserPaginateFilter() {
|
||||||
{
|
{
|
||||||
@ -111,7 +120,7 @@ public class UserController {
|
|||||||
setIsLock(isLock);
|
setIsLock(isLock);
|
||||||
setIsVerify(isVerify);
|
setIsVerify(isVerify);
|
||||||
setIsSetPassword(isSetPassword);
|
setIsSetPassword(isSetPassword);
|
||||||
setDepIds(depIds);
|
setDepIds(finalDepIds);
|
||||||
setSortAlgo(sortAlgo);
|
setSortAlgo(sortAlgo);
|
||||||
setSortField(sortField);
|
setSortField(sortField);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ package xyz.playedu.api.types.paginate;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 杭州白书科技有限公司
|
* @Author 杭州白书科技有限公司
|
||||||
*
|
*
|
||||||
@ -36,7 +38,7 @@ public class UserPaginateFilter {
|
|||||||
// 创建时间范围过滤
|
// 创建时间范围过滤
|
||||||
private String[] createdAt;
|
private String[] createdAt;
|
||||||
|
|
||||||
private String depIds;
|
private List<Integer> depIds;
|
||||||
|
|
||||||
// 排序控制
|
// 排序控制
|
||||||
private String sortField;
|
private String sortField;
|
||||||
|
@ -36,24 +36,23 @@
|
|||||||
<select id="paginateCount" resultType="java.lang.Long">
|
<select id="paginateCount" resultType="java.lang.Long">
|
||||||
SELECT count(1)
|
SELECT count(1)
|
||||||
FROM `users`
|
FROM `users`
|
||||||
<if test="depIds != null and depIds != ''">
|
|
||||||
<choose>
|
|
||||||
<when test="depIds.indexOf('0') == 0">
|
|
||||||
LEFT JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
|
||||||
</when>
|
|
||||||
<otherwise>
|
|
||||||
INNER JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
|
||||||
</otherwise>
|
|
||||||
</choose>
|
|
||||||
</if>
|
|
||||||
<where>
|
<where>
|
||||||
<if test="depIds != null and depIds != ''">
|
<if test="depIds != null">
|
||||||
<choose>
|
<choose>
|
||||||
<when test="depIds.indexOf('0') == 0">
|
<when test="depIds.size == 0">
|
||||||
AND `user_department`.`user_id` IS NULL
|
AND `users`.`id` IN (
|
||||||
|
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||||
|
`users`.`id`
|
||||||
|
WHERE `user_department`.`user_id` IS NULL
|
||||||
|
)
|
||||||
</when>
|
</when>
|
||||||
<otherwise>
|
<otherwise>
|
||||||
AND `user_department`.`dep_id` IN (#{depIds})
|
AND `users`.`id` IN (
|
||||||
|
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||||
|
`users`.`id`
|
||||||
|
WHERE `user_department`.`dep_id` IN (<foreach collection="depIds" item="depId" separator=",">
|
||||||
|
#{depId}</foreach>)
|
||||||
|
)
|
||||||
</otherwise>
|
</otherwise>
|
||||||
</choose>
|
</choose>
|
||||||
</if>
|
</if>
|
||||||
@ -78,7 +77,7 @@
|
|||||||
<if test="isSetPassword != null">
|
<if test="isSetPassword != null">
|
||||||
AND `users`.`is_set_password` = #{isSetPassword}
|
AND `users`.`is_set_password` = #{isSetPassword}
|
||||||
</if>
|
</if>
|
||||||
<if test="createdAt != null">
|
<if test="createdAt != null and createdAt.size == 2">
|
||||||
AND `users`.`created_at` BETWEEN
|
AND `users`.`created_at` BETWEEN
|
||||||
<foreach collection="createdAt" item="createdAtItem" separator=" AND ">#{createdAtItem}</foreach>
|
<foreach collection="createdAt" item="createdAtItem" separator=" AND ">#{createdAtItem}</foreach>
|
||||||
</if>
|
</if>
|
||||||
@ -88,24 +87,23 @@
|
|||||||
<select id="paginate" resultType="xyz.playedu.api.domain.User">
|
<select id="paginate" resultType="xyz.playedu.api.domain.User">
|
||||||
SELECT `users`.*
|
SELECT `users`.*
|
||||||
FROM `users`
|
FROM `users`
|
||||||
<if test="depIds != null and depIds != ''">
|
|
||||||
<choose>
|
|
||||||
<when test="depIds.indexOf('0') == 0">
|
|
||||||
LEFT JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
|
||||||
</when>
|
|
||||||
<otherwise>
|
|
||||||
INNER JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
|
||||||
</otherwise>
|
|
||||||
</choose>
|
|
||||||
</if>
|
|
||||||
<where>
|
<where>
|
||||||
<if test="depIds != null and depIds != ''">
|
<if test="depIds != null">
|
||||||
<choose>
|
<choose>
|
||||||
<when test="depIds.indexOf('0') == 0">
|
<when test="depIds.size == 0">
|
||||||
AND `user_department`.`user_id` IS NULL
|
AND `users`.`id` IN (
|
||||||
|
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||||
|
`users`.`id`
|
||||||
|
WHERE `user_department`.`user_id` IS NULL
|
||||||
|
)
|
||||||
</when>
|
</when>
|
||||||
<otherwise>
|
<otherwise>
|
||||||
AND `user_department`.`dep_id` IN (#{depIds})
|
AND `users`.`id` IN (
|
||||||
|
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||||
|
`users`.`id`
|
||||||
|
WHERE `user_department`.`dep_id` IN (<foreach collection="depIds" item="depId" separator=",">
|
||||||
|
#{depId}</foreach>)
|
||||||
|
)
|
||||||
</otherwise>
|
</otherwise>
|
||||||
</choose>
|
</choose>
|
||||||
</if>
|
</if>
|
||||||
@ -130,7 +128,7 @@
|
|||||||
<if test="isSetPassword != null">
|
<if test="isSetPassword != null">
|
||||||
AND `users`.`is_set_password` = #{isSetPassword}
|
AND `users`.`is_set_password` = #{isSetPassword}
|
||||||
</if>
|
</if>
|
||||||
<if test="createdAt != null">
|
<if test="createdAt != null and createdAt.size == 2">
|
||||||
AND `users`.`created_at` BETWEEN
|
AND `users`.`created_at` BETWEEN
|
||||||
<foreach collection="createdAt" item="createdAtItem" separator=" AND ">#{createdAtItem}</foreach>
|
<foreach collection="createdAt" item="createdAtItem" separator=" AND ">#{createdAtItem}</foreach>
|
||||||
</if>
|
</if>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user