<?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.supply.judgementBills.mapper.SupplyJudgementBillsMapper">

    <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.project_name AS "projectName",
        a.project_definition AS "projectDefinition",
        a.examine_count AS "examineCount",
        a.material_number AS "materialNumber",
        a.submittals_id AS "submittalsId"
    </sql>



    <select id="get" resultType="com.jeeplus.modules.supply.judgementBills.entity.SupplyJudgementBills">
        SELECT
        <include refid="infoColumns"/>
        ,mi.material_description as "materialDescription"
        ,mi.unit_of_measurement as "unit"
        FROM supply_judgement_bills a
        left join material_library mi on a.material_number = mi.material_code
        WHERE a.id = #{id}
    </select>

    <select id="findList" resultType="com.jeeplus.modules.supply.judgementBills.entity.SupplyJudgementBills">
        SELECT
        <include refid="infoColumns"/>
        ,mi.material_description as "materialDescription"
        ,mi.unit_of_measurement as "unit"
        FROM supply_judgement_bills a
        left join material_library mi on a.material_number = mi.material_code
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            ${dataScope}
            <if test="materialNumber != null and materialNumber != ''">
                AND a.material_number LIKE CONCAT('%',#{materialNumber},'%')
            </if>
            <if test="projectDefinition != null and projectDefinition != ''">
                AND a.project_definition LIKE CONCAT('%',#{projectDefinition},'%')
            </if>
            <if test="submittalsId != null and submittalsId != ''">
                AND a.submittals_id LIKE CONCAT('%',#{submittalsId},'%')
            </if>
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
                ORDER BY a.material_number asc,a.update_date DESC
            </otherwise>
        </choose>
    </select>

    <select id="getProjectDefinitionList" resultType="java.lang.String">
        select project_definition_number from project_information
        WHERE project_definition_number in
        <foreach collection="list" item="projectDefinition" index="index" open="(" separator="," close=")">
            #{projectDefinition}
        </foreach>
    </select>

    <insert id="insertList">
        insert into supply_judgement_bills (
        id,
        create_by,
        create_date,
        update_by,
        update_date,
        remarks,
        material_number,
        material_description,
        examine_count,
        unit,
        project_definition,
        project_name,
        submittals_id
        )
        values
        <foreach collection="list" item="item" index="index" separator="," >
            (
            #{item.id},
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.remarks},
            #{item.materialNumber},
            #{item.materialDescription},
            #{item.examineCount},
            #{item.unit},
            #{item.projectDefinition},
            #{item.projectName},
            #{item.submittalsId}
            )
        </foreach>
    </insert>

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

    <!--物理删除-->
    <update id="deleteByIdList">
        DELETE
        FROM supply_judgement_bills
        WHERE id in
        <foreach collection="list" item="id" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
