|
@@ -1,8 +1,11 @@
|
|
|
package cn.com.qmth.mps.service.impl;
|
|
|
|
|
|
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;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -13,7 +16,10 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.signature.SignatureEntity;
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
@@ -25,8 +31,15 @@ import cn.com.qmth.mps.entity.SchoolEntity;
|
|
|
import cn.com.qmth.mps.enums.ExamStatus;
|
|
|
import cn.com.qmth.mps.enums.Role;
|
|
|
import cn.com.qmth.mps.service.ExamService;
|
|
|
+import cn.com.qmth.mps.service.PaperService;
|
|
|
import cn.com.qmth.mps.service.SchoolService;
|
|
|
+import cn.com.qmth.mps.util.BatchSetDataUtil;
|
|
|
import cn.com.qmth.mps.util.HttpUtil;
|
|
|
+import cn.com.qmth.mps.util.PageUtil;
|
|
|
+import cn.com.qmth.mps.vo.exam.ExamDomain;
|
|
|
+import cn.com.qmth.mps.vo.exam.ExamPaperCountVo;
|
|
|
+import cn.com.qmth.mps.vo.exam.ExamQuery;
|
|
|
+import cn.com.qmth.mps.vo.exam.ExamVo;
|
|
|
|
|
|
@Service
|
|
|
public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements ExamService {
|
|
@@ -34,6 +47,9 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
|
|
|
private String markingcloudServer;
|
|
|
@Autowired
|
|
|
private SchoolService schoolService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PaperService paperService;
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
@@ -89,4 +105,108 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
|
|
|
return this.getOne(wrapper);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void saveExam(ExamDomain domain, User user) {
|
|
|
+ if (domain.getSchoolId() == null) {
|
|
|
+ throw new StatusException("学校不能为空");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(domain.getSchoolId())) {
|
|
|
+ throw new StatusException("非法操作");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(domain.getName())) {
|
|
|
+ throw new StatusException("考试名称不能为空");
|
|
|
+ }
|
|
|
+ if (domain.getExamStatus()==null) {
|
|
|
+ throw new StatusException("状态不能为空");
|
|
|
+ }
|
|
|
+ ExamEntity ue = null;
|
|
|
+ if (domain.getId() != null) {
|
|
|
+ ue = this.getById(domain.getId());
|
|
|
+ if (ue == null) {
|
|
|
+ throw new StatusException("未找到考试");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ue = new ExamEntity();
|
|
|
+ ue.setSchoolId(user.getSchoolId());
|
|
|
+ }
|
|
|
+ ue.setExamStatus(domain.getExamStatus());
|
|
|
+ ue.setName(domain.getName());
|
|
|
+ this.saveOrUpdate(ue);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<ExamVo> page(ExamQuery 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<ExamVo> iPage = this.baseMapper.page(new Page<ExamVo>(query.getPageNumber(), query.getPageSize()), query);
|
|
|
+ if(CollectionUtils.isNotEmpty(iPage.getRecords())) {
|
|
|
+ new BatchSetDataUtil<ExamVo>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void setData(List<ExamVo> dataList) {
|
|
|
+ List<Long> examIds = dataList.stream().map(dto -> dto.getId()).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ExamPaperCountVo> ret = paperService.findPaperCount(examIds);
|
|
|
+ if (ret != null && ret.size() > 0) {
|
|
|
+ Map<Long, Integer> countMap = new HashMap<>();
|
|
|
+ for (ExamPaperCountVo item : ret) {
|
|
|
+ countMap.put(item.getExamId(), item.getPaperCount());
|
|
|
+ }
|
|
|
+ for (ExamVo vo : dataList) {
|
|
|
+ vo.setPaperCount(countMap.get(vo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.setDataForBatch(iPage.getRecords(), 20);
|
|
|
+ }
|
|
|
+ return PageUtil.of(iPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamVo> unClose(User user) {
|
|
|
+ List<ExamVo> ret=this.baseMapper.unClose(user.getSchoolId());
|
|
|
+ if(CollectionUtils.isNotEmpty(ret)) {
|
|
|
+ new BatchSetDataUtil<ExamVo>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void setData(List<ExamVo> dataList) {
|
|
|
+ List<Long> examIds = dataList.stream().map(dto -> dto.getId()).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ExamPaperCountVo> ret = paperService.findPaperCount(examIds);
|
|
|
+ if (ret != null && ret.size() > 0) {
|
|
|
+ Map<Long, Integer> countMap = new HashMap<>();
|
|
|
+ for (ExamPaperCountVo item : ret) {
|
|
|
+ countMap.put(item.getExamId(), item.getPaperCount());
|
|
|
+ }
|
|
|
+ for (ExamVo vo : dataList) {
|
|
|
+ vo.setPaperCount(countMap.get(vo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.setDataForBatch(ret, 20);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExamVo info(Long id, User accessUser) {
|
|
|
+ ExamEntity ue = this.getById(id);
|
|
|
+ if (ue == null) {
|
|
|
+ throw new StatusException("未找到考试信息");
|
|
|
+ }
|
|
|
+ ExamVo vo = new ExamVo();
|
|
|
+ vo.setId(ue.getId());
|
|
|
+ vo.setName(ue.getName());
|
|
|
+ vo.setSchoolId(ue.getSchoolId());
|
|
|
+ vo.setCode(ue.getCode());
|
|
|
+ vo.setExamStatus(ue.getExamStatus());
|
|
|
+ vo.setPaperCount(paperService.findPaperCount(ue.getId()));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|