<?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.workprojectdeposit.dao.WorkProjectDepositDao">
    
	<sql id="workProjectDepositColumns">
		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.del_flag AS "delFlag",
		a.remarks AS "remarks",
		a.biding_project_id AS "bidingProject.id",
		a.biding_office_name AS "bidingOfficeName",
		a.contacts AS "contacts",
		a.phone AS "phone",
		a.e_mail AS "email",
		a.deposit AS "deposit",
		a.deposit_status AS "depositStatus",
		a.biding_document_fee AS "bidingDocumentFee",
		a.biding_document_status AS "bidingDocumentStatus",
		a.biding_state AS "bidingState",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		b.project_name AS "bidingProject.projectName"
	</sql>
	
	<sql id="workProjectDepositJoins">
		JOIN sys_office o ON o.id = a.office_id
		JOIN sys_office s ON s.id = a.company_id
		LEFT JOIN  work_biding_project b ON b.id = a.biding_project_id
	</sql>

	<select id="getByBidingProjectId" resultType="WorkProjectDeposit">
		SELECT
			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.del_flag AS "delFlag",
			a.remarks AS "remarks",
			a.biding_project_id AS "bidingProject.id",
			a.biding_office_name AS "bidingOfficeName",
			a.contacts AS "contacts",
			a.phone AS "phone",
			a.e_mail AS "email",
			a.deposit AS "deposit",
			a.deposit_status AS "depositStatus",
			a.biding_document_fee AS "bidingDocumentFee",
			a.biding_document_status AS "bidingDocumentStatus",
			a.biding_state AS "bidingState",
			a.company_id AS "companyId",
			a.office_id AS "officeId"
		FROM work_project_deposit a
		JOIN work_biding_project b ON a.biding_project_id = b.id
		WHERE a.biding_project_id = #{workBidingProjectId}
	</select>

	<select id="getById" resultType="WorkProjectDeposit">
		SELECT
			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.del_flag AS "delFlag",
			a.remarks AS "remarks",
			a.biding_project_id AS "bidingProject.id",
			a.biding_office_name AS "bidingOfficeName",
			a.contacts AS "contacts",
			a.phone AS "phone",
			a.e_mail AS "email",
			a.deposit AS "deposit",
			a.deposit_status AS "depositStatus",
			a.biding_document_fee AS "bidingDocumentFee",
			a.biding_document_status AS "bidingDocumentStatus",
			a.biding_state AS "bidingState",
			a.company_id AS "companyId",
			a.office_id AS "officeId"
		FROM work_project_deposit a
		JOIN work_biding_project b ON a.biding_project_id = b.id
		WHERE a.id = #{workProjectDepositId}
	</select>

	<select id="get" resultType="WorkProjectDeposit" >
		SELECT 
			<include refid="workProjectDepositColumns"/>
		FROM work_project_deposit a
		<include refid="workProjectDepositJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkProjectDeposit" >
		SELECT 
			<include refid="workProjectDepositColumns"/>
		FROM work_project_deposit a
		<include refid="workProjectDepositJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="bidingProject != null and bidingProject.projectName != null and bidingProject.projectName != ''">
				AND b.project_name LIKE
					<if test="dbName == 'oracle'">'%'||#{bidingProject.projectName}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{bidingProject.projectName}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{bidingProject.projectName},'%')</if>
			</if>
			<if test="bidingOfficeName != null and bidingOfficeName != ''">
				AND a.biding_office_name LIKE
					<if test="dbName == 'oracle'">'%'||#{bidingOfficeName}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{bidingOfficeName}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{bidingOfficeName},'%')</if>
			</if>
			<if test="depositStatus != null and depositStatus != ''">
				AND a.deposit_status = #{depositStatus}
			</if>
			<if test="bidingDocumentStatus != null and bidingDocumentStatus != ''">
				AND a.biding_document_status = #{bidingDocumentStatus}
			</if>
			${sqlMap.dsf}
		</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>
	
	<select id="findAllList" resultType="WorkProjectDeposit" >
		SELECT 
			<include refid="workProjectDepositColumns"/>
		FROM work_project_deposit a
		<include refid="workProjectDepositJoins"/>
		<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>

	<select id="getByPid" resultType="WorkProjectDeposit" >
		SELECT
		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.del_flag AS "delFlag",
		a.remarks AS "remarks",
		a.biding_project_id AS "bidingProject.id",
		a.biding_office_name AS "bidingOfficeName",
		a.contacts AS "contacts",
		a.phone AS "phone",
		a.e_mail AS "email",
		a.deposit AS "deposit",
		a.deposit_status AS "depositStatus",
		a.biding_document_fee AS "bidingDocumentFee",
		a.biding_document_status AS "bidingDocumentStatus",
		a.biding_state AS "bidingState",
		b.project_name AS "bidingProject.projectName"
		FROM work_project_deposit a
		LEFT JOIN  work_biding_project b ON b.id = a.biding_project_id
		where a.del_flag = 0 and a.biding_project_id = #{bidingProjectid}
	</select>
	
	<insert id="insert">
		INSERT INTO work_project_deposit(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			remarks,
			biding_project_id,
			biding_office_name,
			contacts,
			phone,
			e_mail,
			deposit,
			deposit_status,
			biding_document_fee,
			biding_state,
			company_id,
			office_id,
			biding_document_status
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
			#{remarks},
			#{bidingProject.id},
			#{bidingOfficeName},
			#{contacts},
			#{phone},
			#{email},
			#{deposit},
			#{depositStatus},
			#{bidingDocumentFee},
			#{bidingState},
			#{companyId},
			#{officeId},
			#{bidingDocumentStatus}
		)
	</insert>
	
	<update id="update">
		UPDATE work_project_deposit SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			biding_project_id = #{bidingProject.id},
			biding_office_name = #{bidingOfficeName},
			contacts = #{contacts},
			phone = #{phone},
			e_mail = #{email},
			deposit = #{deposit},
			deposit_status = #{depositStatus},
			biding_document_fee = #{bidingDocumentFee},
			biding_state = #{bidingState},
			company_id = #{companyId},
			office_id = #{officeId},
			biding_document_status = #{bidingDocumentStatus}
		WHERE id = #{id}
	</update>
	<update id="updateState">
		UPDATE work_project_deposit SET
		biding_state = #{bidingState}
		WHERE id = #{id}
	</update>

	<update id="updateStatus">
		UPDATE work_project_deposit SET
		deposit_status = #{depositStatus}
		WHERE id = #{id}
	</update>
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_project_deposit
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_project_deposit SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkProjectDeposit" statementType="STATEMENT">
		select * FROM work_project_deposit  where ${propertyName} = '${value}'
	</select>
	
</mapper>