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 1de143c..aa51335 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 @@ -100,6 +100,7 @@ public class LoginController { assessUser.setStartTime(new Date()); assessUser.setUserId(userId); assessUser.setUserName(userName); + assessUser.setUserType(yyyfLoginRequestVo.getUserType()); //获取案例信息 HashOperations examPaperOpsForHash = redisTemplate.opsForHash(); 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 49ff1aa..d490bb3 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 @@ -5,6 +5,7 @@ import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.YyyfUserDto; import com.blockchain.common.base.util.YyyfUserDtoUtils; import com.blockchain.server.yyyf.controller.api.StudentAnswerApi; +import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.enums.UserEnums; @@ -17,15 +18,14 @@ import io.swagger.annotations.ApiParam; import lombok.SneakyThrows; 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.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 org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -41,6 +41,8 @@ import java.util.concurrent.TimeUnit; @RequestMapping("/studentAnswer") public class StudentAnswerController { + private static Logger LOG = LoggerFactory.getLogger(StudentAnswerController.class); + @Autowired private AssessUserTargetService assessUserTargetService; @Autowired @@ -56,10 +58,11 @@ public class StudentAnswerController { @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId") String assessUserId, @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STUDENT_TASK_RATE) @RequestParam(name = "taskRate") Double taskRate, @ApiParam(StudentAnswerApi.SaveAnswer.METHOD_STARGE_ID) @RequestParam(name = "code") String code) { - String caseKey = YyyfConstant.CASE_KEY + yyyfUserId; + + AssessUserTarget assessUserTarget = this.assessUserTargetService.selectByAssessUserAndCode(assessUserId, code); Integer answer = -1; - if (redisTemplate.hasKey(caseKey)) { - AssessUserTarget assessUserTarget = this.assessUserTargetService.selectByAssessUserAndCode(assessUserId, code); + if (assessUserTarget != null) { + assessUserTarget.setStudentRate(taskRate); int compareAnswer = taskRate.compareTo(assessUserTarget.getTaskRate()); //最终指标结果一致 @@ -70,46 +73,31 @@ public class StudentAnswerController { } assessUserTarget.setAnswer(answer); this.assessUserTargetService.update(assessUserTarget); - redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); + + String caseKey = YyyfConstant.CASE_KEY + yyyfUserId; + if (redisTemplate.hasKey(caseKey)) + redisTemplate.expire(caseKey, 2, TimeUnit.HOURS); + } else { - throw new UserException(UserEnums.USER_NOT_BIND_YYYF); + throw new UserException(UserEnums.NO_INDICATORS_FOUND); } return ResultDTO.requstSuccess(answer); } @SneakyThrows - @PostMapping("/submit") - @ApiOperation(value = StudentAnswerApi.SaveAnswer.METHOD_NAME, - notes = StudentAnswerApi.SaveAnswer.METHOD_NOTE) - public ResultDTO submit(HttpServletRequest request) { - YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); + @GetMapping("/submit") + @ApiOperation(value = StudentAnswerApi.Submit.METHOD_NAME, + notes = StudentAnswerApi.Submit.METHOD_NOTE) + public ResultDTO submit(HttpServletRequest request) { + YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); String assessUserId = yyyfUserDto.getAssessUserId(); - AssessUser assessUser = this.assessUserService.selectAssessUserById(assessUserId); + AssessUserDto assessUserDto = this.assessUserService.submit(assessUserId); - if (assessUser.getEndTime() != null) { - throw new UserException(UserEnums.PROHIBIT_DUPLICATE_SUBMISSION); + if(assessUserDto.getAchieveMentType()==1){ + redisTemplate.delete(YyyfConstant.CASE_KEY + assessUserDto.getUserId()); } - Double totalScore = 0d; - List 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(); + return ResultDTO.requstSuccess(assessUserDto); } } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java index 6a14574..d609786 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/TeachingGradeController.java @@ -9,6 +9,7 @@ import com.blockchain.server.yyyf.service.AssessUserTaskService; import com.blockchain.server.yyyf.utils.MSExcelUtil; import com.blockchain.server.yyyf.utils.ResponseUtils; +import io.swagger.annotations.ApiParam; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.util.CellRangeAddress; @@ -18,8 +19,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import springfox.documentation.annotations.ApiIgnore; import sun.misc.BASE64Decoder; import javax.servlet.ServletOutputStream; @@ -63,7 +67,7 @@ public class TeachingGradeController { * @author huan.xu * @date 2019-11-08 18:03:39 **/ - @RequestMapping(value = "/getGradeData"/*,produces = {"application/text;charset=UTF-8"}*/) + @GetMapping(value = "/getGradeData"/*,produces = {"application/text;charset=UTF-8"}*/) @ResponseBody @SuppressWarnings("all") public void getGradeData(HttpServletRequest request, HttpServletResponse response) { @@ -164,7 +168,7 @@ public class TeachingGradeController { * @author huan.xu * @date 2019-11-08 18:27:22 **/ - public Map getWrongStatistics(String issueId, Integer notExamNum) { + private Map getWrongStatistics(String issueId, Integer notExamNum) { Map wrongStatistics = new HashMap(); //根据考核发布id,获取考核点信息 List> taskListDb = assessUserTaskService.selectYHTaskInfoByIssueId(issueId); @@ -273,6 +277,7 @@ public class TeachingGradeController { **/ @RequestMapping("/studyGrade/mygrade") + @ApiIgnore public String selectPractiseProList(String reqType, String issueId, String examName, Integer userId, String stuNo, String userName, String className, String caseId, Model model) { try {/* AssessUser assessUser = null; @@ -347,6 +352,7 @@ public class TeachingGradeController { * @date 2019-11-08 18:46:05 **/ @RequestMapping("/studyGrade/examMesaageDetails") + @ApiIgnore public String examMesaageDetails(String assessUserId, Model model) { AssessUser assessUser = this.assessUserService.selectAssessUserById(assessUserId.trim()); cratePractiseProDtosForNotNull(assessUser, model); @@ -382,30 +388,32 @@ public class TeachingGradeController { * @author huan.xu * @date 2019-11-08 18:39:55 **/ - @RequestMapping("/studyGrade/reSynchroze") + @GetMapping("/studyGrade/reSynchroze") @ResponseBody @SuppressWarnings("all") - public Map reSynchroze(String issueId, String authorization) { + public Map reSynchroze(@ApiParam("考试id") @RequestParam("issueId") String issueId, + @ApiParam("验证码") @RequestParam("authorization") String authorization) { Map result = new HashMap<>(); - /* result.put("status", 0); + result.put("status", 0); result.put("msg", "系统错误"); try { if ("87DIVy348Oxzj3ha".equals(authorization)) { - result = this.scoreSynchroService.synchrozeScoreList(issueId); - + this.assessUserService.synchronousScore(issueId); + result.put("status", 1); + result.put("msg", "同步成功"); } else { result.put("msg", "验证错误"); } } catch (Exception e) { result.put("msg", "同步失败,请进行后台检查"); logger.error(e.getMessage(), e); - }*/ + } return result; } - @RequestMapping("/export") + @GetMapping("/export") @ResponseBody public void yhExport(HttpServletRequest request, HttpServletResponse response) {/* String examName = request.getParameter("examName"); 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 6625f57..0c9621b 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 @@ -9,11 +9,16 @@ public class StudentAnswerApi { public static class SaveAnswer { public static final String METHOD_NAME = "学生答题"; - public static final String METHOD_NOTE = "学生答题统一调用,调用成功,返回结果:0答案正确,1答案错误,-1系统错误"; + public static final String METHOD_NOTE = "学生答题统一调用,调用成功,返回结果:0答案正确,1答案错误,-1系统错误。状态码(code)1096:查不到指标"; 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_STARGE_ID="指标id"; } + public static class Submit { + public static final String METHOD_NAME = "学生提交成绩"; + public static final String METHOD_NOTE = "学生提交成绩,状态码(code)1097:禁止重复提交 "; + } + } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/AssessUserDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/AssessUserDto.java new file mode 100644 index 0000000..477a664 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/AssessUserDto.java @@ -0,0 +1,25 @@ +package com.blockchain.server.yyyf.dto; + +import com.blockchain.server.yyyf.entity.AssessUser; +import com.blockchain.server.yyyf.entity.AssessUserTarget; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author Mr.Xu + * @version 1.0 + * @className AssessUserDto + * @description + * @date 2020-05-14 22:07 + */ +@Data +public class AssessUserDto extends AssessUser implements Serializable { + private static final long serialVersionUID = -4573665667880888958L; + + /** + * 指标完成情况 + **/ + private List assessUserTargetList; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfStudentAnswerDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfStudentAnswerDto.java new file mode 100644 index 0000000..643c487 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/YyyfStudentAnswerDto.java @@ -0,0 +1,31 @@ +package com.blockchain.server.yyyf.dto; + +import com.blockchain.server.yyyf.entity.AssessUser; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author Mr.Xu + * @version 1.0 + * @className YyyfStudentAnswerDto + * @description + * @date 2020-05-14 22:52 + */ +@Data +public class YyyfStudentAnswerDto implements Serializable { + private static final long serialVersionUID = 505667820932379758L; + private String authorization="87DIVy348Oxzj3ha"; + private String sysType="130"; + private Integer userId; + private Double totalScore; + private Date startTime; + private Date endTime; + private int achievementType; + private String assessmentId; + private String caseId; + private String classId; + private String courseId; +} 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 c50f9bc..62f1f04 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 @@ -98,4 +98,11 @@ public class AssessUser implements Serializable { @Column(name = "user_name") private String userName; + /** + * 用户类型:0学生,1老师,2管理员 + */ + @Column(name = "user_Type") + private Integer userType; + + } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java index f6159a6..aabde4a 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/enums/UserEnums.java @@ -5,6 +5,7 @@ package com.blockchain.server.yyyf.enums; * @data 2019/2/21 20:53 */ public enum UserEnums { + NO_INDICATORS_FOUND(1096,"查不到指标","No indicators found","查不到指標"), 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_BIND_YYYF(1099, "该用户未绑定以渔有方或者以渔有方登录已失效", "The user does not bind yyyf", "該用戶未綁定以漁有方或者以漁有方登錄已失效"), 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 4f064eb..c6a0082 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 @@ -1,6 +1,7 @@ package com.blockchain.server.yyyf.mapper; +import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.dto.PractiseProDto; import com.blockchain.server.yyyf.entity.AssessUser; import org.apache.ibatis.annotations.Param; @@ -14,7 +15,7 @@ import java.util.Map; @Repository public interface AssessUserMapper extends Mapper { - int insert(AssessUser assessUser); + // int insert(AssessUser assessUser); void batchInsert(List assessUserList); @@ -41,4 +42,12 @@ public interface AssessUserMapper extends Mapper { void delAssessUserByIssueId(@Param("issueId") String issueId); + /** + * @description 通过AssessUserDtoLis批量更新AssessUser + * @author Mr.Xu + * @date 2020-05-15 00:08:17 + * @param [assessUserDtoList] + * @return void + **/ + void batchUpdateTotalScoreByAssessUserDtoList(@Param("assessUserDtoList") List assessUserDtoList); } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java index 3cd809c..94764a3 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserTargetMapper.java @@ -1,5 +1,6 @@ package com.blockchain.server.yyyf.mapper; +import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.entity.AssessUserTarget; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -12,5 +13,14 @@ public interface AssessUserTargetMapper extends Mapper { + /** + * @description 批量插入指标 + * @author Mr.Xu + * @date 2020-05-14 23:24:21 + * @param [list] + * @return void + **/ void batchInsert(@Param("list")List list); + + List selectAssessUserDtoByIssueId(@Param("issueId") String issueId); } 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 b6eadfe..3dfad42 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 @@ -3,9 +3,11 @@ package com.blockchain.server.yyyf.service; import com.blockchain.server.train.dto.TrainCaseTargetDto; +import com.blockchain.server.yyyf.dto.AssessUserDto; import com.blockchain.server.yyyf.dto.PractiseProDto; import com.blockchain.server.yyyf.entity.AssessUser; +import java.text.ParseException; import java.util.List; import java.util.Map; @@ -92,5 +94,39 @@ public interface AssessUserService { **/ void insert(AssessUser assessUser); + /** + * @description 初始化考核数据 + * @author Mr.Xu + * @date 2020-05-14 22:03:38 + * @param [assessUser, trainCaseTargeList] + * @return void + **/ void initAssessUser(AssessUser assessUser, List trainCaseTargeList ); + + /** + * @description 更新数据 + * @author Mr.Xu + * @date 2020-05-14 22:03:02 + * @param [assessUser] + * @return void + **/ + void update(AssessUser assessUser); + + /** + * @description 提交事务 + * @author Mr.Xu + * @date 2020-05-14 22:24:29 + * @param [assessUserId] + * @return void + **/ + AssessUserDto submit(String assessUserId); + + /** + * @description 批量同步成绩 + * @author Mr.Xu + * @date 2020-05-14 23:21:20 + * @param [issueId] + * @return void + **/ + void synchronousScore(String issueId); } 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 0012358..dea29ed 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 @@ -3,24 +3,36 @@ 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.AssessUserDto; +import com.blockchain.server.yyyf.dto.ExamDto; import com.blockchain.server.yyyf.dto.PractiseProDto; +import com.blockchain.server.yyyf.dto.YyyfStudentAnswerDto; import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.entity.AssessUserTarget; +import com.blockchain.server.yyyf.enums.UserEnums; +import com.blockchain.server.yyyf.exceprion.UserException; 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 com.blockchain.server.yyyf.utils.HttpClientUtil; import io.swagger.models.auth.In; +import lombok.SneakyThrows; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import tk.mybatis.mapper.entity.Example; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -35,6 +47,8 @@ import java.util.List; public class AssessUserServiceImpl implements AssessUserService { private static Logger LOG = LoggerFactory.getLogger(AssessUserServiceImpl.class); + @Autowired + private RedisTemplate redisTemplate; @Autowired private AssessUserMapper assessUserMapper; @@ -43,31 +57,37 @@ public class AssessUserServiceImpl implements AssessUserService { @Autowired private AssessUserTaskMapper assessUserTaskMapper; - private static final String durationUnit = "m";//时长单位 + + @Value("${yyyf.url}") + private String yyyfUrl; + @Value("${yyyf.assessment}") + private String assessment; + @Value("${yyyf.assessmentList}") + private String assessmentList; @Override - public List selectPractiseProList (String assessUserId){ + public List selectPractiseProList(String assessUserId) { return this.assessUserMapper.selectPractiseProList(assessUserId); } @Override public AssessUser selectScore(String issueId, Integer userId) { - return this.assessUserMapper.selectScore(issueId,userId); + return this.assessUserMapper.selectScore(issueId, userId); } @Override public List selectAssessUserListByIssuerIdAndUserId(String issueId, Integer userId) { - return this.assessUserMapper.selectAssessUserListByIssuerIdAndUserId(issueId,userId); + return this.assessUserMapper.selectAssessUserListByIssuerIdAndUserId(issueId, userId); } @Override public AssessUser selectAssessUserById(String assessUserId) { - return this.assessUserMapper.selectByPrimaryKey(assessUserId); + return this.assessUserMapper.selectByPrimaryKey(assessUserId); } @Override @@ -83,10 +103,10 @@ public class AssessUserServiceImpl implements AssessUserService { @Override public AssessUser selectAssessUserByUserIdAndissueIdForNotEnd(Integer userId, String issueId) { - Example example=new Example(AssessUser.class); + Example example = new Example(AssessUser.class); Example.Criteria criteria = example.createCriteria(); - criteria.andCondition(" user_id =",userId) - .andCondition(" issue_id = ",issueId) + criteria.andCondition(" user_id =", userId) + .andCondition(" issue_id = ", issueId) .andCondition(" end_time is null "); return this.assessUserMapper.selectOneByExample(example); } @@ -98,13 +118,13 @@ public class AssessUserServiceImpl implements AssessUserService { } @Override - public void initAssessUser(AssessUser assessUser, List trainCaseTargeList ) { + public void initAssessUser(AssessUser assessUser, List trainCaseTargeList) { - List list=new ArrayList<>(trainCaseTargeList.size()); - int j=1; - for(TrainCaseTargetDto trainCaseTargetDto :trainCaseTargeList){ - AssessUserTarget assessUserTarget=new AssessUserTarget(); - BeanUtils.copyProperties(trainCaseTargetDto,assessUserTarget); + List 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()); @@ -115,5 +135,107 @@ public class AssessUserServiceImpl implements AssessUserService { this.assessUserTargetMapper.batchInsert(list); } + @Override + public void update(AssessUser assessUser) { + this.assessUserMapper.updateByPrimaryKey(assessUser); + } + + + @SneakyThrows + @Override + public AssessUserDto submit(String assessUserId) { + AssessUser assessUser = this.selectAssessUserById(assessUserId); + + if (assessUser.getEndTime() != null) { + throw new UserException(UserEnums.PROHIBIT_DUPLICATE_SUBMISSION); + } + Double totalScore = 0d; + //获取指标信息 + Example example = new Example(AssessUserTarget.class); + Example.Criteria criteria = example.createCriteria(); + criteria.andCondition(" assess_user_id = ", assessUserId); + List assessUserTargetList = this.assessUserTargetMapper.selectByExample(example); + + for (AssessUserTarget assessUserTarget : assessUserTargetList) { + 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 duration = sdf.parse(sdf.format(now)).getTime() - sdf.parse(sdf.format(startTime)).getTime(); + assessUser.setDuration(Math.toIntExact(duration)); + if (assessUser.getUserType() == 0 && assessUser.getAchieveMentType() == 0) { + YyyfStudentAnswerDto yyyfStudentAnswerDto = new YyyfStudentAnswerDto(); + BeanUtils.copyProperties(assessUser, yyyfStudentAnswerDto); + yyyfStudentAnswerDto.setAssessmentId(assessUser.getIssueId()); + HttpClientUtil.doPostWithJSON(new StringBuilder().append(yyyfUrl).append(assessment).toString(), yyyfStudentAnswerDto); + } + + this.update(assessUser); + + AssessUserDto assessUserDto = new AssessUserDto(); + BeanUtils.copyProperties(assessUser, assessUserDto); + assessUserDto.setAssessUserTargetList(assessUserTargetList); + + return assessUserDto; + } + + @SneakyThrows + @Override + public void synchronousScore(String issueId) { + List assessUserDtoList = this.assessUserTargetMapper.selectAssessUserDtoByIssueId(issueId); + List updateAssessUserDtoList = new ArrayList<>(); + List yyyfStudentAnswerDtoList = new ArrayList<>(assessUserDtoList.size()); + + Date now = new Date(); + + for (AssessUserDto assessUserDto : assessUserDtoList) { + List assessUserTargetList = assessUserDto.getAssessUserTargetList(); + if (assessUserDto.getEndTime() == null) { + Double totalScore = 0d; + for (AssessUserTarget assessUserTarget : assessUserTargetList) { + Double taskScore = assessUserTarget.getTaskScore(); + if (assessUserTarget.getAnswer() == 0) { + totalScore += taskScore; + } + } + Date startTime = assessUserDto.getStartTime(); + assessUserDto.setTotalScore(totalScore); + assessUserDto.setEndTime(now); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //考试时长 + long duration = sdf.parse(sdf.format(now)).getTime() - sdf.parse(sdf.format(startTime)).getTime(); + assessUserDto.setDuration(Math.toIntExact(duration)); + updateAssessUserDtoList.add(assessUserDto); + } + YyyfStudentAnswerDto yyyfStudentAnswerDto = new YyyfStudentAnswerDto(); + BeanUtils.copyProperties(assessUserDto, yyyfStudentAnswerDto); + yyyfStudentAnswerDto.setAssessmentId(issueId); + yyyfStudentAnswerDtoList.add(yyyfStudentAnswerDto); + + redisTemplate.delete(YyyfConstant.CASE_KEY + assessUserDto.getUserId()); + } + + //获取考核信息 + HashOperations examDtoOpsForHash = redisTemplate.opsForHash(); + // 获取所有参加考核学生信息 + HashOperations> studentOpsForHash = redisTemplate.opsForHash(); + studentOpsForHash.delete(YyyfConstant.JOIN_EXAM_STU_IDS_KEY, issueId); + examDtoOpsForHash.delete(YyyfConstant.EXAM_KEY, issueId); + + if (updateAssessUserDtoList.size() > 0) + this.assessUserMapper.batchUpdateTotalScoreByAssessUserDtoList(assessUserDtoList); + + HttpClientUtil.doPostWithJSON(new StringBuilder().append(yyyfUrl).append(assessmentList).toString(), yyyfStudentAnswerDtoList); + + } + } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java new file mode 100644 index 0000000..4ce757c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ScheduleTask.java @@ -0,0 +1,56 @@ +package com.blockchain.server.yyyf.task; + +import com.blockchain.common.base.constant.YyyfConstant; +import com.blockchain.server.yyyf.dto.ExamDto; +import com.blockchain.server.yyyf.service.AssessUserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; + +import java.util.Date; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * @author Mr.Xu + * @version 1.0 + * @className ScheduleTask + * @description + * @date 2020-05-14 23:16 + */ +@Configuration +@EnableScheduling +public class ScheduleTask { + private Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired + private AssessUserService assessUserService; + + @Autowired + private RedisTemplate redisTemplate; + + @Scheduled(initialDelay = 5000,fixedRate=60000) + private void OneMinuteTask() { + logger.info("开始扫描考试"+ new Date()); + HashOperations examDtoOpsForHash = redisTemplate.opsForHash(); + Map examDtoMap = examDtoOpsForHash.entries(YyyfConstant.EXAM_KEY); + Set> entries = examDtoMap.entrySet(); + Iterator> iterator = entries.iterator(); + Date now =new Date(); + logger.info("size is " + entries.size() ); + while(iterator.hasNext()){ + Map.Entry next = iterator.next(); + ExamDto examDto = next.getValue(); + Date endTime = examDto.getEndTime(); + if(now.after(endTime)){ + this.assessUserService.synchronousScore(examDto.getExamId()); + } + } + logger.info("完成扫描考试"+ new Date()); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/HttpClientUtil.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/HttpClientUtil.java new file mode 100644 index 0000000..967535a --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/utils/HttpClientUtil.java @@ -0,0 +1,259 @@ +package com.blockchain.server.yyyf.utils; + +import com.alibaba.fastjson.JSON; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.*; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author huan.xu + * @version 1.0 + * @className HttpClientUtil + * @description + * @date 2019-11-12 17:33 + */ +public class HttpClientUtil { + + private static final CloseableHttpClient httpClient; + private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientUtil.class); + public static final String CHARSET = "UTF-8"; + + static { + RequestConfig config = RequestConfig.custom().setConnectTimeout(60000).setSocketTimeout(15000).build(); + httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); + } + + public static String doGet(String url, Map params) { + return doGet(url, params, CHARSET); + } + + public static String doPost(String url, Map params) { + return doPost(url, params, CHARSET); + } + + public static String doPostWithJSON(String url, Object params) throws Exception { + return doPostWithJSON(url, params, CHARSET); + } + + public static String doPutWithJSON(String url, Object params) throws Exception { + return doPutWithJSON(url, params, CHARSET); + } + + public static String doDeleteWithJSON(String url, Object params) throws Exception { + return doDeleteWithJSON(url, params, CHARSET); + } + + + /** + * HTTP Get 获取内容 + * + * @param url 请求的url地址 ?之前的地址 + * @param params 请求的参数 + * @param charset 编码格式 + * @return 页面内容 + */ + public static String doGet(String url, Map params, String charset) { + if (StringUtils.isBlank(url)) { + return null; + } + try { + if (params != null && !params.isEmpty()) { + List pairs = new ArrayList(params.size()); + for (Map.Entry entry : params.entrySet()) { + String value = entry.getValue(); + if (value != null) { + pairs.add(new BasicNameValuePair(entry.getKey(), value)); + } + } + url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset)); + } + HttpGet httpGet = new HttpGet(url); + CloseableHttpResponse response = httpClient.execute(httpGet); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + httpGet.abort(); + throw new RuntimeException("HttpClient,error status code :" + statusCode); + } + HttpEntity entity = response.getEntity(); + String result = null; + if (entity != null) { + result = EntityUtils.toString(entity, "utf-8"); + } + EntityUtils.consume(entity); + response.close(); + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * HTTP Post 获取内容 + * + * @param url 请求的url地址 ?之前的地址 + * @param params 请求的参数 + * @param charset 编码格式 + * @return 页面内容 + */ + public static String doPost(String url, Map params, String charset) { + if (StringUtils.isBlank(url)) { + return null; + } + try { + List pairs = null; + if (params != null && !params.isEmpty()) { + pairs = new ArrayList<>(params.size()); + for (Map.Entry entry : params.entrySet()) { + String value = entry.getValue(); + if (value != null) { + pairs.add(new BasicNameValuePair(entry.getKey(), value)); + } + } + } + HttpPost httpPost = new HttpPost(url); + if (pairs != null && pairs.size() > 0) { + httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET)); + } + CloseableHttpResponse response = httpClient.execute(httpPost); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + httpPost.abort(); + throw new RuntimeException("HttpClient,error status code :" + statusCode); + } + HttpEntity entity = response.getEntity(); + String result = null; + if (entity != null) { + result = EntityUtils.toString(entity, "utf-8"); + } + EntityUtils.consume(entity); + response.close(); + return result; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * json post + * + * @author: fengyu.wang + * @date: 2017-10-27 16:14:47 + */ + public static String doPostWithJSON(String url, Object params, String charset) throws Exception { + LOGGER.info("doPostWithJSON -- URL:" + url); + HttpPost httpPost = new HttpPost(url); + + StringEntity entity = new StringEntity(JSON.toJSONString(params), charset); + LOGGER.info("doPostWithJSON -- params:" + JSON.toJSONString(params)); + entity.setContentEncoding(charset); + entity.setContentType("application/json"); + httpPost.setEntity(entity); + + HttpResponse response = httpClient.execute(httpPost); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + httpPost.abort(); + throw new RuntimeException("HttpClient,error status code :" + statusCode); + } + HttpEntity responseEntity = response.getEntity(); + String respContent = EntityUtils.toString(responseEntity, charset); + LOGGER.info("doPostWithJSON -- respContent:" + respContent); + return respContent; + } + + + /** + * 方法 doPostWithJSON 功能: json put + * + * @author ningning.jiang 2017年10月30日 17:11:28 + */ + public static String doPutWithJSON(String url, Object params, String charset) throws Exception { + LOGGER.info("doPutWithJSON -- URL:" + url); + HttpPut httpPut = new HttpPut(url); + + StringEntity entity = new StringEntity(JSON.toJSONString(params), charset); + LOGGER.info("doPutWithJSON -- params:" + JSON.toJSONString(params)); + entity.setContentEncoding(charset); + entity.setContentType("application/json"); + httpPut.setEntity(entity); + + HttpResponse response = httpClient.execute(httpPut); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + httpPut.abort(); + throw new RuntimeException("HttpClient,error status code :" + statusCode); + } + HttpEntity responseEntity = response.getEntity(); + String respContent = EntityUtils.toString(responseEntity, charset); + LOGGER.info("doPutWithJSON -- respContent:" + respContent); + return respContent; + } + + /** + * 方法 doPutWithJSON 功能:delete json + * + * @author ningning.jiang 2017年10月31日 08:46:44 + */ + public static String doDeleteWithJSON(String url, Object params, String charset) throws Exception { + LOGGER.info("doDeleteWithJSON -- URL:" + url); + HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(url); + + StringEntity entity = new StringEntity(JSON.toJSONString(params), charset); + LOGGER.info("doDeleteWithJSON -- params:" + JSON.toJSONString(params)); + entity.setContentEncoding(charset); + entity.setContentType("application/json"); + httpDelete.setEntity(entity); + + HttpResponse response = httpClient.execute(httpDelete); + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + httpDelete.abort(); + throw new RuntimeException("HttpClient,error status code :" + statusCode); + } + HttpEntity responseEntity = response.getEntity(); + String respContent = EntityUtils.toString(responseEntity, charset); + LOGGER.info("doDeleteWithJSON -- respContent:" + respContent); + return respContent; + } +} + +class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { + + private static final String METHOD_NAME = "DELETE"; + + public String getMethod() { + return METHOD_NAME; + } + + public HttpDeleteWithBody(final String uri) { + super(); + setURI(URI.create(uri)); + } + + public HttpDeleteWithBody(final URI uri) { + super(); + setURI(uri); + } + + public HttpDeleteWithBody() { + super(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml index 7a4767b..ec64404 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml @@ -104,26 +104,7 @@ t.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( - #{id}, - #{trainId}, - #{issueId}, - #{ssPractiseId}, - #{userId}, - #{userName}, - #{totalScore}, - #{duration}, - #{durationUnit}, - #{startTime}, - #{endTime}, - #{caseId}, - #{achieveMentType}, - #{classId}, - #{courseId} - ) - + insert into yyyf_server_assess_user @@ -149,6 +130,14 @@ + + + update yyyf_server_assess_user + set total_score = #{item.totalScore,jdbcType=DECIMAL}, duration = #{item.duration,jdbcType=INTEGER},end_time = #{item.endTime,jdbcType=TIMESTAMP} + where id = #{item.id,jdbcType=VARCHAR} + + + delete from yyyf_server_assess_user where issue_id=#{issueId} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml index c87da3d..f110943 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserTargetMapper.xml @@ -10,43 +10,41 @@ --> - - - and t.id=#{id,jdbcType=VARCHAR} - - - and t.assess_user_id=#{assessUserId,jdbcType=VARCHAR} - - - and t.project_name=#{projectName,jdbcType=VARCHAR} - - - and t.project_id=#{projectId,jdbcType=VARCHAR} - - - and t.project_score=#{projectScore,jdbcType=NUMERIC} - - - and t.duration=#{duration,jdbcType=INTEGER} - - - and t.duration_unit=#{durationUnit,jdbcType=VARCHAR} - - - and t.project_case_desc=#{projectCaseDesc,jdbcType=VARCHAR} - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - t.id, - t.assess_user_id, - t.project_name, - t.project_id, - t.project_score, - t.duration, - t.duration_unit, - t.project_case_desc, - insert into yyyf_server_assess_user_target @@ -63,4 +61,40 @@ + + \ No newline at end of file