<?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.ruoyi.nanjing.mapper.TBdSubstationMapper">

    <resultMap type="TBdSubstation" id="TBdSubstationResult">
        <result property="ID"    column="ID"    />
        <result property="StationID"    column="StationID"    />
        <result property="StationCode"    column="StationCode"    />
        <result property="StationType"    column="StationType"    />
        <result property="MachineID"    column="MachineID"    />
        <result property="UniteID"    column="UniteID"    />
        <result property="CustomerCode"    column="CustomerCode"    />
        <result property="StationName"    column="StationName"    />
        <result property="ParentStationID"    column="ParentStationID"    />
        <result property="ParentStationCode"    column="ParentStationCode"    />
        <result property="ParentStationName"    column="ParentStationName"    />
        <result property="PreStationID"    column="PreStationID"    />
        <result property="PreStationCode"    column="PreStationCode"    />
        <result property="Reamark"    column="Reamark"    />
        <result property="UserID"    column="UserID"    />
        <result property="UpdateTime"    column="UpdateTime"    />
        <result property="TableName"    column="TableName"    />
        <result property="IsSemi"    column="IsSemi"    />
        <result property="IsNGStation"    column="IsNGStation"    />
        <result property="HaveData"    column="HaveData"    />
        <result property="IsShow"    column="IsShow"    />
        <result property="UseFlag"    column="UseFlag"    />
        <result property="paraCount"    column="paraCount"    />
        <result property="OrderID"    column="OrderID"    />
        <result property="LimitID"    column="LimitID"    />
        <result property="ImageUrl"    column="ImageUrl"    />
        <result property="LineID"    column="LineID"    />
        <association property="stationtype" column="StationName" javaType="com.ruoyi.nanjing.domain.TBdStationtype" resultMap="stationtp"/>
        <association property="linetype" column="LineTypeName" javaType="com.ruoyi.nanjing.domain.TBdLinetype" resultMap="lineName"/>
    </resultMap>

    <resultMap id="lineName" type="com.ruoyi.nanjing.domain.TBdLinetype">
        <result property="LineID"    column="LineID"    />
        <result property="LineTypeName"    column="LineTypeName"    />
    </resultMap>

    <resultMap id="stationtp" type="com.ruoyi.nanjing.domain.TBdStationtype">
        <result property="ID"    column="ID"    />
        <result property="typeName"    column="Type_Name"    />
    </resultMap>

    <sql id="selectTBdSubstationVo">
        select t1.ID,t1.StationID, t1.StationCode, t1.StationType, t1.MachineID, t1.UniteID,
        t1.CustomerCode, t1.StationName, t1.ParentStationID, t1.ParentStationCode, t1.ParentStationName,
        t1.PreStationID, t1.PreStationCode, t1.Reamark, t1.UserID, t1.UpdateTime, t1.TableName, t1.IsSemi,
        t1.IsNGStation, t1.HaveData, t1.IsShow, t1.UseFlag, t1.paraCount, t1.OrderID,t1.LimitID, t1.ImageUrl, t1.LineID,
        t2.LineTypeName,t3.Type_Name from T_BD_SubStation t1
        left join T_BD_LineType t2 on t1.LineID = t2.LineID
        left join T_BD_StationType t3 on t1.StationType = t3.ID
    </sql>

    <select id="selectStationcode" resultMap="TBdSubstationResult">
        select top 1 * from T_BD_SubStation order by StationID desc
    </select>

    <select id="selectOrderid" resultMap="TBdSubstationResult">
        select top 1 * from T_BD_SubStation order by OrderID desc
    </select>

    <select id="createTable" parameterType="map" statementType="CALLABLE" resultType="string">
        {
            call SP_SY_CreatStationTableByStationCode(
                #{tableName,mode=IN,jdbcType=VARCHAR},
                #{ParaAmount,mode=IN,jdbcType=BIGINT}
            )
        }
    </select>

    <select id="updateTable" parameterType="map" statementType="CALLABLE" resultMap="TBdSubstationResult">
        {
            call SP_Pro_UpdateParaTable(
                #{paraCount,mode=IN,jdbcType=INTEGER},
                #{tableName,mode=IN,jdbcType=VARCHAR},
                #{stationID,mode=IN,jdbcType=INTEGER}
            )
        }
    </select>

    <select id="deletePara" parameterType="map" statementType="CALLABLE" resultMap="TBdSubstationResult">
        {
            call SP_Pro_DeleteStationPara(
                #{stationID,mode=IN,jdbcType=INTEGER}
            )
        }
    </select>
    <select id="selectTBdSubstationList" parameterType="TBdSubstation" resultMap="TBdSubstationResult">
        <include refid="selectTBdSubstationVo"/>
        <where>
            <if test="StationID != null "> and t1.StationID = #{StationID}</if>
            <if test="StationCode != null  and StationCode != ''"> and t1.StationCode = #{StationCode}</if>
            <if test="StationType != null "> and t1.StationType = #{StationType}</if>
            <if test="MachineID != null  and MachineID != ''"> and t1.MachineID = #{MachineID}</if>
            <if test="UniteID != null "> and t1.UniteID = #{UniteID}</if>
            <if test="CustomerCode != null  and CustomerCode != ''"> and t1.CustomerCode = #{CustomerCode}</if>
            <if test="StationName != null "> and t1.StationName like ('%' + #{StationName} + '%')</if>
            <if test="ParentStationID != null  and ParentStationID != ''"> and t1.ParentStationID = #{ParentStationID}</if>
            <if test="ParentStationCode != null  and ParentStationCode != ''"> and t1.ParentStationCode = #{ParentStationCode}</if>
            <if test="ParentStationName != null "> and t1.ParentStationName like ('%' + #{ParentStationName} + '%')</if>
            <if test="PreStationID != null  and PreStationID != ''"> and t1.PreStationID = #{PreStationID}</if>
            <if test="PreStationCode != null  and PreStationCode != ''"> and t1.PreStationCode = #{PreStationCode}</if>
            <if test="Reamark != null "> and t1.Reamark = #{Reamark}</if>
            <if test="UserID != null  and UserID != ''"> and t1.UserID = #{UserID}</if>
            <if test="UpdateTime != null "> and t1.UpdateTime = #{UpdateTime}</if>
            <if test="TableName != null "> and t1.TableName like ('%' + #{TableName} + '%')</if>
            <if test="IsSemi != null  and IsSemi != ''"> and t1.IsSemi = #{IsSemi}</if>
            <if test="IsNGStation != null  and IsNGStation != ''"> and t1.IsNGStation = #{IsNGStation}</if>
            <if test="HaveData != null  and HaveData != ''"> and t1.HaveData = #{HaveData}</if>
            <if test="IsShow != null  and IsShow != ''"> and t1.IsShow = #{IsShow}</if>
            <if test="UseFlag != null  and UseFlag != ''"> and t1.UseFlag = #{UseFlag}</if>
            <if test="paraCount != null "> and t1.paraCount = #{paraCount}</if>
            <if test="OrderID != null "> and t1.OrderID = #{OrderID}</if>
            <if test="LimitID != null  and LimitID != ''"> and t1.LimitID = #{LimitID}</if>
            <if test="ImageUrl != null "> and t1.ImageUrl = #{ImageUrl}</if>
            <if test="LineID != null "> and t1.LineID = #{LineID}</if>
        </where>
    </select>

    <select id="selectTBdSubstationById" parameterType="Long" resultMap="TBdSubstationResult">
        <include refid="selectTBdSubstationVo"/>
        where t1.ID = #{ID}
    </select>

    <insert id="insertTBdSubstation" parameterType="TBdSubstation">
        insert into T_BD_SubStation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ID != null">ID,</if>
            <if test="StationID != null">StationID,</if>
            <if test="StationCode != null">StationCode,</if>
            <if test="StationType != null">StationType,</if>
            <if test="MachineID != null">MachineID,</if>
            <if test="UniteID != null">UniteID,</if>
            <if test="CustomerCode != null">CustomerCode,</if>
            <if test="StationName != null">StationName,</if>
            <if test="ParentStationID != null">ParentStationID,</if>
            <if test="ParentStationCode != null">ParentStationCode,</if>
            <if test="ParentStationName != null">ParentStationName,</if>
            <if test="PreStationID != null">PreStationID,</if>
            <if test="PreStationCode != null">PreStationCode,</if>
            <if test="Reamark != null">Reamark,</if>
            <if test="UserID != null">UserID,</if>
            <if test="UpdateTime != null">UpdateTime,</if>
            <if test="TableName != null">TableName,</if>
            <if test="IsSemi != null">IsSemi,</if>
            <if test="IsNGStation != null">IsNGStation,</if>
            <if test="HaveData != null">HaveData,</if>
            <if test="IsShow != null">IsShow,</if>
            <if test="UseFlag != null">UseFlag,</if>
            <if test="paraCount != null">paraCount,</if>
            <if test="OrderID != null">OrderID,</if>
            <if test="LimitID != null">LimitID,</if>
            <if test="ImageUrl != null">ImageUrl,</if>
            <if test="LineID != null">LineID,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ID != null">#{ID},</if>
            <if test="StationID != null">#{StationID},</if>
            <if test="StationCode != null">#{StationCode},</if>
            <if test="StationType != null">#{StationType},</if>
            <if test="MachineID != null">#{MachineID},</if>
            <if test="UniteID != null">#{UniteID},</if>
            <if test="CustomerCode != null">#{CustomerCode},</if>
            <if test="StationName != null">#{StationName},</if>
            <if test="ParentStationID != null">#{ParentStationID},</if>
            <if test="ParentStationCode != null">#{ParentStationCode},</if>
            <if test="ParentStationName != null">#{ParentStationName},</if>
            <if test="PreStationID != null">#{PreStationID},</if>
            <if test="PreStationCode != null">#{PreStationCode},</if>
            <if test="Reamark != null">#{Reamark},</if>
            <if test="UserID != null">#{UserID},</if>
            <if test="UpdateTime != null">#{UpdateTime},</if>
            <if test="TableName != null">#{TableName},</if>
            <if test="IsSemi != null">#{IsSemi},</if>
            <if test="IsNGStation != null">#{IsNGStation},</if>
            <if test="HaveData != null">#{HaveData},</if>
            <if test="IsShow != null">#{IsShow},</if>
            <if test="UseFlag != null">#{UseFlag},</if>
            <if test="paraCount != null">#{paraCount},</if>
            <if test="OrderID != null">#{OrderID},</if>
            <if test="LimitID != null">#{LimitID},</if>
            <if test="ImageUrl != null">#{ImageUrl},</if>
            <if test="LineID != null">#{LineID},</if>
         </trim>
    </insert>

    <update id="updateTBdSubstation" parameterType="TBdSubstation">
        update T_BD_SubStation
        <trim prefix="SET" suffixOverrides=",">
            <if test="StationID != null">StationID = #{StationID},</if>
            <if test="StationCode != null">StationCode = #{StationCode},</if>
            <if test="StationType != null">StationType = #{StationType},</if>
            <if test="MachineID != null">MachineID = #{MachineID},</if>
            <if test="UniteID != null">UniteID = #{UniteID},</if>
            <if test="CustomerCode != null">CustomerCode = #{CustomerCode},</if>
            <if test="StationName != null">StationName = #{StationName},</if>
            <if test="ParentStationID != null">ParentStationID = #{ParentStationID},</if>
            <if test="ParentStationCode != null">ParentStationCode = #{ParentStationCode},</if>
            <if test="ParentStationName != null">ParentStationName = #{ParentStationName},</if>
            <if test="PreStationID != null">PreStationID = #{PreStationID},</if>
            <if test="PreStationCode != null">PreStationCode = #{PreStationCode},</if>
            <if test="Reamark != null">Reamark = #{Reamark},</if>
            <if test="UserID != null">UserID = #{UserID},</if>
            <if test="UpdateTime != null">UpdateTime = #{UpdateTime},</if>
            <if test="TableName != null">TableName = #{TableName},</if>
            <if test="IsSemi != null">IsSemi = #{IsSemi},</if>
            <if test="IsNGStation != null">IsNGStation = #{IsNGStation},</if>
            <if test="HaveData != null">HaveData = #{HaveData},</if>
            <if test="IsShow != null">IsShow = #{IsShow},</if>
            <if test="UseFlag != null">UseFlag = #{UseFlag},</if>
            <if test="paraCount != null">paraCount = #{paraCount},</if>
            <if test="OrderID != null">OrderID = #{OrderID},</if>
            <if test="LimitID != null">LimitID = #{LimitID},</if>
            <if test="ImageUrl != null">ImageUrl = #{ImageUrl},</if>
            <if test="LineID != null">LineID = #{LineID},</if>
        </trim>
        where ID = #{ID}
    </update>

    <delete id="deleteTBdSubstationById" parameterType="Long">
        delete from T_BD_SubStation where ID = #{ID}
    </delete>

    <delete id="deleteTBdSubstationByIds" parameterType="String">
        delete from T_BD_SubStation where ID in
        <foreach item="ID" collection="array" open="(" separator="," close=")">
            #{ID}
        </foreach>
    </delete>

</mapper>
