<?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">
<mapper namespace="com.sunxung.factoring.mapper.project.ProjectCoreEnterpriseMapper">

	<select id="findById" resultType="com.sunxung.factoring.entity.project.ProjectCoreEnterprise">
		select
			id,
			c_project_information_id,
			c_enterprise_id,
			c_enterprise_history_id,
			centralized_procurement_platform,
			historical_cooperation,
			historical_cooperation_duration,
			historical_cooperation_scale,
			historical_cooperation_invoicing_amount,
			historical_cooperation_maximum_accounting_period,
			historical_cooperation_times,
			status statusStr,
			gmt_modified
		from c_project_core_enterprise where id = #{id}
	</select>
    <select id="findBySearch" resultType="com.sunxung.factoring.entity.project.ProjectCoreEnterprise">
		select
		    t1.id,
			t2.business_number,
			t2.project_name,
			t3.corporate_name ownerName,
			t5.corporate_name customerName,
			t8.name projectStatusStr,
			t9.name coreStatusStr,
			t1.gmt_modified,
			t10.corporate_name supplierName,
			t1.gmt_modified
		from c_project_core_enterprise t1
			left join c_project_information t2 on t1.c_project_information_id = t2.id
			left join c_enterprise t3 on t2.c_enterprise_id = t3.id
			left join c_project_core_enterprise t4 on t4.c_project_information_id = t2.id
			left join c_enterprise t5 on t4.c_enterprise_id =t5.id
			left join c_supplier_info t6 on t2.c_supplier_info_id = t6.id
			left join c_sys_user t7 on t7.id = t6.sys_user_id
			left join t_dictionary t8 on t8.code = t2.status
			left join t_dictionary t9 on t9.code = t4.status
			left join c_enterprise t10 on t10.id = t6.c_enterprise_id
		<where>
			<if test="fastSearch != null and fastSearch !=''">
				AND (t2.project_name like concat('%',#{fastSearch},'%') OR t5.corporate_name like concat('%',#{fastSearch},'%'))
			</if>
			<if test="status != null and status !=''">
				AND t1.status = #{status}
			</if>
			<if test="userIds != null and userIds.size()>0">
				AND t7.risk_manager in
				<foreach collection="userIds" index="index" item="item"  open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
			order by t1.gmt_modified
	</select>
    <select id="getByProjectInfoId" resultType="com.sunxung.factoring.entity.project.ProjectCoreEnterprise">
		select
			t1.id,
			t1.c_project_information_id,
			t1.c_enterprise_id,
			t1.c_enterprise_history_id,
			t1.centralized_procurement_platform,
			t1.historical_cooperation,
			t1.historical_cooperation_duration,
			t1.historical_cooperation_scale,
			t1.historical_cooperation_invoicing_amount,
			t1.historical_cooperation_maximum_accounting_period,
			t1.historical_cooperation_times,
			t1.status statusStr,
			t2.business_number,
			t2.project_name,
			t3.corporate_name ownerName,
			t5.corporate_name customerName,
			t8.name projectStatusStr,
			t9.name coreStatusStr
		from c_project_core_enterprise t1
				 left join c_project_information t2 on t1.c_project_information_id = t2.id
				 left join c_enterprise t3 on t2.c_enterprise_id = t3.id
				 left join c_project_core_enterprise t4 on t4.c_project_information_id = t2.id
				 left join c_enterprise t5 on t4.c_enterprise_id =t5.id
				 left join c_supplier_info t6 on t2.c_supplier_info_id = t6.id
				 left join c_sys_user t7 on t7.id = t6.sys_user_id
				 left join t_dictionary t8 on t8.code = t2.status
				 left join t_dictionary t9 on t9.code = t4.status
		where t1.c_project_information_id = #{cProjectInformationId}
	</select>
    <select id="getByEnterpriseId" parameterType="java.lang.Long" resultType="com.sunxung.factoring.entity.project.ProjectCoreEnterprise">
		select a.* from c_project_core_enterprise a where a.c_enterprise_id = #{enterpriseId}
	</select>
</mapper>
