<?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:20  -->
<mapper namespace="net.northking.cctp.dw.db.dao.DwReBusComponentDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.dw.dto.atu.DwReBusComponentDetailDto">
      <!--  -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                          <!--  -->
    <result column="com_name" jdbcType="VARCHAR" property="comName"/>
        <!--  -->
    <result column="com_type" jdbcType="INTEGER" property="comType"/>
        <!--  -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!--  -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!--  -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!--  -->
    <result column="created_time" jdbcType="DATE" property="createdTime"/>
        <!--  -->
    <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.dw.db.entity.DwReBusComponent">
    select
    id
    ,com_name
    ,com_type
    ,tenant_id
    ,project_id
    ,created_by
    ,created_time
    ,is_deleted
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="comName != null">
        AND com_name = #{comName,jdbcType=VARCHAR}
      </if>
      <if test="comType != null">
        AND com_type = #{comType,jdbcType=INTEGER}
      </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="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=DATE}
      </if>
      <if test="isDeleted != null">
        AND is_deleted = #{isDeleted,jdbcType=INTEGER}
      </if>
    </trim>
  </select>

  <select id="countByGroup" resultType="net.northking.cctp.dw.dto.atu.DwReBusComponentDetailDto">
    select
    count(com_type) mount,
    com_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_deleted=0
    group by created_by,com_type
  </select>
    <select id="getComponentNum" resultType="java.lang.Integer">
      select count(*)
      from
      <include refid="Table_Name"/>
      where is_deleted=0
      <if test="projectId!=null and projectId!=''">
        and project_id = #{projectId}
      </if>
      <if test="userId!=null and userId!=''">
        and principal_id = #{userId}
      </if>
      <if test="queryToday==1">
        <if test="todayStart!=null">
          and created_time <![CDATA[>=]]> #{todayStart}
        </if>
        <if test="todayEnd!=null">
          and created_time <![CDATA[<=]]> #{todayEnd}
        </if>
      </if>
    </select>
</mapper>