<?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.ModuleListingMapper">
    
	<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.del_flag AS "delFlag",
		a.remarks AS "remarks",
		a.md_big_class AS "mdBigClass",
        a.md_The_class AS "mdTheClass",
        a.md_name AS "mdName",
        a.big_classification AS "bigClassification",
        a.the_classification AS "theClassification",
        a.small_classification AS "smallClassification",
        a.material_code AS "materialCode",
        a.material_description AS "materialDescription",
        a.extension_description AS "extensionDescription",
        a.md_units AS "mdUnits",
        a.md_count AS "mdCount",
        a.md_single_weight AS "mdSingleWeight",
        a.md_total_weight AS "mdTotalWeight",
       	a.md_the_party AS "mdTheParty",
        a.md_text AS "mdText",
        a.md_total_amount AS "mdTotalAmount",
        a.block_Id AS "blockId"
	</sql>

    
	<select id="get" resultType="ModuleListing" >
		SELECT 
			<include refid="infoColumns"/>
		FROM md_module_listing a
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="ModuleListing" >
		SELECT 
			<include refid="infoColumns"/>
		FROM md_module_listing a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="blockId != null and blockId != ''">
				AND a.block_id = #{blockId}
			</if>
			<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="mdName != null and mdName != ''">
				AND a.md_name LIKE CONCAT(CONCAT('%',#{mdName},'%'))
			</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="ModuleListing" >
		SELECT 
			<include refid="infoColumns"/>
		FROM md_module_listing 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_listing(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			remarks,
			md_big_class,
			md_the_class,
			md_name,
			big_classification,
			the_classification,
			small_classification,
			material_code,
			material_description,
			extension_description,
			md_units,
			md_count,
			md_single_weight,
			md_total_weight,
			md_the_party,
			md_text,
			md_total_amount,
			block_Id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
			#{remarks},
			#{mdBigClass},
			#{mdTheClass},
			#{mdName},
			#{bigClassification},
			#{theClassification},
			#{smallClassification},
			#{materialCode},
			#{materialDescription},
			#{extensionDescription},
			#{mdUnits},
			#{mdCount},
			#{mdSingleWeight},
			#{mdTotalWeight},
			#{mdTheParty},
			#{mdText},
			#{mdTotalAmount},
			#{blockId}
		)
	</insert>

	<insert id="insertList" parameterType="java.util.List">
		INSERT INTO md_module_listing(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			remarks,
			md_big_class,
			md_the_class,
			md_name,
			big_classification,
			the_classification,
			small_classification,
			material_code,
			material_description,
			extension_description,
			md_units,
			md_count,
			md_single_weight,
			md_total_weight,
			md_the_party,
			md_text,
			md_total_amount,
			block_Id
		) VALUES
		<foreach collection="list" item="item" index="index" separator=",">
		  (
				#{item.id},
				#{item.createBy.id},
				#{item.createDate},
				#{item.updateBy.id},
				#{item.updateDate},
				#{item.delFlag},
				#{item.remarks},
				#{item.mdBigClass},
				#{item.mdTheClass},
				#{item.mdName},
				#{item.bigClassification},
				#{item.theClassification},
				#{item.smallClassification},
				#{item.materialCode},
				#{item.materialDescription},
				#{item.extensionDescription},
				#{item.mdUnits},
				#{item.mdCount},
				#{item.mdSingleWeight},
				#{item.mdTotalWeight},
				#{item.mdTheParty},
				#{item.mdText},
				#{item.mdTotalAmount},
				#{item.blockId}
			)
		</foreach>
	</insert>

	<update id="update">
		UPDATE md_module_listing SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			del_flag = #{delFlag},
			md_big_class = #{mdBigClass},
			md_The_class = #{mdTheClass},
			md_name = #{mdName},
			big_classification = #{bigClassification},
			the_classification = #{theClassification},
			small_classification = #{smallClassification},
			material_code = #{materialCode},
			material_description = #{materialDescription},
			extension_description = #{extensionDescription},
			md_units = #{mdUnits},
			md_count = #{mdCount},
			md_single_weight = #{mdSingleWeight},
			md_total_weight = #{mdTotalWeight},
			md_the_party = #{mdTheParty},
			md_text = #{mdText},
			md_total_amount = #{mdTotalAmount}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM md_module_listing
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE md_module_listing SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="TestNote" statementType="STATEMENT">
		select * FROM md_module_listing  where ${propertyName} = '${value}'
	</select>

	<!-- 根据版本号查找模块清单-->
	<select id="findByList" resultType="ModuleListing">
		SELECT
		<include refid="infoColumns"/>
		FROM md_module_listing a
		<where>
			a.block_id in
			<foreach collection="list" item="item" open="(" close=")" separator=",">
				#{item.id}
			</foreach>
		</where>
	</select>
</mapper>