<?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.WorkContentAltermanageDao">
    
	<sql id="workContentAltermanageColumns">
		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.alter_type AS "alterType",
		a.alter_date AS "alterDate",
		a.alter_cost AS "alterCost",
		a.alter_ctnt AS "alterCtnt",
		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",
		cd.name AS "contract.name"
	</sql>
	
	<sql id="workContentAltermanageJoins">
		LEFT JOIN  project_content_data cd ON cd.id = a.cont_id
	</sql>
	
    
	<select id="get" resultType="WorkContentAltermanage" >
		SELECT 
			<include refid="workContentAltermanageColumns"/>
		FROM work_content_altermanage a
		<include refid="workContentAltermanageJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentAltermanage" >
		SELECT 
			<include refid="workContentAltermanageColumns"/>
		FROM work_content_altermanage a
		<include refid="workContentAltermanageJoins"/>
		<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>
			<if test="contract != null and contract.id != null and contract.id !=''">
				AND a.cont_id = #{contract.id}
			</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" parameterType="String" resultType="WorkContentAltermanage">
       SELECT
		<include refid="workContentAltermanageColumns"/>
		,pcd.name as 'proConTentName',wct.type_name as 'typeName',su.name as 'createName'
		FROM work_content_altermanage a
		<include refid="workContentAltermanageJoins"/>
		left join project_content_data pcd on pcd.id =a.content_id
		left join project_content_info pci on pci.info_id = a.content_id
		left join work_content_type wct on wct.type_id = pci.dict_type
        left join sys_user su on su.id = a.create_by
		<where>
			a.cont_id = #{conId} and pcd.del_flag=0
		</where>
	</select>
	
	<select id="findAllList" resultType="WorkContentAltermanage" >
		SELECT 
			<include refid="workContentAltermanageColumns"/>
		FROM work_content_altermanage a
		<include refid="workContentAltermanageJoins"/>
		<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_altermanage(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			cont_id,
			alter_type,
			alter_date,
			alter_cost,
			alter_ctnt,
			review_amt,
			set_amt,
			sub_date,
			set_date,
			in_account,
			in_payment
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{contract.id},
			#{alterType},
			#{alterDate},
			#{alterCost},
			#{alterCtnt},
			#{reviewAmt},
			#{setAmt},
			#{subDate},
			#{setDate},
			#{inAccount},
			#{inPayment}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_altermanage SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			cont_id = #{contract.id},
			alter_type = #{alterType},
			alter_date = #{alterDate},
			alter_cost = #{alterCost},
			alter_ctnt = #{alterCtnt},
			review_amt = #{reviewAmt},
			set_amt = #{setAmt},
			sub_date = #{subDate},
			set_date = #{setDate},
			in_account = #{inAccount},
			in_payment = #{inPayment}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_altermanage
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_altermanage SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentAltermanage" statementType="STATEMENT">
		select * FROM work_content_altermanage  where ${propertyName} = '${value}'
	</select>
	
</mapper>