<?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.oa.mapper.OaNotifyMaterialMapper">

	<sql id="materialColumns">
		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.itemDetail AS "itemDetail",
		a.projectDefinition AS "projectDefinition",
		a.materialCode AS "materialCode",
		a.materialDescription AS "materialDescription",
		a.measuringUnit AS "measuringUnit",
		a.quantityDemanded AS "quantityDemanded",
		a.quantityDelivered AS "quantityDelivered",
		a.stockNumber AS "stockNumber",
		a.parentId AS "parentId"
	</sql>

	<select id="get" resultType="com.jeeplus.modules.oa.entity.OaNotifyMaterial" >
		SELECT
		<include refid="materialColumns"/>
		FROM oa_notify_material a
		WHERE a.id = #{id}
	</select>

	<select id="findList" resultType="com.jeeplus.modules.oa.entity.OaNotifyMaterial" >
		SELECT
		<include refid="materialColumns"/>
		FROM oa_notify_material a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="parentId != null and  parentId != ''">
				AND parentId = #{parentId}
			</if>
		</where>
	</select>

	<select id="findAllList" resultType="com.jeeplus.modules.oa.entity.OaNotifyMaterial" >
		SELECT
		<include refid="materialColumns"/>
		FROM oa_notify_material a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</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 oa_notify_material(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
		)
	</insert>

	<insert id="insertList">
		INSERT INTO oa_notify_material(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			itemDetail,
			projectDefinition,
			materialCode,
			materialDescription,
			measuringUnit,
			quantityDemanded,
			quantityDelivered,
			stockNumber,
			parentId
		) VALUES
		<foreach collection="list" item="item" index="index" separator="," >
			(
			#{item.id},
			#{item.createBy.id},
			#{item.createDate},
			#{item.updateBy.id},
			#{item.updateDate},
			#{item.remarks},
			#{item.delFlag},
			#{item.itemDetail},
			#{item.projectDefinition},
			#{item.materialCode},
			#{item.materialDescription},
			#{item.measuringUnit},
			#{item.quantityDemanded},
			#{item.quantityDelivered},
			#{item.stockNumber},
			#{item.parentId}
			)
		</foreach>
	</insert>

	<update id="update">
		UPDATE oa_notify_material SET

		WHERE id = #{id}
	</update>


	<!--物理删除-->
	<update id="delete">
		DELETE FROM oa_notify_material
		WHERE parentId = #{parentId}
	</update>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE oa_notify_material SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>


	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="com.jeeplus.modules.oa.entity.OaNotifyMaterial" statementType="STATEMENT">
		select * FROM oa_notify_material  where ${id} = '${value}'
	</select>

</mapper>