|
@@ -0,0 +1,297 @@
|
|
|
+package com.zhongzheng.modules.bank.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.bank.bo.*;
|
|
|
+import com.zhongzheng.modules.bank.domain.QuestionOld;
|
|
|
+import com.zhongzheng.modules.bank.domain.QuestionOldChild;
|
|
|
+import com.zhongzheng.modules.bank.domain.QuestionOldOptions;
|
|
|
+import com.zhongzheng.modules.bank.domain.QuestionOther;
|
|
|
+import com.zhongzheng.modules.bank.mapper.QuestionOtherMapper;
|
|
|
+import com.zhongzheng.modules.bank.service.IExamService;
|
|
|
+import com.zhongzheng.modules.bank.service.IQuestionOtherService;
|
|
|
+import com.zhongzheng.modules.bank.service.IQuestionService;
|
|
|
+import com.zhongzheng.modules.bank.vo.ExamVo;
|
|
|
+import com.zhongzheng.modules.bank.vo.QuestionOtherVo;
|
|
|
+import com.zhongzheng.modules.course.service.ICourseMenuExamService;
|
|
|
+import com.zhongzheng.modules.order.domain.OrderGoods;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 第三方题库Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2023-08-03
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class QuestionOtherServiceImpl extends ServiceImpl<QuestionOtherMapper, QuestionOther> implements IQuestionOtherService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQuestionService iQuestionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IExamService iExamService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public QuestionOtherVo queryById(Long id){
|
|
|
+ QuestionOther db = this.baseMapper.selectById(id);
|
|
|
+ JSONObject jsonObject = (JSONObject) JSONObject.parse(db.getJsonStr());
|
|
|
+ List<QuestionOld> qList = JSONArray.parseArray(String.valueOf(jsonObject.get("data")),QuestionOld.class);
|
|
|
+ if (!db.getJsonStr().contains("\"msg\":\"获取成功\"")) {
|
|
|
+ throw new CustomException("同步请求错误");
|
|
|
+ }
|
|
|
+ int i = 1;
|
|
|
+ List<ExamQuestionAddBo> qIdList = new ArrayList<>();
|
|
|
+ for(QuestionOld old : qList){
|
|
|
+ QuestionAddBo childAddBo = new QuestionAddBo();
|
|
|
+ String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
+ childAddBo.setStatus(1);
|
|
|
+ childAddBo.setContent(old.getTitle());
|
|
|
+ childAddBo.setSdQid(old.getSdQid());
|
|
|
+ childAddBo.setImportNo(importNo);
|
|
|
+ childAddBo.setCreateTime(DateUtils.getNowTime());
|
|
|
+ childAddBo.setCreateBy("admin");
|
|
|
+ childAddBo.setPublishStatus(1);
|
|
|
+ if(old.getQuiztype()==1){
|
|
|
+ childAddBo.setType(1);
|
|
|
+ }
|
|
|
+ else if(old.getQuiztype()==2){
|
|
|
+ childAddBo.setType(2);
|
|
|
+ }
|
|
|
+ else if(old.getQuiztype()==4){
|
|
|
+ childAddBo.setType(3);
|
|
|
+ }
|
|
|
+ else if(old.getQuiztype()==5){
|
|
|
+ childAddBo.setType(4);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(old.getQuiztype()<3){
|
|
|
+ childAddBo.setAnalysisContent(old.getAnalysis());
|
|
|
+ String answerQuestion="";
|
|
|
+ List<QuestionChildAddBo> optionsList = new ArrayList<>();
|
|
|
+ for(QuestionOldOptions options : old.getOptions()){
|
|
|
+ QuestionChildAddBo addBo = new QuestionChildAddBo();
|
|
|
+ addBo.setContent(options.getOptiontitle());
|
|
|
+ addBo.setOptionsId(dealOptions(options.getSerialnum()));
|
|
|
+ if(options.getIsanswer()){
|
|
|
+ answerQuestion+=options.getSerialnum();
|
|
|
+ }
|
|
|
+ optionsList.add(addBo);
|
|
|
+ }
|
|
|
+ childAddBo.setOptionsList(optionsList);
|
|
|
+ childAddBo.setAnswerQuestion(dealImportAnswer(answerQuestion));
|
|
|
+ }
|
|
|
+ else if(old.getQuiztype()==4){
|
|
|
+ childAddBo.setAnalysisContent(old.getAnalysis());
|
|
|
+ String answerQuestion="";
|
|
|
+ for(QuestionOldOptions options : old.getOptions()){
|
|
|
+ if(options.getIsanswer()){
|
|
|
+ if(options.getSerialnum().equals("A")){
|
|
|
+ answerQuestion = "1";
|
|
|
+ }else{
|
|
|
+ answerQuestion = "0";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ childAddBo.setAnswerQuestion(answerQuestion);
|
|
|
+ }
|
|
|
+ else if(old.getQuiztype()==5){
|
|
|
+ List<QuestionChildAddBo> optionsList = new ArrayList<>();
|
|
|
+ for(QuestionOldChild oldChild :old.getChildlist()){
|
|
|
+ QuestionChildAddBo addBo = new QuestionChildAddBo();
|
|
|
+ addBo.setContent(oldChild.getTitle());
|
|
|
+ if(oldChild.getQuiztype()==1){
|
|
|
+ addBo.setType(1);
|
|
|
+ }
|
|
|
+ else if(oldChild.getQuiztype()==2){
|
|
|
+ addBo.setType(2);
|
|
|
+ }
|
|
|
+ else if(oldChild.getQuiztype()==4){
|
|
|
+ addBo.setType(3);
|
|
|
+ }
|
|
|
+ addBo.setAnalysisContent(oldChild.getAnalysis());
|
|
|
+ if(oldChild.getQuiztype()<3){
|
|
|
+ String answerQuestion="";
|
|
|
+ List<QuestionOptionsAddBo> optionsItemList = new ArrayList<>();
|
|
|
+ for(QuestionOldOptions options : oldChild.getOptions()){
|
|
|
+ QuestionOptionsAddBo addChildBo = new QuestionOptionsAddBo();
|
|
|
+ addChildBo.setContent(options.getOptiontitle());
|
|
|
+ addChildBo.setOptionsId(dealOptions(options.getSerialnum()));
|
|
|
+ if(options.getIsanswer()){
|
|
|
+ answerQuestion+=options.getSerialnum();
|
|
|
+ }
|
|
|
+ optionsItemList.add(addChildBo);
|
|
|
+ }
|
|
|
+ addBo.setOptionsList(optionsItemList);
|
|
|
+ addBo.setAnswerQuestion(dealImportAnswer(answerQuestion));
|
|
|
+ }
|
|
|
+ else if(oldChild.getQuiztype()==4){
|
|
|
+ String answerQuestion="";
|
|
|
+ for(QuestionOldOptions options : oldChild.getOptions()){
|
|
|
+ if(options.getIsanswer()){
|
|
|
+ if(options.getSerialnum().equals("A")){
|
|
|
+ answerQuestion = "1";
|
|
|
+ }else{
|
|
|
+ answerQuestion = "0";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addBo.setAnswerQuestion(answerQuestion);
|
|
|
+ }
|
|
|
+ optionsList.add(addBo);
|
|
|
+ }
|
|
|
+ childAddBo.setOptionsList(optionsList);
|
|
|
+ }
|
|
|
+ childAddBo.setFromPlat(2);
|
|
|
+ Long qId = iQuestionService.insertByAddBoImportBackId(childAddBo,i);
|
|
|
+ ExamQuestionAddBo questionAddBo = new ExamQuestionAddBo();
|
|
|
+ questionAddBo.setQuestionId(qId);
|
|
|
+ questionAddBo.setSort(i);
|
|
|
+ qIdList.add(questionAddBo);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ ExamAddBo examAddBo = new ExamAddBo();
|
|
|
+ examAddBo.setExamName("七大员新考试卷");
|
|
|
+ examAddBo.setDoType(1);
|
|
|
+ examAddBo.setStatus(1);
|
|
|
+ examAddBo.setPublishStatus(1L);
|
|
|
+ examAddBo.setQuestionList(qIdList);
|
|
|
+ ExamVo examVo = iExamService.insertByAddBo(examAddBo);
|
|
|
+ QuestionOtherEditBo editBo = new QuestionOtherEditBo();
|
|
|
+ editBo.setId(id);
|
|
|
+ editBo.setExamId(examVo.getExamId());
|
|
|
+ updateByEditBo(editBo);
|
|
|
+ return BeanUtil.toBean(db, QuestionOtherVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long queryByUserMajor(Long userId, String majorname) {
|
|
|
+ QuestionOther questionOther = getOne(new LambdaQueryWrapper<QuestionOther>()
|
|
|
+ .eq(QuestionOther::getUserId, userId).eq(QuestionOther::getMajorname, majorname)
|
|
|
+ .eq(QuestionOther::getStatus, 1));
|
|
|
+ if(Validator.isNotEmpty(questionOther)){
|
|
|
+ return questionOther.getExamId();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long dealOptions(String v) {
|
|
|
+ if ("A".equals(v)) {
|
|
|
+ return 1L;
|
|
|
+ } else if ("B".equals(v)) {
|
|
|
+ return 2L;
|
|
|
+ } else if ("C".equals(v)) {
|
|
|
+ return 3L;
|
|
|
+ } else if ("D".equals(v)) {
|
|
|
+ return 4L;
|
|
|
+ } else if ("E".equals(v)) {
|
|
|
+ return 5L;
|
|
|
+ } else if ("F".equals(v)) {
|
|
|
+ return 6L;
|
|
|
+ }
|
|
|
+ return 99L;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String dealImportAnswer(String Answer) {
|
|
|
+ String[] itemArray = Answer.split("");
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String v : itemArray) {
|
|
|
+ if ("A".equals(v)) {
|
|
|
+ list.add("1");
|
|
|
+ } else if ("B".equals(v)) {
|
|
|
+ list.add("2");
|
|
|
+ } else if ("C".equals(v)) {
|
|
|
+ list.add("3");
|
|
|
+ } else if ("D".equals(v)) {
|
|
|
+ list.add("4");
|
|
|
+ } else if ("E".equals(v)) {
|
|
|
+ list.add("5");
|
|
|
+ } else if ("F".equals(v)) {
|
|
|
+ list.add("6");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return String.join(",", list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<QuestionOtherVo> queryList(QuestionOtherQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<QuestionOther> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getUserId() != null, QuestionOther::getUserId, bo.getUserId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getMajorname()), QuestionOther::getMajorname, bo.getMajorname());
|
|
|
+ lqw.eq(bo.getStatus() != null, QuestionOther::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getJsonStr()), QuestionOther::getJsonStr, bo.getJsonStr());
|
|
|
+ lqw.eq(bo.getFromPlat() != null, QuestionOther::getFromPlat, bo.getFromPlat());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<QuestionOtherVo> entity2Vo(Collection<QuestionOther> collection) {
|
|
|
+ List<QuestionOtherVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, QuestionOtherVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<QuestionOther> page = (Page<QuestionOther>)collection;
|
|
|
+ Page<QuestionOtherVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(QuestionOtherAddBo bo) {
|
|
|
+ QuestionOther add = BeanUtil.toBean(bo, QuestionOther.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(QuestionOtherEditBo bo) {
|
|
|
+ QuestionOther update = BeanUtil.toBean(bo, QuestionOther.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(QuestionOther entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|