<?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.ProjectDepositManagementDao">
    
	<sql id="projectDepositManagementColumns">
		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.deposit_amount AS "depositAmount",
		a.project_id AS "projectId",
		a.status AS "status",
		a.process_instance_id AS "processInstanceId",
		p.project_name AS "project.projectName",
		p.project_number AS "project.projectNumber",
		r.openbid_time AS "openbidTime",
		a.client_Id AS "clientId",
		i.name AS "clientName"
	</sql>
	
	<sql id="projectDepositManagementJoins">
		LEFT JOIN  project p ON p.id = a.project_id
		LEFT JOIN  work_client_info i ON i.id = a.client_id
		LEFT JOIN  project_evaluation_record r ON r.project_id = a.project_id
	</sql>

	<select id="get" resultType="ProjectDepositManagement" >
		SELECT 
			<include refid="projectDepositManagementColumns"/>
		FROM project_deposit_management a
		<include refid="projectDepositManagementJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByProcessInstanceId" resultType="ProjectDepositManagement">
		SELECT
		<include refid="projectDepositManagementColumns"/>
		FROM project_deposit_management a
		<include refid="projectDepositManagementJoins"/>
		WHERE a.process_instance_id = #{processInstanceId}
	</select>
	
	<select id="findList" resultType="ProjectDepositManagement" >
		SELECT 
			<include refid="projectDepositManagementColumns"/>
		FROM project_deposit_management a
		<include refid="projectDepositManagementJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="depositAmount != null and depositAmount != ''">
				AND a.deposit_amount = #{depositAmount}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY a.update_date ASC
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="ProjectDepositManagement" >
		SELECT 
			<include refid="projectDepositManagementColumns"/>
		FROM project_deposit_management a
		<include refid="projectDepositManagementJoins"/>
		<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 project_deposit_management(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			deposit_amount,
			project_id,
			status,
			client_Id,
			process_instance_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{depositAmount},
			#{projectName},
			#{status},
			#{clientId},
			#{processInstanceId}
		)
	</insert>
	
	<update id="update">
		UPDATE project_deposit_management SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			deposit_amount = #{depositAmount},
			project_id = #{projectId},
			status = #{status},
			process_instance_id = #{processInstanceId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM project_deposit_management
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE project_deposit_management SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>

	<update id="updateProcessInstanceId">
		UPDATE project_deposit_management SET
		process_instance_id = #{processInstanceId}
		WHERE id = #{id}
	</update>

	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="ProjectDepositManagement" statementType="STATEMENT">
		select * FROM project_deposit_management  where ${propertyName} = '${value}'
	</select>
	
</mapper>