<?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.workengineeringprice.dao.WorkEngineeringPriceDao">
    
	<sql id="workEngineeringPriceColumns">
		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.send_price AS "sendPrice",
		a.approved_price AS "approvedPrice",
		a.contract_price AS "contractPrice",
		a.add_edit_amount  AS "addEditAmount",
		a.add_edit_rate AS "addEditRate",
		a.consult_amount  AS "consultAmount",
		a.civil_engineering_cost AS "civilEngineeringCost",
		a.installation_cost AS "installationCost",
		a.engineering_id AS "engineeringId"
	</sql>
	
	<sql id="workEngineeringPriceJoins">
	</sql>
	
    
	<select id="get" resultType="WorkEngineeringPrice" >
		SELECT 
			<include refid="workEngineeringPriceColumns"/>
		FROM work_engineering_price a
		<include refid="workEngineeringPriceJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByEngineeringId" resultType="WorkEngineeringPrice" >
		SELECT
			<include refid="workEngineeringPriceColumns"/>
		FROM work_engineering_price a
		<include refid="workEngineeringPriceJoins"/>
		WHERE a.engineering_id = #{engineeringId}
	</select>

	<select id="findList" resultType="WorkEngineeringPrice" >
		SELECT 
			<include refid="workEngineeringPriceColumns"/>
		FROM work_engineering_price a
		<include refid="workEngineeringPriceJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="engineeringId != null and engineeringId != ''">
				AND a.engineering_id = #{engineeringId}
			</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="WorkEngineeringPrice" >
		SELECT 
			<include refid="workEngineeringPriceColumns"/>
		FROM work_engineering_price a
		<include refid="workEngineeringPriceJoins"/>
		<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_engineering_price(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			send_price,
			approved_price,
			contract_price,
			add_edit_amount ,
			add_edit_rate,
			consult_amount ,
			civil_engineering_cost,
			installation_cost,
			engineering_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{sendPrice},
			#{approvedPrice},
			#{contractPrice},
			#{addEditAmount},
			#{addEditRate},
			#{consultAmount},
			#{civilEngineeringCost},
			#{installationCost},
			#{engineeringId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_engineering_price SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			send_price = #{sendPrice},
			approved_price = #{approvedPrice},
			contract_price = #{contractPrice},
			add_edit_amount  = #{addEditAmount},
			add_edit_rate = #{addEditRate},
			consult_amount  = #{consultAmount},
			civil_engineering_cost = #{civilEngineeringCost},
			installation_cost = #{installationCost},
			engineering_id = #{engineeringId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_engineering_price
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_engineering_price SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkEngineeringPrice" statementType="STATEMENT">
		select * FROM work_engineering_price  where ${propertyName} = '${value}'
	</select>
	
</mapper>