|
@@ -1,23 +1,32 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ClazzContentDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ExamTaskPlanStatisticDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.TCStatisticsDto;
|
|
|
+import com.qmth.distributed.print.business.bean.result.TCStatisticResult;
|
|
|
import com.qmth.distributed.print.business.entity.TCStatistics;
|
|
|
import com.qmth.distributed.print.business.entity.TCStatisticsTemp;
|
|
|
+import com.qmth.distributed.print.business.entity.TeachStudent;
|
|
|
+import com.qmth.distributed.print.business.enums.ClazzContentEnum;
|
|
|
+import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.StatisticsStatusEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.TCStatisticsMapper;
|
|
|
-import com.qmth.distributed.print.business.service.TCStatisticsService;
|
|
|
-import com.qmth.distributed.print.business.service.TCStatisticsTempService;
|
|
|
+import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.entity.BasicStudent;
|
|
|
import com.qmth.teachcloud.common.entity.SysOrg;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.service.BasicStudentService;
|
|
|
import com.qmth.teachcloud.common.service.SysOrgService;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -26,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -50,77 +60,129 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
@Resource
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
|
- /**
|
|
|
- * 查找印刷计划信息
|
|
|
- *
|
|
|
- * @param iPage
|
|
|
- * @param collegeId
|
|
|
- * @param teachingRoomId
|
|
|
- * @param status
|
|
|
- * @param courseName
|
|
|
- * @param teacherName
|
|
|
- * @param schoolId
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
+ @Resource
|
|
|
+ TeachStudentService teachStudentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ BasicStudentService basicStudentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ExamDetailService examDetailService;
|
|
|
+
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
@Override
|
|
|
public IPage<TCStatisticsDto> list(IPage<Map> iPage, Long semesterId, Long examId, Long collegeId, Long teachingRoomId, StatisticsStatusEnum status, String courseName, String teacherName, Long schoolId, Long userId) {
|
|
|
return tcStatisticsMapper.list(iPage, semesterId, examId, collegeId, teachingRoomId, Objects.nonNull(status) ? status.name() : null, courseName, teacherName, schoolId, userId);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 导入关联数据
|
|
|
- *
|
|
|
- * @param sysUser
|
|
|
- * @param batchNo
|
|
|
- */
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void importJoinData(SysUser sysUser, String batchNo) {
|
|
|
- List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsTempService.findByBatchNo(sysUser.getSchoolId(), batchNo);
|
|
|
+ public void importJoinData(List<TCStatisticsTemp> tcStatisticsTempList) {
|
|
|
+ List<TCStatistics> insertTCStatisticsList = new ArrayList<>();
|
|
|
if (Objects.nonNull(tcStatisticsTempList) && tcStatisticsTempList.size() > 0) {
|
|
|
- batchNo = SystemConstant.getUuid();
|
|
|
- Set<Long> orgIds = this.joinDataGetOrgIds(sysUser, batchNo, tcStatisticsTempList);
|
|
|
- List<TCStatisticsDto> tcStatisticsDtoList = this.findByBatchNoCount(sysUser.getSchoolId(), batchNo, orgIds);
|
|
|
- if (Objects.nonNull(tcStatisticsDtoList) && tcStatisticsDtoList.size() > 0) {
|
|
|
- this.saveJoinData(sysUser, tcStatisticsDtoList);
|
|
|
+ Long requestUserId = tcStatisticsTempList.get(0).getCreateId();
|
|
|
+ Long examId = tcStatisticsTempList.get(0).getExamId();
|
|
|
+
|
|
|
+ for (TCStatisticsTemp tcStatisticsTemp : tcStatisticsTempList) {
|
|
|
+ List<ClazzContentDto> clazzContentDtoList = new ArrayList<>();
|
|
|
+ String courseCode = tcStatisticsTemp.getCourseCode();
|
|
|
+ String clazzIds = tcStatisticsTemp.getClazzIds();
|
|
|
+ // 总印份数(只是学生数不包含备份)
|
|
|
+ int printSum;
|
|
|
+ StatisticsStatusEnum status = StatisticsStatusEnum.FINISH;
|
|
|
+ // 导入的班级
|
|
|
+ Set<Long> clazzIdSet = Arrays.stream(clazzIds.split(",")).map(SystemConstant::convertIdToLong).collect(Collectors.toSet());
|
|
|
+ // 根据课程和考试查到的命题计划数据
|
|
|
+ List<ExamTaskPlanStatisticDto> examTaskPlanStatisticDtoList = this.baseMapper.findByExamIdCourseCode(examId,courseCode);
|
|
|
+ for (Long clazzId : clazzIdSet) {
|
|
|
+ // 匹配到班级的所有命题计划
|
|
|
+ List<ExamTaskPlanStatisticDto> matchClazzList = examTaskPlanStatisticDtoList.stream().filter(e -> {
|
|
|
+ Set<Long> ebcClazzIdSet = Arrays.stream(e.getClazzIds().split(",")).map(SystemConstant::convertIdToLong).collect(Collectors.toSet());
|
|
|
+ return ebcClazzIdSet.contains(clazzId);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ ClazzContentDto clazzContent = new ClazzContentDto();
|
|
|
+ clazzContent.setClazzId(clazzId);
|
|
|
+ clazzContent.setClazzName(examDetailService.findClazzNamesByClazzIds(String.valueOf(clazzId), ","));
|
|
|
+ if (matchClazzList.size() > 1) {
|
|
|
+ // 同一个班级课程的命题任务多次提交
|
|
|
+ status = StatisticsStatusEnum.UN_FINISH;
|
|
|
+ clazzContent.setStatus(ClazzContentEnum.EXCEPTION);
|
|
|
+ } else if (matchClazzList.size() == 1) {
|
|
|
+ ExamTaskPlanStatisticDto matchClazz = matchClazzList.get(0);
|
|
|
+ // 查询考场表状态为已印刷的被匹配数据
|
|
|
+ clazzContent.setExamPrintPlanId(matchClazz.getExamPrintPlanId());
|
|
|
+ clazzContent.setExamPrintPlanName(matchClazz.getExamPrintPlanName());
|
|
|
+ clazzContent.setPaperNumber(matchClazz.getPaperNumber());
|
|
|
+ clazzContent.setStudentCount(matchClazz.getStudentCount());
|
|
|
+
|
|
|
+ ExamDetailStatusEnum examDetailStatus = matchClazz.getExamDetailStatus();
|
|
|
+ if (ExamDetailStatusEnum.FINISH.equals(examDetailStatus)) {
|
|
|
+ // 改版机对应的命题任务完成印刷
|
|
|
+ clazzContent.setStatus(ClazzContentEnum.FINISH);
|
|
|
+ } else {
|
|
|
+ // 该班级对应的命题任务还未完成印刷
|
|
|
+ status = StatisticsStatusEnum.UN_FINISH;
|
|
|
+ clazzContent.setStatus(ClazzContentEnum.UN_FINISH);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 连考场都没查到 -> 未完成
|
|
|
+ status = StatisticsStatusEnum.UN_FINISH;
|
|
|
+ clazzContent.setStatus(ClazzContentEnum.UN_FINISH);
|
|
|
+ }
|
|
|
+ clazzContentDtoList.add(clazzContent);
|
|
|
+ }
|
|
|
+ Integer teachClazzStudentCount = teachStudentService.count(new QueryWrapper<TeachStudent>().lambda().in(TeachStudent::getTeachClazzId,clazzIdSet));
|
|
|
+ Integer basicClazzStudentCount = basicStudentService.count(new QueryWrapper<BasicStudent>().lambda().in(BasicStudent::getClazzId,clazzIdSet));
|
|
|
+ printSum = teachClazzStudentCount + basicClazzStudentCount;
|
|
|
+
|
|
|
+ TCStatistics tcStatistics = new TCStatistics();
|
|
|
+ tcStatistics.setExamId(examId);
|
|
|
+ tcStatistics.setBatchNo(tcStatisticsTemp.getBatchNo());
|
|
|
+ tcStatistics.setCollegeId(tcStatisticsTemp.getCollegeId());
|
|
|
+ tcStatistics.setCollegeName(tcStatisticsTemp.getCollegeName());
|
|
|
+ tcStatistics.setTeachingRoomId(tcStatisticsTemp.getTeachingRoomId());
|
|
|
+ tcStatistics.setTeachingRoomName(tcStatisticsTemp.getTeachingRoomName());
|
|
|
+ tcStatistics.setCourseName(tcStatisticsTemp.getCourseName());
|
|
|
+ tcStatistics.setCourseCode(tcStatisticsTemp.getCourseCode());
|
|
|
+ tcStatistics.setTeacherName(tcStatisticsTemp.getTeacherName());
|
|
|
+ tcStatistics.setClazzIds(clazzIds);
|
|
|
+ tcStatistics.setClazzName(examDetailService.findClazzNamesByClazzIds(clazzIds,","));
|
|
|
+ tcStatistics.setClazzContent(JSON.toJSONString(clazzContentDtoList));
|
|
|
+ tcStatistics.setPrintSum(printSum);
|
|
|
+ tcStatistics.setStatus(status);
|
|
|
+ tcStatistics.insertInfo(requestUserId);
|
|
|
+ if (StatisticsStatusEnum.FINISH.equals(status)){
|
|
|
+ ClazzContentDto cell = clazzContentDtoList.get(0);
|
|
|
+ tcStatistics.setPrintPlanId(cell.getExamPrintPlanId());
|
|
|
+ tcStatistics.setPaperNumber(cell.getPaperNumber());
|
|
|
+ }
|
|
|
+ insertTCStatisticsList.add(tcStatistics);
|
|
|
}
|
|
|
}
|
|
|
+ this.saveBatch(insertTCStatisticsList);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除导入数据
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @param courseSet
|
|
|
- * @param setCollections
|
|
|
- */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void removeImportData(Long userId, Set<String> courseSet, Set<Long>... setCollections) {
|
|
|
+ public void removeImportData(Long examId, Long userId) {
|
|
|
TCStatisticsService tcStatisticsService = SpringContextHolder.getBean(TCStatisticsService.class);
|
|
|
QueryWrapper<TCStatistics> tcStatisticsQueryWrapper = new QueryWrapper<>();
|
|
|
- tcStatisticsQueryWrapper.lambda().in(TCStatistics::getCollegeId, setCollections[0])
|
|
|
- .in(TCStatistics::getTeachingRoomId, setCollections[1])
|
|
|
- .in(TCStatistics::getCourseCode, courseSet)
|
|
|
- .in(TCStatistics::getClazzId, setCollections[2])
|
|
|
+ tcStatisticsQueryWrapper.lambda()
|
|
|
+ .eq(TCStatistics::getExamId, examId)
|
|
|
.eq(TCStatistics::getCreateId, userId);
|
|
|
tcStatisticsService.remove(tcStatisticsQueryWrapper);
|
|
|
|
|
|
QueryWrapper<TCStatisticsTemp> tcStatisticsTempQueryWrapper = new QueryWrapper<>();
|
|
|
- tcStatisticsTempQueryWrapper.lambda().in(TCStatisticsTemp::getCollegeId, setCollections[0])
|
|
|
- .in(TCStatisticsTemp::getTeachingRoomId, setCollections[1])
|
|
|
- .in(TCStatisticsTemp::getCourseCode, courseSet)
|
|
|
- .in(TCStatisticsTemp::getClazzId, setCollections[2])
|
|
|
+ tcStatisticsTempQueryWrapper.lambda()
|
|
|
+ .eq(TCStatisticsTemp::getExamId, examId)
|
|
|
.eq(TCStatisticsTemp::getCreateId, userId);
|
|
|
tcStatisticsTempService.remove(tcStatisticsTempQueryWrapper);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 刷新数据
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Result freshenData() {
|
|
@@ -150,12 +212,6 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
return ResultUtil.ok(true);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除数据
|
|
|
- *
|
|
|
- * @param ids
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Result deleteData(List<Long> ids) {
|
|
@@ -164,6 +220,50 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
return ResultUtil.ok(true);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public IPage<TCStatisticResult> findExamTaskPrintStatistic(Long semesterId, Long examId, Long collegeId, Long teachingRoomId, StatisticsStatusEnum status, String courseName, String teacherName, Long schoolId, Long userId, Integer pageNumber, Integer pageSize) {
|
|
|
+ return tcStatisticsMapper.findExamTaskPrintStatistic(new Page<>(pageNumber,pageSize), examId, collegeId, teachingRoomId, status, courseName, teacherName, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void refreshTCStatisticByExamIdAndRequestUser(Long examId, SysUser requestUser) {
|
|
|
+ Long requestUserId = requestUser.getId();
|
|
|
+ List<TCStatistics> tcStatisticsList = this.list(new QueryWrapper<TCStatistics>().lambda().eq(TCStatistics::getExamId,examId).eq(TCStatistics::getCreateId,requestUserId));
|
|
|
+ if (tcStatisticsList != null && tcStatisticsList.size() > 0){
|
|
|
+ String key = SystemConstant.REDIS_LOCK_BATCH_NO_PREFIX + Math.abs((examId + String.valueOf(requestUserId)).hashCode());
|
|
|
+ boolean lock = redisUtil.lock(key, SystemConstant.REDIS_LOCK_BATCH_NO_TIME_OUT);
|
|
|
+ if (!lock){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("正在刷新数据,请稍候再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 删除该用户现在的本次考试的统计数据
|
|
|
+ this.removeImportData(examId,requestUserId);
|
|
|
+ List<TCStatisticsTemp> tcStatisticsTempList = tcStatisticsList.stream().flatMap(e ->{
|
|
|
+ TCStatisticsTemp tcStatisticsTemp = new TCStatisticsTemp(
|
|
|
+ examId,
|
|
|
+ e.getCollegeId(),
|
|
|
+ e.getCollegeName(),
|
|
|
+ e.getTeachingRoomId(),
|
|
|
+ e.getTeachingRoomName(),
|
|
|
+ e.getCourseName(),
|
|
|
+ e.getCourseCode(),
|
|
|
+ e.getTeacherName(),
|
|
|
+ e.getClazzIds(),
|
|
|
+ e.getClazzName(),
|
|
|
+ e.getBatchNo(),
|
|
|
+ requestUserId);
|
|
|
+ return Stream.of(tcStatisticsTemp);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ this.importJoinData(tcStatisticsTempList);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 关联数据获取orgIds
|
|
|
*
|
|
@@ -205,7 +305,7 @@ public class TCStatisticsServiceImpl extends ServiceImpl<TCStatisticsMapper, TCS
|
|
|
t.getCourseCode() + ":" +
|
|
|
t.getPaperNumber() + ":" +
|
|
|
t.getPrintPlanId() + ":" +
|
|
|
- t.getClazzId();
|
|
|
+ t.getClazzIds();
|
|
|
if (!map.containsKey(key)) {
|
|
|
map.computeIfAbsent(key, v -> t);
|
|
|
} else {
|