<?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.WorkContentClaimDao">
    
	<sql id="workContentClaimColumns">
		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.contract_id AS "contract.id",
		a.claim_type AS "claimType",
		a.claim_date AS "claimDate",
		a.content AS "content",
		a.review_amt AS "reviewAmt",
		a.set_amt AS "setAmt",
		a.review_date AS "reviewDate",
		a.set_date AS "setDate",
		a.in_account AS "inAccount",
		a.in_payment AS "inPayment",
		pd.name AS "contract.name",
		su.name AS "createBy.name"
	</sql>
	
	<sql id="workContentClaimJoins">
		LEFT JOIN  project_content_data pd ON pd.id = a.contract_id
		LEFT JOIN sys_user su on su.id = a.create_by
	</sql>
	
    
	<select id="get" resultType="WorkContentClaim" >
		SELECT 
			<include refid="workContentClaimColumns"/>
		FROM work_content_claim a
		<include refid="workContentClaimJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="findByConId" resultType="WorkContentClaim" parameterType="String">
		select wcc.review_amt  as 'reviewAmt',wcc.set_amt as 'setAmt',wcc.content_id as 'contentId',pcd2.name as 'proConTentName',wcc.cont_id as 'contractId',
		wct.type_name as 'typeName',wcc.create_date as 'createDate',wcc.update_date as 'updateDate', pcd.name as 'name',
		wct.type_name as 'typeName',su.name as 'createName'
		from (select id,create_by,create_date,update_by,update_date,remarks,del_flag,project_id,content_id,cont_id,alter_type,alter_date,review_amt,set_amt  from work_content_altermanage
		union all
		select id,create_by,create_date,update_by,update_date,remarks,del_flag,project_id,content_id,cont_id,price_type,price_date,review_amt,set_amt from work_content_pricemanage
		union all
		select id,create_by,create_date,update_by,update_date,remarks,del_flag,project_id,content_id,contract_id,claim_type,claim_date,review_amt,set_amt from work_content_claim
		union all
		select id,create_by,create_date,update_by,update_date,remarks,del_flag,project_id,content_id,cont_id,visa_type,
		visa_date,review_amt,set_amt from work_content_visamanage) as  wcc
		left join project_content_data pcd on wcc.cont_id = pcd.id
		left join project_content_data pcd2 on pcd2.id =wcc.content_id
		left join project_content_info pci on pci.info_id = wcc.content_id
		left join work_content_type wct on wct.type_id = pci.dict_type
		left join sys_user su on su.id = wcc.create_by
		where pcd.id = #{conId} and pci.info_id is not null
		order by wcc.update_date asc
	</select>
	
	<select id="findList" resultType="WorkContentClaim" >
		SELECT 
			<include refid="workContentClaimColumns"/>
		FROM work_content_claim a
		<include refid="workContentClaimJoins"/>
		<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="WorkContentClaim" >
		SELECT 
			<include refid="workContentClaimColumns"/>
		FROM work_content_claim a
		<include refid="workContentClaimJoins"/>
		<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_claim(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			contract_id,
			claim_type,
			claim_date,
			content,
			review_amt,
			set_amt,
			review_date,
			set_date,
			in_account,
			in_payment
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{contract.id},
			#{claimType},
			#{claimDate},
			#{content},
			#{reviewAmt},
			#{setAmt},
			#{reviewDate},
			#{setDate},
			#{inAccount},
			#{inPayment}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_claim SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			contract_id = #{contract.id},
			claim_type = #{claimType},
			claim_date = #{claimDate},
			content = #{content},
			review_amt = #{reviewAmt},
			set_amt = #{setAmt},
			review_date = #{reviewDate},
			set_date = #{setDate},
			in_account = #{inAccount},
			in_payment = #{inPayment}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_claim
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_claim SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentClaim" statementType="STATEMENT">
		select * FROM work_content_claim  where ${propertyName} = '${value}'
	</select>
	
</mapper>