mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-25 22:42:45 +08:00
完成后台的线上课-学员api接口
This commit is contained in:
parent
a6b5eae000
commit
4514adb9d0
@ -24,6 +24,7 @@ public class BPermissionConstant {
|
||||
public final static String USER_DESTROY = "user-destroy";
|
||||
|
||||
public final static String COURSE = "course";
|
||||
public final static String COURSE_USER = "course-user";
|
||||
|
||||
public final static String RESOURCE_DESTROY = "resource-destroy";
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import xyz.playedu.api.request.backend.CourseUserDestroyRequest;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.CourseUserPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/24 16:08
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/course/{courseId}/user")
|
||||
public class CourseUserController {
|
||||
|
||||
@Autowired
|
||||
private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index(@PathVariable(name = "courseId") Integer courseId, @RequestParam HashMap<String, Object> params) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||
String sortField = MapUtils.getString(params, "sort_field");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||
String name = MapUtils.getString(params, "name");
|
||||
String email = MapUtils.getString(params, "email");
|
||||
String idCard = MapUtils.getString(params, "id_card");
|
||||
|
||||
CourseUserPaginateFilter filter = new CourseUserPaginateFilter();
|
||||
filter.setCourseId(courseId);
|
||||
filter.setName(name);
|
||||
filter.setEmail(email);
|
||||
filter.setIdCard(idCard);
|
||||
filter.setSortAlgo(sortAlgo);
|
||||
filter.setSortField(sortField);
|
||||
|
||||
PaginationResult<UserCourseRecord> result = userCourseRecordService.paginate(page, size, filter);
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("data", result.getData());
|
||||
data.put("total", result.getTotal());
|
||||
data.put("users", userService.chunks(result.getData().stream().map(UserCourseRecord::getUserId).toList()));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@PostMapping("/destroy")
|
||||
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @RequestBody @Validated CourseUserDestroyRequest req) {
|
||||
if (req.getIds().size() == 0) {
|
||||
return JsonResponse.error("请选择需要删除的数据");
|
||||
}
|
||||
userCourseRecordService.destroy(courseId, req.getIds());
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
}
|
@ -3,16 +3,21 @@ package xyz.playedu.api.mapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import xyz.playedu.api.types.paginate.CourseUserPaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_course_records】的数据库操作Mapper
|
||||
* @createDate 2023-03-20 16:41:04
|
||||
* @Entity xyz.playedu.api.domain.UserCourseRecord
|
||||
*/
|
||||
* @author tengteng
|
||||
* @description 针对表【user_course_records】的数据库操作Mapper
|
||||
* @createDate 2023-03-20 16:41:04
|
||||
* @Entity xyz.playedu.api.domain.UserCourseRecord
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserCourseRecordMapper extends BaseMapper<UserCourseRecord> {
|
||||
List<UserCourseRecord> paginate(CourseUserPaginateFilter filter);
|
||||
|
||||
long paginateTotal(CourseUserPaginateFilter filter);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/24 16:22
|
||||
*/
|
||||
@Data
|
||||
public class CourseUserDestroyRequest {
|
||||
@NotNull(message = "ids参数不存在")
|
||||
private List<Integer> ids;
|
||||
}
|
@ -2,6 +2,8 @@ package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.CourseUserPaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -17,4 +19,8 @@ public interface UserCourseRecordService extends IService<UserCourseRecord> {
|
||||
void storeOrUpdate(Integer userId, Integer courseId, Integer hourCount, Integer finishedCount);
|
||||
|
||||
List<UserCourseRecord> chunk(Integer userId, List<Integer> courseIds);
|
||||
|
||||
PaginationResult<UserCourseRecord> paginate(int page, int size, CourseUserPaginateFilter filter);
|
||||
|
||||
void destroy(Integer courseId, List<Integer> ids);
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ public interface UserService extends IService<User> {
|
||||
|
||||
List<User> chunks(List<Integer> ids, List<String> fields);
|
||||
|
||||
List<User> chunks(List<Integer> ids);
|
||||
|
||||
Long total();
|
||||
|
||||
Long todayCount();
|
||||
|
@ -5,6 +5,8 @@ import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
import xyz.playedu.api.mapper.UserCourseRecordMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.types.paginate.CourseUserPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -74,6 +76,24 @@ public class UserCourseRecordServiceImpl extends ServiceImpl<UserCourseRecordMap
|
||||
}
|
||||
return list(query().getWrapper().eq("user_id", userId).in("course_id", courseIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaginationResult<UserCourseRecord> paginate(int page, int size, CourseUserPaginateFilter filter) {
|
||||
Integer pageStart = (page - 1) * size;
|
||||
filter.setPageStart(pageStart);
|
||||
filter.setPageSize(size);
|
||||
|
||||
PaginationResult<UserCourseRecord> result = new PaginationResult<>();
|
||||
result.setTotal(getBaseMapper().paginateTotal(filter));
|
||||
result.setData(getBaseMapper().paginate(filter));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(Integer courseId, List<Integer> ids) {
|
||||
remove(query().getWrapper().in("id", ids).eq("course_id", courseId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,6 +166,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
return list(query().getWrapper().in("id", ids).select(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> chunks(List<Integer> ids) {
|
||||
if (ids == null || ids.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return list(query().getWrapper().in("id", ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long total() {
|
||||
return count();
|
||||
|
@ -0,0 +1,19 @@
|
||||
package xyz.playedu.api.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/24 16:10
|
||||
*/
|
||||
@Data
|
||||
public class CourseUserPaginateFilter {
|
||||
private Integer courseId;
|
||||
private String email;
|
||||
private String name;
|
||||
private String idCard;
|
||||
private String sortField;
|
||||
private String sortAlgo;
|
||||
private Integer pageStart;
|
||||
private Integer pageSize;
|
||||
}
|
@ -18,9 +18,86 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,user_id,course_id,
|
||||
hour_count,finished_count,progress,
|
||||
is_finished,finished_at,created_at,
|
||||
id,user_id,course_id,
|
||||
hour_count,finished_count,progress,
|
||||
is_finished,finished_at,created_at,
|
||||
updated_at
|
||||
</sql>
|
||||
<select id="paginateTotal" resultType="java.lang.Long">
|
||||
SELECT count(1)
|
||||
FROM `user_course_records`
|
||||
INNER JOIN `users` ON `users`.`id` = `user_course_records`.`user_id`
|
||||
<where>
|
||||
<if test="courseId != null">
|
||||
AND `user_course_records`.`course_id` = #{courseId}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
AND `users`.`name` LIKE concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="email != null and email != ''">
|
||||
AND `users`.`email` = #{email}
|
||||
</if>
|
||||
<if test="idCard != null and idCard != ''">
|
||||
AND `users`.`id_card` = #{idCard}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="paginate" resultType="xyz.playedu.api.domain.UserCourseRecord">
|
||||
SELECT `user_course_records`.*
|
||||
FROM `user_course_records`
|
||||
INNER JOIN `users` ON `users`.`id` = `user_course_records`.`user_id`
|
||||
<where>
|
||||
<if test="courseId != null">
|
||||
AND `user_course_records`.`course_id` = #{courseId}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
AND `users`.`name` LIKE concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="email != null and email != ''">
|
||||
AND `users`.`email` = #{email}
|
||||
</if>
|
||||
<if test="idCard != null and idCard != ''">
|
||||
AND `users`.`id_card` = #{idCard}
|
||||
</if>
|
||||
</where>
|
||||
<if test="sortAlgo == 'asc'">
|
||||
<choose>
|
||||
<when test="sortField == 'finished_count'">
|
||||
ORDER BY `user_course_records`.`finished_count` ASC
|
||||
</when>
|
||||
<when test="sortField == 'progress'">
|
||||
ORDER BY `user_course_records`.`progress` ASC
|
||||
</when>
|
||||
<when test="sortField == 'finished_at'">
|
||||
ORDER BY `user_course_records`.`finished_at` ASC
|
||||
</when>
|
||||
<when test="sortField == 'created_at'">
|
||||
ORDER BY `user_course_records`.`created_at` ASC
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY `user_course_records`.`id` ASC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="sortAlgo != 'asc'">
|
||||
<choose>
|
||||
<when test="sortField == 'finished_count'">
|
||||
ORDER BY `user_course_records`.`finished_count` DESC
|
||||
</when>
|
||||
<when test="sortField == 'progress'">
|
||||
ORDER BY `user_course_records`.`progress` DESC
|
||||
</when>
|
||||
<when test="sortField == 'finished_at'">
|
||||
ORDER BY `user_course_records`.`finished_at` DESC
|
||||
</when>
|
||||
<when test="sortField == 'created_at'">
|
||||
ORDER BY `user_course_records`.`created_at` DESC
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY `user_course_records`.`id` DESC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
LIMIT #{pageStart}, #{pageSize};
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user