<?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 2022 . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）：dw库测试点列表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-01-27 16:05:09  -->
<mapper namespace="net.northking.cctp.dw.db.dao.DwTestPointDao">


  <!-- 请在本文件内添加自定义SQL语句 -->
  <insert id="insertByBatchIgnore" parameterType="java.util.List">
    insert ignore into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      id,
      project_id,
      created_by,
      created_time,
      tenant_id,
      point_status,
      belong_module,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
        #{item.id, jdbcType=VARCHAR},
        #{item.projectId, jdbcType=VARCHAR},
        #{item.createdBy, jdbcType=VARCHAR},
        #{item.createdTime, jdbcType=TIMESTAMP},
        #{item.tenantId, jdbcType=VARCHAR},
        #{item.pointStatus, jdbcType=INTEGER},
        #{item.belongModule, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>

  <select id="findTestPointStatistics" resultType="net.northking.cctp.dw.dto.MtTestPointStatisticsDetailDto">
    select
    created_by as userName,
    count(1)as testPointCount
    FROM
    <include refid="Table_Name" />
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="proId != null">
        AND project_id = #{proId,jdbcType=VARCHAR}
      </if>
      <if test="startTime != null and endTime !=null and startTime != '' and endTime !=''">
        and DATE_FORMAT(created_time,'%Y-%m-%d') BETWEEN DATE_FORMAT( #{startTime},'%Y-%m-%d') AND DATE_FORMAT(#{endTime},'%Y-%m-%d')
      </if>
    </trim>
    GROUP BY created_by
  </select>
  <select id="findProIdList" resultType="net.northking.cctp.dw.db.entity.DwTestPoint">
    select
    tenant_id tenantId,
    project_id projectId
    from
    dw_test_point
    group by
    tenant_id,
    project_id
  </select>
</mapper>