<?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.moduleacquisition.mapper.ModuleBlockMapper">
    
	<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.md_big_class AS "mdBigClass",
		a.md_the_class AS "mdTheClass",
		a.md_small_class AS "mdSmallClass",
		a.md_unit AS "mdUnit",
		a.md_img AS "mdImg",
		a.md_big_sort AS "mdBigSort",
		a.md_the_sort AS "mdTheSort",
		a.md_small_sort AS "mdSmallSort",
		a.md_version AS "mdVersion"
	</sql>

    
	<select id="get" resultType="ModuleBlock" >
		SELECT 
			<include refid="infoColumns"/>
		FROM md_module_block a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="ModuleBlock" >
		SELECT 
			<include refid="infoColumns"/>
		FROM md_module_block a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="mdBigClass != null and mdBigClass != ''">
				AND a.md_big_class LIKE CONCAT(CONCAT('%',#{mdBigClass},'%'))
			</if>
			<if test="mdTheClass != null and mdTheClass != ''">
				AND a.md_the_class LIKE CONCAT(CONCAT('%',#{mdTheClass},'%'))
			</if>
			<if test="mdSmallClass != null and mdSmallClass != ''">
				AND a.md_small_class LIKE CONCAT(CONCAT('%',#{mdSmallClass},'%'))
			</if>
			<if test="mdSmallClass != null and mdSmallClass != ''">
				AND a.md_small_class LIKE CONCAT(CONCAT('%',#{mdSmallClass},'%'))
			</if>
			<if test="mdVersion != null and mdVersion  != ''">
				AND a.md_version =  #{mdVersion}
			</if>
		</where>
		order by md_version+0 desc ,md_big_sort,md_the_sort,md_small_sort
	</select>
	
	<select id="findAllList" resultType="MaterialProject" >
		SELECT 
			<include refid="infoColumns"/>
		FROM md_module_block 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 md_module_block(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			md_big_class,
			md_the_class,
			md_small_class,
			md_unit,
			md_img,
			md_big_sort,
			md_the_sort,
			md_small_sort,
			md_version
		) VALUES (
				#{id},
				#{createBy.id},
				#{createDate},
				#{updateBy.id},
				#{updateDate},
				#{remarks},
				#{delFlag},
				#{mdBigClass},
				#{mdTheClass},
				#{mdSmallClass},
				#{mdUnit},
				#{mdImg},
				#{mdBigSort},
				#{mdTheSort},
				#{mdSmallSort},
				#{mdVersion}

		)
	</insert>

	<insert id="insertList">
		INSERT INTO md_module_block(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			md_big_class,
			md_the_class,
			md_small_class,
			md_unit,
			md_img,
			md_big_sort,
			md_the_sort,
			md_small_sort,
			md_version
		) 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.mdBigClass},
				#{item.mdTheClass},
				#{item.mdSmallClass},
				#{item.mdUnit},
				#{item.mdImg},
				#{item.mdBigSort},
				#{item.mdTheSort},
				#{item.mdSmallSort},
				#{item.mdVersion}
			)
		</foreach>
	</insert>

	<update id="update">
		UPDATE md_module_block SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			del_flag = #{delFlag},
			md_big_class = #{mdBigClass},
			md_the_class = #{mdTheClass},
			md_small_class = #{mdSmallClass},
			md_unit = #{mdUnit},
			md_img = #{mdImg}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM md_module_block
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE md_module_block SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="TestNote" statementType="STATEMENT">
		select * FROM md_module_block  where ${propertyName} = '${value}'
	</select>

	<select id="findMaxVersion" resultType="java.lang.String">
		select md_version from md_module_block group by md_version order by md_version+0 desc LIMIT 1
	</select>

	<select id="findAllVersion" resultType="ModuleVersion">
		select md_version AS version from md_module_block
		<where>
			del_flag = '0'
		</where>
		group by md_version order by md_version+0 DESC
	</select>
</mapper>