<?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.workreceiptssettle.dao.WorkReceiptsSettleDetailDao">
    
	<sql id="workReceiptsSettleDetailColumns">
		a.id AS "id",
		a.settle_id AS "settleId",
		a.invoice_id AS "invoice.id",
		a.status AS "status",
		a.settle_pct AS "settlePct",
		a.settle_amt AS "settleAmt",
		a.settle_date AS "settleDate",
		a.create_date AS "createDate"
	</sql>
	
	<sql id="workReceiptsSettleDetailJoins">
	</sql>
	
    
	<select id="get" resultType="WorkReceiptsSettleDetail" >
		SELECT 
			<include refid="workReceiptsSettleDetailColumns"/>
		FROM work_receipts_settle_detail a
		<include refid="workReceiptsSettleDetailJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkReceiptsSettleDetail" >
		SELECT 
			<include refid="workReceiptsSettleDetailColumns"/>
		FROM work_receipts_settle_detail a
		<include refid="workReceiptsSettleDetailJoins"/>
		<where>
			<if test="settleId!=null and settleId !=''">
                AND a.settle_id = #{settleId}
            </if>
			<if test="invoice!=null and invoice.id !=null and invoice.id !=''">
                AND a.invoice_id = #{invoice.id}
            </if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="WorkReceiptsSettleDetail" >
		SELECT 
			<include refid="workReceiptsSettleDetailColumns"/>
		FROM work_receipts_settle_detail a
		<include refid="workReceiptsSettleDetailJoins"/>
		<where>

		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO work_receipts_settle_detail(
			id,
			settle_id,
			invoice_id,
			status,
			settle_pct,
			settle_amt,
			settle_date,
			create_date
		) VALUES (
			#{id},
			#{settleId},
			#{invoice.id},
			#{status},
			#{settlePct},
			#{settleAmt},
			#{settleDate},
			#{createDate}
		)
	</insert>
	
	<update id="update">
		UPDATE work_receipts_settle_detail SET 	
			settle_id = #{settleId},
			invoice_id = #{invoice.id},
			status = #{status},
			settle_pct = #{settlePct},
			settle_amt = #{settleAmt},
			settle_date = #{settleDate}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_receipts_settle_detail
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_receipts_settle_detail SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkReceiptsSettleDetail" statementType="STATEMENT">
		select * FROM work_receipts_settle_detail  where ${propertyName} = '${value}'
	</select>

    <!--物理删除-->
    <update id="deleteBySettleId">
        DELETE FROM work_receipts_settle_detail
        WHERE settle_id = #{settleId}
    </update>

    <update id="updatePayStatus">
        UPDATE work_receipts_settle_detail SET status = #{status},settle_date = #{settleDate} WHERE settle_id = #{settleId} AND invoice_id = #{invoice.id}
    </update>
</mapper>