<?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.workcontent.dao.WorkContentContractSumDao">
    
	<sql id="infoColums">
		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",
		b.project_id AS "projectId",
		b.content_id AS "contentId",
		b.cnumber AS "cnumber",
		b.cont_cate AS "contCate",
		b.cont_attr AS "contAttr",
		b.letting_agent AS "lettingAgent",
		b.contractor AS "contractor",
		b.scope AS "scope",
		b.sign_date AS "signDate",
		b.titular_amt AS "targetCost",
        b.true_amt AS "contractAmount"
--         a.budget_fee AS "budgetFee",
--         a.settlement_fee AS "settlementFee",
--         a.visa_change_fee AS "visaChangeFee",
--         a.supplement_fee AS "supplementFee",
--         a.contract_difference AS "contractDifference",
--         a.claim_fee AS "claimFee" ,
--         a.deductions_parameter AS "deductionsParameter",
--         a.dynamic_cost AS "dynamicCost",
--         a.with_contract_amount AS "withContractAmount" ,
--         a.with_target_cost AS "withTargetCost"
	</sql>
	
	<!--<sql id="workContentContractinfoJoins">-->
		<!--LEFT JOIN  project_content_data pd ON pd.id = a.program_id-->
	<!--</sql>-->
	
    
	<select id="get" resultType="WorkContentContractSum" >
		SELECT 
			<include refid="infoColums"/>
		FROM work_content_contractsum a
		LEFT JOIN work_content_contractinfo b on a.contract_id =  b.id

		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentContractSum" >
		SELECT 
			<include refid="infoColums"/>
		FROM work_content_contractsum a
		LEFT JOIN work_content_contractinfo b on a.contract_id =  b.id
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="projectId != null and projectId != ''">
				AND a.project_id = #{projectId}
			</if>
			<if test="contentId != null and contentId != ''">
				AND a.content_id = #{contentId}
			</if>
		</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="WorkContentContractinfo" >-->
		<!--SELECT -->
			<!--<include refid="infoColums"/>-->
		<!--FROM work_content_contractsum a-->
		<!--<include refid="workContentContractinfoJoins"/>-->
		<!--<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 work_content_contractsum(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
            project_id,
            content_id,
            contract_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
            #{projectId},
            #{contentId},
			#{contractId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_contractsum SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			program_id = #{program.id},
			cnumber = #{cnumber},
			cont_cate = #{contCate},
			cont_attr = #{contAttr},
			letting_agent = #{lettingAgent},
			contractor = #{contractor},
			scope = #{scope},
			sign_date = #{signDate},
			target_cost = #{targetCost},
            contract_amount = #{contractAmount},
            budget_fee = #{budgetFee},
            settlement_fee = #{settlementFee},
            visaChange_fee = #{visaChangeFee},
            supplement_fee = #{supplementFee},
            contract_difference = #{contractDifference},
            claim_fee  = #{claimFee},
            deductions_parameter = #{deductionsParameter},
            dynamic_cost = #{dynamicCost},
            with_contract_amount = #{withContractAmount},
            with_target_cost = #{withTargetCost}

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

</mapper>