<?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.ResourceDataMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.ResourceData">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="belong_to" jdbcType="BIGINT" property="belongTo" />
    <result column="data_tag" jdbcType="VARCHAR" property="dataTag" />
    <result column="data_catelog_id" jdbcType="BIGINT" property="dataCatelogId" />
    <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.ResourceDataWithBLOBs">
    <result column="data_item" jdbcType="LONGVARCHAR" property="dataItem" />
    <result column="data_file" jdbcType="LONGVARCHAR" property="dataFile" />
    <result column="demo_file" jdbcType="LONGVARCHAR" property="demoFile" />
  </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, belong_to, data_tag, data_catelog_id, created_at, created_by, deleted_at, deleted_by
  </sql>
  <sql id="Blob_Column_List">
    data_item, data_file, demo_file
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceDataExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from resource_data
    <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.ResourceDataExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from resource_data
    <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_data
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from resource_data
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceDataExample">
    delete from resource_data
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.ResourceDataWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_data (id,belong_to, data_tag, data_catelog_id,
      created_at, created_by, deleted_at, 
      deleted_by, data_item, data_file, 
      demo_file)
    values (#{id},#{belongTo,jdbcType=BIGINT}, #{dataTag,jdbcType=VARCHAR}, #{dataCatelogId,jdbcType=BIGINT},
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{deletedAt,jdbcType=TIMESTAMP}, 
      #{deletedBy,jdbcType=BIGINT}, #{dataItem,jdbcType=LONGVARCHAR}, #{dataFile,jdbcType=LONGVARCHAR}, 
      #{demoFile,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceDataWithBLOBs">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_data
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="belongTo != null">
        belong_to,
      </if>
      <if test="dataTag != null">
        data_tag,
      </if>
      <if test="dataCatelogId != null">
        data_catelog_id,
      </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="dataItem != null">
        data_item,
      </if>
      <if test="dataFile != null">
        data_file,
      </if>
      <if test="demoFile != null">
        demo_file,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="belongTo != null">
        #{belongTo,jdbcType=BIGINT},
      </if>
      <if test="dataTag != null">
        #{dataTag,jdbcType=VARCHAR},
      </if>
      <if test="dataCatelogId != null">
        #{dataCatelogId,jdbcType=BIGINT},
      </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="dataItem != null">
        #{dataItem,jdbcType=LONGVARCHAR},
      </if>
      <if test="dataFile != null">
        #{dataFile,jdbcType=LONGVARCHAR},
      </if>
      <if test="demoFile != null">
        #{demoFile,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceDataExample" resultType="java.lang.Long">
    select count(*) from resource_data
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update resource_data
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.belongTo != null">
        belong_to = #{record.belongTo,jdbcType=BIGINT},
      </if>
      <if test="record.dataTag != null">
        data_tag = #{record.dataTag,jdbcType=VARCHAR},
      </if>
      <if test="record.dataCatelogId != null">
        data_catelog_id = #{record.dataCatelogId,jdbcType=BIGINT},
      </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.dataItem != null">
        data_item = #{record.dataItem,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.dataFile != null">
        data_file = #{record.dataFile,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.demoFile != null">
        demo_file = #{record.demoFile,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update resource_data
    set id = #{record.id,jdbcType=BIGINT},
      belong_to = #{record.belongTo,jdbcType=BIGINT},
      data_tag = #{record.dataTag,jdbcType=VARCHAR},
      data_catelog_id = #{record.dataCatelogId,jdbcType=BIGINT},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      data_item = #{record.dataItem,jdbcType=LONGVARCHAR},
      data_file = #{record.dataFile,jdbcType=LONGVARCHAR},
      demo_file = #{record.demoFile,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update resource_data
    set id = #{record.id,jdbcType=BIGINT},
      belong_to = #{record.belongTo,jdbcType=BIGINT},
      data_tag = #{record.dataTag,jdbcType=VARCHAR},
      data_catelog_id = #{record.dataCatelogId,jdbcType=BIGINT},
      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.ResourceDataWithBLOBs">
    update resource_data
    <set>
      <if test="belongTo != null">
        belong_to = #{belongTo,jdbcType=BIGINT},
      </if>
      <if test="dataTag != null">
        data_tag = #{dataTag,jdbcType=VARCHAR},
      </if>
      <if test="dataCatelogId != null">
        data_catelog_id = #{dataCatelogId,jdbcType=BIGINT},
      </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="dataItem != null">
        data_item = #{dataItem,jdbcType=LONGVARCHAR},
      </if>
      <if test="dataFile != null">
        data_file = #{dataFile,jdbcType=LONGVARCHAR},
      </if>
      <if test="demoFile != null">
        demo_file = #{demoFile,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceDataWithBLOBs">
    update resource_data
    set belong_to = #{belongTo,jdbcType=BIGINT},
      data_tag = #{dataTag,jdbcType=VARCHAR},
      data_catelog_id = #{dataCatelogId,jdbcType=BIGINT},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      data_item = #{dataItem,jdbcType=LONGVARCHAR},
      data_file = #{dataFile,jdbcType=LONGVARCHAR},
      demo_file = #{demoFile,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.ResourceData">
    update resource_data
    set belong_to = #{belongTo,jdbcType=BIGINT},
      data_tag = #{dataTag,jdbcType=VARCHAR},
      data_catelog_id = #{dataCatelogId,jdbcType=BIGINT},
      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.ResourceDataRegisterSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceDataRegisterListModel">
    <if test="resourceName != null and resourceName.length() &gt; 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>
    SELECT r.id, r.catelog_type, r.resource_name, r.resource_summary, s.sector_name belong_to, r.resource_state, r.register_date
    FROM resource r
    JOIN resource_data rd ON r.id = rd.id
    LEFT JOIN sector s ON rd.belong_to = s.id
    <if test="userId !=null">
      left join admin a on a.org_id=s.id
    </if>
    <where>
      <if test="userId !=null">
        and a.id=#{userId}
      </if>
      <if test="belongTo != null">
        and s.id = #{belongTo}
      </if>
      <if test="resourceName != null and resourceName.length() &gt; 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() &gt; 0">
        AND r.resource_state = #{resourceState}
      </if>
      <if test="resourceType != null and resourceType.length() &gt; 0">
        AND r.resource_type = #{resourceType}
      </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() &gt; 0">
      <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
    </if>
    SELECT COUNT(*)
    FROM resource r
    JOIN resource_data rd ON r.id = rd.id
    LEFT JOIN sector s ON rd.belong_to = s.id
    <if test="userId !=null">
      left join admin a on a.org_id=s.id
    </if>
    <where>
      <if test="userId !=null">
        and a.id=#{userId}
      </if>
      <if test="belongTo != null">
        and s.id = #{belongTo}
      </if>
      <if test="resourceName != null and resourceName.length() &gt; 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() &gt; 0">
        AND r.resource_state = #{resourceState}
      </if>
      <if test="resourceType != null and resourceType.length() &gt; 0">
        AND r.resource_type = #{resourceType}
      </if>
    </where>
  </select>
</mapper>