<?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.ParkingAuthorizeDAO">
    <resultMap id="ParkingAuthorizeMap" type="com.jpsoft.shinestar.modules.base.entity.ParkingAuthorize">
        <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="remark" column="remark_"/>
        <result property="companyId" column="company_id" />
        <result property="authorizedCompanyId" column="authorized_company_id" />
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.ParkingAuthorize">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_parking_authorize
	    (id_,create_by,create_time,update_by,update_time,del_flag,remark_,company_id,authorized_company_id)
		values
		(
#{id,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{remark,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{authorizedCompanyId,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_parking_authorize where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.ParkingAuthorize">
        update base_parking_authorize
        <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="remark!=null">
                remark_ = #{remark,jdbcType=VARCHAR},
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="authorizedCompanyId!=null">
                authorized_company_id=#{authorizedCompanyId,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="ParkingAuthorizeMap">
        select *from base_parking_authorize where id_=#{0} and del_flag = 0
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_parking_authorize where id_=#{0}
    </select>
    <select id="list" resultMap="ParkingAuthorizeMap">
		select * from base_parking_authorize
	</select>
    <select id="search" parameterType="hashmap" resultMap="ParkingAuthorizeMap">
        <![CDATA[
			select * from base_parking_authorize
		]]>
        <where>
            <if test="searchParams.id != null">
                and ID_ like #{searchParams.id}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByAuthorizedCompanyId" resultMap="ParkingAuthorizeMap">
        <![CDATA[
        select * from base_parking_authorize
        where del_flag = 0
        and authorized_company_id = #{companyId}
        limit 1
        ]]>
    </select>
</mapper>