<?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.RequirementReceiveMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataportal.entity.RequirementReceive">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="rqrmnt_id" jdbcType="BIGINT" property="rqrmntId" />
    <result column="received_by" jdbcType="BIGINT" property="receivedBy" />
    <result column="received_at" jdbcType="TIMESTAMP" property="receivedAt" />
    <result column="contact" jdbcType="VARCHAR" property="contact" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <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.hsdataportal.entity.RequirementReceive">
    <result column="solution" jdbcType="LONGVARCHAR" property="solution" />
  </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, rqrmnt_id, received_by, received_at, contact, phone, created_at, created_by, 
    deleted_at, deleted_by
  </sql>
  <sql id="Blob_Column_List">
    solution
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataportal.entity.RequirementReceiveExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from requirement_receive
    <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.RequirementReceiveExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from requirement_receive
    <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 requirement_receive
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from requirement_receive
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataportal.entity.RequirementReceiveExample">
    delete from requirement_receive
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataportal.entity.RequirementReceive">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into requirement_receive (rqrmnt_id, received_by, received_at, 
      contact, phone, created_at, 
      created_by, deleted_at, deleted_by, 
      solution)
    values (#{rqrmntId,jdbcType=BIGINT}, #{receivedBy,jdbcType=BIGINT}, #{receivedAt,jdbcType=TIMESTAMP}, 
      #{contact,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{createdBy,jdbcType=BIGINT}, #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, 
      #{solution,jdbcType=LONGVARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataportal.entity.RequirementReceive">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into requirement_receive
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="rqrmntId != null">
        rqrmnt_id,
      </if>
      <if test="receivedBy != null">
        received_by,
      </if>
      <if test="receivedAt != null">
        received_at,
      </if>
      <if test="contact != null">
        contact,
      </if>
      <if test="phone != null">
        phone,
      </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="solution != null">
        solution,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="rqrmntId != null">
        #{rqrmntId,jdbcType=BIGINT},
      </if>
      <if test="receivedBy != null">
        #{receivedBy,jdbcType=BIGINT},
      </if>
      <if test="receivedAt != null">
        #{receivedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="contact != null">
        #{contact,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,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="solution != null">
        #{solution,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataportal.entity.RequirementReceiveExample" resultType="java.lang.Long">
    select count(*) from requirement_receive
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update requirement_receive
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.rqrmntId != null">
        rqrmnt_id = #{record.rqrmntId,jdbcType=BIGINT},
      </if>
      <if test="record.receivedBy != null">
        received_by = #{record.receivedBy,jdbcType=BIGINT},
      </if>
      <if test="record.receivedAt != null">
        received_at = #{record.receivedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.contact != null">
        contact = #{record.contact,jdbcType=VARCHAR},
      </if>
      <if test="record.phone != null">
        phone = #{record.phone,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.solution != null">
        solution = #{record.solution,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update requirement_receive
    set id = #{record.id,jdbcType=BIGINT},
      rqrmnt_id = #{record.rqrmntId,jdbcType=BIGINT},
      received_by = #{record.receivedBy,jdbcType=BIGINT},
      received_at = #{record.receivedAt,jdbcType=TIMESTAMP},
      contact = #{record.contact,jdbcType=VARCHAR},
      phone = #{record.phone,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},
      solution = #{record.solution,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update requirement_receive
    set id = #{record.id,jdbcType=BIGINT},
      rqrmnt_id = #{record.rqrmntId,jdbcType=BIGINT},
      received_by = #{record.receivedBy,jdbcType=BIGINT},
      received_at = #{record.receivedAt,jdbcType=TIMESTAMP},
      contact = #{record.contact,jdbcType=VARCHAR},
      phone = #{record.phone,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.hsdataportal.entity.RequirementReceive">
    update requirement_receive
    <set>
      <if test="rqrmntId != null">
        rqrmnt_id = #{rqrmntId,jdbcType=BIGINT},
      </if>
      <if test="receivedBy != null">
        received_by = #{receivedBy,jdbcType=BIGINT},
      </if>
      <if test="receivedAt != null">
        received_at = #{receivedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="contact != null">
        contact = #{contact,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,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="solution != null">
        solution = #{solution,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataportal.entity.RequirementReceive">
    update requirement_receive
    set rqrmnt_id = #{rqrmntId,jdbcType=BIGINT},
      received_by = #{receivedBy,jdbcType=BIGINT},
      received_at = #{receivedAt,jdbcType=TIMESTAMP},
      contact = #{contact,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      solution = #{solution,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataportal.entity.RequirementReceive">
    update requirement_receive
    set rqrmnt_id = #{rqrmntId,jdbcType=BIGINT},
      received_by = #{receivedBy,jdbcType=BIGINT},
      received_at = #{receivedAt,jdbcType=TIMESTAMP},
      contact = #{contact,jdbcType=VARCHAR},
      phone = #{phone,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="selectList" parameterType="java.lang.Long" resultType="com.lightinit.hsdataportal.model.ReceiveListModel">
    SELECT
  r.rqrmnt_name as 'rqrmntName',
  r.rqrmnt_type as 'rqrmntType',
  r.publish_by as 'publishBy',
  u.username as 'userName',
  rr.solution,
  rr.phone,
  ra.deadline,
  ra.expected_quote as 'money',
  rr.received_at  as 'receivedAt'
FROM
  `requirement` r
  JOIN `requirement_api` ra ON r.`id` = ra.`id`

  JOIN `requirement_receive` rr
    ON r.id = rr.`rqrmnt_id`
  JOIN USER u
    ON rr.`received_by` = u.id
    WHERE u.id=#{id}
UNION
SELECT
  r.rqrmnt_name as 'rqrmntName',
  r.rqrmnt_type as 'rqrmntType',
  r.publish_by as 'publishBy',
  u.username as 'userName',
  rr.solution,
  rr.phone,
  rm.deadline,
  rm.money money,
  rr.received_at  as 'receivedAt'

FROM
  `requirement` r
  JOIN `requirement_microapp` rm ON r.`id` = rm.`id`

  JOIN `requirement_receive` rr
    ON r.id = rr.`rqrmnt_id`
  JOIN USER u
    ON rr.`received_by` = u.id
   WHERE u.id=#{id}
  </select>
</mapper>