<?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.InformationInfoDAO">
    <resultMap id="InformationInfoMap" type="com.jpsoft.shinestar.modules.base.entity.InformationInfo">
        <id property="id" column="id_"/>
        <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="delFlag" column="del_flag"/>
        <result property="popedom" column="popedom_"/>
        <result property="community" column="community_"/>
        <result property="content" column="content_"/>
        <result property="status" column="status_"/>
        <result property="returnContent" column="return_content"/>
        <result property="returnTime" column="return_time"/>
        <result property="type" column="type_"/>
        <result property="img" column="img_"/>
        <result property="category" column="category_"/>
        <result property="companyId" column="company_id"/>
        <result property="personId" column="person_id"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.InformationInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_information_info
	    (id_,create_by,create_time,update_by,update_time,del_flag,popedom_,community_,content_,status_,return_content,return_time,type_,img_,
	    category_,company_id,person_id)
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{delFlag,jdbcType= NUMERIC }
			,#{popedom,jdbcType=VARCHAR}
			,#{community,jdbcType=VARCHAR}
			,#{content,jdbcType=VARCHAR}
			,#{status,jdbcType=VARCHAR}
			,#{returnContent,jdbcType=VARCHAR}
			,#{returnTime,jdbcType= TIMESTAMP }
			,#{type,jdbcType=VARCHAR}
			,#{img,jdbcType=VARCHAR}
			,#{category,jdbcType=NUMERIC}
			,#{companyId,jdbcType=VARCHAR}
			,#{personId,jdbcType=NUMERIC}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_information_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.InformationInfo">
        update base_information_info
        <set>
            <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="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="popedom!=null">
                popedom_=#{popedom,jdbcType=VARCHAR},
            </if>
            <if test="community!=null">
                community_=#{community,jdbcType=VARCHAR},
            </if>
            <if test="content!=null">
                content_=#{content,jdbcType=VARCHAR},
            </if>
            <if test="status!=null">
                status_=#{status,jdbcType=VARCHAR},
            </if>
            <if test="returnContent!=null">
                return_content=#{returnContent,jdbcType=VARCHAR},
            </if>
            <if test="returnTime!=null">
                return_time=#{returnTime,jdbcType= TIMESTAMP },
            </if>
            <if test="type!=null">
                type_=#{type,jdbcType=VARCHAR},
            </if>
            <if test="img!=null">
                img_=#{img,jdbcType=VARCHAR},
            </if>
            <if test="category!=null">
                category_=#{category,jdbcType=NUMERIC},
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="personId!=null">
                person_id=#{personId,jdbcType=VARCHAR},
            </if>

        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="InformationInfoMap">
        select
        id_,create_by,create_time,update_by,update_time,del_flag,popedom_,community_,content_,status_,return_content,return_time,type_,img_,category_,company_id,person_id
        from base_information_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_information_info where id_=#{0}
    </select>
    <select id="list" resultMap="InformationInfoMap">
        select * from base_information_info
    </select>
    <select id="search" parameterType="hashmap" resultMap="InformationInfoMap">
        <![CDATA[
			select a.* from base_information_info a left join base_person_info b on a.person_id = b.id_
		]]>
        <where>
            a.del_flag = false
            <if test="searchParams.popedom != null">
                and a.popedom_ = #{searchParams.popedom}
            </if>
            <if test="searchParams.type != null">
                and a.type_ = #{searchParams.type}
            </if>
            <if test="searchParams.name != null">
                and b.name_ like #{searchParams.name}
            </if>
            <if test="searchParams.status != null">
                and a.status_ = #{searchParams.status}
            </if>
            <if test="searchParams.statusN != null">
                <if test="searchParams.statusN ==0">
                    <![CDATA[
						and a.status_ = '0'
					]]>
                </if>
                <if test="searchParams.statusN !=0">
                    <![CDATA[
						and a.status_ <> '0'
					]]>
                </if>
            </if>
            <if test="searchParams.beginTime != null">
                <![CDATA[
                  and a.create_time >= #{searchParams.beginTime}
            	]]>
            </if>
            <if test="searchParams.endTime != null">
                <![CDATA[
                  and a.create_time <= #{searchParams.endTime}
            	]]>
            </if>
            <if test="searchParams.companyList != null">
                <foreach collection="searchParams.companyList" index="index" item="item" open="and a.company_id in("
                         separator="," close=")">
                    #{item.id}
                </foreach>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByOwnerIdAndType" resultMap="InformationInfoMap">
        select
        id_,create_by,create_time,update_by,update_time,del_flag,popedom_,community_,content_,status_,return_content,return_time,type_
        from base_information_info where popedom_=#{personId} and type_=#{type}
    </select>

</mapper>