<?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.ParkingApplyDAO">
	<resultMap id="ParkingApplyMap" type="com.jpsoft.shinestar.modules.base.entity.ParkingApply">
		<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="parkingId" column="parking_id" />
			<result property="popedomId" column="popedom_id" />
			<result property="contractType" column="contract_type" />
			<result property="contractDuration" column="contract_duration" />
			<result property="startTime" column="start_time" />
			<result property="carNum" column="car_num" />
			<result property="estimateFee" column="estimate_fee" />
			<result property="endTime" column="end_time" />
			<result property="orderId" column="order_id"/>
			<result property="status" column="status_"/>
			<result property="payType" column="pay_type"/>
			<result property="companyId" column="company_id"/>
			<result property="parkingName" column="parking_name"/>
			<result property="reason" column="reason_"/>
			<result property="actualFee" column="actual_fee"/>
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.ParkingApply">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_parking_apply
	    (id_,create_by,create_time,update_by,update_time,del_flag,parking_id,popedom_id,contract_type,contract_duration,start_time,car_num,estimate_fee,end_time,order_id,status_,pay_type,company_id,parking_name,reason_,actual_fee)
		values
		(
#{id,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{parkingId,jdbcType=VARCHAR}
,#{popedomId,jdbcType=VARCHAR}
,#{contractType,jdbcType=VARCHAR}
,#{contractDuration,jdbcType= VARCHAR }
,#{startTime,jdbcType= TIMESTAMP }
,#{carNum,jdbcType=VARCHAR}
,#{estimateFee,jdbcType=DECIMAL}
,#{endTime,jdbcType=TIMESTAMP}
,#{orderId,jdbcType=VARCHAR}
,#{status,jdbcType=VARCHAR}
,#{payType,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{parkingName,jdbcType=VARCHAR}
,#{reason,jdbcType=VARCHAR}
,#{actualFee,jdbcType=DECIMAL}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_parking_apply where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.ParkingApply">
		update base_parking_apply
		<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="parkingId!=null">
		parking_id=#{parkingId,jdbcType=VARCHAR},
		</if>
				<if test="popedomId!=null">
					popedom_id=#{popedomId,jdbcType=VARCHAR},
		</if>
				<if test="contractType!=null">
		contract_type=#{contractType,jdbcType=VARCHAR},
		</if>
				<if test="contractDuration!=null">
		contract_duration=#{contractDuration,jdbcType= NUMERIC },
		</if>
			<if test="startTime!=null">
				start_time=#{startTime,jdbcType= TIMESTAMP },
			</if>

			<if test="carNum != null">
				car_num = #{carNum,jdbcType=VARCHAR},
			</if>

			<if test="estimateFee != null">
				estimate_fee = #{estimateFee,jdbcType=DECIMAL},
			</if>
			<if test="endTime != null">
				end_time = #{endTime,jdbcType=TIMESTAMP},
			</if>
			<if test="orderId != null">
				order_id = #{orderId,jdbcType=VARCHAR},
			</if>
			<if test="status != null">
				status_ = #{status,jdbcType=VARCHAR},
			</if>
			<if test="payType != null">
				pay_type = #{payType,jdbcType=VARCHAR},
			</if>
			<if test="companyId != null">
				company_id = #{companyId,jdbcType=VARCHAR},
			</if>
			<if test="parkingName != null">
				parking_name = #{parkingName,jdbcType=VARCHAR},
			</if>
			<if test="reason != null">
				reason_ = #{reason,jdbcType=VARCHAR},
			</if>
			<if test="actualFee != null">
				actual_fee = #{actualFee,jdbcType=DECIMAL}
			</if>

		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="ParkingApplyMap">
		select *from base_parking_apply where id_=#{0} and del_flag = 0
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_parking_apply where id_=#{0}
	</select>
	<select id="list" resultMap="ParkingApplyMap">
		select * from base_parking_apply
	</select>
	<select id="search" parameterType="hashmap" resultMap="ParkingApplyMap">
		<![CDATA[
			select * from base_parking_apply
		]]>
		<where>
			del_flag = 0
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.companyId != null">
				and company_id  =  #{searchParams.companyId}
			</if>
			<if test="searchParams.popedomId != null">
				and popedom_id  =  #{searchParams.popedomId}
			</if>

			<if test="searchParams.status != null">
				and status_ = #{searchParams.status}
			</if>
			<if test="searchParams.notStatus != null">
				and status_ != #{searchParams.notStatus}
			</if>
			<if test="searchParams.parkingId != null">
				and parking_id = #{searchParams.parkingId}
			</if>
			<if test="searchParams.endTime != null">
				<![CDATA[
				and end_time > #{searchParams.endTime}
				]]>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="findByPopedomIdAndStatus" resultMap="ParkingApplyMap">
		<![CDATA[
		select * from base_parking_apply
		where del_flag = 0
		and popedom_id = #{popedomId}
		and status_ = #{status}
		limit 1
		]]>
	</select>

	<select id="findByPopedomIdAndPayStatus" resultMap="ParkingApplyMap">
		select a.*
		from
		base_parking_apply a left join
		base_order_info b on a.order_id = b.id_
		where
		a.del_flag = 0
		and b.del_flag = 0
		and a.popedom_id = #{popedomId}
		and b.pay_status = #{payStatus}
		limit 1
	</select>
	<select id="findByOrderId" resultMap="ParkingApplyMap">
		<![CDATA[
		select * from base_parking_apply
		where del_flag = 0
		and order_id = #{orderId}
		limit 1
		]]>

	</select>

	<select id="findByPopedomId" resultMap="ParkingApplyMap">
		<![CDATA[
		select * from base_parking_apply
		where del_flag = 0
		and popedom_id = #{popedomId}
		]]>
	</select>
</mapper>