<?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.jeeplus.modules.project.dao.BidInformationDao">

	<sql id="bidInformationColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.bid_opening_time AS "bidOpeningTime",
		a.winning_bid_number AS "winningBidNumber",
		a.central_investment_online AS "centralInvestmentOnline",
		a.tenderee_archives AS "tendereeArchives",
		a.paper_archiving AS "paperArchiving",
		a.time_of_winning_bid AS "timeOfWinningBid",
		a.filing_time AS "filingTime",
		a.first_acceptance_time AS "firstAcceptanceTime",
		a.final_archiving_time AS "finalArchivingTime",
		a.process_instance_id AS "processInstanceId",
		a.status AS "status",
		a.project_id AS "projectId"
	</sql>

	<sql id="bidInformationJoins">
	</sql>

	<sql id="bidInformationColumn">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		Date(a.bid_opening_time) AS "bidOpeningTime",
		a.winning_bid_number AS "winningBidNumber",
		a.central_investment_online AS "centralInvestmentOnline",
		a.tenderee_archives AS "tendereeArchives",
		a.paper_archiving AS "paperArchiving",
		Date(a.time_of_winning_bid) AS "timeOfWinningBid",
		Date(a.filing_time) AS "filingTime",
		Date(a.first_acceptance_time) AS "firstAcceptanceTime",
		Date(a.final_archiving_time) AS "finalArchivingTime",
		a.process_instance_id AS "processInstanceId",
		a.status AS "status",
		a.project_id AS "projectId",
		b.create_date AS "project.createDate",
        b.project_number AS "project.projectNumber",
        b.project_name AS "project.projectName",
        e.name AS "workClientInfo.name",
		cc.leader AS "workprojectgroup.leader",
		GROUP_CONCAT(f.name) AS "archivedirectory.name",
        GROUP_CONCAT(f.number) AS "archivedirectory.number",
        GROUP_CONCAT(f.remarks) AS "archivedirectory.remarks",
        GROUP_CONCAT(f.page_number) AS "archivedirectory.pageNumber"
	</sql>

	<sql id="bidInformationJoin">
		left join project b on a.project_id=b.id
		left join project_group_info cc on cc.project_id = b.id
		left join work_contract_info dd on dd.id = b.contract_info
        left join work_client_info e on dd.client_id = e.id
        left join archive_directory f on f.bid_information_id = a.id
	</sql>
	
    
	<select id="get" resultType="BidInformation" >
		SELECT
			<include refid="bidInformationColumn"/>
		FROM bid_information a
		<include refid="bidInformationJoin"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="BidInformation" >
		SELECT
			<include refid="bidInformationColumn"/>
		FROM bid_information a
		<include refid="bidInformationJoin"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="project != null and project.projectName != null and project.projectName != ''">
				AND b.project_name = #{project.projectName}
			</if>
			<if test="project != null and project.projectNumber != null and project.projectNumber != ''">
				AND b.project_number = #{project.projectNumber}
			</if>
			<if test="project != null and project.createDate != null and project.createDate != ''">
				AND #{project.createDate}  LIKE
					concat('%' ,DATE(b.create_date),'%')
			</if>
			<if test="workClientInfo != null and workClientInfo.name != null and workClientInfo.name != ''">
				AND e.name = #{workClientInfo.name}
			</if>
			<if test="workprojectgroup != null and workprojectgroup.leader != null and workprojectgroup.leader != ''">
				AND cc.leader = #{workprojectgroup.leader}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			${sqlMap.dsf}
		</where>
		GROUP BY a.id
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="BidInformation" >
		SELECT 
			<include refid="bidInformationColumns"/>
		FROM bid_information a
		<include refid="bidInformationJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO bid_information(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			bid_opening_time,
			winning_bid_number,
			central_investment_online,
			tenderee_archives,
			paper_archiving,
			time_of_winning_bid,
			filing_time,
			first_acceptance_time,
			final_archiving_time,
			process_instance_id,
			status,
			project_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{bidOpeningTime},
			#{winningBidNumber},
			#{centralInvestmentOnline},
			#{tendereeArchives},
			#{paperArchiving},
			#{timeOfWinningBid},
			#{filingTime},
			#{firstAcceptanceTime},
			#{finalArchivingTime},
			#{processInstanceId},
			#{status},
			#{projectId}
		)
	</insert>
	
	<update id="update">
		UPDATE bid_information SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			bid_opening_time = #{bidOpeningTime},
			winning_bid_number = #{winningBidNumber},
			central_investment_online = #{centralInvestmentOnline},
			tenderee_archives = #{tendereeArchives},
			paper_archiving = #{paperArchiving},
			time_of_winning_bid = #{timeOfWinningBid},
			filing_time = #{filingTime},
			first_acceptance_time = #{firstAcceptanceTime},
			final_archiving_time = #{finalArchivingTime},
			process_instance_id = #{processInstanceId},
			status = #{status},
			project_id = #{projectId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM bid_information
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE bid_information SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="BidInformation" statementType="STATEMENT">
		select * FROM bid_information  where ${propertyName} = '${value}'
	</select>
	
</mapper>