|
@@ -3,7 +3,10 @@ package cn.com.qmth.mps.service.impl;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -16,7 +19,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
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.qmth.boot.core.collection.PageResult;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
@@ -30,8 +36,14 @@ import cn.com.qmth.mps.entity.PaperEntity;
|
|
|
import cn.com.qmth.mps.enums.Role;
|
|
|
import cn.com.qmth.mps.service.CourseService;
|
|
|
import cn.com.qmth.mps.service.ExamService;
|
|
|
+import cn.com.qmth.mps.service.PaperGroupService;
|
|
|
import cn.com.qmth.mps.service.PaperService;
|
|
|
+import cn.com.qmth.mps.util.BatchSetDataUtil;
|
|
|
+import cn.com.qmth.mps.util.PageUtil;
|
|
|
import cn.com.qmth.mps.vo.exam.ExamPaperCountVo;
|
|
|
+import cn.com.qmth.mps.vo.paper.GroupCountVo;
|
|
|
+import cn.com.qmth.mps.vo.paper.PaperQuery;
|
|
|
+import cn.com.qmth.mps.vo.paper.PaperVo;
|
|
|
|
|
|
@Service
|
|
|
public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> implements PaperService {
|
|
@@ -41,7 +53,9 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
|
|
|
@Autowired
|
|
|
private CourseService courseService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private PaperGroupService paperGroupService;
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public List<String> importPaper(Long examId, User user, MultipartFile file) {
|
|
@@ -156,6 +170,38 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
return this.count(wrapper);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public PageResult<PaperVo> page(PaperQuery query, User user) {
|
|
|
+ if (query.getSchoolId() == null) {
|
|
|
+ throw new StatusException("学校不能为空");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
|
|
|
+ throw new StatusException("非法操作");
|
|
|
+ }
|
|
|
+ IPage<PaperVo> iPage = this.baseMapper.page(new Page<PaperVo>(query.getPageNumber(), query.getPageSize()), query);
|
|
|
+ if(CollectionUtils.isNotEmpty(iPage.getRecords())) {
|
|
|
+ new BatchSetDataUtil<PaperVo>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void setData(List<PaperVo> dataList) {
|
|
|
+ List<Long> paperIds = dataList.stream().map(dto -> dto.getId()).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
|
|
|
+ if (ret != null && ret.size() > 0) {
|
|
|
+ Map<Long, Integer> countMap = new HashMap<>();
|
|
|
+ for (GroupCountVo item : ret) {
|
|
|
+ countMap.put(item.getPaperId(), item.getGroupCount());
|
|
|
+ }
|
|
|
+ for (PaperVo vo : dataList) {
|
|
|
+ vo.setGroupCount(countMap.get(vo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.setDataForBatch(iPage.getRecords(), 20);
|
|
|
+ }
|
|
|
+ return PageUtil.of(iPage);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|