<?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.PersonApplicationInfoDAO">
	<resultMap id="PersonApplicationInfoMap" type="com.jpsoft.shinestar.modules.base.entity.PersonApplicationInfo">
		<id property="id" column="id_" />
		<result property="personId" column="person_id" />
			<result property="name" column="name_" />
			<result property="applicantTime" column="applicant_time" />
			<result property="companyId" column="company_id" />
			<result property="personRoleId" column="person_role_id" />
			<result property="structureId" column="structure_id" />
			<result property="telephone" column="telephone_" />
			<result property="idCard" column="id_card" />
			<result property="faceImageUrl" column="face_image_url" />
			<result property="address" column="address_" />
			<result property="sceneId" column="scene_id" />
			<result property="regionId" column="region_id" />
			<result property="status" column="status_" />
			<result property="examinePopedomId" column="examine_popedom_id" />
			<result property="examineTime" column="examine_time" />
			<result property="remark" column="remark_" />
			<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="sceneName" column="scene_name" />
		<result property="companyName" column="company_name" />
		<result property="personRoleName" column="person_role_name" />
		<result property="statusN" column="statusN_"/>
		<result property="structureName" column="structure_name"/>
		<result property="serviceCompanyId" column="service_company_id"/>
		<result property="popularizePersonId" column="popularize_person_id"/>
		<result property="examineName" column="examine_name"/>
		<result property="deviceIds" column="device_ids"/>
		<result property="openId" column="open_id"/>
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.PersonApplicationInfo">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_person_application_info
	    (id_,person_id,name_,applicant_time,company_id,person_role_id,structure_id,telephone_,id_card,face_image_url,address_,scene_id,region_id,status_,examine_popedom_id,examine_time,remark_,create_by,create_time,update_by,update_time,del_flag,service_company_id,popularize_person_id,examine_name,device_ids,open_id)
		values
		(
#{id,jdbcType=VARCHAR}
,#{personId,jdbcType=BIGINT}
,#{name,jdbcType=VARCHAR}
,#{applicantTime,jdbcType= TIMESTAMP }
,#{companyId,jdbcType=VARCHAR}
,#{personRoleId,jdbcType=VARCHAR}
,#{structureId,jdbcType=VARCHAR}
,#{telephone,jdbcType=VARCHAR}
,#{idCard,jdbcType=VARCHAR}
,#{faceImageUrl,jdbcType=VARCHAR}
,#{address,jdbcType=VARCHAR}
,#{sceneId,jdbcType=VARCHAR}
,#{regionId,jdbcType=VARCHAR}
,#{status,jdbcType=VARCHAR}
,#{examinePopedomId,jdbcType=VARCHAR}
,#{examineTime,jdbcType= TIMESTAMP }
,#{remark,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{serviceCompanyId,jdbcType=VARCHAR}
,#{popularizePersonId,jdbcType=BIGINT}
,#{examineName,jdbcType=VARCHAR}
,#{deviceIds,jdbcType=VARCHAR}
,#{openId,jdbcType=VARCHAR}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_person_application_info where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.PersonApplicationInfo">
		update base_person_application_info
		<set>
			<if test="personId!=null">
				person_id=#{personId,jdbcType=BIGINT},
			</if>
				<if test="name!=null">
		name_=#{name,jdbcType=VARCHAR},
		</if>
				<if test="applicantTime!=null">
		applicant_time=#{applicantTime,jdbcType= TIMESTAMP },
		</if>
				<if test="companyId!=null">
		company_id=#{companyId,jdbcType=VARCHAR},
		</if>
				<if test="personRoleId!=null">
		person_role_id=#{personRoleId,jdbcType=VARCHAR},
		</if>
				<if test="structureId!=null">
		structure_id=#{structureId,jdbcType=VARCHAR},
		</if>
				<if test="telephone!=null">
		telephone_=#{telephone,jdbcType=VARCHAR},
		</if>
				<if test="idCard!=null">
		id_card=#{idCard,jdbcType=VARCHAR},
		</if>
				<if test="faceImageUrl!=null">
		face_image_url=#{faceImageUrl,jdbcType=VARCHAR},
		</if>
				<if test="address!=null">
		address_=#{address,jdbcType=VARCHAR},
		</if>
				<if test="sceneId!=null">
		scene_id=#{sceneId,jdbcType=VARCHAR},
		</if>
				<if test="regionId!=null">
		region_id=#{regionId,jdbcType=VARCHAR},
		</if>
				<if test="status!=null">
		status_=#{status,jdbcType=VARCHAR},
		</if>
				<if test="examinePopedomId!=null">
		examine_popedom_id=#{examinePopedomId,jdbcType=VARCHAR},
		</if>
				<if test="examineTime!=null">
		examine_time=#{examineTime,jdbcType= TIMESTAMP },
		</if>
				<if test="remark!=null">
		remark_=#{remark,jdbcType=VARCHAR},
		</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="serviceCompanyId!=null">
				service_company_id=#{serviceCompanyId,jdbcType=VARCHAR },
			</if>
			<if test="popularizePersonId!=null">
				popularize_person_id=#{popularizePersonId,jdbcType=BIGINT },
			</if>
			<if test="examineName!=null">
				examine_name=#{examineName,jdbcType=VARCHAR },
			</if>
			<if test="deviceIds!=null">
				device_ids=#{deviceIds,jdbcType=VARCHAR },
			</if>
			<if test="openId != null">
				open_id = #{openId,jdbcType=VARCHAR}
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="PersonApplicationInfoMap">
			select
				a.*,
				b.scene_name as scene_name,
				c.name_ as company_name,
				d.person_role_name as person_role_name
			from
				base_person_application_info a
				left join base_scene_info b on a.scene_id = b.id_
				left join base_company_info c on a.company_id = c.id_
				left join base_person_role_info d on a.person_role_id = d.id_
			where
				a.id_ = #{0}
				and a.del_flag = 0
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_person_application_info where id_=#{0}
	</select>
	<select id="list" resultMap="PersonApplicationInfoMap">
		select * from base_person_application_info
	</select>
	<select id="search" parameterType="hashmap" resultMap="PersonApplicationInfoMap">
		<![CDATA[
			select
				a.*,
				b.scene_name as scene_name,
				c.name_ as company_name,
				d.person_role_name as person_role_name
			from
				base_person_application_info a
				left join base_scene_info b on a.scene_id = b.id_
				left join base_company_info c on a.company_id = c.id_
				left join base_person_role_info d on a.person_role_id = d.id_
		]]>
		<where>
			a.del_flag = 0
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.companyId != null">
				and a.company_id  = #{searchParams.companyId}
			</if>
			<if test="searchParams.companyCode != null">
				and c.code_ like #{searchParams.companyCode}
			</if>
			<if test="searchParams.name != null">
				and a.name_  like #{searchParams.name}
			</if>
            <if test="searchParams.telephone != null">
                and a.telephone_  like #{searchParams.telephone}
            </if>
			<if test="searchParams.serviceCompanyId != null">
				and a.service_company_id  = #{searchParams.serviceCompanyId}
			</if>

			<if test="searchParams.InCompanyId != null">
				<foreach collection="searchParams.InCompanyId" index="index" item="item" open="and a.company_id in("
						 separator="," close=")">
					#{item}
				</foreach>
			</if>

			<if test="searchParams.status != null">
				and a.status_ = #{searchParams.status}
			</if>
			<if test="searchParams.notStatus != null">
				and a.status_ != #{searchParams.notStatus}
			</if>
			<if test="searchParams.serviceCompanyIdIsNull != null">
				and a.service_company_id is null
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="findByTelephoneAndStatus" resultMap="PersonApplicationInfoMap">
		<![CDATA[
		select * from base_person_application_info
		where del_flag = 0
		and status_ = #{status}
		and telephone_ = #{phone}
		and person_id is null
		limit 1
		]]>
	</select>

	<select id="findIsExistApply" resultMap="PersonApplicationInfoMap">
		<![CDATA[
		select * from base_person_application_info
		where del_flag = 0
		and company_id = #{companyId}
		and telephone_ = #{telephone}
		and status_ = #{status}
		limit 1
		]]>
	</select>

	<select id="findPhoneAndStatus" resultMap="PersonApplicationInfoMap">
		<![CDATA[
		select * from base_person_application_info
		where del_flag = 0
		and status_ = #{status}
		and telephone_ = #{phone}
		limit 1
		]]>
	</select>
</mapper>