<?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.TSyTracestateMapper">

    <resultMap type="TSyTracestate" id="TSyTracestateResult">
        <result property="barcode"    column="Barcode"    />
        <result property="productID"    column="ProductID"    />
        <result property="beginTime"    column="BeginTime"    />
        <result property="endTime"    column="EndTime"    />
        <result property="shiftID"    column="ShiftID"    />
        <result property="groupID"    column="GroupID"    />
        <result property="shiftNo"    column="ShiftNo"    />
        <result property="semibarcodeA"    column="SemiBarcode_A"    />
        <result property="semibarcodeB"    column="SemiBarcode_B"    />
        <result property="semibarcodeC"    column="SemiBarcode_C"    />
        <result property="productBarcode"    column="ProductBarcode"    />
        <result property="semiBarcode2"    column="SemiBarcode2"    />
        <result property="shellbarcode"    column="shellbarcode"    />
        <result property="nameplateInfo"    column="NameplateInfo"    />
        <result property="markRecord"    column="MarkRecord"    />
        <result property="attr1"    column="Attr1"    />
        <result property="attr2"    column="Attr2"    />
        <result property="isDis"    column="ISDis"    />
        <result property="disChecker"    column="DisChecker"    />
        <result property="disTime"    column="DisTime"    />
        <result property="state"    column="State"    />
        <result property="currentStationID"    column="CurrentStationID"    />
        <result property="nGStationID"    column="NGStationID"    />
        <result property="finishFlag"    column="FinishFlag"    />
        <result property="d9Remark"    column="D9Remark"    />
    </resultMap>

    <!--    <resultMap id="paraAll" type="com.ruoyi.nanjing.domain.ParaAllShow">-->
    <!--        <result property="barcode"    column="系统条码"    />-->
    <!--        <result property="productName"    column="机种类型"    />-->
    <!--        <result property="semiBarcode"    column="产品码"    />-->
    <!--        <result property="state"    column="合格状态"    />-->
    <!--        <result property="currentStation"    column="当前工位"    />-->
    <!--        <result property="NGStation"    column="NG工位"    />-->
    <!--        <result property="finishFlag"    column="完成状态"    />-->
    <!--        <result property="namePlateInfo"    column="标签Y/N"    />-->
    <!--        <result property="isDis"    column="返修Y/N"    />-->
    <!--        <result property="beginTime"    column="开始时间"    />-->
    <!--        <result property="endTime"    column="结束时间"    />-->
    <!--        <result property="proBarcode"    column="部件码"    />-->
    <!--        <result property="stationCode"    column="工位代码"    />-->
    <!--        <result property="insertTime"    column="记录时间"    />-->
    <!--        <result property="paraName"    column="参数名称"    />-->
    <!--        <result property="realVal"    column="实测值"    />-->
    <!--        <result property="minVal"    column="最小值"    />-->
    <!--        <result property="maxVal"    column="最大值"    />-->
    <!--        <result property="paraState"    column="参数状态"    />-->
    <!--    </resultMap>-->

    <resultMap type="java.util.HashMap" id="col2">
        <result property="semiBarcode"    column="产品码"    />
        <result property="proBarcode"    column="部件码"   />
        <result property="stationCode"    column="工位代码"   />
        <result property="insertTime"    column="记录时间"   />
        <result property="paraName"    column="参数名称"    />
        <result property="realVal"    column="实测值"    />
        <result property="minVal"    column="最小值"   />
        <result property="maxVal"    column="最大值"    />
        <result property="paraState"    column="参数状态" />
        <!--        <collection column="{semiCode=semiBarcode}" property="proRpList" ofType="com.ruoyi.nanjing.domain.ProRpList" select="getAttribute" >-->
        <!--        </collection>-->
    </resultMap>

    <resultMap type="java.util.HashMap" id="col1" >
        <result property="barcode"    column="系统条码"    />
        <result property="semiBarcode"    column="产品码"    />
        <result property="productName"    column="机种类型"  />
        <result property="isDis"    column="返修Y/N"   />
        <result property="state"    column="合格状态"   />
        <result property="finishFlag"    column="完成状态"    />
        <result property="currentStation"    column="当前工位"    />
        <result property="NGStation"    column="NG工位"    />
        <result property="namePlateInfo"    column="标签Y/N"    />
        <result property="beginTime"    column="开始时间"    />
        <result property="endTime"    column="结束时间"    />
    </resultMap>

    <sql id="selectTSyTracestateVo">
        select Barcode, ProductID, BeginTime, EndTime, ShiftID, GroupID, ShiftNo, SemiBarcode_A, SemiBarcode_B, SemiBarcode_C, ProductBarcode, SemiBarcode2, shellbarcode, NameplateInfo, MarkRecord, Attr1, Attr2, ISDis, DisChecker, DisTime, State, CurrentStationID, NGStationID, FinishFlag, D9Remark from T_SY_TraceState
    </sql>

    <select id="getInfo" resultMap="col1">
        select t1.Barcode as 系统条码,t5.ProductBarcode as 产品码,
        t2.ProductName as 机种类型,case t1.isDis when 1  then ' Y' else 'N' end  as '返修Y/N' ,
        case t1.State when 1  then  '合格' when 2 then '不合格' else '异常' end  as '合格状态',
        case t1.FinishFlag when 1  then  '完成' else '未完成' end  as 完成状态,t3.StationName as 当前工位,
        t4.StationName as NG工位,Machine as '标签Y/N',
        begintime as 开始时间,Endtime as  结束时间
        from T_SY_TraceState t1  left  join T_BD_ProductInfo t2  on t1.ProductID=t2.ProductID
        left join T_BD_SubStation t3  on t1.CurrentStationID=t3.StationID
        left join T_BD_SubStation t4  on t1.NGStationID=t4.StationID
        left join T_RP_BarcodeRelationShip t5 on t1.SemiBarcode_A = t5.SemiBarcode
        where t5.ProductBarcode=#{semiCode,jdbcType = VARCHAR}
    </select>
    <select id="selectTSyTracestateList" parameterType="TSyTracestate" resultMap="TSyTracestateResult">
        <include refid="selectTSyTracestateVo"/>
        <where>
        </where>
    </select>

    <select id="selectTSyTracestateById" parameterType="String" resultMap="TSyTracestateResult">
        <include refid="selectTSyTracestateVo"/>
        where Barcode = #{barcode}
    </select>


    <select id="selectAllPara" statementType="CALLABLE" parameterType="map" resultMap="col1,col2" >
        {
            call pro_AllParaShowInfo_Net
            (
                #{semiBarcode,mode=IN,jdbcType=VARCHAR},
                 #{beginTime,mode=IN,jdbcType=DATE},
                  #{endTime,mode=IN,jdbcType=DATE}
            )
        }
    </select>
    <select id="selectStationPara" statementType="CALLABLE" parameterType="map" resultType="java.util.LinkedHashMap" >
        {
            call pro_SelectSemiStationParaData
            (
             #{beginTime,mode=IN,jdbcType=DATE},
             #{endTime,mode=IN,jdbcType=DATE},
             #{Barcode,mode=IN,jdbcType=VARCHAR},
             #{SemiBarcode,mode=IN,jdbcType=VARCHAR},
             #{StationID,mode=IN,jdbcType=VARCHAR},
             #{StateID,mode=IN,jdbcType=VARCHAR}
            )
        }
    </select>

    <insert id="insertTSyTracestate" parameterType="TSyTracestate">
        insert into T_SY_TraceState
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="barcode != null">Barcode,</if>
            <if test="productID != null">ProductID,</if>
            <if test="beginTime != null">BeginTime,</if>
            <if test="endTime != null">EndTime,</if>
            <if test="shiftID != null">ShiftID,</if>
            <if test="groupID != null">GroupID,</if>
            <if test="shiftNo != null">ShiftNo,</if>
            <if test="semibarcodeA != null">SemiBarcode_A,</if>
            <if test="semibarcodeB != null">SemiBarcode_B,</if>
            <if test="semibarcodeC != null">SemiBarcode_C,</if>
            <if test="productBarcode != null">ProductBarcode,</if>
            <if test="semiBarcode2 != null">SemiBarcode2,</if>
            <if test="shellbarcode != null">shellbarcode,</if>
            <if test="nameplateInfo != null">NameplateInfo,</if>
            <if test="markRecord != null">MarkRecord,</if>
            <if test="attr1 != null">Attr1,</if>
            <if test="attr2 != null">Attr2,</if>
            <if test="isDis != null">ISDis,</if>
            <if test="disChecker != null">DisChecker,</if>
            <if test="disTime != null">DisTime,</if>
            <if test="state != null">State,</if>
            <if test="currentStationID != null">CurrentStationID,</if>
            <if test="nGStationID != null">NGStationID,</if>
            <if test="finishFlag != null">FinishFlag,</if>
            <if test="d9Remark != null">D9Remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="barcode != null">#{barcode},</if>
            <if test="productID != null">#{productID},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="shiftID != null">#{shiftID},</if>
            <if test="groupID != null">#{groupID},</if>
            <if test="shiftNo != null">#{shiftNo},</if>
            <if test="semibarcodeA != null">#{semibarcodeA},</if>
            <if test="semibarcodeB != null">#{semibarcodeB},</if>
            <if test="semibarcodeC != null">#{semibarcodeC},</if>
            <if test="productBarcode != null">#{productBarcode},</if>
            <if test="semiBarcode2 != null">#{semiBarcode2},</if>
            <if test="shellbarcode != null">#{shellbarcode},</if>
            <if test="nameplateInfo != null">#{nameplateInfo},</if>
            <if test="markRecord != null">#{markRecord},</if>
            <if test="attr1 != null">#{attr1},</if>
            <if test="attr2 != null">#{attr2},</if>
            <if test="isDis != null">#{isDis},</if>
            <if test="disChecker != null">#{disChecker},</if>
            <if test="disTime != null">#{disTime},</if>
            <if test="state != null">#{state},</if>
            <if test="currentStationID != null">#{currentStationID},</if>
            <if test="nGStationID != null">#{nGStationID},</if>
            <if test="finishFlag != null">#{finishFlag},</if>
            <if test="d9Remark != null">#{d9Remark},</if>
        </trim>
    </insert>

    <update id="updateTSyTracestate" parameterType="TSyTracestate">
        update T_SY_TraceState
        <trim prefix="SET" suffixOverrides=",">
            <if test="productID != null">ProductID = #{productID},</if>
            <if test="beginTime != null">BeginTime = #{beginTime},</if>
            <if test="endTime != null">EndTime = #{endTime},</if>
            <if test="shiftID != null">ShiftID = #{shiftID},</if>
            <if test="groupID != null">GroupID = #{groupID},</if>
            <if test="shiftNo != null">ShiftNo = #{shiftNo},</if>
            <if test="semibarcodeA != null">SemiBarcode_A = #{semibarcodeA},</if>
            <if test="semibarcodeB != null">SemiBarcode_B = #{semibarcodeB},</if>
            <if test="semibarcodeC != null">SemiBarcode_C = #{semibarcodeC},</if>
            <if test="productBarcode != null">ProductBarcode = #{productBarcode},</if>
            <if test="semiBarcode2 != null">SemiBarcode2 = #{semiBarcode2},</if>
            <if test="shellbarcode != null">shellbarcode = #{shellbarcode},</if>
            <if test="nameplateInfo != null">NameplateInfo = #{nameplateInfo},</if>
            <if test="markRecord != null">MarkRecord = #{markRecord},</if>
            <if test="attr1 != null">Attr1 = #{attr1},</if>
            <if test="attr2 != null">Attr2 = #{attr2},</if>
            <if test="isDis != null">ISDis = #{isDis},</if>
            <if test="disChecker != null">DisChecker = #{disChecker},</if>
            <if test="disTime != null">DisTime = #{disTime},</if>
            <if test="state != null">State = #{state},</if>
            <if test="currentStationID != null">CurrentStationID = #{currentStationID},</if>
            <if test="nGStationID != null">NGStationID = #{nGStationID},</if>
            <if test="finishFlag != null">FinishFlag = #{finishFlag},</if>
            <if test="d9Remark != null">D9Remark = #{d9Remark},</if>
        </trim>
        where Barcode = #{barcode}
    </update>

    <delete id="deleteTSyTracestateById" parameterType="String">
        delete from T_SY_TraceState where Barcode = #{barcode}
    </delete>

    <delete id="deleteTSyTracestateByIds" parameterType="String">
        delete from T_SY_TraceState where Barcode in
        <foreach item="barcode" collection="array" open="(" separator="," close=")">
            #{barcode}
        </foreach>
    </delete>

</mapper>
