<?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.WorkContentPricemanageDao">
    
	<sql id="workContentPricemanageColumns">
		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.cont_id AS "contract.id",
		a.price_type AS "priceType",
		a.price_date AS "priceDate",
		a.review_amt AS "reviewAmt",
		a.set_amt AS "setAmt",
		a.sub_date AS "subDate",
		a.set_date AS "setDate",
		a.in_account AS "inAccount",
		a.in_payment AS "inPayment",
		a.scope AS "scope",
		a.explains AS "explain",
		cd.name AS "contract.name"
	</sql>
	
	<sql id="workContentPricemanageJoins">
		LEFT JOIN  project_content_data cd ON cd.id = a.cont_id
	</sql>
	
    
	<select id="get" resultType="WorkContentPricemanage" >
		SELECT 
			<include refid="workContentPricemanageColumns"/>
		FROM work_content_pricemanage a
		<include refid="workContentPricemanageJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentPricemanage" >
		SELECT 
			<include refid="workContentPricemanageColumns"/>
		FROM work_content_pricemanage a
		<include refid="workContentPricemanageJoins"/>
		<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="WorkContentPricemanage" >
		SELECT 
			<include refid="workContentPricemanageColumns"/>
		FROM work_content_pricemanage a
		<include refid="workContentPricemanageJoins"/>
		<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_pricemanage(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			cont_id,
			price_type,
			price_date,
			scope,
			review_amt,
			set_amt,
			sub_date,
			set_date,
			in_account,
			in_payment,
			explains
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{contract.id},
			#{priceType},
			#{priceDate},
			#{scope},
			#{reviewAmt},
			#{setAmt},
			#{subDate},
			#{setDate},
			#{inAccount},
			#{inPayment},
			#{explain}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_pricemanage SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			cont_id = #{contract.id},
			price_type = #{priceType},
			price_date = #{priceDate},
			scope = #{scope},
			review_amt = #{reviewAmt},
			set_amt = #{setAmt},
			sub_date = #{subDate},
			set_date = #{setDate},
			in_account = #{inAccount},
			in_payment = #{inPayment},
			explains = #{explain}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_pricemanage
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_pricemanage SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentPricemanage" statementType="STATEMENT">
		select * FROM work_content_pricemanage  where ${propertyName} = '${value}'
	</select>
	
</mapper>