<?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.materialProvided.mapper.MaterialProvidedVersionMapper">
    
	<sql id="materialColumns">
		a.id AS "id",
		a.create_by As "createBy.id",
		a.create_date As "createDate",
		a.versionName AS "versionName",
		a.versionAlias AS "versionAlias"
	</sql>
	<select id="get" resultType="MaterialProvidedVersion" >
		SELECT 
			<include refid="materialColumns"/>
		FROM xm_material_provided_version a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="MaterialProvidedVersion" >
		SELECT
			<include refid="materialColumns"/>
		FROM xm_material_provided_version a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="versionName != null  and  versionName != ''" >
				AND a.versionName LIKE CONCAT(CONCAT('%',#{versionName},'%'))
			</if>
			<if test="versionAlias != null and  versionAlias != ''">
				AND a.versionAlias LIKE CONCAT(CONCAT('%',#{versionAlias},'%'))
			</if>
		</where>
		order by create_date DESC
	</select>
	
	<select id="findAllList" resultType="MaterialProvidedVersion" >
		SELECT
			<include refid="materialColumns"/>
		FROM xm_material_provided_version a
			<include refid="materialColumns"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</where>
		order by create_date DESC
	</select>
	
	<insert id="insert">
		INSERT INTO xm_material_provided_version(
			id,
			create_by,
			create_date,
			del_flag,
			versionName,
			versionAlias
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{delFlag},
			#{versionName},
			#{versionAlias}
		)
	</insert>

	<!--物理删除-->
	<update id="delete">
		DELETE FROM xm_material_provided_version
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE xm_material_provided_version SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>

	<!-- 查找最大的版本信息 -->
	<select id="findMaxVersion" resultType="com.jeeplus.modules.sg.managementcenter.materialProvided.entity.MaterialProvidedVersion">
		select
		<include refid="materialColumns"/>
		from xm_material_provided_version order by create_date desc LIMIT 1
	</select>

	<select id="findAllVersion" resultType="com.jeeplus.modules.sg.managementcenter.materialProvided.entity.MaterialProvidedVersion">
		select
		<include refid="materialColumns"/>
		from
		xm_material_provided_version a
		<where>
			a.del_flag = '0'
		</where>
	   order by a.create_date DESC
	</select>

	<select id="findById" resultType="MaterialProvidedVersion" >
		SELECT
		<include refid="materialColumns"/>
		FROM xm_material_provided_version a
		<where>
			a.del_flag = '0' and a.versionName = #{versionName}
		</where>
	</select>
</mapper>