c81a246a 康伟

kangwei : 在线考试接口:修改计算成绩,我的考试列表,考试记录

1 个父辈 3021dd21
正在显示 20 个修改的文件 包含 295 行增加72 行删除
......@@ -142,7 +142,13 @@ public class QuestionController {
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
try {
questionService.removeById(id);
boolean isUse = questionService.checkByPaper(id);
if(isUse){//true被使用
return Result.error("删除失败!试题被试卷使用");
}else{
questionService.removeById(id);
}
} catch (Exception e) {
log.error("删除失败",e.getMessage());
return Result.error("删除失败!");
......
......@@ -7,15 +7,17 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.modules.edu.entity.Paper;
import com.skua.modules.edu.entity.Question;
import com.skua.modules.edu.entity.QuestionOption;
import com.skua.modules.edu.entity.UserPaper;
import com.skua.modules.common.service.ICommonSqlService;
import com.skua.modules.edu.entity.*;
import com.skua.modules.edu.service.IPaperService;
import com.skua.modules.edu.service.IUserPaperService;
import com.skua.modules.edu.vo.PaperVO;
import com.skua.modules.edu.vo.UserPaperVO;
import com.skua.modules.equipment.pojo.Equipment;
import com.skua.modules.equipment.util.EquipmentUtils;
import com.skua.modules.equipment.vo.EquipmentVO;
import com.skua.modules.guest.util.DateUtil;
import com.skua.tool.util.JoinSqlUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
......@@ -34,6 +36,8 @@ import java.io.IOException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Slf4j
@Api(tags="在线考试-用户考试")
......@@ -46,28 +50,53 @@ public class UserPaperController {
@Autowired
private IUserPaperService userPaperService;
// 我的 考试
@AutoLog(value = "在线考试--试卷列表")
@ApiOperation(value="在线考试--试卷列表", notes="在线考试--试卷列表")
@GetMapping(value = "/paperList")
public Result<IPage<Paper>> queryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
public Result<IPage<Paper>> queryPageList(Paper paper,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
HttpServletRequest req) throws Exception{
Result<IPage<Paper>> result = new Result<IPage<Paper>>();
QueryWrapper<Paper> queryWrapper = new QueryWrapper<>() ;// QueryGenerator.initQueryWrapper(paperAnswer, req.getParameterMap());
//QueryWrapper<Paper> queryWrapper = new QueryWrapper<>() ;// QueryGenerator.initQueryWrapper(paperAnswer, req.getParameterMap());
Page<Paper> page = new Page<Paper>(pageNo, pageSize);
queryWrapper.like("exam_user_ids", BaseContextHandler.getUserId());
/* queryWrapper.like("exam_user_ids", BaseContextHandler.getUserId());
queryWrapper.eq("send_status","1");//已发布的状态
String currentDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss");
queryWrapper.le("start_time",currentDate);// 当前时间 > 开始结束时间
queryWrapper.ge("end_time",currentDate);
IPage<Paper> pageList = paperService.page(page, queryWrapper);
IPage<Paper> pageList = paperService.page(page, queryWrapper);*/
paper.setUserId(BaseContextHandler.getUserId());
paper.setStartTime(DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
paper.setEndTime( DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss") );
IPage<Paper> pageList = paperService.queryMyPaperByList(page ,paper);
result.setSuccess(true);
result.setResult(pageList);
return result;
/* String currentDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss");
StringBuffer sql = new StringBuffer();
sql.append("select aaa.* from ( ");
sql.append(" select ifnull(up.user_id ,0) 'user_id', ifnull(count(up.id) ,0) as user_count, d.depart_name , p.* from edu_paper p ");
sql.append(" left join edu_user_paper up on p.id = up.paper_id ");
sql.append(" left join sys_depart d on p.depart_id = d.id");
sql.append(" where p.send_status =1 and p.exam_user_ids like '%"+BaseContextHandler.getUserId()+"%'");
if( paper.getDepartId() != null && paper.getDepartId().length() > 0){
sql.append(" and p.depart_id= '"+paper.getDepartId()+"' ");
}
if( paper.getPaperTitle() != null && paper.getPaperTitle().length() > 0){
sql.append(" and p.paper_title like '%"+paper.getPaperTitle()+"%' ");
}
if( paper.getDepartId() != null && paper.getDepartId().length() > 0){
sql.append(" and p.depart_id= '"+paper.getDepartId()+"' ");
}
sql.append(" and p.send_time >= '"+currentDate+"' and and p.send_time <= '"+currentDate+"'");
sql.append(" )aaa where aaa.user_id = 0 ");
// 分页查询
Page<Map<String, Object>> pageList = iCommonSqlService.queryForPage(page, sql.toString());
List<Paper> paperList = JoinSqlUtils.multiMaps2Beans(pageList.getRecords(), Paper.class);
//List<Paper> paperList = EquipmentUtils.equipEntities2VOs(dataList);
*/
}
// 根据试卷获取试题
......@@ -76,20 +105,21 @@ public class UserPaperController {
@GetMapping(value = "/startExam")
public Result<PaperVO> startExam(@RequestParam(name="id",required=true) String id) {
Result<PaperVO> result = new Result<PaperVO>();
Boolean flag = paperService.checkExamCount(id,BaseContextHandler.getUserId());
PaperVO paperVO = paperService.queryById(id);
if(paperVO == null) {
result.error500("未找到对应实体");
}else if( paperVO!= null && !"1".equals(paperVO.getSendStatus() ) ) {
result.error500("试卷未发布!");
}else{
result.setResult(paperVO);
result.setSuccess(true);
}
/* Boolean flag = paperService.checkExamCount(id,BaseContextHandler.getUserId());
if(flag){
PaperVO paperVO = paperService.queryById(id);
if(paperVO == null) {
result.error500("未找到对应实体");
}else if( paperVO!= null && !"1".equals(paperVO.getSendStatus() ) ) {
result.error500("试卷未发布!");
}else{
result.setResult(paperVO);
result.setSuccess(true);
}
}else{
result.error500("考试次数已用完!不能参加考试");
}
}*/
return result;
}
// 在线答题
......@@ -103,10 +133,13 @@ public class UserPaperController {
Result<UserPaperVO> result = new Result<UserPaperVO>();
String paperScore = "0";
try {
userPaperVO.setEndTime(DateUtil.getCurrentDate());
userPaperVO.setEndTime(DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
userPaperVO.setUserId(BaseContextHandler.getUserId());//考试人编号
paperScore = paperService.submitPaper(userPaperVO);
userPaperVO.setScore( paperScore );
//计算排名
userPaperService.changeRankByPaperId(userPaperVO.getPaperId() ) ;
result.setResult( userPaperVO );
result.success("交卷成功!");
} catch (Exception e) {
......@@ -127,24 +160,29 @@ public class UserPaperController {
@AutoLog(value = "在线考试--历史试卷列表")
@ApiOperation(value="在线考试--历史试卷列表", notes="在线考试--历史试卷列表")
@GetMapping(value = "/historyList")
public Result<IPage<UserPaper>> historyList(
@RequestParam(name="paperId",required=true) String paperId,
@RequestParam(name="userId") String userId,
public Result<IPage<Paper>> historyList(
Paper paper,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
Result<IPage<UserPaper>> result = new Result<IPage<UserPaper>>();
QueryWrapper<UserPaper> queryWrapper = new QueryWrapper<>() ;// QueryGenerator.initQueryWrapper(paperAnswer, req.getParameterMap());
Page<UserPaper> page = new Page<UserPaper>(pageNo, pageSize);
queryWrapper.eq("paper_id",paperId);
if(userId == null ){
userId = BaseContextHandler.getUserId();
}
queryWrapper.eq("user_id",userId);//已发布的状态
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) throws Exception {
Result<IPage<Paper>> result = new Result<IPage<Paper>>();
/* StringBuffer sql = new StringBuffer();
sql.append("select up.score, p.* from edu_user_paper up ");
sql.append(" left join edu_paper p on p.id = up.paper_id ");
sql.append(" where up.user_id = '"+BaseContextHandler.getUserId()+"' ");
// 分页查询
Page page = new Page(pageNo, pageSize);
Page<Map<String, Object>> pageList = iCommonSqlService.queryForPage(page, sql.toString());
List<Paper> paperList = JoinSqlUtils.multiMaps2Beans(pageList.getRecords(), Paper.class);
*/
IPage<UserPaper> pageList = userPaperService.page(page, queryWrapper);
Page<Paper> page = new Page<Paper>(pageNo, pageSize);
paper.setUserId(BaseContextHandler.getUserId());//获取当前用户编号
IPage<Paper> paperList = paperService.queryMyPaperRecoredByList(page,paper);
result.setResult(paperList);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
//历史试卷详情 history_detail
......@@ -214,7 +252,7 @@ public class UserPaperController {
paragraphOption = document.createParagraph();
setHight( paragraphOption , "500" );
optionRun = paragraphOption.createRun();
optionRun.setText(" "+option.getAlias()+"."+ option.getOptionTitle());
optionRun.setText(" "+option.getAlias()+". "+ option.getOptionTitle());
}
}
index++;
......
......@@ -127,4 +127,26 @@ public class Paper {
@ApiModelProperty(value = "delFlag")
private Integer delFlag;
@TableField(exist=false)
@ApiModelProperty(value = "考试人次")
private Integer userCount ;
@TableField(exist=false)
@ApiModelProperty(value = "扩展:考试人员")
private String userId;
@TableField(exist=false)
@ApiModelProperty(value = "扩展:考试分数")
private String score;
@TableField(exist=false)
@ApiModelProperty(value = "扩展:考试名次")
private String rank;
@TableField(exist=false)
@ApiModelProperty(value = "扩展:用户考试试卷编号")
private String userPaperId;
}
......
......@@ -2,6 +2,8 @@ package com.skua.modules.edu.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import com.skua.modules.edu.entity.Paper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
......@@ -10,5 +12,20 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* 在线考试-试卷
*/
public interface PaperMapper extends BaseMapper<Paper> {
/***
* 我的试卷列表
* @param page
* @param paper
* @return
*/
IPage<Paper> queryMyPaperByList(Page<Paper> page, @Param("param") Paper paper);
/***
* 我的试卷记录
* @param page
* @param paper
* @return
*/
IPage<Paper> queryMyPaperRecoredByList(Page<Paper> page, @Param("param") Paper paper);
}
......
......@@ -25,4 +25,10 @@ public interface QuestionMapper extends BaseMapper<Question> {
*/
public List<Question> selectListByPaperIdAndUserId(@Param("paperId") String paperId,@Param("userPaperId") String userPaperId);
/***
* 校验试题是否被试卷使用
* @param questionId
* @return
*/
public int checkByPaper(@Param("questionId")String questionId);
}
......
......@@ -27,4 +27,12 @@ public interface UserPaperMapper extends BaseMapper<UserPaper> {
public UserPaper queryLastOne(String paperId, String userId);
public int queryPaperCount(String paperId, String userId);
/***
* 设置试卷的考试排名
* @param paperId
* @return
*/
public int changeRankByPaperId( @Param("paperId") String paperId);
}
......
......@@ -2,4 +2,38 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.skua.modules.edu.mapper.PaperMapper">
<!-- 我的考试列表 -->
<select id="queryMyPaperByList" resultType="com.skua.modules.edu.entity.Paper">
select aaa.* from (
select d.depart_name , IFNULL(up.user_id,0) 'user_id',
p.* ,( select count(1) from edu_user_paper up where up.paper_id = p.id ) 'user_count'
from edu_paper p
left join sys_depart d on p.depart_id = d.id
left join edu_user_paper up on p.id = up.paper_id and up.user_id = #{param.userId}
where
p.send_status =1
<if test="param.userId != null and param.userId !=''">
and p.exam_user_ids like CONCAT('%',#{param.userId},'%')
</if>
<if test="param.departId != null and param.departId !=''">
and p.depart_id = #{param.departId}
</if>
)aaa where aaa.user_id > 0
<!-- <if test="param.startTime != null and param.startTime !=''">
and p.start_time &lt;= #{param.startTime}
</if>
<if test="param.endTime != null and param.endTime !=''">
and p.end_time &gt;= #{param.endTime}
</if>-->
</select>
<!-- 考试记录-->
<select id="queryMyPaperRecoredByList" resultType="com.skua.modules.edu.entity.Paper">
select up.score, up.rank,up.id as 'user_paper_id', p.* from edu_user_paper up
left join edu_paper p on p.id = up.paper_id
where up.user_id = #{param.userId}
order by up.start_time desc
</select>
</mapper>
\ No newline at end of file
......
......@@ -19,7 +19,9 @@
where pq.paper_id = #{paperId}
</select>
<select id="checkByPaper" resultType="java.lang.Integer">
select count(1) from edu_paper_question where question_id =#{questionId}
</select>
</mapper>
\ No newline at end of file
......
......@@ -4,9 +4,10 @@
<!-- 校对答案,设置试题分值-->
<update id="checkAnswerByUserPaperId" >
update edu_user_answer ua , edu_question q ,edu_paper_question pq
update edu_user_answer ua , edu_question q ,edu_paper_question pq
set ua.score = pq.score
where ua.user_paper_id = #{userPaperId} and ua.question_id = q.id and ua.answer = q.question_answer and pq.question_id = ua.question_id ;
where q.id = ua.question_id and q.id = pq.question_id and ua.paper_id = pq.paper_id
and ua.user_paper_id =#{userPaperId}
</update>
</mapper>
\ No newline at end of file
......
......@@ -9,7 +9,7 @@
<select id="queryLastOne" resultType="com.skua.modules.edu.entity.UserPaper">
select t.* from edu_user_answer t where t.paper_id = #{paperId} and t.user_id = #{userId}
select t.* from edu_user_answer t where t.paper_id = #{paperId} and t.user_id = #{userId} limit 1
</select>
......@@ -17,4 +17,18 @@
select IFNULL(count(1 ),'0') as 'userExamCount' from edu_user_answer where paper_id = #{paperId} and user_id = #{userId}
</select>
<!-- 设置试卷的考试排名-->
<update id="changeRankByPaperId" >
update edu_user_paper up ,(
SELECT
a.user_id ,
( SELECT count( DISTINCT b.score ) + 1 FROM edu_user_paper b WHERE b.score > a.score and b.paper_id = #{paperId} ) sort
FROM
edu_user_paper a
where a.paper_id = #{paperId}
)aaa set up.rank = aaa.sort
where up.paper_id =#{paperId} and up.user_id = aaa.user_id
</update>
</mapper>
\ No newline at end of file
......
package com.skua.modules.edu.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.modules.edu.entity.Paper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.skua.modules.edu.entity.Question;
......@@ -56,4 +58,21 @@ public interface IPaperService extends IService<Paper> {
* @return
*/
public Boolean checkExamCount(String paperId, String userId);
/***
* 我的试卷列表
* @param page
* @param paper
* @return
*/
IPage<Paper> queryMyPaperByList(Page<Paper> page, Paper paper);
/***
* 我的试卷记录
* @param page
* @param paper
* @return
*/
IPage<Paper> queryMyPaperRecoredByList(Page<Paper> page, Paper paper);
}
......
......@@ -29,4 +29,12 @@ public interface IQuestionService extends IService<Question> {
* @return
*/
public Question queryById(String id);
/***
* 校验 试题是否被试卷使用,如果使用返回true,未使用返回false
* @param questionId
* @return
*/
public boolean checkByPaper(String questionId);
}
......
......@@ -2,10 +2,16 @@ package com.skua.modules.edu.service;
import com.skua.modules.edu.entity.UserPaper;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.ibatis.annotations.Param;
/**
* 在线考试
*/
public interface IUserPaperService extends IService<UserPaper> {
/***
* 设置试卷的考试排名
* @param paperId
* @return
*/
public int changeRankByPaperId( String paperId);
}
......
package com.skua.modules.edu.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.skua.core.context.BaseContextHandler;
......@@ -96,17 +98,17 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
PaperVO paperVO = new PaperVO();//
if( paper != null ){
BeanUtils.copyProperties(paper, paperVO);
List<Question> questionList = questionMapper.selectListByPaperId(id);
List<QuestionOption> optionList = null;
if(questionList != null && !questionList.isEmpty()){
// 创建Gson实例
Gson gson = new Gson();
Type questionTypeListType = new TypeToken<List<QuestionOption>>() {}.getType();
for( Question question : questionList){
optionList = gson.fromJson(question.getQuestionData(),questionTypeListType);
question.setOptionList(optionList );
}
}
List<Question> questionList = questionMapper.selectListByPaperId(id);
List<QuestionOption> optionList = null;
if(questionList != null && !questionList.isEmpty()){
// 创建Gson实例
Gson gson = new Gson();
Type questionTypeListType = new TypeToken<List<QuestionOption>>() {}.getType();
for( Question question : questionList){
optionList = gson.fromJson(question.getQuestionData(),questionTypeListType);
question.setOptionList(optionList );
}
}
paperVO.setQuestionList(questionList);
}
return paperVO;
......@@ -159,6 +161,25 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
}
/***
* 我的试卷列表
* @param page
* @param paper
* @return
*/
public IPage<Paper> queryMyPaperByList(Page<Paper> page, Paper paper){
return this.baseMapper.queryMyPaperByList(page,paper) ;
}
/***
* 我的试卷记录
* @param page
* @param paper
* @return
*/
public IPage<Paper> queryMyPaperRecoredByList(Page<Paper> page, Paper paper){
return this.baseMapper.queryMyPaperRecoredByList(page,paper) ;
}
/***
* 交卷
* @param paperVO
*/
......@@ -187,14 +208,10 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
userPaperMapper.updateById( userPaper);
//计算分数
// answer.setScore( totalScore );
// answerMapper.updateById( answer ) ;
// answer.setScore( totalScore );
// answerMapper.updateById( answer ) ;
return totalScore;
}
/* public String queryPaperScore(String paperId,String userId){
}*/
}
......
......@@ -91,4 +91,14 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
return question;
}
/***
* 校验 试题是否被试卷使用
* @param questionId
* @return
*/
public boolean checkByPaper(String questionId){
int count = this.baseMapper.checkByPaper( questionId );
return count > 0?true:false;
}
}
......
......@@ -12,5 +12,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
*/
@Service
public class UserPaperServiceImpl extends ServiceImpl<UserPaperMapper, UserPaper> implements IUserPaperService {
/***
* 设置试卷的考试排名
* @param paperId
* @return
*/
public int changeRankByPaperId( String paperId){
return this.baseMapper.changeRankByPaperId(paperId);
}
}
......
......@@ -28,7 +28,6 @@ public class PaperVO extends Paper {
@ApiModelProperty(value = "试卷试题集合")
private List<Question> questionList;
@ApiModelProperty(value = "参加考试人员")
private String userId;
}
......
......@@ -73,6 +73,20 @@ public class DistributContractController {
return result;
}
@AutoLog(value = "erp分销合同-列表查询")
@ApiOperation(value="erp分销合同-分页列表查询", notes="erp分销合同-分页列表查询")
@GetMapping(value = "/disContractList")
public Result<List<DistributContract>> queryPageList(DistributContract distributContract,
HttpServletRequest req) {
Result<List<DistributContract>> result = new Result<List<DistributContract>>();
QueryWrapper<DistributContract> queryWrapper = QueryGenerator.initQueryWrapper(distributContract, req.getParameterMap());
List<DistributContract> dataList = distributContractService.list(queryWrapper);
result.setSuccess(true);
result.setResult(dataList);
return result;
}
@AutoLog(value = "erp分销合同-添加")
@ApiOperation(value="erp分销合同-添加", notes="erp分销合同-添加")
@PostMapping(value = "/add")
......
......@@ -10,13 +10,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.query.QueryGenerator;
import com.skua.core.service.ISequenceService;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.erp.entity.MaterialAcceptanceForm;
import com.skua.modules.erp.service.IMaterialAcceptanceFormService;
import java.util.Date;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......
......@@ -10,9 +10,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.query.QueryGenerator;
import com.skua.core.service.ISequenceService;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.erp.entity.MaterialIN;
import com.skua.modules.erp.service.IMaterialINService;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!