From 656d6f8029f8bf9b2daa9dcc89101a879a70b860 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期三, 03 十二月 2025 23:10:05 +0800
Subject: [PATCH] feat:优先添加执行人

---
 ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml |  159 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 121 insertions(+), 38 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
index 8b904e6..09303ac 100644
--- a/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
@@ -14,7 +14,6 @@
         <result property="vehicleModel"   column="vehicle_model"   />
         <result property="status"         column="status"          />
         <result property="platformCode"   column="platform_code"   />
-        <result property="deptId"         column="dept_id"         />
         <result property="deptName"       column="dept_name"       />
         <result property="createBy"       column="create_by"       />
         <result property="createTime"     column="create_time"     />
@@ -22,69 +21,138 @@
         <result property="updateTime"     column="update_time"     />
         <result property="remark"         column="remark"          />
     </resultMap>
+    
+    <!-- 鍖呭惈澶氬垎鍏徃鍏宠仈鐨勫畬鏁寸粨鏋滄槧灏勶紙浠呭湪闇�瑕佹椂浣跨敤锛� -->
+    <resultMap type="com.ruoyi.system.domain.VehicleInfo" id="VehicleInfoWithDeptsResult" extends="VehicleInfoResult">
+        <!-- 澶氫釜鍒嗗叕鍙稿叧鑱旓紙绔嬪嵆鍔犺浇锛岄伩鍏嶅欢杩熷姞杞藉鑷寸殑搴忓垪鍖栭棶棰橈級 -->
+        <collection property="deptIds" ofType="Long" 
+                    select="selectVehicleDeptIds" 
+                    column="vehicle_id"
+                    fetchType="eager"/>
+        <collection property="deptNames" ofType="String" 
+                    select="selectVehicleDeptNames" 
+                    column="vehicle_id"
+                    fetchType="eager"/>
+    </resultMap>
 
     <sql id="selectVehicleInfoVo">
-        select v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand, v.vehicle_model, v.status, v.platform_code, v.dept_id, d.dept_name, v.create_by, v.create_time, v.update_by, v.update_time, v.remark
+        select v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand, v.vehicle_model, v.status, v.platform_code, v.create_by, v.create_time, v.update_by, v.update_time, v.remark
         from tb_vehicle_info v
-        left join sys_dept d on v.dept_id = d.dept_id
     </sql>
+    
+    <!-- 鏌ヨ杞﹁締鍏宠仈鐨勬墍鏈夊垎鍏徃ID -->
+    <select id="selectVehicleDeptIds" resultType="Long">
+        SELECT dept_id FROM tb_vehicle_dept WHERE vehicle_id = #{vehicle_id}
+    </select>
+    
+    <!-- 鏌ヨ杞﹁締鍏宠仈鐨勬墍鏈夊垎鍏徃鍚嶇О -->
+    <select id="selectVehicleDeptNames" resultType="String">
+        SELECT d.dept_name 
+        FROM tb_vehicle_dept vd
+        LEFT JOIN sys_dept d ON vd.dept_id = d.dept_id
+        WHERE vd.vehicle_id = #{vehicle_id}
+    </select>
 
-    <select id="selectVehicleInfoList" parameterType="VehicleInfo" resultMap="VehicleInfoResult">
-        <include refid="selectVehicleInfoVo"/>
+    <select id="selectVehicleInfoListWithDepts" parameterType="VehicleInfo" resultMap="VehicleInfoWithDeptsResult">
+        select v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand, 
+               v.vehicle_model, v.status, v.platform_code, v.create_by, v.create_time, 
+               v.update_by, v.update_time, v.remark
+        from tb_vehicle_info v
         <where>  
-            <if test="vehicleNo != null  and vehicleNo != ''"> and v.vehicle_no = #{vehicleNo}</if>
+            <if test="vehicleNo != null  and vehicleNo != ''"> and v.vehicle_no LIKE concat('%', #{vehicleNo}, '%')</if>
             <if test="deviceId != null  and deviceId != ''"> and v.device_id = #{deviceId}</if>
             <if test="vehicleType != null  and vehicleType != ''"> and v.vehicle_type = #{vehicleType}</if>
             <if test="vehicleBrand != null  and vehicleBrand != ''"> and v.vehicle_brand = #{vehicleBrand}</if>
             <if test="vehicleModel != null  and vehicleModel != ''"> and v.vehicle_model = #{vehicleModel}</if>
             <if test="status != null  and status != ''"> and v.status = #{status}</if>
             <if test="platformCode != null  and platformCode != ''"> and v.platform_code = #{platformCode}</if>
-<<<<<<< HEAD
-            <if test="deptId != null"> and v.dept_id = #{deptId}</if>
-=======
-            <!-- 閮ㄩ棬杩囨护锛氳嚜鍔ㄦ煡鎵句紶鍏ラ儴闂ㄦ墍灞炵殑鍒嗗叕鍙革紙parent_id=100锛� -->
+            <!-- 閮ㄩ棬杩囨护锛氭牴鎹垎鍏徃ID鏌ヨ杞﹁締锛堥�氳繃鍏宠仈琛級 -->
             <if test="deptId != null">
-                and v.dept_id = (
-                    <!-- 濡傛灉浼犲叆鐨勫氨鏄垎鍏徃锛坧arent_id=100锛夛紝鐩存帴杩斿洖 -->
-                    select case 
-                        when exists(select 1 from sys_dept where dept_id = #{deptId} and parent_id = 100) then #{deptId}
-                        else (
-                            <!-- 鍚﹀垯浠� ancestors 涓煡鎵惧垎鍏徃ID -->
-                            select d.dept_id
-                            from sys_dept d
-                            where d.parent_id = 100
-                            and FIND_IN_SET(d.dept_id, (
-                                select ancestors from sys_dept where dept_id = #{deptId}
-                            ))
-                            limit 1
-                        )
-                    end
+                and EXISTS (
+                    SELECT 1 FROM tb_vehicle_dept vd2 
+                    WHERE vd2.vehicle_id = v.vehicle_id 
+                    AND vd2.dept_id = #{deptId}
                 )
             </if>
-            <!-- 浠诲姟杞﹁締閫夋嫨蹇呴』杩囨护锛氬彧鏄剧ずcar_id鍜宒ept_id閮戒笉涓虹┖鐨勮溅杈� -->
-            and v.car_id is not null and v.car_id != ''
-            and v.dept_id is not null
             and v.status=0
->>>>>>> feature-task
         </where>
+        group by v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand,
+                 v.vehicle_model, v.status, v.platform_code, v.create_by, v.create_time,
+                 v.update_by, v.update_time, v.remark
+        order by v.create_time desc
     </select>
     
-    <select id="selectVehicleInfoById" parameterType="Long" resultMap="VehicleInfoResult">
+    <select id="selectVehicleInfoList" parameterType="VehicleInfo" resultMap="VehicleInfoResult">
+        select v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand, 
+               v.vehicle_model, v.status, v.platform_code, v.create_by, v.create_time, 
+               v.update_by, v.update_time, v.remark,
+               GROUP_CONCAT(DISTINCT d.dept_name ORDER BY d.dept_name SEPARATOR ',') as dept_name
+        from tb_vehicle_info v
+        left join tb_vehicle_dept vd on v.vehicle_id = vd.vehicle_id
+        left join sys_dept d on vd.dept_id = d.dept_id
+        <where>  
+            <if test="vehicleNo != null  and vehicleNo != ''"> and v.vehicle_no LIKE concat('%', #{vehicleNo}, '%')</if>
+            <if test="deviceId != null  and deviceId != ''"> and v.device_id = #{deviceId}</if>
+            <if test="vehicleType != null  and vehicleType != ''"> and v.vehicle_type = #{vehicleType}</if>
+            <if test="vehicleBrand != null  and vehicleBrand != ''"> and v.vehicle_brand = #{vehicleBrand}</if>
+            <if test="vehicleModel != null  and vehicleModel != ''"> and v.vehicle_model = #{vehicleModel}</if>
+            <if test="status != null  and status != ''"> and v.status = #{status}</if>
+            <if test="platformCode != null  and platformCode != ''"> and v.platform_code = #{platformCode}</if>
+            <!-- 閮ㄩ棬杩囨护锛氭牴鎹垎鍏徃ID鏌ヨ杞﹁締锛堥�氳繃鍏宠仈琛級 -->
+            <if test="deptId != null">
+                and EXISTS (
+                    SELECT 1 FROM tb_vehicle_dept vd2 
+                    WHERE vd2.vehicle_id = v.vehicle_id 
+                    AND vd2.dept_id = #{deptId}
+                )
+            </if>
+            <!-- 浠诲姟杞﹁締閫夋嫨蹇呴』杩囨护锛氬彧鏄剧ずcar_id涓嶄负绌轰笖宸插叧鑱斿垎鍏徃鐨勮溅杈� -->
+<!--            and v.car_id is not null and v.car_id != ''-->
+<!--            and EXISTS (SELECT 1 FROM tb_vehicle_dept vd WHERE vd.vehicle_id = v.vehicle_id)-->
+            and v.status=0
+
+        </where>
+        group by v.vehicle_id, v.car_id, v.device_id, v.vehicle_no, v.vehicle_type, v.vehicle_brand,
+                 v.vehicle_model, v.status, v.platform_code, v.create_by, v.create_time,
+                 v.update_by, v.update_time, v.remark
+    </select>
+    
+    <select id="selectVehicleInfoById" parameterType="Long" resultMap="VehicleInfoWithDeptsResult">
+        <include refid="selectVehicleInfoVo"/>
+        where v.vehicle_id = #{vehicleId}
+    </select>
+    
+    <!-- 鏌ヨ杞﹁締淇℃伅锛堝寘鍚鍒嗗叕鍙稿叧鑱旓級 -->
+    <select id="selectVehicleInfoWithDeptsById" parameterType="Long" resultMap="VehicleInfoWithDeptsResult">
         <include refid="selectVehicleInfoVo"/>
         where v.vehicle_id = #{vehicleId}
     </select>
 
     <select id="selectVehicleInfoByPlateNumber" parameterType="String" resultMap="VehicleInfoResult">
         <include refid="selectVehicleInfoVo"/>
-        where v.vehicle_no = #{plateNumber}
-<<<<<<< HEAD
+        where v.vehicle_no LIKE concat('%', #{plateNumber}, '%')
+        limit 1
     </select>
 
     <select id="selectVehicleInfoByVehicleNo" parameterType="String" resultMap="VehicleInfoResult">
         <include refid="selectVehicleInfoVo"/>
-        where v.vehicle_no = #{vehicleNo}
-=======
->>>>>>> feature-task
+        where v.vehicle_no LIKE concat('%', #{vehicleNo}, '%')
+    </select>
+    
+    <!-- 鏍规嵁鏃х郴缁熻溅杈咺D(CarID)鏌ヨ杞﹁締淇℃伅 -->
+    <select id="selectVehicleInfoByCarId" parameterType="Integer" resultMap="VehicleInfoResult">
+        <include refid="selectVehicleInfoVo"/>
+        where v.car_id = #{carId}
+    </select>
+    
+    <!-- 鏍规嵁鏃х郴缁熻溅杈咺D鏌ヨ杞﹁締淇℃伅 -->
+    <select id="selectVehicleInfoByCarID" resultType="java.util.HashMap">
+        SELECT 
+            vehicle_id,
+            car_id,
+            vehicle_no
+        FROM tb_vehicle_info 
+        WHERE car_id = #{carID}
     </select>
         
     <insert id="insertVehicleInfo" parameterType="VehicleInfo" useGeneratedKeys="true" keyProperty="vehicleId">
@@ -98,7 +166,6 @@
             <if test="vehicleModel != null">vehicle_model,</if>
             <if test="status != null">status,</if>
             <if test="platformCode != null">platform_code,</if>
-            <if test="deptId != null">dept_id,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>
@@ -114,7 +181,6 @@
             <if test="vehicleModel != null">#{vehicleModel},</if>
             <if test="status != null">#{status},</if>
             <if test="platformCode != null">#{platformCode},</if>
-            <if test="deptId != null">#{deptId},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
@@ -134,7 +200,6 @@
             <if test="vehicleModel != null">vehicle_model = #{vehicleModel},</if>
             <if test="status != null">status = #{status},</if>
             <if test="platformCode != null">platform_code = #{platformCode},</if>
-            <if test="deptId != null">dept_id = #{deptId},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="remark != null">remark = #{remark},</if>
@@ -182,4 +247,22 @@
         ORDER BY uv.bind_time DESC
         LIMIT 1
     </select>
+    
+    <!-- 鎵归噺鎻掑叆杞﹁締-鍒嗗叕鍙稿叧鑱� -->
+    <insert id="batchInsertVehicleDept">
+        INSERT INTO tb_vehicle_dept (vehicle_id, dept_id, order_class, create_by, create_time)
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (#{item.vehicleId}, #{item.deptId}, #{item.orderClass}, #{item.createBy}, NOW())
+        </foreach>
+        ON DUPLICATE KEY UPDATE
+        order_class = VALUES(order_class),
+        update_by = VALUES(create_by),
+        update_time = NOW()
+    </insert>
+    
+    <!-- 鍒犻櫎杞﹁締鐨勬墍鏈夊垎鍏徃鍏宠仈 -->
+    <delete id="deleteVehicleDeptByVehicleId">
+        DELETE FROM tb_vehicle_dept WHERE vehicle_id = #{vehicleId}
+    </delete>
 </mapper> 
\ No newline at end of file

--
Gitblit v1.9.1