<?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.hsdataportal.mapper.PublishInfoMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataportal.entity.PublishInfo">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="resource_id" jdbcType="BIGINT" property="resourceId" />
    <result column="publish_state" jdbcType="VARCHAR" property="publishState" />
    <result column="data_tag" jdbcType="VARCHAR" property="dataTag" />
    <result column="publish_channel" jdbcType="VARCHAR" property="publishChannel" />
    <result column="audited_by" jdbcType="BIGINT" property="auditedBy" />
    <result column="audited_at" jdbcType="TIMESTAMP" property="auditedAt" />
    <result column="audit_result" jdbcType="VARCHAR" property="auditResult" />
    <result column="audit_opinion" jdbcType="VARCHAR" property="auditOpinion" />
    <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" />
    <result column="out_id_1" jdbcType="VARCHAR" property="outId1" />
    <result column="out_id_2" jdbcType="VARCHAR" property="outId2" />
    <result column="out_id_3" jdbcType="VARCHAR" property="outId3" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.lightinit.hsdataportal.entity.PublishInfoWithBLOBs">
    <result column="resource_img" jdbcType="LONGVARCHAR" property="resourceImg" />
    <result column="share_condition" jdbcType="LONGVARCHAR" property="shareCondition" />
    <result column="open_condition" jdbcType="LONGVARCHAR" property="openCondition" />
  </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, resource_id, publish_state, data_tag, publish_channel, audited_by, audited_at, 
    audit_result, audit_opinion, created_at, created_by, deleted_at, deleted_by, out_id_1, 
    out_id_2, out_id_3
  </sql>
  <sql id="Blob_Column_List">
    resource_img, share_condition, open_condition
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataportal.entity.PublishInfoExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from publish_info
    <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.hsdataportal.entity.PublishInfoExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from publish_info
    <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 publish_info
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from publish_info
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataportal.entity.PublishInfoExample">
    delete from publish_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataportal.entity.PublishInfoWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into publish_info (resource_id, publish_state, data_tag, 
      publish_channel, audited_by, audited_at, 
      audit_result, audit_opinion, created_at, 
      created_by, deleted_at, deleted_by, 
      out_id_1, out_id_2, out_id_3, 
      resource_img, share_condition, open_condition
      )
    values (#{resourceId,jdbcType=BIGINT}, #{publishState,jdbcType=VARCHAR}, #{dataTag,jdbcType=VARCHAR}, 
      #{publishChannel,jdbcType=VARCHAR}, #{auditedBy,jdbcType=BIGINT}, #{auditedAt,jdbcType=TIMESTAMP}, 
      #{auditResult,jdbcType=VARCHAR}, #{auditOpinion,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{createdBy,jdbcType=BIGINT}, #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, 
      #{outId1,jdbcType=VARCHAR}, #{outId2,jdbcType=VARCHAR}, #{outId3,jdbcType=VARCHAR}, 
      #{resourceImg,jdbcType=LONGVARCHAR}, #{shareCondition,jdbcType=LONGVARCHAR}, #{openCondition,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataportal.entity.PublishInfoWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into publish_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="resourceId != null">
        resource_id,
      </if>
      <if test="publishState != null">
        publish_state,
      </if>
      <if test="dataTag != null">
        data_tag,
      </if>
      <if test="publishChannel != null">
        publish_channel,
      </if>
      <if test="auditedBy != null">
        audited_by,
      </if>
      <if test="auditedAt != null">
        audited_at,
      </if>
      <if test="auditResult != null">
        audit_result,
      </if>
      <if test="auditOpinion != null">
        audit_opinion,
      </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="outId1 != null">
        out_id_1,
      </if>
      <if test="outId2 != null">
        out_id_2,
      </if>
      <if test="outId3 != null">
        out_id_3,
      </if>
      <if test="resourceImg != null">
        resource_img,
      </if>
      <if test="shareCondition != null">
        share_condition,
      </if>
      <if test="openCondition != null">
        open_condition,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="resourceId != null">
        #{resourceId,jdbcType=BIGINT},
      </if>
      <if test="publishState != null">
        #{publishState,jdbcType=VARCHAR},
      </if>
      <if test="dataTag != null">
        #{dataTag,jdbcType=VARCHAR},
      </if>
      <if test="publishChannel != null">
        #{publishChannel,jdbcType=VARCHAR},
      </if>
      <if test="auditedBy != null">
        #{auditedBy,jdbcType=BIGINT},
      </if>
      <if test="auditedAt != null">
        #{auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditResult != null">
        #{auditResult,jdbcType=VARCHAR},
      </if>
      <if test="auditOpinion != null">
        #{auditOpinion,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="outId1 != null">
        #{outId1,jdbcType=VARCHAR},
      </if>
      <if test="outId2 != null">
        #{outId2,jdbcType=VARCHAR},
      </if>
      <if test="outId3 != null">
        #{outId3,jdbcType=VARCHAR},
      </if>
      <if test="resourceImg != null">
        #{resourceImg,jdbcType=LONGVARCHAR},
      </if>
      <if test="shareCondition != null">
        #{shareCondition,jdbcType=LONGVARCHAR},
      </if>
      <if test="openCondition != null">
        #{openCondition,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataportal.entity.PublishInfoExample" resultType="java.lang.Long">
    select count(*) from publish_info
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update publish_info
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.resourceId != null">
        resource_id = #{record.resourceId,jdbcType=BIGINT},
      </if>
      <if test="record.publishState != null">
        publish_state = #{record.publishState,jdbcType=VARCHAR},
      </if>
      <if test="record.dataTag != null">
        data_tag = #{record.dataTag,jdbcType=VARCHAR},
      </if>
      <if test="record.publishChannel != null">
        publish_channel = #{record.publishChannel,jdbcType=VARCHAR},
      </if>
      <if test="record.auditedBy != null">
        audited_by = #{record.auditedBy,jdbcType=BIGINT},
      </if>
      <if test="record.auditedAt != null">
        audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.auditResult != null">
        audit_result = #{record.auditResult,jdbcType=VARCHAR},
      </if>
      <if test="record.auditOpinion != null">
        audit_opinion = #{record.auditOpinion,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.outId1 != null">
        out_id_1 = #{record.outId1,jdbcType=VARCHAR},
      </if>
      <if test="record.outId2 != null">
        out_id_2 = #{record.outId2,jdbcType=VARCHAR},
      </if>
      <if test="record.outId3 != null">
        out_id_3 = #{record.outId3,jdbcType=VARCHAR},
      </if>
      <if test="record.resourceImg != null">
        resource_img = #{record.resourceImg,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.shareCondition != null">
        share_condition = #{record.shareCondition,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.openCondition != null">
        open_condition = #{record.openCondition,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update publish_info
    set id = #{record.id,jdbcType=BIGINT},
      resource_id = #{record.resourceId,jdbcType=BIGINT},
      publish_state = #{record.publishState,jdbcType=VARCHAR},
      data_tag = #{record.dataTag,jdbcType=VARCHAR},
      publish_channel = #{record.publishChannel,jdbcType=VARCHAR},
      audited_by = #{record.auditedBy,jdbcType=BIGINT},
      audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{record.auditResult,jdbcType=VARCHAR},
      audit_opinion = #{record.auditOpinion,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},
      out_id_1 = #{record.outId1,jdbcType=VARCHAR},
      out_id_2 = #{record.outId2,jdbcType=VARCHAR},
      out_id_3 = #{record.outId3,jdbcType=VARCHAR},
      resource_img = #{record.resourceImg,jdbcType=LONGVARCHAR},
      share_condition = #{record.shareCondition,jdbcType=LONGVARCHAR},
      open_condition = #{record.openCondition,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update publish_info
    set id = #{record.id,jdbcType=BIGINT},
      resource_id = #{record.resourceId,jdbcType=BIGINT},
      publish_state = #{record.publishState,jdbcType=VARCHAR},
      data_tag = #{record.dataTag,jdbcType=VARCHAR},
      publish_channel = #{record.publishChannel,jdbcType=VARCHAR},
      audited_by = #{record.auditedBy,jdbcType=BIGINT},
      audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{record.auditResult,jdbcType=VARCHAR},
      audit_opinion = #{record.auditOpinion,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},
      out_id_1 = #{record.outId1,jdbcType=VARCHAR},
      out_id_2 = #{record.outId2,jdbcType=VARCHAR},
      out_id_3 = #{record.outId3,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataportal.entity.PublishInfoWithBLOBs">
    update publish_info
    <set>
      <if test="resourceId != null">
        resource_id = #{resourceId,jdbcType=BIGINT},
      </if>
      <if test="publishState != null">
        publish_state = #{publishState,jdbcType=VARCHAR},
      </if>
      <if test="dataTag != null">
        data_tag = #{dataTag,jdbcType=VARCHAR},
      </if>
      <if test="publishChannel != null">
        publish_channel = #{publishChannel,jdbcType=VARCHAR},
      </if>
      <if test="auditedBy != null">
        audited_by = #{auditedBy,jdbcType=BIGINT},
      </if>
      <if test="auditedAt != null">
        audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditResult != null">
        audit_result = #{auditResult,jdbcType=VARCHAR},
      </if>
      <if test="auditOpinion != null">
        audit_opinion = #{auditOpinion,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="outId1 != null">
        out_id_1 = #{outId1,jdbcType=VARCHAR},
      </if>
      <if test="outId2 != null">
        out_id_2 = #{outId2,jdbcType=VARCHAR},
      </if>
      <if test="outId3 != null">
        out_id_3 = #{outId3,jdbcType=VARCHAR},
      </if>
      <if test="resourceImg != null">
        resource_img = #{resourceImg,jdbcType=LONGVARCHAR},
      </if>
      <if test="shareCondition != null">
        share_condition = #{shareCondition,jdbcType=LONGVARCHAR},
      </if>
      <if test="openCondition != null">
        open_condition = #{openCondition,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataportal.entity.PublishInfoWithBLOBs">
    update publish_info
    set resource_id = #{resourceId,jdbcType=BIGINT},
      publish_state = #{publishState,jdbcType=VARCHAR},
      data_tag = #{dataTag,jdbcType=VARCHAR},
      publish_channel = #{publishChannel,jdbcType=VARCHAR},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      out_id_1 = #{outId1,jdbcType=VARCHAR},
      out_id_2 = #{outId2,jdbcType=VARCHAR},
      out_id_3 = #{outId3,jdbcType=VARCHAR},
      resource_img = #{resourceImg,jdbcType=LONGVARCHAR},
      share_condition = #{shareCondition,jdbcType=LONGVARCHAR},
      open_condition = #{openCondition,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataportal.entity.PublishInfo">
    update publish_info
    set resource_id = #{resourceId,jdbcType=BIGINT},
      publish_state = #{publishState,jdbcType=VARCHAR},
      data_tag = #{dataTag,jdbcType=VARCHAR},
      publish_channel = #{publishChannel,jdbcType=VARCHAR},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      out_id_1 = #{outId1,jdbcType=VARCHAR},
      out_id_2 = #{outId2,jdbcType=VARCHAR},
      out_id_3 = #{outId3,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <!--sun:-->
  <select id="getDataDetail" parameterType="com.lightinit.hsdataportal.model.DataSearchModel" resultType="com.lightinit.hsdataportal.model.DataDetailModel">
    SELECT ps.id AS publish_settingId,pu.id AS pulish_infoId,pu.resource_img,r.id AS resource_id,r.resource_name,r.resource_identity,r.share_type,r.open_type,r.resource_summary,pu.audited_at,rd.data_item,
    rd.data_tag,rd.belong_to,s.sector_name,r.catelog_theme,rd.data_tag,rd.demo_file,rd.data_file,ps.package_price,ps.package_months,r.catelog_custom, rvt.view_times,
    rc1.catelog_type,rc1.catelog_name AS catelog_basicName,rc2.catelog_type,rc2.catelog_name AS catelog_sectorName,rc3.catelog_type,rc3.catelog_name AS catelog_themeName,rc4.catelog_type,rc4.catelog_name AS catelog_customName,
    <if test="openType !=null and openType !=''">
      (SELECT COUNT(*) FROM resource_follow rf WHERE  rf.platform_type=#{platformType} AND publish_setting_id = ps.id  ) followTotalCount
    </if>
    <if test="shareType !=null and shareType !=''">
      (SELECT COUNT(*) FROM resource_follow rf WHERE rf.platform_type=#{platformType} AND publish_setting_id = ps.id  ) followTotalCount
    </if>
    FROM publish_info pu
    JOIN resource r ON pu.resource_id=r.id
    JOIN publish_setting ps ON ps.publish_info_id=pu.id
    LEFT JOIN resource_data rd ON r.id=rd.id
    LEFT JOIN sector s ON rd.belong_to=s.id
    LEFT JOIN resource_view_times rvt ON rvt.id=r.id
    LEFT JOIN resource_catelog rc1 ON r.catelog_basic=rc1.id
    LEFT JOIN resource_catelog rc2 ON r.catelog_sector=rc2.id
    LEFT JOIN resource_catelog rc3 ON r.catelog_theme=rc3.id
    LEFT JOIN resource_catelog rc4 ON r.catelog_custom=rc4.id
    <where>
          AND  pu.publish_state =#{publishState}
        <if test="openType !=null and openType !=''">
            and r.open_type !=#{openType} and  r.open_type is not null and r.open_type !=''
        </if>
        <if test="shareType !=null and shareType !=''">
          and r.share_type !=#{shareType} and  r.share_type is not null and r.share_type !=''
        </if>
        <if test="publisthSettingId !=null">
          and ps.id=#{publisthSettingId}
        </if>
        <if test="publisthSettingId == null">
          and 1=2
        </if>
      </where>
  </select>

  <!--sun-->
  <select id="getDataFollowTotalCount" resultType="long">
    SELECT COUNT(*) FROM resource_follow rf WHERE rf.publish_setting_id=#{publish_settingId}
    <if test="openType !=null and openType !=''">
       AND  rf.platform_type='开放平台'
    </if>
    <if test="shareType !=null and shareType !=''">
       AND rf.platform_type='共享平台'
    </if>
  </select>

    <!--sun:-->
    <select id="getDataOpenIndex" parameterType="com.lightinit.hsdataportal.model.DataSearchModel" resultType="com.lightinit.hsdataportal.model.DataListModel">
        <if test="resourceName !=null and resourceName!=''">
            <bind name="resourceNameLike" value="'%'+resourceName+'%'" />
        </if>
        <if test="catelogThemeCode != null and catelogThemeCode.length() &gt; 0">
            <bind name="catelogThemeCode" value="_parameter.catelogThemeCode + '%'" />
        </if>
        <if test="sectorCode != null and sectorCode.length() &gt; 0">
            <bind name="sectorCode" value="_parameter.sectorCode + '%'" />
        </if>
        <if test="resourceIdentity != null and resourceIdentity.length() &gt; 0">
          <bind name="resourceIdentity" value="'%'+_parameter.resourceIdentity + '%'" />
        </if>
        <if test="serviceTag != null and serviceTag.length() &gt; 0">
          <bind name="serviceTag" value="'%'+_parameter.serviceTag + '%'" />
        </if>
      SELECT
      r.id AS resource_id,
      ps.id AS publish_settingId,
      pu.id AS pulish_infoId,
      r.resource_name,
      ps.package_name,
      rvt.view_times,
      r.resource_type,
      r.share_type,
      r.open_type,
      rc.catelog_type,
      rc.id AS catelog_id,
      rc.catelog_name,
      pu.publish_state,
      pu.created_at,
      pu.resource_img,
      ps.charge_method,
      s.sector_name,
      rd.data_tag,
      <if test="openType !=null and openType !=''">
        (SELECT COUNT(*) FROM resource_follow rf WHERE  rf.platform_type=#{platformType} AND publish_setting_id = ps.id  ) resourceFollowCount
      </if>
      <if test="shareType !=null and shareType !=''">
        (SELECT COUNT(*) FROM resource_follow rf WHERE rf.platform_type=#{platformType} AND publish_setting_id = ps.id  ) resourceFollowCount
      </if>
      FROM publish_info pu
      INNER JOIN resource r ON r.id=pu.resource_id
      INNER JOIN resource_data rd ON rd.id=r.id
      LEFT JOIN resource_view_times rvt ON rvt.id=r.id
      LEFT JOIN resource_catelog rc ON r.catelog_theme=rc.id
      LEFT JOIN sector s ON s.id=rd.belong_to
      INNER JOIN publish_setting ps ON ps.publish_info_id=pu.id
      left join resource_sort rs on r.id = rs.resource_id and rs.sort_category = #{sortCategory}
        <where>
          r.resource_type=#{resourceType}   AND pu.publish_state =#{publishState} AND ps.deleted_at is NULL
          <if test="openType !=null and openType !=''">
            and r.open_type !=#{openType} and  r.open_type is not null and r.open_type !=''
          </if>
          <if test="shareType !=null and shareType !=''">
            and r.share_type !=#{shareType} and  r.share_type is not null and r.share_type !=''
          </if>
          <if test="chargeMethod != null and chargeMethod.length()&gt;0">
            AND ps.charge_method = #{chargeMethod}
          </if>
            <if test="catelogThemeCode != null and catelogThemeCode.length() &gt; 0">
                AND rc.catelog_code LIKE #{catelogThemeCode}
            </if>
            <if test="sectorCode != null and sectorCode.length() &gt; 0">
                AND s.`sector_code` LIKE #{sectorCode}
            </if>
            <if test="catelogName !=null and catelogName !=''">
              and rc.catelog_name=#{catelogName}
            </if>
            <if test="resourceName !=null and resourceName !=''">
              and r.resource_name like #{resourceNameLike}
            </if>
           <if test="moreCondition !=null and moreCondition !=''">
                and r.share_type =#{moreCondition}
            </if>

          <if test="catelogTheme != null">
            AND r.catelog_theme = #{catelogTheme}
          </if>
          <if test="catelogSector != null">
            AND r.catelog_sector = #{catelogSector}
          </if>
          <if test="resourceIdentity != null and resourceIdentity.length() &gt; 0">
            AND r.resource_identity like #{resourceIdentity}
          </if>
          <if test="serviceTag != null and serviceTag.length() &gt; 0">
            AND rd.data_tag like #{serviceTag}
          </if>


            <if test="sortType !=null and sortType==0">
              ORDER BY rs.sort_value DESC
            </if>
            <if test="sortType !=null and sortType==1">
                 ORDER BY pu.created_at DESC
          </if>
          <if test="sortType !=null and sortType ==2">  /*浏览次数还是关注次数*/
                ORDER BY rvt.view_times DESC
          </if>
          <if test="page != null">
            limit ${page.beginIndex},${page.pageSize}
          </if>
        </where>
    </select>

    <!--sun:计算总页数-->
    <select id="getIndexCount" parameterType="com.lightinit.hsdataportal.model.DataSearchModel" resultType="Long">
      <if test="resourceName !=null and resourceName!=''">
        <bind name="resourceNameLike" value="'%'+resourceName+'%'" />
      </if>
      <if test="catelogThemeCode != null and catelogThemeCode.length() &gt; 0">
        <bind name="catelogThemeCode" value="_parameter.catelogThemeCode + '%'" />
      </if>
      <if test="sectorCode != null and sectorCode.length() &gt; 0">
        <bind name="sectorCode" value="_parameter.sectorCode + '%'" />
      </if>
        select count(*)
        FROM publish_info pu
        INNER JOIN resource r ON r.id=pu.resource_id
        INNER JOIN resource_data rd ON rd.id=r.id
        LEFT JOIN resource_view_times rvt ON rvt.id=r.id
        LEFT JOIN resource_catelog rc ON r.catelog_theme=rc.id
        LEFT JOIN sector s ON s.id=rd.belong_to
        INNER JOIN publish_setting ps ON ps.publish_info_id=pu.id
        <where>
            r.resource_type=#{resourceType}   AND pu.publish_state =#{publishState} AND ps.deleted_at IS NULL
            <if test="openType !=null and openType !=''">
                and r.open_type !=#{openType} and  r.open_type is not null and r.open_type !=''
            </if>
            <if test="shareType !=null and shareType !=''">
                and r.share_type !=#{shareType} and  r.share_type is not null and r.share_type !=''
            </if>
            <if test="chargeMethod != null and chargeMethod.length()&gt;0">
                AND ps.charge_method = #{chargeMethod}
            </if>
            <if test="catelogThemeCode != null and catelogThemeCode.length() &gt; 0">
              AND rc.catelog_code LIKE #{catelogThemeCode}
            </if>
            <if test="sectorCode != null and sectorCode.length() &gt; 0">
              AND s.`sector_code` LIKE #{sectorCode}
            </if>
            <if test="catelogName !=null and catelogName !=''">
                and rc.catelog_name=#{catelogName}
            </if>
            <if test="resourceName !=null and resourceName !=''">
                and r.resource_name like #{resourceNameLike}
            </if>
            <if test="catelogTheme != null">
                AND r.catelog_theme = #{catelogTheme}
            </if>
            <if test="catelogSector != null">
                AND r.catelog_sector = #{catelogSector}
            </if>
            <if test="moreCondition !=null and moreCondition !=''">
              and r.share_type =#{moreCondition}
            </if>
        </where>
    </select>

  <!--sun:-->
  <select id="getDataOpenType" parameterType="com.lightinit.hsdataportal.model.DataOpenSearchModel" resultType="com.lightinit.hsdataportal.model.DataApplyPriceModel">
      SELECT ps.id,ps.id AS publish_settingId,ps.charge_method,ps.package_price,ps.package_name,ps.package_months,ps.self_cost,ps.buy_times_limit,
      ps.use_times_limit,ps.effective_date,ps.expiried_date,ps.description,r.resource_name,
      pu.id AS publish_infoId,r.open_type,r.share_type,r.id AS resource_id FROM publish_info pu
      JOIN publish_setting ps ON pu.id=ps.publish_info_id
      JOIN resource r ON r.id=pu.resource_id
      <where>
          pu.publish_state=#{publishState}
      <if test="openType !=null and openType !=''">
        and r.open_type !=#{openType} and r.open_type IS NOT NULL and r.open_type !=''
      </if>
      <if test="shareType !=null and shareType !=''">
          and r.share_type !=#{shareType} and r.share_type IS NOT NULL and r.share_type !=''
      </if>
      <if test="id !=null">
          and ps.id=#{id}
      </if>
      <if test="id ==null">
          and 1=2
      </if>
      </where>
  </select>


  <select id="getDataViewList" parameterType="com.lightinit.hsdataportal.model.DataViewListModel" resultType="com.lightinit.hsdataportal.model.DataViewListModel">
    select rg.id,rg.catelog_code,rg.catelog_name,rg.catelog_img from resource_catelog  rg
    where rg.catelog_type=#{catelogType} and rg.parent_id is null and rg.is_open=#{type} and rg.is_data_catelog=#{type}
    <if test="openType !=null and openType !=null">
      and rg.is_open=#{type} and rg.is_data_catelog=#{type}
    </if>
    <if test="shareType !=null and shareType !=null">
      and rg.is_share=#{type} and rg.is_data_catelog=#{type}
    </if>
  </select>
  <!--sun-->
  <select id="getDataStructreList" parameterType="com.lightinit.hsdataportal.model.DataOpenSearchModel" resultType="com.lightinit.hsdataportal.model.DataStructListModel">
      SELECT s.id, s.sector_name,s.sector_code, COUNT(rd.id) AS perTotal
      FROM sector s
      LEFT JOIN sector bt ON bt.sector_code LIKE CONCAT(s.sector_code, "%")
      LEFT JOIN resource_data rd ON bt.id = rd.belong_to
      INNER JOIN resource r ON rd.id=r.id
      INNER JOIN publish_info pu ON r.id=pu.resource_id
    WHERE s.parent_id IS NULL AND r.resource_type=#{resourceType} AND pu.publish_state=#{publishState}
      <if test="openType !=null and openType !=''">
        and r.open_type !=#{openType} and r.open_type is not null and r.open_type !=''
      </if>
      <if test="shareType !=null and shareType !=''">
        and r.share_type !=#{shareType} and r.share_type is not null and r.share_type !=''
      </if>
      GROUP BY s.id, s.sector_name
    <if test="page != null">
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>

    <!--sun-->
    <select id="getSectorTotal" parameterType="com.lightinit.hsdataportal.model.DataOpenSearchModel" resultType="long">
     SELECT  COUNT(*)  FROM (SELECT s.id, s.sector_name,s.sector_code, COUNT(rd.id) AS perTotal
      FROM sector s
      LEFT JOIN sector bt ON bt.sector_code LIKE CONCAT(s.sector_code, "%")
      LEFT JOIN resource_data rd ON bt.id = rd.belong_to
      INNER JOIN resource r ON rd.id=r.id
      INNER JOIN publish_info pu ON r.id=pu.resource_id
      WHERE s.parent_id IS NULL AND r.resource_type=#{resourceType} AND pu.publish_state=#{publishState}
      <if test="openType !=null and openType !=''">
        and r.open_type !=#{openType} and r.open_type is not null and r.open_type !=''
      </if>
      <if test="shareType !=null and shareType !=''">
        and r.share_type !=#{shareType} and r.share_type is not null and r.share_type !=''
      </if>
      GROUP BY s.id, s.sector_name) w
    </select>
    <!--sun-->
    <select id="getSectorDataTotal" parameterType="com.lightinit.hsdataportal.model.DataOpenSearchModel" resultType="long">
        SELECT SUM(w.perTotal) AS total FROM (SELECT s.id, s.sector_name,s.sector_code, COUNT(rd.id) AS perTotal
      FROM sector s
      LEFT JOIN sector bt ON bt.sector_code LIKE CONCAT(s.sector_code, "%")
      LEFT JOIN resource_data rd ON bt.id = rd.belong_to
      INNER JOIN resource r ON rd.id=r.id
      INNER JOIN publish_info pu ON r.id=pu.resource_id
      WHERE s.parent_id IS NULL AND r.resource_type=#{resourceType} AND pu.publish_state=#{publishState}
      <if test="openType !=null and openType !=''">
        and r.open_type !=#{openType} and r.open_type is not null and r.open_type !=''
      </if>
      <if test="shareType !=null and shareType !=''">
        and r.share_type !=#{shareType} and r.share_type is not null and r.open_type !=''
      </if>
      GROUP BY s.id, s.sector_name) w
    </select>
</mapper>