<?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-11-12 15:54:21  -->
<mapper namespace="net.northking.cctp.testbug.db.dao.BugOverallTendencyChartDao">


  <!-- 请在本文件内添加自定义SQL语句 -->

  <resultMap id="DetailMap" type="net.northking.cctp.testbug.dto.BugOverallTendencyChartDetailDto">
      <!--  -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                      <!-- 租户id -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!-- 创建时间 -->
    <result column="created_time" jdbcType="DATE" property="createdTime"/>
        <!-- 未解决 -->
    <result column="unsolved" jdbcType="INTEGER" property="unsolved"/>
        <!-- 已解决 -->
    <result column="solved" jdbcType="INTEGER" property="solved"/>
        <!-- 所有 -->
    <result column="all" jdbcType="INTEGER" property="all"/>
        <!-- 项目id -->
    <result column="pro_id" jdbcType="VARCHAR" property="proId"/>
        <!-- 记录类型 -->
    <result column="record_type" jdbcType="INTEGER" property="recordType"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.testbug.db.entity.BugOverallTendencyChart">
    select
    id
    ,tenant_id
    ,created_time
    ,unsolved
    ,solved
    ,all
    ,pro_id
    ,record_type
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=DATE}
      </if>
      <if test="unsolved != null">
        AND unsolved = #{unsolved,jdbcType=INTEGER}
      </if>
      <if test="solved != null">
        AND solved = #{solved,jdbcType=INTEGER}
      </if>
      <if test="all != null">
        AND all = #{all,jdbcType=INTEGER}
      </if>
      <if test="proId != null">
        AND pro_id=#{proId,jdbcType=VARCHAR}
      </if>
      <if test="recordType != null">
        AND record_type=#{recordType,jdbcType=INTEGER}
      </if>
    </trim>
  </select>

  <select id="selectGroupByTime"  resultType="net.northking.cctp.testbug.dto.BugOverallTendencyChartDetailDto">
    select
    created_time
    ,sum(unsolved) unsolved
    ,sum(solved) solved
    ,sum(`all`) allAmount
    from
    <include refid="Table_Name"/>
    group by created_time
  </select>

</mapper>