123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.huaxu.dao.RoleMapper">
- <!-- 结果集 -->
- <resultMap type="com.huaxu.entity.Role" id="RoleMap">
- <result property="id" column="ID" jdbcType="INTEGER"/>
- <result property="tenantId" column="TENANT_ID" jdbcType="VARCHAR"/>
- <result property="roleName" column="ROLE_NAME" jdbcType="VARCHAR"/>
- <result property="description" column="DESCRIPTION" jdbcType="VARCHAR"/>
- <result property="roleState" column="ROLE_STATE" jdbcType="INTEGER"/>
- <result property="permissionType" column="PERMISSION_TYPE" jdbcType="INTEGER"/>
- <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
- <result property="status" column="STATUS" jdbcType="INTEGER"/>
- <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
- <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
- <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
- <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
- </resultMap>
- <resultMap type="com.huaxu.dto.RoleDto" id="RoleDtoMap">
- <result property="id" column="ID" jdbcType="INTEGER"/>
- <result property="roleName" column="ROLE_NAME" jdbcType="VARCHAR"/>
- <result property="users" column="users" jdbcType="INTEGER"/>
- <result property="roleState" column="ROLE_STATE" jdbcType="INTEGER"/>
- </resultMap>
- <!-- 基本字段 -->
- <sql id="Base_Column_List">
- ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY </sql>
- <!-- 查询单个 -->
- <select id="selectById" resultMap="RoleMap">
- select
- <include refid="Base_Column_List"/>
- from uims_role
- where ID = #{id}
- </select>
- <!-- 查询全部 -->
- <select id="selectAll" resultMap="RoleMap">
- select
- <include refid="Base_Column_List"/>
- from uims_role
- </select>
- <!--通过实体作为筛选条件查询-->
- <select id="selectList" resultMap="RoleMap">
- select
- <include refid="Base_Column_List"/>
- from uims_role
- <where>
- and status!=0
- <if test="id != null">
- and ID = #{id}
- </if>
- <if test="tenantId != null and tenantId != ''">
- and TENANT_ID = #{tenantId}
- </if>
- <if test="roleName != null and roleName != ''">
- and ROLE_NAME = #{roleName}
- </if>
- <if test="description != null and description != ''">
- and DESCRIPTION = #{description}
- </if>
- <if test="roleState != null">
- and ROLE_STATE = #{roleState}
- </if>
- <if test="permissionType != null">
- and PERMISSION_TYPE = #{permissionType}
- </if>
- <if test="remark != null and remark != ''">
- and REMARK = #{remark}
- </if>
- <if test="status != null">
- and STATUS = #{status}
- </if>
- <if test="dateCreate != null">
- and DATE_CREATE = #{dateCreate}
- </if>
- <if test="createBy != null and createBy != ''">
- and CREATE_BY = #{createBy}
- </if>
- <if test="dateUpdate != null">
- and DATE_UPDATE = #{dateUpdate}
- </if>
- <if test="updateBy != null and updateBy != ''">
- and UPDATE_BY = #{updateBy}
- </if>
- </where>
- </select>
- <!-- 新增所有列 -->
- <insert id="insert" keyProperty="id" useGeneratedKeys="true">
- insert into uims_role(ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
- values ( #{id}, #{tenantId}, #{roleName}, #{description}, #{roleState}, #{permissionType}, #{remark}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
- </insert>
- <!-- 批量新增 -->
- <insert id="batchInsert">
- insert into uims_role(ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS,
- DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
- values
- <foreach collection="roles" item="item" index="index" separator=",">
- (
- #{item.id}, #{item.tenantId}, #{item.roleName}, #{item.description}, #{item.roleState},
- #{item.permissionType}, #{item.remark}, #{item.status}, #{item.dateCreate}, #{item.createBy},
- #{item.dateUpdate}, #{item.updateBy} )
- </foreach>
- </insert>
- <!-- 通过主键修改数据 -->
- <update id="update">
- update uims.uims_role
- <set>
- <if test="tenantId != null and tenantId != ''">
- TENANT_ID = #{tenantId},
- </if>
- <if test="roleName != null and roleName != ''">
- ROLE_NAME = #{roleName},
- </if>
- <if test="description != null and description != ''">
- DESCRIPTION = #{description},
- </if>
- <if test="roleState != null">
- ROLE_STATE = #{roleState},
- </if>
- <if test="permissionType != null">
- PERMISSION_TYPE = #{permissionType},
- </if>
- <if test="remark != null and remark != ''">
- REMARK = #{remark},
- </if>
- <if test="status != null">
- STATUS = #{status},
- </if>
- <if test="dateCreate != null">
- DATE_CREATE = #{dateCreate},
- </if>
- <if test="createBy != null and createBy != ''">
- CREATE_BY = #{createBy},
- </if>
- <if test="dateUpdate != null">
- DATE_UPDATE = #{dateUpdate},
- </if>
- <if test="updateBy != null and updateBy != ''">
- UPDATE_BY = #{updateBy},
- </if>
- </set>
- where ID = #{id}
- </update>
- <!--通过主键删除-->
- <delete id="deleteById">
- delete from uims_role where ID = #{id}
- </delete>
- <!-- 总数 -->
- <select id="count" resultType="int">
- select count(*) from uims_role
- </select>
- <select id="selectPage" resultMap="RoleDtoMap">
- select
- <include refid="Base_Column_List"/>,users
- from uims_role a left join
- (select count(*) users ,ROLE_ID from uims_user_role b
- <where>
- and status!=0
- </where>
- group by b.ROLE_ID ) b
- ON a.id=b.ROLE_ID
- <where>
- and status!=0
- <if test="role.id != null">
- and ID = #{role.id}
- </if>
- <if test="role.tenantId != null and role.tenantId != ''">
- and TENANT_ID = #{role.tenantId}
- </if>
- <if test="role.roleName != null and role.roleName != ''">
- and ROLE_NAME like concat('%', #{role.roleName}, '%')
- </if>
- <if test="role.description != null and role.description != ''">
- and DESCRIPTION = #{role.description}
- </if>
- <if test="role.roleState != null">
- and ROLE_STATE = #{role.roleState}
- </if>
- <if test="role.permissionType != null">
- and PERMISSION_TYPE = #{role.permissionType}
- </if>
- <if test="role.remark != null and role.remark != ''">
- and REMARK = #{role.remark}
- </if>
- <if test="role.status != null">
- and STATUS = #{role.status}
- </if>
- <if test="role.dateCreate != null">
- and DATE_CREATE = #{role.dateCreate}
- </if>
- <if test="role.createBy != null and role.createBy != ''">
- and CREATE_BY = #{role.createBy}
- </if>
- <if test="role.dateUpdate != null">
- and DATE_UPDATE = #{role.dateUpdate}
- </if>
- <if test="role.updateBy != null and role.updateBy != ''">
- and UPDATE_BY = #{role.updateBy}
- </if>
- </where>
- </select>
- <select id="findRoleUser" resultType="com.huaxu.entity.Role">
- select a.id,b.ROLE_NAME from uims_user_role a join uims_role b on a.ROLE_ID=b.ID
- where a.ROLE_ID=#{id} and a.status!=0 limit 1
- </select>
- <sql id="sysAreaJoins">
- left join uims_org com ON com.id = a.company_org_id
- left join uims_org dep ON dep.id = a.dept_org_id
- left join uims_user_role userrole ON userrole.USER_ID=a.id
- </sql>
- <sql id="userColumns">
- a.id as "id" ,
- a.tenant_id as "tenantId" ,
- a.username as "username" ,
- a.phone as "phone" ,
- a.company_org_id as "companyOrgId" ,
- a.dept_org_id as "deptOrgId" ,
- a.photo as "photo" ,
- a.user_type as "userType" ,
- a.enable_state as "enableState" ,
- a.remark as "remark" ,
- a.email as "email" ,
- a.status as "status" ,
- a.date_create as "dateCreate" ,
- a.create_by as "createBy" ,
- a.date_update as "dateUpdate" ,
- a.update_by as "updateBy",
- com.org_name as "companyOrgName" ,
- dep.org_name as "deptOrgName",
- userrole.id as roleId
- </sql>
- <select id="findUsersByRole" resultType="com.huaxu.entity.UserEntity">
- select <include refid="userColumns"/>
- from uims_user_role b join uims_user a on b.USER_ID=a.ID
- <include refid="sysAreaJoins"/>
- where b.ROLE_ID=#{id} and b.status!=0 and userrole.status!=0
- </select>
- <update id="deleteRoleUser">
- update uims_user_role set status=0 where ROLE_ID=#{id}
- </update>
- <update id="deleteRoleMenu">
- update uims_role_menu set status=0 where ROLE_ID=#{id}
- </update>
- </mapper>
|