<?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.RequirementMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.Requirement">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="platform_type" jdbcType="VARCHAR" property="platformType" />
    <result column="rqrmnt_type" jdbcType="VARCHAR" property="rqrmntType" />
    <result column="rqrmnt_state" jdbcType="VARCHAR" property="rqrmntState" />
    <result column="rqrmnt_source" jdbcType="VARCHAR" property="rqrmntSource" />
    <result column="publish_by" jdbcType="BIGINT" property="publishBy" />
    <result column="publish_at" jdbcType="TIMESTAMP" property="publishAt" />
    <result column="rqrmnt_name" jdbcType="VARCHAR" property="rqrmntName" />
    <result column="rqrmnt_summary" jdbcType="VARCHAR" property="rqrmntSummary" />
    <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="view_times" jdbcType="BIGINT" property="viewTimes" />
    <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>
  <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, rqrmnt_type, rqrmnt_state, rqrmnt_source, publish_by, publish_at, 
    rqrmnt_name, rqrmnt_summary, audited_by, audited_at, audit_result, audit_opinion, 
    view_times, created_at, created_by, deleted_at, deleted_by
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.RequirementExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from requirement
    <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
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from requirement
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.RequirementExample">
    delete from requirement
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.Requirement">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into requirement (platform_type, rqrmnt_type, rqrmnt_state, 
      rqrmnt_source, publish_by, publish_at, 
      rqrmnt_name, rqrmnt_summary, audited_by, 
      audited_at, audit_result, audit_opinion, 
      view_times, created_at, created_by, 
      deleted_at, deleted_by)
    values (#{platformType,jdbcType=VARCHAR}, #{rqrmntType,jdbcType=VARCHAR}, #{rqrmntState,jdbcType=VARCHAR}, 
      #{rqrmntSource,jdbcType=VARCHAR}, #{publishBy,jdbcType=BIGINT}, #{publishAt,jdbcType=TIMESTAMP}, 
      #{rqrmntName,jdbcType=VARCHAR}, #{rqrmntSummary,jdbcType=VARCHAR}, #{auditedBy,jdbcType=BIGINT}, 
      #{auditedAt,jdbcType=TIMESTAMP}, #{auditResult,jdbcType=VARCHAR}, #{auditOpinion,jdbcType=VARCHAR}, 
      #{viewTimes,jdbcType=BIGINT}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.Requirement">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into requirement
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="platformType != null">
        platform_type,
      </if>
      <if test="rqrmntType != null">
        rqrmnt_type,
      </if>
      <if test="rqrmntState != null">
        rqrmnt_state,
      </if>
      <if test="rqrmntSource != null">
        rqrmnt_source,
      </if>
      <if test="publishBy != null">
        publish_by,
      </if>
      <if test="publishAt != null">
        publish_at,
      </if>
      <if test="rqrmntName != null">
        rqrmnt_name,
      </if>
      <if test="rqrmntSummary != null">
        rqrmnt_summary,
      </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="viewTimes != null">
        view_times,
      </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>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="platformType != null">
        #{platformType,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntType != null">
        #{rqrmntType,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntState != null">
        #{rqrmntState,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntSource != null">
        #{rqrmntSource,jdbcType=VARCHAR},
      </if>
      <if test="publishBy != null">
        #{publishBy,jdbcType=BIGINT},
      </if>
      <if test="publishAt != null">
        #{publishAt,jdbcType=TIMESTAMP},
      </if>
      <if test="rqrmntName != null">
        #{rqrmntName,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntSummary != null">
        #{rqrmntSummary,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="viewTimes != null">
        #{viewTimes,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>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.RequirementExample" resultType="java.lang.Long">
    select count(*) from requirement
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update requirement
    <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.rqrmntType != null">
        rqrmnt_type = #{record.rqrmntType,jdbcType=VARCHAR},
      </if>
      <if test="record.rqrmntState != null">
        rqrmnt_state = #{record.rqrmntState,jdbcType=VARCHAR},
      </if>
      <if test="record.rqrmntSource != null">
        rqrmnt_source = #{record.rqrmntSource,jdbcType=VARCHAR},
      </if>
      <if test="record.publishBy != null">
        publish_by = #{record.publishBy,jdbcType=BIGINT},
      </if>
      <if test="record.publishAt != null">
        publish_at = #{record.publishAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.rqrmntName != null">
        rqrmnt_name = #{record.rqrmntName,jdbcType=VARCHAR},
      </if>
      <if test="record.rqrmntSummary != null">
        rqrmnt_summary = #{record.rqrmntSummary,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.viewTimes != null">
        view_times = #{record.viewTimes,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>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update requirement
    set id = #{record.id,jdbcType=BIGINT},
      platform_type = #{record.platformType,jdbcType=VARCHAR},
      rqrmnt_type = #{record.rqrmntType,jdbcType=VARCHAR},
      rqrmnt_state = #{record.rqrmntState,jdbcType=VARCHAR},
      rqrmnt_source = #{record.rqrmntSource,jdbcType=VARCHAR},
      publish_by = #{record.publishBy,jdbcType=BIGINT},
      publish_at = #{record.publishAt,jdbcType=TIMESTAMP},
      rqrmnt_name = #{record.rqrmntName,jdbcType=VARCHAR},
      rqrmnt_summary = #{record.rqrmntSummary,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},
      view_times = #{record.viewTimes,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.Requirement">
    update requirement
    <set>
      <if test="platformType != null">
        platform_type = #{platformType,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntType != null">
        rqrmnt_type = #{rqrmntType,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntState != null">
        rqrmnt_state = #{rqrmntState,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntSource != null">
        rqrmnt_source = #{rqrmntSource,jdbcType=VARCHAR},
      </if>
      <if test="publishBy != null">
        publish_by = #{publishBy,jdbcType=BIGINT},
      </if>
      <if test="publishAt != null">
        publish_at = #{publishAt,jdbcType=TIMESTAMP},
      </if>
      <if test="rqrmntName != null">
        rqrmnt_name = #{rqrmntName,jdbcType=VARCHAR},
      </if>
      <if test="rqrmntSummary != null">
        rqrmnt_summary = #{rqrmntSummary,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="viewTimes != null">
        view_times = #{viewTimes,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>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.Requirement">
    update requirement
    set platform_type = #{platformType,jdbcType=VARCHAR},
      rqrmnt_type = #{rqrmntType,jdbcType=VARCHAR},
      rqrmnt_state = #{rqrmntState,jdbcType=VARCHAR},
      rqrmnt_source = #{rqrmntSource,jdbcType=VARCHAR},
      publish_by = #{publishBy,jdbcType=BIGINT},
      publish_at = #{publishAt,jdbcType=TIMESTAMP},
      rqrmnt_name = #{rqrmntName,jdbcType=VARCHAR},
      rqrmnt_summary = #{rqrmntSummary,jdbcType=VARCHAR},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      view_times = #{viewTimes,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.RequirementMicroappPagingSearchModel" resultType="com.lightinit.hsdataplatform.entity.Requirement">
    <if test="requirementName != null and requirementName.length() &gt; 0">
      <bind name="requirementName" value="'%' + _parameter.requirementName + '%'" />
    </if>
      SELECT r.id AS rqrmnt_id,r.rqrmnt_name,r.rqrmnt_summary,r.publish_at,r.created_at,r.rqrmnt_state,r.platform_type,r.rqrmnt_type,r.rqrmnt_source
    FROM requirement r
      INNER JOIN requirement_microapp rm ON r.id=rm.id
    <where>
      <if test="requirementType != null and requirementType.length() &gt; 0">
        AND r.rqrmnt_type = #{requirementType}
      </if>
      <if test="requirementName != null and requirementName.length() &gt; 0">
        AND r.rqrmnt_name like #{requirementName}
      </if>
      <if test="publishDateFrom != null">
        AND r.created_at &gt;= #{publishDateFrom}
      </if>
      <if test="publishDateTo != null">
        AND r.created_at &lt; #{publishDateTo}
      </if>
      <if test="requirementState != null and requirementState.length() &gt; 0">
        AND r.rqrmnt_state = #{requirementState}
      </if>
    </where>
    ORDER BY r.created_at DESC
    <if test="page != null">
      LIMIT #{page.beginIndex},#{page.pageSize}
    </if>
  </select>
  <select id="selectModelListCount" parameterType="com.lightinit.hsdataplatform.model.admin.RequirementMicroappPagingSearchModel" resultType="java.lang.Long">
    <if test="requirementName != null and requirementName.length() &gt; 0">
      <bind name="requirementName" value="'%' + _parameter.requirementName + '%'" />
    </if>
    SELECT count(*)
    FROM requirement r
    INNER JOIN requirement_microapp rm ON r.id=rm.id
    <where>
      <if test="requirementType != null and requirementType.length() &gt; 0">
        AND r.rqrmnt_type = #{requirementType}
      </if>
      <if test="requirementName != null and requirementName.length() &gt; 0">
        AND r.rqrmnt_name like #{requirementName}
      </if>
      <if test="publishDateFrom != null">
        AND r.created_at &gt;= #{publishDateFrom}
      </if>
      <if test="publishDateTo != null">
        AND r.created_at &lt; #{publishDateTo}
      </if>
      <if test="requirementState != null and requirementState.length() &gt; 0">
        AND r.rqrmnt_state = #{requirementState}
      </if>
    </where>
  </select>

  <!--sun-->
  <select id="getModelDetail" parameterType="long" resultType="com.lightinit.hsdataplatform.model.admin.RequirementMicroappDataModel">
    SELECT r.id AS rqrmnt_id,r.rqrmnt_name,r.rqrmnt_summary,r.created_at,r.rqrmnt_state,r.platform_type
    ,rm.money,rm.deadline,rm.contact,rm.phone,rm.category_id,rc.catelog_name,r.publish_by,u.username AS publish_byString,rm.email,r.audit_opinion,r.audited_by,a.showname,a.username,r.publish_at,r.audited_at
    FROM requirement r
    INNER JOIN requirement_microapp rm ON r.id=rm.id
    LEFT JOIN resource_catelog rc ON rc.id=rm.category_id
    LEFT JOIN USER u ON u.id=r.publish_by
    LEFT JOIN admin a ON a.id=r.audited_by
    <where>
      <if test="rqrmntId !=null" >
         r.id=#{rqrmntId}
      </if>
      <if test="rqrmntId ==null">
        1=2
      </if>
    </where>
  </select>
  <select id="selectByBaseExample" parameterType="com.lightinit.hsdataplatform.entity.BaseExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from requirement
    <include refid="Common.Example_Where_Clause" />
  </select>
  <select id="countByBaseExample" parameterType="com.lightinit.hsdataplatform.entity.BaseExample" resultType="java.lang.Long">
    select count(*) from requirement
      <include refid="Common.Example_Where_Clause" />
  </select>

  <select id="getSectorParentNames" resultType="map">
    SELECT s.id AS sectorId,s.sector_name AS sectorName FROM sector s WHERE s.parent_id IS null
  </select>
</mapper>