Browse Source

试卷结构

xiatian 2 years ago
parent
commit
fdd021252d

+ 13 - 13
src/main/java/cn/com/qmth/mps/controller/PaperController.java

@@ -36,51 +36,51 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/paper")
 @Aac(strict = BOOL.FALSE, auth = BOOL.TRUE)
 public class PaperController extends BaseController {
-	
+
 	@Autowired
 	private PaperService paperService;
-	
+
 	@PostMapping("import-course")
 	@ApiOperation(value = "导入科目")
 	public ImportMsg importPaper(@RequestParam Long examId, @RequestParam MultipartFile file) {
-		List<String> failRecords=paperService.importPaper(examId,getAccessUser(),file);
+		List<String> failRecords = paperService.importPaper(examId, getAccessUser(), file);
 		ImportMsg msg = new ImportMsg();
 		msg.setHasError(CollectionUtils.isNotEmpty(failRecords));
 		msg.setErrMsg(failRecords);
 		return msg;
 	}
-	
+
 	@PostMapping("import-struct-subject")
 	@ApiOperation(value = "导入主观题试卷结构")
 	public ImportMsg importSubjectStruct(@RequestParam Long examId, @RequestParam MultipartFile file) {
-		List<String> failRecords=paperService.importPaper(examId,getAccessUser(),file);
+		List<String> failRecords = paperService.importPaper(examId, getAccessUser(), file);
 		ImportMsg msg = new ImportMsg();
 		msg.setHasError(CollectionUtils.isNotEmpty(failRecords));
 		msg.setErrMsg(failRecords);
 		return msg;
 	}
-	
 
 	@ApiOperation(value = "下载科目导入模板")
 	@PostMapping("template-course")
 	public void getImportTemplate() {
 		exportFile("科目导入模板.xlsx", ResouceUtil.getStream("importtemplates/courseImport.xlsx"));
 	}
+
 	@ApiOperation(value = "下载试卷结构导入模板")
 	@PostMapping("template-struct")
 	public void getStructImportTemplate() {
 		exportFile("试卷结构导入模板.xlsx", ResouceUtil.getStream("importtemplates/structImport.xlsx"));
 	}
+
 	@ApiOperation(value = "导出主观题")
 	@PostMapping("export-subjective")
 	public void exportSubjective(PaperQuery query, HttpServletResponse response) {
 	}
-	
 
 	@ApiOperation(value = "获取分页")
 	@RequestMapping(value = "page", method = RequestMethod.POST)
 	public PageResult<PaperVo> page(PaperQuery query) {
-		return null;
+		return paperService.page(query, getAccessUser());
 	}
 
 	@ApiOperation(value = "获取列表")
@@ -106,25 +106,25 @@ public class PaperController extends BaseController {
 	public PaperVo structSubmit(@RequestBody StructDomain domain) {
 		return null;
 	}
-	
+
 	@ApiOperation(value = "试卷结构暂存")
 	@RequestMapping(value = "struct/save ", method = RequestMethod.POST)
 	public PaperVo structSave(@RequestBody StructDomain domain) {
 		return null;
 	}
-	
+
 	@ApiOperation(value = "获取分组列表")
 	@RequestMapping(value = "group/list", method = RequestMethod.POST)
 	public List<GroupVo> groupList(@RequestParam Long paperId) {
 		return null;
 	}
-	
+
 	@ApiOperation(value = "获取分组信息")
 	@RequestMapping(value = "group/info", method = RequestMethod.POST)
-	public GroupVo groupInfo(@RequestParam Long paperId,@RequestParam Integer groupNumber) {
+	public GroupVo groupInfo(@RequestParam Long paperId, @RequestParam Integer groupNumber) {
 		return null;
 	}
-	
+
 	@ApiOperation(value = "保存分组信息")
 	@RequestMapping(value = "group/save", method = RequestMethod.POST)
 	public void groupInfo(@RequestBody PaperGroup domain) {

+ 6 - 0
src/main/java/cn/com/qmth/mps/dao/PaperDao.java

@@ -5,12 +5,18 @@ import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 import cn.com.qmth.mps.entity.PaperEntity;
 import cn.com.qmth.mps.vo.exam.ExamPaperCountVo;
+import cn.com.qmth.mps.vo.paper.PaperQuery;
+import cn.com.qmth.mps.vo.paper.PaperVo;
 
 public interface PaperDao extends BaseMapper<PaperEntity> {
 
 	List<ExamPaperCountVo> findPaperCount(@Param(value = "examIds") List<Long> examIds);
 
+	IPage<PaperVo> page(Page<PaperVo> page,@Param(value = "req") PaperQuery query);
+
 }

+ 14 - 0
src/main/java/cn/com/qmth/mps/dao/PaperGroupDao.java

@@ -0,0 +1,14 @@
+package cn.com.qmth.mps.dao;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import cn.com.qmth.mps.entity.PaperGroupEntity;
+import cn.com.qmth.mps.vo.paper.GroupCountVo;
+
+public interface PaperGroupDao extends BaseMapper<PaperGroupEntity> {
+
+	List<GroupCountVo> findGroupCount(List<Long> paperIds);
+
+}

+ 16 - 0
src/main/java/cn/com/qmth/mps/service/PaperGroupService.java

@@ -0,0 +1,16 @@
+package cn.com.qmth.mps.service;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import cn.com.qmth.mps.entity.PaperGroupEntity;
+import cn.com.qmth.mps.vo.paper.GroupCountVo;
+
+public interface PaperGroupService  extends IService<PaperGroupEntity> {
+
+	List<GroupCountVo> findGroupCount(@Param(value = "paperIds")List<Long> paperIds);
+
+}

+ 5 - 0
src/main/java/cn/com/qmth/mps/service/PaperService.java

@@ -5,10 +5,13 @@ import java.util.List;
 import org.springframework.web.multipart.MultipartFile;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.boot.core.collection.PageResult;
 
 import cn.com.qmth.mps.bean.User;
 import cn.com.qmth.mps.entity.PaperEntity;
 import cn.com.qmth.mps.vo.exam.ExamPaperCountVo;
+import cn.com.qmth.mps.vo.paper.PaperQuery;
+import cn.com.qmth.mps.vo.paper.PaperVo;
 
 public interface PaperService  extends IService<PaperEntity> {
 
@@ -18,4 +21,6 @@ public interface PaperService  extends IService<PaperEntity> {
 
 	Integer findPaperCount(Long examId);
 
+	PageResult<PaperVo> page(PaperQuery query, User accessUser);
+
 }

+ 23 - 0
src/main/java/cn/com/qmth/mps/service/impl/PaperGroupServiceImpl.java

@@ -0,0 +1,23 @@
+package cn.com.qmth.mps.service.impl;
+
+import java.util.List;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import cn.com.qmth.mps.dao.PaperGroupDao;
+import cn.com.qmth.mps.entity.PaperGroupEntity;
+import cn.com.qmth.mps.service.PaperGroupService;
+import cn.com.qmth.mps.vo.paper.GroupCountVo;
+
+@Service
+public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroupEntity> implements PaperGroupService {
+
+	@Override
+	public List<GroupCountVo> findGroupCount(List<Long> paperIds) {
+		return this.baseMapper.findGroupCount(paperIds);
+	}
+
+
+}

+ 47 - 1
src/main/java/cn/com/qmth/mps/service/impl/PaperServiceImpl.java

@@ -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);
+	}
+
 
 
 }

+ 2 - 2
src/main/java/cn/com/qmth/mps/util/AuthorizationCreateUtil.java

@@ -10,10 +10,10 @@ public class AuthorizationCreateUtil {
 
     
     public static void main(String[] args) {
-    	long time = System.currentTimeMillis();
+    	long time = 1660207360840L;
     	String identity="SUPER_ADMIN_1";//登录后user属性
     	String token="ffffffffbb53efadffffffffd5066d0b";//登录后user属性
-    	String url="/api/exam/sync";//请求路径
+    	String url="/api/exam/list";//请求路径
     	String s = SignatureEntity.build(SignatureType.TOKEN, "post", url, time, identity, token);
     	System.out.println("time:"+time);
     	System.out.println("Authorization:"+s);

+ 26 - 0
src/main/java/cn/com/qmth/mps/vo/paper/GroupCountVo.java

@@ -0,0 +1,26 @@
+package cn.com.qmth.mps.vo.paper;
+
+import cn.com.qmth.mps.entity.base.BaseEntity;
+public class GroupCountVo extends BaseEntity{
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -2762342766185496673L;
+	private Long paperId;
+	private Integer groupCount;
+	
+	
+	public Long getPaperId() {
+		return paperId;
+	}
+	public void setPaperId(Long paperId) {
+		this.paperId = paperId;
+	}
+	public Integer getGroupCount() {
+		return groupCount;
+	}
+	public void setGroupCount(Integer groupCount) {
+		this.groupCount = groupCount;
+	}
+	
+}

+ 16 - 0
src/main/java/cn/com/qmth/mps/vo/paper/PaperVo.java

@@ -14,6 +14,8 @@ public class PaperVo extends BaseEntity{
 	private Long schoolId;
 	@ApiModelProperty("考试id")
 	private Long examId;
+	@ApiModelProperty("考试名称")
+	private String examName;
 	@ApiModelProperty("科目id")
 	private Long courseId;
 	@ApiModelProperty("科目代码")
@@ -26,6 +28,8 @@ public class PaperVo extends BaseEntity{
 	private Double subjectiveScore;
 	@ApiModelProperty("分组是否完成")
 	private Boolean groupFinish;
+	@ApiModelProperty("分组数")
+	private Integer groupCount;
 	public Long getId() {
 		return id;
 	}
@@ -81,6 +85,18 @@ public class PaperVo extends BaseEntity{
 	public void setGroupFinish(Boolean groupFinish) {
 		this.groupFinish = groupFinish;
 	}
+	public Integer getGroupCount() {
+		return groupCount;
+	}
+	public void setGroupCount(Integer groupCount) {
+		this.groupCount = groupCount;
+	}
+	public String getExamName() {
+		return examName;
+	}
+	public void setExamName(String examName) {
+		this.examName = examName;
+	}
 
 	
 	

+ 1 - 1
src/main/resources/mapper/ExamMapper.xml

@@ -7,7 +7,7 @@
 		t
 		where
 		t.school_id=#{req.schoolId}
-		<if test="req.name != null and reqname !=''">
+		<if test="req.name != null and req.name !=''">
 			and t.name like concat('%', #{req.name}, '%')
 		</if>
 		order by t.update_time desc

+ 14 - 0
src/main/resources/mapper/PaperGroupMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.qmth.mps.dao.PaperGroupDao">
+
+	<select id="findGroupCount" resultType="cn.com.qmth.mps.vo.paper.GroupCountVo">
+		select t.paper_id,count(1) paperCount from mps_paper_group
+		t
+		where 1=2
+		<foreach collection="paperIds" index="index" item="paperId">
+			or t.paper_id=#{paperId}
+		</foreach>
+		group by t.paper_id
+	</select>
+</mapper>

+ 35 - 2
src/main/resources/mapper/PaperMapper.xml

@@ -2,13 +2,46 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.qmth.mps.dao.PaperDao">
 
-	<select id="findPaperCount" resultType="cn.com.qmth.mps.vo.exam.ExamPaperCountVo">
+	<select id="findPaperCount"
+		resultType="cn.com.qmth.mps.vo.exam.ExamPaperCountVo">
 		select t.exam_id,count(1) paperCount from mps_paper
 		t
 		where 1=2
 		<foreach collection="examIds" index="index" item="examId">
-			or t.exam_id=#{examId}
+			or
+			t.exam_id=#{examId}
 		</foreach>
 		group by t.exam_id
 	</select>
+
+	<select id="page" resultType="cn.com.qmth.mps.vo.paper.PaperVo">
+		select t.*,c.name courseName,c.code courseCode,e.name examName from mps_paper
+		t left join mps_course c on t.course_id=c.id
+		left join mps_exam e on t.exam_id=e.id
+		where
+		t.school_id=#{req.schoolId}
+		<if test="req.examId != null">
+			and t.exam_id =#{req.examId}
+		</if>
+		<if test="req.groupFinish != null">
+			and t.group_finish =#{req.groupFinish}
+		</if>
+		<if test="req.courseCode != null and req.courseCode !=''">
+			and c.code like concat('%', #{req.courseCode}, '%')
+		</if>
+		<if test="req.courseName != null and req.courseName !=''">
+			and c.name like concat('%', #{req.courseName}, '%')
+		</if>
+		<if test="req.name != null and req.name !=''">
+			and t.name like concat('%', #{req.name}, '%')
+		</if>
+		<if test="req.totalScoreMin != null">
+			and t.total_score &gt;=#{req.totalScoreMin}
+		</if>
+		<if test="req.totalScoreMax != null">
+			and t.total_score &lt;=#{req.totalScoreMax}
+		</if>
+		
+		order by t.update_time desc
+	</select>
 </mapper>

+ 1 - 1
src/main/resources/mapper/SchoolMapper.xml

@@ -10,7 +10,7 @@
 		<if test="schoolId != null">
 			and t.id=#{schoolId}
 		</if>
-		<if test="req.name != null and reqname !=''">
+		<if test="req.name != null and req.name !=''">
 			and t.name like concat('%', #{req.name}, '%')
 		</if>
 		order by t.update_time desc

+ 1 - 1
src/main/resources/mapper/UserMapper.xml

@@ -13,7 +13,7 @@
 		<if test="req.loginName != null and req.loginName !=''">
 			and t.login_name like concat('%', #{req.loginName}, '%')
 		</if>
-		<if test="req.name != null and reqname !=''">
+		<if test="req.name != null and req.name !=''">
 			and t.name like concat('%', #{req.name}, '%')
 		</if>
 		order by t.update_time desc