Ver Fonte

sql优化

zouxuan há 2 anos atrás
pai
commit
e34b246b02

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

@@ -392,7 +392,8 @@ public interface IndexBaseMonthDataDao extends BaseDAO<Long, IndexBaseMonthData>
                                                                  @Param("organIds") List<Integer> organIds,@Param("tenantId") Integer tenantId);
 
     int countStudentErrorLeave(@Param("organIdList") Set<Integer> organIdList,
-                               @Param("format") String format,
+                               @Param("firstDay") String firstDay,
+                               @Param("lastDay") String lastDay,
                                @Param("classGroupIds") List<Long> classGroupIds,
                                @Param("studentErrorLeaveNum") Integer studentErrorLeaveNum,@Param("tenantId") Integer tenantId);
 

+ 17 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -842,13 +842,20 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			two.setDesc(IndexErrorType.STUDENT_INFO.getMsg());
 			List<IndexErrInfoDto> twoChild = new ArrayList<>();
 			tasks = new ArrayList<>();
+			Date now = new Date();
 			//学员请假异常提醒(只提醒本月的异常)
 			tasks.add(() -> {
 				int studentErrorLeave = 0;
 				String studentErrorLeaveNum = sysTenantConfigService.getTenantConfigValue(SysConfigService.STUDENT_ERROR_LEAVE_NUM, tenantId);
 				if (StringUtils.isNotEmpty(studentErrorLeaveNum)) {
-					String format1 = DateUtil.format(new Date(), DateUtil.ISO_YEAR_MONTH_FORMAT);
-					studentErrorLeave = indexBaseMonthDataDao.countStudentErrorLeave(organIdList, format1, classGroupIdList, Integer.parseInt(studentErrorLeaveNum), tenantId);
+					String firstDay = DateUtil.format(DateUtil.getFirstDayOfMonth(now), DateUtil.ISO_YEAR_MONTH_FORMAT);
+					String lastDay = DateUtil.format(DateUtil.getLastDayOfMonth(now), DateUtil.ISO_YEAR_MONTH_FORMAT);
+					studentErrorLeave = indexBaseMonthDataDao.countStudentErrorLeave(organIdList,
+							firstDay,
+							lastDay,
+							classGroupIdList,
+							Integer.parseInt(studentErrorLeaveNum),
+							tenantId);
 				}
 				twoChild.add(new IndexErrInfoDto(IndexErrorType.STUDENT_ERROR_LEAVE,studentErrorLeave));
 			});
@@ -1318,8 +1325,14 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			int studentErrorLeave = 0;
 			String studentErrorLeaveNum = sysTenantConfigService.getTenantConfigValue(SysConfigService.STUDENT_ERROR_LEAVE_NUM, tenantId);
 			if(StringUtils.isNotEmpty(studentErrorLeaveNum)){
-				String format1 = DateUtil.format(new Date(), DateUtil.ISO_YEAR_MONTH_FORMAT);
-				studentErrorLeave = indexBaseMonthDataDao.countStudentErrorLeave(organIds, format1, classGroupIds,Integer.parseInt(studentErrorLeaveNum), tenantId);
+				String firstDay = DateUtil.format(DateUtil.getFirstDayOfMonth(date), DateUtil.ISO_YEAR_MONTH_FORMAT);
+				String lastDay = DateUtil.format(DateUtil.getLastDayOfMonth(date), DateUtil.ISO_YEAR_MONTH_FORMAT);
+				studentErrorLeave = indexBaseMonthDataDao.countStudentErrorLeave(organIds,
+						firstDay,
+						lastDay,
+						classGroupIds,
+						Integer.parseInt(studentErrorLeaveNum),
+						tenantId);
 			}
 			if(studentErrorLeave > 0){
 				flag2 = true;

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/IndexBaseMonthDataMapper.xml

@@ -1699,7 +1699,7 @@
 		SELECT COUNT(DISTINCT c.user_id_) FROM (
 		SELECT sa.user_id_ FROM student_attendance sa
 		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
-		WHERE DATE_FORMAT(cs.class_date_,'%Y-%m') = #{format} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
+		WHERE cs.class_date_ BETWEEN #{firstDay} AND #{lastDay} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
 		<if test="organIdList != null and organIdList.size > 0">
 			AND cs.organ_id_ IN
 			<foreach collection="organIdList" open="(" close=")" item="item" separator=",">