<?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.aucma.api.mapper.PdaBindingMapper">


    <select id="selectBoxNameByCode" resultType="string">
        select MATERIAL_NAME from AUCMA_MES.BASE_MATERIALINFO where MATERIAL_CODE = #{boxCode}
    </select>

    <insert id="insertBindingInfo">
        INSERT INTO AUCMA_SCADA.CODE_BINDING(OBJ_ID, BOX_CODE, BOX_NAME, LINER_CODE, BINDING_RESULT, RECORD_TIME1)
        VALUES (AUCMA_SCADA.SEQ_CODE_BINDING.nextval, #{boxCode}, #{boxName}, #{innerCode}, '成功', SYSDATE)
    </insert>
    <update id="updateCodeBinding">
        UPDATE AUCMA_SCADA.CODE_BINDING
        SET PRODUCT_CODE   = #{innerCode}, BINDING_RESULT = '成功',RECORD_TIME2   = SYSDATE,IS_PASS= 1
        where BOX_CODE = #{boxCode}
    </update>


    <select id="countQualityRecordByCode" resultType="int">
        select count(OBJ_ID)
        from AUCMA_MES.REPORT_QUALITY_INSPECTION
        where BAR_CODE = #{code} and IS_FLAG !=1
    </select>
    <update id="submitRepair" parameterType="com.aucma.api.domain.dto.RepairSubmitInfoDto">
        UPDATE AUCMA_MES.REPORT_QUALITY_INSPECTION
        SET PROCESS_RESULT = #{info.repairName},
            REWORK_NUMBER  = 1,
            FINISH_TIME    = sysdate,
            IS_FLAG        = #{info.isFlag},
            UPDATED_BY     = #{info.loginName},
            UPDATED_TIME   = sysdate
        WHERE OBJ_ID in
        <foreach item="objId" collection="info.list" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </update>

    <select id="findCheckInfoByCode" resultMap="com.aucma.report.mapper.ReportQualityInspectionMapper.ReportQualityInspectionResult">
        select OBJ_ID,
               MATERIAL_NAME,
               QUALITY_DEFECT_CODE,
               QUALITY_DEFECT_NAME
        from AUCMA_MES.REPORT_QUALITY_INSPECTION
        where BAR_CODE = #{code}
          and IS_FLAG is null
    </select>
    <select id="checkSelectRepairInfo" resultMap="com.aucma.report.mapper.ReportQualityInspectionMapper.ReportQualityInspectionResult">
        select OBJ_ID,
               MATERIAL_NAME,
               QUALITY_DEFECT_CODE,
               QUALITY_DEFECT_NAME
        from AUCMA_MES.REPORT_QUALITY_INSPECTION
        where BAR_CODE = #{code}
          and IS_FLAG = 1
    </select>

</mapper>