<?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.boco.nbd.wios.manage.mapper.def.SystemNoticeMapper">

  <resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.SystemNotice">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="title" jdbcType="VARCHAR" property="title" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="create_account" jdbcType="VARCHAR" property="createAccount" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="modify_account" jdbcType="VARCHAR" property="modifyAccount" />
    <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
    <result column="publish_time" jdbcType="TIMESTAMP" property="publishTime" />
    <result column="notice_annex" jdbcType="VARCHAR" property="noticeAnnex" />
    <result column="file_annex" jdbcType="VARCHAR" property="fileAnnex" />
    <result column="display_from" jdbcType="TIMESTAMP" property="displayFrom" />
    <result column="display_end" jdbcType="TIMESTAMP" property="displayEnd" />
  </resultMap>


  <sql id="Base_Column_List">
  tsn.id,
  tsn.title,
  tsn.type,
  tsn.content,
  tsn.status,
  tsn.create_account,
  tsn.create_time,
  tsn.modify_account,
  tsn.modify_time,
  tsn.publish_time,
  tsn.notice_annex,
  tsn.file_annex,
  tsn.display_from,
  tsn.display_end
</sql>

<sql id="Base_Column_ForList">
  tsn.id,
  tsn.title,
  tsn.type,
  tsn.status,
  tsn.create_account,
  tsn.create_time,
  tsn.modify_account,
  tsn.modify_time,
  tsn.publish_time,
  tsn.notice_annex,
  tsn.file_annex,
  tsn.display_from,
  tsn.display_end
</sql>


  <delete id="delete" parameterType="java.lang.String">
  delete from t_system_notice
  where id = #{id,jdbcType=INTEGER}
</delete>


  <insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.SystemNotice">
  insert into t_system_notice (id, title, type,
    content, status, create_account,
    create_time, modify_account, modify_time,
    publish_time, notice_annex, file_annex,
    display_from, display_end)
  values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
    #{content,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{createAccount,jdbcType=VARCHAR},
    #{createTime,jdbcType=TIMESTAMP}, #{modifyAccount,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP},
    #{publishTime,jdbcType=TIMESTAMP}, #{noticeAnnex,jdbcType=VARCHAR}, #{fileAnnex,jdbcType=VARCHAR},
    #{displayFrom,jdbcType=TIMESTAMP}, #{displayEnd,jdbcType=TIMESTAMP})
</insert>





  <update id="updateNotice" parameterType="com.boco.nbd.wios.manage.entity.bo.SystemNoticeBo">
    update t_system_notice
    <set>
      <if test="title != null">
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="createAccount != null">
        create_account = #{createAccount,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyAccount != null">
        modify_account = #{modifyAccount,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="publishTime != null">
        publish_time = #{publishTime,jdbcType=TIMESTAMP},
      </if>
      <if test="noticeAnnex != null">
        notice_annex = #{noticeAnnex,jdbcType=VARCHAR},
      </if>
      <if test="fileAnnex != null">
        file_annex = #{fileAnnex,jdbcType=VARCHAR},
      </if>
      <if test="displayFrom != null">
        display_from = #{displayFrom,jdbcType=TIMESTAMP},
      </if>
      <if test="displayEnd != null">
        display_end = #{displayEnd,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>




  <select id="selectById" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from  t_system_notice tsn
    where tsn.id = #{id,jdbcType=INTEGER}
  </select>

  <select id="getList" parameterType="com.boco.nbd.wios.manage.entity.bo.SystemNoticeBo" resultType="com.boco.nbd.wios.manage.entity.bo.SystemNoticeVo">
    select
    <include refid="Base_Column_ForList" />
    from  t_system_notice tsn
    <include refid="findPageWithWhere" />
    order by tsn.modify_time desc
  </select>

  <select id="getDetail" parameterType="com.boco.nbd.wios.manage.entity.bo.SystemNoticeBo" resultType="com.boco.nbd.wios.manage.entity.bo.SystemNoticeVo">
    select
    <include refid="Base_Column_List" />
    ,tu1.name createAccountName
    ,tu2.name modifyAccountName
    from  t_system_notice tsn
    left join t_user tu1 on  tsn.create_account = tu1.account
    left join t_user tu2 on  tsn.modify_account = tu2.account
    where tsn.id = #{id}
  </select>


  <sql id="findPageWithWhere">
    <where> 1=1
        and tsn.status != 0
      <if test="allList != null and allList == 0" >
        and tsn.status = 1
      </if>
      <if test="id != null and id != ''" >
        and tsn.id = #{id,jdbcType=INTEGER}
      </if>
      <if test="title != null and title != ''" >
        and tsn.title = #{title,jdbcType=VARCHAR}
      </if>
      <if test="type != null" >
        and tsn.type = #{type,jdbcType=INTEGER}
      </if>
      <if test="content != null and content != ''" >
        and tsn.content = #{content,jdbcType=VARCHAR}
      </if>
      <if test="createAccount != null and createAccount != ''" >
        and tsn.create_account = #{createAccount,jdbcType=VARCHAR}
      </if>
      <if test="createTime != null" >
        and tsn.create_time = #{createTime,jdbcType=TIMESTAMP}
      </if>
      <if test="modifyAccount != null and modifyAccount != ''" >
        and tsn.modify_account = #{modifyAccount,jdbcType=VARCHAR}
      </if>
      <if test="modifyTime != null" >
        and tsn.modify_time = #{modifyTime,jdbcType=TIMESTAMP}
      </if>
      <if test="publishTime != null" >
        and tsn.publish_time = #{publishTime,jdbcType=TIMESTAMP}
      </if>
      <if test="noticeAnnex != null and noticeAnnex != ''" >
        and tsn.notice_annex = #{noticeAnnex,jdbcType=VARCHAR}
      </if>
      <if test="fileAnnex != null and fileAnnex != ''" >
        and tsn.file_annex = #{fileAnnex,jdbcType=VARCHAR}
      </if>
      <if test="allList != null and allList == 0 and type ==1">
        <![CDATA[   and DATE_FORMAT(tsn.display_from, '%Y-%m-%d')<=  DATE_FORMAT(#{nowDate}, '%Y-%m-%d')   ]]>
      </if>
      <if test="allList != null and allList == 0 and type ==1">
        <![CDATA[   and DATE_FORMAT(tsn.display_end, '%Y-%m-%d')>=  DATE_FORMAT(#{nowDate}, '%Y-%m-%d')   ]]>
      </if>
    </where>
  </sql>


<!--  <select id="findPageWithResult" parameterType="com.starcharge.wios.dto.SystemNoticeDTO" resultMap="BaseResultMap">-->
<!--    select-->
<!--    <include refid="Base_Column_List" />-->
<!--    from  t_system_notice-->
<!--    <include refid="findPageWithWhere" />-->
<!--    limit #{start},#{pageSize}-->
<!--  </select>-->




</mapper>