答题提交处理

pull/1/head
huan.xu 5 years ago
parent 9e6f60dca8
commit d286a3b57c
  1. 23
      blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/YyyfUserDto.java
  2. 32
      blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/util/YyyfUserDtoUtils.java
  3. 14
      blockchain-server/blockchain-server-user/src/main/java/com/blockchain/server/user/controller/LoginController.java
  4. 2
      blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml
  5. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java
  6. 87
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java
  7. 106
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java
  8. 5
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java
  9. 16
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/AssessUserTargetDto.java
  10. 10
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java
  11. 16
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUserTarget.java
  12. 1
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java
  13. 2
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java
  14. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java
  15. 3
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java
  16. 26
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserTargetService.java
  17. 28
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java
  18. 29
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserTargetServiceImpl.java
  19. 6
      blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml
  20. 32
      blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml

@ -16,23 +16,22 @@ import java.util.Map;
@Data @Data
public class YyyfUserDto implements Serializable { public class YyyfUserDto implements Serializable {
private static final long serialVersionUID = -6752296227958588252L; private static final long serialVersionUID = -6752296227958588252L;
/**传过来的用户id*/ /**
* 传过来的用户id
*/
private Integer userId; private Integer userId;
/**用户名称*/ /**
* 用户名称
*/
private String userName; private String userName;
/**用户类型:0学生,1老师,2管理员*/
private Integer userType;
/**班级id*/
private Integer classId;
/**学校id,为以后logo修改预留参数*/
private Integer schoolId;
/** /**
* 课程id * 成绩主表id
*/ */
private String courseId; private String assessUserId;
/** /**
* 请求类型0 考试 1 练习 2 不计分 3 教师管理员的案例管理 * 用户类型:0学生1老师2管理员
*/ */
private Integer reqType; private Integer userType;
} }

@ -0,0 +1,32 @@
package com.blockchain.common.base.util;
import com.blockchain.common.base.constant.BaseConstant;
import com.blockchain.common.base.dto.YyyfUserDto;
import org.springframework.data.redis.core.RedisTemplate;
import javax.servlet.http.HttpServletRequest;
/**
* @author huan.xu
* @version 1.0
* @className YyyfUserDto
* @description
* @date 2020-05-14 14:09
*/
public class YyyfUserDtoUtils {
/**
* @description 从cookies 获取以渔有方用户信息
* @param [request, redisTemplate]
* @return com.blockchain.common.base.dto.YyyfUserDto
**/
public static YyyfUserDto getYyyfUserDto(HttpServletRequest request, RedisTemplate redisTemplate) {
YyyfUserDto yyyfUserDto = null;
String yyyfTtoken = request.getHeader(BaseConstant.YYYF_TOKEN_HEADER);
//如果有token,拿到用户信息,与以渔有方进行绑定
if (redisTemplate.hasKey(yyyfTtoken)) {
yyyfUserDto = (YyyfUserDto) redisTemplate.opsForValue().get(yyyfTtoken);
}
return yyyfUserDto;
}
}

@ -9,6 +9,7 @@ import com.blockchain.common.base.dto.YyyfUserDto;
import com.blockchain.common.base.util.HttpRequestUtil; import com.blockchain.common.base.util.HttpRequestUtil;
import com.blockchain.common.base.util.RSACoderUtils; import com.blockchain.common.base.util.RSACoderUtils;
import com.blockchain.common.base.util.SSOHelper; import com.blockchain.common.base.util.SSOHelper;
import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.user.common.constants.other.InternationalConstant; import com.blockchain.server.user.common.constants.other.InternationalConstant;
import com.blockchain.server.user.common.enums.SmsCountEnum; import com.blockchain.server.user.common.enums.SmsCountEnum;
import com.blockchain.server.user.common.enums.UserEnums; import com.blockchain.server.user.common.enums.UserEnums;
@ -317,22 +318,20 @@ public class LoginController {
} }
/** /**
* @description 处理yyyf账号绑定
* @param [userId, tel, request] * @param [userId, tel, request]
* @return java.lang.String * @return java.lang.String
* @description 处理yyyf账号绑定
**/ **/
private Integer dealBindYyyfAccount(String userId, String tel, HttpServletRequest request) { private Integer dealBindYyyfAccount(String userId, String tel, HttpServletRequest request) {
Integer yyyfUserId = null; Integer yyyfUserId = null;
String yyyfTtoken = request.getHeader(BaseConstant.YYYF_TOKEN_HEADER); String yyyfTtoken = request.getHeader(BaseConstant.YYYF_TOKEN_HEADER);
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate);
//如果有token,拿到用户信息,与以渔有方进行绑定 //如果有token,拿到用户信息,与以渔有方进行绑定
if (redisTemplate.hasKey(yyyfTtoken)) { if (yyyfUserDto != null) {
YyyfUserDto yyyfUserDto = (YyyfUserDto) redisTemplate.opsForValue().get(yyyfTtoken); yyyfUserId = yyyfUserDto.getUserId();
yyyfUserId = yyyfUserDto.getId();
YyyfUser yyyfUser = this.yyyfUserService.selectByYyyfUserIdAndTel(yyyfUserId, tel); YyyfUser yyyfUser = this.yyyfUserService.selectByYyyfUserIdAndTel(yyyfUserId, tel);
if (yyyfUser == null) { if (yyyfUser == null) {
this.yyyfUserService.saveUser(yyyfUserId, userId, yyyfUserDto.getName()); this.yyyfUserService.saveUser(yyyfUserId, userId, yyyfUserDto.getUserName());
this.redisTemplate.delete(yyyfTtoken); this.redisTemplate.delete(yyyfTtoken);
} else { } else {
if (!yyyfUser.getUserId().equals(userId)) { if (!yyyfUser.getUserId().equals(userId)) {
@ -342,7 +341,6 @@ public class LoginController {
} else { } else {
throw new UserException(UserEnums.USER_NOT_BIND_YYYF); throw new UserException(UserEnums.USER_NOT_BIND_YYYF);
} }
return yyyfUserId; return yyyfUserId;
} }
} }

@ -1,7 +1,5 @@
server: server:
port: 8101 port: 8101
servlet:
context-path: /user
#注册中心 #注册中心
eureka: eureka:
client: client:

@ -24,7 +24,7 @@ public class TrainCaseTargetDto implements Serializable {
private String name; private String name;
/** /**
* 任务目标运算符1大于2小于3等 * 任务目标运算符-1小于0等于1大
*/ */
private Integer taskOperate; private Integer taskOperate;
/** /**
@ -43,5 +43,5 @@ public class TrainCaseTargetDto implements Serializable {
/** /**
* 指标id * 指标id
*/ */
private String targeId; private String targetId;
} }

@ -5,10 +5,13 @@ import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.common.base.dto.TokenDTO; import com.blockchain.common.base.dto.TokenDTO;
import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.dto.YyyfUserDto;
import com.blockchain.common.base.util.RSACoderUtils; import com.blockchain.common.base.util.RSACoderUtils;
import com.blockchain.server.train.dto.ExamPaperDto;
import com.blockchain.server.train.dto.TrainCaseTargetDto;
import com.blockchain.server.yyyf.controller.api.LoginApi; import com.blockchain.server.yyyf.controller.api.LoginApi;
import com.blockchain.server.yyyf.dto.*; import com.blockchain.server.yyyf.dto.*;
import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUser;
import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.service.AssessUserService;
import com.blockchain.server.yyyf.service.AssessUserTargetService;
import com.blockchain.server.yyyf.utils.IdGenerator; import com.blockchain.server.yyyf.utils.IdGenerator;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -18,7 +21,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -54,43 +56,41 @@ public class LoginController {
//存到redis中用于以渔有方用户与智信链用户进行绑定 //存到redis中用于以渔有方用户与智信链用户进行绑定
YyyfUserDto yyyfUserDto = new YyyfUserDto();
//登录返回的Data //登录返回的Data
YyyfLoginDto yyyfLoginDto = new YyyfLoginDto(); YyyfLoginDto yyyfLoginDto = new YyyfLoginDto();
yyyfLoginDto.setStatus(0); yyyfLoginDto.setStatus(0);
String userName = null; String userName = null;
try { try {
userName = new String(new BASE64Decoder().decodeBuffer(yyyfLoginRequestVo.getUserName().replaceAll(" ", "+")), "UTF-8"); userName = new String(new BASE64Decoder().decodeBuffer(yyyfLoginRequestVo.getUserName().replaceAll(" ", "+")), "UTF-8");
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
//根据案例id,考核id封装相关信息。 //根据案例id,考核id封装相关信息。
//1、从缓存中取案列相关 //1、从缓存中取案列相关
//0 考试 1 练习 2 不计分 3 教师、管理员的案例管理 //0 考试 1 练习 2 不计分 3 教师、管理员的案例管理
int reqType = yyyfLoginRequestVo.getReqType().intValue(); int reqType = yyyfLoginRequestVo.getReqType().intValue();
int userType = yyyfLoginRequestVo.getUserType().intValue();
Integer classId = yyyfLoginRequestVo.getClassId(); Integer classId = yyyfLoginRequestVo.getClassId();
Integer userId = yyyfLoginRequestVo.getUserId(); Integer userId = yyyfLoginRequestVo.getUserId();
Integer schoolId = yyyfLoginRequestVo.getSchoolId();
yyyfUserDto.setClassId(classId);
yyyfUserDto.setUserId(userId);
yyyfUserDto.setUserName(userName);
yyyfUserDto.setSchoolId(schoolId);
yyyfUserDto.setUserType(userType);
yyyfUserDto.setClassId(classId);
yyyfUserDto.setCourseId(yyyfLoginRequestVo.getCourserId());
//以渔有方考核id //以渔有方考核id
String examId = yyyfLoginRequestVo.getReqId(); String examId = yyyfLoginRequestVo.getReqId();
//试卷id(项目id) //试卷id(项目id)
String examPaperId = yyyfLoginRequestVo.getCaseId(); String examPaperId = yyyfLoginRequestVo.getCaseId();
YyyfUserDto yyyfUserDto = new YyyfUserDto();
yyyfUserDto.setUserName(userName);
yyyfUserDto.setUserId(userId);
yyyfUserDto.setUserType(yyyfLoginRequestVo.getUserType());
//做考试和练习 //做考试和练习
if (0 == reqType || 1 == reqType) { if (0 == reqType || 1 == reqType) {
AssessUser assessUser = this.assessUserService.selectAssessUserByUserIdAndissueIdForNotEnd(userId, examId); AssessUser assessUser = this.assessUserService.selectAssessUserByUserIdAndissueIdForNotEnd(userId, examId);
if (assessUser == null) { if (assessUser == null) {
String assessUserId = IdGenerator.uuid();
assessUser = new AssessUser(); assessUser = new AssessUser();
assessUser.setId(IdGenerator.uuid()); assessUser.setId(assessUserId);
assessUser.setAchieveMentType(reqType == 0 ? 1 : 0); assessUser.setAchieveMentType(reqType == 0 ? 1 : 0);
assessUser.setCaseId(yyyfLoginRequestVo.getCaseId()); assessUser.setCaseId(yyyfLoginRequestVo.getCaseId());
assessUser.setClassId(String.valueOf(classId)); assessUser.setClassId(String.valueOf(classId));
@ -99,9 +99,19 @@ public class LoginController {
assessUser.setSsPractiseId(yyyfLoginRequestVo.getCaseId()); assessUser.setSsPractiseId(yyyfLoginRequestVo.getCaseId());
assessUser.setStartTime(new Date()); assessUser.setStartTime(new Date());
assessUser.setUserId(userId); assessUser.setUserId(userId);
this.assessUserService.insert(assessUser); assessUser.setUserName(userName);
//获取案例信息
HashOperations<String, String, ExamPaperDto> examPaperOpsForHash = redisTemplate.opsForHash();
ExamPaperDto examPaperDto = examPaperOpsForHash.get(YyyfConstant.EXAM_PAPER_KEY, examPaperId);
List<TrainCaseTargetDto> trainCaseTargeList = examPaperDto.getTrainCaseTargeList();
this.assessUserService.initAssessUser(assessUser, trainCaseTargeList);
} }
yyyfUserDto.setAssessUserId(assessUser.getId());
HashOperations<String, String, ExamDto> examDtoOpsForHash = redisTemplate.opsForHash(); HashOperations<String, String, ExamDto> examDtoOpsForHash = redisTemplate.opsForHash();
//将参加考试的人员缓存 //将参加考试的人员缓存
@ -160,50 +170,10 @@ public class LoginController {
return handleAfterLogin(yyyfLoginDto, yyyfUserDto); return handleAfterLogin(yyyfLoginDto, yyyfUserDto);
} }
ValueOperations<String, Object> studentAnsweValueOperations = redisTemplate.opsForValue();
String studentAnswerDtoKey = YyyfConstant.ANSER_KEY + userId + examPaperId;
StudentAnswerDto studentAnswerDto = (StudentAnswerDto) studentAnsweValueOperations.get(studentAnswerDtoKey);
if (studentAnswerDto != null) {
//答题结果、且未提交
Map<String, Double> result = studentAnswerDto.getResult();
if (result != null && result.size() > 0 && result.get("isSubmit") == null) {
yyyfLoginDto.setStatus(3);
yyyfLoginDto.setMsg(YyyfConstant.INCOMPLETE_PRACTICE);
PractiseTipDto practiseTipDto = new PractiseTipDto();
practiseTipDto.setExamId(examId);
practiseTipDto.setExamPaperId(examPaperId);
practiseTipDto.setYyyfUserId(userId);
yyyfLoginDto.setPractiseTipDto(practiseTipDto);
Map<String, String> map = new HashMap<String, String>();
map.put("examPaperId", examPaperId);
map.put("examId", examId);
redisTemplate.opsForValue().set(caseKey, map);
redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS);
redisTemplate.expire(caseKey, 2, TimeUnit.HOURS);
return handleAfterLogin(yyyfLoginDto, yyyfUserDto);
}
}
} }
//删除强制提醒的缓存 //删除强制提醒的缓存
redisTemplate.delete(YyyfConstant.ANSER_KEY + userId); // redisTemplate.delete(YyyfConstant.ANSER_KEY + userId);
/* ValueOperations<String, Object> studentAnsweValueOperations = redisTemplate.opsForValue();
String studentAnswerDtoKey = YyyfConstant.ANSER_KEY + userId + examPaperId;
StudentAnswerDto studentAnswerDto = new StudentAnswerDto();
studentAnswerDto.setUserId(userId);
studentAnswerDto.setUserType(userType);
studentAnswerDto.setBeginTime(new Date());
studentAnswerDto.setExamId(examId);
studentAnswerDto.setType(reqType);
studentAnswerDto.setExamPaperId(examPaperId);
studentAnswerDto.setUserName(userName);
studentAnswerDto.setClassId(classId);
studentAnswerDto.setCourseId(yyyfLoginRequestVo.getCourserId());
studentAnsweValueOperations.set(studentAnswerDtoKey, studentAnswerDto);*/
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
@ -211,12 +181,9 @@ public class LoginController {
map.put("examId", examId); map.put("examId", examId);
redisTemplate.opsForValue().set(caseKey, map); redisTemplate.opsForValue().set(caseKey, map);
// redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS);
redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); redisTemplate.expire(caseKey, 2, TimeUnit.HOURS);
} }
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
return handleAfterLogin(yyyfLoginDto, yyyfUserDto); return handleAfterLogin(yyyfLoginDto, yyyfUserDto);
} }

@ -3,35 +3,33 @@ package com.blockchain.server.yyyf.controller;
import com.blockchain.common.base.constant.YyyfConstant; import com.blockchain.common.base.constant.YyyfConstant;
import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.dto.YyyfUserDto;
import com.blockchain.server.train.dto.ExamPaperDto; import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.train.dto.TrainCaseTargetDto;
import com.blockchain.server.yyyf.controller.api.StudentAnswerApi; import com.blockchain.server.yyyf.controller.api.StudentAnswerApi;
import com.blockchain.server.yyyf.dto.AssessUserTargetDto; import com.blockchain.server.yyyf.entity.AssessUser;
import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.AssessUserTarget;
import com.blockchain.server.yyyf.enums.UserEnums; import com.blockchain.server.yyyf.enums.UserEnums;
import com.blockchain.server.yyyf.exceprion.UserException; import com.blockchain.server.yyyf.exceprion.UserException;
import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.service.AssessUserService;
import com.blockchain.server.yyyf.service.AssessUserTargetService; import com.blockchain.server.yyyf.service.AssessUserTargetService;
import com.blockchain.server.yyyf.utils.IdGenerator;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils; import lombok.SneakyThrows;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
/** /**
* @author huangxl * @author huangxl
@ -43,12 +41,10 @@ import java.util.concurrent.atomic.AtomicReference;
@RequestMapping("/studentAnswer") @RequestMapping("/studentAnswer")
public class StudentAnswerController { public class StudentAnswerController {
private static final Logger LOG = LoggerFactory.getLogger(StudentAnswerController.class);
@Autowired
private AssessUserService assessUserService;
@Autowired @Autowired
private AssessUserTargetService assessUserTargetService; private AssessUserTargetService assessUserTargetService;
@Autowired
private AssessUserService assessUserService;
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@ -56,50 +52,64 @@ public class StudentAnswerController {
@PostMapping("/saveAnswer") @PostMapping("/saveAnswer")
@ApiOperation(value = StudentAnswerApi.SaveAnswer.METHOD_NAME, @ApiOperation(value = StudentAnswerApi.SaveAnswer.METHOD_NAME,
notes = StudentAnswerApi.SaveAnswer.METHOD_NOTE) notes = StudentAnswerApi.SaveAnswer.METHOD_NOTE)
public ResultDTO saveAnswer(@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_YYYF_USER_DTO) @RequestParam(name = "yyyfUserDto") YyyfUserDto yyyfUserDto, public ResultDTO<Integer> saveAnswer(@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_YYYF_USER_ID) @RequestParam(name = "yyyfUserId") Integer yyyfUserId,
@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate")String taskRate, @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId") String assessUserId,
@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STARGE_ID) @RequestParam(name = "targeId")String targeId) { @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate") Double taskRate,
@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STARGE_ID) @RequestParam(name = "code") String code) {
Integer yyyfUserId=yyyfUserDto.getUserId();
String caseKey = YyyfConstant.CASE_KEY + yyyfUserId; String caseKey = YyyfConstant.CASE_KEY + yyyfUserId;
Integer answer = -1;
if (redisTemplate.hasKey(caseKey)) { if (redisTemplate.hasKey(caseKey)) {
Map<String,String> map = (Map<String,String>) redisTemplate.opsForValue().get(caseKey); AssessUserTarget assessUserTarget = this.assessUserTargetService.selectByAssessUserAndCode(assessUserId, code);
String caseId=map.get("examPaperId"); assessUserTarget.setStudentRate(taskRate);
String examId=map.get("examId"); int compareAnswer = taskRate.compareTo(assessUserTarget.getTaskRate());
//最终指标结果一致
HashOperations<String, String, ExamPaperDto> examPaperOpsForHash = redisTemplate.opsForHash(); if (assessUserTarget.getTaskOperate().intValue() == compareAnswer) {
ExamPaperDto examPaperDto = examPaperOpsForHash.get(YyyfConstant.EXAM_PAPER_KEY, caseId); answer = 0;
TrainCaseTargetDto trainCaseTargetDto =null; } else {
answer = 1;
List<TrainCaseTargetDto> trainCaseTargeList = examPaperDto.getTrainCaseTargeList();
for(TrainCaseTargetDto targetDto:trainCaseTargeList){
if(targetDto.getTargeId().equals(targeId)){
trainCaseTargetDto=targetDto;
break;
}
}
AssessUserTargetDto assessUserTargetDto= assessUserTargetService.selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId(yyyfUserId,examId,caseId);
String assessUserId=assessUserTargetDto.getAssessUserId();
if(StringUtils.isBlank(assessUserTargetDto.getId())){
AssessUserTarget assessUserTarget =new AssessUserTarget();
BeanUtils.copyProperties(trainCaseTargetDto,assessUserTarget);
assessUserTarget.setAssessUserId(assessUserId);
//学生答题的结果
// assessUserTarget.set
} }
assessUserTarget.setAnswer(answer);
this.assessUserTargetService.update(assessUserTarget);
redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); redisTemplate.expire(caseKey, 2, TimeUnit.HOURS);
// redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS);
} else { } else {
throw new UserException(UserEnums.USER_NOT_BIND_YYYF); throw new UserException(UserEnums.USER_NOT_BIND_YYYF);
} }
return new ResultDTO(); return ResultDTO.requstSuccess(answer);
} }
@SneakyThrows
@PostMapping("/submit")
@ApiOperation(value = StudentAnswerApi.SaveAnswer.METHOD_NAME,
notes = StudentAnswerApi.SaveAnswer.METHOD_NOTE)
public ResultDTO<Integer> submit(HttpServletRequest request) {
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate);
String assessUserId = yyyfUserDto.getAssessUserId();
AssessUser assessUser = this.assessUserService.selectAssessUserById(assessUserId);
if (assessUser.getEndTime() != null) {
throw new UserException(UserEnums.PROHIBIT_DUPLICATE_SUBMISSION);
}
Double totalScore = 0d;
List<AssessUserTarget> assessUserTargetList = this.assessUserTargetService.selectAssessUserTargetByAssessUserId(assessUserId);
for (AssessUserTarget assessUserTarget : assessUserTargetList) {
Integer answer = assessUserTarget.getAnswer();
Double taskScore = assessUserTarget.getTaskScore();
if (assessUserTarget.getAnswer() == 0) {
totalScore += taskScore;
}
}
Date startTime = assessUser.getStartTime();
Date now = new Date();
assessUser.setTotalScore(totalScore);
assessUser.setEndTime(now);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//考试时长
//考试时长
long duration1 = sdf.parse(sdf.format(now)).getTime() - sdf.parse(sdf.format(startTime)).getTime();
long duration = now.getTime() - startTime.getTime();
return ResultDTO.requstSuccess();
}
} }

@ -9,8 +9,9 @@ public class StudentAnswerApi {
public static class SaveAnswer { public static class SaveAnswer {
public static final String METHOD_NAME = "学生答题"; public static final String METHOD_NAME = "学生答题";
public static final String METHOD_NOTE = "学生答题统一调用"; public static final String METHOD_NOTE = "学生答题统一调用,调用成功,返回结果:0答案正确,1答案错误,-1系统错误";
public static final String METHOD_YYYF_USER_DTO = "以渔有方用户"; public static final String METHOD_YYYF_USER_ID= "以渔有方用户ID";
public static final String METHOD_ASSESS_USER_ID= "assessUser的主键ID";
public static final String METHOD_STUDENT_TASK_RATE="学生任务目标比率"; public static final String METHOD_STUDENT_TASK_RATE="学生任务目标比率";
public static final String METHOD_STARGE_ID="指标id"; public static final String METHOD_STARGE_ID="指标id";
} }

@ -1,16 +0,0 @@
package com.blockchain.server.yyyf.dto;
import com.blockchain.server.yyyf.entity.AssessUserTarget;
import lombok.Data;
/**
* @author huan.xu
* @version 1.0
* @className AssessUserTargetDto
* @description
* @date 2020-05-13 16:52
*/
@Data
public class AssessUserTargetDto extends AssessUserTarget {
private String assessUserId;
}

@ -48,7 +48,7 @@ public class AssessUser implements Serializable {
* 得分 * 得分
*/ */
@Column(name = "total_score") @Column(name = "total_score")
private BigDecimal totalScore; private Double totalScore;
/** /**
* 时长 * 时长
*/ */
@ -58,7 +58,7 @@ public class AssessUser implements Serializable {
* 时长单位 * 时长单位
*/ */
@Column(name = "duration_unit") @Column(name = "duration_unit")
private String durationUnit; private String durationUnit="m";
/** /**
* 开始时间 * 开始时间
*/ */
@ -92,6 +92,10 @@ public class AssessUser implements Serializable {
*/ */
@Column(name = "course_id") @Column(name = "course_id")
private String courseId; private String courseId;
/**
* 绑定的课程id
*/
@Column(name = "user_name")
private String userName;
} }

@ -27,8 +27,8 @@ public class AssessUserTarget implements Serializable {
/** /**
* 指标id * 指标id
*/ */
@Column(name = "targe_id") @Column(name = "target_id")
private String targeId; private String targetId;
/** /**
* 指标名称 * 指标名称
@ -37,7 +37,7 @@ public class AssessUserTarget implements Serializable {
private String targetName; private String targetName;
/** /**
* 任务目标运算符1大于2等于3小 * 任务目标运算符-1小于0等于1大
*/ */
@Column(name = "task_operate") @Column(name = "task_operate")
private Integer taskOperate; private Integer taskOperate;
@ -62,4 +62,14 @@ public class AssessUserTarget implements Serializable {
*/ */
@Column(name = "sort") @Column(name = "sort")
private Integer sort; private Integer sort;
/**
* 学生答题计算的指标
*/
@Column(name = "student_rate")
private Double studentRate;
/**
* 学生是否完成指标0完成1未
*/
@Column(name = "answer")
private Integer answer;
} }

@ -5,6 +5,7 @@ package com.blockchain.server.yyyf.enums;
* @data 2019/2/21 20:53 * @data 2019/2/21 20:53
*/ */
public enum UserEnums { public enum UserEnums {
PROHIBIT_DUPLICATE_SUBMISSION(1097,"禁止重复提交","Prohibit duplicate submission","禁止重複提交"),
USER_NOT_FORBID_OTHER_USER(1098, "禁止登录他人账号", "The user does not allow login other user's accout", "禁止登錄他人賬號"), USER_NOT_FORBID_OTHER_USER(1098, "禁止登录他人账号", "The user does not allow login other user's accout", "禁止登錄他人賬號"),
USER_NOT_BIND_YYYF(1099, "该用户未绑定以渔有方或者以渔有方登录已失效", "The user does not bind yyyf", "該用戶未綁定以漁有方或者以漁有方登錄已失效"), USER_NOT_BIND_YYYF(1099, "该用户未绑定以渔有方或者以渔有方登录已失效", "The user does not bind yyyf", "該用戶未綁定以漁有方或者以漁有方登錄已失效"),
USER_EXISTS(1100, "该用户已存在", "The user already exists", "該用戶已存在"), USER_EXISTS(1100, "该用户已存在", "The user already exists", "該用戶已存在"),

@ -34,7 +34,7 @@ public interface AssessUserMapper extends Mapper<AssessUser> {
List<AssessUser> selectAssessUserListByIssuerIdAndUserId(@Param("issueId") String issueId, @Param("userId") Integer userId); List<AssessUser> selectAssessUserListByIssuerIdAndUserId(@Param("issueId") String issueId, @Param("userId") Integer userId);
AssessUser selectAssessUserById(@Param("assessUserId") String assessUserId);
List<AssessUser> selectAssessUserListByIssueId(@Param("issueId") String issueId); List<AssessUser> selectAssessUserListByIssueId(@Param("issueId") String issueId);

@ -1,6 +1,5 @@
package com.blockchain.server.yyyf.mapper; package com.blockchain.server.yyyf.mapper;
import com.blockchain.server.yyyf.dto.AssessUserTargetDto;
import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.AssessUserTarget;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -12,5 +11,6 @@ import java.util.List;
public interface AssessUserTargetMapper extends Mapper<AssessUserTarget> { public interface AssessUserTargetMapper extends Mapper<AssessUserTarget> {
AssessUserTargetDto selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId(@Param("userId") Integer userId, @Param("issueId") String issueId,@Param("caseId") String caseId);
void batchInsert(@Param("list")List<AssessUserTarget> list);
} }

@ -2,6 +2,7 @@ package com.blockchain.server.yyyf.service;
import com.blockchain.server.train.dto.TrainCaseTargetDto;
import com.blockchain.server.yyyf.dto.PractiseProDto; import com.blockchain.server.yyyf.dto.PractiseProDto;
import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUser;
@ -90,4 +91,6 @@ public interface AssessUserService {
* @return void * @return void
**/ **/
void insert(AssessUser assessUser); void insert(AssessUser assessUser);
void initAssessUser(AssessUser assessUser, List<TrainCaseTargetDto> trainCaseTargeList );
} }

@ -1,13 +1,29 @@
package com.blockchain.server.yyyf.service; package com.blockchain.server.yyyf.service;
import com.blockchain.server.yyyf.dto.AssessUserTargetDto;
import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.AssessUserTarget;
import java.util.List;
public interface AssessUserTargetService{ public interface AssessUserTargetService{
/**
* @description 根据assessUserId和code获取指标信息
* @param [assessUserId, code]
* @return com.blockchain.server.yyyf.entity.AssessUserTarget
**/
AssessUserTarget selectByAssessUserAndCode(String assessUserId, String code);
/**
* @description 更新
* @param [assessUserTarget]
* @return void
**/
void update(AssessUserTarget assessUserTarget);
/** /**
* @description 获取指标情况 * @description 通过assessUserId 获取指标答题情况
* @param [yyyfUserId, examId, caseId] * @param [assessUserId]
* @return com.blockchain.server.yyyf.dto.AssessUserTargetDto * @return java.util.List<com.blockchain.server.yyyf.entity.AssessUserTarget>
**/ **/
AssessUserTargetDto selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId(Integer yyyfUserId, String examId, String caseId); List<AssessUserTarget> selectAssessUserTargetByAssessUserId(String assessUserId);
} }

@ -1,7 +1,11 @@
package com.blockchain.server.yyyf.service.impl; package com.blockchain.server.yyyf.service.impl;
import com.blockchain.common.base.constant.YyyfConstant;
import com.blockchain.server.train.dto.ExamPaperDto;
import com.blockchain.server.train.dto.TrainCaseTargetDto;
import com.blockchain.server.yyyf.dto.PractiseProDto; import com.blockchain.server.yyyf.dto.PractiseProDto;
import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUser;
import com.blockchain.server.yyyf.entity.AssessUserTarget;
import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserMapper;
import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper;
import com.blockchain.server.yyyf.mapper.AssessUserTaskMapper; import com.blockchain.server.yyyf.mapper.AssessUserTaskMapper;
@ -9,11 +13,14 @@ import com.blockchain.server.yyyf.service.AssessUserService;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -59,7 +66,8 @@ public class AssessUserServiceImpl implements AssessUserService {
@Override @Override
public AssessUser selectAssessUserById(String assessUserId) { public AssessUser selectAssessUserById(String assessUserId) {
return this.assessUserMapper.selectAssessUserById(assessUserId);
return this.assessUserMapper.selectByPrimaryKey(assessUserId);
} }
@Override @Override
@ -89,5 +97,23 @@ public class AssessUserServiceImpl implements AssessUserService {
this.assessUserMapper.insertSelective(assessUser); this.assessUserMapper.insertSelective(assessUser);
} }
@Override
public void initAssessUser(AssessUser assessUser, List<TrainCaseTargetDto> trainCaseTargeList ) {
List<AssessUserTarget> list=new ArrayList<>(trainCaseTargeList.size());
int j=1;
for(TrainCaseTargetDto trainCaseTargetDto :trainCaseTargeList){
AssessUserTarget assessUserTarget=new AssessUserTarget();
BeanUtils.copyProperties(trainCaseTargetDto,assessUserTarget);
assessUserTarget.setAssessUserId(assessUser.getId());
assessUserTarget.setTargetId(trainCaseTargetDto.getId());
assessUserTarget.setTargetName(trainCaseTargetDto.getName());
assessUserTarget.setSort(j++);
list.add(assessUserTarget);
}
this.assessUserMapper.insert(assessUser);
this.assessUserTargetMapper.batchInsert(list);
}
} }

@ -1,23 +1,46 @@
package com.blockchain.server.yyyf.service.impl; package com.blockchain.server.yyyf.service.impl;
import com.blockchain.server.yyyf.dto.AssessUserTargetDto;
import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.AssessUserTarget;
import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper;
import com.blockchain.server.yyyf.service.AssessUserTargetService; import com.blockchain.server.yyyf.service.AssessUserTargetService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/** /**
* @version 1.0 * @version 1.0
* @className AssessUserProjectServiceImpl * @className AssessUserProjectServiceImpl
* @description * @description
*/ */
@Transactional(rollbackFor = Exception.class)
@Service @Service
public class AssessUserTargetServiceImpl implements AssessUserTargetService { public class AssessUserTargetServiceImpl implements AssessUserTargetService {
@Autowired @Autowired
private AssessUserTargetMapper assessUserTargetMapper; private AssessUserTargetMapper assessUserTargetMapper;
@Override
public AssessUserTarget selectByAssessUserAndCode(String assessUserId, String code) {
Example example=new Example(AssessUserTarget.class);
Example.Criteria criteria=example.createCriteria();
criteria.andCondition(" assess_user_id= ",assessUserId);
criteria.andCondition(" code = ",code);
return this.assessUserTargetMapper.selectOneByExample(example);
}
@Override @Override
public AssessUserTargetDto selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId(Integer yyyfUserId, String examId, String caseId) { public void update(AssessUserTarget assessUserTarget) {
return this.assessUserTargetMapper.selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId(yyyfUserId,examId,caseId); this.assessUserTargetMapper.updateByPrimaryKeySelective(assessUserTarget);
} }
@Override
public List<AssessUserTarget> selectAssessUserTargetByAssessUserId(String assessUserId) {
Example example=new Example(AssessUserTarget.class);
Example.Criteria criteria = example.createCriteria();
criteria.andCondition(" assess_user_id = " ,assessUserId);
return this.assessUserTargetMapper.selectByExample(example);
}
} }

@ -105,13 +105,14 @@
</sql> </sql>
<insert id="insert" parameterType="com.blockchain.server.yyyf.entity.AssessUser"> <insert id="insert" parameterType="com.blockchain.server.yyyf.entity.AssessUser">
insert into yyyf_server_assess_user ( id, train_id, issue_id, ss_practise_id, user_id, total_score, duration, duration_unit, start_time, end_time, case_id, achieve_ment_type, class_id, course_id) insert into yyyf_server_assess_user ( id, train_id, issue_id, ss_practise_id, user_id,user_name, total_score, duration, duration_unit, start_time, end_time, case_id, achieve_ment_type, class_id, course_id)
values( values(
#{id}, #{id},
#{trainId}, #{trainId},
#{issueId}, #{issueId},
#{ssPractiseId}, #{ssPractiseId},
#{userId}, #{userId},
#{userName},
#{totalScore}, #{totalScore},
#{duration}, #{duration},
#{durationUnit}, #{durationUnit},
@ -194,9 +195,6 @@
where achieve_ment_type=0 and issue_id=#{issueId} and user_id=#{userId} where achieve_ment_type=0 and issue_id=#{issueId} and user_id=#{userId}
ORDER BY start_time desc ORDER BY start_time desc
</select> </select>
<select id="selectAssessUserById" resultMap="YfServerAssessUserResultMap">
select * from yyyf_server_assess_user where id=#{assessUserId}
</select>
<select id="selectAssessUserListByIssueId" resultMap="YfServerAssessUserResultMap"> <select id="selectAssessUserListByIssueId" resultMap="YfServerAssessUserResultMap">
select * from yyyf_server_assess_user where issue_id=#{issueId} and achieve_ment_type = 1 select * from yyyf_server_assess_user where issue_id=#{issueId} and achieve_ment_type = 1

@ -47,26 +47,20 @@
t.duration_unit, t.duration_unit,
t.project_case_desc, t.project_case_desc,
</sql> </sql>
<select id="selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId"
resultType="com.blockchain.server.yyyf.dto.AssessUserTargetDto">
SELECT <insert id="batchInsert" parameterType="java.util.List">
u.id AS assessUserId, insert into yyyf_server_assess_user_target
t.id AS id, (id,assess_user_id, target_name, target_id, code, task_operate, task_rate,task_score, sort)
t.targe_id AS targeId, values
t.target_name AS targetName,
t.task_operate AS taskOperate,
t.task_rate AS taskRate,
t.task_score AS taskScore,
t. CODE AS CODE,
t.sort AS sort
FROM
yyyf_server_assess_user u
LEFT JOIN yyyf_server_assess_user_target t ON (
u.end_time IS NULL
AND u.case_id = #{caseId} and u.id=t.assess_user_id and u.user_id=#{userId}
AND u.issue_id = #{issueId} )
</select>
<foreach collection ="list" item="item" index= "index" separator =",">
( #{item.id,jdbcType=VARCHAR},
#{item.assessUserId,jdbcType=VARCHAR}, #{item.targetName,jdbcType=VARCHAR}, #{item.targetId,jdbcType=VARCHAR},
#{item.code,jdbcType=VARCHAR}, #{item.taskOperate,jdbcType=TINYINT}, #{item.taskRate,jdbcType=DECIMAL},
#{item.taskScore,jdbcType=DECIMAL}, #{item.sort,jdbcType=INTEGER}
)
</foreach >
</insert>
</mapper> </mapper>
Loading…
Cancel
Save