<?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.casematerialsnorm.dao.CaseMaterialsNormDao">
    
	<sql id="caseMaterialsNormColumns">
		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.name AS "name",
		a.type AS "type",
		a.unit_content AS "unitContent",
		a.unit AS "unit",
		a.all_price AS "allPrice",
		a.proportion AS "proportion",
		a.case_id AS "caseId"
	</sql>
	
	<sql id="caseMaterialsNormJoins">
	</sql>
	
    
	<select id="get" resultType="CaseMaterialsNorm" >
		SELECT 
			<include refid="caseMaterialsNormColumns"/>
		FROM case_materials_norm a
		<include refid="caseMaterialsNormJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="CaseMaterialsNorm" >
		SELECT 
			<include refid="caseMaterialsNormColumns"/>
		FROM case_materials_norm a
		<include refid="caseMaterialsNormJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="caseId!= null and caseId!= ''">
				AND a.case_id = #{caseId}
			</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="CaseMaterialsNorm" >
		SELECT 
			<include refid="caseMaterialsNormColumns"/>
		FROM case_materials_norm a
		<include refid="caseMaterialsNormJoins"/>
		<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 case_materials_norm(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			name,
			type,
			unit_content,
			unit,
			all_price,
			proportion,
			case_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{name},
			#{type},
			#{unitContent},
			#{unit},
			#{allPrice},
			#{proportion},
			#{caseId}
		)
	</insert>
	
	<update id="update">
		UPDATE case_materials_norm SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			name = #{name},
			type = #{type},
			unit_content = #{unitContent},
			unit = #{unit},
			all_price = #{allPrice},
			proportion = #{proportion},
			case_id = #{caseId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM case_materials_norm
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE case_materials_norm SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="CaseMaterialsNorm" statementType="STATEMENT">
		select * FROM case_materials_norm  where ${propertyName} = '${value}'
	</select>
	
</mapper>