Browse Source

学生报到

dzx 1 month ago
parent
commit
ee549383f6

+ 42 - 0
src/main/java/com/xjrsoft/common/enums/RoleCodeEnum.java

@@ -0,0 +1,42 @@
+package com.xjrsoft.common.enums;
+
+
+/**
+ * 系统角色编码
+ */
+public enum RoleCodeEnum {
+    /**
+     * 超级管理员
+     */
+    ADMIN("ADMIN", "超级管理员"),
+    /**
+     * 教师
+     */
+    TEACHER("TEACHER", "教师"),
+    /**
+     * 学生
+     */
+    STUDENT("STUDENT", "学生"),
+    /**
+     * 家长
+     */
+    PARENT("PARENT", "家长"),
+
+    CLASSTE("CLASSTE", "班主任");
+
+    final String code;
+    final String value;
+
+    public String getCode() {
+        return this.code;
+    }
+
+    public String getValue() {
+        return this.value;
+    }
+
+    RoleCodeEnum(final String code, final String message) {
+        this.code = code;
+        this.value = message;
+    }
+}

+ 3 - 0
src/main/java/com/xjrsoft/module/base/service/IBaseClassService.java

@@ -21,4 +21,7 @@ public interface IBaseClassService extends MPJBaseService<BaseClass> {
     List<StudentClassVo> getStudentClass();
 
     Page<ClassStatisticsVo> getAttendancePage(Page<ClassStatisticsVo> page, AttendanceStatisticDto dto);
+
+
+    Long getIdByTeacherId(Long teacherId);
 }

+ 24 - 0
src/main/java/com/xjrsoft/module/base/service/impl/BaseClassServiceImpl.java

@@ -1,9 +1,12 @@
 package com.xjrsoft.module.base.service.impl;
 
+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.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.xjrsoft.common.enums.DeleteMark;
+import com.xjrsoft.common.enums.EnabledMark;
 import com.xjrsoft.module.attendance.dto.AttendanceStatisticDto;
 import com.xjrsoft.module.attendance.vo.ClassStatisticsVo;
 import com.xjrsoft.module.base.dto.BaseClassPageDto;
@@ -103,4 +106,25 @@ public class BaseClassServiceImpl extends MPJBaseServiceImpl<BaseClassMapper, Ba
     public Page<ClassStatisticsVo> getAttendancePage(Page<ClassStatisticsVo> page, AttendanceStatisticDto dto){
         return baseClassMapper.getAttendanceClass(page, dto);
     };
+
+
+    /**
+     * 根据教师id查询班级id
+     * @param teacherId 教师userId
+     * @return 班主任所负责的班级id
+     */
+    @Override
+    public Long getIdByTeacherId(Long teacherId){
+        List<BaseClass> list = this.baseMapper.selectList(
+                new QueryWrapper<BaseClass>().lambda()
+                        .eq(BaseClass::getTeacherId, teacherId)
+                        .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
+                        .eq(BaseClass::getEnabledMark, EnabledMark.ENABLED.getCode())
+                        .orderByDesc(BaseClass::getCreateDate)
+        );
+        if(list.isEmpty()){
+            return null;
+        }
+        return list.get(0).getId();
+    };
 }

+ 20 - 0
src/main/java/com/xjrsoft/module/student/controller/StudentReportRecordController.java

@@ -3,14 +3,18 @@ package com.xjrsoft.module.student.controller;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xjrsoft.common.enums.DeleteMark;
+import com.xjrsoft.common.enums.EnabledMark;
 import com.xjrsoft.common.enums.EnrollTypeEnum;
 import com.xjrsoft.common.enums.GenderDictionaryEnum;
+import com.xjrsoft.common.enums.RoleCodeEnum;
 import com.xjrsoft.common.enums.StudyStatusEnum;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
@@ -18,6 +22,7 @@ import com.xjrsoft.common.page.PageOutput;
 import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.module.base.entity.BaseGrade;
 import com.xjrsoft.module.base.entity.BaseSemester;
+import com.xjrsoft.module.base.service.IBaseClassService;
 import com.xjrsoft.module.base.service.IBaseGradeService;
 import com.xjrsoft.module.base.service.IBaseSemesterService;
 import com.xjrsoft.module.databoard.vo.ItemCountVo;
@@ -77,6 +82,8 @@ public class StudentReportRecordController {
     private final IBaseSemesterService semesterService;
     private final IBaseGradeService gradeService;
     private final IStudentReportPlanService studentReportPlanService;
+    private final IStudentReportPlanService planService;
+    private final IBaseClassService classService;
 
     @GetMapping(value = "/page")
     @ApiOperation(value="学生报到记录表列表(分页)")
@@ -190,6 +197,7 @@ public class StudentReportRecordController {
     @ApiOperation(value="班级统计")
     @SaCheckPermission("studentreportrecord:detail")
     public RT<StudentReportRecordStatisticsVo> classStatistics(@Valid StudentReportRecordStatisticsDto dto){
+
         if(dto.getTeacherId() == null){
             dto.setTeacherId(StpUtil.getLoginIdAsLong());
         }
@@ -213,6 +221,10 @@ public class StudentReportRecordController {
                 dto.setGradeId(gradeList.get(0).getId());
             }
         }
+
+        Long planId = planService.getEffectivePlanId(dto.getTeacherId());
+        dto.setStudentReportPlanId(planId);
+
         StudentReportRecordStatisticsVo statisticsVo = studentReportRecordService.getClassStatistics(dto);
         if(statisticsVo == null){
             statisticsVo = new StudentReportRecordStatisticsVo();
@@ -335,6 +347,14 @@ public class StudentReportRecordController {
     @ApiOperation(value="学生报到记录表列表(分页)")
     @SaCheckPermission("studentreportrecord:detail")
     public RT<PageOutput<StudentReportRecordPlanPageVo>> planPage(@Valid StudentReportRecordPageDto dto){
+        List<String> roleList = StpUtil.getRoleList();
+        if(roleList.size() == 2 && roleList.contains(RoleCodeEnum.TEACHER.getCode()) && roleList.contains(RoleCodeEnum.CLASSTE.getCode())){
+            Long classId = classService.getIdByTeacherId(StpUtil.getLoginIdAsLong());
+            if(ObjectUtil.isNull(classId)){
+                return RT.ok(new PageOutput<>());
+            }
+            dto.setClassId(classId);
+        }
         Page<StudentReportRecordPlanPageVo> planPage = studentReportRecordService.getPlanPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
         PageOutput<StudentReportRecordPlanPageVo> pageOutput = ConventPage.getPageOutput(planPage, StudentReportRecordPlanPageVo.class);
         return RT.ok(pageOutput);

+ 5 - 0
src/main/java/com/xjrsoft/module/student/dto/StudentReportRecordStatisticsDto.java

@@ -1,5 +1,6 @@
 package com.xjrsoft.module.student.dto;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.xjrsoft.common.page.PageInput;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -29,4 +30,8 @@ public class StudentReportRecordStatisticsDto extends PageInput {
 
     @ApiModelProperty("班级id")
     private Long classId;
+
+    @JsonIgnore
+    @ApiModelProperty("报到计划id")
+    private Long studentReportPlanId;
 }

+ 2 - 0
src/main/java/com/xjrsoft/module/student/service/IStudentReportPlanService.java

@@ -46,4 +46,6 @@ public interface IStudentReportPlanService extends MPJBaseService<StudentReportP
     List<BaseClass> validateClass(Long id, List<Long> classIds);
 
     Boolean release(StudentReportPlan studentReportPlan);
+
+    Long getEffectivePlanId(Long teacherId);
 }

+ 27 - 0
src/main/java/com/xjrsoft/module/student/service/impl/StudentReportPlanServiceImpl.java

@@ -5,6 +5,7 @@ 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.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.EnabledMark;
 import com.xjrsoft.module.base.entity.BaseClass;
@@ -27,6 +28,7 @@ import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -184,4 +186,29 @@ public class StudentReportPlanServiceImpl extends MPJBaseServiceImpl<StudentRepo
         }
         return true;
     }
+
+    /**
+     * 查询有效的计划id
+     * @param teacherId 班主任id
+     * @return 计划id
+     */
+    @Override
+    public Long getEffectivePlanId(Long teacherId) {
+        LocalDateTime now = LocalDateTime.now();
+        List<StudentReportPlan> list = this.selectJoinList(StudentReportPlan.class,
+                new MPJLambdaWrapper<StudentReportPlan>()
+                        .leftJoin(StudentReportPlanClassRelation.class, StudentReportPlanClassRelation::getStudentReportPlanId, StudentReportPlan::getId)
+                        .leftJoin(BaseClass.class, BaseClass::getId, StudentReportPlanClassRelation::getClassId)
+                        .eq(teacherId != null, BaseClass::getTeacherId, teacherId)
+                        .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
+                        .eq(StudentReportPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
+                        .ge(StudentReportPlan::getStartTime, now)
+                        .le(StudentReportPlan::getEndTime, now)
+                        .orderByDesc(StudentReportPlan::getId)
+        );
+        if(!list.isEmpty()){
+           return list.get(0).getId();
+        }
+        return null;
+    }
 }

+ 5 - 2
src/main/resources/mapper/student/StudentReportRecordMapper.xml

@@ -30,6 +30,9 @@
         INNER JOIN student_report_record a3 ON a1.id = a3.user_id
         WHERE a1.delete_mark = 0 AND a2.delete_mark = 0 and a3.delete_mark = 0
         AND a2.class_id = t1.id AND a3.base_semester_id = #{dto.baseSemesterId} AND a3.report_time IS NOT NULL
+        <if test="dto.studentReportPlanId != null">
+            and a3.student_report_plan_id = #{dto.studentReportPlanId}
+        </if>
         ) AS arrived_count
         FROM base_class t1
         INNER JOIN xjr_user t2 ON t1.teacher_id = t2.id
@@ -111,7 +114,7 @@
         <if test="dto.reportTimeStart != null and dto.reportTimeEnd != null">
             and t1.report_time between #{dto.reportTimeStart} and #{dto.reportTimeEnd}
         </if>
-        ORDER BY t1.id desc
+        ORDER BY t1.report_time IS NULL DESC, t1.report_time DESC
     </select>
     <select id="getPlanPageList" parameterType="com.xjrsoft.module.student.dto.StudentReportRecordPageDto" resultType="com.xjrsoft.module.student.vo.StudentReportRecordPlanPageVo">
         SELECT t1.id, t1.user_id, t4.name AS grade_name,t5.name AS class_name,t6.name AS teacher_name,
@@ -170,7 +173,7 @@
         <if test="dto.reportTimeStart != null and dto.reportTimeEnd != null">
             and t1.report_time between #{dto.reportTimeStart} and #{dto.reportTimeEnd}
         </if>
-        ORDER BY t1.id desc
+        ORDER BY t1.report_time IS NULL DESC, t1.report_time DESC
     </select>
     <select id="getStatisticsDataList" parameterType="com.xjrsoft.module.student.dto.StudentReportRecordStatisticsDto"
             resultType="com.xjrsoft.module.student.vo.StudentReportRecordStatisticsListVo">