From fa5ea853099e88be253fca4fb2b0c2b7af5f396e Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 09 十一月 2025 15:57:04 +0800
Subject: [PATCH] feat:微信登录

---
 ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml |  150 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 126 insertions(+), 24 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
index fada6a4..123a769 100644
--- a/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/VehicleInfoMapper.xml
@@ -4,57 +4,104 @@
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.system.mapper.VehicleInfoMapper">
     
-    <resultMap type="VehicleInfo" id="VehicleInfoResult">
-        <result property="vehicleId"    column="vehicle_id"    />
-        <result property="deviceId"     column="device_id"     />
-        <result property="vehicleNo"    column="vehicle_no"    />
-        <result property="vehicleType"  column="vehicle_type"  />
-        <result property="vehicleBrand" column="vehicle_brand" />
-        <result property="vehicleModel" column="vehicle_model" />
-        <result property="status"       column="status"        />
-        <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 type="com.ruoyi.system.domain.VehicleInfo" id="VehicleInfoResult">
+        <id     property="vehicleId"      column="vehicle_id"      />
+        <result property="carId"          column="car_id"          />
+        <result property="deviceId"       column="device_id"       />
+        <result property="vehicleNo"      column="vehicle_no"      />
+        <result property="vehicleType"    column="vehicle_type"    />
+        <result property="vehicleBrand"   column="vehicle_brand"   />
+        <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"     />
+        <result property="updateBy"       column="update_by"       />
+        <result property="updateTime"     column="update_time"     />
+        <result property="remark"         column="remark"          />
+        <!-- 澶氫釜鍒嗗叕鍙稿叧鑱� -->
+        <collection property="deptIds" ofType="Long" 
+                    select="selectVehicleDeptIds" 
+                    column="vehicle_id"/>
+        <collection property="deptNames" ofType="String" 
+                    select="selectVehicleDeptNames" 
+                    column="vehicle_id"/>
     </resultMap>
 
     <sql id="selectVehicleInfoVo">
-        select vehicle_id, device_id, vehicle_no, vehicle_type, vehicle_brand, vehicle_model, status, create_by, create_time, update_by, update_time, remark
-        from tb_vehicle_info
+        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
+        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"/>
         <where>  
-            <if test="vehicleNo != null  and vehicleNo != ''"> and vehicle_no = #{vehicleNo}</if>
-            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
-            <if test="vehicleType != null  and vehicleType != ''"> and vehicle_type = #{vehicleType}</if>
-            <if test="vehicleBrand != null  and vehicleBrand != ''"> and vehicle_brand = #{vehicleBrand}</if>
-            <if test="vehicleModel != null  and vehicleModel != ''"> and vehicle_model = #{vehicleModel}</if>
-            <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="vehicleNo != null  and vehicleNo != ''"> and v.vehicle_no = #{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 vd 
+                    WHERE vd.vehicle_id = v.vehicle_id 
+                    AND vd.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
+
         </where>
     </select>
     
     <select id="selectVehicleInfoById" parameterType="Long" resultMap="VehicleInfoResult">
         <include refid="selectVehicleInfoVo"/>
-        where vehicle_id = #{vehicleId}
+        where v.vehicle_id = #{vehicleId}
     </select>
 
     <select id="selectVehicleInfoByPlateNumber" parameterType="String" resultMap="VehicleInfoResult">
         <include refid="selectVehicleInfoVo"/>
-        where vehicle_no = #{plateNumber}
+        where v.vehicle_no = #{plateNumber}
+    </select>
+
+    <select id="selectVehicleInfoByVehicleNo" parameterType="String" resultMap="VehicleInfoResult">
+        <include refid="selectVehicleInfoVo"/>
+        where v.vehicle_no = #{vehicleNo}
     </select>
         
     <insert id="insertVehicleInfo" parameterType="VehicleInfo" useGeneratedKeys="true" keyProperty="vehicleId">
         insert into tb_vehicle_info
         <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="carId != null">car_id,</if>
             <if test="deviceId != null">device_id,</if>
             <if test="vehicleNo != null">vehicle_no,</if>
             <if test="vehicleType != null">vehicle_type,</if>
             <if test="vehicleBrand != null">vehicle_brand,</if>
             <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>
@@ -62,12 +109,15 @@
             <if test="remark != null">remark,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="carId != null">#{carId},</if>
             <if test="deviceId != null">#{deviceId},</if>
             <if test="vehicleNo != null">#{vehicleNo},</if>
             <if test="vehicleType != null">#{vehicleType},</if>
             <if test="vehicleBrand != null">#{vehicleBrand},</if>
             <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>
@@ -79,14 +129,18 @@
     <update id="updateVehicleInfo" parameterType="VehicleInfo">
         update tb_vehicle_info
         <trim prefix="SET" suffixOverrides=",">
+            <if test="carId != null">car_id = #{carId},</if>
             <if test="deviceId != null">device_id = #{deviceId},</if>
             <if test="vehicleNo != null">vehicle_no = #{vehicleNo},</if>
             <if test="vehicleType != null">vehicle_type = #{vehicleType},</if>
             <if test="vehicleBrand != null">vehicle_brand = #{vehicleBrand},</if>
             <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>
-            update_time = sysdate()
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="remark != null">remark = #{remark},</if>
         </trim>
         where vehicle_id = #{vehicleId}
     </update>
@@ -101,4 +155,52 @@
             #{vehicleId}
         </foreach>
     </delete>
+    
+    <!-- 缁戝畾杞﹁締鍒扮敤鎴� -->
+    <insert id="bindVehicleToUser">
+        INSERT INTO sys_user_vehicle (user_id, vehicle_id, bind_time, bind_by, status, create_by, create_time)
+        VALUES (#{userId}, #{vehicleId}, NOW(), #{bindBy}, '0', #{bindBy}, NOW())
+    </insert>
+    
+    <!-- 瑙g粦鐢ㄦ埛杞﹁締 -->
+    <update id="unbindVehicleFromUser">
+        UPDATE sys_user_vehicle 
+        SET status = '1', update_time = NOW()
+        WHERE user_id = #{userId} AND vehicle_id = #{vehicleId} AND status = '0'
+    </update>
+    
+    <!-- 瑙g粦鐢ㄦ埛鐨勬墍鏈夎溅杈� -->
+    <update id="unbindAllVehiclesFromUser">
+        UPDATE sys_user_vehicle 
+        SET status = '1', update_time = NOW()
+        WHERE user_id = #{userId} AND status = '0'
+    </update>
+    
+    <!-- 鑾峰彇鐢ㄦ埛褰撳墠缁戝畾鐨勮溅杈� -->
+    <select id="getUserBoundVehicle" resultMap="VehicleInfoResult">
+        SELECT v.* 
+        FROM tb_vehicle_info v
+        INNER JOIN sys_user_vehicle uv ON v.vehicle_id = uv.vehicle_id
+        WHERE uv.user_id = #{userId} AND uv.status = '0'
+        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