Jelajahi Sumber

修复。 task 添加 更新 问题。

tom 5 bulan lalu
induk
melakukan
5043c750e4

+ 4 - 4
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/RealExamCollectionController.java

@@ -34,14 +34,14 @@ public class RealExamCollectionController extends BaseController {
 
     @GetMapping("/teacher/exam/list")
     @ApiOperation("[教师][分页]查询考试集合列表")
-    public TableDataInfo listExamByTeacher(RealExamCollection p) {
-        return service.listExamByTeacher(p);
+    public TableDataInfo listExamByTeacher(RealExamCollection q) {
+        return service.listExamByTeacher(q);
     }
 
     @GetMapping("/teacher/exercise/list")
     @ApiOperation("[教师][分页]查询练习集合列表")
-    public TableDataInfo listExerciseByTeacher(RealExamCollection p) {
-        return service.listExerciseByTeacher(p);
+    public TableDataInfo listExerciseByTeacher(RealExamCollection q) {
+        return service.listExerciseByTeacher(q);
     }
 
     @GetMapping(value = "/teacher/exam/{id}")

+ 13 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/TestIotController.java

@@ -2,8 +2,10 @@ package com.ruoyi.sim.controller;
 
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.sim.domain.Fault;
 import com.ruoyi.sim.domain.RealExam;
 import com.ruoyi.sim.service.impl.CommSendService;
+import com.ruoyi.sim.service.impl.FaultService;
 import com.ruoyi.sim.service.impl.MajorService;
 import com.ruoyi.sim.service.impl.RealExamService;
 import io.swagger.annotations.Api;
@@ -14,6 +16,8 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 @RestController
 @RequestMapping("/sim/iot")
 @Api("测试通信Controller")
@@ -25,6 +29,8 @@ public class TestIotController extends BaseController {
     private CommSendService commSnedService;
     @Autowired
     private RealExamService realExamService;
+    @Autowired
+    private FaultService faultService;
 
     @ApiOperation("testIot通信")
     @GetMapping(value = "/{codeId}")
@@ -114,4 +120,11 @@ public class TestIotController extends BaseController {
         }
         return AjaxResult.success();
     }
+
+    @ApiOperation("testIot通信")
+    @GetMapping(value = "/testIndex2/{codeId}")
+    public AjaxResult testIndex2(@PathVariable("codeId") Integer codeId) {
+        List<Fault> list = faultService.randomEnable3("0001");
+        return AjaxResult.success(list);
+    }
 }

+ 4 - 7
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/vo/RealExamCollectionVo.java

@@ -1,19 +1,16 @@
 package com.ruoyi.sim.domain.vo;
 
+import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.sim.domain.RealExamCollection;
 
+import java.util.List;
+
 public class RealExamCollectionVo extends RealExamCollection {
 
     /**
      * 班级Id数组
      */
-    private Long[] clazzIds;
+    private List<SysDept> clazzIds;
 
-    public Long[] getClazzIds() {
-        return clazzIds;
-    }
 
-    public void setClazzIds(Long[] clazzIds) {
-        this.clazzIds = clazzIds;
-    }
 }

+ 27 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/FaultService.java

@@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.sim.domain.TaskFault;
 import com.ruoyi.sim.domain.vo.FaultTreeVo;
+import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -248,6 +249,32 @@ public class FaultService {
         return isType(faultId, Fault.Type.TYPE_GZBW);
     }
 
+    public static int COUNT_3 = 3;
+
+    public List<Fault> randomEnable3(final String simType) {
+        return randomEnable(simType, COUNT_3);
+    }
+
+    /**
+     * 随机出题。
+     *
+     * @param simType
+     * @param selectCount 选中题目数量。
+     * @return
+     */
+    public List<Fault> randomEnable(final String simType, final int selectCount) {
+        List<Fault> list1 = listAllType3EnableBySimType(simType);
+        Set<Fault> set = new HashSet<>();
+        for (int i = 0; i < selectCount; i++) {
+            int index = RandomUtils.nextInt(0, list1.size() - i);
+            set.add(list1.get(index));
+            list1.remove(index);
+        }
+        if (set.size() != selectCount) {
+            throw new RuntimeException("randomEnable fail!");
+        }
+        return set.stream().toList();
+    }
 
 //    private static List<FaultNode> toTree2(List<FaultNode> list) {
 //        List<FaultNode> tree = new ArrayList<>();

+ 12 - 10
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamCollectionService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.sim.service.impl;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import cn.ele6.catalyzer.ruoyi.vue.custom.Ele6RYBaseService;
@@ -95,18 +96,19 @@ public class RealExamCollectionService extends Ele6RYBaseService {
     /**
      * [教师][分页]查询考试集合列表
      *
-     * @param p
+     * @param q
      * @return
      */
-    public TableDataInfo listExamByTeacher(RealExamCollection p) {
+    public TableDataInfo listExamByTeacher(RealExamCollection q) {
         startPage();
-        p.setExamCollectionType(RealExamCollection.Type.EXAM);
-        List<RealExamCollectionVo> list = new ArrayList<>();
-        realExamCollectionMapper.selectRealExamCollectionList(p).forEach((RealExamCollection s) -> {
-            RealExamCollectionVo t = new RealExamCollectionVo();
-            BeanUtils.copyProperties(s, t);
-            list.add(t);
-        });
+        q.setExamCollectionType(RealExamCollection.Type.EXAM);
+        List<RealExamCollectionVo> list = Collections.emptyList();
+        realExamCollectionMapper.selectRealExamCollectionList(q)
+                .forEach((RealExamCollection s) -> {
+                    RealExamCollectionVo t = new RealExamCollectionVo();
+                    BeanUtils.copyProperties(s, t);
+                    list.add(t);
+                });
         return getDataTable(list);
     }
 
@@ -119,7 +121,7 @@ public class RealExamCollectionService extends Ele6RYBaseService {
     public TableDataInfo listExerciseByTeacher(RealExamCollection p) {
         startPage();
         p.setExamCollectionType(RealExamCollection.Type.EXERCISE);
-        List<RealExamCollectionVo> list = new ArrayList<>();
+        List<RealExamCollectionVo> list = Collections.emptyList();
         realExamCollectionMapper.selectRealExamCollectionList(p).forEach((RealExamCollection s) -> {
             RealExamCollectionVo t = new RealExamCollectionVo();
             BeanUtils.copyProperties(s, t);

+ 5 - 17
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/TaskFaultService.java

@@ -6,7 +6,9 @@ import java.util.List;
 
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.sim.domain.Fault;
+import com.ruoyi.sim.domain.Task;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.sim.mapper.TaskFaultMapper;
@@ -112,23 +114,9 @@ public class TaskFaultService {
         return updateTaskFault(f);
     }
 
-    public int insertOrUpdateTaskFault(TaskFault tf) {
-        if (tf == null) {
-            return 0;
-        }
-        if (tf.getTaskId() == null || tf.getTaskId() == 0) {
-            return insertTaskFault(tf);
-        } else {
-            if (tf.getRelId() == null || tf.getRelId() == 0) {
-                TaskFault tf2 = selectUniqueTaskFault(tf.getTaskId(), tf.getFaultId());
-                tf2.setTaskId(tf.getTaskId());
-                tf2.setFaultId(tf.getFaultId());
-                tf2.setFlag(tf.getFlag());
-                return updateTaskFault(tf2);
-            } else {
-                return updateTaskFault(tf);
-            }
-        }
+    public boolean exist(Long taskId, String faultId) {
+        TaskFault tf = selectUniqueTaskFault(taskId, faultId);
+        return tf != null;
     }
 
     public int deleteTaskFaultByTaskId(Long taskId) {

+ 21 - 1
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/TaskService.java

@@ -223,6 +223,13 @@ public class TaskService {
         if (arE1.isError()) {
             return arE1;
         }
+        // check taskId
+        {
+            Task tQ = taskMapper.selectTaskByTaskId(tv.getTaskId());
+            if (tQ == null) {
+                return AjaxResult.error("taskId not exist!");
+            }
+        }
         //
         tv.setCreateByUserId(SecurityUtils.getUserId());
         tv.setCreateBy(SecurityUtils.getUsername());
@@ -258,6 +265,11 @@ public class TaskService {
         return AjaxResult.success();
     }
 
+    public boolean exist(Long taskId) {
+        return (selectTaskByTaskId(taskId) != null);
+    }
+
+
     /**
      * 处理关联数据。
      *
@@ -304,11 +316,19 @@ public class TaskService {
 
             // 故障部位冲突 暂时没有故障部位冲突。
             // UNKNOWN 作为 NO 插入或修改数据。
+            // 处理flag。
             if (TaskFault.Flag.UNKNOWN.equals(flag)) {
                 tf.setFlag(TaskFault.Flag.NO);
             }
             tf.setTaskId(taskId);
-            taskFaultService.insertOrUpdateTaskFault(tf);
+            //
+            TaskFault tfQ = taskFaultService.selectUniqueTaskFault(taskId, tf.getFaultId());
+            if (tfQ == null) {
+                taskFaultService.insertTaskFault(taskId, tf.getFaultId(), tf.getFlag());
+            } else {
+                tfQ.setFlag(tf.getFlag());
+                taskFaultService.updateTaskFault(tfQ);
+            }
         }
         return AjaxResult.success();
     }