<?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.RequirementDataMapper">
    <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.RequirementData">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="data_uses" jdbcType="VARCHAR" property="dataUses"/>
        <result column="sector_id" jdbcType="BIGINT" property="sectorId"/>
        <result column="rqrmnt_sector_id" jdbcType="BIGINT" property="rqrmntSectorId"/>
        <result column="data_add_mode" jdbcType="VARCHAR" property="dataAddMode"/>
        <result column="feedback_at" jdbcType="TIMESTAMP" property="feedbackAt"/>
        <result column="feedback_by" jdbcType="BIGINT" property="feedbackBy"/>
        <result column="feedback_result" jdbcType="VARCHAR" property="feedbackResult"/>
        <result column="feedback_desc" jdbcType="VARCHAR" property="feedbackDesc"/>
        <result column="data_publish_url" jdbcType="VARCHAR" property="dataPublishUrl"/>
        <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 id="ResultMapWithSupply" type="com.lightinit.hsdataplatform.entity.RequirementDataSupply">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="platform_type" jdbcType="VARCHAR" property="platformType" />
        <result column="rqrmnt_state" jdbcType="VARCHAR" property="rqrmntState" />
        <result column="rqrmnt_name" jdbcType="VARCHAR" property="requirementName"/>
        <result column="rqrmnt_summary" jdbcType="VARCHAR" property="requirementSummary"/>
        <result column="rqrmnt_source" jdbcType="VARCHAR" property="requirementSource"/>
        <result column="audited_by" jdbcType="VARCHAR" property="auditUserId"/>
        <result column="audit_showname" jdbcType="VARCHAR" property="auditShownName"/>
        <result column="audit_result" jdbcType="VARCHAR" property="auditResult"/>
        <result column="audit_opinion" jdbcType="VARCHAR" property="auditOpinion"/>
        <result column="audited_at" jdbcType="TIMESTAMP" property="auditDate"/>
        <result column="publish_at" jdbcType="TIMESTAMP" property="publishAt"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="rqrmnt_userid" jdbcType="BIGINT" property="rqrmntUseriId"/>
        <result column="rqrmnt_username" jdbcType="VARCHAR" property="rqrmntUserName"/>
        <result column="rqrmnt_user_showname" jdbcType="VARCHAR" property="rqrmntUserShowName"/>

        <result column="belongto_sectorid" jdbcType="BIGINT" property="belongtoSectorId"/>
        <result column="belogngto_sectorname" jdbcType="VARCHAR" property="belongtoSectorName"/>


        <result column="rqrmnt_sector_id" jdbcType="BIGINT" property="rqrmntSectorId"/>
        <result column="rqrmnt_sectorname" jdbcType="VARCHAR" property="rqrmntSectorName"/>

        <result column="feedback_org" jdbcType="VARCHAR" property="feedbackOrg"/>
        <result column="feedback_sector" jdbcType="VARCHAR" property="feedbackSector"/>

        <result column="feedback_result" jdbcType="VARCHAR" property="feedbackResult"/>
        <result column="feedback_desc" jdbcType="VARCHAR" property="feedbackDesc"/>
        <result column="data_uses" jdbcType="VARCHAR" property="dataUses"/>
        <result column="feedback_userid" jdbcType="BIGINT" property="feedbackUserId"/>
        <result column="feedback_username" jdbcType="VARCHAR" property="feedbackUserName"/>
        <result column="feedback_showname" jdbcType="VARCHAR" property="feedbackShowName"/>
        <result column="feedback_at" jdbcType="TIMESTAMP" property="feedbackDate"/>

    </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, data_uses, sector_id, rqrmnt_sector_id, data_add_mode, feedback_at, feedback_by, 
    feedback_result, feedback_desc, data_publish_url, created_at, created_by, deleted_at, 
    deleted_by
  </sql>
    <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.RequirementDataExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from requirement_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="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from requirement_data
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from requirement_data
    where id = #{id,jdbcType=BIGINT}
  </delete>
    <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.RequirementDataExample">
        delete from requirement_data
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.RequirementData">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into requirement_data (data_uses, sector_id, rqrmnt_sector_id,
        data_add_mode, feedback_at, feedback_by,
        feedback_result, feedback_desc, data_publish_url,
        created_at, created_by, deleted_at,
        deleted_by)
        values (#{dataUses,jdbcType=VARCHAR}, #{sectorId,jdbcType=BIGINT}, #{rqrmntSectorId,jdbcType=BIGINT},
        #{dataAddMode,jdbcType=VARCHAR}, #{feedbackAt,jdbcType=TIMESTAMP}, #{feedbackBy,jdbcType=BIGINT},
        #{feedbackResult,jdbcType=VARCHAR}, #{feedbackDesc,jdbcType=VARCHAR}, #{dataPublishUrl,jdbcType=VARCHAR},
        #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{deletedAt,jdbcType=TIMESTAMP},
        #{deletedBy,jdbcType=BIGINT})
    </insert>
    <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.RequirementData">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into requirement_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataUses != null">
                data_uses,
            </if>
            <if test="sectorId != null">
                sector_id,
            </if>
            <if test="rqrmntSectorId != null">
                rqrmnt_sector_id,
            </if>
            <if test="dataAddMode != null">
                data_add_mode,
            </if>
            <if test="feedbackAt != null">
                feedback_at,
            </if>
            <if test="feedbackBy != null">
                feedback_by,
            </if>
            <if test="feedbackResult != null">
                feedback_result,
            </if>
            <if test="feedbackDesc != null">
                feedback_desc,
            </if>
            <if test="dataPublishUrl != null">
                data_publish_url,
            </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="dataUses != null">
                #{dataUses,jdbcType=VARCHAR},
            </if>
            <if test="sectorId != null">
                #{sectorId,jdbcType=BIGINT},
            </if>
            <if test="rqrmntSectorId != null">
                #{rqrmntSectorId,jdbcType=BIGINT},
            </if>
            <if test="dataAddMode != null">
                #{dataAddMode,jdbcType=VARCHAR},
            </if>
            <if test="feedbackAt != null">
                #{feedbackAt,jdbcType=TIMESTAMP},
            </if>
            <if test="feedbackBy != null">
                #{feedbackBy,jdbcType=BIGINT},
            </if>
            <if test="feedbackResult != null">
                #{feedbackResult,jdbcType=VARCHAR},
            </if>
            <if test="feedbackDesc != null">
                #{feedbackDesc,jdbcType=VARCHAR},
            </if>
            <if test="dataPublishUrl != null">
                #{dataPublishUrl,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>
        </trim>
    </insert>
    <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.RequirementDataExample">
        select count(*) from requirement_data
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update requirement_data
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=BIGINT},
            </if>
            <if test="record.dataUses != null">
                data_uses = #{record.dataUses,jdbcType=VARCHAR},
            </if>
            <if test="record.sectorId != null">
                sector_id = #{record.sectorId,jdbcType=BIGINT},
            </if>
            <if test="record.rqrmntSectorId != null">
                rqrmnt_sector_id = #{record.rqrmntSectorId,jdbcType=BIGINT},
            </if>
            <if test="record.dataAddMode != null">
                data_add_mode = #{record.dataAddMode,jdbcType=VARCHAR},
            </if>
            <if test="record.feedbackAt != null">
                feedback_at = #{record.feedbackAt,jdbcType=TIMESTAMP},
            </if>
            <if test="record.feedbackBy != null">
                feedback_by = #{record.feedbackBy,jdbcType=BIGINT},
            </if>
            <if test="record.feedbackResult != null">
                feedback_result = #{record.feedbackResult,jdbcType=VARCHAR},
            </if>
            <if test="record.feedbackDesc != null">
                feedback_desc = #{record.feedbackDesc,jdbcType=VARCHAR},
            </if>
            <if test="record.dataPublishUrl != null">
                data_publish_url = #{record.dataPublishUrl,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>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update requirement_data
        set id = #{record.id,jdbcType=BIGINT},
        data_uses = #{record.dataUses,jdbcType=VARCHAR},
        sector_id = #{record.sectorId,jdbcType=BIGINT},
        rqrmnt_sector_id = #{record.rqrmntSectorId,jdbcType=BIGINT},
        data_add_mode = #{record.dataAddMode,jdbcType=VARCHAR},
        feedback_at = #{record.feedbackAt,jdbcType=TIMESTAMP},
        feedback_by = #{record.feedbackBy,jdbcType=BIGINT},
        feedback_result = #{record.feedbackResult,jdbcType=VARCHAR},
        feedback_desc = #{record.feedbackDesc,jdbcType=VARCHAR},
        data_publish_url = #{record.dataPublishUrl,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.hsdataplatform.entity.RequirementData">
        update requirement_data
        <set>
            <if test="dataUses != null">
                data_uses = #{dataUses,jdbcType=VARCHAR},
            </if>
            <if test="sectorId != null">
                sector_id = #{sectorId,jdbcType=BIGINT},
            </if>
            <if test="rqrmntSectorId != null">
                rqrmnt_sector_id = #{rqrmntSectorId,jdbcType=BIGINT},
            </if>
            <if test="dataAddMode != null">
                data_add_mode = #{dataAddMode,jdbcType=VARCHAR},
            </if>
            <if test="feedbackAt != null">
                feedback_at = #{feedbackAt,jdbcType=TIMESTAMP},
            </if>
            <if test="feedbackBy != null">
                feedback_by = #{feedbackBy,jdbcType=BIGINT},
            </if>
            <if test="feedbackResult != null">
                feedback_result = #{feedbackResult,jdbcType=VARCHAR},
            </if>
            <if test="feedbackDesc != null">
                feedback_desc = #{feedbackDesc,jdbcType=VARCHAR},
            </if>
            <if test="dataPublishUrl != null">
                data_publish_url = #{dataPublishUrl,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>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.RequirementData">
    update requirement_data
    set data_uses = #{dataUses,jdbcType=VARCHAR},
      sector_id = #{sectorId,jdbcType=BIGINT},
      rqrmnt_sector_id = #{rqrmntSectorId,jdbcType=BIGINT},
      data_add_mode = #{dataAddMode,jdbcType=VARCHAR},
      feedback_at = #{feedbackAt,jdbcType=TIMESTAMP},
      feedback_by = #{feedbackBy,jdbcType=BIGINT},
      feedback_result = #{feedbackResult,jdbcType=VARCHAR},
      feedback_desc = #{feedbackDesc,jdbcType=VARCHAR},
      data_publish_url = #{dataPublishUrl,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="selectModelList" parameterType="com.lightinit.hsdataplatform.model.admin.DataSupplyPagingSearchModel"
            resultMap="ResultMapWithSupply">
        <if test="belongtoSectorName != null and belongtoSectorName.length() &gt; 0">
            <bind name="belongtoSectorName" value="'%' + _parameter.belongtoSectorName + '%'"/>
        </if>
        <if test="rqrmntSectorName != null and rqrmntSectorName.length() &gt; 0">
            <bind name="rqrmntSectorName" value="'%' + _parameter.rqrmntSectorName + '%'"/>
        </if>
        select A.* from(
              SELECT
            r.id,
            r.platform_type ,
            r.rqrmnt_state ,
            r.rqrmnt_name ,
            r.rqrmnt_summary ,
            r.rqrmnt_source,
            r.audited_by ,
            ra.showname audit_showname,
            r.audit_result ,
            r.audit_opinion ,
            r.audited_at,
            r.created_at,
            r.publish_at,
            r.publish_by rqrmnt_userid,
            u.username rqrmnt_username,

            rd.sector_id belongto_sectorid,
            bs.sector_name belogngto_sectorname ,

            rd.rqrmnt_sector_id,
            rs.sector_name rqrmnt_sectorname,

            o.org_name feedback_org,
            os.sector_name feedback_sector,

            rd.feedback_result,
            rd.feedback_desc,
            rd.data_uses,
            rd.feedback_by feedback_userid,
            fba.username feedback_username,
            fba.showname feedback_showname,
            rd.feedback_at


            FROM requirement_data rd
            INNER JOIN requirement r
            ON rd.id = r.id
            LEFT JOIN admin ra
            ON r.audited_by=ra.id

            LEFT JOIN sector bs
            ON rd.sector_id = bs.id
            LEFT JOIN sector rs
            ON rd.rqrmnt_sector_id=rs.id
            LEFT JOIN admin fba
            ON rd.feedback_by = fba.id
            LEFT JOIN organization o
            ON fba.org_id=o.id
            LEFT JOIN sector os
            ON o.sector_id=os.id

            LEFT JOIN admin u
            ON r.publish_by=u.id
            where r.platform_type=#{backType}

      UNION
            SELECT
            r.id,
            r.platform_type ,
            r.rqrmnt_state ,
            r.rqrmnt_name ,
            r.rqrmnt_summary ,
            r.rqrmnt_source,
            r.audited_by ,
            ra.showname audit_showname,
            r.audit_result ,
            r.audit_opinion ,
            r.audited_at,
            r.created_at,
            r.publish_at,
            r.publish_by rqrmnt_userid,
            u.username rqrmnt_username,

            rd.sector_id belongto_sectorid,
            bs.sector_name belogngto_sectorname ,

            rd.rqrmnt_sector_id,
            rs.sector_name rqrmnt_sectorname,

            o.org_name feedback_org,
            os.sector_name feedback_sector,

            rd.feedback_result,
            rd.feedback_desc,
            rd.data_uses,
            rd.feedback_by feedback_userid,
            fba.username feedback_username,
            fba.showname feedback_showname,
            rd.feedback_at


            FROM requirement_data rd
            INNER JOIN requirement r
            ON rd.id = r.id
            LEFT JOIN admin ra
            ON r.audited_by=ra.id

            LEFT JOIN sector bs
            ON rd.sector_id = bs.id
            LEFT JOIN sector rs
            ON rd.rqrmnt_sector_id=rs.id
            LEFT JOIN admin fba
            ON rd.feedback_by = fba.id
            LEFT JOIN organization o
            ON fba.org_id=o.id
            LEFT JOIN sector os
            ON o.sector_id=os.id

            LEFT JOIN USER u
            ON r.publish_by=u.id
            LEFT JOIN user_personal up
            ON up.id=u.id  where r.platform_type=#{openType}
      UNION
            SELECT
            r.id,
            r.platform_type ,
            r.rqrmnt_state ,
            r.rqrmnt_name ,
            r.rqrmnt_summary ,
            r.rqrmnt_source,
            r.audited_by ,
            ra.showname audit_showname,
            r.audit_result ,
            r.audit_opinion ,
            r.audited_at,
            r.created_at,
            r.publish_at,
            r.publish_by rqrmnt_userid,
            u.username rqrmnt_username,

            rd.sector_id belongto_sectorid,
            bs.sector_name belogngto_sectorname ,

            rd.rqrmnt_sector_id,
            rs.sector_name rqrmnt_sectorname,

            o.org_name feedback_org,
            os.sector_name feedback_sector,

            rd.feedback_result,
            rd.feedback_desc,
            rd.data_uses,
            rd.feedback_by feedback_userid,
            fba.username feedback_username,
            fba.showname feedback_showname,
            rd.feedback_at


            FROM requirement_data rd
            INNER JOIN requirement r
            ON rd.id = r.id
            LEFT JOIN admin ra
            ON r.audited_by=ra.id

            LEFT JOIN sector bs
            ON rd.sector_id = bs.id
            LEFT JOIN sector rs
            ON rd.rqrmnt_sector_id=rs.id
            LEFT JOIN admin fba
            ON rd.feedback_by = fba.id
            LEFT JOIN organization o
            ON fba.org_id=o.id
            LEFT JOIN sector os
            ON o.sector_id=os.id
            LEFT JOIN admin u
            ON r.publish_by=u.id where r.platform_type=#{shareType}) A
            <if test="userId !=null">
                LEFT JOIN sector s ON s.id=A.belongto_sectorid
                LEFT JOIN admin aa ON aa.org_id=s.id
            </if>
        <where>
            <if test="userId !=null">
                AND aa.id=#{userId}
            </if>
            <if test="id!=0">
                AND A.id = #{id}
            </if>
            <if test="belongtoSectorId != null">
                AND A.belongto_sectorid= #{belongtoSectorId}
            </if>
            <if test="belongtoSectorName != null and belongtoSectorName.length() &gt; 0">
                AND A.belogngto_sectorname like #{belongtoSectorName}
            </if>
            <if test="rqrmntSectorId != null">
                AND A.rqrmnt_sector_id= #{rqrmntSectorId}
            </if>
            <if test="rqrmntSectorName != null and rqrmntSectorName.length() &gt; 0">
                AND A.sector_name like #{rqrmntSectorName}
            </if>
            <if test="requirementSource != null and requirementSource.length() &gt; 0">
                AND A.platform_type = #{requirementSource}
            </if>
            <if test="requirementState != null and requirementState.length() &gt; 0">
                AND A.rqrmnt_state = #{requirementState}
            </if>
            <if test="publishDateFrom != null">
                AND A.created_at &gt;= #{publishDateFrom}
            </if>
            <if test="publishDateTo != null">
                AND A.created_at &lt; #{publishDateTo}
            </if>
        </where>
        ORDER BY A.id DESC
        <if test="page != null">
            LIMIT #{page.beginIndex},#{page.pageSize}
        </if>
    </select>
    <select id="selectModelListCount"
            parameterType="com.lightinit.hsdataplatform.model.admin.DataSupplyPagingSearchModel"
            resultType="java.lang.Long">
        <if test="belongtoSectorName != null and belongtoSectorName.length() &gt; 0">
            <bind name="belongtoSectorName" value="'%' + _parameter.belongtoSectorName + '%'"/>
        </if>
        <if test="rqrmntSectorName != null and rqrmntSectorName.length() &gt; 0">
            <bind name="rqrmntSectorName" value="'%' + _parameter.rqrmntSectorName + '%'"/>
        </if>
        SELECT COUNT(*) FROM
        (SELECT A.* FROM(
        SELECT
        r.id,
        r.platform_type ,
        r.rqrmnt_state ,
        r.rqrmnt_name ,
        r.rqrmnt_summary ,
        r.rqrmnt_source,
        r.audited_by ,
        ra.showname audit_showname,
        r.audit_result ,
        r.audit_opinion ,
        r.audited_at,
        r.created_at,
        r.publish_at,
        r.publish_by rqrmnt_userid,
        u.username rqrmnt_username,

        rd.sector_id belongto_sectorid,
        bs.sector_name belogngto_sectorname ,

        rd.rqrmnt_sector_id,
        rs.sector_name rqrmnt_sectorname,

        o.org_name feedback_org,
        os.sector_name feedback_sector,

        rd.feedback_result,
        rd.feedback_desc,
        rd.data_uses,
        rd.feedback_by feedback_userid,
        fba.username feedback_username,
        fba.showname feedback_showname,
        rd.feedback_at


        FROM requirement_data rd
        INNER JOIN requirement r
        ON rd.id = r.id
        LEFT JOIN admin ra
        ON r.audited_by=ra.id

        LEFT JOIN sector bs
        ON rd.sector_id = bs.id
        LEFT JOIN sector rs
        ON rd.rqrmnt_sector_id=rs.id
        LEFT JOIN admin fba
        ON rd.feedback_by = fba.id
        LEFT JOIN organization o
        ON fba.org_id=o.id
        LEFT JOIN sector os
        ON o.sector_id=os.id

        LEFT JOIN admin u
        ON r.publish_by=u.id
        where r.platform_type=#{backType}

        UNION

        SELECT
        r.id,
        r.platform_type ,
        r.rqrmnt_state ,
        r.rqrmnt_name ,
        r.rqrmnt_summary ,
        r.rqrmnt_source,
        r.audited_by ,
        ra.showname audit_showname,
        r.audit_result ,
        r.audit_opinion ,
        r.audited_at,
        r.created_at,
        r.publish_at,
        r.publish_by rqrmnt_userid,
        u.username rqrmnt_username,

        rd.sector_id belongto_sectorid,
        bs.sector_name belogngto_sectorname ,

        rd.rqrmnt_sector_id,
        rs.sector_name rqrmnt_sectorname,

        o.org_name feedback_org,
        os.sector_name feedback_sector,

        rd.feedback_result,
        rd.feedback_desc,
        rd.data_uses,
        rd.feedback_by feedback_userid,
        fba.username feedback_username,
        fba.showname feedback_showname,
        rd.feedback_at


        FROM requirement_data rd
        INNER JOIN requirement r
        ON rd.id = r.id
        LEFT JOIN admin ra
        ON r.audited_by=ra.id

        LEFT JOIN sector bs
        ON rd.sector_id = bs.id
        LEFT JOIN sector rs
        ON rd.rqrmnt_sector_id=rs.id
        LEFT JOIN admin fba
        ON rd.feedback_by = fba.id
        LEFT JOIN organization o
        ON fba.org_id=o.id
        LEFT JOIN sector os
        ON o.sector_id=os.id

        LEFT JOIN USER u
        ON r.publish_by=u.id
        LEFT JOIN user_personal up
        ON up.id=u.id  WHERE r.platform_type=#{openType}

        UNION

        SELECT
        r.id,
        r.platform_type ,
        r.rqrmnt_state ,
        r.rqrmnt_name ,
        r.rqrmnt_summary ,
        r.rqrmnt_source,
        r.audited_by ,
        ra.showname audit_showname,
        r.audit_result ,
        r.audit_opinion ,
        r.audited_at,
        r.created_at,
        r.publish_at,
        r.publish_by rqrmnt_userid,
        u.username rqrmnt_username,

        rd.sector_id belongto_sectorid,
        bs.sector_name belogngto_sectorname ,

        rd.rqrmnt_sector_id,
        rs.sector_name rqrmnt_sectorname,

        o.org_name feedback_org,
        os.sector_name feedback_sector,

        rd.feedback_result,
        rd.feedback_desc,
        rd.data_uses,
        rd.feedback_by feedback_userid,
        fba.username feedback_username,
        fba.showname feedback_showname,
        rd.feedback_at


        FROM requirement_data rd
        INNER JOIN requirement r
        ON rd.id = r.id
        LEFT JOIN admin ra
        ON r.audited_by=ra.id

        LEFT JOIN sector bs
        ON rd.sector_id = bs.id
        LEFT JOIN sector rs
        ON rd.rqrmnt_sector_id=rs.id
        LEFT JOIN admin fba
        ON rd.feedback_by = fba.id
        LEFT JOIN organization o
        ON fba.org_id=o.id
        LEFT JOIN sector os
        ON o.sector_id=os.id
        LEFT JOIN admin u
        ON r.publish_by=u.id WHERE r.platform_type=#{shareType}) A
        <if test="userId !=null">
            LEFT JOIN sector s ON s.id=A.belongto_sectorid
            LEFT JOIN admin aa ON aa.org_id=s.id
            where aa.id=#{userId}
        </if>
        ) B

        <where>
            <if test="id!=0">
                AND B.id = #{id}
            </if>
            <if test="belongtoSectorId != null">
                AND B.belongto_sectorid= #{belongtoSectorId}
            </if>
            <if test="belongtoSectorName != null and belongtoSectorName.length() &gt; 0">
                AND B.belogngto_sectorname like #{belongtoSectorName}
            </if>
            <if test="rqrmntSectorId != null">
                AND B.rqrmnt_sector_id= #{rqrmntSectorId}
            </if>
            <if test="rqrmntSectorName != null and rqrmntSectorName.length() &gt; 0">
                AND B.sector_name like #{rqrmntSectorName}
            </if>
            <if test="requirementSource != null and requirementSource.length() &gt; 0">
                AND B.platform_type = #{requirementSource}
            </if>
            <if test="requirementState != null and requirementState.length() &gt; 0">
                AND B.rqrmnt_state = #{requirementState}
            </if>
            <if test="publishDateFrom != null">
                AND B.created_at &gt;= #{publishDateFrom}
            </if>
            <if test="publishDateTo != null">
                AND B.created_at &lt; #{publishDateTo}
            </if>
        </where>
    </select>
    <!--<select id="selectModelListCount"
            parameterType="com.lightinit.hsdataplatform.model.admin.DataSupplyPagingSearchModel"
            resultType="java.lang.Long">
        <if test="belongtoSectorName != null and belongtoSectorName.length() &gt; 0">
            <bind name="belongtoSectorName" value="'%' + _parameter.belongtoSectorName + '%'"/>
        </if>
        <if test="rqrmntSectorName != null and rqrmntSectorName.length() &gt; 0">
            <bind name="rqrmntSectorName" value="'%' + _parameter.rqrmntSectorName + '%'"/>
        </if>
        SELECT COUNT(*)
        FROM requirement_data rd
        INNER JOIN requirement r
        ON rd.id = r.id
        LEFT JOIN admin ra
        ON r.audited_by=ra.id
        LEFT JOIN admin rqa
        ON r.publish_by=rqa.id
        LEFT JOIN sector bs
        ON rd.sector_id = bs.id
        LEFT JOIN sector rs
        ON rd.rqrmnt_sector_id=rs.id
        LEFT JOIN admin fba
        ON rd.feedback_by = fba.id
        LEFT JOIN organization o
        ON fba.org_id=o.id
        LEFT JOIN sector os
        ON o.sector_id=os.id


        <where>
            <if test="id!=0">
                AND r.id = #{id}
            </if>
            <if test="belongtoSectorId != null">
                AND rd.sector_id= #{belongtoSectorId}
            </if>
            <if test="belongtoSectorName != null and belongtoSectorName.length() &gt; 0">
                AND bs.sector_name like #{belongtoSectorName}
            </if>
            <if test="rqrmntSectorId != null">
                AND rd.rqrmnt_sector_id= #{rqrmntSectorId}
            </if>
            <if test="rqrmntSectorName != null and rqrmntSectorName.length() &gt; 0">
                AND rs.sector_name like #{rqrmntSectorName}
            </if>
            <if test="requirementState != null and requirementState.length() &gt; 0">
                AND r.rqrmnt_state = #{requirementState}
            </if>
            <if test="publishDateFrom != null">
                AND r.publish_at &gt;= #{publishDateFrom}
            </if>
            <if test="publishDateTo != null">
                AND r.publish_at &lt; #{publishDateTo}
            </if>
        </where>
    </select>-->

    <insert id="insertRequirementDataId" parameterType="com.lightinit.hsdataplatform.entity.RequirementData">
        insert into requirement_data (id, data_uses, sector_id, rqrmnt_sector_id,
        data_add_mode, feedback_at, feedback_by,
        feedback_result, feedback_desc, data_publish_url,
        created_at, created_by, deleted_at,
        deleted_by)
        values (#{id}, #{dataUses,jdbcType=VARCHAR}, #{sectorId,jdbcType=BIGINT}, #{rqrmntSectorId,jdbcType=BIGINT},
        #{dataAddMode,jdbcType=VARCHAR}, #{feedbackAt,jdbcType=TIMESTAMP}, #{feedbackBy,jdbcType=BIGINT},
        #{feedbackResult,jdbcType=VARCHAR}, #{feedbackDesc,jdbcType=VARCHAR}, #{dataPublishUrl,jdbcType=VARCHAR},
        #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{deletedAt,jdbcType=TIMESTAMP},
        #{deletedBy,jdbcType=BIGINT})
    </insert>
</mapper>