<?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.ResourceMicroappMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.ResourceMicroapp">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="provider" jdbcType="BIGINT" property="provider" />
    <result column="service_method" jdbcType="VARCHAR" property="serviceMethod" />
    <result column="service_channel" jdbcType="VARCHAR" property="serviceChannel" />
    <result column="service_tag" jdbcType="VARCHAR" property="serviceTag" />
    <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.ResourceMicroappWithBLOBs">
    <result column="demo_url" jdbcType="LONGVARCHAR" property="demoUrl" />
    <result column="url" jdbcType="LONGVARCHAR" property="url" />
    <result column="screenshot" jdbcType="LONGVARCHAR" property="screenshot" />
  </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_method, service_channel, service_tag, created_at, created_by, 
    deleted_at, deleted_by
  </sql>
  <sql id="Blob_Column_List">
    demo_url, url, screenshot
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroappExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from resource_microapp
    <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.ResourceMicroappExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from resource_microapp
    <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_microapp
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from resource_microapp
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroappExample">
    delete from resource_microapp
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroappWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_microapp (id, provider, service_method, service_channel,
      service_tag, created_at, created_by, 
      deleted_at, deleted_by, demo_url, 
      url, screenshot)
    values (#{id,jdbcType=BIGINT}, #{provider,jdbcType=BIGINT}, #{serviceMethod,jdbcType=VARCHAR}, #{serviceChannel,jdbcType=VARCHAR},
      #{serviceTag,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, #{demoUrl,jdbcType=LONGVARCHAR}, 
      #{url,jdbcType=LONGVARCHAR}, #{screenshot,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroappWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_microapp
    <trim prefix="(" suffix=")" suffixOverrides=",">
        id,
      <if test="provider != null">
        provider,
      </if>
      <if test="serviceMethod != null">
        service_method,
      </if>
      <if test="serviceChannel != null">
        service_channel,
      </if>
      <if test="serviceTag != null">
        service_tag,
      </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="demoUrl != null">
        demo_url,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="screenshot != null">
        screenshot,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="provider != null">
        #{provider,jdbcType=BIGINT},
      </if>
      <if test="serviceMethod != null">
        #{serviceMethod,jdbcType=VARCHAR},
      </if>
      <if test="serviceChannel != null">
        #{serviceChannel,jdbcType=VARCHAR},
      </if>
      <if test="serviceTag != null">
        #{serviceTag,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="demoUrl != null">
        #{demoUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="url != null">
        #{url,jdbcType=LONGVARCHAR},
      </if>
      <if test="screenshot != null">
        #{screenshot,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroappExample" resultType="java.lang.Long">
    select count(*) from resource_microapp
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update resource_microapp
    <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.serviceMethod != null">
        service_method = #{record.serviceMethod,jdbcType=VARCHAR},
      </if>
      <if test="record.serviceChannel != null">
        service_channel = #{record.serviceChannel,jdbcType=VARCHAR},
      </if>
      <if test="record.serviceTag != null">
        service_tag = #{record.serviceTag,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.demoUrl != null">
        demo_url = #{record.demoUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.url != null">
        url = #{record.url,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.screenshot != null">
        screenshot = #{record.screenshot,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update resource_microapp
    set id = #{record.id,jdbcType=BIGINT},
      provider = #{record.provider,jdbcType=BIGINT},
      service_method = #{record.serviceMethod,jdbcType=VARCHAR},
      service_channel = #{record.serviceChannel,jdbcType=VARCHAR},
      service_tag = #{record.serviceTag,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},
      demo_url = #{record.demoUrl,jdbcType=LONGVARCHAR},
      url = #{record.url,jdbcType=LONGVARCHAR},
      screenshot = #{record.screenshot,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update resource_microapp
    set id = #{record.id,jdbcType=BIGINT},
      provider = #{record.provider,jdbcType=BIGINT},
      service_method = #{record.serviceMethod,jdbcType=VARCHAR},
      service_channel = #{record.serviceChannel,jdbcType=VARCHAR},
      service_tag = #{record.serviceTag,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.ResourceMicroappWithBLOBs">
    update resource_microapp
    <set>
      <if test="provider != null">
        provider = #{provider,jdbcType=BIGINT},
      </if>
      <if test="serviceMethod != null">
        service_method = #{serviceMethod,jdbcType=VARCHAR},
      </if>
      <if test="serviceChannel != null">
        service_channel = #{serviceChannel,jdbcType=VARCHAR},
      </if>
      <if test="serviceTag != null">
        service_tag = #{serviceTag,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="demoUrl != null">
        demo_url = #{demoUrl,jdbcType=LONGVARCHAR},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=LONGVARCHAR},
      </if>
      <if test="screenshot != null">
        screenshot = #{screenshot,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroappWithBLOBs">
    update resource_microapp
    set provider = #{provider,jdbcType=BIGINT},
      service_method = #{serviceMethod,jdbcType=VARCHAR},
      service_channel = #{serviceChannel,jdbcType=VARCHAR},
      service_tag = #{serviceTag,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      demo_url = #{demoUrl,jdbcType=LONGVARCHAR},
      url = #{url,jdbcType=LONGVARCHAR},
      screenshot = #{screenshot,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.ResourceMicroapp">
    update resource_microapp
    set provider = #{provider,jdbcType=BIGINT},
      service_method = #{serviceMethod,jdbcType=VARCHAR},
      service_channel = #{serviceChannel,jdbcType=VARCHAR},
      service_tag = #{serviceTag,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="selectModelList" parameterType="com.lightinit.hsdataplatform.model.admin.ResourceMicroappRegisterSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceMicroappRegisterListModel">
    <if test="resourceName != null and resourceName.length() > 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>

    SELECT r.id, r.catelog_type, r.resource_name, r.resource_summary, r.resource_identity, r.resource_state, r.register_date,s.sector_name provider
    ,
    (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_theme`) themename
    FROM resource r
    JOIN resource_microapp rd ON r.id = rd.id
    LEFT JOIN sector s ON rd.provider = s.id
    left JOIN admin a ON a.id = r.created_by
    <where>
      <if test="provider != null and provider.length() > 0">
        s.id = #{provider}
      </if>
      <if test="resourceName != null and resourceName.length() > 0">
        AND r.resource_name like #{resourceName}
      </if>
      <if test="registerDateFrom != null">
        AND r.register_date &gt;= #{registerDateFrom}
      </if>
      <if test="registerDateTo != null">
        AND r.register_date &lt; #{registerDateTo}
      </if>
      <if test="resourceState != null and resourceState.length() > 0 and resourceState != '全部'">
        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="selectModelListCount" parameterType="com.lightinit.hsdataplatform.model.admin.ResourceDataRegisterSearchModel" resultType="java.lang.Long">
    <if test="resourceName != null and resourceName.length() > 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>

    SELECT COUNT(*)
<!--     ,
     (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_theme`) themename-->
    FROM resource r
    JOIN resource_microapp rd ON r.id = rd.id
    LEFT JOIN sector s ON rd.provider = s.id
    left JOIN admin a ON a.id = r.created_by
    <where>
      <if test="provider != null and provider.length() > 0">
        s.id = #{provider}
      </if>
      <if test="resourceName != null and resourceName.length() > 0">
        AND r.resource_name like #{resourceName}
      </if>
      <if test="registerDateFrom != null">
        AND r.register_date &gt;= #{registerDateFrom}
      </if>
      <if test="registerDateTo != null">
        AND r.register_date &lt; #{registerDateTo}
      </if>
      <if test="resourceState != null and resourceState.length() > 0 and resourceState != '全部'">
        AND r.resource_state = #{resourceState}
      </if>
      <if test="orgId != null ">
        AND a.org_id = #{orgId}
      </if>
    </where>
<!--     GROUP BY r.`catelog_theme`-->
  </select>
  <select id="selectDic" parameterType="java.lang.Long" resultType="com.lightinit.hsdataplatform.model.admin.ResourceMicroappRegisterListModel">
     SELECT s.sector_name provider,
     (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_basic`) basicname,
   (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_custom`) customname,
   (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_sector`) sectorname,
   (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_theme`) themename
    FROM resource r
    JOIN resource_microapp rd ON r.id = rd.id
    LEFT JOIN sector s ON rd.provider = s.id
     where r.id = #{id,jdbcType=BIGINT}
  </select>
  <select id="querypublishList" parameterType="com.lightinit.hsdataplatform.model.admin.ResourceMicroappRegisterSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceMicroappRegisterListModel">
    <if test="resourceName != null and resourceName.length() > 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>

    SELECT r.id, r.catelog_type, r.resource_name, r.resource_summary, r.resource_identity, r.resource_state, r.register_date,s.sector_name provider,p.publish_state,
    (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_theme`) themename
    FROM resource r
    JOIN publish_info p ON r.id = p.resource_id
    JOIN resource_microapp rd ON r.id = rd.id

    LEFT JOIN sector s ON rd.provider = s.id
    LEFT JOIN  admin a
    ON a.id = r.created_by
    <where>
      <if test="provider != null and provider.length() > 0">
        s.id = #{provider}
      </if>
      <if test="resourceName != null and resourceName.length() > 0">
        AND r.resource_name like #{resourceName}
      </if>
      <if test="registerDateFrom != null">
        AND r.register_date &gt;= #{registerDateFrom}
      </if>
      <if test="registerDateTo != null">
        AND r.register_date &lt; #{registerDateTo}
      </if>
      <if test="resourceState != null and resourceState.length() > 0 and resourceState != '全部'">
        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="querypublishCount" parameterType="com.lightinit.hsdataplatform.model.admin.ResourceDataRegisterSearchModel" resultType="java.lang.Long">
    <if test="resourceName != null and resourceName.length() > 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>

    SELECT COUNT(*)
    <!--,
    (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_theme`) themename-->
    FROM resource r
    JOIN publish_info p ON r.id = p.resource_id
    JOIN resource_microapp rd ON r.id = rd.id

    LEFT JOIN sector s ON rd.provider = s.id
    LEFT JOIN  admin a
    ON a.id = r.created_by
    <where>
      <if test="provider != null and provider.length() > 0">
        s.id = #{provider}
      </if>
      <if test="resourceName != null and resourceName.length() > 0">
        AND r.resource_name like #{resourceName}
      </if>
      <if test="registerDateFrom != null">
        AND r.register_date &gt;= #{registerDateFrom}
      </if>
      <if test="registerDateTo != null">
        AND r.register_date &lt; #{registerDateTo}
      </if>
      <if test="resourceState != null and resourceState.length() > 0 and resourceState != '全部'">
        AND r.resource_state = #{resourceState}
      </if>
      <if test="orgId != null ">
        AND a.org_id = #{orgId}
      </if>
    </where>
  </select>
  <select id="selectMicroappAduitModel" parameterType="java.lang.Long" resultType="com.lightinit.hsdataplatform.model.admin.ResourceMicroappPublishDataModel">
     SELECT r.id, r.catelog_type, r.resource_name, r.resource_summary, r.resource_identity, r.resource_state, r.register_date,s.sector_name provider,
      (SELECT catelog_name FROM resource_catelog rc WHERE rc.id = r.`catelog_theme`) themename,
      rs.package_name,rs.package_price,rs.buy_times_limit,rs.use_times_limit,rs.effective_date,rs.expiried_date,
      p.resource_img,rd.service_tag,rd.demo_url,rd.url,r.audit_opinion
      FROM resource r
      JOIN publish_info p ON r.id = p.resource_id
      JOIN resource_microapp rd ON r.id = rd.id
      JOIN publish_setting rs ON rs.publish_info_id = p.id
      LEFT JOIN sector s ON rd.provider = s.id
      where r.id = #{id,jdbcType=BIGINT}
  </select>
</mapper>