BaseClassCourseServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package com.xjrsoft.module.base.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.github.yulichang.base.MPJBaseServiceImpl;
  5. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  6. import com.xjrsoft.common.enums.ArchivesStatusEnum;
  7. import com.xjrsoft.common.exception.MyException;
  8. import com.xjrsoft.common.utils.VoToColumnUtil;
  9. import com.xjrsoft.module.base.dto.BaseClassCoursePageDto;
  10. import com.xjrsoft.module.base.dto.ClassCourseReuseDto;
  11. import com.xjrsoft.module.base.entity.BaseClassCourse;
  12. import com.xjrsoft.module.base.entity.BaseCourseSubject;
  13. import com.xjrsoft.module.base.entity.ClassCourseTextbook;
  14. import com.xjrsoft.module.base.entity.CourseBookInfo;
  15. import com.xjrsoft.module.base.mapper.BaseClassCourseMapper;
  16. import com.xjrsoft.module.base.service.IBaseClassCourseService;
  17. import com.xjrsoft.module.base.vo.BaseClassCoursePageVo;
  18. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  19. import com.xjrsoft.module.student.mapper.BaseStudentSchoolRollMapper;
  20. import com.xjrsoft.module.system.entity.DictionaryDetail;
  21. import com.xjrsoft.module.textbook.dto.TextbookSubscriptionExportQueryListDto;
  22. import com.xjrsoft.module.textbook.entity.Textbook;
  23. import com.xjrsoft.module.textbook.entity.TextbookStudentClaim;
  24. import com.xjrsoft.module.textbook.entity.TextbookSubscription;
  25. import com.xjrsoft.module.textbook.entity.WfTextbookSubscriptionItem;
  26. import com.xjrsoft.module.textbook.mapper.TextbookStudentClaimMapper;
  27. import com.xjrsoft.module.textbook.vo.TextbookSubscriptionExportQueryListVo;
  28. import lombok.AllArgsConstructor;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import java.util.ArrayList;
  32. import java.util.Arrays;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. import java.util.Map;
  36. import java.util.TreeMap;
  37. import java.util.stream.Collectors;
  38. /**
  39. * @title: 班级课程
  40. * @Author brealinxx
  41. * @Date: 2024-06-04
  42. * @Version 1.0
  43. */
  44. @Service
  45. @AllArgsConstructor
  46. public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCourseMapper, BaseClassCourse> implements IBaseClassCourseService {
  47. private final BaseClassCourseMapper baseClassCourseMapper;
  48. private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;
  49. private final TextbookStudentClaimMapper textbookStudentClaimMapper;
  50. @Override
  51. public Page<BaseClassCoursePageVo> getPage(Page<BaseClassCoursePageVo> page, BaseClassCoursePageDto dto) {
  52. return baseClassCourseMapper.getPage(page, dto);
  53. }
  54. @Override
  55. public List<CourseBookInfo> getAllCourseBook(Long[] classIds, Long subjectGroupId, Long semester){
  56. return baseClassCourseMapper.getAllCourseBook(classIds, subjectGroupId, semester);
  57. }
  58. @Override
  59. public List<CourseBookInfo> getSelectedCourseBook(Long[] subjectGroupId, Long semester){
  60. return baseClassCourseMapper.getSelectedCourseBook(subjectGroupId, semester);
  61. }
  62. @Override
  63. @Transactional
  64. public Boolean updateAddCourseBook(ClassCourseTextbook dto){
  65. if (dto.getClassIds() == null || dto.getClassIds().length == 0 || dto.getBaseSemesterId() == null || dto.getBaseSemesterId() == 0) {
  66. return false;
  67. }
  68. boolean isSuccess = false;
  69. List<Long> classIdList = Arrays.asList(dto.getClassIds());
  70. //删除班级的这学期的所有课程教材
  71. LambdaQueryWrapper<BaseClassCourse> baseClassCourseLambdaQueryWrapper = new LambdaQueryWrapper<>();
  72. baseClassCourseLambdaQueryWrapper
  73. .in(BaseClassCourse::getClassId, classIdList)
  74. .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
  75. ;
  76. isSuccess = this.remove(baseClassCourseLambdaQueryWrapper);
  77. // 获取所有班级的所有学生
  78. LambdaQueryWrapper<BaseStudentSchoolRoll> baseStudentSchoolRollLambdaQueryWrapper = new LambdaQueryWrapper<>();
  79. baseStudentSchoolRollLambdaQueryWrapper
  80. .in(BaseStudentSchoolRoll::getClassId, classIdList)
  81. .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
  82. ;
  83. List<BaseStudentSchoolRoll> baseStudentSchoolRolls = baseStudentSchoolRollMapper.selectList(baseStudentSchoolRollLambdaQueryWrapper);
  84. Map<Long, List<Long>> userIdsMap = baseStudentSchoolRolls.stream()
  85. .filter(student -> student.getClassId() != null && student.getUserId() != null)
  86. .collect(Collectors.groupingBy(
  87. BaseStudentSchoolRoll::getClassId, // 根据classId分组
  88. Collectors.mapping(BaseStudentSchoolRoll::getUserId, // 提取userId
  89. Collectors.toList()) // 收集到List<Long>
  90. )
  91. );
  92. List<BaseClassCourse> baseClassCourseList = new ArrayList<>();
  93. List<TextbookStudentClaim> textbookStudentClaimList = new ArrayList<>();
  94. for (Long classId : dto.getClassIds()) {
  95. for (String id : dto.getIds()) {
  96. String[] idArr = id.split("_");
  97. if (idArr[0].equals("") || idArr[1].equals("")) {
  98. continue;
  99. }
  100. Long courseId = Long.parseLong(idArr[0]);
  101. Long textbookId = Long.parseLong(idArr[1]);
  102. baseClassCourseList.add(new BaseClassCourse() {{
  103. setBaseSemesterId(dto.getBaseSemesterId());
  104. setClassId(classId);
  105. setCourseId(courseId);
  106. setTextbookId(textbookId);
  107. }});
  108. // 添加学生领取教材数据
  109. List<Long> userIds = userIdsMap.get(classId);
  110. for (Long userId : userIds) {
  111. textbookStudentClaimList.add(new TextbookStudentClaim() {{
  112. setStudentUserId(userId);
  113. setBaseSemesterId(dto.getBaseSemesterId());
  114. setClassId(classId);
  115. setTextbookId(textbookId);
  116. }});
  117. }
  118. }
  119. }
  120. for (TextbookStudentClaim textbookStudentClaim : textbookStudentClaimList) {
  121. textbookStudentClaimMapper.insert(textbookStudentClaim);
  122. }
  123. return this.saveBatch(baseClassCourseList);
  124. }
  125. @Override
  126. public void updateRemoveCourseBook(Long classId, Long courseId, Long textbookId){
  127. baseClassCourseMapper.updateRemoveClassCourseTextbooks(classId, courseId, textbookId);
  128. }
  129. @Override
  130. public void markExistingRecordsAsDeleted(Long newClassId, Long sourceClassId){
  131. baseClassCourseMapper.markExistingRecordsAsDeleted(newClassId, sourceClassId);
  132. }
  133. @Override
  134. @Transactional
  135. public Boolean duplicateCourseBook(ClassCourseReuseDto dto){
  136. LambdaQueryWrapper<BaseClassCourse> baseClassCourseLambdaQueryWrapper = new LambdaQueryWrapper<>();
  137. baseClassCourseLambdaQueryWrapper
  138. .eq(dto.getOldClassId() != null && dto.getOldClassId() > 0, BaseClassCourse::getClassId, dto.getOldClassId())
  139. .eq(dto.getOldBaseSemesterId() != null && dto.getOldBaseSemesterId() > 0, BaseClassCourse::getBaseSemesterId, dto.getOldBaseSemesterId())
  140. ;
  141. List<BaseClassCourse> baseClassCourseList = this.list(baseClassCourseLambdaQueryWrapper);
  142. if(baseClassCourseList == null || baseClassCourseList.isEmpty()){
  143. throw new MyException("该学期的该班级没有可以复用的课程!");
  144. }
  145. boolean isSuccess = false;
  146. //删除班级的所有课程教材
  147. LambdaQueryWrapper<BaseClassCourse> removeLambdaQueryWrapper = new LambdaQueryWrapper<>();
  148. removeLambdaQueryWrapper
  149. .in(BaseClassCourse::getClassId, dto.getNewClassIds())
  150. .eq(BaseClassCourse::getBaseSemesterId, dto.getNewBaseSemesterId())
  151. ;
  152. isSuccess = this.remove(removeLambdaQueryWrapper);
  153. List<BaseClassCourse> newBaseClassCourseList = new ArrayList<>();
  154. for (Long newClassId : dto.getNewClassIds()){
  155. for (BaseClassCourse baseClassCourse : baseClassCourseList){
  156. Long courseId = baseClassCourse.getCourseId();
  157. Long textbookId = baseClassCourse.getTextbookId();
  158. newBaseClassCourseList.add(new BaseClassCourse(){{
  159. setBaseSemesterId(dto.getNewBaseSemesterId());
  160. setClassId(newClassId);
  161. setCourseId(courseId);
  162. setTextbookId(textbookId);
  163. }});
  164. }
  165. }
  166. isSuccess = this.saveBatch(newBaseClassCourseList);
  167. return isSuccess;
  168. //baseClassCourseMapper.insertClassCourseTextbookCombinations(newClassId, sourceClassId, semester);
  169. }
  170. @Override
  171. public Map<String, Map<String, Object>> getSemesterTree() {
  172. List<Map<String, Object>> semesterData = baseClassCourseMapper.getAllSemesterNames();
  173. Map<String, Map<String, Object>> tree = new TreeMap<>();
  174. for (Map<String, Object> data : semesterData) {
  175. String name = (String) data.get("name");
  176. String[] parts = name.split("年");
  177. String year = parts[0]; // 年份
  178. String semesterType = parts[1].substring(0, parts[1].length() - 1); // 学期类型(春期/秋期)
  179. Long id = Long.parseLong(data.get("id").toString());
  180. if (!tree.containsKey(year + "年")) {
  181. tree.put(year + "年", new HashMap<>());
  182. }
  183. Map<String, Object> yearMap = tree.get(year + "年");
  184. if (semesterType.equals("春")) {
  185. yearMap.put("springName", name);
  186. yearMap.put("springId", id);
  187. } else if (semesterType.equals("秋")) {
  188. yearMap.put("autumnName", name);
  189. yearMap.put("autumnId", id);
  190. }
  191. }
  192. return tree;
  193. }
  194. @Override
  195. public Long GetClassIdByName(String name){
  196. return baseClassCourseMapper.getClassIdByName(name);
  197. }
  198. @Override
  199. public Long GetCourseIdByName(String name){
  200. return baseClassCourseMapper.getCourseIdByName(name);
  201. }
  202. @Override
  203. public Long GetTextbookIdByName(String name){
  204. return baseClassCourseMapper.getBookIdByName(name);
  205. }
  206. @Override
  207. public Long GetBaseSemesterIdByName(String name) {
  208. return baseClassCourseMapper.getBaseSemesterIdByName(name);
  209. }
  210. @Override
  211. public boolean checkExits(Long classId,Long courseId,Long textbookId){
  212. return baseClassCourseMapper.checkExits(classId, courseId, textbookId);
  213. }
  214. @Override
  215. public boolean checkExitsWithoutTextbook(Long classId, Long courseId) {
  216. return this.baseMapper.checkExitsWithoutTextbook(classId, courseId);
  217. }
  218. }