From 9e6f60dca816025327e8eee5ac64475013e90a8c Mon Sep 17 00:00:00 2001 From: unclekh <5177787+unclekh@user.noreply.gitee.com> Date: Wed, 13 May 2020 22:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=94=E9=A2=98=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/base/dto/YyyfUserDto.java | 16 ++++++-- .../src/main/resources/bootstrap.yml | 2 + .../server/train/dto/ExamPaperDto.java | 27 ++++++------- .../server/train/dto/TrainCaseTargetDto.java | 14 +++++-- .../yyyf/controller/LoginController.java | 36 +++++++++++++---- .../controller/StudentAnswerController.java | 39 +++++++++++++++---- .../yyyf/controller/api/StudentAnswerApi.java | 2 +- .../server/yyyf/entity/AssessUser.java | 2 +- .../server/yyyf/mapper/AssessUserMapper.java | 4 +- .../yyyf/service/AssessUserService.java | 18 +++++++++ .../service/impl/AssessUserServiceImpl.java | 19 +++++++++ .../server/yyyf/utils/IdGenerator.java | 17 ++++++++ 12 files changed, 156 insertions(+), 40 deletions(-) create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/IdGenerator.java diff --git a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/YyyfUserDto.java b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/YyyfUserDto.java index 996f62f..9bc0659 100644 --- a/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/YyyfUserDto.java +++ b/blockchain-common/blockchain-common-base/src/main/java/com/blockchain/common/base/dto/YyyfUserDto.java @@ -3,6 +3,8 @@ package com.blockchain.common.base.dto; import lombok.Data; import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Map; /** * @author huan.xu @@ -15,14 +17,22 @@ import java.io.Serializable; public class YyyfUserDto implements Serializable { private static final long serialVersionUID = -6752296227958588252L; /**传过来的用户id*/ - private Integer id; + private Integer userId; /**用户名称*/ - private String name; + private String userName; /**用户类型:0学生,1老师,2管理员*/ - private Integer type; + private Integer userType; /**班级id*/ private Integer classId; /**学校id,为以后logo修改预留参数*/ private Integer schoolId; + /** + * 课程id + */ + private String courseId; + /** + * 请求类型:0 考试 1 练习 2 不计分 3 教师、管理员的案例管理 + */ + private Integer reqType; } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml b/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml index 2ce250b..edf2f92 100644 --- a/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml +++ b/blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml @@ -1,5 +1,7 @@ server: port: 8101 + servlet: + context-path: /user #注册中心 eureka: client: diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java index d3086e3..0274cad 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/ExamPaperDto.java @@ -1,5 +1,6 @@ package com.blockchain.server.train.dto; + import lombok.Data; import java.io.Serializable; @@ -12,31 +13,25 @@ public class ExamPaperDto implements Serializable { * id */ private String id; - /** - * 指标名称 + * 案例名称 */ private String name; /** - * 任务目标运算符:1大于2小于 + * 实训用途:1考核 2练习 */ - private Integer taskOperate; - /** - * 任务目标比率 - */ - private Double taskRate; - /** - * 任务分数 - */ - private Double taskScore; + private Integer type; + /** - * 指标代码 + * 指标 */ - private String code; + List trainCaseTargeList; + /** - * 指标id + * 案例内容描述 */ - private String targeId; + // private String content; + } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java index b947ab1..b70c4a3 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/train/dto/TrainCaseTargetDto.java @@ -13,9 +13,8 @@ import java.io.Serializable; @Data public class TrainCaseTargetDto implements Serializable { private static final long serialVersionUID = 1L; - /** - * 指标id + * id */ private String id; @@ -25,7 +24,7 @@ public class TrainCaseTargetDto implements Serializable { private String name; /** - * 任务目标运算符:1大于2小于 + * 任务目标运算符:1大于2小于3等于 */ private Integer taskOperate; /** @@ -36,4 +35,13 @@ public class TrainCaseTargetDto implements Serializable { * 任务分数 */ private Double taskScore; + /** + * 指标代码 + */ + private String code; + + /** + * 指标id + */ + private String targeId; } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java index 28c3c76..d17774e 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/LoginController.java @@ -7,7 +7,9 @@ import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.util.RSACoderUtils; import com.blockchain.server.yyyf.controller.api.LoginApi; import com.blockchain.server.yyyf.dto.*; +import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.service.AssessUserService; +import com.blockchain.server.yyyf.utils.IdGenerator; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -69,10 +71,13 @@ public class LoginController { Integer schoolId = yyyfLoginRequestVo.getSchoolId(); yyyfUserDto.setClassId(classId); - yyyfUserDto.setId(userId); - yyyfUserDto.setName(userName); + yyyfUserDto.setUserId(userId); + yyyfUserDto.setUserName(userName); yyyfUserDto.setSchoolId(schoolId); - yyyfUserDto.setType(userType); + yyyfUserDto.setUserType(userType); + yyyfUserDto.setClassId(classId); + yyyfUserDto.setCourseId(yyyfLoginRequestVo.getCourserId()); + //以渔有方考核id String examId = yyyfLoginRequestVo.getReqId(); @@ -80,6 +85,23 @@ public class LoginController { String examPaperId = yyyfLoginRequestVo.getCaseId(); //做考试和练习 if (0 == reqType || 1 == reqType) { + + + AssessUser assessUser = this.assessUserService.selectAssessUserByUserIdAndissueIdForNotEnd(userId, examId); + if(assessUser==null){ + assessUser=new AssessUser(); + assessUser.setId(IdGenerator.uuid()); + assessUser.setAchieveMentType(reqType==0?1:0); + assessUser.setCaseId(yyyfLoginRequestVo.getCaseId()); + assessUser.setClassId(String.valueOf(classId)); + assessUser.setCourseId(yyyfLoginRequestVo.getCourserId()); + assessUser.setIssueId(examId); + assessUser.setSsPractiseId(yyyfLoginRequestVo.getCaseId()); + assessUser.setStartTime(new Date()); + assessUser.setUserId(userId); + this.assessUserService.insert(assessUser); + + } HashOperations examDtoOpsForHash = redisTemplate.opsForHash(); //将参加考试的人员缓存 @@ -168,7 +190,7 @@ public class LoginController { //删除强制提醒的缓存 redisTemplate.delete(YyyfConstant.ANSER_KEY + userId); - ValueOperations studentAnsweValueOperations = redisTemplate.opsForValue(); + /* ValueOperations studentAnsweValueOperations = redisTemplate.opsForValue(); String studentAnswerDtoKey = YyyfConstant.ANSER_KEY + userId + examPaperId; StudentAnswerDto studentAnswerDto = new StudentAnswerDto(); studentAnswerDto.setUserId(userId); @@ -181,7 +203,7 @@ public class LoginController { studentAnswerDto.setClassId(classId); studentAnswerDto.setCourseId(yyyfLoginRequestVo.getCourserId()); - studentAnsweValueOperations.set(studentAnswerDtoKey, studentAnswerDto); + studentAnsweValueOperations.set(studentAnswerDtoKey, studentAnswerDto);*/ Map map = new HashMap(); @@ -189,7 +211,7 @@ public class LoginController { map.put("examId", examId); redisTemplate.opsForValue().set(caseKey, map); - redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); + // redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); } } catch (IOException e) { @@ -204,7 +226,7 @@ public class LoginController { */ private ResultDTO handleAfterLogin(YyyfLoginDto yyyfLoginDto, YyyfUserDto yyyfUserDto) { int status = yyyfLoginDto.getStatus(); - String token = generateToken(String.valueOf(yyyfUserDto.getId()), System.currentTimeMillis(), + String token = generateToken(String.valueOf(yyyfUserDto.getUserId()), System.currentTimeMillis(), YyyfConstant.YYYF_ZHIXINLIAN_USER_KEY); yyyfLoginDto.setYyyfUserToken(token); if (status != 2) { diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java index 6219415..8d27238 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/StudentAnswerController.java @@ -2,6 +2,9 @@ package com.blockchain.server.yyyf.controller; import com.blockchain.common.base.constant.YyyfConstant; import com.blockchain.common.base.dto.ResultDTO; +import com.blockchain.common.base.dto.YyyfUserDto; +import com.blockchain.server.train.dto.ExamPaperDto; +import com.blockchain.server.train.dto.TrainCaseTargetDto; import com.blockchain.server.yyyf.controller.api.StudentAnswerApi; import com.blockchain.server.yyyf.dto.AssessUserTargetDto; import com.blockchain.server.yyyf.entity.AssessUserTarget; @@ -9,20 +12,26 @@ import com.blockchain.server.yyyf.enums.UserEnums; import com.blockchain.server.yyyf.exceprion.UserException; import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.service.AssessUserTargetService; +import com.blockchain.server.yyyf.utils.IdGenerator; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; /** * @author huangxl @@ -47,26 +56,42 @@ public class StudentAnswerController { @PostMapping("/saveAnswer") @ApiOperation(value = StudentAnswerApi.SaveAnswer.METHOD_NAME, notes = StudentAnswerApi.SaveAnswer.METHOD_NOTE) - public ResultDTO saveAnswer(@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_YYYF_USER_ID) @RequestParam(name = "yyyfUserId")Integer yyyfUserId, + public ResultDTO saveAnswer(@ApiParam(StudentAnswerApi.SaveAnswer.METHOD_YYYF_USER_DTO) @RequestParam(name = "yyyfUserDto") YyyfUserDto yyyfUserDto, @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate")String taskRate, @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STARGE_ID) @RequestParam(name = "targeId")String targeId) { - String caseKey = YyyfConstant.CASE_KEY + yyyfUserId; - String studentAnswerDtoKey = null; + + Integer yyyfUserId=yyyfUserDto.getUserId(); + String caseKey = YyyfConstant.CASE_KEY + yyyfUserId ; if (redisTemplate.hasKey(caseKey)) { Map map = (Map) redisTemplate.opsForValue().get(caseKey); String caseId=map.get("examPaperId"); String examId=map.get("examId"); + HashOperations examPaperOpsForHash = redisTemplate.opsForHash(); + ExamPaperDto examPaperDto = examPaperOpsForHash.get(YyyfConstant.EXAM_PAPER_KEY, caseId); + TrainCaseTargetDto trainCaseTargetDto =null; - AssessUserTargetDto assessUserTargetDto= assessUserTargetService.selectAssessUserTargetDtoByUserIdAndIssueIdAndCaseId(yyyfUserId,examId,caseId); + List trainCaseTargeList = examPaperDto.getTrainCaseTargeList(); + for(TrainCaseTargetDto targetDto:trainCaseTargeList){ + if(targetDto.getTargeId().equals(targeId)){ + trainCaseTargetDto=targetDto; + break; + } + } - if(assessUserTargetDto==null){ - + 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 } redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); - redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); + // redisTemplate.expire(studentAnswerDtoKey, 2, TimeUnit.HOURS); }else{ diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java index e1056a8..463cf06 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/StudentAnswerApi.java @@ -10,7 +10,7 @@ public class StudentAnswerApi { public static class SaveAnswer { public static final String METHOD_NAME = "学生答题"; public static final String METHOD_NOTE = "学生答题统一调用"; - public static final String METHOD_YYYF_USER_ID = "以渔有方用户id"; + public static final String METHOD_YYYF_USER_DTO = "以渔有方用户"; public static final String METHOD_STUDENT_TASK_RATE="学生任务目标比率"; public static final String METHOD_STARGE_ID="指标id"; } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java index 081a0e8..3d51d61 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/entity/AssessUser.java @@ -24,7 +24,7 @@ public class AssessUser implements Serializable { * 子系统id */ @Column(name = "train_id") - private String trainId; + private String trainId="0001"; /** * 已发布id diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java index 241e957..7961d31 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java @@ -12,9 +12,9 @@ import java.util.Map; @Repository -public interface AssessUserMapper extends Mapper { +public interface AssessUserMapper extends Mapper { - void insert(AssessUser assessUser); + int insert(AssessUser assessUser); void batchInsert(List assessUserList); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java index f2a9f30..781df51 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssessUserService.java @@ -72,4 +72,22 @@ public interface AssessUserService { **/ void delAssessUserByIssueId(String examId); + + /** + * @description 查找未结束的记录 + * @author Mr.Xu + * @date 2020-05-13 22:26:38 + * @param [] + * @return com.blockchain.server.yyyf.entity.AssessUser + **/ + AssessUser selectAssessUserByUserIdAndissueIdForNotEnd(Integer userId,String examId); + + /** + * @description 插入 + * @author Mr.Xu + * @date 2020-05-13 22:37:12 + * @param [assessUser] + * @return void + **/ + void insert(AssessUser assessUser); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java index 84f9926..d9eff8d 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssessUserServiceImpl.java @@ -6,11 +6,13 @@ import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTaskMapper; import com.blockchain.server.yyyf.service.AssessUserService; +import io.swagger.models.auth.In; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import tk.mybatis.mapper.entity.Example; import java.util.List; @@ -21,6 +23,7 @@ import java.util.List; * @description 学生用户考核信息表 服务实现类 * @date 2019-10-31 14:34 */ +@Transactional(rollbackFor = Exception.class) @Service public class AssessUserServiceImpl implements AssessUserService { private static Logger LOG = LoggerFactory.getLogger(AssessUserServiceImpl.class); @@ -70,5 +73,21 @@ public class AssessUserServiceImpl implements AssessUserService { this.assessUserMapper.delAssessUserByIssueId(examId); } + @Override + public AssessUser selectAssessUserByUserIdAndissueIdForNotEnd(Integer userId, String issueId) { + Example example=new Example(AssessUser.class); + Example.Criteria criteria = example.createCriteria(); + criteria.andCondition(" user_id =",userId) + .andCondition(" issue_id = ",issueId) + .andCondition(" end_time is null "); + return this.assessUserMapper.selectOneByExample(example); + } + + + @Override + public void insert(AssessUser assessUser) { + this.assessUserMapper.insertSelective(assessUser); + } + } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/IdGenerator.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/IdGenerator.java new file mode 100644 index 0000000..1b6a300 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/IdGenerator.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.utils; + +import java.util.UUID; + +/** + * @author Mr.Xu + * @version 1.0 + * @className IdGenerator + * @description + * @date 2020-05-13 22:17 + */ +public class IdGenerator { + + public static String uuid(){ + return UUID.randomUUID().toString().replaceAll("-",""); + } +}