<?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">
<!--  Copyright (c) 京北方信息技术股份有限公司 Corporation 2021 . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）：用户有效执行用例数中间表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2021-12-17 14:49:41  -->
<mapper namespace="net.northking.cctp.dw.db.dao.MidValidExecJobDao">

    <update id="validExecJob">
        INSERT INTO cctp_dw.mid_valid_exec_job ( created_by, valid_exec, project_id, tenant_id ) SELECT
        temp.createdBy,
        temp.validExec,
        temp.projectId,
        temp.tenantId
        FROM
        (
        SELECT
        updated_by createdBy,
        COUNT( 1 ) validExec,
        project_id projectId,
        tenant_id tenantId
        FROM
        cctp_dw.dw_manual_exec_job
        WHERE
        exec_status NOT IN ( '0', '1' )
        AND is_deleted = 0
        AND updated_by IS NOT NULL
        and tenant_id=#{tenantId}
        and project_id in
        <foreach collection="dataList" separator="," close=")" open="(" item="data">
            #{data.projectId}
        </foreach>
        GROUP BY
        updated_by,project_id
        ORDER BY
        NULL
        ) temp
    </update>
    <delete id="deleteByData">
        delete
        from mid_valid_exec_job
        where
        tenant_id=#{tenantId}
        and
        project_id in
        <foreach collection="dataList" separator="," close=")" open="(" item="data">
            #{data.projectId}
        </foreach>
    </delete>
</mapper>