<?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-14 15:12:07  -->
<mapper namespace="net.northking.cctp.dw.db.dao.PointCompleteDetailsDao">

    <update id="testPointComplete" >
        INSERT INTO cctp_dw.point_complete_details ( id, receiver_name, login_no, news, usering, date_type, tenant_id,
        project_id ) SELECT
        temp.id,
        temp.receiverName,
        temp.receiverName,
        temp.news,
        temp.usering,
        temp.dateType,
        temp.tenantId,
        temp.projectId
        FROM
        (
        SELECT
        UUID_SHORT() AS id,
        a.tenant_id tenantId,
        a.created_by AS receiverName,
        cast((SUM( CASE a.point_STATUS WHEN 0 THEN 1 ELSE 0 END )+0) as signed)  AS news,
        cast((SUM( CASE a.point_STATUS WHEN 1 THEN 1 ELSE 0 END )+0) as signed)  AS usering,
        0 AS dateType,
        a.project_id projectId
        FROM
        dw_test_point a
        WHERE
        date( a.created_time ) = CURDATE()
        and
        project_id in
        <foreach collection="dwTestPoint.projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
        and tenant_id = #{dwTestPoint.tenantId}
        GROUP BY
        a.created_by,
        a.project_id
        UNION ALL
        SELECT
        UUID_SHORT() AS id,
        a.tenant_id tenantId,
        a.created_by AS receiverName,
        cast((SUM( CASE a.point_STATUS WHEN 0 THEN 1 ELSE 0 END )+0) as signed)  AS news,
        cast((SUM( CASE a.point_STATUS WHEN 1 THEN 1 ELSE 0 END )+0) as signed)  AS usering,
        1 AS dateType,
        a.project_id projectId
        FROM
        dw_test_point a
        WHERE
        date( a.created_time ) BETWEEN date(#{lastSat})
        AND CURDATE()
        and
        project_id in
        <foreach collection="dwTestPoint.projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
        and tenant_id = #{dwTestPoint.tenantId}
        GROUP BY
        a.created_by,
        a.project_id
        UNION ALL
        SELECT
        UUID_SHORT() AS id,
        a.tenant_id tenantId,
        a.created_by AS receiverName,
        cast((SUM( CASE a.point_STATUS WHEN 0 THEN 1 ELSE 0 END )+0) as signed) AS news,
        cast((SUM( CASE a.point_STATUS WHEN 1 THEN 1 ELSE 0 END )+0) as signed) AS usering,
        2 AS dateType,
        a.project_id projectId
        FROM
        dw_test_point a
        WHERE
        project_id in
        <foreach collection="dwTestPoint.projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
        and tenant_id = #{dwTestPoint.tenantId}
        GROUP BY
        a.created_by,
        a.project_id
        ) temp
    </update>

    <delete id="deleteAllCompleteByProjectIds" parameterType="net.northking.cctp.dw.db.entity.PointCompleteDetails">
        DELETE FROM cctp_dw.point_complete_details WHERE project_id IN
        <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
    </delete>

</mapper>