Browse Source

fix:1、作业改造

Joburgess 4 năm trước cách đây
mục cha
commit
7613642744

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentDao.java

@@ -97,7 +97,8 @@ public interface StudentDao extends com.ym.mec.common.dal.BaseDAO<Integer, Stude
 
     List<StudentServeCourseDto> getServeStudentCourseStartTimes(@Param("monday") String monday);
 
-    List<StudentServeCourseDto> getStudentFutureCourseInfo(@Param("monday") String monday);
+    List<StudentServeCourseDto> getStudentFutureCourseInfo(@Param("monday") String monday,
+                                                           @Param("studentIds") List<Integer> studentIds);
 
     /**
      * @param monday:

+ 21 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentExtracurricularExercisesSituationDao.java

@@ -20,6 +20,8 @@ public interface StudentExtracurricularExercisesSituationDao extends BaseDAO<Lon
      */
     int batchInsert(@Param("situations")List<StudentExtracurricularExercisesSituation> situations);
 
+    int batchUpdate(@Param("situations")List<StudentExtracurricularExercisesSituation> situations);
+
     /**
      * @describe 根据周一日期删除统计信息
      * @author Joburgess
@@ -83,4 +85,23 @@ public interface StudentExtracurricularExercisesSituationDao extends BaseDAO<Lon
      */
     List<Map<Integer, Long>> getNoFinishedServiceTeacher(@Param("monday") String monday);
 
+    /**
+     * @describe 统计指定星期的服务记录数量
+     * @author Joburgess
+     * @date 2020/12/25 0025
+     * @param sunday:
+     * @return int
+     */
+    int countWeekServiceNum(@Param("sunday") String sunday);
+
+    /**
+     * @describe 获取指定周指定学员的服务指标
+     * @author Joburgess
+     * @date 2020/12/25 0025
+     * @param monday:
+     * @param studentIds:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation>
+     */
+    List<StudentExtracurricularExercisesSituation> findWeekServiceWithStudents(@Param("monday") String monday,
+                                                                               @Param("studentIds") List<Integer> studentIds);
 }

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TeacherAttendanceDto.java

@@ -88,10 +88,21 @@ public class TeacherAttendanceDto {
     @ApiModelProperty(value = "是否是第一次进行学生点名")
     private int studentAttendanceIsFirstTime;
 
+    @ApiModelProperty(value = "能否布置作业")
+    private int enableAssignHomework;
+
     private Integer enableStudentAttendanceTimeRange;
 
     private Integer enableStudentAttendanceTimeRangeVip;
 
+    public int getEnableAssignHomework() {
+        return enableAssignHomework;
+    }
+
+    public void setEnableAssignHomework(int enableAssignHomework) {
+        this.enableAssignHomework = enableAssignHomework;
+    }
+
     public Integer getEnableStudentAttendanceTimeRangeVip() {
         return enableStudentAttendanceTimeRangeVip;
     }

+ 6 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentExtracurricularExercisesSituation.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.dal.entity;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 import java.util.Date;
@@ -199,7 +200,11 @@ public class StudentExtracurricularExercisesSituation {
 	public java.util.Date getUpdateTime(){
 		return this.updateTime;
 	}
-			
+
+	public String getStuAndTeaCode(){
+		return StringUtils.join(this.studentId, this.teacherId);
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/StudentServeService.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -17,7 +18,7 @@ public interface StudentServeService {
      */
     void exercisesSituationStatistics(String monday);
 
-    void exercisesSituationStatistics2(String monday);
+    void exercisesSituationStatistics2(String monday, List<Integer> studentIds);
 
     /**
      * @describe

+ 63 - 14
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentServeServiceImpl.java

@@ -288,7 +288,8 @@ public class StudentServeServiceImpl implements StudentServeService {
     }
 
     @Override
-    public void exercisesSituationStatistics2(String monday) {
+    @Transactional(rollbackFor = Exception.class)
+    public void exercisesSituationStatistics2(String monday, List<Integer> studentIds) {
         LocalDate nowDate = LocalDateTime.now(DateUtil.zoneId).toLocalDate();
 
         if(StringUtils.isNotBlank(monday)){
@@ -299,7 +300,12 @@ public class StudentServeServiceImpl implements StudentServeService {
         LocalDate sunDayDate = nowDate.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
         Date nextMonday = Date.from(sunDayDate.plusDays(1).atStartOfDay(DateUtil.zoneId).toInstant());
 
-        List<StudentServeCourseDto> studentFutureCourseInfo = studentDao.getStudentFutureCourseInfo(monDayDate.toString());
+        int weekServiceNum = studentExtracurricularExercisesSituationDao.countWeekServiceNum(monDayDate.toString());
+        if(weekServiceNum>0&&CollectionUtils.isEmpty(studentIds)){
+            return;
+        }
+
+        List<StudentServeCourseDto> studentFutureCourseInfo = studentDao.getStudentFutureCourseInfo(monDayDate.toString(), studentIds);
         Map<Integer, List<StudentServeCourseDto>> studentCourseMap = studentFutureCourseInfo.stream().collect(Collectors.groupingBy(StudentServeCourseDto::getStudentId));
 
         List<StudentExtracurricularExercisesSituation> results=new ArrayList<>();
@@ -330,7 +336,7 @@ public class StudentServeServiceImpl implements StudentServeService {
                         StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation(studentCourseMapEntry.getKey(),
                                 teacherServiceCourseIdMapEntry.getKey(),nowDate.get(DateUtil.weekFields.weekOfYear()),
                                 DateUtil.stringToDate(monDayDate.toString(), "yyyy-MM-dd"), DateUtil.stringToDate(sunDayDate.toString(), "yyyy-MM-dd"),
-                                "EXERCISE", StringUtils.join(teacherServiceCourseIdMapEntry.getValue(), ","));
+                                "HOMEWORK", StringUtils.join(teacherServiceCourseIdMapEntry.getValue(), ","));
                         studentExtracurricularExercisesSituation.setExpectExercisesNum(teacherServiceCourseIdMapEntry.getValue().size());
                         results.add(studentExtracurricularExercisesSituation);
                     }
@@ -360,18 +366,21 @@ public class StudentServeServiceImpl implements StudentServeService {
                         StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation(studentCourseMapEntry.getKey(),
                                 teacherServiceCourseIdMapEntry.getKey(),nowDate.get(DateUtil.weekFields.weekOfYear()),
                                 DateUtil.stringToDate(monDayDate.toString(), "yyyy-MM-dd"), DateUtil.stringToDate(sunDayDate.toString(), "yyyy-MM-dd"),
-                                "EXERCISE", StringUtils.join(teacherServiceCourseIdMapEntry.getValue(), ","));
+                                "HOMEWORK", StringUtils.join(teacherServiceCourseIdMapEntry.getValue(), ","));
                         studentExtracurricularExercisesSituation.setExpectExercisesNum(teacherServiceCourseIdMapEntry.getValue().size());
                         results.add(studentExtracurricularExercisesSituation);
                     }
                 }
             }else if(typeCourseMap.containsKey(CourseSchedule.CourseScheduleType.MIX)){
-                CourseSchedule studentHistoryLastCourse = courseScheduleStudentPaymentDao.getStudentHistoryLastCourse(studentCourseMapEntry.getKey(), monday, CourseSchedule.CourseScheduleType.SINGLE);
+                CourseSchedule studentHistoryLastCourse = courseScheduleStudentPaymentDao.getStudentHistoryLastCourse(studentCourseMapEntry.getKey(), monDayDate.toString(), CourseSchedule.CourseScheduleType.SINGLE);
                 StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation(studentCourseMapEntry.getKey(),
                         Objects.isNull(studentHistoryLastCourse)?studentCourseMapEntry.getValue().get(0).getLeadTeacherId():studentHistoryLastCourse.getActualTeacherId(),
                         nowDate.get(DateUtil.weekFields.weekOfYear()),
                         DateUtil.stringToDate(monDayDate.toString(), "yyyy-MM-dd"), DateUtil.stringToDate(sunDayDate.toString(), "yyyy-MM-dd"),
                         "EXERCISE", null);
+                if(Objects.isNull(studentExtracurricularExercisesSituation.getTeacherId())){
+                    continue;
+                }
                 results.add(studentExtracurricularExercisesSituation);
             }else if(typeCourseMap.containsKey(CourseSchedule.CourseScheduleType.PRACTICE)){
                 List<StudentServeCourseDto> futureCourseInfo = typeCourseMap.get(CourseSchedule.CourseScheduleType.PRACTICE);
@@ -398,7 +407,7 @@ public class StudentServeServiceImpl implements StudentServeService {
                         StudentExtracurricularExercisesSituation studentExtracurricularExercisesSituation=new StudentExtracurricularExercisesSituation(studentCourseMapEntry.getKey(),
                                 teacherServiceCourseIdMapEntry.getKey(),nowDate.get(DateUtil.weekFields.weekOfYear()),
                                 DateUtil.stringToDate(monDayDate.toString(), "yyyy-MM-dd"), DateUtil.stringToDate(sunDayDate.toString(), "yyyy-MM-dd"),
-                                "EXERCISE", StringUtils.join(teacherServiceCourseIdMapEntry.getValue(), ","));
+                                "HOMEWORK", StringUtils.join(teacherServiceCourseIdMapEntry.getValue(), ","));
                         studentExtracurricularExercisesSituation.setExpectExercisesNum(teacherServiceCourseIdMapEntry.getValue().size());
                         results.add(studentExtracurricularExercisesSituation);
                     }
@@ -407,16 +416,56 @@ public class StudentServeServiceImpl implements StudentServeService {
                 continue;
             }
         }
-        BigDecimal currentPage1=BigDecimal.ONE,
-                pageSize1=new BigDecimal(10000),
-                total1=new BigDecimal(results.size()),
-                totalPage1=total1.divide(pageSize1, BigDecimal.ROUND_UP);
 
-        while (currentPage1.compareTo(totalPage1)<=0){
-            List<StudentExtracurricularExercisesSituation> rows=results.stream().skip(pageSize1.multiply(currentPage1.subtract(BigDecimal.ONE)).longValue()).limit(pageSize1.longValue()).collect(Collectors.toList());
-            studentExtracurricularExercisesSituationDao.batchInsert(rows);
-            currentPage1=currentPage1.add(BigDecimal.ONE);
+        if(CollectionUtils.isEmpty(studentIds)){
+            studentExtracurricularExercisesSituationDao.deleteByMonday(monDayDate.toString());
+            BigDecimal currentPage1=BigDecimal.ONE,
+                    pageSize1=new BigDecimal(10000),
+                    total1=new BigDecimal(results.size()),
+                    totalPage1=total1.divide(pageSize1, BigDecimal.ROUND_UP);
+
+            while (currentPage1.compareTo(totalPage1)<=0){
+                List<StudentExtracurricularExercisesSituation> rows=results.stream().skip(pageSize1.multiply(currentPage1.subtract(BigDecimal.ONE)).longValue()).limit(pageSize1.longValue()).collect(Collectors.toList());
+                studentExtracurricularExercisesSituationDao.batchInsert(rows);
+                currentPage1=currentPage1.add(BigDecimal.ONE);
+            }
+            return;
+        }
+
+        List<StudentExtracurricularExercisesSituation> weekServiceWithStudents = studentExtracurricularExercisesSituationDao.findWeekServiceWithStudents(monDayDate.toString(), studentIds);
+        Map<String, StudentExtracurricularExercisesSituation> codeServeMap = weekServiceWithStudents.stream().collect(Collectors.toMap(StudentExtracurricularExercisesSituation::getStuAndTeaCode, s -> s, (s1, s2) -> s1));
+
+        Set<String> newCodes = results.stream().map(StudentExtracurricularExercisesSituation::getStuAndTeaCode).collect(Collectors.toSet());
+        for (StudentExtracurricularExercisesSituation weekServiceWithStudent : weekServiceWithStudents) {
+            if(weekServiceWithStudent.getActualExercisesNum()>0||newCodes.contains(weekServiceWithStudent.getStuAndTeaCode())){
+                continue;
+            }
+            studentExtracurricularExercisesSituationDao.delete(weekServiceWithStudent.getId());
+        }
+
+        List<StudentExtracurricularExercisesSituation> newService = new ArrayList<>();
+        List<StudentExtracurricularExercisesSituation> updateService = new ArrayList<>();
+        for (StudentExtracurricularExercisesSituation result : results) {
+            if(codeServeMap.containsKey(result.getStuAndTeaCode())){
+                StudentExtracurricularExercisesSituation s = codeServeMap.get(result.getStuAndTeaCode());
+                List<Long> courseIds = new ArrayList<>();
+                if(StringUtils.isNotBlank(s.getCourseIds())&&s.getActualExercisesNum()>0){
+                    courseIds = Arrays.stream(s.getCourseIds().split(",")).map(id->Long.valueOf(id)).collect(Collectors.toList());
+                }
+                if(StringUtils.isNotBlank(result.getCourseIds())){
+                    courseIds.addAll(Arrays.stream(result.getCourseIds().split(",")).map(id->Long.valueOf(id)).collect(Collectors.toList()));
+                }
+                s.setCourseIds(StringUtils.join(courseIds, ","));
+                s.setExpectExercisesNum(courseIds.size());
+                updateService.add(s);
+            }else{
+                newService.add(result);
+            }
         }
+        if(!CollectionUtils.isEmpty(updateService))
+            studentExtracurricularExercisesSituationDao.batchUpdate(updateService);
+        if(!CollectionUtils.isEmpty(newService))
+            studentExtracurricularExercisesSituationDao.batchInsert(newService);
     }
 
     @Override

+ 64 - 0
mec-biz/src/main/resources/config/mybatis/StudentExtracurricularExercisesSituationMapper.xml

@@ -123,6 +123,54 @@
 		</set> WHERE id_ = #{id}
 	</update>
 
+	<update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation">
+		<foreach collection="situations" item="situation" separator=";">
+			UPDATE student_extracurricular_exercises_situation_
+			<set>
+				<if test="situation.exercisesReplyNum != null">
+					exercises_reply_num_ = #{situation.exercisesReplyNum},
+				</if>
+				<if test="situation.monday != null">
+					monday_ = #{situation.monday},
+				</if>
+				<if test="situation.weekOfYear != null">
+					week_of_year_ = #{situation.weekOfYear},
+				</if>
+				<if test="situation.exercisesMessageNum != null">
+					exercises_message_num_ = #{situation.exercisesMessageNum},
+				</if>
+				<if test="situation.teacherId != null">
+					teacher_id_ = #{situation.teacherId},
+				</if>
+				<if test="situation.actualExercisesNum != null">
+					actual_exercises_num_ = #{situation.actualExercisesNum},
+				</if>
+				<if test="situation.exercisesMessageTimelyNum != null">
+					exercises_message_timely_num_ = #{situation.exercisesMessageTimelyNum},
+				</if>
+				<if test="situation.studentId != null">
+					student_id_ = #{situation.studentId},
+				</if>
+				<if test="situation.expectExercisesNum != null">
+					expect_exercises_num_ = #{situation.expectExercisesNum},
+				</if>
+				<if test="situation.sunday != null">
+					sunday_ = #{situation.sunday},
+				</if>
+				<if test="situation.lastSubmitTime!=null">
+					last_submit_time_=#{situation.lastSubmitTime},
+				</if>
+				<if test="situation.serveType!=null">
+					serve_type_=#{situation.serveType},
+				</if>
+				<if test="situation.courseIds!=null and situation.courseIds!=''">
+					course_ids_=#{situation.courseIds},
+				</if>
+				update_time_ = NOW()
+			</set> WHERE id_ = #{situation.id}
+		</foreach>
+	</update>
+
 	<!-- 根据主键删除一条记录 -->
 	<delete id="delete" >
 		DELETE FROM student_extracurricular_exercises_situation_ WHERE id_ = #{id} 
@@ -337,12 +385,14 @@
 		</trim>
 		) tmp
 	</select>
+
 	<select id="findExercisesSituationsById" resultMap="StudentExtracurricularExercisesSituation">
 		SELECT * FROM student_extracurricular_exercises_situation_ WHERE id_ IN
 		<foreach collection="ids" item="id" separator="," open="(" close=")">
 			#{id}
 		</foreach>
 	</select>
+
 	<select id="findTeacherExercisesServiceSituations" resultType="com.ym.mec.biz.dal.dto.TeacherExercisesServiceDto">
 		SELECT
 		teacher_id_ teacherId,
@@ -359,12 +409,15 @@
 		GROUP BY
 		teacher_id_;
 	</select>
+
 	<select id="findLastWeekTodayUpdateNum" resultType="int">
 		SELECT COUNT(id_) FROM student_extracurricular_exercises_situation_ WHERE sunday_=#{sunday} AND DATE_FORMAT(update_time_,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d')
     </select>
+
 	<select id="findStudentExercisesSituationsWithMonDay" resultMap="StudentExtracurricularExercisesSituation">
 		SELECT * FROM student_extracurricular_exercises_situation_ WHERE monday_=#{monday} AND student_id_=#{studentId}
 	</select>
+
 	<select id="getNoFinishedServiceTeacher" resultType="java.util.Map">
 		SELECT
 			teacher_id_ AS 'key',
@@ -379,4 +432,15 @@
 		GROUP BY
 			teacher_id_
 	</select>
+
+	<select id="countWeekServiceNum" resultType="int">
+		SELECT COUNT(id_) FROM student_extracurricular_exercises_situation_ WHERE monday_=#{sunday}
+	</select>
+
+	<select id="findWeekServiceWithStudents" resultMap="StudentExtracurricularExercisesSituation">
+		SELECT * FROM student_extracurricular_exercises_situation_ WHERE monday_=#{monday} AND student_id_ IN
+		<foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+			#{studentId}
+		</foreach>
+	</select>
 </mapper>

+ 8 - 2
mec-biz/src/main/resources/config/mybatis/StudentMapper.xml

@@ -498,8 +498,14 @@
             LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
             LEFT JOIN student stu ON cssp.user_id_ = stu.user_id_
         WHERE stu.service_tag_=1
-          AND cs.class_date_&gt;=#{monday}
-          AND cs.type_ IN ('SINGLE','VIP','MIX','PRACTICE')
+            AND cs.class_date_&gt;=#{monday}
+            AND cs.type_ IN ('SINGLE','VIP','MIX','PRACTICE')
+            <if test="studentIds!=null and studentIds.size()>0">
+                AND cssp.user_id_ IN
+                <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+                    #{studentId}
+                </foreach>
+            </if>
         ORDER BY cssp.user_id_,start_class_time_
     </select>
 

+ 3 - 1
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 
 @RequestMapping("task")
@@ -253,7 +255,7 @@ public class TaskController extends BaseController {
 	//学生服务信息统计
 	@GetMapping("/exercisesSituationStatistics")
 	public void exercisesSituationStatistics(){
-		studentServeService.exercisesSituationStatistics2(null);
+		studentServeService.exercisesSituationStatistics2(null,new ArrayList<>(Arrays.asList(1095257)));
 //		studentServeService.exercisesSituationStatistics(null);
 	}