<?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.fizz.business.mapper.PdiSetupMapper">

    <!--
      说明：本 Mapper XML 统一以 MyBatis-Plus 实体 com.fizz.business.domain.PdiSetups 为准。
      旧版 PdiSetup(大写字段/TYPE/TM_*/TL_*) 已与当前实体不一致，继续保留会导致插入/查询字段缺失。
    -->

    <resultMap id="PdiSetupsResult" type="com.fizz.business.domain.PdiSetups">
        <id     property="id"                        column="id" />
        <result property="coilid"                    column="coilid" />
        <result property="planid"                    column="planid" />
        <result property="steelGrade"                column="steel_grade" />
        <result property="thick"                     column="thick" />
        <result property="yieldStren"                column="yield_stren" />

        <result property="porTension"                column="por_tension" />
        <result property="celTension"                column="cel_tension" />
        <result property="cleanTension"              column="clean_tension" />
        <result property="passivationTension"        column="passivation_tension" />
        <result property="cxlTension"                column="cxl_tension" />
        <result property="trTension"                 column="tr_tension" />
        <result property="levelerEntryTension"       column="leveler_entry_tension" />
        <result property="levelerExitTension"        column="leveler_exit_tension" />
        <result property="straightenerExitTension"   column="straightener_exit_tension" />
        <result property="furTension"                column="fur_tension" />
        <result property="towerTension"              column="tower_tension" />

        <result property="createTime"                column="create_time" />
        <result property="updateTime"                column="update_time" />
    </resultMap>

    <sql id="Base_Column_List">
        id,
        coilid,
        planid,
        steel_grade,
        thick,
        yield_stren,
        por_tension,
        cel_tension,
        clean_tension,
        passivation_tension,
        cxl_tension,
        tr_tension,
        leveler_entry_tension,
        leveler_exit_tension,
        straightener_exit_tension,
        fur_tension,
        tower_tension,
        create_time,
        update_time
    </sql>

    <!-- 列表查询：支持按 coilid/planid/steelGrade/thick/yieldStren 过滤，按更新时间倒序 -->
    <select id="selectPdiSetupList" parameterType="com.fizz.business.domain.PdiSetups" resultMap="PdiSetupsResult">
        select
        <include refid="Base_Column_List"/>
        from pdi_setup
        <where>
            <if test="coilid != null and coilid != ''"> and coilid = #{coilid}</if>
            <if test="planid != null and planid != ''"> and planid = #{planid}</if>
            <if test="steelGrade != null and steelGrade != ''"> and steel_grade = #{steelGrade}</if>
            <if test="thick != null"> and thick = #{thick}</if>
            <if test="yieldStren != null"> and yield_stren = #{yieldStren}</if>
        </where>
        order by update_time desc
    </select>

    <select id="selectPdiSetupById" parameterType="java.lang.Long" resultMap="PdiSetupsResult">
        select
        <include refid="Base_Column_List"/>
        from pdi_setup
        where id = #{id}
    </select>

    <!--
      说明：insert/update 这里保留是为了兼容旧代码可能直接调用 XML 的 SQL。
      如果你们完全使用 MyBatis-Plus 的 BaseMapper/save/updateById，也可以后续删除这些 SQL。
    -->
    <insert id="insertPdiSetup" parameterType="com.fizz.business.domain.PdiSetups" useGeneratedKeys="true" keyProperty="id">
        insert into pdi_setup
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="coilid != null and coilid != ''">coilid,</if>
            <if test="planid != null and planid != ''">planid,</if>
            <if test="steelGrade != null and steelGrade != ''">steel_grade,</if>
            <if test="thick != null">thick,</if>
            <if test="yieldStren != null">yield_stren,</if>

            <if test="porTension != null">por_tension,</if>
            <if test="celTension != null">cel_tension,</if>
            <if test="cleanTension != null">clean_tension,</if>
            <if test="passivationTension != null">passivation_tension,</if>
            <if test="cxlTension != null">cxl_tension,</if>
            <if test="trTension != null">tr_tension,</if>
            <if test="levelerEntryTension != null">leveler_entry_tension,</if>
            <if test="levelerExitTension != null">leveler_exit_tension,</if>
            <if test="straightenerExitTension != null">straightener_exit_tension,</if>
            <if test="furTension != null">fur_tension,</if>
            <if test="towerTension != null">tower_tension,</if>

            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="coilid != null and coilid != ''">#{coilid},</if>
            <if test="planid != null and planid != ''">#{planid},</if>
            <if test="steelGrade != null and steelGrade != ''">#{steelGrade},</if>
            <if test="thick != null">#{thick},</if>
            <if test="yieldStren != null">#{yieldStren},</if>

            <if test="porTension != null">#{porTension},</if>
            <if test="celTension != null">#{celTension},</if>
            <if test="cleanTension != null">#{cleanTension},</if>
            <if test="passivationTension != null">#{passivationTension},</if>
            <if test="cxlTension != null">#{cxlTension},</if>
            <if test="trTension != null">#{trTension},</if>
            <if test="levelerEntryTension != null">#{levelerEntryTension},</if>
            <if test="levelerExitTension != null">#{levelerExitTension},</if>
            <if test="straightenerExitTension != null">#{straightenerExitTension},</if>
            <if test="furTension != null">#{furTension},</if>
            <if test="towerTension != null">#{towerTension},</if>

            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updatePdiSetup" parameterType="com.fizz.business.domain.PdiSetups">
        update pdi_setup
        <trim prefix="SET" suffixOverrides=",">
            <if test="coilid != null and coilid != ''">coilid = #{coilid},</if>
            <if test="planid != null and planid != ''">planid = #{planid},</if>
            <if test="steelGrade != null and steelGrade != ''">steel_grade = #{steelGrade},</if>
            <if test="thick != null">thick = #{thick},</if>
            <if test="yieldStren != null">yield_stren = #{yieldStren},</if>

            <if test="porTension != null">por_tension = #{porTension},</if>
            <if test="celTension != null">cel_tension = #{celTension},</if>
            <if test="cleanTension != null">clean_tension = #{cleanTension},</if>
            <if test="passivationTension != null">passivation_tension = #{passivationTension},</if>
            <if test="cxlTension != null">cxl_tension = #{cxlTension},</if>
            <if test="trTension != null">tr_tension = #{trTension},</if>
            <if test="levelerEntryTension != null">leveler_entry_tension = #{levelerEntryTension},</if>
            <if test="levelerExitTension != null">leveler_exit_tension = #{levelerExitTension},</if>
            <if test="straightenerExitTension != null">straightener_exit_tension = #{straightenerExitTension},</if>
            <if test="furTension != null">fur_tension = #{furTension},</if>
            <if test="towerTension != null">tower_tension = #{towerTension},</if>

            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdiSetupById" parameterType="java.lang.Long">
        delete from pdi_setup where id = #{id}
    </delete>

    <delete id="deletePdiSetupByIds" parameterType="long">
        delete from pdi_setup where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
