<?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.sg.managementcenter.materialinfo.mapper.MaterialVersionMapper">
    
	<sql id="infoColumns">
		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.batch AS "batch"
	</sql>

    
	<select id="get" resultType="MaterialVersion" >
		SELECT 
			<include refid="infoColumns"/>
		FROM xm_material_version a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="MaterialVersion" >
		SELECT 
			<include refid="infoColumns"/>
		FROM xm_material_version a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="batch != null and batch != '' ">
				AND batch = #{batch}
			</if>
		</where>
		ORDER BY a.update_date DESC
	</select>
	

	
	<insert id="insert">
		INSERT INTO xm_material_version(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			batch
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{batch}
		)
	</insert>

    <insert id="insertList">
        INSERT INTO xm_material_standard(
		batch,
		big_classification,
		mid_classification,
		small_classification,
		material_code,
		material_description,
		extend_code,
		combination_code,
		extend_description,
		unit,
		price,
		batch_type,
		specification_id,
		section,
		note
		) VALUES
        <foreach collection="list" item="item" index="index" separator="," >
		(
			#{item.batch},
			#{item.bigClassification},
			#{item.midClassification},
			#{item.smallClassification},
			#{item.materialCode},
			#{item.materialDescription},
			#{item.extendCode},
			#{item.combinationCode},
			#{item.extendDescription},
			#{item.unit},
			#{item.price},
			#{item.batchType},
			#{item.specificationId},
			#{item.section},
			#{item.note}
		)
        </foreach>
	</insert>
	

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

	<update id="deleteData">
		DELETE FROM xm_material_version
		WHERE batch = #{batch}
	</update>

	<delete id="deleteByBatch">
		DELETE FROM xm_material_standard
		WHERE batch = #{batch}
	</delete>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE xm_material_version SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="TestNote" statementType="STATEMENT">
		select * FROM xm_material_version  where ${propertyName} = '${value}'
	</select>





</mapper>