<?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.WorkContentContractinfoDao">
    
	<sql id="workContentContractinfoColumns">
		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.project_id AS "projectId",
		a.content_id AS "contentId",
		a.program_id AS "program.id",
		a.cnumber AS "cnumber",
		a.cont_cate AS "contCate",
		a.cont_attr AS "contAttr",
		a.letting_agent AS "lettingAgent",
		a.contractor AS "contractor",
		a.scope AS "scope",
		a.sign_date AS "signDate",
		a.effect_date AS "effectDate",
		a.titular_amt AS "titularAmt",
		a.true_amt AS "trueAmt",
		a.pledge_percent AS "pledgePercent",
		a.start_work_date AS "startWorkDate",
		a.end_work_date AS "endWorkDate",
		a.stop_percent AS "stopPercent",
		a.stop_amt AS "stopAmt",
		a.status AS "status",
		a.pay_type AS "payType",
		a.pay_amt AS "payAmt",
		a.start_date AS "startDate",
		a.end_date AS "endDate",
		pd.name AS "program.name"
	</sql>
	
	<sql id="workContentContractinfoJoins">
		LEFT JOIN  project_content_data pd ON pd.id = a.program_id
	</sql>
	
    
	<select id="get" resultType="WorkContentContractinfo" >
		SELECT 
			<include refid="workContentContractinfoColumns"/>
		FROM work_content_contractinfo a
		<include refid="workContentContractinfoJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentContractinfo" >
		SELECT 
			<include refid="workContentContractinfoColumns"/>
		FROM work_content_contractinfo a
		<include refid="workContentContractinfoJoins"/>
		<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="findByConId" resultType="WorkContentContractinfo" parameterType="String">
		SELECT
		<include refid="workContentContractinfoColumns"/>
		,pcd.name as 'proContentName',su.name as 'createName'
		FROM work_content_contractinfo a
		<include refid="workContentContractinfoJoins"/>
		LEFT JOIN  project_content_data pcd ON pcd.id = a.content_id
		left join sys_user su on su.id = a.create_by
		<where>
			content_id = #{id} and pcd.del_flag=0
		</where>
	</select>

	<select id="findByType" resultType="WorkContentContractinfo" parameterType="String">
		SELECT
		a.id
		FROM work_content_contractinfo a
		<where>
			a.cnumber = #{cnumber}
		</where>
		order by a.create_date DESC
	</select>
	
	<select id="findAllList" resultType="WorkContentContractinfo" >
		SELECT 
			<include refid="workContentContractinfoColumns"/>
		FROM work_content_contractinfo 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_contractinfo(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			program_id,
			cnumber,
			cont_cate,
			cont_attr,
			letting_agent,
			contractor,
			scope,
			sign_date,
			effect_date,
			titular_amt,
			true_amt,
			pledge_percent,
			start_work_date,
			end_work_date,
			stop_percent,
			stop_amt,
			status,
			pay_type,
			pay_amt,
			start_date,
			end_date
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{program.id},
			#{cnumber},
			#{contCate},
			#{contAttr},
			#{lettingAgent},
			#{contractor},
			#{scope},
			#{signDate},
			#{effectDate},
			#{titularAmt},
			#{trueAmt},
			#{pledgePercent},
			#{startWorkDate},
			#{endWorkDate},
			#{stopPercent},
			#{stopAmt},
			#{status},
			#{payType},
			#{payAmt},
			#{startDate},
			#{endDate}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_contractinfo 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},
			effect_date = #{effectDate},
			titular_amt = #{titularAmt},
			true_amt = #{trueAmt},
			pledge_percent = #{pledgePercent},
			start_work_date = #{startWorkDate},
			end_work_date = #{endWorkDate},
			stop_percent = #{stopPercent},
			stop_amt = #{stopAmt},
			status = #{status},
			pay_type = #{payType},
			pay_amt = #{payAmt},
			start_date = #{startDate},
			end_date = #{endDate}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_contractinfo
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_contractinfo SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentContractinfo" statementType="STATEMENT">
		select * FROM work_content_contractinfo  where ${propertyName} = '${value}'
	</select>

</mapper>