<?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.workprojectcalc.dao.WorkProjectCalcBuildDao">
    
	<sql id="workProjectCalcBuildColumns">
		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.build_number AS "buildNumber",
		a.build_code AS "buildCode",
		a.project_name AS "projectName",
		a.build_unit AS "buildUnit",
		a.build_mode AS "buildMode",
		a.build_other AS "buildOther",
		a.build_index AS "buildIndex",
		a.build_size AS "buildSize",
		a.project_id AS "projectId"
	</sql>
	
	<sql id="workProjectCalcBuildJoins">
	</sql>
	
    
	<select id="get" resultType="WorkProjectCalcBuild" >
		SELECT 
			<include refid="workProjectCalcBuildColumns"/>
		FROM work_project_calc_build a
		<include refid="workProjectCalcBuildJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkProjectCalcBuild" >
		SELECT 
			<include refid="workProjectCalcBuildColumns"/>
		FROM work_project_calc_build a
		<include refid="workProjectCalcBuildJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			and a.project_id = #{projectId}
		</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="WorkProjectCalcBuild" >
		SELECT 
			<include refid="workProjectCalcBuildColumns"/>
		FROM work_project_calc_build a
		<include refid="workProjectCalcBuildJoins"/>
		<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_project_calc_build(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			build_number,
			build_code,
			project_name,
			build_unit,
			build_mode,
			build_other,
			build_index,
			build_size,
			project_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{buildNumber},
			#{buildCode},
			#{projectName},
			#{buildUnit},
			#{buildMode},
			#{buildOther},
			#{buildIndex},
			#{buildSize},
			#{projectId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_project_calc_build SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			build_number = #{buildNumber},
			build_code = #{buildCode},
			project_name = #{projectName},
			build_unit = #{buildUnit},
			build_mode = #{buildMode},
			build_other = #{buildOther},
			build_index = #{buildIndex},
			build_size = #{buildSize},
			project_id = #{projectId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_project_calc_build
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_project_calc_build SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkProjectCalcBuild" statementType="STATEMENT">
		select * FROM work_project_calc_build  where ${propertyName} = '${value}'
	</select>

	<!-- 删除关联所有文件 -->
	<delete id="deleteByProId">
		DELETE FROM work_project_calc_build
		WHERE project_id = #{projectId}
	</delete>
</mapper>