From 6bce1b35246ed695a4272c24254c7073a524818a Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期二, 30 七月 2024 13:33:12 +0800
Subject: [PATCH] 电磁锁查询加入状态修改提交

---
 ard-work/src/main/resources/mapper/sy/ArdTankLockMapper.xml |   58 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/ard-work/src/main/resources/mapper/sy/ArdTankLockMapper.xml b/ard-work/src/main/resources/mapper/sy/ArdTankLockMapper.xml
index 6608f8d..768041d 100644
--- a/ard-work/src/main/resources/mapper/sy/ArdTankLockMapper.xml
+++ b/ard-work/src/main/resources/mapper/sy/ArdTankLockMapper.xml
@@ -42,6 +42,26 @@
         </association>
     </resultMap>
 
+    <resultMap type="ArdTankLock" id="ArdTankLockWithPasswordResult">
+        <result property="id"    column="id"    />
+        <result property="lockNum"    column="lock_num"    />
+        <result property="lockName"    column="lock_name"    />
+        <result property="imgPositionTop"    column="img_position_top"    />
+        <result property="imgPositionLeft"    column="img_position_left"    />
+        <result property="carId"    column="car_id"    />
+        <result property="enable"    column="enable"    />
+        <result property="restartState"    column="restart_state"    />
+        <result property="onlineTime"    column="online_time"    />
+        <collection property="ardTankLockPasswords" ofType="com.ruoyi.sy.domain.ArdTankLockPassword">
+            <result property="id"    column="pid"    />
+            <result property="lockId"    column="lock_id"    />
+            <result property="password"    column="password"    />
+            <result property="no"    column="no"    />
+            <result property="createTime"    column="create_time"    />
+            <result property="useTime"    column="use_time"    />
+        </collection>
+    </resultMap>
+
     <sql id="selectArdTankLockVo">
         select id, lock_num, lock_name, img_position_top, img_position_left, car_id, enable, restart_state, online_time from ard_tank_lock
     </sql>
@@ -135,21 +155,29 @@
     </insert>
 
     <select id="getLockByCarId" resultMap="ArdTankLockWithStateResult" parameterType="java.lang.String">
-        select atl.id,atl.lock_num,atl.lock_name,atl.img_position_top,
+        select t.id,t.lock_num,t.lock_name,t.img_position_top,t.img_position_left,
+        t.car_id,t.enable,t.restart_state,t.online_time,t.sid,t.lock_id,t.slock_num,
+        t.lock_state,t.lock_position_state,t.lock_shell_state,t.srestart_state,
+        t.batter_voltage,t.power_voltage,t.upload_time,t.unique_mark,
+        t.lock_state_mark from (select atl.id,atl.lock_num,atl.lock_name,atl.img_position_top,
         atl.img_position_left,atl.car_id,atl.enable,atl.restart_state,
-        atl.online_time,atls.id as sid,atls.lock_id,atls.lock_num as slock_num,
-        atls.lock_state,atls.lock_position_state,atls.lock_shell_state,
-        atls.restart_state as srestart_state,atls.batter_voltage,
-        atls.power_voltage,atls.upload_time,atls.unique_mark,
+        coalesce(atl.online_time,'') as online_time,coalesce(atls.id,'') as sid,
+        coalesce(atls.lock_id,'') as lock_id,coalesce(atls.lock_num,'') as slock_num,
+        coalesce(atls.lock_state,'') as lock_state,coalesce(atls.lock_position_state,'') as lock_position_state,
+        coalesce(atls.lock_shell_state,'') as lock_shell_state,coalesce(atls.restart_state,'') as srestart_state,
+        coalesce(atls.batter_voltage,'') as batter_voltage,coalesce(atls.power_voltage,'') as power_voltage,
+        coalesce(atls.upload_time,'') as upload_time,coalesce(atls.unique_mark,'') as unique_mark,
         case atls.lock_state
-        when '鍏抽攣鐘舵��' then false
-        when '寮傚父鐘舵��' then false
-        when '寮�閿佺姸鎬�' then true
-        end as lock_state_mark
+          when '鍏抽攣鐘舵��' then false
+          when '寮傚父鐘舵��' then false
+          when '鍔ㄤ綔鐘舵��' then false
+          when '寮�閿佺姸鎬�' then true
+          else false
+          end as lock_state_mark,
+        rank() over(partition by atl.lock_num order by atls.upload_time desc,atl.lock_num) rn
         from ard_tank_lock atl
         left join ard_tank_lock_state atls on atl."id" = atls.lock_id
-        where car_id = #{carId} order by atls.upload_time desc,atl.lock_num
-        limit 1
+        where car_id = #{carId} order by atls.upload_time desc,atl.lock_num)t where t.rn = 1
     </select>
 
     <delete id="deleteLockByCarId" parameterType="java.lang.String">
@@ -204,4 +232,12 @@
     <select id="getIdByLockNum" resultType="java.lang.String" parameterType="java.lang.String">
         select id from ard_tank_lock atl where atl.lock_num = #{lockNum}
     </select>
+
+    <select id="selectArdTankLockWithPassword" resultMap="ArdTankLockWithPasswordResult" >
+        select atl."id",atl.lock_num,atl.lock_name,atl.img_position_top,
+        atl.img_position_left,atl.car_id,atl."enable",atl.restart_state,
+        atl.online_time,atlp."id" as pid,atlp.lock_id,atlp."password",
+        atlp.create_time,atlp.use_time  from ard_tank_lock atl
+        left join ard_tank_lock_password atlp on atl.id = atlp.lock_id and use_time is null
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3