<?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.business.dao.CarryThingsOutFactoryDAO">
	<resultMap id="CarryThingsOutFactoryMap" type="com.jpsoft.shinestar.modules.business.entity.CarryThingsOutFactory">
		<id property="id" column="id_" />
			<result property="personPopedomId" column="person_popedom_id" />
			<result property="leaveFactoryTime" column="leave_factory_time" />
			<result property="leaveFactoryReason" column="leave_factory_reason" />
			<result property="image" column="image_" />
			<result property="auditStatus" column="audit_status" />
			<result property="releaseBy" column="release_by" />
			<result property="releaseStatus" column="release_status" />
			<result property="releaseTime" column="release_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" />
			<result property="procinstId" column="procinst_id" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.CarryThingsOutFactory">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into business_carry_things_out_factory
	    (id_,person_popedom_id,leave_factory_time,leave_factory_reason,image_,audit_status,release_by,release_status,release_time,create_by,create_time,update_by,update_time,del_flag,procinst_id)
		values
		(
#{id,jdbcType=VARCHAR}
,#{personPopedomId,jdbcType= VARCHAR }
,#{leaveFactoryTime,jdbcType= TIMESTAMP }
,#{leaveFactoryReason,jdbcType=VARCHAR}
,#{image,jdbcType=VARCHAR}
,#{auditStatus,jdbcType=VARCHAR}
,#{releaseBy,jdbcType=VARCHAR}
,#{releaseStatus,jdbcType=VARCHAR}
,#{releaseTime,jdbcType= TIMESTAMP }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{procinstId,jdbcType= VARCHAR }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from business_carry_things_out_factory where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.CarryThingsOutFactory">
		update business_carry_things_out_factory
		<set>
				<if test="personPopedomId!=null">
		person_popedom_id=#{personPopedomId,jdbcType= VARCHAR },
		</if>
				<if test="leaveFactoryTime!=null">
		leave_factory_time=#{leaveFactoryTime,jdbcType= TIMESTAMP },
		</if>
				<if test="leaveFactoryReason!=null">
		leave_factory_reason=#{leaveFactoryReason,jdbcType=VARCHAR},
		</if>
				<if test="image!=null">
		image_=#{image,jdbcType=VARCHAR},
		</if>
				<if test="auditStatus!=null">
		audit_status=#{auditStatus,jdbcType=VARCHAR},
		</if>
				<if test="releaseBy!=null">
		release_by=#{releaseBy,jdbcType=VARCHAR},
		</if>
				<if test="releaseStatus!=null">
		release_status=#{releaseStatus,jdbcType=VARCHAR},
		</if>
				<if test="releaseTime!=null">
		release_time=#{releaseTime,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>
			<if test="procinstId!=null">
				procinst_id=#{procinstId,jdbcType= VARCHAR }
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="CarryThingsOutFactoryMap">
		select * from business_carry_things_out_factory where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from business_carry_things_out_factory where id_=#{0}
	</select>
	<select id="list" resultMap="CarryThingsOutFactoryMap">
		select * from business_carry_things_out_factory
	</select>
	<select id="getAppointmentPassNum" parameterType="hashmap" resultType="int">
		<![CDATA[
			select count(*) from business_carry_things_out_factory a
			inner join base_person_popedom b on a.person_popedom_id = b.id_
			inner join base_person_info c on b.person_id = c.id_
			inner join base_company_info d on c.company_id = d.id_
		]]>
		<where>
			a.del_flag = false
			<if test="searchParams.companyId != null">
				and d.code_ like #{searchParams.companyId}
			</if>
			<if test="searchParams.releaseStatus != null">
				and a.release_status = #{searchParams.releaseStatus}
			</if>
			<if test="searchParams.auditStatus != null">
				and a.audit_status = #{searchParams.auditStatus}
			</if>
			<if test="searchParams.startTime != null">
				<![CDATA[
					and a.leave_factory_time >=#{searchParams.startTime}
				]]>
			</if>
			<if test="searchParams.endTime != null">
				<![CDATA[
					and a.leave_factory_time <=#{searchParams.endTime}
				]]>
			</if>
		</where>
	</select>

	<select id="search" parameterType="hashmap" resultMap="CarryThingsOutFactoryMap">
		<![CDATA[
			select * from business_carry_things_out_factory a
			inner join base_person_popedom b on a.person_popedom_id = b.id_
			inner join base_person_info c on b.person_id = c.id_
			inner join base_company_info d on c.company_id = d.id_
		]]>
		<where>
			a.del_flag = false and b.del_flag = false and c.del_flag = false and d.del_flag = false
			<if test="searchParams.id != null">
				and a.ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.personPopedomId != null">
				and a.person_popedom_id = #{searchParams.personPopedomId}
			</if>
			<if test="searchParams.personName != null">
				and c.name_ like #{searchParams.personName}
			</if>
			<if test="searchParams.companyId != null">
				and d.id_ = #{searchParams.companyId}
			</if>
			<if test="searchParams.auditStatus != null">
				and a.audit_status = #{searchParams.auditStatus}
			</if>
			<if test="searchParams.releaseStatus != null">
				and a.release_status = #{searchParams.releaseStatus}
			</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>


		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
	<select id="guardSearch" parameterType="hashmap" resultMap="CarryThingsOutFactoryMap">
		<![CDATA[
			select * from business_carry_things_out_factory a
			inner join base_person_popedom b on a.person_popedom_id = b.id_
			inner join base_person_info c on b.person_id = c.id_
			inner join base_company_info d on c.company_id = d.id_
		]]>
		<where>
			a.del_flag = false
			<if test="searchParams.companyId != null">
				and d.code_ like #{searchParams.companyId}
			</if>
			<if test="searchParams.auditStatus != null">
				and a.audit_status = #{searchParams.auditStatus}
			</if>
			<if test="searchParams.startTime != null">
				<![CDATA[
					and a.leave_factory_time >=#{searchParams.startTime}
				]]>
			</if>
			<if test="searchParams.endTime != null">
				<![CDATA[
					and a.leave_factory_time <=#{searchParams.endTime}
				]]>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>
</mapper>