Browse Source

各角色显示内容优化

shenhao 3 years atrás
parent
commit
07652f6816

+ 7 - 2
src/main/java/com/aijia/kmt/controller/KmtExerciseController.java

@@ -12,6 +12,7 @@ import com.aijia.kmt.vo.rollbackai.AddExerciseQuestionRequest;
 import com.aijia.kmt.vo.rollbackai.ExerciseBooksEditRequest;
 import com.aijia.kmt.vo.rollbackai.ExerciseQuestionDealRequest;
 import com.aijia.kmt.vo.rollbackai.ExerciseQuestionsEditRequest;
+import com.aijia.train.bean.TrTrainPartUser;
 import com.alibaba.fastjson.JSON;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -133,8 +134,12 @@ public class KmtExerciseController extends BaseController {
             String  userId = tokenManager.getUserId(accessToken);
             //是管理员
             int type = 1;
-            if(!userId.equals(request.getUserId())){
-                type = 2;
+            if(request.getUserId()==null){
+                type = 1;
+            }else{
+                if(!userId.equals(request.getUserId())){
+                    type = 2;
+                }
             }
 
             data.put("units", kmtExerciseMapperService.findExerciseBookDetail(request, userId,type));

+ 4 - 5
src/main/java/com/aijia/kmt/mapper/KmtExerciseMapper.java

@@ -12,10 +12,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.*;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 @Mapper
 public interface KmtExerciseMapper {
@@ -470,7 +467,7 @@ public interface KmtExerciseMapper {
      * @param questionIds
      * @return
      */
-    List<QuestionListKnowModel> findQuestionKnowByQuestionIds(@Param("questionIds") List<String> questionIds,@Param("userId") String userId);
+    List<QuestionListKnowModel> findQuestionKnowByQuestionIds(@Param("questionIds") List<String> questionIds,@Param("userId") String userId,@Param("roleType") int roleType);
 
 
     /**
@@ -1302,4 +1299,6 @@ public interface KmtExerciseMapper {
 
     @Select("select distinct book_id from kmt_exercise_book where part_flag != 3 order by book_id")
     List<String> findAllBookId (Page page);
+
+    List<QuestionListKnowModel> findQuestionKnowByQuestionIds2(@Param("questionIds")List<String> copyList);
 }

+ 1 - 1
src/main/java/com/aijia/kmt/service/impl/KmtExerciseQuestionDealServiceImpl.java

@@ -619,7 +619,7 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
                     questionInfo.setUpdateType(request.getEndX());
                     questionInfo.setEsLoaded(request.getEndY());
                     questionInfo.setEnumerate(request.getEnumerate());
-                    questionInfo.setStatus(2);
+                    questionInfo.setStatus(0);
                     userExerciseMapper.insert(questionInfo);
                 }else{
                     kmtExerciseMapper.updateQuestionStartPointAndEndPoint(request.getStartX(), request.getStartY(),

+ 55 - 22
src/main/java/com/aijia/kmt/service/impl/KmtExerciseQuestionListServiceImpl.java

@@ -48,7 +48,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
     @Override
     public ResponseEntity findQuestionList (String userId, ExerciseQuestionsRequest request,int type) {
         TrTrainPartUser user = userServiceMapper.selectById(userId);
-        String paramUserId = user.getManagerType()==1?request.getUserId():userId;
+        String paramUserId = StringUtils.isBlank(request.getUserId())?userId:request.getUserId();
 
         TrTrainPartUser partUser = userServiceMapper.selectById(paramUserId);
         int roleType = partUser.getRoleType();
@@ -56,8 +56,6 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
         if(partUser.getManagerType() == 1){
             roleType = 0;
         }
-
-
         ResponseEntity responseEntity = new ResponseEntity();
         Map<String, Object> data = new HashMap<>();
         Page page = new Page(request.getPageNo(), request.getPageSize());
@@ -68,7 +66,8 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
             }
         List<ExerciseQuetionDto> questions  = kmtExerciseMapper.findQuestionByBookCourseIdAndUserIdNew(request, paramUserId, page,user.getManagerType(), type,roleType);
         //管理员看到的题目列表是两层级, 老师看到的列表是一层级
-        List<QuestionListV1Dto> list = changeDbQuestion(questions,true,paramUserId,type); //默认两层级的结构
+        //默认两层级的结构
+        List<QuestionListV1Dto> list = changeDbQuestion(questions,true,paramUserId,type);
         data.put("list", list);
         data.put("pageNo", page.getCurrent());
         data.put("pageSize", page.getSize());
@@ -121,7 +120,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
                         kmtExerciseQuestion.setAnswer(check && StringUtil.isNotBlank(userExercise.getAnswer())?userExercise.getAnswer():jsonObject.getString("option_answer"));
                         kmtExerciseQuestion.setAnswerJson(check && StringUtil.isNotBlank(userExercise.getAnswerJson())?userExercise.getAnswerJson():jsonObject.getString("answer_json"));
 //                        kmtExerciseQuestion.setQuestionAnalysis(check && StringUtil.isNotBlank(userExercise.getAnalysis())?userExercise.getAnalysis():jsonObject.getString("analysis"));
-//                        kmtExerciseQuestion.setAnalysisJson(check && StringUtil.isNotBlank(userExercise.getAnalysisJson())?userExercise.getAnalysisJson():jsonObject.getString("analysis_json"));
+                        kmtExerciseQuestion.setAnalysisJson(check && StringUtil.isNotBlank(userExercise.getAnalysisJson())?userExercise.getAnalysisJson():"");
                         kmtExerciseQuestion.setOriginAnswer(check && StringUtil.isNotBlank(userExercise.getAnswerText())?userExercise.getAnswerText():jsonObject.getString("question_answer"));
                     }else{
                         kmtExerciseQuestion.setQuestion(check && StringUtil.isNotBlank(userExercise.getQuestion())?userExercise.getQuestion():"");
@@ -129,7 +128,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
                         kmtExerciseQuestion.setAnswer(check && StringUtil.isNotBlank(userExercise.getAnswer())?userExercise.getAnswer():"");
                         kmtExerciseQuestion.setAnswerJson(check && StringUtil.isNotBlank(userExercise.getAnswerJson())?userExercise.getAnswerJson():"");
 //                        kmtExerciseQuestion.setQuestionAnalysis(check && StringUtil.isNotBlank(userExercise.getAnalysis())?userExercise.getAnalysis():"");
-//                        kmtExerciseQuestion.setAnalysisJson(check && StringUtil.isNotBlank(userExercise.getAnalysisJson())?userExercise.getAnalysisJson():"");
+                        kmtExerciseQuestion.setAnalysisJson(check && StringUtil.isNotBlank(userExercise.getAnalysisJson())?userExercise.getAnalysisJson():"");
                         kmtExerciseQuestion.setOriginAnswer(check && StringUtil.isNotBlank(userExercise.getAnswerText())?userExercise.getAnswerText():"");
                     }
                 }
@@ -171,13 +170,13 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
         List<QuestionListV1Dto> result = new ArrayList<>();
         if (CollectionUtils.isNotEmpty(list)){
             List<String> questionIds = list.stream().map(ExerciseQuetionDto::getQuestionId).collect(Collectors.toList());
-            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,null);
+            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,null,0);
             List<TbLibManager> users = getDealUsers(list);
 
             list.forEach(temp -> {
                 QuestionListV1Dto tar = changeExerciseDto2QuestionListDto(temp, questionKnows, users,null);
                 if (isTwoLevel && StringUtil.isNotBlank(temp.getParentId())){
-                    addTar2Result(tar, result, temp.getParentId(), temp.getExerciseBookId(),null);
+                    addTar2Result(tar, result, temp.getParentId(), temp.getExerciseBookId(),null,0);
                 } else {
                     result.add(tar);
                 }
@@ -196,13 +195,49 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
         if (CollectionUtils.isNotEmpty(list)){
             List<String> questionIds = list.stream().map(ExerciseQuetionDto::getQuestionId).collect(Collectors.toList());
 
-            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,userId);
+            TrTrainPartUser user = userServiceMapper.selectById(userId);
+            //已提交
+            List<QuestionListKnowModel> questionKnows = null;
+            if(type == 2){
+                questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds2(questionIds);
+            }else{
+                if(user.getStudyStatus()>3){
+                    questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,userId,type);
+                }else{
+                    //查询用户提交记录
+                    List<TrTrainUserExercise> userExerciseList = userExerciseMapper.selectList(
+                            new QueryWrapper<TrTrainUserExercise>().eq("user_id",userId)
+                    );
+                    List<String> postList = new ArrayList<>();
+                    List<String> copyList = new ArrayList<>();
+                    copyList.addAll(questionIds);
+                    questionIds.forEach(s->{
+                        userExerciseList.forEach(ue->{
+                            if(ue.getQuestionId().equals(s) && ue.getStatus()>0){
+                                postList.add(s);
+                                copyList.remove(s);
+                            }
+                        });
+                    });
+                    if(postList.size()>0){
+                        questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(postList,userId,type);
+                    }
+                    if(questionKnows == null || questionKnows.size()==0){
+                        questionKnows = new ArrayList<>();
+                    }
+                    if(user.getRoleType()>1){
+                        questionKnows.addAll(kmtExerciseMapper.findQuestionKnowByQuestionIds2(copyList));
+                    }
+                }
+            }
+
             List<TbLibManager> users = getDealUsers(list);
 
+            List<QuestionListKnowModel> finalQuestionKnows = questionKnows;
             list.forEach(temp -> {
-                QuestionListV1Dto tar = changeExerciseDto2QuestionListDto(temp, questionKnows, users,userId);
+                QuestionListV1Dto tar = changeExerciseDto2QuestionListDto(temp, finalQuestionKnows, users,userId);
                 if (isTwoLevel && StringUtil.isNotBlank(temp.getParentId())){
-                    addTar2Result(tar, result, temp.getParentId(), temp.getExerciseBookId(),userId);
+                    addTar2Result(tar, result, temp.getParentId(), temp.getExerciseBookId(),userId,type);
                 } else {
                     result.add(tar);
                 }
@@ -221,14 +256,12 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
     private QuestionListV1Dto changeExerciseDto2QuestionListDto (ExerciseQuetionDto exerciseDto, List<QuestionListKnowModel> questionKnows,
                                                                  List<TbLibManager> users,String userId) {
         QuestionListV1Dto tar = new QuestionListV1Dto();
-            TrTrainPartUser user = userServiceMapper.selectById(userId);
-            if(user.getRoleType()>1){
-                //设置知识点
-                setQuestionKnowledge(tar, questionKnows.stream().filter(map ->
-                        exerciseDto.getQuestionId().equals(map.getQuestionId())).collect(Collectors.toList()));
-            }
+//            TrTrainPartUser user = userServiceMapper.selectById(userId);
+            //设置知识点
+            setQuestionKnowledge(tar, questionKnows.stream().filter(map ->
+                    exerciseDto.getQuestionId().equals(map.getQuestionId())).collect(Collectors.toList()));
         //设置打回人和被打回人
-        setFromUserAndToUser(tar, exerciseDto);
+//        setFromUserAndToUser(tar, exerciseDto);
         //设置加工审核人
 //        appendQuestionDealUser(users, tar, exerciseDto);
         //状态
@@ -238,7 +271,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
         return tar;
     }
 
-    private void addTar2Result (QuestionListV1Dto tar, List<QuestionListV1Dto> result, String parentId, String bookId,String userId){
+    private void addTar2Result (QuestionListV1Dto tar, List<QuestionListV1Dto> result, String parentId, String bookId,String userId,int type){
         if (StringUtil.isNotBlank(parentId)){
             boolean exist = false;
             for (QuestionListV1Dto questionListV1Dto : result) {
@@ -251,7 +284,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
 
             //如果大题不存在, 新增空大题(只有题目id), 可能大题已经被加工
             if (!exist){
-                QuestionListV1Dto parent = getParentQuestionV1Dto(parentId, bookId,userId);
+                QuestionListV1Dto parent = getParentQuestionV1Dto(parentId, bookId,userId,type);
                 parent.setIsQuestionCanDeal(1); //大题不可加工
                 parent.getChildQuestions().add(tar);
                 result.add(parent);
@@ -263,7 +296,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
      * 查询父题dto
      * @return
      */
-    private QuestionListV1Dto getParentQuestionV1Dto (String parentId, String bookId,String userId) {
+    private QuestionListV1Dto getParentQuestionV1Dto (String parentId, String bookId,String userId,int type) {
         QuestionListV1Dto parent = new QuestionListV1Dto();
         if (StringUtil.isNotBlank(parentId)){
             String temp = kmtExerciseMapper.findDifferentExerciseBookId(parentId);
@@ -274,7 +307,7 @@ public class KmtExerciseQuestionListServiceImpl implements KmtExerciseQuestionLi
                         q.setIsCommonFlag(q.getIsCommonFlag() == 0 ? 1 : 0);
                     }
                 }
-                List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(Collections.singletonList(parentId),userId);
+                List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(Collections.singletonList(parentId),userId,type);
                 List<TbLibManager> users = getDealUsers(questions);
                 this.appendQuestionDtoDataFromJSONFile(questions,userId);
                 for (ExerciseQuetionDto q : questions){

+ 3 - 3
src/main/java/com/aijia/kmt/service/impl/KmtExerciseQuestionServiceImpl.java

@@ -137,7 +137,7 @@ public class KmtExerciseQuestionServiceImpl implements KmtExerciseQuestionServic
         List<ExerciseBookCourseClassDto> result = new ArrayList<>();
         if (CollectionUtils.isNotEmpty(list)){
             List<String> questionIds = list.stream().map(ExerciseQuetionDto::getQuestionId).collect(Collectors.toList());
-            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,userId);
+            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,userId,0);
             result = getCommonQuestionGroupList(list, questionKnows, hasBigQuestionIndex);
         }
         return  result;
@@ -148,7 +148,7 @@ public class KmtExerciseQuestionServiceImpl implements KmtExerciseQuestionServic
         List<ExerciseBookCourseClassDto> result = new ArrayList<>();
         if (CollectionUtils.isNotEmpty(list)){
             List<String> questionIds = list.stream().map(ExerciseQuetionDto::getQuestionId).collect(Collectors.toList());
-            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,null);
+            List<QuestionListKnowModel> questionKnows = kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,null,0);
             List<TbLibManager> users = getDealUsers(list); //加工审核员用户信息
             for (ExerciseQuetionDto exerciseQuestionDto : list){
                 this.setQuestionStatus(exerciseQuestionDto);
@@ -472,7 +472,7 @@ public class KmtExerciseQuestionServiceImpl implements KmtExerciseQuestionServic
             List<KmtSysUser> analysisHandlers = kmtSysUserMapper.selectBatchIds(new ArrayList(analysisHandlerIds));
             List<KmtSysUser> analysisAuditers = kmtSysUserMapper.selectBatchIds(new ArrayList(analysisAuditerIds));
 
-            List<QuestionListKnowModel> questionKnows =  kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,null);
+            List<QuestionListKnowModel> questionKnows =  kmtExerciseMapper.findQuestionKnowByQuestionIds(questionIds,null,0);
 
             list.forEach(kmtExerciseQuestion -> {
                 ExerciseBookCourseClassDto bookCourseClass = this.isBookCourseClassExist(result, kmtExerciseQuestion.getBookCourseId(),

+ 22 - 21
src/main/resources/mybatis/mapper/KmtExerciseMapper.xml

@@ -1086,23 +1086,6 @@
                 #{id}
             </foreach>
             and eqk.user_id = #{userId}
-            union all
-            select eqk1.question_id, hds1.id how_details_id, hds1.alias detail_name, hdks1.id how_details_kd_id, hdks1.alias
-            kd_name,
-            hds1.grade, hds1.course_name, hds1.type version_type, hds1.semester, khd1.is_zt module_type, hs1.alias how_name,
-            hds1.num, hdks1.num as num2
-            from kmt_exercise_question_know eqk1
-            left join zyb_know_how_details_sort hds1 on eqk1.how_detail_sort_id=hds1.id
-            left join zyb_know_how_details_sort hs1 on hds1.how_id=hs1.how_id and hds1.type=hs1.type and
-            hds1.semester=hs1.semester and hds1.grade=hs1.grade and hs1.stat=1
-            left join zyb_know_how_details_sort hdks1 on eqk1.how_detail_kd_sort_id=hdks1.id
-            left join zyb_know_how_details khd1 on hds1.how_details_id=khd1.id
-            where question_id in
-            <foreach collection="questionIds" item="id" index="index" open="(" close=")" separator=",">
-                #{id}
-            </foreach>and question_id not in (
-                select question_id from tr_train_user_question_know where user_id = #{userId}
-            )
         )t  order by t.question_id, t.num, t.num2
     </select>
 
@@ -2217,14 +2200,14 @@
 	eq.remark reason,
 	eq.from_user_id,
 	eq.to_user_id,
-	<if test="roleType == 1 or roleType ==2 ">
+	<if test="roleType == 1 or roleType ==2">
         ue.question_type as question_types,
         ue.difficulty_level as difficulty_levels,
         ue.real_exam_type as real_exam_types,
         ue.training_skill as  training_skills,
     </if>
     <!-- 解析或者管理员-->
-    <if test="roleType ==3 or roleType ==0 ">
+    <if test="roleType ==3 or roleType == 0">
         ifnull(ue.question_type,eq.question_type) question_types,
         ifnull(ue.difficulty_level,eq.difficulty_level) difficulty_levels,
         ifnull(ue.real_exam_type,eq.real_exam_type) real_exam_types,
@@ -2266,7 +2249,7 @@
         and eq.id=#{req.questionId}
     </if>
     <if test="type == 0">
-        and (ue.id is null or ue.status = 2)
+        and (ue.id is null or (ue.status = 2 or ue.status = 0))
     </if>
 
         order by t.number
@@ -2381,7 +2364,7 @@
         q_question_workbook t
         INNER JOIN kmt_exercise_questions eq ON t.question_id = eq.id
         INNER JOIN tr_train_question_check ec ON t.question_id = ec.question_id and ec.status = 1
-        LEFT JOIN tr_train_user_exercise eb ON eq.id = eb.question_id and eb.user_id ='a919d6d3-1e99-11ec-aea2-00163e02e90a'
+        LEFT JOIN tr_train_user_exercise eb ON eq.id = eb.question_id and eb.user_id =#{userId}
         LEFT JOIN ( SELECT @group_row := 1, @group_row2 := 1, @parent_code := '' ) AS b ON 1 = 1
         WHERE
         eq.exercise_book_id =#{bookId}
@@ -2485,4 +2468,22 @@
         </foreach>
         limit 0, 5000
     </select>
+    <select id="findQuestionKnowByQuestionIds2" resultType="com.aijia.kmt.dto.QuestionListKnowModel">
+        select * from (
+            select eqk1.question_id, hds1.id how_details_id, hds1.alias detail_name, hdks1.id how_details_kd_id, hdks1.alias
+            kd_name,
+            hds1.grade, hds1.course_name, hds1.type version_type, hds1.semester, khd1.is_zt module_type, hs1.alias how_name,
+            hds1.num, hdks1.num as num2
+            from kmt_exercise_question_know eqk1
+            left join zyb_know_how_details_sort hds1 on eqk1.how_detail_sort_id=hds1.id
+            left join zyb_know_how_details_sort hs1 on hds1.how_id=hs1.how_id and hds1.type=hs1.type and
+            hds1.semester=hs1.semester and hds1.grade=hs1.grade and hs1.stat=1
+            left join zyb_know_how_details_sort hdks1 on eqk1.how_detail_kd_sort_id=hdks1.id
+            left join zyb_know_how_details khd1 on hds1.how_details_id=khd1.id
+            where question_id in
+            <foreach collection="questionIds" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        )t order by t.question_id, t.num, t.num2
+    </select>
 </mapper>