Pārlūkot izejas kodu

feat(server): 下一题流程

Go 4 gadi atpakaļ
vecāks
revīzija
f9be8a0d75

+ 19 - 0
server/data/src/main/java/com/qxgmat/data/constants/enums/SettingKey.java

@@ -1,5 +1,8 @@
 package com.qxgmat.data.constants.enums;
 
+import com.qxgmat.data.constants.enums.module.PaperModule;
+import com.qxgmat.data.constants.enums.module.QuestionModule;
+
 /**
  * Created by gaojie on 2017/11/19.
  */
@@ -23,4 +26,20 @@ public enum SettingKey {
     private SettingKey(String key){
         this.key = key;
     }
+
+    /**
+     * 根据组卷模块获取对应时间
+     * @param module
+     * @return
+     */
+    public static SettingKey getTimeByPaperModule(PaperModule module){
+        switch (module){
+            case EXAMINATION:
+                return EXAMINATION_TIME;
+            case EXERCISE:
+                return EXERCISE_TIME;
+            default:
+                return null;
+        }
+    }
 }

+ 109 - 39
server/data/src/main/java/com/qxgmat/data/dao/entity/UserPaper.java

@@ -30,6 +30,12 @@ public class UserPaper implements Serializable {
     private String module;
 
     /**
+     * 组卷扩展:examination, exercise
+     */
+    @Column(name = "`module_extend`")
+    private String moduleExtend;
+
+    /**
      * 对应模块id
      */
     @Column(name = "`module_id`")
@@ -48,22 +54,28 @@ public class UserPaper implements Serializable {
     private Integer times;
 
     /**
-     * 时间
+     * 单次时间:系统时间
      */
     @Column(name = "`time`")
     private Integer time;
 
     /**
-     * 用户做题时间-累计
+     * 总作答时间
+     */
+    @Column(name = "`total_time`")
+    private Integer totalTime;
+
+    /**
+     * 总作答次数
      */
-    @Column(name = "`user_time`")
-    private Integer userTime;
+    @Column(name = "`total_number`")
+    private Integer totalNumber;
 
     /**
-     * 正确总题数-累计
+     * 总正确次数
      */
-    @Column(name = "`correct_number`")
-    private Integer correctNumber;
+    @Column(name = "`total_correct`")
+    private Integer totalCorrect;
 
     /**
      * 删除时间
@@ -148,6 +160,24 @@ public class UserPaper implements Serializable {
     }
 
     /**
+     * 获取组卷扩展:examination, exercise
+     *
+     * @return module_extend - 组卷扩展:examination, exercise
+     */
+    public String getModuleExtend() {
+        return moduleExtend;
+    }
+
+    /**
+     * 设置组卷扩展:examination, exercise
+     *
+     * @param moduleExtend 组卷扩展:examination, exercise
+     */
+    public void setModuleExtend(String moduleExtend) {
+        this.moduleExtend = moduleExtend;
+    }
+
+    /**
      * 获取对应模块id
      *
      * @return module_id - 对应模块id
@@ -202,57 +232,75 @@ public class UserPaper implements Serializable {
     }
 
     /**
-     * 获取时间
+     * 获取单次时间:系统时间
      *
-     * @return time - 时间
+     * @return time - 单次时间:系统时间
      */
     public Integer getTime() {
         return time;
     }
 
     /**
-     * 设置时间
+     * 设置单次时间:系统时间
      *
-     * @param time 时间
+     * @param time 单次时间:系统时间
      */
     public void setTime(Integer time) {
         this.time = time;
     }
 
     /**
-     * 获取用户做题时间-累计
+     * 获取总作答时间
+     *
+     * @return total_time - 总作答时间
+     */
+    public Integer getTotalTime() {
+        return totalTime;
+    }
+
+    /**
+     * 设置总作答时间
+     *
+     * @param totalTime 总作答时间
+     */
+    public void setTotalTime(Integer totalTime) {
+        this.totalTime = totalTime;
+    }
+
+    /**
+     * 获取总作答次数
      *
-     * @return user_time - 用户做题时间-累计
+     * @return total_number - 总作答次数
      */
-    public Integer getUserTime() {
-        return userTime;
+    public Integer getTotalNumber() {
+        return totalNumber;
     }
 
     /**
-     * 设置用户做题时间-累计
+     * 设置总作答次数
      *
-     * @param userTime 用户做题时间-累计
+     * @param totalNumber 总作答次数
      */
-    public void setUserTime(Integer userTime) {
-        this.userTime = userTime;
+    public void setTotalNumber(Integer totalNumber) {
+        this.totalNumber = totalNumber;
     }
 
     /**
-     * 获取正确总题数-累计
+     * 获取总正确次数
      *
-     * @return correct_number - 正确总题数-累计
+     * @return total_correct - 总正确次数
      */
-    public Integer getCorrectNumber() {
-        return correctNumber;
+    public Integer getTotalCorrect() {
+        return totalCorrect;
     }
 
     /**
-     * 设置正确总题数-累计
+     * 设置总正确次数
      *
-     * @param correctNumber 正确总题数-累计
+     * @param totalCorrect 总正确次数
      */
-    public void setCorrectNumber(Integer correctNumber) {
-        this.correctNumber = correctNumber;
+    public void setTotalCorrect(Integer totalCorrect) {
+        this.totalCorrect = totalCorrect;
     }
 
     /**
@@ -301,12 +349,14 @@ public class UserPaper implements Serializable {
         sb.append(", userId=").append(userId);
         sb.append(", title=").append(title);
         sb.append(", module=").append(module);
+        sb.append(", moduleExtend=").append(moduleExtend);
         sb.append(", moduleId=").append(moduleId);
         sb.append(", questionNoIds=").append(questionNoIds);
         sb.append(", times=").append(times);
         sb.append(", time=").append(time);
-        sb.append(", userTime=").append(userTime);
-        sb.append(", correctNumber=").append(correctNumber);
+        sb.append(", totalTime=").append(totalTime);
+        sb.append(", totalNumber=").append(totalNumber);
+        sb.append(", totalCorrect=").append(totalCorrect);
         sb.append(", deleteTime=").append(deleteTime);
         sb.append(", isReset=").append(isReset);
         sb.append("]");
@@ -373,6 +423,16 @@ public class UserPaper implements Serializable {
         }
 
         /**
+         * 设置组卷扩展:examination, exercise
+         *
+         * @param moduleExtend 组卷扩展:examination, exercise
+         */
+        public Builder moduleExtend(String moduleExtend) {
+            obj.setModuleExtend(moduleExtend);
+            return this;
+        }
+
+        /**
          * 设置题目编号id列表:json
          *
          * @param questionNoIds 题目编号id列表:json
@@ -383,9 +443,9 @@ public class UserPaper implements Serializable {
         }
 
         /**
-         * 设置时间
+         * 设置单次时间:系统时间
          *
-         * @param time 时间
+         * @param time 单次时间:系统时间
          */
         public Builder time(Integer time) {
             obj.setTime(time);
@@ -403,22 +463,32 @@ public class UserPaper implements Serializable {
         }
 
         /**
-         * 设置用户做题时间-累计
+         * 设置总作答时间
+         *
+         * @param totalTime 总作答时间
+         */
+        public Builder totalTime(Integer totalTime) {
+            obj.setTotalTime(totalTime);
+            return this;
+        }
+
+        /**
+         * 设置总作答次数
          *
-         * @param userTime 用户做题时间-累计
+         * @param totalNumber 总作答次数
          */
-        public Builder userTime(Integer userTime) {
-            obj.setUserTime(userTime);
+        public Builder totalNumber(Integer totalNumber) {
+            obj.setTotalNumber(totalNumber);
             return this;
         }
 
         /**
-         * 设置正确总题数-累计
+         * 设置总正确次数
          *
-         * @param correctNumber 正确总题数-累计
+         * @param totalCorrect 总正确次数
          */
-        public Builder correctNumber(Integer correctNumber) {
-            obj.setCorrectNumber(correctNumber);
+        public Builder totalCorrect(Integer totalCorrect) {
+            obj.setTotalCorrect(totalCorrect);
             return this;
         }
 

+ 6 - 4
server/data/src/main/java/com/qxgmat/data/dao/mapping/UserPaperMapper.xml

@@ -9,12 +9,14 @@
     <result column="user_id" jdbcType="INTEGER" property="userId" />
     <result column="title" jdbcType="VARCHAR" property="title" />
     <result column="module" jdbcType="VARCHAR" property="module" />
+    <result column="module_extend" jdbcType="VARCHAR" property="moduleExtend" />
     <result column="module_id" jdbcType="INTEGER" property="moduleId" />
     <result column="question_no_ids" jdbcType="VARCHAR" property="questionNoIds" typeHandler="com.nuliji.tools.mybatis.handler.IntegerArrayWithJsonHandler" />
     <result column="times" jdbcType="INTEGER" property="times" />
     <result column="time" jdbcType="INTEGER" property="time" />
-    <result column="user_time" jdbcType="INTEGER" property="userTime" />
-    <result column="correct_number" jdbcType="INTEGER" property="correctNumber" />
+    <result column="total_time" jdbcType="INTEGER" property="totalTime" />
+    <result column="total_number" jdbcType="INTEGER" property="totalNumber" />
+    <result column="total_correct" jdbcType="INTEGER" property="totalCorrect" />
     <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime" />
     <result column="is_reset" jdbcType="INTEGER" property="isReset" />
   </resultMap>
@@ -22,7 +24,7 @@
     <!--
       WARNING - @mbg.generated
     -->
-    `id`, `user_id`, `title`, `module`, `module_id`, `question_no_ids`, `times`, `time`, 
-    `user_time`, `correct_number`, `delete_time`, `is_reset`
+    `id`, `user_id`, `title`, `module`, `module_extend`, `module_id`, `question_no_ids`, 
+    `times`, `time`, `total_time`, `total_number`, `total_correct`, `delete_time`, `is_reset`
   </sql>
 </mapper>

+ 1 - 1
server/gateway-api/src/main/java/com/qxgmat/controller/admin/PreviewController.java

@@ -70,7 +70,7 @@ public class PreviewController {
         HomeworkPreview entity = homeworkPreviewService.get(id);
         HomeworkPreviewDetailDto dto = Transform.convert(entity, HomeworkPreviewDetailDto.class);
 
-//        List<QuestionNoRelation> questionNos = questionNoService.listByIds(entity.getQuestionNoIds());
+//        List<QuestionNoRelation> questionNos = questionNoService.listWithRelationByIds(entity.getQuestionNoIds());
 //        List<QuestionNoExtendDto> questionNoExtendDtos = Transform.convert(questionNos, QuestionNoExtendDto.class);
 //
 //        dto.setQuestionNos(questionNoExtendDtos);

+ 2 - 3
server/gateway-api/src/main/java/com/qxgmat/controller/admin/QuestionController.java

@@ -23,7 +23,6 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Collection;
 import java.util.List;
 
 @RestController("AdminQuestionController")
@@ -110,9 +109,9 @@ public class QuestionController {
     public Response<List<QuestionNoExtendDto>> listNo(@RequestBody @Validated QuestionNoSearchDto dto, HttpServletRequest request) {
         List<QuestionNoRelation> questionNos;
         if (dto.getIds() != null && dto.getIds().length > 0){
-           questionNos = questionNoService.listByIds(dto.getIds());
+           questionNos = questionNoService.listWithRelationByIds(dto.getIds());
         }else if(dto.getNos() != null && dto.getNos().length > 0){
-            questionNos = questionNoService.listByNos(dto.getNos(), dto.getModule());
+            questionNos = questionNoService.listWithRelationByNos(dto.getNos(), dto.getModule());
         }else{
             throw new ParameterException("需要id或编号");
         }

+ 2 - 2
server/gateway-api/src/main/java/com/qxgmat/service/HomeworkPreviewService.java

@@ -181,7 +181,7 @@ public class HomeworkPreviewService extends AbstractService {
         Integer[] userIds = homeworkPreview.getUserIds();
 
         // 获取考题时间
-        List<QuestionNoRelation> relationList = questionNoService.listByIds(homeworkPreview.getQuestionNoIds());
+        List<QuestionNoRelation> relationList = questionNoService.listWithRelationByIds(homeworkPreview.getQuestionNoIds());
         Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relationList);
         for(Integer userId : userIds){
             userPaperService.add(UserPaper.builder()
@@ -217,7 +217,7 @@ public class HomeworkPreviewService extends AbstractService {
         editList.removeAll(oldList);
 
         // 获取考题时间
-        List<QuestionNoRelation> relationList = questionNoService.listByIds(homeworkPreview.getQuestionNoIds());
+        List<QuestionNoRelation> relationList = questionNoService.listWithRelationByIds(homeworkPreview.getQuestionNoIds());
         Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relationList);
         for(Integer userId : newList){
             if (!editList.contains(userId)){

+ 42 - 0
server/gateway-api/src/main/java/com/qxgmat/service/UserQuestionService.java

@@ -6,9 +6,12 @@ import com.nuliji.tools.AbstractService;
 import com.nuliji.tools.PageResult;
 import com.nuliji.tools.exception.ParameterException;
 import com.nuliji.tools.exception.SystemException;
+import com.nuliji.tools.mybatis.Example;
 import com.qxgmat.data.constants.enums.module.QuestionModule;
 import com.qxgmat.data.dao.UserQuestionMapper;
 import com.qxgmat.data.dao.entity.UserQuestion;
+import com.qxgmat.data.dao.entity.UserReport;
+import com.qxgmat.service.annotation.InitQuestion;
 import com.qxgmat.service.inline.QuestionNoService;
 import com.qxgmat.service.inline.SentenceQuestionService;
 import com.qxgmat.util.annotation.Callback;
@@ -41,6 +44,45 @@ public class UserQuestionService extends AbstractService {
         return new PageResult<>(null, 0);
     }
 
+    /**
+     * 获取当前报告最后一题
+     * @param userId
+     * @param userReportId
+     * @return
+     */
+    public UserQuestion getLastByReport(Integer userId, Integer userReportId){
+        Example example = new Example(UserQuestion.class);
+        example.and(
+                example.createCriteria()
+                        .andEqualTo("userId", userId)
+                        .andEqualTo("paper_id", userReportId)
+        );
+        example.orderBy("id").desc();
+        return one(userQuestionMapper, example);
+    }
+
+
+    /**
+     * 根据用户report创建下一题
+     * @param report
+     * @param lastQuestion
+     * @param IInitQuestion
+     * @return
+     */
+    public UserQuestion addByReport(UserReport report, UserQuestion lastQuestion, InitQuestion IInitQuestion){
+        UserQuestion question = UserQuestion.builder()
+                .reportId(report.getId())
+                .userId(report.getUserId())
+                .build();
+        // 回调,根据模块更新设置
+        boolean result = IInitQuestion.callback(question, report, lastQuestion);
+        if (!result) {
+            // 做题结束
+            return null;
+        }
+        return add(question);
+    }
+
     public UserQuestion add(UserQuestion question){
         int result = insert(userQuestionMapper, question);
         question = one(userQuestionMapper, question.getId());

+ 13 - 0
server/gateway-api/src/main/java/com/qxgmat/service/annotation/InitQuestion.java

@@ -0,0 +1,13 @@
+package com.qxgmat.service.annotation;
+
+
+import com.qxgmat.data.dao.entity.UserQuestion;
+import com.qxgmat.data.dao.entity.UserReport;
+
+/**
+ * Created by gaojie on 2017/11/20.
+ */
+@FunctionalInterface
+public interface InitQuestion {
+    boolean callback(UserQuestion question, UserReport report, UserQuestion lastQuestion);
+}

+ 1 - 1
server/gateway-api/src/main/java/com/qxgmat/service/annotation/InitReport.java

@@ -9,5 +9,5 @@ import com.qxgmat.data.dao.entity.UserReport;
  */
 @FunctionalInterface
 public interface InitReport {
-    void callback(UserPaper paper, UserReport report);
+    void callback(UserReport report, UserPaper paper);
 }

+ 126 - 20
server/gateway-api/src/main/java/com/qxgmat/service/extend/QuestionFlowService.java

@@ -5,12 +5,14 @@ import com.nuliji.tools.exception.ParameterException;
 import com.qxgmat.data.constants.enums.SettingKey;
 import com.qxgmat.data.constants.enums.module.PaperModule;
 import com.qxgmat.data.constants.enums.module.QuestionModule;
+import com.qxgmat.data.dao.entity.QuestionNo;
 import com.qxgmat.data.dao.entity.UserPaper;
 import com.qxgmat.data.dao.entity.UserQuestion;
 import com.qxgmat.data.dao.entity.UserReport;
 import com.qxgmat.data.relation.entity.QuestionNoRelation;
 import com.qxgmat.service.*;
 import com.qxgmat.service.annotation.InitPaper;
+import com.qxgmat.service.annotation.InitQuestion;
 import com.qxgmat.service.annotation.InitReport;
 import com.qxgmat.service.inline.QuestionNoService;
 import com.qxgmat.service.inline.SentenceQuestionService;
@@ -57,23 +59,25 @@ public class QuestionFlowService {
     private ToolsService toolsService;
 
     // 初始化试卷的callback,根据试卷模块进行后续处理
-    private Map<PaperModule, InitPaper> initPaperCallback;
+    private Map<PaperModule, InitPaper> initPaperCallback = new HashMap<>();
 
-    // 初始化报告的callback,根据设置进行后续处理
-    private Map<PaperModule, InitReport> initReportCallback;
+    // 初始化报告的callback,根据试卷模块进行后续处理
+    private Map<PaperModule, InitReport> initReportCallback = new HashMap<>();
+
+    // 根据
+    private Map<PaperModule, InitQuestion> nextCallback = new HashMap<>();
 
     // 完成试卷的callback,根据试卷模块进行后续处理
-    private Map<PaperModule, Callback> finishCallback;
+    private Map<PaperModule, Callback> finishCallback = new HashMap<>();
 
     // 提交答题的callback,根据试题模块进行后续处理
     private Map<QuestionModule, Callback> submitCallback;
 
     public QuestionFlowService(){
-        initPaperCallback = new HashMap<>();
         initPaperCallback.put(PaperModule.EXERCISE, (paper, id)->{
            exercisePaperService.initUserPaper(paper, id);
             // 获取考题时间
-            List<QuestionNoRelation> relationList = questionNoService.listByIds(paper.getQuestionNoIds());
+            List<QuestionNoRelation> relationList = questionNoService.listWithRelationByIds(paper.getQuestionNoIds());
             Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relationList);
             paper.setTime(time);
         });
@@ -90,40 +94,88 @@ public class QuestionFlowService {
             sentencePaperService.initUserPaper(paper, id);
         });
 
-        initReportCallback = new HashMap<>();
-        initReportCallback.put(PaperModule.EXERCISE, (paper, report)->{
+        initReportCallback.put(PaperModule.EXERCISE, (report, paper)->{
             JSONObject setting = report.getSetting();
             if (setting.getBoolean("disorder")){
                 // 随机试题
-                report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
+                report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
             }
         });
-        initReportCallback.put(PaperModule.HOMEWORK_PREVIEW, (paper, report)->{
+        initReportCallback.put(PaperModule.HOMEWORK_PREVIEW, (report, paper)->{
             JSONObject setting = report.getSetting();
             if (setting.getBoolean("disorder")){
                 // 随机试题
-                report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
+                report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
             }
         });
-        initReportCallback.put(PaperModule.COLLECT, (paper, report)->{
+        initReportCallback.put(PaperModule.COLLECT, (report, paper)->{
             JSONObject setting = report.getSetting();
             if (setting.getBoolean("disorder")){
                 // 随机试题
-                report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
+                report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
             }
         });
-        initReportCallback.put(PaperModule.ERROR, (paper, report)->{
+        initReportCallback.put(PaperModule.ERROR, (report, paper)->{
             JSONObject setting = report.getSetting();
             if (setting.getBoolean("disorder")){
                 // 随机试题
-                report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
+                report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
             }
         });
         initReportCallback.put(PaperModule.SENTENCE, (paper, report)->{
             // 无特殊设置
         });
 
-        finishCallback = new HashMap<>();
+        nextCallback.put(PaperModule.EXERCISE, (question, report, lastQuestion)->{
+            Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
+            if (questionNoId == 0) return false;
+            QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
+            question.setQuestionNoId(relation.getId());
+            question.setQuestionId(relation.getQuestionId());
+            Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relation);
+            question.setTime(time);
+            return true;
+        });
+        nextCallback.put(PaperModule.HOMEWORK_PREVIEW, (question, report, lastQuestion)->{
+            Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
+            if (questionNoId == 0) return false;
+            QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
+            question.setQuestionNoId(relation.getId());
+            question.setQuestionId(relation.getQuestionId());
+            Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relation);
+            question.setTime(time);
+            return true;
+        });
+        nextCallback.put(PaperModule.COLLECT, (question, report, lastQuestion)->{
+            Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
+            if (questionNoId == 0) return false;
+            QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
+            question.setQuestionNoId(relation.getId());
+            question.setQuestionId(relation.getQuestionId());
+            Integer time = toolsService.computerTime(SettingKey.getTimeByPaperModule(PaperModule.ValueOf(relation.getModule())), relation);
+            question.setTime(time);
+            return true;
+        });
+        nextCallback.put(PaperModule.ERROR, (question, report, lastQuestion)->{
+            Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
+            if (questionNoId == 0) return false;
+            QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
+            question.setQuestionNoId(relation.getId());
+            question.setQuestionId(relation.getQuestionId());
+            Integer time = toolsService.computerTime(SettingKey.getTimeByPaperModule(PaperModule.ValueOf(relation.getModule())), relation);
+            question.setTime(time);
+            return true;
+        });
+        nextCallback.put(PaperModule.SENTENCE, (question, report, lastQuestion)->{
+            Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
+            if (questionNoId == 0) return false;
+            QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
+            question.setQuestionNoId(relation.getId());
+            question.setQuestionId(relation.getQuestionId());
+            question.setTime(0);
+            return true;
+        });
+
         finishCallback.put(PaperModule.EXERCISE, (obj)->{
             return exercisePaperService.finished((UserPaper) obj);
         });
@@ -167,13 +219,31 @@ public class QuestionFlowService {
         return report;
     }
 
+    /**
+     * 获取report的下一道题
+     * @param userId
+     * @param userReportId
+     * @return
+     */
     public UserQuestion next(Integer userId, Integer userReportId){
-        // 查找未完成的questionid
+        UserQuestion userQuestion = userQuestionService.getLastByReport(userId, userReportId);
+        // 查找未完成的questionId
+        if (userQuestion==null || userQuestion.getUserTime() >0){
+            // 创建新的question
+            UserReport report = userReportService.get(userReportId);
+            userQuestion = userQuestionService.addByReport(report, userQuestion, nextCallback.get(PaperModule.ValueOf(report.getModule())));
+        }
 
-        // 创建新的question
-        return null;
+        return userQuestion;
     }
 
+    /**
+     * 提交试题
+     * @param userId
+     * @param userQuestionId
+     * @param answer
+     * @return
+     */
     @Transactional
     public Boolean submit(Integer userId, Integer userQuestionId, JSONObject answer){
         UserQuestion userQuestion = userQuestionService.get(userQuestionId);
@@ -190,11 +260,26 @@ public class QuestionFlowService {
         return true;
     }
 
+    /**
+     * 完成试卷,进行试卷分析
+     * @param userId
+     * @param userReportId
+     * @return
+     */
     @Transactional
     public Boolean finish(Integer userId, Integer userReportId){
+        // 设定paper完成次数加1
+
+        // 统计
         return true;
     }
 
+    /**
+     * 重新开始一份试卷:设定试卷reset=1,列表不绑定最后一次考试记录
+     * @param paperId
+     * @param userId
+     * @return
+     */
     public Boolean restart(Integer paperId, Integer userId){
         return userPaperService.reset(paperId, userId);
     }
@@ -204,7 +289,7 @@ public class QuestionFlowService {
      * @param questionNoIds
      * @return
      */
-    private Integer[] RandomQuestionNoIds(Integer[] questionNoIds){
+    private Integer[] randomQuestionNoIds(Integer[] questionNoIds){
         Integer[] ran = new Integer[questionNoIds.length];
         List<Integer> base = Arrays.stream(questionNoIds).collect(Collectors.toList());
         int length = base.size();
@@ -214,4 +299,25 @@ public class QuestionFlowService {
         }
         return ran;
     }
+
+    /**
+     * 顺序获取下一题
+     * @param ids
+     * @param id
+     * @return
+     */
+    private Integer nextId(Integer[] ids, Integer id){
+        if (id == null) return ids[0];
+        boolean flag = false;
+        for(Integer a : ids){
+            if (a.equals(id)){
+                flag = true;
+                continue;
+            }
+            if (flag){
+                return a;
+            }
+        }
+        return 0;
+    }
 }

+ 24 - 0
server/gateway-api/src/main/java/com/qxgmat/service/extend/ToolsService.java

@@ -44,4 +44,28 @@ public class ToolsService {
         }
         return time;
     }
+
+    /**
+     * 根据练习或者模考时间设置获取单个考题时间
+     *      setting: {struct: {difficult: ""}}
+     * @param settingKey
+     * @param relation
+     * @return
+     */
+    public Integer computerTime(SettingKey settingKey, QuestionNoRelation relation){
+        Setting setting = settingService.getByKey(settingKey);
+        JSONObject value = setting.getValue();
+
+        JSONObject difficultMap = null;
+        for (Integer struct : relation.getModuleStruct()){
+            // 判断结构体
+            difficultMap = value.getJSONObject(String.valueOf(struct));
+            if (difficultMap != null) break;
+        }
+        if (difficultMap == null) return 0;
+        // 判断难度
+        String t = difficultMap.getString(relation.getQuestion().getDifficult());
+        if (t == null || t.isEmpty()) return 0;
+        return Integer.valueOf(t);
+    }
 }

+ 13 - 3
server/gateway-api/src/main/java/com/qxgmat/service/inline/QuestionNoService.java

@@ -91,7 +91,7 @@ public class QuestionNoService extends AbstractService {
      * @param module
      * @return
      */
-    public List<QuestionNoRelation> listByNos(String[] nos, String module){
+    public List<QuestionNoRelation> listWithRelationByNos(String[] nos, String module){
         if (nos.length == 0) return new ArrayList<>();
         Example example = new Example(QuestionNo.class);
         example.and(
@@ -122,16 +122,26 @@ public class QuestionNoService extends AbstractService {
     }
 
     /**
-     * 根据题目编号id获取关联题目
+     * 根据题目编号id列表获取关联题目
      * @param ids
      * @return
      */
-    public List<QuestionNoRelation> listByIds(Number[] ids){
+    public List<QuestionNoRelation> listWithRelationByIds(Number[] ids){
         List<QuestionNo> p = select(questionNoMapper, ids);
         return relation(p);
     }
 
     /**
+     * 根据题目编号id获取关联题目
+     * @param id
+     * @return
+     */
+    public QuestionNoRelation getWithRelation(Number id){
+        QuestionNo questionNo = get(id);
+        return relation(questionNo);
+    }
+
+    /**
      * 绑定no和question
      * @param ids
      * @param questionId

+ 1 - 1
server/gateway-api/src/main/java/com/qxgmat/service/inline/UserReportService.java

@@ -79,7 +79,7 @@ public class UserReportService extends AbstractService {
                 .questionNoIds(paper.getQuestionNoIds())
                 .build();
         // 回调,根据模块更新设置
-        IInitReport.callback(paper, report);
+        IInitReport.callback(report, paper);
         return add(report);
     }