<?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.CanteenOutsourcerBalanceDAO">
	<resultMap id="CanteenOutsourcerBalanceMap" type="com.jpsoft.shinestar.modules.base.entity.CanteenOutsourcerBalance">
		<id property="id" column="id_" />
			<result property="personId" column="person_id" />
			<result property="cardNumber" column="card_number" />
			<result property="amount" column="amount_" />
			<result property="lastRechargeTime" column="last_recharge_time" />
			<result property="lastUseTime" column="last_use_time" />
			<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" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CanteenOutsourcerBalance">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_canteen_outsourcer_balance
	    (id_,person_id,card_number,amount_,last_recharge_time,last_use_time,create_by,create_time,update_by,update_time,del_flag)
		values
		(
#{id,jdbcType=VARCHAR}
,#{personId,jdbcType= NUMERIC }
,#{cardNumber,jdbcType=VARCHAR}
,#{amount,jdbcType= NUMERIC }
,#{lastRechargeTime,jdbcType= TIMESTAMP }
,#{lastUseTime,jdbcType= TIMESTAMP }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_canteen_outsourcer_balance where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CanteenOutsourcerBalance">
		update base_canteen_outsourcer_balance
		<set>
				<if test="personId!=null">
		person_id=#{personId,jdbcType= NUMERIC },
		</if>
				<if test="cardNumber!=null">
		card_number=#{cardNumber,jdbcType=VARCHAR},
		</if>
				<if test="amount!=null">
		amount_=#{amount,jdbcType= NUMERIC },
		</if>
				<if test="lastRechargeTime!=null">
		last_recharge_time=#{lastRechargeTime,jdbcType= TIMESTAMP },
		</if>
				<if test="lastUseTime!=null">
		last_use_time=#{lastUseTime,jdbcType= TIMESTAMP },
		</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="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="CanteenOutsourcerBalanceMap">
		select 
id_,person_id,card_number,amount_,last_recharge_time,last_use_time,create_by,create_time,update_by,update_time,del_flag		from base_canteen_outsourcer_balance where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_canteen_outsourcer_balance where id_=#{0}
	</select>
	<select id="list" resultMap="CanteenOutsourcerBalanceMap">
		select * from base_canteen_outsourcer_balance
	</select>
	<select id="findByPersonId" resultMap="CanteenOutsourcerBalanceMap">
		select * from base_canteen_outsourcer_balance where del_flag=false and person_id = #{0} limit 1
	</select>
	<select id="search" parameterType="hashmap" resultMap="CanteenOutsourcerBalanceMap">
		<![CDATA[
			select * from base_canteen_outsourcer_balance a left join
			base_person_info b on a.person_id = b.id_ left join
			base_company_info c on b.company_id = c.id_
		]]>
		<where>
			a.del_flag = false and b.del_flag = false and c.del_flag = false
			<if test="searchParams.name != null">
				and b.name_ like #{searchParams.name}
			</if>
			<if test="searchParams.cardNumber != null">
				and a.card_number like #{searchParams.cardNumber}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
</mapper>