<?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.RequirementFollowMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataportal.entity.RequirementFollow">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="platform_type" jdbcType="VARCHAR" property="platformType" />
    <result column="follower_id" jdbcType="BIGINT" property="followerId" />
    <result column="rqrmnt_id" jdbcType="BIGINT" property="rqrmntId" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
  </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, platform_type, follower_id, rqrmnt_id, created_at
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdataportal.entity.RequirementFollowExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from requirement_follow
    <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="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from requirement_follow
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from requirement_follow
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataportal.entity.RequirementFollowExample">
    delete from requirement_follow
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataportal.entity.RequirementFollow">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into requirement_follow (platform_type, follower_id, rqrmnt_id, 
      created_at)
    values (#{platformType,jdbcType=VARCHAR}, #{followerId,jdbcType=BIGINT}, #{rqrmntId,jdbcType=BIGINT}, 
      #{createdAt,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataportal.entity.RequirementFollow">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into requirement_follow
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="platformType != null">
        platform_type,
      </if>
      <if test="followerId != null">
        follower_id,
      </if>
      <if test="rqrmntId != null">
        rqrmnt_id,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="platformType != null">
        #{platformType,jdbcType=VARCHAR},
      </if>
      <if test="followerId != null">
        #{followerId,jdbcType=BIGINT},
      </if>
      <if test="rqrmntId != null">
        #{rqrmntId,jdbcType=BIGINT},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataportal.entity.RequirementFollowExample" resultType="java.lang.Long">
    select count(*) from requirement_follow
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update requirement_follow
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.platformType != null">
        platform_type = #{record.platformType,jdbcType=VARCHAR},
      </if>
      <if test="record.followerId != null">
        follower_id = #{record.followerId,jdbcType=BIGINT},
      </if>
      <if test="record.rqrmntId != null">
        rqrmnt_id = #{record.rqrmntId,jdbcType=BIGINT},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update requirement_follow
    set id = #{record.id,jdbcType=BIGINT},
      platform_type = #{record.platformType,jdbcType=VARCHAR},
      follower_id = #{record.followerId,jdbcType=BIGINT},
      rqrmnt_id = #{record.rqrmntId,jdbcType=BIGINT},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataportal.entity.RequirementFollow">
    update requirement_follow
    <set>
      <if test="platformType != null">
        platform_type = #{platformType,jdbcType=VARCHAR},
      </if>
      <if test="followerId != null">
        follower_id = #{followerId,jdbcType=BIGINT},
      </if>
      <if test="rqrmntId != null">
        rqrmnt_id = #{rqrmntId,jdbcType=BIGINT},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataportal.entity.RequirementFollow">
    update requirement_follow
    set platform_type = #{platformType,jdbcType=VARCHAR},
      follower_id = #{followerId,jdbcType=BIGINT},
      rqrmnt_id = #{rqrmntId,jdbcType=BIGINT},
      created_at = #{createdAt,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectList"  parameterType="java.lang.Long" resultType="com.lightinit.hsdataportal.model.MyFollowRequirementListModel">
    SELECT r.id,r.rqrmnt_name,r.rqrmnt_type,f.created_at,u.username publishBy ,f.id followId,f.created_at
    FROM requirement r
    JOIN requirement_follow f
    ON f.`rqrmnt_id` = r.id
    join user u on u.id = f.follower_id
    <where>
      u.id = #{id} and
      f.`platform_type`='开放平台'
    </where>
  </select>

  <select id="selectShareList" parameterType="java.lang.Long" resultType="com.lightinit.hsdataportal.model.MyFollowRequirementListModel">
    SELECT r.id,r.rqrmnt_name,r.rqrmnt_type,f.created_at,u.username publishBy,f.id followId,f.created_at
    FROM requirement r
    JOIN requirement_follow f
    ON f.`rqrmnt_id` = r.id
    join admin u on u.id = f.follower_id
    <where>
      u.id = #{id} and
      f.`platform_type`='共享平台'
    </where>
  </select>



</mapper>