<?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.WorkContentInvestmentCostDao">
    
	<sql id="workContentInvestmentCostColumns">
		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.cost_type AS "costType",
		a.cost_num AS "costNum",
		a.cost_name AS "costName",
		a.buildind_cost AS "buildindCost",
		a.equipment_cost AS "equipmentCost",
		a.installation_cost AS "installationCost",
		a.other_expenses AS "otherExpenses",
		a.total_cost AS "totalCost",
		a.count AS "count",
		a.unit AS "unit",
		a.target AS "target",
		a.expense_type AS "expenseType",
		a.node_types AS "nodeTypes"
	</sql>
	
	<sql id="workContentInvestmentCostJoins">
	</sql>
	
    
	<select id="get" resultType="WorkContentInvestmentCost" >
		SELECT 
			<include refid="workContentInvestmentCostColumns"/>
		FROM work_content_investment_cost a
		<include refid="workContentInvestmentCostJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentInvestmentCost" >
		SELECT 
			<include refid="workContentInvestmentCostColumns"/>
		FROM work_content_investment_cost a
		<include refid="workContentInvestmentCostJoins"/>
		<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="WorkContentInvestmentCost" >
		SELECT 
			<include refid="workContentInvestmentCostColumns"/>
		FROM work_content_investment_cost a
		<include refid="workContentInvestmentCostJoins"/>
		<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_investment_cost(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			cost_type,
			cost_num,
			cost_name,
			buildind_cost,
			equipment_cost,
			installation_cost,
			other_expenses,
			total_cost,
			count,
			unit,
			target,
			expense_type,
			node_types
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{costType},
			#{costNum},
			#{costName},
			#{buildindCost},
			#{equipmentCost},
			#{installationCost},
			#{otherExpenses},
			#{totalCost},
			#{count},
			#{unit},
			#{target},
			#{expenseType},
			#{nodeTypes}
		)
	</insert>

    <insert id="batchInsert" parameterType="java.util.List">
		INSERT INTO work_content_investment_cost(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			cost_type,
			cost_num,
			cost_name,
			buildind_cost,
			equipment_cost,
			installation_cost,
			other_expenses,
			total_cost,
			count,
			unit,
			target,
			expense_type,
			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.costType},
            #{item.costNum},
            #{item.costName},
            #{item.buildindCost},
            #{item.equipmentCost},
            #{item.InstallationCost},
            #{item.otherExpenses},
            #{item.totalCost},
            #{item.count},
            #{item.unit},
            #{item.target},
            #{item.expenseType},
            #{item.nodeTypes})
        </foreach>
	</insert>
	
	<update id="update">
		UPDATE work_content_investment_cost SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			cost_type = #{costType},
			cost_num = #{costNum},
			cost_name = #{costName},
			buildind_cost = #{buildindCost},
			equipment_cost = #{equipmentCost},
			installation_cost = #{installationCost},
			other_expenses = #{otherExpenses},
			total_cost = #{totalCost},
			count = #{count},
			unit = #{unit},
			target = #{target},
			expense_type = #{expenseType},
			node_types = #{nodeTypes}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_investment_cost
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_investment_cost SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentInvestmentCost" statementType="STATEMENT">
		select * FROM work_content_investment_cost  where ${propertyName} = '${value}'
	</select>
	
</mapper>