<?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.SchoolServeDAO">
    <resultMap id="SchoolServeMap" type="com.jpsoft.shinestar.modules.base.entity.SchoolServe">
        <id property="id" column="id_" />
        <result property="companyId" column="company_id" />
        <result property="companyName" column="company_name" />
        <result property="dictionaryId" column="dictionary_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="shareTitle" column="share_title" />
        <result property="shareImg" column="share_img" />
        <result property="shareDescription" column="share_description" />
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.SchoolServe">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_school_serve
            (id_,company_id,dictionary_id,status_,del_flag,create_by,create_time,update_by,update_time)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{companyId,jdbcType=VARCHAR}
            ,#{dictionaryId,jdbcType=VARCHAR}
            ,#{status,jdbcType=BOOLEAN}
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_school_serve where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.SchoolServe">
        update base_school_serve
        <set>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="dictionaryId!=null">
                dictionary_id=#{dictionaryId,jdbcType=VARCHAR},
            </if>
            <if test="status!=null">
                status_=#{status,jdbcType=BOOLEAN},
            </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>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="SchoolServeMap">
        select * from base_school_serve where id_=#{0} and del_flag = 0
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_school_serve where id_=#{0} and del_flag = 0
    </select>
    <select id="list" resultMap="SchoolServeMap">
		select * from base_school_serve where del_flag = 0
	</select>
    <select id="search" parameterType="hashmap" resultMap="SchoolServeMap">
        <![CDATA[
			select t1.* ,t2.name_ as company_name
			from base_school_serve t1 left join base_company_info t2
			on t1.company_id = t2.id_
		]]>
        <where>
            t1.del_flag = false
            <if test="searchParams.id != null">
                and t1.id_ = #{searchParams.id}
            </if>
            <if test="searchParams.companyId != null">
                and t1.company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.status != null">
                and t1.status_ = #{searchParams.status}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByCompanyId" resultMap="SchoolServeMap">
        <![CDATA[
        select * from base_school_serve
        where del_flag = 0
        and company_id = #{companyId}
        ]]>
    </select>

    <select id="searchParams" resultMap="SchoolServeMap">
        <![CDATA[
			SELECT
                a.*
            FROM
                base_school_serve a
		]]>
        <where>
            a.del_flag = false
            <if test="searchParams.companyId != null">
                and a.company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.status != null">
                and a.status_ = #{searchParams.status}
            </if>
            <if test="searchParams.dictionaryId != null">
                and a.dictionary_id = #{searchParams.dictionaryId}
            </if>
        </where>
    </select>
</mapper>