MerchantRoleMapper.xml 5.16 KB
<?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="cn.com.glsx.merchants.mapper.MerchantRoleMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.merchants.entity.MerchantRole">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="role_name" jdbcType="VARCHAR" property="roleName"/>
        <result column="role_code" jdbcType="VARCHAR" property="roleCode"/>
        <result column="role_description" jdbcType="VARCHAR" property="roleDescription"/>
        <result column="merchant_id" jdbcType="INTEGER" property="merchantId"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
        <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="created_account" jdbcType="VARCHAR" property="createdAccount"/>
        <result column="updated_account" jdbcType="VARCHAR" property="updatedAccount"/>
        <result column="admin_flag" jdbcType="TINYINT" property="adminFlag"/>
    </resultMap>
    <resultMap id="ResultMap" type="cn.com.glsx.merchants.model.response.MerchantRoleResponse"
               extends="BaseResultMap">
        <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, role_name, role_code, role_description, merchant_id, created_by, created_time, updated_by,
    updated_time, del_flag, created_account, updated_account
  </sql>
    <select id="selectById" parameterType="java.lang.Integer" resultMap="ResultMap">
    select t.id, t.role_name, t.role_code, t.role_description, t.merchant_id, t.created_by, t.created_time, t.updated_by,
    t.updated_time, t.del_flag, t.created_account, t.updated_account, m.merchant_name, t.admin_flag
    from platform_merchant_role t left join platform_merchant m on t.merchant_id = m.id
    where 1 = 1 and t.id = #{id,jdbcType=INTEGER}
  </select>
    <select id="selectByCondition" resultMap="ResultMap"
            parameterType="cn.com.glsx.merchants.model.request.MerchantRoleRequest">
        select t.id, t.role_name, t.role_code, t.role_description, t.merchant_id, t.created_by, t.created_time,
        t.updated_by, t.admin_flag,
        t.updated_time, t.del_flag, t.created_account, t.updated_account, CONCAT(m.merchant_name,'(',m.merchantNo,')')
        as merchant_name
        from platform_merchant_role t left join platform_merchant m on t.merchant_id = m.id
        where t.del_flag in (0, 1)
        <if test="obj.roleName != null and obj.roleName != ''">
            and t.role_name like CONCAT('%',#{obj.roleName,jdbcType=VARCHAR},'%')
        </if>
        <if test="obj.merchantId != null">
            and t.merchant_id = #{obj.merchantId,jdbcType=INTEGER}
        </if>
        <if test="obj.merchantNo != null">
            and m.merchantNo = #{obj.merchantNo,jdbcType=INTEGER}
        </if>
        <if test="obj.delFlag != null">
            and t.del_flag = #{obj.delFlag,jdbcType=TINYINT}
        </if>
        <if test="obj.dataPermission != null and obj.dataPermission.size() > 0">
            and t.merchant_id in
            <foreach collection="obj.dataPermission" item="item" index="index" open="(" close=")" separator=",">
                #{item,jdbcType=INTEGER}
            </foreach>
        </if>
        order by updated_time desc
    </select>
    <select id="selectByNameAndMerchantId" resultMap="ResultMap">
        select
        <include refid="Base_Column_List"/>
        from platform_merchant_role
        where del_flag in (0, 1) and role_name = #{name,jdbcType=VARCHAR} and merchant_id =
        #{merchantId,jdbcType=INTEGER}
    </select>
    <select id="findRoleByIds" resultMap="ResultMap">
        select t.id, t.role_name, t.role_code, t.role_description, t.merchant_id, t.created_by, t.created_time,
        t.updated_by,
        t.updated_time, t.del_flag, t.created_account, t.updated_account, CONCAT(m.merchant_name,'(',m.merchantNo,')')
        as merchant_name
        from platform_merchant_role t left join platform_merchant m on t.merchant_id = m.id
        where t.del_flag in (0, 1)
        and t.merchant_id in
        <foreach collection="merchantIds" item="item" index="index"
                 open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <select id="findRoleIdsByMerchantIds" resultType="java.lang.Integer">
        select id from platform_merchant_role where del_flag = 0 and merchant_id in
        <foreach collection="merchantIds" item="item" index="index"
                 open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <select id="findByIds" resultMap="BaseResultMap">
        select * from platform_merchant_role where del_flag = 0 and id in
        <foreach collection="ids" item="item" index="index"
                 open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
</mapper>