RoleFunctionRelationMapper.xml 8.82 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.RoleFunctionRelationMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.merchants.entity.RoleFunctionRelation">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="role_accounttype_id" jdbcType="INTEGER" property="roleAccounttypeId"/>
        <result column="product_id" jdbcType="INTEGER" property="productId"/>
        <result column="menu_id" jdbcType="INTEGER" property="menuId"/>
        <result column="funciton_id" jdbcType="INTEGER" property="funcitonId"/>
        <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="function_value" jdbcType="VARCHAR" property="functionValue"/>
    </resultMap>
    <resultMap id="ResultMap" type="cn.com.glsx.merchants.model.response.RoleFunctionRelationResponse"
               extends="BaseResultMap">
        <result column="product_name" jdbcType="VARCHAR" property="productName"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
        , role_accounttype_id, product_id, menu_id, funciton_id, created_by, created_time,
    updated_by, updated_time, del_flag, function_value
    </sql>
    <delete id="deleteByRelationIdList" parameterType="java.lang.Integer">
        update platform_merchant_role_function_relation set del_flag = -1
        where 1 = 1 and role_accounttype_id in
        <foreach collection="idList" separator="," close=")" open="(" index="index" item="item">
            #{item,jdbcType=INTEGER}
        </foreach>
    </delete>
    <delete id="deleteByCondition" parameterType="java.lang.Integer">
        update platform_merchant_role_function_relation set del_flag = -1
        where 1 = 1 and role_accounttype_id in
        <foreach collection="idList" separator="," close=")" open="(" index="index" item="item">
            #{item.id,jdbcType=INTEGER}
        </foreach>
        <if test="productId != null">
            and product_id = #{productId,jdbcType=INTEGER}
        </if>
        <if test="menuId != null">
            and menu_id = #{menuId,jdbcType=INTEGER}
        </if>
        <if test="functionId != null">
            and funciton_id = #{functionId,jdbcType=INTEGER}
        </if>
    </delete>
    <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
        insert into platform_merchant_role_function_relation
        (role_accounttype_id, product_id, menu_id, funciton_id, created_by, created_time,
        updated_by, updated_time, del_flag, function_value)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.roleAccounttypeId,jdbcType=INTEGER}, #{item.productId,jdbcType=INTEGER},
            #{item.menuId,jdbcType=INTEGER}, #{item.funcitonId,jdbcType=INTEGER}, #{item.createdBy,jdbcType=INTEGER},
            #{item.createdTime,jdbcType=TIMESTAMP}, #{item.updatedBy,jdbcType=INTEGER},
            #{item.updatedTime,jdbcType=TIMESTAMP},
            #{item.delFlag,jdbcType=TINYINT}, #{item.functionValue,jdbcType=VARCHAR})
        </foreach>
    </insert>
    <select id="selectByCondition" resultMap="ResultMap"
            parameterType="cn.com.glsx.merchants.model.request.RoleFunctionRelationRequest">
        select t.id, t.role_accounttype_id, t.product_id, t.menu_id, t.funciton_id, t.created_by, t.created_time,
        t.updated_by,t.updated_time, t.function_value, p.product_name
        from platform_merchant_role_function_relation t left join platform_merchant_product p
        on t.product_id = p.id where t.del_flag = 0
        <if test="obj.roleAccounttypeId != null">
            and t.role_accounttype_id = #{obj.roleAccounttypeId,jdbcType=INTEGER}
        </if>
    </select>
    <select id="findMenuFunTreeByRole" resultType="cn.com.glsx.merchants.model.MerchantCompareModel">

        select p1.accounttype_id          as accountTypeId,
               p2.accounttype_name        as accountTypeName,
               p5.product_id              as productId,
               p4.product_name            as productName,
               p5.menu_id                 as menuId,
               p6.menu_name               as menuName,
               p5.funciton_id             as functionId,
               p6.menu_url                as menuUrl,
               p5.function_value          as functionvalue,
               p7.function_name           as functionName,
               p7.function_attribute_name as functionUrl,
               p6.parentId                as parentId,
               p6.menu_position           as sort
        from platform_merchant_role_accounttype_relation p1
                 left join platform_merchant_accounttype p2 on p1.accounttype_id = p2.id
                 left join platform_merchant_role_function_relation p5
                           on p1.id = p5.role_accounttype_id and p5.del_flag = 0
                 left JOIN platform_merchant_product p4 on p5.product_id = p4.id
                 left join platform_merchant_product_menu p6 on p6.id = p5.menu_id
                 left join platform_merchant_product_function p7 on p5.funciton_id = p7.id
        where p1.role_id = #{roleId}
          and p1.del_flag = 0
          and p1.accounttype_id is not null
    </select>

    <select id="findMenuFunTreeByRoleAndMenuId" resultType="cn.com.glsx.merchants.model.MerchantCompareModel">
        select p1.accounttype_id          as accountTypeId,
               p2.accounttype_name        as accountTypeName,
               p5.product_id              as productId,
               p4.product_name            as productName,
               p5.menu_id                 as menuId,
               p6.menu_name               as menuName,
               p5.funciton_id             as functionId,
               p6.menu_url                as menuUrl,
               p5.function_value          as functionvalue,
               p7.function_name           as functionName,
               p7.function_attribute_name as functionUrl,
               p6.parentId                as parentId
                ,
               p6.menu_position           as sort
        from platform_merchant_role_accounttype_relation p1
                 left join platform_merchant_accounttype p2 on p1.accounttype_id = p2.id
                 left join platform_merchant_role_function_relation p5
                           on p1.id = p5.role_accounttype_id and p5.del_flag = 0
                 left JOIN platform_merchant_product p4 on p5.product_id = p4.id
                 left join platform_merchant_product_menu p6 on p6.id = p5.menu_id
                 left join platform_merchant_product_function p7 on p5.funciton_id = p7.id
        where p1.role_id = #{roleId}
          and p1.del_flag = 0
          and p6.id = #{menuId}
          and p1.accounttype_id is not null
    </select>

    <select id="findByCondition" resultMap="BaseResultMap">
        select * from platform_merchant_role_function_relation
        where del_flag = 0
        <if test="productId != null">
            and product_id = #{productId}
        </if>
        and menu_id = #{menuId}
        and role_accounttype_id in
        <foreach collection="ids" separator="," close=")" open="(" index="index" item="item">
            #{item}
        </foreach>
    </select>

    <update id="deleteByMenuId">
        update platform_merchant_role_function_relation
        set del_flag    = -1,
            updated_by=#{roleFunctionRelation.createdBy},
            updated_time=NOW()
        where 1 = 1
          and menu_id = #{roleFunctionRelation.menuId}
    </update>
    <update id="deleteByFunctionId">
        update platform_merchant_role_function_relation
        set del_flag    = -1,
            updated_by=#{roleFunctionRelation.createdBy},
            updated_time=NOW()
        where 1 = 1
          and funciton_id = #{roleFunctionRelation.funcitonId}
    </update>
    <update id="batchUpdate">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update platform_merchant_role_function_relation
            set del_flag = -1,
            updated_by=#{item.createdBy},
            updated_time=NOW()
            where
            role_accounttype_id=#{item.roleAccounttypeId}
            and product_id=#{item.productId}
            and menu_id=#{item.menuId}
            <if test="item.funcitonId != null">
                and funciton_id = #{item.funcitonId}
                and function_value = #{item.functionValue}
            </if>
        </foreach>
    </update>
</mapper>