<?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.engagement.code.SystemEngagementCodeRuleMapper">
    <resultMap id="BaseResultMap" type="cn.ey.biz.module.system.controller.engagement.code.vo.EngagementCodeRuleRespVO">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="entity_code" jdbcType="VARCHAR" property="entityCode"/>
        <result column="bu_code" jdbcType="VARCHAR" property="buCode"/>
        <result column="ou_code" jdbcType="VARCHAR" property="ouCode"/>
        <result column="mu_code" jdbcType="VARCHAR" property="muCode"/>
        <result column="smu_code" jdbcType="VARCHAR" property="smuCode"/>
        <result column="sl_code" jdbcType="VARCHAR" property="slCode"/>
        <result column="ssl_code" jdbcType="VARCHAR" property="sslCode"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="updater" jdbcType="VARCHAR" property="updater"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, entity_code, bu_code, ou_code, mu_code, smu_code, version, creator,
        create_time, updater, update_time, deleted,sl_code,ssl_code
    </sql>

    <insert id="insert" keyColumn="id" keyProperty="id"
            parameterType="cn.ey.biz.module.system.dal.dataobject.engagement.code.SystemEngagementCodeRuleDO"
            useGeneratedKeys="true">
        insert into system_engagement_code_rule (entity_code, bu_code, ou_code,
        mu_code, smu_code, version,
        creator, create_time,
        updater, update_time, deleted,sl_code,ssl_code
        )
        values (#{entityCode,jdbcType=VARCHAR}, #{buCode,jdbcType=VARCHAR}, #{ouCode,jdbcType=VARCHAR},
        #{muCode,jdbcType=VARCHAR}, #{smuCode,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER},
        #{creator,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
        #{updater,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{slCode}, #{sslCode}
        )
    </insert>

    <select id="selectById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from system_engagement_code_rule
        where id=#{id} and deleted=0
    </select>

    <select id="selectByParam"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from system_engagement_code_rule
        where
        deleted=0
        <if test="entityCode!=null and entityCode!=''">
            and entity_code=#{entityCode}
        </if>
        <if test="buCode != null and buCode != ''">
            and bu_code = #{buCode}
        </if>
        <if test="ouCode != null and ouCode != ''">
            and ou_code=#{ouCode}
        </if>
        <if test="muCode!=null and muCode!=''">
            and mu_code=#{muCode}
        </if>
        <if test="smuCode!=null and smuCode!=''">
            and smu_code=#{smuCode}
        </if>
        <if test="slCode!=null and slCode!=''">
            and sl_code=#{slCode}
        </if>
        <if test="sslCode!=null and sslCode!=''">
            and ssl_code=#{sslCode}
        </if>
    </select>
    <select id="selectOneForMaxTime"
            resultType="cn.ey.biz.module.system.dal.dataobject.engagement.code.SystemEngagementCodeRuleDO">
        select
        <include refid="Base_Column_List"/>
        from system_engagement_code_rule
        where
        deleted=0
        order by update_time desc limit 1
    </select>

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