package com.engine.htsc.workflow.util;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.comInfo.PropBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName WorkflowTodoUtil
 * @Description: 待办接口基础SQL
 * @Author K1810007
 * @Date 2022/7/15
 * @Version V1.0
 **/
public class WorkflowTodoUtil {

    /***
     * PC待办基础sql
     * @param useridAll
     * @return
     */
    public String getWorkflowTodoUnView(String useridAll,String excludeSqlWhere)
    {
        BaseBean bb = new BaseBean();
        String sql = "" ;
        try{
            //PC待办中的标准sql
            sql =   " select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark,\n" +
                    "        t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid," +
                    "        t2.receivedate||' '||t2.receivetime as receiveTime  \n" +
                    " from workflow_requestbase t1" +
                    " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid" +
                    " inner join workflow_base t3 on t1.workflowid=t3.id \n" +
                    " where t2.userid in (" + useridAll + ") " +
                    " and t2.usertype=0 \n" +
                    " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + "))) \n" +
                    " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='') \n" +
                    " and ((t2.isremark='0' and (t2.takisremark is null or t2.takisremark=0 )) or t2.isremark in('1','5','8','9','7','11')) \n" +
                    " and t2.islasttimes=1 " +
                    " and t2.isremark not in('5') \n" +
                    " and t2.isprocessed is null " +
                    " and t2.viewtype = '0' \n" +
                    " and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') and t1.currentnodetype = '3')) \n" +
                    " and (isprocessing = '' or isprocessing is null) " +
                    " and t3.isvalid in(1,3) " + excludeSqlWhere +
                    " and ( exists (select 1 from workflow_requestlog log where log.requestid=t2.requestid and log.logtype in ('0','2','i') ) or nvl(t1.notdraft,0)=1)\n" +
                    " and ((t2.isremark not in ('1','8','9')) or (t2.isremark = '1' and t2.takisremark = '2'))\n" ;

        }catch (Exception e){
            bb.infoLog("WorkflowTodoUtil","WorkflowTodoUtil-getWorkflowTodoUnView-e:"+e);
        }
        bb.infoLog("WorkflowTodoUtil","todounview:"+sql);
        return sql;
    }

    /***
     * PC联席负责人通知阅读待阅基础sql
     * @param useridAll
     * @return
     */
    public String getWorkflowNoticeUnView(String useridAll){

        BaseBean bb = new BaseBean();
        String sql = "" ;
        try{
            String lhlxfzr_nodenumber = new PropBean().getPropName("todo_lhlxfzr_nodenumber");
            String lhlxfzr_workflow = new PropBean().getPropName("todo_lhlxfzr_workflow");
            String addSqlWhere = "";
            if(!"".equals(lhlxfzr_workflow))
            {
                lhlxfzr_workflow = "'"+lhlxfzr_workflow.replace(",","','")+"'" ;
                addSqlWhere += " and t3.unnumber  in(" + lhlxfzr_workflow + ")  ";
            }

            if(!"".equals(lhlxfzr_nodenumber)){
                lhlxfzr_nodenumber = "'"+lhlxfzr_nodenumber.replace(",","','")+"'";
                addSqlWhere += " and t2.nodeid in( select id from workflow_nodebase where unnumber in("+lhlxfzr_nodenumber+") " + ")";
            }

            sql =" select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark, \n" +
                    " t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid," +
                    " t2.receivedate||' '||t2.receivetime as receiveTime \n" +
                    " from workflow_requestbase t1  \n" +
                    " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid" +
                    " inner join workflow_base t3 on t1.workflowid=t3.id \n" +
                    " where t2.userid in (" + useridAll + ") " +
                    " and t2.usertype=0 " +
                    " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + ")))   \n" +
                    " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='') " +
                    " and t2.preisremark in ('1','8','9','11') \n" +
                    " and t2.takisremark is null  " +
                    " and nvl(t1.isstopped,0) != 1  " +
                    " and t2.viewtype = '0'  " +
                    " and t2.islasttimes=1   \n" +
                    " and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') and t1.currentnodetype = '3')) \n" +
                    " and (isprocessing = '' or isprocessing is null)  " +
                    " and t3.isvalid in(1,3) " +
                    addSqlWhere ;

        }catch (Exception e){
            bb.infoLog("WorkflowTodoUtil","WorkflowTodoUtil-getWorkflowTodoUnView-e:"+e);
        }
        bb.infoLog("WorkflowTodoUtil","noticeunview:"+sql);
        return sql;

    }


    /***
     * PC在办基础sql
     * @param useridAll
     * @return
     */
    public String getWorkflowTodoView(String useridAll,String excludeSqlWhere)
    {
        BaseBean bb = new BaseBean();
        String sql = "" ;
        try{

            sql =   " select  t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark,\n" +
                    "         t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid," +
                    "         t2.receivedate||' '||t2.receivetime as receiveTime \n" +
                    " from workflow_requestbase t1 \n" +
                    " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid" +
                    " inner join workflow_base t3 on t1.workflowid=t3.id \n" +
                    " where t2.userid in (" + useridAll + ") " +
                    " and t2.usertype=0 \n" +
                    " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + "))) \n" +
                    " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='') \n" +
                    " and ((t2.isremark='0' and (t2.takisremark is null or t2.takisremark=0 )) or t2.isremark in('1','5','8','9','7','11')) \n" +
                    " and t2.islasttimes=1 " +
                    " and t2.viewtype != '0' \n" +
                    " and t2.isremark not in ('4','2')" +
                    " and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') and t1.currentnodetype = '3')) \n" +
                    " and (isprocessing = '' or isprocessing is null) " +
                    " and t3.isvalid in(1,3) " +
                    " and ( exists (select 1 from workflow_requestlog log where log.requestid=t2.requestid and log.logtype in ('0','2','i') ) or nvl(t1.notdraft,0)=1 )\n" +
                    " and not exists ( select 1 from uf_lcgzb t4 where t4.lcid=t1.requestid and lcdqzt=1 and gzr in (" + useridAll + ") ) \n" +
                    " and ( (t2.isremark not in ('1','8','9') )or (t2.isremark = '1' and t2.takisremark = '2' ) )\n" +
                    " and not exists( select 1 from workflow_attention q where exists( select id from workflow_attentionTypeSet r where r.showname='收文等待' and r.userid in(" + useridAll + ") and q.atypeid =  r.id ) and userid in(" + useridAll + ") and q.usertype=0 and q.requestid = t1.requestid) \n"+
                    excludeSqlWhere ;

        }catch (Exception e){
            bb.infoLog("WorkflowTodoUtil","WorkflowTodoUtil-getWorkflowTodoView-e:"+e);
        }
        bb.infoLog("WorkflowTodoUtil","noticeunview:"+sql);
        return sql;
    }


    /***
     *
     * @param useridAll
     * @return
     */
    public String getWorkflowNoticeView(String useridAll){
        BaseBean bb = new BaseBean();

        String sql = "" ;
        try{

            String lhlxfzr_nodenumber = new PropBean().getPropName("todo_lhlxfzr_nodenumber");
            String lhlxfzr_workflow = new PropBean().getPropName("todo_lhlxfzr_workflow");
            String addSqlWhere = "";
            if(!"".equals(lhlxfzr_workflow))
            {
                lhlxfzr_workflow = "'"+lhlxfzr_workflow.replace(",","','")+"'" ;
                addSqlWhere += " and t3.unnumber  in(" + lhlxfzr_workflow + ")  ";
            }

            if(!"".equals(lhlxfzr_nodenumber)){
                lhlxfzr_nodenumber = "'"+lhlxfzr_nodenumber.replace(",","','")+"'";
                addSqlWhere += " and t2.nodeid in( select id from workflow_nodebase where unnumber in("+lhlxfzr_nodenumber+") " + ")";
            }

            sql =" select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark, \n" +
                    " t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid,t2.receivedate||' '||t2.receivetime as receiveTime\n" +
                    " from workflow_requestbase t1" +
                    " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid" +
                    " inner join workflow_base t3 on t1.workflowid=t3.id \n" +
                    " where  t2.userid in (" + useridAll + ") " +
                    " and t2.usertype=0 " +
                    " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + ")))   \n" +
                    " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='') " +
                    " and t2.preisremark in ('1','8','9','11') \n" +
                    " and t2.takisremark is null  " +
                    " and nvl(t1.isstopped,0) != 1  " +
                    " and t2.islasttimes=1 "+
                    " and t2.viewtype != '0' " +
                    " and t2.isremark not in ('4','2')  \n" +
                    " and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') and t1.currentnodetype = '3')) \n" +
                    " and (isprocessing = '' or isprocessing is null)  " +
                    " and t3.isvalid in(1,3) " +
                    addSqlWhere  ;

        }catch (Exception e){
            bb.infoLog("WorkflowTodoUtil","WorkflowTodoUtil-getWorkflowNoticeView-e:"+e);
        }
        bb.infoLog("WorkflowTodoUtil","noticeview:"+sql);
        return sql;

    }


    /***
     * 移动端待办接口，包含：PC的待办+PC的在办
     * @param useridAll
     * @return
     */
    public String getWorkflowMobileTodoData(String useridAll,String excludeSqlWhere)
    {
        BaseBean bb = new BaseBean();
        String sql = "" ;
        try{

            String where =  " and not exists(" +
                            " select k.id \n" +
                            " from uf_yddbxdkjd t\n" +
                            " inner join workflow_base l on l.unnumber = t.lc\n" +
                            " inner join workflow_flownode p on p.workflowid = l.id\n" +
                            " inner join workflow_nodebase k on k.id = p.nodeid\n" +
                            " where instr(','||t.jd||',',','||k.unnumber||',') > 0 \n" +
                            " and k.id = t1.currentnodeid \n" +
                            ") ";


            sql =   " select t3.workflowname,t1.currentnodeid,\n" +
                    "        case when t1.currentnodeid > 0 then t4.nodename else t5.nodename end as nodename,\n" +
                    "        h1.lastname,t1.requestid,t1.requestname,t1.creater,\n" +
                    "        t1.workflowid,t1.requestmark,t1.requestlevel,t1.createdate,t1.createtime,\n" +
                    "        t2.receivedate||' '||t2.receivetime as receiveTime,t2.isremark,t2.userid,t2.islasttimes,\n" +
                    "        t3.isvalid,t2.takisremark \n" +
                    "  from workflow_requestbase t1\n" +
                    "  inner join workflow_currentoperator t2 on t1.requestid = t2.requestid\n" +
                    "  inner join workflow_base t3 on t1.workflowid = t3.id \n" +
                    "  left join workflow_nodebase t4  on t1.currentnodeid = t4.id\n" +
                    "  left join workflow_freenode t5  on t1.currentnodeid = t5.id\n" +
                    "  left join hrmresource h1 on h1.id = t2.userid\n" +
                    "  where t2.usertype = 0\n" +
                    "   and t2.userid in ("+useridAll+") " +
                    "   and (nvl(t1.currentstatus, -1) = -1 or (nvl(t1.currentstatus, -1) = 0 and t1.creater in ("+useridAll+")))\n" +
                    "   and (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" +
                    "   and ((t2.isremark = '0' and (t2.takisremark is null or t2.takisremark = '0')) or t2.isremark in ('1', '5', '8', '9', '7', '11'))\n" +
                    "   and t2.islasttimes = 1\n" +
                    "   and (t2.isprocessing = '' or t2.isprocessing is null)\n" +
                    "   and t3.isvalid in(1,3)  \n" +
                    "   and (exists( select 1 from workflow_requestlog log where log.requestid = t2.requestid and log.logtype in ('0', '2', 'i')) or nvl(t1.notdraft, 0) = 1)\n" +
                    "   and ((t2.isremark not in ('1','8','9')) or (t2.isremark = '1' and t2.takisremark = '2'))\n" +
                    excludeSqlWhere + where ;

        }catch (Exception e){
            bb.infoLog("WorkflowTodoUtil","WorkflowTodoUtil-getWorkflowMobileTodoData-e:"+e);
        }
        bb.infoLog("WorkflowTodoUtil","MobileTodoData:"+sql);
        return sql;
    }

    /***
     *  移动端联席负责人通知阅读的接口，包含：PC的待阅+PC的在阅
     * @param useridAll
     * @return
     */
    public String getWorkfloMobileNoticeData(String useridAll){
        String sql = "" ;
        BaseBean bb = new BaseBean();
        try{
            String lhlxfzr_nodenumber = new PropBean().getPropName("todo_lhlxfzr_nodenumber");
            String lhlxfzr_workflow = new PropBean().getPropName("todo_lhlxfzr_workflow");
            String addSqlWhere = "";
            if(!"".equals(lhlxfzr_workflow))
            {
                lhlxfzr_workflow = "'"+lhlxfzr_workflow.replace(",","','")+"'" ;
                addSqlWhere += " and t3.unnumber  in(" + lhlxfzr_workflow + ") \n";
            }

            if(!"".equals(lhlxfzr_nodenumber)){
                lhlxfzr_nodenumber = "'"+lhlxfzr_nodenumber.replace(",","','")+"'";
                addSqlWhere += " and t2.nodeid in( select id from workflow_nodebase where unnumber in("+lhlxfzr_nodenumber+") " + ") ";
            }

            sql =   " select t3.workflowname,\n" +
                    "        t1.currentnodeid,\n" +
                    "        case\n" +
                    "          when t1.currentnodeid > 0 then\n" +
                    "               t4.nodename\n" +
                    "           else\n" +
                    "               t5.nodename\n" +
                    "       end as nodename,\n" +
                    "       h1.lastname,\n" +
                    "       t1.requestid,\n" +
                    "       t1.requestname,\n" +
                    "       t1.creater,\n" +
                    "       t1.workflowid,\n" +
                    "       t1.requestmark,\n" +
                    "       t1.requestlevel,\n" +
                    "       t1.createdate,\n" +
                    "       t1.createtime,\n" +
                    "       t2.receivedate||' '||t2.receivetime as receiveTime,\n" +
                    "       t2.isremark,\n" +
                    "       t2.userid,\n" +
                    "       t2.islasttimes,\n" +
                    "       t3.isvalid,\n" +
                    "       t2.takisremark\n" +
                    " from workflow_requestbase t1  \n" +
                    " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid \n" +
                    " inner join workflow_base t3 on t1.workflowid=t3.id \n" +
                    " left join workflow_nodebase t4  on t1.currentnodeid = t4.id\n" +
                    " left join workflow_freenode t5  on t1.currentnodeid = t5.id\n" +
                    " left join hrmresource h1 on h1.id = t2.userid\n" +
                    " where t2.userid in (" + useridAll + ") " +
                    " and t2.usertype = 0 " +
                    " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + ")))   \n" +
                    " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='') " +
                    " and t2.preisremark in ('1','8','9','11') \n" +
                    " and t2.takisremark is null  \n" +
                    " and nvl(t1.isstopped,0) != 1  \n" +
                    " and t2.islasttimes=1  \n" +
                    " and (t2.viewtype = '0' or ( t2.viewtype != '0'  and t2.isremark not in ('4','2'))) \n" +
                    " and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') and t1.currentnodetype = '3')) \n" +
                    " and (isprocessing = '' or isprocessing is null)  \n" +
                    " and t3.isvalid in(1,3) \n" +
                    addSqlWhere ;

        }catch (Exception e){
            bb.infoLog("WorkflowTodoUtil","WorkflowTodoUtil-getWorkfloMobileNoticeData-e:"+e);
        }
        bb.infoLog("WorkflowTodoUtil","MobileTodoData:"+sql);
        return sql;

    }

    /***
     * 标签过滤
     * @param useridAll
     * @return
     */

    public List<String> queryLabelData(String useridAll){

        List<String> bqList = new ArrayList<String>();
        RecordSet rs = new RecordSet();

        try{
            String bqSql = "" ;
            String lxsql = " select unnumber,bq from uf_lcbqgl " ;
            rs.execute(lxsql);
            while (rs.next())
            {
                String unnumber = Util.null2String(rs.getString("unnumber"));
                String bq = Util.null2String(rs.getString("bq"));

                unnumber = "'"+unnumber.replace(",","','")+"'" ;
                bq = "'"+bq.replace(",","','")+"'" ;
                if(!"".equals(unnumber) && !"".equals(bq)){
                    bqSql += bqSql == "" ?
                            "    select t.requestid,k.workflowid\n" +
                                    "    from workflow_attention t\n" +
                                    "    inner join workflow_requestbase k on k.requestid = t.requestid\n" +
                                    "    inner join workflow_base d on d.id = k.workflowid\n" +
                                    "    where t.atypeid in(\n" +
                                    "        select id from workflow_attentionTypeSet where showname in("+bq+")\n" +
                                    "    )\n" +
                                    "    and t.userid in("+useridAll+")\n" +
                                    "    and d.unnumber in("+unnumber+")\n"
                            :
                            "    union all" +
                                    "    select t.requestid,k.workflowid\n" +
                                    "    from workflow_attention t\n" +
                                    "    inner join workflow_requestbase k on k.requestid = t.requestid\n" +
                                    "    inner join workflow_base d on d.id = k.workflowid\n" +
                                    "    where t.atypeid in(\n" +
                                    "        select id from workflow_attentionTypeSet where showname in("+bq+")\n" +
                                    "    )\n" +
                                    "    and t.userid in("+useridAll+")\n" +
                                    "    and d.unnumber in("+unnumber+")\n" ;
                }
            }

            if(!"".equals(bqSql)){
                String sql = " select p3.requestid from (" + bqSql + ") p3 ";
                rs.executeQuery(sql);
                while (rs.next()){
                    String requestid = Util.null2String(rs.getString("requestid"));
                    bqList.add(requestid);
                }
            }
        }catch (Exception e){

        }
        return bqList;
    }


    /***
     * 电子用印
     * @param useridAll
     * @return
     */
    public List<String> queryElectPrintData(String useridAll){
        List<String> dzyyList = new ArrayList<String>();
        RecordSet rs = new RecordSet();
        try{
            String dzyySql =" select l1.requestid from (\n" +
                    "    select t.requestid\n" +
                    "    from workflow_attention t\n" +
                    "    where t.atypeid in(\n" +
                    "        select id from workflow_attentionTypeSet where showname in('电子用印')\n" +
                    "    )\n" +
                    "    and t.userid in("+useridAll+")\n" +
                    ") l1 " ;
            rs.executeQuery(dzyySql);
            while(rs.next()){
                String requestid = Util.null2String(rs.getString("requestid"));
                dzyyList.add(requestid);
            }
        }catch (Exception e){

        }
        return dzyyList;
    }


    /***
     * 邮寄数据
     * @param useridAll
     * @return
     */
    public List<String> queryMailData(String useridAll){
        List<String> dzyyList = new ArrayList<String>();
        RecordSet rs = new RecordSet();
        try{
            String dzyySql =" select l1.requestid from (\n" +
                    "    select t.requestid\n" +
                    "    from workflow_attention t\n" +
                    "    where t.atypeid in(\n" +
                    "        select id from workflow_attentionTypeSet where showname in('邮寄')\n" +
                    "    )\n" +
                    "    and t.userid in("+useridAll+")\n" +
                    ") l1 " ;
            rs.executeQuery(dzyySql);
            while(rs.next()){
                String requestid = Util.null2String(rs.getString("requestid"));
                dzyyList.add(requestid);
            }
        }catch (Exception e){

        }
        return dzyyList;
    }


    /***
     *
     * @param useridAll
     * @param num
     * @return
     */
    public String queryNoticeUnReadData(String useridAll,String excludeSqlWhere,int num){

        String sql =" select * from ( " +
                " select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark,\n" +
                " t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid,t2.receivedate||' '||t2.receivetime as receiveTime \n" +
                " from workflow_requestbase t1,workflow_currentoperator t2,workflow_base t3   \n" +
                " where t1.requestid = t2.requestid \n" +
                " and t1.workflowid=t3.id \n" +
                " and t2.userid in (" + useridAll + ") and t2.usertype=0 \n" +
                " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + ")))   \n" +
                " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  \n" +
                " and t2.preisremark in ('1','8','9','11') \n" +
                " and t2.takisremark is null  and nvl(t1.isstopped,0) != 1  and t2.islasttimes=1 and t2.viewtype = '0' \n" +
                " and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') and t1.currentnodetype = '3')) \n" +
                " and (isprocessing = '' or isprocessing is null)  and t3.isvalid in(1,3) " + excludeSqlWhere +
                " order by t2.receivedate desc,t2.receivetime desc " +
                " ) where rownum<=" + num;

        return sql;
    }

    /***
     *
     * @param useridAll
     * @param excludeSqlWhere
     * @param num
     * @return
     */
    public String queryWorkflowShelveData(String useridAll,String excludeSqlWhere,int num){

        String sql =" select * from ( \n" +
                    " select gzr userid,t2.requestid,t2.workflowid,t3.workflowname,t2.requestname,t2.requestmark,\n" +
                    " t2.creater,t2.createdate, t2.createtime,t2.requestlevel,t2.currentnodeid,t1.gzrq||' '||t1.gzsj as receiveTime \n" +
                    " from workflow_requestbase t2\n" +
                    " inner join workflow_base t3 on t3.id = t2.workflowid\n" +
                    " left join uf_lcgzb t1 on t1.lcid = t2.requestid \n" +
                    " where gzr in ("+useridAll+") and lcdqzt = 1 " + excludeSqlWhere +
                    " order by t1.gzrq desc,t1.gzsj desc ) where  rownum<="+num;

        return sql;
    }



    public String queryWorkflowDraftData(String useridAll,String excludeSqlWhere,int num){

        String sql =" select * from ("+
                "select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark,\n" +
                "t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid,t1.createdate||' '||t1.createtime as receiveTime\n" +
                "from workflow_requestbase t1,workflow_currentoperator t2,workflow_base t3 \n" +
                "where t1.requestid = t2.requestid and t1.workflowid=t3.id \n" +
                "and t2.userid in ("+useridAll+" ) and t2.usertype=0 \n" +
                "and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in ("+useridAll+")))   \n" +
                "and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  \n" +
                "and t1.creater in ("+useridAll+") and t1.creatertype = 0 and t1.creater = t2.userid   \n" +
                "and (not exists (select 1 from workflow_requestlog wr where wr.logtype in ('0','2','i') and wr.requestid = t1.requestid  ) \n" +
                "and t1.currentnodetype != '3' ) and t3.isvalid in(1,3) "+excludeSqlWhere+" order by t1.createdate desc,t1.createtime desc " +
                ") where  rownum<="+num;

        return sql;
    }

    /***
     *
     * @param useridAll
     * @param excludeSqlWhere
     * @param num
     * @return
     */
    public String queryNoticeReadingData(String useridAll,String excludeSqlWhere,int num){

        String sql = "select * from ( \n" +
                " select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark,\n" +
                " t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid,t2.receivedate||' '||t2.receivetime as receiveTime \n" +
                " from workflow_requestbase t1,workflow_currentoperator t2,workflow_base t3   \n" +
                " where t1.requestid = t2.requestid and t1.workflowid=t3.id and t2.userid in (" + useridAll + " ) and t2.usertype=0 \n" +
                " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + ")))   \n" +
                " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  and t2.preisremark in ('1','8','9','11') \n" +
                " and t2.takisremark is null  and nvl(t1.isstopped,0) != 1  and t2.islasttimes=1   and t2.viewtype != '0'  \n" +
                " and t2.isremark not in ('4','2') and (t1.currentnodetype <> '3' or (t2.isremark in ('1', '8', '9','11') \n" +
                " and t1.currentnodetype = '3')) and (isprocessing = '' or isprocessing is null)  and t3.isvalid in(1,3) " + excludeSqlWhere +
                " order by t2.receivedate desc,t2.receivetime desc \n" +
                " ) where rownum<=" + num;

        return sql;
    }

    /***
     *
     * @param useridAll
     * @param excludeSqlWhere
     * @param num
     * @return
     */
    public String queryNoticeReadedData(String useridAll,String excludeSqlWhere,int num){

        String sql =" select * from ( " +
                " select t2.userid,t1.workflowid,t1.requestid,t3.workflowname,t1.requestname,t1.requestmark,\n" +
                " t1.creater,t1.createdate, t1.createtime,t1.requestlevel,t1.currentnodeid,t2.receivedate||' '||t2.receivetime as receiveTime \n" +
                " from workflow_requestbase t1,workflow_currentoperator t2,workflow_base t3   \n" +
                " where t1.requestid = t2.requestid and t1.workflowid=t3.id and t2.userid in (" + useridAll + ") and t2.usertype=0 \n" +
                " and (nvl(t1.currentstatus,-1) = -1 or (nvl(t1.currentstatus,-1)=0 and t1.creater in (" + useridAll + ")))   \n" +
                " and (t1.deleted<>1 or t1.deleted is null or t1.deleted='')  and t2.preisremark in ('1','8','9','11') \n" +
                " and t2.takisremark is null  and nvl(t1.isstopped,0) != 1  and t2.islasttimes=1   and t2.isremark  in ('4','2')  \n" +
                " and (isprocessing = '' or isprocessing is null)  and t3.isvalid in(1,3) " + excludeSqlWhere +
                " order by t2.receivedate desc,t2.receivetime desc " +
                " ) where rownum<=" + num;


        return sql;
    }

}
