<?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">
<mapper namespace="com.lightinit.hsdataplatform.mapper.ResourceApiMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.ResourceApi">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="provider" jdbcType="BIGINT" property="provider" />
    <result column="service_type" jdbcType="VARCHAR" property="serviceType" />
    <result column="service_tag" jdbcType="VARCHAR" property="serviceTag" />
    <result column="component" jdbcType="VARCHAR" property="component" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="BIGINT" property="deletedBy" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.lightinit.hsdataplatform.entity.ResourceApi">
    <result column="return_code" jdbcType="LONGVARCHAR" property="returnCode" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, provider, service_type, service_tag, component, created_at, created_by, deleted_at, 
    deleted_by
  </sql>
  <sql id="Blob_Column_List">
    return_code
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceApiExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from resource_api
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceApiExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from resource_api
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from resource_api
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from resource_api
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceApiExample">
    delete from resource_api
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.ResourceApi">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_api (id,provider, service_type, service_tag,
      component, created_at, created_by, 
      deleted_at, deleted_by, return_code
      )
    values (#{id},#{provider,jdbcType=BIGINT}, #{serviceType,jdbcType=VARCHAR}, #{serviceTag,jdbcType=VARCHAR},
      #{component,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, #{returnCode,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceApi">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_api
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="provider != null">
        provider,
      </if>
      <if test="serviceType != null">
        service_type,
      </if>
      <if test="serviceTag != null">
        service_tag,
      </if>
      <if test="component != null">
        component,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="deletedAt != null">
        deleted_at,
      </if>
      <if test="deletedBy != null">
        deleted_by,
      </if>
      <if test="returnCode != null">
        return_code,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="provider != null">
        #{provider,jdbcType=BIGINT},
      </if>
      <if test="serviceType != null">
        #{serviceType,jdbcType=VARCHAR},
      </if>
      <if test="serviceTag != null">
        #{serviceTag,jdbcType=VARCHAR},
      </if>
      <if test="component != null">
        #{component,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="returnCode != null">
        #{returnCode,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceApiExample" resultType="java.lang.Long">
    select count(*) from resource_api
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update resource_api
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.provider != null">
        provider = #{record.provider,jdbcType=BIGINT},
      </if>
      <if test="record.serviceType != null">
        service_type = #{record.serviceType,jdbcType=VARCHAR},
      </if>
      <if test="record.serviceTag != null">
        service_tag = #{record.serviceTag,jdbcType=VARCHAR},
      </if>
      <if test="record.component != null">
        component = #{record.component,jdbcType=VARCHAR},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=BIGINT},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      </if>
      <if test="record.returnCode != null">
        return_code = #{record.returnCode,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update resource_api
    set id = #{record.id,jdbcType=BIGINT},
      provider = #{record.provider,jdbcType=BIGINT},
      service_type = #{record.serviceType,jdbcType=VARCHAR},
      service_tag = #{record.serviceTag,jdbcType=VARCHAR},
      component = #{record.component,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      return_code = #{record.returnCode,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update resource_api
    set id = #{record.id,jdbcType=BIGINT},
      provider = #{record.provider,jdbcType=BIGINT},
      service_type = #{record.serviceType,jdbcType=VARCHAR},
      service_tag = #{record.serviceTag,jdbcType=VARCHAR},
      component = #{record.component,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceApi">
    update resource_api
    <set>
      <if test="provider != null">
        provider = #{provider,jdbcType=BIGINT},
      </if>
      <if test="serviceType != null">
        service_type = #{serviceType,jdbcType=VARCHAR},
      </if>
      <if test="serviceTag != null">
        service_tag = #{serviceTag,jdbcType=VARCHAR},
      </if>
      <if test="component != null">
        component = #{component,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="returnCode != null">
        return_code = #{returnCode,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceApi">
    update resource_api
    set provider = #{provider,jdbcType=BIGINT},
      service_type = #{serviceType,jdbcType=VARCHAR},
      service_tag = #{serviceTag,jdbcType=VARCHAR},
      component = #{component,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      return_code = #{returnCode,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.ResourceApi">
    update resource_api
    set provider = #{provider,jdbcType=BIGINT},
      service_type = #{serviceType,jdbcType=VARCHAR},
      service_tag = #{serviceTag,jdbcType=VARCHAR},
      component = #{component,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="queryRegisterApiAllList" parameterType="com.lightinit.hsdataplatform.model.admin.ResourceAPIRegisterSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceAPIRegisterListModel">
    <if test="resourceName != null and resourceName.length() > 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>
    <if test="providerName != null and providerName.length() > 0">
      <bind name="providerName" value="'%' + _parameter.providerName + '%'" />
    </if>
    SELECT r.id,r.`catelog_type`,r.`resource_name`,r.`resource_identity`,r.out_id_1 outId1,
    r.`resource_summary`,s.`sector_name` providerName,r.`register_date`,r.`resource_state`
    FROM resource r
    JOIN resource_api ra ON r.id = ra.id
    LEFT JOIN sector s ON ra.provider = s.id
    left JOIN admin a ON a.id = r.created_by
    <where>
      <if test="providerName != null and providerName.length() > 0">
        s.sector_name like #{providerName}
      </if>
      <if test="resourceName != null and resourceName.length() > 0">
        AND r.resource_name like #{resourceName}
      </if>
      <if test="registerAPIFrom != null">
        AND r.register_date &gt;= #{registerAPIFrom}
      </if>
      <if test="registerAPITo != null">
        AND r.register_date &lt; #{registerAPITo}
      </if>
      <if test="resourceState != null and resourceState.length() > 0">
        AND r.resource_state = #{resourceState}
      </if>
      <if test="orgId != null ">
        AND a.org_id = #{orgId}
      </if>
    </where>
    ORDER BY r.id DESC
    <if test="page != null" >
      LIMIT #{page.beginIndex},#{page.pageSize}
    </if>
  </select>
  <select id="queryRegisterApiCount" parameterType="com.lightinit.hsdataplatform.model.admin.ResourceAPIRegisterSearchModel" resultType="java.lang.Long">
    <if test="resourceName != null and resourceName.length() > 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>
    <if test="providerName != null and providerName.length() > 0">
      <bind name="providerName" value="'%' + _parameter.providerName + '%'" />
    </if>
    SELECT count(*)
    FROM resource r
    JOIN resource_api ra ON r.id = ra.id
    LEFT JOIN sector s ON ra.provider = s.id
    left JOIN admin a ON a.id = r.created_by
    <where>
      <if test="providerName != null and providerName.length() > 0">
        s.sector_name LIKE #{providerName}
      </if>
      <if test="resourceName != null and resourceName.length() > 0">
        AND r.resource_name like #{resourceName}
      </if>
      <if test="registerAPIFrom != null">
        AND r.register_date &gt;= #{registerAPIFrom}
      </if>
      <if test="registerAPITo != null">
        AND r.register_date &lt; #{registerAPITo}
      </if>
      <if test="resourceState != null and resourceState.length() > 0">
        AND r.resource_state = #{resourceState}
      </if>
      <if test="orgId != null ">
        AND a.org_id = #{orgId}
      </if>
    </where>
  </select>
</mapper>