<?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.WorkReceiptsSettleInvoiceDao">
    
	<sql id="workReceiptsSettleInvoiceColumns">
		a.id AS "id",
		a.settle_id AS "settleId",
		a.code AS "code",
		a.num AS "num",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.total_money AS "totalMoney",
		a.tax_rate AS "taxRate"
	</sql>
	
	<sql id="workReceiptsSettleInvoiceJoins">
	</sql>
	
    
	<select id="get" resultType="WorkReceiptsSettleInvoice" >
		SELECT 
			<include refid="workReceiptsSettleInvoiceColumns"/>
		FROM work_receipts_settle_invoice a
		<include refid="workReceiptsSettleInvoiceJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkReceiptsSettleInvoice" >
		SELECT 
			<include refid="workReceiptsSettleInvoiceColumns"/>
		FROM work_receipts_settle_invoice a
		<include refid="workReceiptsSettleInvoiceJoins"/>
		<where>
			<if test="settleId!=null and settleId!=''">
                AND a.settle_id = #{settleId}
            </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="WorkReceiptsSettleInvoice" >
		SELECT 
			<include refid="workReceiptsSettleInvoiceColumns"/>
		FROM work_receipts_settle_invoice a
		<include refid="workReceiptsSettleInvoiceJoins"/>
		<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_invoice(
			id,
			settle_id,
			code,
			num,
			create_by,
			create_date,
			total_money,
			tax_rate
		) VALUES (
			#{id},
			#{settleId},
			#{code},
			#{num},
			#{createBy.id},
			#{createDate},
			#{totalMoney},
			#{taxRate}
		)
	</insert>
	
	<update id="update">
		UPDATE work_receipts_settle_invoice SET 	
			settle_id = #{settleId},
			code = #{code},
			num = #{num},
			total_money = #{totalMoney},
			tax_rate = #{taxRate}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_receipts_settle_invoice
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_receipts_settle_invoice SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkReceiptsSettleInvoice" statementType="STATEMENT">
		select * FROM work_receipts_settle_invoice  where ${propertyName} = '${value}'
	</select>

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