<?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.dk.mdm.mapper.mst.OrgMacMapper">

    <!-- 通用设置 -->
    <!-- 通用查询列 -->
    <sql id="Base_Column_List">
        org_id, mac_id, display_no, flg_default, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
    </sql>

    <sql id="Base_Column_List_prefix">
        tmom.org_id, tmom.mac_id, tmom.display_no, tmom.flg_default, tmom.cp_id, tmom.op_create_time, tmom.op_create_user_id, tmom.op_update_time, tmom.op_update_user_id, tmom.op_app_code, tmom.op_timestamp, tmom.op_db_user
    </sql>
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.OrgMac">
        <id column="org_id" property="orgId"/>
                <result column="mac_id" property="macId" typeHandler="UuidTypeHandler"/>
        <result column="mac_name" property="macName"/>
                <result column="display_no" property="displayNo"/>
                <result column="flg_default" property="flgDefault"/>
                <result column="cp_id" property="cpId"/>
            <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
                <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
            <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
                <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
                <result column="op_app_code" property="opAppCode"/>
            <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
                <result column="op_db_user" property="opDbUser"/>
    </resultMap>

    <!-- 通用条件列 -->
    <sql id="Condition">
        <where>
            <if test="macId != null and macId != ''">
                AND mac_id = #{macId}
            </if>
            <if test="displayNo != null">
                AND display_no = #{displayNo}
            </if>
            <if test="flgDefault != null">
                AND flg_default = #{flgDefault}
            </if>
            <if test="cpId != null">
                AND cp_id = #{cpId}
            </if>
            <if test="opCreateTime != null">
                AND op_create_time = #{opCreateTime}
            </if>
            <if test="opCreateUserId != null and opCreateUserId != ''">
                AND op_create_user_id = #{opCreateUserId}
            </if>
            <if test="opUpdateTime != null">
                AND op_update_time = #{opUpdateTime}
            </if>
            <if test="opUpdateUserId != null and opUpdateUserId != ''">
                AND op_update_user_id = #{opUpdateUserId}
            </if>
            <if test="opAppCode != null and opAppCode != ''">
                AND op_app_code = #{opAppCode}
            </if>
            <if test="opTimestamp != null">
                AND op_timestamp = #{opTimestamp}
            </if>
            <if test="opDbUser != null and opDbUser != ''">
                AND op_db_user = #{opDbUser}
            </if>
             <if test="orgId != null">
            AND org_id = #{orgId}::uuid
        </if>
        </where>
    </sql>

    <sql id="Condition_prefix">
        <where>
            <if test="macId != null and macId != ''">
                AND tmom.mac_id = #{macId}
            </if>
            <if test="displayNo != null">
                AND tmom.display_no = #{displayNo}
            </if>
            <if test="flgDefault != null">
                AND tmom.flg_default = #{flgDefault}
            </if>
            <if test="cpId != null">
                AND tmom.cp_id = #{cpId}
            </if>
            <if test="opCreateTime != null">
                AND tmom.op_create_time = #{opCreateTime}
            </if>
            <if test="opCreateUserId != null and opCreateUserId != ''">
                AND tmom.op_create_user_id = #{opCreateUserId}
            </if>
            <if test="opUpdateTime != null">
                AND tmom.op_update_time = #{opUpdateTime}
            </if>
            <if test="opUpdateUserId != null and opUpdateUserId != ''">
                AND tmom.op_update_user_id = #{opUpdateUserId}
            </if>
            <if test="opAppCode != null and opAppCode != ''">
                AND tmom.op_app_code = #{opAppCode}
            </if>
            <if test="opTimestamp != null">
                AND tmom.op_timestamp = #{opTimestamp}
            </if>
            <if test="opDbUser != null and opDbUser != ''">
                AND tmom.op_db_user = #{opDbUser}
            </if>
            <if test="orgId != null">
                AND tmom.org_id = #{orgId}::uuid
            </if>
        </where>
    </sql>
    <sql id="idsForeach">
        <!-- 根据主键orgId批量操作 -->
        WHERE org_id in
        <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </sql>

    <!-- 查询表t_mst_org_mac，（条件查询+分页）列表 -->
    <select id="selectByCond" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List_prefix"/>
        ,tmma.mac_name
        FROM dkic_b.t_mst_org_mac tmom
        left join dkic_b.t_mst_money_account tmma on tmma.mac_id=tmom.mac_id
        <include refid="Condition_prefix"/>
        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
            limit #{end} offset #{start}
        </if>
    </select>

    <!-- 查询表t_mst_org_mac，（条件查询）个数 -->
    <select id="countByCond" resultType="Long">
        SELECT
        count(1)
        FROM dkic_b.t_mst_org_mac tmom
        left join dkic_b.t_mst_money_account tmma on tmma.mac_id=tmom.mac_id
        <include refid="Condition_prefix"/>
    </select>

    <!-- 根据主键查询表t_mst_org_mac的一行数据 -->
    <select id="selectById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_mst_org_mac
        WHERE org_id = #{id}::uuid
    </select>

    <!-- 根据主键锁定表t_mst_org_mac的一行数据 -->
    <select id="selectByIdForUpdate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_mst_org_mac
        WHERE org_id = #{orgId}
        for update
    </select>

    <delete id="deleteByOrgId">
        DELETE FROM dkic_b.t_mst_org_mac WHERE org_id = #{orgId}::uuid
    </delete>
</mapper>
