<?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="cn.iocoder.yudao.module.knowledge.mapper.TRegulatoryFrameworkExecutionMapper">


    <select id="selectPageMonitor" parameterType="cn.iocoder.yudao.module.knowledge.controller.requestdto.MonitorRequestPage"
            resultType="cn.iocoder.yudao.module.knowledge.entity.TRegulatoryFrameworkExecution">
        SELECT
        t.id,
        t.CODE,
        t.NAME,
        t.state,
        t.descr,
        t.deleted,
        t.creator,
        t.creator_id,
        t.create_time,
        t.update_time,
        (((
        SELECT
        COUNT(*)
        FROM
        t_rfeu_task tr
        WHERE
        tr.rfec_id = t.id and tr.deleted =0
        AND tr.status = '2'
        )/(
        SELECT
        COUNT(*)
        FROM
        t_rfe_user tr
        WHERE
        tr.ref_code = t.id and tr.deleted =0
        ))* 100
        ) process_num
        FROM
        t_regulatory_framework_execution t
        WHERE
            t.deleted = 0
            <if test="monitorRequestPage.searchKey != '' and monitorRequestPage.searchKey != null">
                AND t.name LIKE CONCAT( '%',#{monitorRequestPage.searchKey}, '%')
            </if>
            <if test="monitorRequestPage.state != '' and monitorRequestPage.state != null">
                AND t.state = #{monitorRequestPage.state}
            </if>
          <if test="monitorRequestPage.bgnTime!=null and monitorRequestPage.bgnTime !=''">
              AND (t.create_time >= date_format(#{monitorRequestPage.bgnTime},'%y-%m-%d 00:00:00') and t.create_time <![CDATA[<=]]> date_format(#{monitorRequestPage.endTime},'%y-%m-%d 23:59:59'))
          </if>
        GROUP BY t.id
        ORDER BY t.create_time DESC

    </select>
    <select id="findTask" resultType="cn.iocoder.yudao.module.knowledge.entity.TRegulatoryFrameworkExecution">
        SELECT
            t.id,
            t.code,
            t.name,
            t.state,
            t.descr,
            t.deleted,
            t.creator,
            t.creator_id,
            t.create_time,
            t.update_time,
            trt.status,
            trt.id as taskId
        FROM
            t_regulatory_framework_execution t
          inner join  t_rfeu_task trt on t.id=rfec_id and trt.deleted=0
        WHERE
        t.deleted = 0 and trt.user_id = #{monitorRequestPage.userId}
        <if test="monitorRequestPage.searchKey != '' and monitorRequestPage.searchKey != null">
            AND t.name LIKE CONCAT( '%',#{monitorRequestPage.searchKey}, '%')
        </if>
        <if test="monitorRequestPage.state != '' and monitorRequestPage.state != null">
            AND trt.status = #{monitorRequestPage.state}
        </if>
        <if test="monitorRequestPage.bgnTime!=null and monitorRequestPage.bgnTime !=''">
            AND (t.create_time >= date_format(#{monitorRequestPage.bgnTime},'%y-%m-%d 00:00:00') and t.create_time <![CDATA[<=]]> date_format(#{monitorRequestPage.endTime},'%y-%m-%d 23:59:59'))
        </if>
        ORDER BY t.create_time DESC

    </select>
    <select id="findOwn" resultType="cn.iocoder.yudao.module.knowledge.entity.RfeuTaskContent">
            select  rrc.*,trc.file_name as fileName,trc.file_url as fileUrl  from
            r_rfeu_task_content rrc
            inner join t_rfeu_task trt on trt.id = rrc.task_id
            inner join t_rfe_content trc on trc.id =content_id
            where rrc.deleted = 0
            and  execution_id=#{executionId} and trt.user_id = #{userId}

    </select>

</mapper>

