<?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="org.springblade.zhaocai.mapper.ProcurementPlanMaterialMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="procurementPlanMaterialResultMap" type="org.springblade.zhaocai.pojo.entity.ProcurementPlanMaterial">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="plan_id" property="planId"/>
        <result column="project_id" property="projectId"/>
        <result column="sort_no" property="sortNo"/>
        <result column="material_name" property="materialName"/>
        <result column="material_code" property="materialCode"/>
        <result column="specification" property="specification"/>
        <result column="brand" property="brand"/>
        <result column="unit" property="unit"/>
        <result column="reference_price" property="referencePrice"/>
        <result column="quantity" property="quantity"/>
        <result column="estimated_amount" property="estimatedAmount"/>
        <result column="contact_person" property="contactPerson"/>
        <result column="contact_person_id" property="contactPersonId"/>
        <result column="apply_date" property="applyDate"/>
        <result column="expect_date" property="expectDate"/>
        <result column="last_year_total" property="lastYearTotal"/>
        <result column="last_year_avg_price" property="lastYearAvgPrice"/>
        <result column="last_year_total_amount" property="lastYearTotalAmount"/>
        <result column="requirement_intro" property="requirementIntro"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="baseColumnList">
        select
        id, tenant_id, create_user, create_time, update_user, update_time, status, is_deleted,
        plan_id, project_id, sort_no, material_name, material_code, specification, brand, unit,
        reference_price, quantity, estimated_amount, contact_person, contact_person_id, apply_date,
        expect_date, last_year_total, last_year_avg_price, last_year_total_amount, requirement_intro, remark
    </sql>

    <select id="selectByProjectId" resultMap="procurementPlanMaterialResultMap">
        <include refid="baseColumnList"/>
        from zc_procurement_plan_material
        where project_id = #{projectId}
        and is_deleted = 0
        order by sort_no asc
    </select>

    <delete id="deleteByPlanId">
        delete from zc_procurement_plan_material where plan_id = #{planId}
    </delete>

</mapper>
