mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-25 10:42:59 +08:00
fix: 【FCJDFDXTXS-145】更换资源学习情况学习人员分页查询方法
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 资源学习情况筛选状态枚举
|
||||
* 需要注意的是,这个枚举不对应数据库表字段
|
||||
*/
|
||||
@Getter
|
||||
public enum StudyCourseQueryStatusEnum {
|
||||
|
||||
NOT_START(1, "未开始"),
|
||||
|
||||
FINISH(2, "已完成"),
|
||||
|
||||
STUDYING(3, "学习中"),
|
||||
|
||||
NOT_FINISH(4, "未完成"),
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
private final String label;
|
||||
|
||||
StudyCourseQueryStatusEnum(int code, String label) {
|
||||
this.code = code;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static StudyCourseQueryStatusEnum getByCode(int code) {
|
||||
return Arrays.stream(values()).filter(e -> code == e.code).findFirst().orElse(FINISH);
|
||||
}
|
||||
}
|
||||
@@ -1226,7 +1226,16 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
return error("无课程信息");
|
||||
}
|
||||
try {
|
||||
PageList<StudyCourseItem> rs = studyService.findItemPage(pager.getPageIndex(), pager.getPageSize(), null, contentId, courseId, name, status,aid);
|
||||
// PageList<StudyCourseItem> rs = studyService.findItemPage(pager.getPageIndex(), pager.getPageSize(), null, contentId, courseId, name, status,aid);
|
||||
// 换方法
|
||||
List<String> userIdList;
|
||||
if (StringUtils.isNotBlank(aid)) {
|
||||
String[] ids = aid.split(",");
|
||||
userIdList = Arrays.asList(ids);
|
||||
} else {
|
||||
userIdList = new ArrayList<>();
|
||||
}
|
||||
PageList<StudyCourseItem> rs = studyService.itemPage(pager.getPageIndex(), pager.getPageSize(), contentId, courseId, status, userIdList);
|
||||
return success(rs);
|
||||
}catch(Exception e) {
|
||||
log.error("【资源学习情况分页查询】错误:{}", e.getMessage());
|
||||
@@ -1258,7 +1267,16 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
return success(new PageList<>());
|
||||
}
|
||||
// 分页查询资源学习信息(只查询有考试信息的部分)
|
||||
PageList<StudyCourseItem> rs = studyService.findItemPage(pager.getPageIndex(), pager.getPageSize(), null, contentId, courseId, name, status,aid);
|
||||
// PageList<StudyCourseItem> rs = studyService.findItemPage(pager.getPageIndex(), pager.getPageSize(), null, contentId, courseId, name, status,aid);
|
||||
// 换方法
|
||||
List<String> userIdList;
|
||||
if (StringUtils.isNotBlank(aid)) {
|
||||
String[] ids = aid.split(",");
|
||||
userIdList = Arrays.asList(ids);
|
||||
} else {
|
||||
userIdList = new ArrayList<>();
|
||||
}
|
||||
PageList<StudyCourseItem> rs = studyService.itemPage(pager.getPageIndex(), pager.getPageSize(), contentId, courseId, status, userIdList);
|
||||
// 拼接考试信息
|
||||
List<StudyCourseItem> studyCourseItems = rs.getList();
|
||||
if (studyCourseItems != null && !studyCourseItems.isEmpty() && !studyExams.isEmpty()) {
|
||||
@@ -1301,8 +1319,17 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
return success(new PageList<>());
|
||||
}
|
||||
// 分页查询资源学习信息(只查询有评估信息的部分)
|
||||
PageList<StudyCourseItem> rs = studyService.findItemPage(pager.getPageIndex(), pager.getPageSize(), null, contentId, courseId, name, status,aid);
|
||||
// 拼接评估信息
|
||||
// PageList<StudyCourseItem> rs = studyService.findItemPage(pager.getPageIndex(), pager.getPageSize(), null, contentId, courseId, name, status,aid);
|
||||
// 换方法
|
||||
List<String> userIdList;
|
||||
if (StringUtils.isNotBlank(aid)) {
|
||||
String[] ids = aid.split(",");
|
||||
userIdList = Arrays.asList(ids);
|
||||
} else {
|
||||
userIdList = new ArrayList<>();
|
||||
}
|
||||
PageList<StudyCourseItem> rs = studyService.itemPage(pager.getPageIndex(), pager.getPageSize(), contentId, courseId, status, userIdList);
|
||||
// 拼接评估信息
|
||||
List<StudyCourseItem> studyCourseItems = rs.getList();
|
||||
if (studyCourseItems != null && !studyCourseItems.isEmpty() && !studyAssesses.isEmpty()) {
|
||||
for (StudyCourseItem studyCourseItem : studyCourseItems) {
|
||||
|
||||
@@ -1,10 +1,161 @@
|
||||
package com.xboe.school.study.dao;
|
||||
|
||||
import com.xboe.enums.StudyCourseQueryStatusEnum;
|
||||
import com.xboe.module.course.vo.CoursePageVo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.school.study.entity.StudyCourseItem;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Repository
|
||||
public class StudyCourseItemDao extends BaseDao<StudyCourseItem> {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* 查询学习记录
|
||||
* @param courseId 课程id
|
||||
* @param contentId 内容id
|
||||
* @param userIds 用户id
|
||||
* @param status 状态
|
||||
* @param pageQuery 是否分页
|
||||
* @param pageIndex 页码
|
||||
* @param pageSize 每页数量
|
||||
* @return
|
||||
*/
|
||||
public List<StudyCourseItem> queryList(String courseId, String contentId, List<String> userIds, Integer status,
|
||||
boolean pageQuery, int pageIndex, int pageSize) {
|
||||
StringBuilder builder = new StringBuilder("SELECT ");
|
||||
builder.append("bsc.id AS study_id,");
|
||||
builder.append("bsc.course_id,");
|
||||
builder.append("bsc.aid,");
|
||||
builder.append("bsc.aname,");
|
||||
builder.append("bsci.id AS id,");
|
||||
builder.append("bsci.content_id AS content_id,");
|
||||
builder.append("MAX(bsci.finish_time) AS finish_time,");
|
||||
builder.append("COALESCE(MAX(bsci.progress), 0) AS progress,");
|
||||
builder.append("COALESCE(bsci.status, 1) AS status,");
|
||||
builder.append("MAX(bsci.score) AS score");
|
||||
// from及后面的语句
|
||||
appendFrom(builder, userIds, status);
|
||||
Query query = entityManager.createNativeQuery(builder.toString());
|
||||
setQueryParam(query, courseId, contentId, userIds, status, pageQuery, pageIndex, pageSize);
|
||||
|
||||
List<Object[]> resultList = query.getResultList();
|
||||
List<StudyCourseItem> itemList = new ArrayList<>();
|
||||
for (Object[] row : resultList) {
|
||||
StudyCourseItem item = new StudyCourseItem();
|
||||
// 防止BigInteger为null的情况
|
||||
BigInteger studyId = (BigInteger) row[0];
|
||||
if (studyId != null) {
|
||||
item.setStudyId(studyId.toString());
|
||||
}
|
||||
BigInteger thisCourseId = (BigInteger) row[1];
|
||||
if (thisCourseId != null) {
|
||||
item.setCourseId(thisCourseId.toString());
|
||||
}
|
||||
BigInteger aid = (BigInteger) row[2];
|
||||
if (aid != null) {
|
||||
item.setAid(aid.toString());
|
||||
}
|
||||
item.setAname((String) row[3]);
|
||||
BigInteger id = (BigInteger) row[4];
|
||||
if (id != null) {
|
||||
item.setId(id.toString());
|
||||
}
|
||||
BigInteger thisContentId = (BigInteger) row[5];
|
||||
if (thisContentId != null) {
|
||||
item.setContentId(thisContentId.toString());
|
||||
}
|
||||
Timestamp finishTimestamp = (Timestamp) row[6];
|
||||
if (finishTimestamp != null) {
|
||||
item.setFinishTime(finishTimestamp.toLocalDateTime());
|
||||
}
|
||||
item.setProgress((Integer) row[7]);
|
||||
item.setStatus((Integer) row[8]);
|
||||
Number score = (Number) row[9];
|
||||
if (score != null) {
|
||||
item.setScore(score.floatValue());
|
||||
}
|
||||
|
||||
itemList.add(item);
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public long countList(String courseId, String contentId, List<String> userIds, Integer status) {
|
||||
StringBuilder builder = new StringBuilder("SELECT COUNT(*)");
|
||||
// from及后面的语句
|
||||
appendFrom(builder, userIds, status);
|
||||
Query query = entityManager.createNativeQuery(builder.toString());
|
||||
setQueryParam(query, courseId, contentId, userIds, status, false, 0, 0);
|
||||
Number count = (Number) query.getSingleResult();
|
||||
return count.longValue();
|
||||
}
|
||||
|
||||
private void appendFrom(StringBuilder builder, List<String> userIds, Integer status) {
|
||||
builder.append(" FROM boe_study_course bsc LEFT JOIN boe_study_course_item bsci ON bsc.id = bsci.study_id AND bsci.content_id = :contentId");
|
||||
// where条件
|
||||
// courseId
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append("WHERE bsc.course_id = :courseId");
|
||||
// 用户
|
||||
if (userIds != null && !userIds.isEmpty()) {
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append("AND bsc.aid IN (:userIds)");
|
||||
}
|
||||
// 状态
|
||||
if (status != null) {
|
||||
builder.append(System.lineSeparator());
|
||||
StudyCourseQueryStatusEnum queryStatusEnum = StudyCourseQueryStatusEnum.getByCode(status);
|
||||
switch (queryStatusEnum) {
|
||||
case NOT_START:
|
||||
builder.append("AND COALESCE(bsci.status, 1) = 1");
|
||||
break;
|
||||
case STUDYING:
|
||||
builder.append("AND bsci.status = 2");
|
||||
break;
|
||||
case NOT_FINISH:
|
||||
builder.append("AND bsci.status != 9");
|
||||
break;
|
||||
case FINISH:
|
||||
default:
|
||||
builder.append("AND bsci.status = 9");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// group by
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append("GROUP BY bsc.id");
|
||||
// 排序
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append("ORDER BY bsc.id DESC");
|
||||
}
|
||||
|
||||
private void setQueryParam(Query query, String courseId, String contentId, List<String> userIds, Integer status,
|
||||
boolean pageQuery, int pageIndex, int pageSize) {
|
||||
query.setParameter("courseId", courseId);
|
||||
query.setParameter("contentId", contentId);
|
||||
if (userIds != null && !userIds.isEmpty()) {
|
||||
query.setParameter("userIds", userIds);
|
||||
}
|
||||
if (status != null) {
|
||||
query.setParameter("status", status);
|
||||
}
|
||||
if (pageQuery) {
|
||||
// 设置OFFSET和LIMIT
|
||||
query.setFirstResult((pageIndex - 1) * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,18 @@ public interface IStudyService {
|
||||
*/
|
||||
PageList<StudyCourseItem> findItemPage(int pageIndex, int pageSize, List<String> ids, String contentId, String courseId, String name, Integer status,String aid);
|
||||
|
||||
/**
|
||||
* 资源学习情况学习人员的分页查询
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @param contentId
|
||||
* @param courseId
|
||||
* @param status
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
PageList<StudyCourseItem> itemPage(int pageIndex, int pageSize, String contentId, String courseId, Integer status, List<String> userIdList);
|
||||
|
||||
/**
|
||||
* 为courseContents列表设置展示名称(章名+节名 或 课程名+节名)
|
||||
* 25.12.15新增
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseSection;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseSectionService;
|
||||
import com.xboe.module.course.vo.CoursePageVo;
|
||||
import com.xboe.school.study.dao.StudyCourseDao;
|
||||
import com.xboe.school.study.dao.StudyCourseItemDao;
|
||||
import com.xboe.school.study.dao.StudyTimeDao;
|
||||
@@ -370,6 +371,28 @@ public class StudyServiceImpl implements IStudyService{
|
||||
return pageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageList<StudyCourseItem> itemPage(int pageIndex, int pageSize, String contentId, String courseId, Integer status, List<String> userIdList) {
|
||||
long count = scItemDao.countList(contentId, courseId, userIdList, status);
|
||||
List<StudyCourseItem> list = scItemDao.queryList(contentId, courseId, userIdList, status, true, pageIndex, pageSize);
|
||||
List<String> contentIds = list.stream().map(StudyCourseItem::getContentId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
if (!contentIds.isEmpty()) {
|
||||
List<CourseContent> contentList = courseContentService.getByIds(contentIds);
|
||||
if (contentList != null) {
|
||||
setContentDisplayName(contentList);
|
||||
// 根据contentId将展示名称映射到item
|
||||
for (StudyCourseItem studyCourseItem : list) {
|
||||
studyCourseItem.setDisplayName(contentList.stream().filter(content -> content.getId().equals(studyCourseItem.getContentId())).findFirst().map(CourseContent::getDisplayName).orElse(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
PageList<StudyCourseItem> result = new PageList<>();
|
||||
result.setCount((int) count);
|
||||
result.setPageSize(pageSize);
|
||||
result.setList(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 CourseContent 列表设置展示名称(章名+节名 或 课程名+节名)
|
||||
* 基于 25.12.15 的展示逻辑:优先使用 章名+节名,章不存在则退化为 课程名+节名
|
||||
|
||||
Reference in New Issue
Block a user