<?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.ey.biz.module.system.dal.mapper.codeblock.CodeBlockLegalEntityMapper">
    <resultMap id="BaseResultMap" type="cn.ey.biz.module.system.dal.dataobject.codeblock.CodeBlockLegalEntityDO">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="legal_entity_code" jdbcType="VARCHAR" property="legalEntityCode"/>
        <result column="sl_code" jdbcType="VARCHAR" property="slCode"/>
        <result column="ssl_code" jdbcType="VARCHAR" property="sslCode"/>
        <result column="smu_code" jdbcType="VARCHAR" property="smuCode"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, legal_entity_code,sl_code,ssl_code, smu_code, update_time,updater
    </sql>


    <update id="deleteBatchByIds">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update system_code_block_legal_entity
            <set>
                deleted = 1
            </set>
            where id = #{item}
        </foreach>
    </update>

    <select id="selectExistByParam" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from system_code_block_legal_entity
        where legal_entity_code=#{legalEntityCode} and deleted=0
        <if test="slCode != null and slCode != ''">
            and sl_code = #{slCode}
        </if>
        <if test="sslCode != null and sslCode != ''">
            and ssl_code = #{sslCode}
        </if>
        <if test="smuCode != null and smuCode != ''">
            and smu_code = #{smuCode}
        </if>
    </select>

    <select id="selectOneForMaxTime"
            resultType="cn.ey.biz.module.system.dal.dataobject.codeblock.CodeBlockLegalEntityDO">
        select
        <include refid="Base_Column_List"/>
        from system_code_block_legal_entity
        where
        deleted=0
        order by update_time desc limit 1
    </select>

</mapper>