| | |
| | | */ |
| | | @Override |
| | | public Result add(ExamTemplateForm form) { |
| | | ExamTemplate entity = ExamTemplateForm.getEntityByForm(form, null); |
| | | User currentUser = webContext.getCurrentUser(); |
| | | entity.setCreateUser(currentUser.getId()); |
| | | entity.setCreateTime(new Date()); |
| | | if(!StringUtils.isEmpty(entity.getVisibility())) { |
| | | entity.setVisibility(VisibilityEnum.fromCode(entity.getVisibility()).getName()); |
| | | } |
| | | List<TemplateQuestionDTO> questionList = form.getQuestionList(); |
| | | BigDecimal score = BigDecimal.ZERO; |
| | | //设置题目信息 |
| | | for (TemplateQuestionDTO dto : questionList) { |
| | | score = score.add(dto.getScore().multiply(BigDecimal.valueOf(dto.getNum()))); |
| | | Integer questionType = dto.getQuestionType(); |
| | | switch (QuestionTypeEnum.fromCode(questionType)){ |
| | | //单选 |
| | | case SingleChoice: |
| | | entity.setSingleChoice(dto.getNum()); |
| | | entity.setSingleScore(dto.getScore()); |
| | | break; |
| | | //多选 |
| | | case MultipleChoice: |
| | | entity.setMultipleChoice(dto.getNum()); |
| | | entity.setMultipleScore(dto.getScore()); |
| | | break; |
| | | //判断 |
| | | case TrueFalse: |
| | | entity.setTrueFalse(dto.getNum()); |
| | | entity.setTrueFalseScore(dto.getScore()); |
| | | break; |
| | | //填空 |
| | | case GapFilling: |
| | | entity.setGapFilling(dto.getNum()); |
| | | entity.setGapScore(dto.getScore()); |
| | | break; |
| | | //简答 |
| | | case ShortAnswer: |
| | | entity.setShortAnswer(dto.getNum()); |
| | | entity.setShortAnswerScore(dto.getScore()); |
| | | break; |
| | | //计算 |
| | | case Calculation: |
| | | entity.setCalculation(dto.getNum()); |
| | | entity.setCalculationScore(dto.getScore()); |
| | | break; |
| | | } |
| | | } |
| | | entity.setScore(score); |
| | | baseMapper.insert(entity); |
| | | // ExamTemplate entity = ExamTemplateForm.getEntityByForm(form, null); |
| | | // User currentUser = webContext.getCurrentUser(); |
| | | // entity.setCreateUser(currentUser.getId()); |
| | | // entity.setCreateTime(new Date()); |
| | | // if(!StringUtils.isEmpty(entity.getVisibility())) { |
| | | // entity.setVisibility(VisibilityEnum.fromCode(entity.getVisibility()).getName()); |
| | | // } |
| | | // List<TemplateQuestionDTO> questionList = form.getQuestionList(); |
| | | // BigDecimal score = BigDecimal.ZERO; |
| | | // //设置题目信息 |
| | | // for (TemplateQuestionDTO dto : questionList) { |
| | | // score = score.add(dto.getScore().multiply(BigDecimal.valueOf(dto.getNum()))); |
| | | // Integer questionType = dto.getQuestionType(); |
| | | // switch (QuestionTypeEnum.fromCode(questionType)){ |
| | | // //单选 |
| | | // case SingleChoice: |
| | | // entity.setSingleChoice(dto.getNum()); |
| | | // entity.setSingleScore(dto.getScore()); |
| | | // break; |
| | | // //多选 |
| | | // case MultipleChoice: |
| | | // entity.setMultipleChoice(dto.getNum()); |
| | | // entity.setMultipleScore(dto.getScore()); |
| | | // break; |
| | | // //判断 |
| | | // case TrueFalse: |
| | | // entity.setTrueFalse(dto.getNum()); |
| | | // entity.setTrueFalseScore(dto.getScore()); |
| | | // break; |
| | | // //填空 |
| | | // case GapFilling: |
| | | // entity.setGapFilling(dto.getNum()); |
| | | // entity.setGapScore(dto.getScore()); |
| | | // break; |
| | | // //简答 |
| | | // case ShortAnswer: |
| | | // entity.setShortAnswer(dto.getNum()); |
| | | // entity.setShortAnswerScore(dto.getScore()); |
| | | // break; |
| | | // //计算 |
| | | // case Calculation: |
| | | // entity.setCalculation(dto.getNum()); |
| | | // entity.setCalculationScore(dto.getScore()); |
| | | // break; |
| | | // } |
| | | // } |
| | | // entity.setScore(score); |
| | | // baseMapper.insert(entity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result update(ExamTemplateForm form) { |
| | | ExamTemplate entity = ExamTemplateForm.getEntityByForm(form, null); |
| | | if(!StringUtils.isEmpty(entity.getVisibility())) { |
| | | entity.setVisibility(VisibilityEnum.fromCode(entity.getVisibility()).getName()); |
| | | } |
| | | List<TemplateQuestionDTO> questionList = form.getQuestionList(); |
| | | BigDecimal score = BigDecimal.ZERO; |
| | | //设置题目信息 |
| | | for (TemplateQuestionDTO dto : questionList) { |
| | | score = score.add(dto.getScore().multiply(BigDecimal.valueOf(dto.getNum()))); |
| | | Integer questionType = dto.getQuestionType(); |
| | | switch (QuestionTypeEnum.fromCode(questionType)){ |
| | | //单选 |
| | | case SingleChoice: |
| | | entity.setSingleChoice(dto.getNum()); |
| | | entity.setSingleScore(dto.getScore()); |
| | | break; |
| | | //多选 |
| | | case MultipleChoice: |
| | | entity.setMultipleChoice(dto.getNum()); |
| | | entity.setMultipleScore(dto.getScore()); |
| | | break; |
| | | //判断 |
| | | case TrueFalse: |
| | | entity.setTrueFalse(dto.getNum()); |
| | | entity.setTrueFalseScore(dto.getScore()); |
| | | break; |
| | | //填空 |
| | | case GapFilling: |
| | | entity.setGapFilling(dto.getNum()); |
| | | entity.setGapScore(dto.getScore()); |
| | | break; |
| | | //简答 |
| | | case ShortAnswer: |
| | | entity.setShortAnswer(dto.getNum()); |
| | | entity.setShortAnswerScore(dto.getScore()); |
| | | break; |
| | | //计算 |
| | | case Calculation: |
| | | entity.setCalculation(dto.getNum()); |
| | | entity.setCalculationScore(dto.getScore()); |
| | | break; |
| | | } |
| | | } |
| | | entity.setScore(score); |
| | | examTemplateMapper.removeById(entity.getId()); |
| | | baseMapper.insert(entity); |
| | | return Result.ok("修改成功"); |
| | | // ExamTemplate entity = ExamTemplateForm.getEntityByForm(form, null); |
| | | // if(!StringUtils.isEmpty(entity.getVisibility())) { |
| | | // entity.setVisibility(VisibilityEnum.fromCode(entity.getVisibility()).getName()); |
| | | // } |
| | | // List<TemplateQuestionDTO> questionList = form.getQuestionList(); |
| | | // BigDecimal score = BigDecimal.ZERO; |
| | | // //设置题目信息 |
| | | // for (TemplateQuestionDTO dto : questionList) { |
| | | // score = score.add(dto.getScore().multiply(BigDecimal.valueOf(dto.getNum()))); |
| | | // Integer questionType = dto.getQuestionType(); |
| | | // switch (QuestionTypeEnum.fromCode(questionType)){ |
| | | // //单选 |
| | | // case SingleChoice: |
| | | // entity.setSingleChoice(dto.getNum()); |
| | | // entity.setSingleScore(dto.getScore()); |
| | | // break; |
| | | // //多选 |
| | | // case MultipleChoice: |
| | | // entity.setMultipleChoice(dto.getNum()); |
| | | // entity.setMultipleScore(dto.getScore()); |
| | | // break; |
| | | // //判断 |
| | | // case TrueFalse: |
| | | // entity.setTrueFalse(dto.getNum()); |
| | | // entity.setTrueFalseScore(dto.getScore()); |
| | | // break; |
| | | // //填空 |
| | | // case GapFilling: |
| | | // entity.setGapFilling(dto.getNum()); |
| | | // entity.setGapScore(dto.getScore()); |
| | | // break; |
| | | // //简答 |
| | | // case ShortAnswer: |
| | | // entity.setShortAnswer(dto.getNum()); |
| | | // entity.setShortAnswerScore(dto.getScore()); |
| | | // break; |
| | | // //计算 |
| | | // case Calculation: |
| | | // entity.setCalculation(dto.getNum()); |
| | | // entity.setCalculationScore(dto.getScore()); |
| | | // break; |
| | | // } |
| | | // } |
| | | // entity.setScore(score); |
| | | // examTemplateMapper.removeById(entity.getId()); |
| | | // baseMapper.insert(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | |
| | | List<ExamTemplate> records = page.getRecords(); |
| | | List<ExamTemplateVO> vos = new ArrayList<>(); |
| | | for (ExamTemplate examTemplate : records) { |
| | | ExamTemplateVO vo = new ExamTemplateVO(); |
| | | BeanUtils.copyProperties(examTemplate,vo); |
| | | String visibility = vo.getVisibility(); |
| | | vo.setVisibility(VisibilityEnum.valueOf(visibility).getCode()+""); |
| | | //整理题目信息为集合 |
| | | List<TemplateQuestionDTO> questionList = new ArrayList<>(); |
| | | addQuestionList(questionList,QuestionTypeEnum.SingleChoice.getCode(),examTemplate.getSingleScore(),examTemplate.getSingleChoice()); |
| | | addQuestionList(questionList,QuestionTypeEnum.MultipleChoice.getCode(),examTemplate.getMultipleScore(),examTemplate.getMultipleChoice()); |
| | | addQuestionList(questionList,QuestionTypeEnum.TrueFalse.getCode(),examTemplate.getTrueFalseScore(),examTemplate.getTrueFalse()); |
| | | addQuestionList(questionList,QuestionTypeEnum.GapFilling.getCode(),examTemplate.getGapScore(),examTemplate.getGapFilling()); |
| | | addQuestionList(questionList,QuestionTypeEnum.ShortAnswer.getCode(),examTemplate.getShortAnswerScore(),examTemplate.getShortAnswer()); |
| | | addQuestionList(questionList,QuestionTypeEnum.Calculation.getCode(),examTemplate.getCalculationScore(),examTemplate.getCalculation()); |
| | | vo.setQuestionList(questionList); |
| | | vos.add(vo); |
| | | // ExamTemplateVO vo = new ExamTemplateVO(); |
| | | // BeanUtils.copyProperties(examTemplate,vo); |
| | | // String visibility = vo.getVisibility(); |
| | | // vo.setVisibility(VisibilityEnum.valueOf(visibility).getCode()+""); |
| | | // //整理题目信息为集合 |
| | | // List<TemplateQuestionDTO> questionList = new ArrayList<>(); |
| | | // addQuestionList(questionList,QuestionTypeEnum.SingleChoice.getCode(),examTemplate.getSingleScore(),examTemplate.getSingleChoice()); |
| | | // addQuestionList(questionList,QuestionTypeEnum.MultipleChoice.getCode(),examTemplate.getMultipleScore(),examTemplate.getMultipleChoice()); |
| | | // addQuestionList(questionList,QuestionTypeEnum.TrueFalse.getCode(),examTemplate.getTrueFalseScore(),examTemplate.getTrueFalse()); |
| | | // addQuestionList(questionList,QuestionTypeEnum.GapFilling.getCode(),examTemplate.getGapScore(),examTemplate.getGapFilling()); |
| | | // addQuestionList(questionList,QuestionTypeEnum.ShortAnswer.getCode(),examTemplate.getShortAnswerScore(),examTemplate.getShortAnswer()); |
| | | // addQuestionList(questionList,QuestionTypeEnum.Calculation.getCode(),examTemplate.getCalculationScore(),examTemplate.getCalculation()); |
| | | // vo.setQuestionList(questionList); |
| | | // vos.add(vo); |
| | | } |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | } |