|
@@ -5,22 +5,22 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.ym.mec.biz.dal.enums.ClassGroupStudentStatusEnum;
|
|
|
import com.ym.mec.education.base.PageResponse;
|
|
|
-import com.ym.mec.education.entity.ClassGroup;
|
|
|
-import com.ym.mec.education.entity.CourseSchedule;
|
|
|
-import com.ym.mec.education.entity.StudentAttendance;
|
|
|
+import com.ym.mec.education.entity.*;
|
|
|
import com.ym.mec.education.enums.StudentAttendanceStatusEnum;
|
|
|
import com.ym.mec.education.mapper.StudentAttendanceMapper;
|
|
|
import com.ym.mec.education.req.ClassGroupReq;
|
|
|
-import com.ym.mec.education.resp.StudentAttendanceResq;
|
|
|
-import com.ym.mec.education.service.IClassGroupService;
|
|
|
-import com.ym.mec.education.service.ICourseScheduleService;
|
|
|
-import com.ym.mec.education.service.IStudentAttendanceService;
|
|
|
-import com.ym.mec.education.service.ISubjectService;
|
|
|
+import com.ym.mec.education.req.CourseScheduleReq;
|
|
|
+import com.ym.mec.education.resp.StudentAttendanceResp;
|
|
|
+import com.ym.mec.education.resp.StudentAttendanceStatisticsResp;
|
|
|
+import com.ym.mec.education.service.*;
|
|
|
import com.ym.mec.education.utils.DateUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -41,17 +41,24 @@ public class StudentAttendanceServiceImpl extends ServiceImpl<StudentAttendanceM
|
|
|
private IClassGroupService groupService;
|
|
|
@Autowired
|
|
|
private ISubjectService subjectService;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private IClassGroupStudentMapperService classGroupStudentMapperService;
|
|
|
|
|
|
@Override
|
|
|
public PageResponse getPage(ClassGroupReq classGroupReq) {
|
|
|
+ if (Objects.isNull(classGroupReq.getGroupId())){
|
|
|
+ return PageResponse.errorParam();
|
|
|
+ }
|
|
|
Page<StudentAttendance> pageParam = new Page(classGroupReq.getPageNo(), classGroupReq.getPageSize());
|
|
|
QueryWrapper<StudentAttendance> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.lambda().eq(Objects.nonNull(classGroupReq.getGroupId()),
|
|
|
StudentAttendance::getClassGroupId, classGroupReq.getGroupId());
|
|
|
IPage<StudentAttendance> page = page(pageParam, queryWrapper);
|
|
|
- IPage<StudentAttendanceResq> pageResult = new Page<>();
|
|
|
+ IPage<StudentAttendanceResp> pageResult = new Page<>();
|
|
|
BeanUtils.copyProperties(page, pageResult);
|
|
|
- List<StudentAttendanceResq> list = Lists.newArrayList();
|
|
|
+ List<StudentAttendanceResp> list = Lists.newArrayList();
|
|
|
QueryWrapper<StudentAttendance> leaveWrapper = new QueryWrapper<>();
|
|
|
QueryWrapper<StudentAttendance> normalWrapper = new QueryWrapper<>();
|
|
|
//总人数
|
|
@@ -65,24 +72,135 @@ public class StudentAttendanceServiceImpl extends ServiceImpl<StudentAttendanceM
|
|
|
.eq(true, StudentAttendance::getStatus, StudentAttendanceStatusEnum.NORMAL.getCode());
|
|
|
Integer normalCount = count(normalWrapper);
|
|
|
page.getRecords().forEach(item -> {
|
|
|
- StudentAttendanceResq studentAttendanceResq = new StudentAttendanceResq();
|
|
|
- studentAttendanceResq.setLeaveNum(leaveCount).setAttendanceRate(normalCount + "/" + totalCount);
|
|
|
+ StudentAttendanceResp studentAttendanceResp = new StudentAttendanceResp();
|
|
|
+ studentAttendanceResp.setLeaveNum(leaveCount);
|
|
|
+ if (totalCount != 0) {
|
|
|
+ studentAttendanceResp.setAttendanceRate(normalCount + "/" + totalCount);
|
|
|
+ }
|
|
|
QueryWrapper<CourseSchedule> courseScheduleQueryWrapper = new QueryWrapper<>();
|
|
|
courseScheduleQueryWrapper.lambda().eq(true, CourseSchedule::getClassGroupId, classGroupReq.getGroupId())
|
|
|
.eq(true, CourseSchedule::getTeacherId, item.getTeacherId());
|
|
|
CourseSchedule courseSchedule = courseScheduleService.getOne(courseScheduleQueryWrapper);
|
|
|
if (Objects.nonNull(courseSchedule)) {
|
|
|
- studentAttendanceResq.setClassDate(DateUtil.date2String(courseSchedule.getClassDate())
|
|
|
+ studentAttendanceResp.setClassDate(DateUtil.date2String(courseSchedule.getClassDate())
|
|
|
+ " " + DateUtil.date2Week(courseSchedule.getClassDate()))
|
|
|
.setClassTime(courseSchedule.getStartClassTime() + "-" + courseSchedule.getEndClassTime());
|
|
|
}
|
|
|
ClassGroup classGroup = groupService.getById(classGroupReq.getGroupId());
|
|
|
if (Objects.nonNull(classGroup)) {
|
|
|
- studentAttendanceResq.setSubjectName(subjectService.getSubjectNameList(classGroup.getSubjectIdList()));
|
|
|
- list.add(studentAttendanceResq);
|
|
|
+ studentAttendanceResp.setSubjectName(subjectService.getSubjectNameList(classGroup.getSubjectIdList()));
|
|
|
+ list.add(studentAttendanceResp);
|
|
|
}
|
|
|
});
|
|
|
pageResult.setRecords(list);
|
|
|
return PageResponse.success(pageResult);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResponse getPageByCourse(CourseScheduleReq courseScheduleReq) {
|
|
|
+ if (Objects.isNull(courseScheduleReq.getCourseScheduleId())) {
|
|
|
+ return PageResponse.errorParam();
|
|
|
+ }
|
|
|
+ Page<StudentAttendanceResp> pageResult = new Page<>();
|
|
|
+ Page<StudentAttendance> studentAttendancePage = new Page<>(courseScheduleReq.getPageNo(), courseScheduleReq.getPageSize());
|
|
|
+ QueryWrapper<StudentAttendance> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(true, StudentAttendance::getCourseScheduleId, courseScheduleReq.getCourseScheduleId());
|
|
|
+ IPage<StudentAttendance> page = page(studentAttendancePage, queryWrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(page.getRecords())) {
|
|
|
+ List<StudentAttendanceResp> list = Lists.newArrayList();
|
|
|
+ page.getRecords().forEach(item -> {
|
|
|
+ StudentAttendanceResp studentAttendanceResp = new StudentAttendanceResp();
|
|
|
+ if (Objects.nonNull(item.getUserId())) {
|
|
|
+ SysUser user = userService.getById(item.getUserId());
|
|
|
+ if (Objects.nonNull(user) && StringUtils.isNotBlank(user.getRealName())) {
|
|
|
+ studentAttendanceResp.setStudentName(user.getRealName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(item.getStatus())) {
|
|
|
+ studentAttendanceResp.setStatus(StudentAttendanceStatusEnum.getMsgByCode(item.getStatus()));
|
|
|
+ }
|
|
|
+ list.add(studentAttendanceResp);
|
|
|
+ });
|
|
|
+ pageResult.setRecords(list);
|
|
|
+ }
|
|
|
+ return PageResponse.success(pageResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResponse statisticsList(CourseScheduleReq courseScheduleReq) {
|
|
|
+ if (Objects.isNull(courseScheduleReq.getCourseScheduleId())) {
|
|
|
+ PageResponse.errorParam();
|
|
|
+ }
|
|
|
+ Page<ClassGroupStudentMapper> classGroupStudentMapperPage = new Page<>(courseScheduleReq.getPageNo(), courseScheduleReq.getPageSize());
|
|
|
+ Page<StudentAttendanceStatisticsResp> pageResult = new Page();
|
|
|
+ CourseSchedule courseSchedule = courseScheduleService.getById(courseScheduleReq.getCourseScheduleId());
|
|
|
+ if (Objects.nonNull(courseSchedule)) {
|
|
|
+ ClassGroup classGroup = groupService.getById(courseSchedule.getClassGroupId());
|
|
|
+ if (Objects.nonNull(classGroup)) {
|
|
|
+ List<String> subjectNameList = subjectService.getSubjectNameList(classGroup.getSubjectIdList());
|
|
|
+ QueryWrapper<ClassGroupStudentMapper> classGroupStudentMapperQueryWrapper = new QueryWrapper<>();
|
|
|
+ classGroupStudentMapperQueryWrapper.lambda().eq(true, ClassGroupStudentMapper::getClassGroupId, classGroup.getId())
|
|
|
+ .in(true, ClassGroupStudentMapper::getStatus,
|
|
|
+ ClassGroupStudentStatusEnum.NORMAL.getCode(), ClassGroupStudentStatusEnum.LEAVE.getCode());
|
|
|
+ IPage<ClassGroupStudentMapper> studentMapperPage = classGroupStudentMapperService.page(classGroupStudentMapperPage, classGroupStudentMapperQueryWrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(studentMapperPage.getRecords())) {
|
|
|
+ List<StudentAttendanceStatisticsResp> studentAttendanceStatisticsRespList = Lists.newArrayList();
|
|
|
+ BeanUtils.copyProperties(studentMapperPage, pageResult);
|
|
|
+ studentMapperPage.getRecords().forEach(item -> {
|
|
|
+ StudentAttendanceStatisticsResp resp = new StudentAttendanceStatisticsResp();
|
|
|
+ SysUser user = userService.getById(item.getUserId());
|
|
|
+ if (Objects.nonNull(user) && StringUtils.isNotBlank(user.getRealName())) {
|
|
|
+ resp.setStudentName(user.getRealName());
|
|
|
+ }
|
|
|
+ resp.setSubjectName(subjectNameList);
|
|
|
+ //TODO 暂时缺少是否连续旷课
|
|
|
+ //到课天数
|
|
|
+ QueryWrapper<StudentAttendance> normalWrapper = new QueryWrapper<>();
|
|
|
+ normalWrapper.lambda().eq(true, StudentAttendance::getCourseScheduleId, courseScheduleReq.getCourseScheduleId())
|
|
|
+ .eq(true, StudentAttendance::getUserId, item.getUserId())
|
|
|
+ .eq(true, StudentAttendance::getStatus, StudentAttendanceStatusEnum.NORMAL.getCode());
|
|
|
+ int normalDay = count(normalWrapper);
|
|
|
+ //旷课天数
|
|
|
+ QueryWrapper<StudentAttendance> truantWrapper = new QueryWrapper<>();
|
|
|
+ truantWrapper.lambda().eq(true, StudentAttendance::getCourseScheduleId, courseScheduleReq.getCourseScheduleId())
|
|
|
+ .eq(true, StudentAttendance::getUserId, item.getUserId())
|
|
|
+ .eq(true, StudentAttendance::getStatus, StudentAttendanceStatusEnum.TRUANT.getCode());
|
|
|
+ int truantDay = count(truantWrapper);
|
|
|
+ //请假天数
|
|
|
+ QueryWrapper<StudentAttendance> leaveWrapper = new QueryWrapper<>();
|
|
|
+ leaveWrapper.lambda().eq(true, StudentAttendance::getCourseScheduleId, courseScheduleReq.getCourseScheduleId())
|
|
|
+ .eq(true, StudentAttendance::getUserId, item.getUserId())
|
|
|
+ .eq(true, StudentAttendance::getStatus, StudentAttendanceStatusEnum.LEAVE.getCode());
|
|
|
+ int leaveDay = count(leaveWrapper);
|
|
|
+ resp.setNormalDay(normalDay);
|
|
|
+ resp.setTruantDay(truantDay);
|
|
|
+ resp.setLeaveDay(leaveDay);
|
|
|
+ //每个学生的考勤明细
|
|
|
+ QueryWrapper<StudentAttendance> studentAttendanceQueryWrapper = new QueryWrapper<>();
|
|
|
+ studentAttendanceQueryWrapper.lambda().eq(true, StudentAttendance::getCourseScheduleId, courseScheduleReq.getCourseScheduleId())
|
|
|
+ .eq(true, StudentAttendance::getUserId, item.getUserId());
|
|
|
+ List<StudentAttendance> studentAttendanceList = list(studentAttendanceQueryWrapper);
|
|
|
+ List<StudentAttendanceResp> studentAttendanceRespList = Lists.newArrayList();
|
|
|
+ if (!CollectionUtils.isEmpty(studentAttendanceList)) {
|
|
|
+ studentAttendanceList.forEach(studentAttendance -> {
|
|
|
+ StudentAttendanceResp studentAttendanceResp = new StudentAttendanceResp();
|
|
|
+ if (Objects.nonNull(studentAttendance.getCreateTime())) {
|
|
|
+ studentAttendanceResp.setClassDate(DateUtil.date2String(studentAttendance.getCreateTime(),
|
|
|
+ DateUtil.DATE_FORMAT)).setClassWeek(DateUtil.date2Week(studentAttendance.getCreateTime()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(studentAttendance.getStatus())) {
|
|
|
+ studentAttendanceResp.setStatus(StudentAttendanceStatusEnum.getMsgByCode(studentAttendance.getStatus()));
|
|
|
+ }
|
|
|
+ studentAttendanceRespList.add(studentAttendanceResp);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ resp.setList(studentAttendanceRespList);
|
|
|
+ studentAttendanceStatisticsRespList.add(resp);
|
|
|
+ });
|
|
|
+ pageResult.setRecords(studentAttendanceStatisticsRespList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageResponse.success(pageResult);
|
|
|
+ }
|
|
|
}
|