Pārlūkot izejas kodu

添加 Task 相关。

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

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

@@ -1,32 +1,98 @@
 package com.ruoyi.sim.controller;
 
-import com.ruoyi.common.core.controller.BaseController;
-import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.sim.domain.Major;
-import com.ruoyi.sim.service.IMajorService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.factory.annotation.Autowired;
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.sim.domain.Task;
+import com.ruoyi.sim.service.ITaskService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
 
-import java.util.List;
-
-@Api("TaskController")
+/**
+ * 任务Controller
+ *
+ * @author tom
+ * @date 2024-12-13
+ */
 @RestController
 @RequestMapping("/sim/task")
 public class TaskController extends BaseController {
-
     @Autowired
-    private IMajorService majorService;
+    private ITaskService taskService;
 
-    @GetMapping("/list")
+    /**
+     * 查询任务列表
+     */
     @PreAuthorize("@ss.hasPermi('sim:task:list')")
-    public TableDataInfo list(Major major) {
+    @GetMapping("/list")
+    public TableDataInfo list(Task task) {
         startPage();
-        List<Major> list = majorService.selectMajorList(major);
+        List<Task> list = taskService.selectTaskList(task);
         return getDataTable(list);
     }
+
+    /**
+     * 导出任务列表
+     */
+    @PreAuthorize("@ss.hasPermi('sim:task:export')")
+    @Log(title = "任务", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, Task task) {
+        List<Task> list = taskService.selectTaskList(task);
+        ExcelUtil<Task> util = new ExcelUtil<Task>(Task.class);
+        util.exportExcel(response, list, "任务数据");
+    }
+
+    /**
+     * 获取任务详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('sim:task:query')")
+    @GetMapping(value = "/{taskId}")
+    public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
+        return success(taskService.selectTaskByTaskId(taskId));
+    }
+
+    /**
+     * 新增任务
+     */
+    @PreAuthorize("@ss.hasPermi('sim:task:add')")
+    @Log(title = "任务", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody Task task) {
+        return toAjax(taskService.insertTask(task));
+    }
+
+    /**
+     * 修改任务
+     */
+    @PreAuthorize("@ss.hasPermi('sim:task:edit')")
+    @Log(title = "任务", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody Task task) {
+        return toAjax(taskService.updateTask(task));
+    }
+
+    /**
+     * 删除任务
+     */
+    @PreAuthorize("@ss.hasPermi('sim:task:remove')")
+    @Log(title = "任务", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{taskIds}")
+    public AjaxResult remove(@PathVariable Long[] taskIds) {
+        return toAjax(taskService.deleteTaskByTaskIds(taskIds));
+    }
 }

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

@@ -0,0 +1,103 @@
+package com.ruoyi.sim.domain;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * 任务对象 sim_task
+ *
+ * @author tom
+ * @date 2024-12-13
+ */
+public class Task extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 任务ID
+     */
+    private Long taskId;
+
+    /**
+     * 模拟器型号
+     */
+    @Excel(name = "模拟器型号")
+    private String simType;
+
+    /**
+     * 任务类型
+     * 1:教师创建管理
+     * 2:考试临时数据
+     */
+    @Excel(name = "任务类型")
+    private String taskType;
+
+    /**
+     * 任务名称
+     */
+    @Excel(name = "任务名称")
+    private String name;
+
+    /**
+     * 创建教师ID/用户ID
+     */
+    @Excel(name = "创建教师ID/用户ID")
+    private Long createByUserId;
+
+    public void setTaskId(Long taskId) {
+        this.taskId = taskId;
+    }
+
+    public Long getTaskId() {
+        return taskId;
+    }
+
+    public void setSimType(String simType) {
+        this.simType = simType;
+    }
+
+    public String getSimType() {
+        return simType;
+    }
+
+    public void setTaskType(String taskType) {
+        this.taskType = taskType;
+    }
+
+    public String getTaskType() {
+        return taskType;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setCreateByUserId(Long createByUserId) {
+        this.createByUserId = createByUserId;
+    }
+
+    public Long getCreateByUserId() {
+        return createByUserId;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("taskId", getTaskId())
+                .append("simType", getSimType())
+                .append("taskType", getTaskType())
+                .append("name", getName())
+                .append("createByUserId", getCreateByUserId())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
+                .append("remark", getRemark())
+                .toString();
+    }
+}

+ 61 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/mapper/TaskMapper.java

@@ -0,0 +1,61 @@
+package com.ruoyi.sim.mapper;
+
+import java.util.List;
+
+import com.ruoyi.sim.domain.Task;
+
+/**
+ * 任务Mapper接口
+ *
+ * @author tom
+ * @date 2024-12-13
+ */
+public interface TaskMapper {
+    /**
+     * 查询任务
+     *
+     * @param taskId 任务主键
+     * @return 任务
+     */
+    public Task selectTaskByTaskId(Long taskId);
+
+    /**
+     * 查询任务列表
+     *
+     * @param task 任务
+     * @return 任务集合
+     */
+    public List<Task> selectTaskList(Task task);
+
+    /**
+     * 新增任务
+     *
+     * @param task 任务
+     * @return 结果
+     */
+    public int insertTask(Task task);
+
+    /**
+     * 修改任务
+     *
+     * @param task 任务
+     * @return 结果
+     */
+    public int updateTask(Task task);
+
+    /**
+     * 删除任务
+     *
+     * @param taskId 任务主键
+     * @return 结果
+     */
+    public int deleteTaskByTaskId(Long taskId);
+
+    /**
+     * 批量删除任务
+     *
+     * @param taskIds 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteTaskByTaskIds(Long[] taskIds);
+}

+ 61 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/service/ITaskService.java

@@ -0,0 +1,61 @@
+package com.ruoyi.sim.service;
+
+import java.util.List;
+
+import com.ruoyi.sim.domain.Task;
+
+/**
+ * 任务Service接口
+ *
+ * @author tom
+ * @date 2024-12-13
+ */
+public interface ITaskService {
+    /**
+     * 查询任务
+     *
+     * @param taskId 任务主键
+     * @return 任务
+     */
+    public Task selectTaskByTaskId(Long taskId);
+
+    /**
+     * 查询任务列表
+     *
+     * @param task 任务
+     * @return 任务集合
+     */
+    public List<Task> selectTaskList(Task task);
+
+    /**
+     * 新增任务
+     *
+     * @param task 任务
+     * @return 结果
+     */
+    public int insertTask(Task task);
+
+    /**
+     * 修改任务
+     *
+     * @param task 任务
+     * @return 结果
+     */
+    public int updateTask(Task task);
+
+    /**
+     * 批量删除任务
+     *
+     * @param taskIds 需要删除的任务主键集合
+     * @return 结果
+     */
+    public int deleteTaskByTaskIds(Long[] taskIds);
+
+    /**
+     * 删除任务信息
+     *
+     * @param taskId 任务主键
+     * @return 结果
+     */
+    public int deleteTaskByTaskId(Long taskId);
+}

+ 90 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/TaskServiceImpl.java

@@ -0,0 +1,90 @@
+package com.ruoyi.sim.service.impl;
+
+import java.util.List;
+
+import com.ruoyi.common.utils.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.sim.mapper.TaskMapper;
+import com.ruoyi.sim.domain.Task;
+import com.ruoyi.sim.service.ITaskService;
+
+/**
+ * 任务Service业务层处理
+ *
+ * @author tom
+ * @date 2024-12-13
+ */
+@Service
+public class TaskServiceImpl implements ITaskService {
+    @Autowired
+    private TaskMapper taskMapper;
+
+    /**
+     * 查询任务
+     *
+     * @param taskId 任务主键
+     * @return 任务
+     */
+    @Override
+    public Task selectTaskByTaskId(Long taskId) {
+        return taskMapper.selectTaskByTaskId(taskId);
+    }
+
+    /**
+     * 查询任务列表
+     *
+     * @param task 任务
+     * @return 任务
+     */
+    @Override
+    public List<Task> selectTaskList(Task task) {
+        return taskMapper.selectTaskList(task);
+    }
+
+    /**
+     * 新增任务
+     *
+     * @param task 任务
+     * @return 结果
+     */
+    @Override
+    public int insertTask(Task task) {
+        task.setCreateTime(DateUtils.getNowDate());
+        return taskMapper.insertTask(task);
+    }
+
+    /**
+     * 修改任务
+     *
+     * @param task 任务
+     * @return 结果
+     */
+    @Override
+    public int updateTask(Task task) {
+        task.setUpdateTime(DateUtils.getNowDate());
+        return taskMapper.updateTask(task);
+    }
+
+    /**
+     * 批量删除任务
+     *
+     * @param taskIds 需要删除的任务主键
+     * @return 结果
+     */
+    @Override
+    public int deleteTaskByTaskIds(Long[] taskIds) {
+        return taskMapper.deleteTaskByTaskIds(taskIds);
+    }
+
+    /**
+     * 删除任务信息
+     *
+     * @param taskId 任务主键
+     * @return 结果
+     */
+    @Override
+    public int deleteTaskByTaskId(Long taskId) {
+        return taskMapper.deleteTaskByTaskId(taskId);
+    }
+}

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

@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.sim.mapper.TaskMapper">
+
+    <resultMap type="Task" id="TaskResult">
+        <result property="taskId" column="task_id"/>
+        <result property="simType" column="sim_type"/>
+        <result property="taskType" column="task_type"/>
+        <result property="name" column="name"/>
+        <result property="createByUserId" column="create_by_user_id"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="remark" column="remark"/>
+    </resultMap>
+
+    <sql id="selectTaskVo">
+        select task_id,
+               sim_type,
+               task_type,
+               name,
+               create_by_user_id,
+               create_by,
+               create_time,
+               update_by,
+               update_time,
+               remark
+        from sim_task
+    </sql>
+
+    <select id="selectTaskList" parameterType="Task" resultMap="TaskResult">
+        <include refid="selectTaskVo"/>
+        <where>
+            <if test="simType != null  and simType != ''">and sim_type = #{simType}</if>
+            <if test="taskType != null  and taskType != ''">and task_type = #{taskType}</if>
+            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
+            <if test="createByUserId != null ">and create_by_user_id = #{createByUserId}</if>
+        </where>
+    </select>
+
+    <select id="selectTaskByTaskId" parameterType="Long" resultMap="TaskResult">
+        <include refid="selectTaskVo"/>
+        where task_id = #{taskId}
+    </select>
+
+    <insert id="insertTask" parameterType="Task">
+        insert into sim_task
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="taskId != null">task_id,</if>
+            <if test="simType != null">sim_type,</if>
+            <if test="taskType != null">task_type,</if>
+            <if test="name != null">name,</if>
+            <if test="createByUserId != null">create_by_user_id,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="remark != null">remark,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="taskId != null">#{taskId},</if>
+            <if test="simType != null">#{simType},</if>
+            <if test="taskType != null">#{taskType},</if>
+            <if test="name != null">#{name},</if>
+            <if test="createByUserId != null">#{createByUserId},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="remark != null">#{remark},</if>
+        </trim>
+    </insert>
+
+    <update id="updateTask" parameterType="Task">
+        update sim_task
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="simType != null">sim_type = #{simType},</if>
+            <if test="taskType != null">task_type = #{taskType},</if>
+            <if test="name != null">name = #{name},</if>
+            <if test="createByUserId != null">create_by_user_id = #{createByUserId},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="remark != null">remark = #{remark},</if>
+        </trim>
+        where task_id = #{taskId}
+    </update>
+
+    <delete id="deleteTaskByTaskId" parameterType="Long">
+        delete
+        from sim_task
+        where task_id = #{taskId}
+    </delete>
+
+    <delete id="deleteTaskByTaskIds" parameterType="String">
+        delete from sim_task where task_id in
+        <foreach item="taskId" collection="array" open="(" separator="," close=")">
+            #{taskId}
+        </foreach>
+    </delete>
+</mapper>