<?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.WorkContentBiddingplanDao">
    
	<sql id="workContentBiddingplanColumns">
		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.plan_name AS "contProgram.id",
		a.bidding_type AS "biddingType",
		a.bidding_date AS "biddingDate",
		a.ctrl_price AS "ctrlPrice",
		cd.name AS "contProgram.name"
	</sql>
	
	<sql id="workContentBiddingplanJoins">
        LEFT JOIN project_content_data cd on cd.id = a.plan_name
	</sql>
	
    
	<select id="get" resultType="WorkContentBiddingplan" >
		SELECT 
			<include refid="workContentBiddingplanColumns"/>
		FROM work_content_biddingplan a
		<include refid="workContentBiddingplanJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkContentBiddingplan" >
		SELECT 
			<include refid="workContentBiddingplanColumns"/>
		FROM work_content_biddingplan a
		<include refid="workContentBiddingplanJoins"/>
		<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="WorkContentBiddingplan" >
		SELECT 
			<include refid="workContentBiddingplanColumns"/>
		FROM work_content_biddingplan a
		<include refid="workContentBiddingplanJoins"/>
		<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_biddingplan(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			content_id,
			plan_name,
			bidding_type,
			bidding_date,
			ctrl_price
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{contentId},
			#{contProgram.id},
			#{biddingType},
			#{biddingDate},
			#{ctrlPrice}
		)
	</insert>
	
	<update id="update">
		UPDATE work_content_biddingplan SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			project_id = #{projectId},
			content_id = #{contentId},
			plan_name = #{contProgram.id},
			bidding_type = #{biddingType},
			bidding_date = #{biddingDate},
			ctrl_price = #{ctrlPrice}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_content_biddingplan
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_content_biddingplan SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkContentBiddingplan" statementType="STATEMENT">
		select
        <include refid="workContentBiddingplanColumns"/>
        FROM work_content_biddingplan a
        <include refid="workContentBiddingplanJoins"/>
        where ${propertyName} = '${value}'
	</select>
	
</mapper>