<?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.zcloud.mapper.datasource.specheck.SpeCheckSourceMapper">
    <sql id="Field2">
        specheckSourceId,
        specheckTaskId,
        specheckRecordId,
        riskunitId,
        corpinfoId,
        creator,
        creatTime,
        operator,
        operatTime
    </sql>
    <sql id="FieldValue2">
        #{item.specheckSourceId},
        #{item.specheckTaskId},
        #{item.specheckRecordId},
        #{item.riskunitId},
        #{item.corpinfoId},
        #{item.creator},
        #{item.creatTime},
        #{item.operator},
        #{item.operatTime}
    </sql>

    <insert id="saveByBatch">
        INSERT INTO specheck_source (<include refid="Field2"></include>)
        values
        <foreach collection="list" item="item" separator=",">
            (
            <include refid="FieldValue2"></include>
            )
        </foreach>
        ON DUPLICATE KEY UPDATE specheckTaskId = specheckTaskId;
    </insert>
    <update id="updateBySpeSourceId">
        update specheck_source
        set specheckRecordId = #{specheckRecordId},
            EXAMINE = 1
        where specheckSourceId = #{specheckSourceId}
    </update>

    <select id="getDangerSourceList" resultType="com.zcloud.entity.PageData">
        select r.RISKUNIT_ID
        from bus_riskunit r
        where r.ISDELETE = '0'
          and r.CORPINFO_ID = #{corpinfoId}
          AND r.SOURCE_ID IS NOT NULL
          AND r.SOURCE_ID != ''
    </select>
    <select id="checkCanReport" resultType="java.lang.Integer">
        SELECT
            COUNT( 1 ) c
        FROM
            `specheck_source`
        WHERE
            examine = 0
          AND specheckTaskId = #{specheckTaskId}
        GROUP BY
            specheckTaskId
    </select>
</mapper>
