<?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.picking.activiti.mapper.ShowListMapper">

    <sql id="classColumns">
		a.md_big_class AS "mdBigClass",
		a.md_the_class AS "mdTheClass",
		a.md_name AS "mdName",
		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 "meTheParty",
		a.md_text AS "mdText",
		a.md_total_amount AS "mdTotalAmount",
		a.block_id AS "blockId"
	</sql>



    <select id="get" resultType="com.jeeplus.modules.sg.picking.activiti.entity.ShowList">
        SELECT
        <include refid="classColumns"/>,
		FROM md_module_listing a
		WHERE a.id = #{id}
    </select>

    <select id="findList" resultType="com.jeeplus.modules.sg.picking.activiti.entity.ShowList">
        SELECT
        <include refid="classColumns"/>
        FROM md_module_listing a
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
        </choose>
        <where>
            <trim prefixOverrides="AND |OR ">
                <if test="findList!=null and findList.size>0">
                    AND block_id in
                <foreach collection="findList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
                </if>
            </trim>
        </where>
        order by material_code,material_description
    </select>

    <select id="findAllList" resultType="com.jeeplus.modules.sg.picking.activiti.entity.ShowList">
        SELECT
        <include refid="classColumns"/>
        FROM md_module_listing a
    </select>

    <!--物理删除-->
    <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>

    <insert id="insert">
		INSERT INTO md_acquisition_process(
			id,
			proc_ins_id,
			project_id,
			the_number,
			version,
			select_number,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{procInsId},
			#{projectId},
			#{theNumber},
			#{sVersion},
			#{selectNumber},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>

    <update id="update">
		UPDATE md_acquisition_process SET
			proc_ins_id = #{procInsId},
			project_id = #{projectId},
			the_number = #{theNumber},
			version = #{sVersion},
			select_number = #{selectNumber},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>

	<select id="findNumber" resultType="string">
		select the_number from md_acquisition_process where project_id = #{projectId} order by the_number DESC LIMIT 1;
	</select>

	<insert id="newSave">
		INSERT INTO md_picking_application(
			id,
			proc_ins_id,
			project_id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{procInsId},
			#{projectId},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>

	<update id="projectUpdate">
		update xm_project_details set earlyMaterial=1
		where id=#{projectId};
	</update>

	<select id="selectProjectId" resultType="string">
		select project_id from md_picking_application where id =#{id}
	</select>
</mapper>