<?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.yd.dal.mapper.marketing.MktAnnouncementMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.marketing.MktAnnouncement">
    <!--@mbg.generated-->
    <!--@Table yd_mkt_announcement-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="insurer_id" jdbcType="BIGINT" property="insurerId" />
    <result column="insurer_branch_id" jdbcType="BIGINT" property="insurerBranchId" />
    <result column="title" jdbcType="LONGVARCHAR" property="title" />
    <result column="content" jdbcType="LONGVARCHAR" property="content" />
    <result column="announcement_type" jdbcType="BIGINT" property="announcementType" />
    <result column="announcement_at" jdbcType="DATE" property="announcementAt" />
    <result column="seq" jdbcType="INTEGER" property="seq" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, insurer_id, insurer_branch_id, title, content, announcement_type, announcement_at, 
    seq, is_active, created_at, created_by
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from yd_mkt_announcement
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from yd_mkt_announcement
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.marketing.MktAnnouncement" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into yd_mkt_announcement (insurer_id, insurer_branch_id, title, 
      content, announcement_type, announcement_at, 
      seq, is_active, created_at, 
      created_by)
    values (#{insurerId,jdbcType=BIGINT}, #{insurerBranchId,jdbcType=BIGINT}, #{title,jdbcType=LONGVARCHAR}, 
      #{content,jdbcType=LONGVARCHAR}, #{announcementType,jdbcType=BIGINT}, #{announcementAt,jdbcType=DATE}, 
      #{seq,jdbcType=INTEGER}, #{isActive,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{createdBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.marketing.MktAnnouncement" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into yd_mkt_announcement
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="insurerId != null">
        insurer_id,
      </if>
      <if test="insurerBranchId != null">
        insurer_branch_id,
      </if>
      <if test="title != null">
        title,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="announcementType != null">
        announcement_type,
      </if>
      <if test="announcementAt != null">
        announcement_at,
      </if>
      <if test="seq != null">
        seq,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="insurerId != null">
        #{insurerId,jdbcType=BIGINT},
      </if>
      <if test="insurerBranchId != null">
        #{insurerBranchId,jdbcType=BIGINT},
      </if>
      <if test="title != null">
        #{title,jdbcType=LONGVARCHAR},
      </if>
      <if test="content != null">
        #{content,jdbcType=LONGVARCHAR},
      </if>
      <if test="announcementType != null">
        #{announcementType,jdbcType=BIGINT},
      </if>
      <if test="announcementAt != null">
        #{announcementAt,jdbcType=DATE},
      </if>
      <if test="seq != null">
        #{seq,jdbcType=INTEGER},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.marketing.MktAnnouncement">
    <!--@mbg.generated-->
    update yd_mkt_announcement
    <set>
      <if test="insurerId != null">
        insurer_id = #{insurerId,jdbcType=BIGINT},
      </if>
      <if test="insurerBranchId != null">
        insurer_branch_id = #{insurerBranchId,jdbcType=BIGINT},
      </if>
      <if test="title != null">
        title = #{title,jdbcType=LONGVARCHAR},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=LONGVARCHAR},
      </if>
      <if test="announcementType != null">
        announcement_type = #{announcementType,jdbcType=BIGINT},
      </if>
      <if test="announcementAt != null">
        announcement_at = #{announcementAt,jdbcType=DATE},
      </if>
      <if test="seq != null">
        seq = #{seq,jdbcType=INTEGER},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.marketing.MktAnnouncement">
    <!--@mbg.generated-->
    update yd_mkt_announcement
    set insurer_id = #{insurerId,jdbcType=BIGINT},
      insurer_branch_id = #{insurerBranchId,jdbcType=BIGINT},
      title = #{title,jdbcType=LONGVARCHAR},
      content = #{content,jdbcType=LONGVARCHAR},
      announcement_type = #{announcementType,jdbcType=BIGINT},
      announcement_at = #{announcementAt,jdbcType=DATE},
      seq = #{seq,jdbcType=INTEGER},
      is_active = #{isActive,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
    <select id="selectByObj" resultMap="BaseResultMap">
      select
      <include refid="Base_Column_List" />
      from yd_mkt_announcement
      <where>
        <if test="id != null">
          id = #{id,jdbcType=BIGINT}
        </if>
        <if test="insurerId != null">
          and insurer_id = #{insurerId,jdbcType=BIGINT}
        </if>
        <if test="insurerBranchId != null">
          and insurer_branch_id = #{insurerBranchId,jdbcType=BIGINT}
        </if>
        <if test="title != null">
          and title = #{title,jdbcType=LONGVARCHAR}
        </if>
        <if test="content != null">
          and content = #{content,jdbcType=LONGVARCHAR}
        </if>
        <if test="announcementType != null">
          and announcement_type = #{announcementType,jdbcType=BIGINT}
        </if>
        <if test="announcementAt != null">
          and announcement_at = #{announcementAt,jdbcType=DATE}
        </if>
        <if test="seq != null">
          and seq = #{seq,jdbcType=INTEGER}
        </if>
        <if test="isActive != null">
          and is_active = #{isActive,jdbcType=INTEGER}
        </if>
        <if test="createdAt != null">
          and created_at = #{createdAt,jdbcType=TIMESTAMP}
        </if>
        <if test="createdBy != null">
          and created_by = #{createdBy,jdbcType=BIGINT}
        </if>
      </where>

    </select>
  <select id="findByIsActiveAndAnnouncementAtBefore" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from yd_mkt_announcement
    WHERE
    is_active = #{isActive}
    and
    announcement_at &lt;= #{date}
    and seq != 0
    order by seq desc , announcement_at desc
  </select>
  <select id="findByIsActiveAndAnnouncementAtBeforeTop" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from yd_mkt_announcement
    WHERE
    is_active = #{isActive}
    and 
    announcement_at &lt;= #{date}
    and seq = 0
    order by seq desc , announcement_at desc
  </select>
</mapper>