From 310633feef20e9b77d44fd25e0b41778e033b33b Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期二, 11 十一月 2025 21:48:46 +0800
Subject: [PATCH] feat: 车辆GPS统计,并修改了一些变更任务状态的逻辑

---
 ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml |   84 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml
index 599cd7e..338d8e2 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml
@@ -30,9 +30,23 @@
         <result property="updateBy"         column="update_by"         />
         <result property="remark"           column="remark"            />
         <result property="delFlag"          column="del_flag"          />
+        <result property="legacySynced"     column="legacy_synced"     />
         <result property="creatorName"      column="creator_name"      />
         <result property="assigneeName"     column="assignee_name"     />
         <result property="deptName"         column="dept_name"         />
+        <collection property="assignedVehicles" ofType="SysTaskVehicle">
+            <result property="id"            column="tv_id"             />
+            <result property="taskId"        column="tv_task_id"        />
+            <result property="vehicleId"     column="tv_vehicle_id"     />
+            <result property="vehicleNo"     column="tv_vehicle_no"     />
+            <result property="vehicleType"   column="tv_vehicle_type"   />
+            <result property="vehicleBrand"  column="tv_vehicle_brand"  />
+            <result property="vehicleModel"  column="tv_vehicle_model"  />
+            <result property="assignTime"    column="tv_assign_time"    />
+            <result property="assignBy"      column="tv_assign_by"      />
+            <result property="status"        column="tv_status"         />
+            <result property="remark"        column="tv_remark"         />
+        </collection>
     </resultMap>
 
     <sql id="selectSysTaskVo">
@@ -41,12 +55,19 @@
                t.destination_longitude, t.destination_latitude, t.estimated_distance,
                t.planned_start_time, t.planned_end_time,
                t.actual_start_time, t.actual_end_time, t.creator_id, t.assignee_id, t.dept_id,
-               t.create_time, t.update_time, t.create_by, t.update_by, t.remark, t.del_flag,
-               u1.nick_name as creator_name, u2.nick_name as assignee_name, d.dept_name
+               t.create_time, t.update_time, t.create_by, t.update_by, t.remark, t.del_flag, t.legacy_synced,
+               u1.nick_name as creator_name, u2.nick_name as assignee_name, d.dept_name,
+               tv.id as tv_id, tv.task_id as tv_task_id, tv.vehicle_id as tv_vehicle_id,
+               v.vehicle_no as tv_vehicle_no, v.vehicle_type as tv_vehicle_type,
+               v.vehicle_brand as tv_vehicle_brand, v.vehicle_model as tv_vehicle_model,
+               tv.assign_time as tv_assign_time, tv.assign_by as tv_assign_by,
+               tv.status as tv_status, tv.remark as tv_remark
         from sys_task t
         left join sys_user u1 on t.creator_id = u1.user_id
         left join sys_user u2 on t.assignee_id = u2.user_id
         left join sys_dept d on t.dept_id = d.dept_id
+        left join sys_task_vehicle tv on t.task_id = tv.task_id
+        left join tb_vehicle_info v on tv.vehicle_id = v.vehicle_id
     </sql>
 
     <select id="selectSysTaskList" parameterType="TaskQueryVO" resultMap="SysTaskResult">
@@ -56,16 +77,38 @@
             <if test="taskCode != null  and taskCode != ''"> and t.task_code like concat('%', #{taskCode}, '%')</if>
             <if test="taskType != null  and taskType != ''"> and t.task_type = #{taskType}</if>
             <if test="taskStatus != null  and taskStatus != ''"> and t.task_status = #{taskStatus}</if>
-            <if test="creatorId != null "> and t.creator_id = #{creatorId}</if>
-            <if test="assigneeId != null "> and t.assignee_id = #{assigneeId}</if>
-            <if test="deptId != null "> and t.dept_id = #{deptId}</if>
+            <!-- 缁煎悎鏌ヨ锛氬綋鍓嶇敤鎴锋墍鍦ㄦ満鏋� OR 褰撳墠鐢ㄦ埛鍒涘缓 OR 鍒嗛厤缁欏綋鍓嶇敤鎴� -->
+            <if test="(creatorId != null and creatorId != 0) or (assigneeId != null and assigneeId != 0) or (deptId != null and deptId != 0)">
+                and (
+                    <if test="deptId != null and deptId != 0">t.dept_id = #{deptId}</if>
+                    <if test="creatorId != null and creatorId != 0">
+                        <if test="deptId != null and deptId != 0"> or </if>
+                        t.creator_id = #{creatorId}
+                    </if>
+                    <if test="assigneeId != null and assigneeId != 0">
+                        <if test="(deptId != null and deptId != 0) or (creatorId != null and creatorId != 0)"> or </if>
+                        t.assignee_id = #{assigneeId}
+                    </if>
+                )
+            </if>
             <if test="plannedStartTimeBegin != null "> and t.planned_start_time &gt;= #{plannedStartTimeBegin}</if>
             <if test="plannedStartTimeEnd != null "> and t.planned_start_time &lt;= #{plannedStartTimeEnd}</if>
             <if test="plannedEndTimeBegin != null "> and t.planned_end_time &gt;= #{plannedEndTimeBegin}</if>
             <if test="plannedEndTimeEnd != null "> and t.planned_end_time &lt;= #{plannedEndTimeEnd}</if>
             <if test="overdue != null and overdue == true"> and t.planned_end_time &lt; now() and t.task_status != 'COMPLETED'</if>
         </where>
-        order by t.create_time desc
+        order by 
+            CASE t.task_status
+                WHEN 'PENDING' THEN 1
+                WHEN 'DEPARTING' THEN 2
+                WHEN 'ARRIVED' THEN 3
+                WHEN 'RETURNING' THEN 4
+                WHEN 'IN_PROGRESS' THEN 5
+                WHEN 'COMPLETED' THEN 6
+                WHEN 'CANCELLED' THEN 7
+                ELSE 8
+            END,
+            t.create_time desc
     </select>
     
     <select id="selectSysTaskByTaskId" parameterType="Long" resultMap="SysTaskResult">
@@ -81,7 +124,7 @@
     <select id="selectMaxTaskCodeByDatePrefix" parameterType="String" resultType="String">
         select max(task_code) 
         from sys_task 
-        where task_code like concat(#{datePrefix}, '%') and del_flag = '0'
+        where task_code like concat(#{datePrefix}, '%')
     </select>
 
     <select id="selectOverdueTasks" resultMap="SysTaskResult">
@@ -93,7 +136,19 @@
     <select id="selectMyTasks" parameterType="Long" resultMap="SysTaskResult">
         <include refid="selectSysTaskVo"/>
         where t.del_flag = '0' and (t.creator_id = #{userId} or t.assignee_id = #{userId})
-        order by t.create_time desc
+        order by 
+            CASE t.task_status
+                WHEN 'PENDING' THEN 1
+                WHEN 'DEPARTING' THEN 2
+                WHEN 'ARRIVED' THEN 3
+                WHEN 'RETURNING' THEN 4
+                WHEN 'IN_PROGRESS' THEN 5
+                WHEN 'COMPLETED' THEN 6
+                WHEN 'CANCELLED' THEN 7
+                ELSE 8
+            END,
+            t.update_time desc,
+            t.create_time desc
     </select>
 
     <select id="selectTaskStatistics" resultType="TaskStatisticsVO">
@@ -213,6 +268,19 @@
         where task_id = #{taskId}
     </update>
 
+    <select id="selectActiveTasksByVehicleId" parameterType="Long" resultMap="SysTaskResult">
+        select t.task_id, t.task_code, t.task_type, t.task_status, t.task_description,
+               t.departure_address, t.destination_address,
+               t.planned_start_time, t.actual_start_time,
+               t.create_time, t.update_time
+        from sys_task t
+        inner join sys_task_vehicle tv on t.task_id = tv.task_id
+        where tv.vehicle_id = #{vehicleId}
+          and t.del_flag = '0'
+          and t.task_status not in ('PENDING', 'COMPLETED', 'CANCELLED')
+        order by t.create_time desc
+    </select>
+
     <delete id="deleteSysTaskByTaskId" parameterType="Long">
         update sys_task set del_flag = '2', update_time = now() where task_id = #{taskId}
     </delete>

--
Gitblit v1.9.1