<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.MessageNoticeDAO">
	<resultMap id="MessageNoticeMap" type="com.jpsoft.shinestar.modules.base.entity.MessageNotice">
		<id property="id" column="id_" />
		<result property="title" column="title_" />
		<result property="content" column="content_" />
		<result property="senderId" column="sender_id" />
		<result property="recipientId" column="recipient_id" />
		<result property="status" column="status_" />
		<result property="delFlag" column="del_flag" />
		<result property="createBy" column="create_by" />
		<result property="createTime" column="create_time" />
		<result property="updateBy" column="update_by" />
		<result property="updateTime" column="update_time" />
		<result property="noticeType" column="notice_type" />
		<result property="classify" column="classify_" />
		<result property="point" column="point_" />
		<result property="isSign" column="is_sign" />
		<result property="isReceive" column="is_receive" />
		<result property="noticeCompany" column="notice_company" />
		<result property="type" column="type_" />
		<result property="noticeLink" column="notice_link" />
		<result property="sendWechat" column="send_wechat" />
		<result property="wechatCode" column="wechat_code" />
	</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.MessageNotice">
		<!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
		<![CDATA[
		insert into base_message_notice
	    (id_,title_,content_,sender_id,recipient_id,status_,del_flag,
	    create_by,create_time,update_by,update_time,
	    notice_type,classify_,point_,is_sign,is_receive,
	    type_,send_wechat,notice_link,wechat_code)
		values
		(
#{id,jdbcType=VARCHAR}
,#{title,jdbcType=VARCHAR}
,#{content,jdbcType=VARCHAR}
,#{senderId,jdbcType=VARCHAR}
,#{recipientId,jdbcType=VARCHAR}
,#{status,jdbcType= NUMERIC }
,#{delFlag,jdbcType= NUMERIC }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{noticeType,jdbcType=VARCHAR}
,#{classify,jdbcType=VARCHAR}
,#{point,jdbcType=NUMERIC}
,#{isSign,jdbcType=NUMERIC}
,#{isReceive,jdbcType= NUMERIC }
,#{type,jdbcType=VARCHAR}
,#{sendWechat,jdbcType= NUMERIC }
,#{noticeLink,jdbcType=VARCHAR}
,#{wechatCode,jdbcType=VARCHAR}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_message_notice where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.MessageNotice">
		update base_message_notice
		<set>
			<if test="title!=null">
				title_=#{title,jdbcType=VARCHAR},
			</if>
			<if test="content!=null">
				content_=#{content,jdbcType=VARCHAR},
			</if>
			<if test="senderId!=null">
				sender_id=#{senderId,jdbcType=VARCHAR},
			</if>
			<if test="recipientId!=null">
				recipient_id=#{recipientId,jdbcType=VARCHAR},
			</if>
			<if test="status!=null">
				status_=#{status,jdbcType= NUMERIC },
			</if>
			<if test="delFlag!=null">
				del_flag=#{delFlag,jdbcType= NUMERIC },
			</if>
			<if test="createBy!=null">
				create_by=#{createBy,jdbcType=VARCHAR},
			</if>
			<if test="createTime!=null">
				create_time=#{createTime,jdbcType= TIMESTAMP },
			</if>
			<if test="updateBy!=null">
				update_by=#{updateBy,jdbcType=VARCHAR},
			</if>
			<if test="updateTime!=null">
				update_time=#{updateTime,jdbcType= TIMESTAMP },
			</if>
			<if test="noticeType!=null">
				notice_type=#{noticeType,jdbcType= TIMESTAMP },
			</if>
			<if test="classify!=null">
				classify_=#{classify,jdbcType= VARCHAR },
			</if>
			<if test="point!=null">
				point_=#{point,jdbcType= NUMERIC },
			</if>
			<if test="isSign!=null">
				is_sign=#{isSign,jdbcType= NUMERIC },
			</if>
			<if test="isReceive!=null">
				is_receive=#{isReceive,jdbcType= NUMERIC },
			</if>
			<if test="type!=null">
				type_=#{type,jdbcType= VARCHAR },
			</if>
			<if test="sendWechat!=null">
				send_wechat=#{sendWechat,jdbcType= NUMERIC },
			</if>
			<if test="noticeLink!=null">
				notice_link=#{noticeLink,jdbcType= VARCHAR },
			</if>
			<if test="wechatCode!=null">
				wechat_code=#{wechatCode,jdbcType= VARCHAR },
			</if>
		</set>
		where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="MessageNoticeMap">
		select * from base_message_notice where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_message_notice where id_=#{0}
	</select>
	<select id="list" resultMap="MessageNoticeMap">
		select * from base_message_notice
	</select>
	<select id="search" parameterType="hashmap" resultMap="MessageNoticeMap">
		<![CDATA[
			SELECT
				a.*,
				c.name_ AS notice_company
			FROM
				base_message_notice a
				left join base_message_notice_company b on b.notice_id = a.id_
				LEFT JOIN base_company_info c ON b.company_id = c.id_
		]]>
		<where>
			a.del_flag = false
			<if test="searchParams.title != null">
				and a.title_ like #{searchParams.title}
			</if>
			<if test="searchParams.companyIds != null">
				and a.id_ in (
				select b.notice_id from base_message_notice_company b where b.company_id in
				<foreach collection="searchParams.companyIds" item="companyId" open="( "  close=" ) " separator=",">
					#{companyId}
				</foreach>
				)
			</if>
			<if test="searchParams.companyId != null">
				and a.id_ in (
				select b.notice_id from base_message_notice_company b where b.company_id  = #{searchParams.companyId}
				)
			</if>
			<if test="searchParams.startTime != null">
				<![CDATA[
				and a.create_time >= #{searchParams.startTime}
				]]>
			</if>
			<if test="searchParams.endTime != null">
				<![CDATA[
				and a.create_time < #{searchParams.endTime}
				]]>
			</if>
			<if test="searchParams.status != null">
				and a.status_ = #{searchParams.status}
			</if>
			<if test="searchParams.createBy != null">
				and a.create_by = #{searchParams.createBy}
			</if>
			<if test="searchParams.type != null">
				and a.type_ = #{searchParams.type}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>
	<select id="searchShort" parameterType="hashmap" resultMap="MessageNoticeMap">
		<![CDATA[
			select a.id_,a.title_,a.create_time,a.update_time from base_message_notice a
		]]>
		<where>
			and a.del_flag = false
			<if test="searchParams.title != null">
				and a.title_ like #{searchParams.title}
			</if>
			<if test="searchParams.companyIds != null">
				and a.id_ in ( SELECT b.notice_id FROM base_message_notice_company b WHERE
				<foreach collection="searchParams.companyIds" item="companyId" open="  b.company_id IN("  close=")" separator=",">
					#{companyId}
				</foreach>
				)
			</if>
			<if test="searchParams.startTime != null">
				<![CDATA[
				and a.create_time >= #{searchParams.startTime}
				]]>
			</if>
			<if test="searchParams.endTime != null">
				<![CDATA[
				and a.create_time < #{searchParams.endTime}
				]]>
			</if>
			<if test="searchParams.noticeTypeList != null">
				<foreach collection="searchParams.noticeTypeList" item="noticeType" open=" and ( "  close=" ) " separator=" or ">
					a.notice_type like concat('%', #{noticeType},'%')
				</foreach>
			</if>
			<if test="searchParams.status != null">
				and a.status_ = #{searchParams.status}
			</if>
			<if test="searchParams.type != null">
				and a.type_ = #{searchParams.type}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>

	<select id="findByClassify" resultMap="MessageNoticeMap">
		select * from base_message_notice
		where del_flag=0
		and classify_ = #{classify}
		<if test="id != null">
			and id_  != #{id}
		</if>
	</select>
</mapper>
