<?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.WorkProjectCalcDecorDao">
    
	<sql id="workProjectCalcDecorColumns">
		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.decor_number AS "decorNumber",
		a.decor_code AS "decorCode",
		a.project_name AS "projectName",
		a.decor_unit AS "decorUnit",
		a.decor_mode AS "decorMode",
		a.decor_size AS "decorSize",
		a.decor_other AS "decorOther",
		a.decor_origin AS "decorOrigin",
		a.project_id AS "projectId"
	</sql>
	
	<sql id="workProjectCalcDecorJoins">
	</sql>
	
    
	<select id="get" resultType="WorkProjectCalcDecor" >
		SELECT 
			<include refid="workProjectCalcDecorColumns"/>
		FROM work_project_calc_decor a
		<include refid="workProjectCalcDecorJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkProjectCalcDecor" >
		SELECT 
			<include refid="workProjectCalcDecorColumns"/>
		FROM work_project_calc_decor a
		<include refid="workProjectCalcDecorJoins"/>
		<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="WorkProjectCalcDecor" >
		SELECT 
			<include refid="workProjectCalcDecorColumns"/>
		FROM work_project_calc_decor a
		<include refid="workProjectCalcDecorJoins"/>
		<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_decor(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			decor_number,
			decor_code,
			project_name,
			decor_unit,
			decor_mode,
			decor_size,
			decor_other,
			decor_origin,
			project_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{decorNumber},
			#{decorCode},
			#{projectName},
			#{decorUnit},
			#{decorMode},
			#{decorSize},
			#{decorOther},
			#{decorOrigin},
			#{projectId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_project_calc_decor SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			decor_number = #{decorNumber},
			decor_code = #{decorCode},
			project_name = #{projectName},
			decor_unit = #{decorUnit},
			decor_mode = #{decorMode},
			decor_size = #{decorSize},
			decor_other = #{decorOther},
			decor_origin = #{decorOrigin},
			project_id = #{projectId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_project_calc_decor
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_project_calc_decor SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkProjectCalcDecor" statementType="STATEMENT">
		select * FROM work_project_calc_decor  where ${propertyName} = '${value}'
	</select>

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