<?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.yifu.cloud.plus.v1.yifu.archives.mapper.TCutsomerDataPermissonMapper">

    <resultMap id="tCutsomerDataPermissonMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TCutsomerDataPermisson">
        <id property="id" column="ID"/>
		<result property="status" column="STATUS"/>
        <result property="createBy" column="CREATE_BY"/>
        <result property="createName" column="CREATE_NAME"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="userId" column="USER_ID"/>
        <result property="userLoginName" column="USER_LOGIN_NAME"/>
        <result property="userNickName" column="USER_NICK_NAME"/>
        <result property="userDeptName" column="USER_DEPT_NAME"/>
        <result property="remark" column="REMARK"/>
        <result property="type" column="type"/>
        <result property="settleDomainId" column="SETTLE_DOMAIN_ID"/>
        <result property="settleDomainName" column="SETTLE_DOMAIN_NAME"/>
        <result property="settleDomainNo" column="SETTLE_DOMAIN_NO"/>
    </resultMap>
    <sql id="base_column_list">
        a.ID
		,a.STATUS
		,a.REMARK
		,a.SETTLE_DOMAIN_ID
		,a.CREATE_BY
		,a.CREATE_NAME
		,a.CREATE_TIME
		,a.USER_ID
		,a.USER_LOGIN_NAME
		,a.USER_NICK_NAME
		,a.USER_DEPT_NAME
		,a.TYPE
		,a.SETTLE_DOMAIN_NAME
		,a.SETTLE_DOMAIN_NO
	</sql>
    <sql id="where_getTCutsomerDataPermissonPage">
		<if test="tCutsomerDataPermisson != null">
			<if test="tCutsomerDataPermisson.idList != null">
				AND a.id in
				<foreach item="idStr" index="index" collection="tCutsomerDataPermisson.idList" open="(" separator="," close=")">
					#{idStr}
				</foreach>
			</if>
			<if test="tCutsomerDataPermisson.userNickName != null and tCutsomerDataPermisson.userNickName.trim() != ''">
				AND a.USER_NICK_NAME like concat('%',#{tCutsomerDataPermisson.userNickName},'%')
			</if>
			<if test="tCutsomerDataPermisson.userLoginName != null and tCutsomerDataPermisson.userLoginName.trim() != ''">
				AND a.USER_LOGIN_NAME like concat('%',#{tCutsomerDataPermisson.userLoginName},'%')
			</if>
			<if test="tCutsomerDataPermisson.userDeptName != null and tCutsomerDataPermisson.userDeptName.trim() != ''">
				AND a.USER_DEPT_NAME like concat('%',#{tCutsomerDataPermisson.userDeptName},'%')
			</if>
			 <if test="tCutsomerDataPermisson.status != null and tCutsomerDataPermisson.status.trim() != ''">
				AND a.STATUS = #{tCutsomerDataPermisson.status}
			</if>
			<if test="tCutsomerDataPermisson.settleDomainName != null and tCutsomerDataPermisson.settleDomainName.trim() != ''">
			   AND a.SETTLE_DOMAIN_NAME like '%${tCutsomerDataPermisson.settleDomainName}%'
			</if>
			<if test="tCutsomerDataPermisson.settleDomainNo != null and tCutsomerDataPermisson.settleDomainNo.trim() != ''">
			   AND a.SETTLE_DOMAIN_NO like '%${tCutsomerDataPermisson.settleDomainNo}%'
			</if>
		</if>
    </sql>
    <!--分页查询-->
    <select id="getTCutsomerDataPermissonPage" resultMap="tCutsomerDataPermissonMap">
        SELECT
        	<include refid="base_column_list"/>
        from t_cutsomer_data_permisson a
        where 1=1
        	<include refid="where_getTCutsomerDataPermissonPage"/>
        ORDER BY a.CREATE_TIME DESC
    </select>
    <!-- 获取当前登录人拥有的所有项目权限 -->
    <select id="selectAllSettleDomainPermissionByUserId" resultMap="tCutsomerDataPermissonMap">
        SELECT
        <include refid="base_column_list"/>
        FROM t_cutsomer_data_permisson a
        WHERE a.STATUS = '0' and a.USER_ID = #{userId}
    </select>
</mapper>
