Browse Source

开学报到导出调整

dzx 9 months ago
parent
commit
a8375f3bf0

+ 3 - 10
src/main/java/com/xjrsoft/module/job/StudentReportPlanTask.java

@@ -3,6 +3,7 @@ package com.xjrsoft.module.job;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.EnabledMark;
+import com.xjrsoft.common.utils.RedisUtil;
 import com.xjrsoft.module.student.entity.StudentReportPlan;
 import com.xjrsoft.module.student.service.IBaseStudentService;
 import com.xjrsoft.module.student.service.IStudentReportPlanService;
@@ -27,7 +28,7 @@ public class StudentReportPlanTask {
     private IStudentReportPlanService planService;
 
 
-    @Scheduled(cron = "0 */15 * * * ?")
+    @Scheduled(cron = "0 */5 * * * ?")
     public void execute() {
         doExecute();
     }
@@ -35,15 +36,7 @@ public class StudentReportPlanTask {
     public void doExecute(){
         //查询已发布未开始的,自动开始
         LocalDateTime now = LocalDateTime.now();
-        List<StudentReportPlan> list = planService.list(
-                new QueryWrapper<StudentReportPlan>().lambda()
-                        .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
-                        .eq(StudentReportPlan::getStatus, 1)
-                        .eq(StudentReportPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
-                        .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
-                        .le(StudentReportPlan::getStartTime, now)
-                        .ge(StudentReportPlan::getEndTime, now)
-        );
+        List<StudentReportPlan> list = planService.getWillBeginData();
 
         for (StudentReportPlan studentReportPlan : list) {
             planService.release(studentReportPlan);

+ 2 - 0
src/main/java/com/xjrsoft/module/student/mapper/StudentReportPlanMapper.java

@@ -24,4 +24,6 @@ public interface StudentReportPlanMapper extends MPJBaseMapper<StudentReportPlan
 
 
     List<BaseClass> validateClass(@Param("id") Long id, @Param("semesterId") Long semesterId, @Param("classIds") List<Long> classIds);
+
+    List<StudentReportPlan> getWillBeginData();
 }

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

@@ -48,4 +48,7 @@ public interface IStudentReportPlanService extends MPJBaseService<StudentReportP
     Boolean release(StudentReportPlan studentReportPlan);
 
     Long getEffectivePlanId(Long teacherId, Long classId);
+
+
+    List<StudentReportPlan> getWillBeginData();
 }

+ 55 - 45
src/main/java/com/xjrsoft/module/student/service/impl/StudentReportPlanServiceImpl.java

@@ -26,6 +26,7 @@ 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 me.zhyd.oauth.log.Log;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -137,57 +138,61 @@ public class StudentReportPlanServiceImpl extends MPJBaseServiceImpl<StudentRepo
     @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);
-        }});
-        if(studentList.isEmpty()){
-            throw new MyException("未能查询到学生,请联系管理员");
-        }
-
-        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());
-                    }}
-            );
-        }
+        try {
+            List<Long> classIds = studentReportPlan.getStudentReportPlanClassRelationList().stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
+            //1、查询选择的学生
+            List<BaseStudentUserPageVo> studentList = studentService.getStudentList(new BaseStudentUserPageDto() {{
+                setClassIds(classIds);
+            }});
+            if(studentList.isEmpty()){
+                return true;
+            }
 
-        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);
+            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());
+                        }}
+                );
             }
 
-            studentService.updateBatchById(baseStudents);
+            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);
+                }
 
-            //修改用户的状态
-            List<User> userList = userService.listByIds(studentUserIds);
+                studentService.updateBatchById(baseStudents);
 
-            for (User user : userList) {
-                user.setEnabledMark(EnabledMark.DISABLED.getCode());
-            }
+                //修改用户的状态
+                List<User> userList = userService.listByIds(studentUserIds);
 
-            userService.updateBatchById(userList);
+                for (User user : userList) {
+                    user.setEnabledMark(EnabledMark.DISABLED.getCode());
+                }
+
+                userService.updateBatchById(userList);
+            }
+        }catch (Exception e){
+            Log.error(e.getMessage(), e);
         }
         return true;
     }
@@ -218,4 +223,9 @@ public class StudentReportPlanServiceImpl extends MPJBaseServiceImpl<StudentRepo
         }
         return null;
     }
+
+    @Override
+    public List<StudentReportPlan> getWillBeginData() {
+        return baseMapper.getWillBeginData();
+    }
 }

+ 5 - 0
src/main/resources/mapper/student/StudentReportPlanMapper.xml

@@ -32,4 +32,9 @@
             #{classId}
         </foreach>
     </select>
+
+    <select id="getWillBeginData" resultType="com.xjrsoft.module.student.entity.StudentReportPlan">
+        SELECT * FROM student_report_plan WHERE delete_mark = 0 AND enabled_mark = 1 AND status = 1
+        AND DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00') = DATE_FORMAT(now(),'%Y-%m-%d %H:00:00')
+    </select>
 </mapper>