<?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.WorkContentCtrlpriceDao">
    
	<sql id="workContentCtrlpriceColumns">
		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.inventory_type AS "inventoryType",
		a.ctrl_num AS "ctrlNum",
		a.cost_name AS "costName",
		a.sum AS "sum",
		a.construction_cost AS "constructionCost",
		a.fees AS "fees",
		a.estimate AS "estimate",
		a.node_types AS "nodeTypes"
	</sql>
	
	<sql id="workContentCtrlpriceJoins">
	</sql>
	
    
	<select id="get" resultType="WorkContentCtrlprice" >
		SELECT 
			<include refid="workContentCtrlpriceColumns"/>
		FROM work_content_ctrlprice a
		<include refid="workContentCtrlpriceJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentCtrlprice" >
		SELECT 
			<include refid="workContentCtrlpriceColumns"/>
		FROM work_content_ctrlprice a
		<include refid="workContentCtrlpriceJoins"/>
		<where>
            <if test="projectId!=null and projectId !=''">
                AND a.project_id = #{projectId}
            </if>
            <if test="contentId!=null and contentId !=''">
                AND a.content_id = #{contentId}
            </if>
            AND 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>
	
	<select id="findAllList" resultType="WorkContentCtrlprice" >
		SELECT 
			<include refid="workContentCtrlpriceColumns"/>
		FROM work_content_ctrlprice a
		<include refid="workContentCtrlpriceJoins"/>
		<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_ctrlprice(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			inventory_type,
			ctrl_num,
			cost_name,
			sum,
			construction_cost,
			fees,
			estimate,
			node_types
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{inventoryType},
			#{ctrlNum},
			#{costName},
			#{sum},
			#{constructionCost},
			#{fees},
			#{estimate},
			#{nodeTypes}
		)
	</insert>

    <insert id="batchInsert">
        INSERT INTO work_content_ctrlprice(
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        remarks,
        del_flag,
        project_id,
        content_id,
        inventory_type,
        ctrl_num,
        cost_name,
        sum,
        construction_cost,
        fees,
        estimate,
        node_types
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.remarks},
            #{item.delFlag},
            #{item.projectId},
            #{item.contentId},
            #{item.inventoryType},
            #{item.ctrlNum},
            #{item.costName},
            #{item.sum},
            #{item.constructionCost},
            #{item.fees},
            #{item.estimate},
            #{item.nodeTypes})
        </foreach>
    </insert>
	
	<update id="update">
		UPDATE work_content_ctrlprice SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			inventory_type = #{inventoryType},
			ctrl_num = #{ctrlNum},
			cost_name = #{costName},
			sum = #{sum},
			construction_cost = #{constructionCost},
			fees = #{fees},
			estimate = #{estimate},
			node_types = #{nodeTypes}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_ctrlprice
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_ctrlprice SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentCtrlprice" statementType="STATEMENT">
		select * FROM work_content_ctrlprice  where ${propertyName} = '${value}'
	</select>

</mapper>