Pārlūkot izejas kodu

添加 任务清单。

tom 5 mēneši atpakaļ
vecāks
revīzija
ca785fbe12

+ 3 - 3
pla-sim/01_SQL/02_table/sim_task_fault.sql

@@ -11,7 +11,7 @@
  Target Server Version : 50740 (5.7.40-log)
  File Encoding         : 65001
 
- Date: 15/12/2024 19:23:59
+ Date: 16/12/2024 15:01:06
 */
 
 SET NAMES utf8mb4;
@@ -26,8 +26,8 @@ CREATE TABLE `sim_task_fault`  (
   `task_id` bigint(20) NOT NULL,
   `fault_id` char(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
   `flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '7' COMMENT '7:未知\r\n1:选中\r\n0:没有选中',
-  `update_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
+  `update_time` datetime NULL DEFAULT NULL,
   PRIMARY KEY (`rel_id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'sim-任务故障关联表' ROW_FORMAT = DYNAMIC;
+) ENGINE = InnoDB AUTO_INCREMENT = 70 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'sim-任务故障关联表' ROW_FORMAT = DYNAMIC;
 
 SET FOREIGN_KEY_CHECKS = 1;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 134 - 33
pla-sim/01_SQL/03_dev_backup/pla-chem-sim-dev-1.sql


+ 1 - 1
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/TaskController.java

@@ -79,7 +79,7 @@ public class TaskController extends BaseController {
     @PostMapping
     @ApiOperation("新增任务")
     public AjaxResult add(@RequestBody TaskVo task) {
-        return taskService.insertTask(task);
+        return taskService.insertTaskByTeacher(task);
     }
 
     /**

+ 6 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/Fault.java

@@ -190,5 +190,11 @@ public class Fault extends BaseEntity implements Comparable<Fault> {
         }
     }
 
+    public static String FAULT_TYPE_1 = "1";
+    public static String FAULT_TYPE_2 = "2";
+    public static String FAULT_TYPE_3 = "3";
+    public static String FAULT_TYPE_4 = "4";
+    public static String FAULT_TYPE_5 = "5";
+
     public static String ROOT_FAULT_ID = "000000000000";
 }

+ 9 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/Task.java

@@ -106,4 +106,13 @@ public class Task extends BaseEntity {
 
     // -------------------------------- tom add  --------------------------------
     public static final Long EMPTY_TASK_ID = 0L;
+
+    /**
+     * 教师创建管理
+     */
+    public static final String TASK_TYPE_TEACHER_ADD = "1";
+    /**
+     * 考试临时数据
+     */
+    public static final String TASK_TYPE_TEMP = "2";
 }

+ 8 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/vo/TaskVo.java

@@ -1,6 +1,8 @@
 package com.ruoyi.sim.domain.vo;
 
 import com.ruoyi.sim.domain.Task;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
 
 import java.util.List;
 
@@ -15,4 +17,10 @@ public class TaskVo extends Task {
     public void setSelectedData(List<FaultTreeVo> selectedData) {
         this.selectedData = selectedData;
     }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("selectedData", selectedData).toString();
+    }
 }

+ 3 - 4
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/TaskFaultService.java

@@ -94,13 +94,13 @@ public class TaskFaultService {
         }
     }
 
-    @Transactional
+
     public int insertTaskFault(Long taskId, String faultId, String flag) {
         TaskFault n = new TaskFault(0L, taskId, faultId, flag);
         return insertTaskFault(n);
     }
 
-    @Transactional
+
     public int updateTaskFault(Long relId, Long taskId, String faultId, String flag) {
         TaskFault f = selectTaskFaultByRelId(relId);
         f.setTaskId(taskId);
@@ -109,7 +109,7 @@ public class TaskFaultService {
         return updateTaskFault(f);
     }
 
-    @Transactional
+
     public int insertOrUpdateTaskFault(TaskFault tf) {
         TaskFault f = selectUniqueTaskFault(tf.getTaskId(), tf.getFaultId());
         if (f == null) {
@@ -119,7 +119,6 @@ public class TaskFaultService {
         }
     }
 
-    @Transactional
     public int deleteTaskFaultByTaskId(Long taskId) {
         TaskFault q = new TaskFault();
         q.setTaskId(taskId);

+ 57 - 9
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/TaskService.java

@@ -2,13 +2,17 @@ package com.ruoyi.sim.service.impl;
 
 import java.util.List;
 
+import cn.hutool.http.useragent.UserAgentUtil;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.sim.domain.Fault;
 import com.ruoyi.sim.domain.TaskFault;
 import com.ruoyi.sim.domain.vo.FaultTreeVo;
 import com.ruoyi.sim.domain.vo.TaskVo;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.sim.mapper.TaskMapper;
@@ -78,7 +82,7 @@ public class TaskService {
     }
 
     // -------------------------------- tom add  --------------------------------
-
+    private static final Logger l = LoggerFactory.getLogger(TaskService.class);
     @Autowired
     private FaultService faultService;
     @Autowired
@@ -87,22 +91,66 @@ public class TaskService {
     /**
      * 新增任务
      *
-     * @param task 任务
+     * @param tv 任务
      * @return 结果
+     * todo:事务有问题。
      */
     @Transactional
-    public AjaxResult insertTask(TaskVo task) {
-        List<FaultTreeVo> selectedData = task.getSelectedData();
-        task.setCreateTime(DateUtils.getNowDate());
-        task.setUpdateTime(DateUtils.getNowDate());
+    public AjaxResult insertTaskByTeacher(TaskVo tv) {
+        l.info("task new task " + tv);
+        // check
+        if (tv == null) {
+            return AjaxResult.error("TaskVo empty!");
+        }
+        if (!faultService.checkSimTypeOk(tv.getSimType())) {
+            return AjaxResult.error("simType error!");
+        }
+        if (!Task.TASK_TYPE_TEACHER_ADD.equals(tv.getTaskType())) {
+            return AjaxResult.error("taskType value error!");
+        }
+        if (StringUtils.isEmpty(tv.getName())) {
+            return AjaxResult.error("name isEmpty!");
+        }
+        //
+        tv.setCreateByUserId(SecurityUtils.getUserId());
+        tv.setCreateBy(SecurityUtils.getUsername());
+        tv.setCreateTime(DateUtils.getNowDate());
+        tv.setUpdateBy(SecurityUtils.getUsername());
+        tv.setUpdateTime(DateUtils.getNowDate());
+        tv.setRemark("");
+        List<FaultTreeVo> selectedData = tv.getSelectedData();
+        taskMapper.insertTask(tv);
         if (selectedData != null) {
             List<FaultTreeVo> list = FaultService.flatten(selectedData);
-            for (FaultTreeVo one : list) {
-                TaskFault tf = one.getTaskFault();
+            for (FaultTreeVo ftv : list) {
+                if (ftv == null) {
+                    continue;
+                }
+                if (!Fault.FAULT_TYPE_3.equals(ftv.getFaultType())) {
+                    continue;
+                }
+                TaskFault tf = ftv.getTaskFault();
+                // check
+                if (tf == null) {
+                    return AjaxResult.error("TaskFault empty!");
+                }
+                String flag = tf.getFlag();
+                if (StringUtils.isEmpty(flag)) {
+                    return AjaxResult.error("flag empty!");
+                }
+                if (TaskFault.UNKNOWN.equals(flag)) {
+                    return AjaxResult.error("flag UNKNOWN!");
+                }
+                if (!TaskFault.YES.equals(flag) && !TaskFault.NO.equals(flag)) {
+                    return AjaxResult.error("flag must YES or NO!");
+                }
+                // todo:选中数量限制
+
+                // todo:故障部位冲突
+                tf.setTaskId(tv.getTaskId());
                 taskFaultService.insertOrUpdateTaskFault(tf);
             }
         }
-        taskMapper.insertTask(task);
         return AjaxResult.success();
     }
 

+ 3 - 0
ruoyi-sim/src/main/resources/mapper/sim/TaskMapper.xml

@@ -47,6 +47,9 @@
     </select>
 
     <insert id="insertTask" parameterType="Task">
+        <selectKey keyProperty="taskId" order="AFTER" resultType="java.lang.Long">
+            select last_insert_id()
+        </selectKey>
         insert into sim_task
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="taskId != null">task_id,</if>

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels