|
@@ -0,0 +1,183 @@
|
|
|
+package com.xjrsoft.module.student.service.impl;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.xjrsoft.common.enums.EnabledMark;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
|
|
|
+import com.xjrsoft.module.student.dto.StudentReportPlanPageDto;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
+import com.xjrsoft.module.student.entity.StudentReportPlan;
|
|
|
+import com.xjrsoft.module.student.entity.StudentReportPlanClassRelation;
|
|
|
+import com.xjrsoft.module.student.entity.StudentReportRecord;
|
|
|
+import com.xjrsoft.module.student.mapper.StudentReportPlanClassRelationMapper;
|
|
|
+import com.xjrsoft.module.student.mapper.StudentReportPlanMapper;
|
|
|
+import com.xjrsoft.module.student.service.IBaseStudentService;
|
|
|
+import com.xjrsoft.module.student.service.IStudentReportPlanService;
|
|
|
+import com.xjrsoft.module.student.service.IStudentReportRecordService;
|
|
|
+import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
|
|
|
+import com.xjrsoft.module.student.vo.StudentReportPlanPageVo;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+* @title: 学生报到计划
|
|
|
+* @Author dzx
|
|
|
+* @Date: 2025-01-21
|
|
|
+* @Version 1.0
|
|
|
+*/
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class StudentReportPlanServiceImpl extends MPJBaseServiceImpl<StudentReportPlanMapper, StudentReportPlan> implements IStudentReportPlanService {
|
|
|
+ private final StudentReportPlanMapper planMapper;
|
|
|
+
|
|
|
+ private final StudentReportPlanClassRelationMapper relationMapper;
|
|
|
+
|
|
|
+ private final IBaseStudentService studentService;
|
|
|
+
|
|
|
+ private final IStudentReportRecordService reportRecordService;
|
|
|
+
|
|
|
+ private final IUserService userService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean add(StudentReportPlan studentReportPlan) {
|
|
|
+ planMapper.insert(studentReportPlan);
|
|
|
+ for (StudentReportPlanClassRelation studentReportPlanClassRelation : studentReportPlan.getStudentReportPlanClassRelationList()) {
|
|
|
+ studentReportPlanClassRelation.setStudentReportPlanId(studentReportPlan.getId());
|
|
|
+ relationMapper.insert(studentReportPlanClassRelation);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean update(StudentReportPlan studentReportPlan) {
|
|
|
+ planMapper.updateById(studentReportPlan);
|
|
|
+ //********************************* StudentReportPlanClassRelation 增删改 开始 *******************************************/
|
|
|
+ {
|
|
|
+ // 查出所有子级的id
|
|
|
+ List<StudentReportPlanClassRelation> studentReportPlanClassRelationList = relationMapper.selectList(Wrappers.lambdaQuery(StudentReportPlanClassRelation.class).eq(StudentReportPlanClassRelation::getStudentReportPlanId, studentReportPlan.getId()).select(StudentReportPlanClassRelation::getId));
|
|
|
+ List<Long> studentReportPlanClassRelationIds = studentReportPlanClassRelationList.stream().map(StudentReportPlanClassRelation::getId).collect(Collectors.toList());
|
|
|
+ //原有子表单 没有被删除的主键
|
|
|
+ List<Long> studentReportPlanClassRelationOldIds = studentReportPlan.getStudentReportPlanClassRelationList().stream().map(StudentReportPlanClassRelation::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ //找到需要删除的id
|
|
|
+ List<Long> studentReportPlanClassRelationRemoveIds = studentReportPlanClassRelationIds.stream().filter(item -> !studentReportPlanClassRelationOldIds.contains(item)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (StudentReportPlanClassRelation studentReportPlanClassRelation : studentReportPlan.getStudentReportPlanClassRelationList()) {
|
|
|
+ //如果不等于空则修改
|
|
|
+ if (studentReportPlanClassRelation.getId() != null) {
|
|
|
+ relationMapper.updateById(studentReportPlanClassRelation);
|
|
|
+ }
|
|
|
+ //如果等于空 则新增
|
|
|
+ else {
|
|
|
+ //已经不存在的id 删除
|
|
|
+ studentReportPlanClassRelation.setStudentReportPlanId(studentReportPlan.getId());
|
|
|
+ relationMapper.insert(studentReportPlanClassRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //已经不存在的id 删除
|
|
|
+ if(studentReportPlanClassRelationRemoveIds.size() > 0){
|
|
|
+ relationMapper.deleteBatchIds(studentReportPlanClassRelationRemoveIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //********************************* StudentReportPlanClassRelation 增删改 结束 *******************************************/
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean delete(List<Long> ids) {
|
|
|
+ planMapper.deleteBatchIds(ids);
|
|
|
+ relationMapper.delete(Wrappers.lambdaQuery(StudentReportPlanClassRelation.class).in(StudentReportPlanClassRelation::getStudentReportPlanId, ids));
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<StudentReportPlanPageVo> getPage(Page<StudentReportPlanPageVo> page, StudentReportPlanPageDto dto) {
|
|
|
+ return this.baseMapper.getPage(page, dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BaseClass> validateClass(Long id, List<Long> classIds) {
|
|
|
+ return this.baseMapper.validateClass(id, classIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布
|
|
|
+ * 发布之后,将学生初始化到报到记录表中
|
|
|
+ * 发布之后,将学生给禁用掉
|
|
|
+ * @param studentReportPlan
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean release(StudentReportPlan studentReportPlan) {
|
|
|
+ List<Long> classIds = studentReportPlan.getStudentReportPlanClassRelationList().stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
|
|
|
+ //1、查询选择的学生
|
|
|
+ List<BaseStudentUserPageVo> studentList = studentService.getStudentList(new BaseStudentUserPageDto() {{
|
|
|
+ setClassIds(classIds);
|
|
|
+ }});
|
|
|
+
|
|
|
+ Date createDate = new Date();
|
|
|
+ List<StudentReportRecord> insertList = new ArrayList<>();
|
|
|
+ for (BaseStudentUserPageVo student : studentList) {
|
|
|
+ insertList.add(
|
|
|
+ new StudentReportRecord(){{
|
|
|
+ setCreateDate(createDate);
|
|
|
+ setCreateUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ setUserId(Long.parseLong(student.getId()));
|
|
|
+ setBaseSemesterId(studentReportPlan.getSemesterId());
|
|
|
+ setStudentReportPlanId(studentReportPlan.getId());
|
|
|
+ }}
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!insertList.isEmpty()){
|
|
|
+ reportRecordService.remove(
|
|
|
+ new QueryWrapper<StudentReportRecord>().lambda()
|
|
|
+ .eq(StudentReportRecord::getStudentReportPlanId, studentReportPlan.getId())
|
|
|
+ );
|
|
|
+
|
|
|
+ reportRecordService.saveBatch(insertList);
|
|
|
+ Set<String> studentUserIds = studentList.stream().map(BaseStudentUserPageVo::getId).collect(Collectors.toSet());
|
|
|
+ //发布后,将学生的状态改为不正常
|
|
|
+ List<BaseStudent> baseStudents = studentService.list(
|
|
|
+ new QueryWrapper<BaseStudent>().lambda()
|
|
|
+ .in(BaseStudent::getUserId, studentUserIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (BaseStudent baseStudent : baseStudents) {
|
|
|
+ baseStudent.setIsNormal(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ studentService.updateBatchById(baseStudents);
|
|
|
+
|
|
|
+ //修改用户的状态
|
|
|
+ List<User> userList = userService.listByIds(studentUserIds);
|
|
|
+
|
|
|
+ for (User user : userList) {
|
|
|
+ user.setEnabledMark(EnabledMark.DISABLED.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ userService.saveBatch(userList);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|