<?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数据库持久层（业务层映射文件）：自动化用例设计同步表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-11-25 11:15:19  -->
<mapper namespace="net.northking.cctp.dw.db.dao.DwAtuCaseDesignDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.dw.dto.atu.DwAtuCaseDesignDetailDto">
      <!--  -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                            <!--  -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!--  -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!--  -->
    <result column="created_time" jdbcType="DATE" property="createdTime"/>
        <!--  -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!--  -->
    <result column="case_name" jdbcType="VARCHAR" property="caseName"/>
        <!--  -->
    <result column="case_no" jdbcType="VARCHAR" property="caseNo"/>
        <!--  -->
    <result column="case_type" jdbcType="INTEGER" property="caseType"/>
        <!--  -->
    <result column="is_delete" jdbcType="INTEGER" property="isDelete"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.dw.db.entity.DwAtuCaseDesign">
    select
    id
    ,tenant_id
    ,project_id
    ,created_time
    ,created_by
    ,case_name
    ,case_no
    ,case_type
    ,is_delete
    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="projectId != null">
        AND project_id = #{projectId,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=DATE}
      </if>
      <if test="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="caseName != null">
        AND case_name = #{caseName,jdbcType=VARCHAR}
      </if>
      <if test="caseNo != null">
        AND case_no = #{caseNo,jdbcType=VARCHAR}
      </if>
      <if test="caseType != null">
        AND case_type = #{caseType,jdbcType=INTEGER}
      </if>
      <if test="isDelete != null">
        AND is_delete = #{isDelete,jdbcType=INTEGER}
      </if>
    </trim>
  </select>

  <select id="countByGroup" resultType="net.northking.cctp.dw.dto.atu.DwAtuCaseDesignDetailDto">
    select
    count(case_type) mount,
    case_type `type`,
    created_by createdBy
    from
    <include refid="Table_Name"/>
    where
    project_id in
    <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
      #{projectId}
    </foreach>
    <if test="startTime!=null and endTime!=null">
      and
      created_time between date_format(#{startTime},"%Y-%m-%d") and date_format(#{endTime},"%Y-%m-%d")
    </if>
    and is_delete=0
    group by created_by,case_type
  </select>
</mapper>