From 1ff17fd97a85cd191467b4a2ffe0e4b7b1959af5 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期日, 12 十一月 2023 17:00:25 +0800
Subject: [PATCH] 查询用户同时得到其对应的多个角色,采用积极关联查询方式

---
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml |   94 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 80 insertions(+), 14 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
index 20721d8..dde6a32 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
@@ -3,27 +3,93 @@
 <!--namespace瀵瑰簲mapper鎺ュ彛鎵�鍦ㄧ殑浣嶇疆-->
 <mapper namespace="com.dy.pipIrrGlobal.daoBa.BaUserMapper">
 
-    <resultMap id="login" type="com.dy.pipIrrGlobal.pojoBa.BaUser">
+    <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaUser">
+        <!--@mbg.generated-->
+        <!--@Table ba_user-->
+        <id property="id" column="id" />
+        <result property="name" column="name"/>
+        <result property="phone" column="phone"/>
+        <result property="password" column="password"/>
+        <result property="orgTag" column="orgTag"/>
+        <result property="supperAdmin" column="supperAdmin"/>
+        <result property="disabled" column="disabled" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.common.mybatis.envm.Disabled"/>
+        <result property="deleted" column="deleted" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.common.mybatis.envm.Deleted"/>
+    </resultMap>
+
+    <resultMap id="partResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaUser">
+        <!--@mbg.generated-->
+        <!--@Table ba_user-->
         <id property="id" column="id" />
         <result property="name" column="name"/>
         <result property="phone" column="phone"/>
         <result property="orgTag" column="orgTag"/>
+        <result property="supperAdmin" column="supperAdmin"/>
+        <result property="disabled" column="disabled" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.common.mybatis.envm.Disabled"/>
     </resultMap>
-    <!--
-        <select id="login" resultMap="login">
-            select id, name, phone, orgTag
-            from ba_user
-            where disabled=0 and deleted=0 and phone=#{phone} and password=#{password}
-        </select>
-        <select id="login" resultType="com.dy.pipIrrGlobal.pojoBa.BaUser">
-            select id, name, phone, orgTag
-        -->
-    <select id="login" resultMap="login" >
-        select *
-        from ba_user r
-        where disabled=0 and deleted=0 and phone=#{phone} and password=#{password}
+
+    <resultMap id="loginResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaUser">
+        <id property="id" column="id" />
+        <result property="name" column="name"/>
+        <result property="phone" column="phone"/>
+        <result property="orgTag" column="orgTag"/>
+        <result property="supperAdmin" column="supperAdmin"/>
+    </resultMap>
+
+    <resultMap id="someResultMap" extends="partResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaUser">
+        <collection property="roleList" fetchType="eager" column="{userId=id}" select="com.dy.pipIrrGlobal.daoBa.BaRoleMapper.selectByUserId" />
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id, name, phone, password, orgTag, supperAdmin, disabled, deleted
+    </sql>
+
+    <sql id="part_Column_List">
+        id, name, phone, orgTag, disabled
+    </sql>
+
+    <sql id="Login_Column_List">
+        id, name, phone, orgTag, supperAdmin
+    </sql>
+
+    <select id="login" resultMap="loginResultMap" >
+        select
+        <include refid="Login_Column_List" />
+        from ba_user
+        where disabled!=1 and deleted!=1 and phone=#{phone} and password=#{password}
     </select>
 
+    <select id="selectTotal" parameterType="java.util.Map" resultType="java.lang.Long">
+        select
+        count(*)
+        from ba_user where supperAdmin!=1 and disabled!=1 and deleted!=1
+        <trim prefix="and" suffixOverrides="and">
+            <if test="name != null">
+                name like concat('%', #{name}, '%') and
+            </if>
+            <if test="phone != null">
+                phone = '#{phone,jdbcType=VARCHAR}'
+            </if>
+        </trim>
+    </select>
+    <select id="selectSome" parameterType="java.util.Map" resultMap="someResultMap">
+        select
+        <include refid="part_Column_List" />
+        from ba_user where supperAdmin!=1 and disabled!=1 and deleted!=1
+        <trim prefix="and" suffixOverrides="and">
+            <if test="name != null">
+                name like concat('%', #{name}, '%') and
+            </if>
+            <if test="phone != null">
+                phone = '#{phone,jdbcType=VARCHAR}'
+            </if>
+        </trim>
+        order by id DESC
+        <trim prefix="limit " >
+            <if test="start != null and count != null">
+                #{start}, #{count}
+            </if>
+        </trim>
+    </select>
     <!--
     <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaUser">
         <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long" id="selectKey">

--
Gitblit v1.8.0