package com.engine.htsc.workflow.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.service.impl.RequestBrowserService;
import weaver.conn.ConnStatement;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo;
import weaver.system.RequestDefaultComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.HEAD;
import java.util.*;

public class WorkflowUtil {


    /**
     * 生成更新Sql
     * @param tableName
     * @param sqlWhere
     * @return
     */
    public static Map<String, Object> getUpdateExcuteSql(String tableName, String sqlWhere, JSONArray dataArray){
        String updateSql = " update "+tableName+" set ";
        Map<String, Object> resultMap = new HashMap<String, Object>();

        List<String> valueList = new ArrayList<String>();
        int dataSize = dataArray.size();
        for(int i=0;i<dataSize;i++){
            JSONObject fieldJson = dataArray.getJSONObject(i);

            String fieldName = Util.null2String(fieldJson.getString("fieldName"));
            String fieldValue = Util.null2String(fieldJson.getString("fieldValue"));
            valueList.add(fieldValue);

            if(i==(dataSize-1)){
                updateSql += fieldName+"=? ";
            }else{
                updateSql += fieldName+"=?, ";
            }
        }
        updateSql += sqlWhere;

        resultMap.put("updateSql",updateSql);
        resultMap.put("fieldValue",valueList);

        return resultMap;
    }

    /**
     * 获取更新数据的键值对数组
     * @param dataArray
     * @return
     */
    public static Map<String, List<String>> getFiledKeyValueMap(JSONArray dataArray){
        Map<String,List<String>> dataMap = new HashMap<String,List<String>>();


        if(dataArray!=null && dataArray.size()>0){


            List<String> keyList = new ArrayList<String>();
            List<String> valueList = new ArrayList<String>();

            for(int i=0;i<dataArray.size();i++){
                JSONObject fieldJson = dataArray.getJSONObject(i);

                String fieldName = Util.null2String(fieldJson.getString("fieldName"));
                keyList.add(fieldName);

                String fieldValue = Util.null2String(fieldJson.getString("fieldValue"));
                valueList.add(fieldValue);


            }
            dataMap.put("fieldName",keyList);
            dataMap.put("fieldValue",valueList);
        }

        return dataMap;
    }

    /**
     * 生成sql占位符
     * @param size
     * @return
     */
    public static String createPlaceHolder(int size){
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<size;i++){
            if(i==(size-1)){
                sb.append("?");
            }else{
                sb.append("?,");
            }
        }
        return sb.toString();
    }


    public static List<SearchConditionOption> getSelectOptions(String fieldid){
        List<SearchConditionOption> selectOptions = new ArrayList <>();  //设置选项值
        RecordSet rs = new RecordSet();
        rs.executeQuery(" select selectname,selectvalue from workflow_selectitem where fieldid=? ", new Object[]{fieldid});
        while(rs.next()){
            String selectname = Util.null2String(rs.getString("selectname"));
            String selectvalue = Util.null2String(rs.getString("selectvalue"));
            selectOptions.add(new SearchConditionOption(selectvalue,selectname));
        }
        return selectOptions;
    }

    /**
     * 获取附件下载链接HTML
     * @param fileids
     * @return
     */
    public static String getDocFileHtml(String ismobile,String fileids,String requestid,
                                        String authStr,String authSignatureStr, String f_weaver_belongto_userid){

        String ecologyContentPath = GCONST.getContextPath();
        String docFileHtml = "<div class=\"space-line\"></div>";
        String fileidArr[] = fileids.split(",");
        RecordSet rs = new RecordSet();
        for(int i=0;i<fileidArr.length;i++){
            String sql = " select imagefileid,imagefilename from docimagefile where docid=? ";
            rs.executeQuery(sql,new Object[]{fileidArr[i]});
            if(rs.next()){

                String imagefileid = Util.null2String(rs.getString("imagefileid"));
                String imagefilename = Util.null2String(rs.getString("imagefilename"));


                String href = ecologyContentPath+"/spa/document/index2file.jsp?f_weaver_belongto_userid="+f_weaver_belongto_userid+
                        "&id="+fileidArr[i]+"&imagefileId="+imagefileid+"&isrequest=1&requestid="+requestid+"&desrequestid=-1" +
                        "&authStr="+authStr+"&authSignatureStr="+authSignatureStr;

                if("1".equals(ismobile)){
                    href = ecologyContentPath+"/spa/document/static4mobile/index.html#/attach/"+imagefileid+"?authStr="+authStr+
                            "&authSignatureStr="+authSignatureStr+"&f_weaver_belongto_userid="+f_weaver_belongto_userid+"&f_weaver_belongto_usertype=0" +
                            "&isrequest=1&requestid="+requestid;
                }

                docFileHtml += "<div class=\"fj-item\"><i class=\"icon-coms-content-o\"></i><a target=\"_blank\" href=\""+href+"\">"+imagefilename+"</a></div>";
            }


        }
        return docFileHtml;
    }

    public String getRequestNameWithRemark(String requestnamenew,String otherparams){
        int requestid = Util.getIntValue(otherparams.substring(0, otherparams.indexOf("+")));
        RequestBrowserService requestBrowserService = new RequestBrowserService();
        String requestname = requestBrowserService.getRequestname(requestnamenew,otherparams);

        RecordSet rs = new RecordSet();
        rs.executeQuery(" select requestmark from workflow_requestbase where requestid=? ",new Object[]{requestid});
        if(rs.next()){
            String requestmark = Util.null2String(rs.getString("requestmark"));
            requestname = requestname+"("+requestmark+")";
        }
        return requestname;
    }

    /**
     * 根据部门id查询一级部门简称
     * @param deptid
     * @return
     */
    public static String getTopDeptShortName(String deptid){
        String shortName = "";
        String sql = " select deptid,cmpAbbre from hrmdepartment a,hrmdepartmentdefined b " +
                " where a.id=b.deptid and a.id in(select id from ( SELECT id,departmentname,supdepid,level " +
                "  FROM hrmdepartment " +
                " START WITH id=? "+
                " connect by nocycle prior supdepid=id ) " +
                " where supdepid is null or supdepid=0)  ";
        RecordSet rs = new RecordSet();
        rs.executeQuery(sql,new Object[]{deptid});
        if(rs.next()){
            shortName = Util.null2String(rs.getString("cmpAbbre"));
        }
        return shortName;
    }


    /**
     * 根据部门查询一级部门简称
     * @param deptid
     * @return
     */
    public static String getTopDeptShortNameNew(String deptid){
        String shortName = "";
        String sql = " select deptid,cmpAbbre from hrmdepartment a,hrmdepartmentdefined b " +
                " where a.id=b.deptid and a.id in(select id from ( SELECT id,departmentname,supdepid,level " +
                "  FROM hrmdepartment " +
                " START WITH id=? "+
                " connect by nocycle prior supdepid=id ) " +
                " where supdepid is null or supdepid=0)  ";
        RecordSet rs = new RecordSet();
        rs.executeQuery(sql,new Object[]{deptid});
        if(rs.next()){
            String cdeptid = Util.null2String(rs.getString("deptid"));
            shortName = Util.null2String(rs.getString("cmpAbbre"));
            if(deptid.equals(cdeptid)){
                shortName = "("+shortName+")";
            }else{
                DepartmentComInfo deptComInfo = new DepartmentComInfo();
                String deptname =  deptComInfo.getDepartmentname(deptid);
                if("".equals(shortName)){
                    shortName = "("+deptname+")";
                }else{
                    shortName = "("+shortName+"/"+deptname+")";
                }
            }
        }
        return shortName;
    }




    public static String getNodeName(String nodeid){
        String nodename = "";
        RecordSet rs = new RecordSet();
        String sql = " select nodename from workflow_nodebase where id=? ";
        rs.executeQuery(sql,new Object[]{nodeid});
        if(rs.next()){
            nodename = Util.null2String(rs.getString("nodename"));
        }else{
            sql = " select nodename from workflow_freenode where id=? ";
            rs.executeQuery(sql,new Object[]{nodeid});
            if(rs.next()){
                nodename = Util.null2String(rs.getString("nodename"));
            }

        }
        return nodename;
    }

    /**
     * 获取流程搁置状态
     * @return
     */
    public static int getShelveStatus(String requestid,User user){
        RecordSet rs =new RecordSet();
        Integer lcdqzt = 0;
        int uid = user.getUID();
        //获取流程搁置状态
        String useridAll = "";
        String account_type = user.getAccount_type();
        if (account_type.equals("1")){
            String sql = "select belongto from hrmresource where status < 4 and id ="+uid;

            rs.execute(sql);
            if (rs.next()){
                int belongto = Util.getIntValue(rs.getString("belongto"));
                User userNew = new User(belongto);
                useridAll = userNew.getUID() + "";
                String belongtoids = userNew.getBelongtoids();
                if (!"".equals(belongtoids)) {
                    useridAll += "," + belongtoids;
                }
            }
        }else {
            useridAll = user.getUID() + "";
            String belongtoids = user.getBelongtoids();
            if (!"".equals(belongtoids)) {
                useridAll += "," + belongtoids;
            }
        }


        String nodeStatusSql = "select lcdqzt from uf_lcgzb where lcid = "+requestid+" and dbms_lob.instr(gzczz, '"+useridAll+"', 1,1)>0";

        rs.execute(nodeStatusSql);
        if (rs.next()){
            lcdqzt = Util.getIntValue(rs.getString("lcdqzt"));
        }
        return  lcdqzt;
    }

    /**
     * 获取节点是否是指定处理人
     * @param requestid
     * @param nodeid
     * @return
     */
    public static boolean getAssignhandler(String requestid,int nodeid){
        boolean isAssignhandler = false;
        RecordSet rs = new RecordSet();
        rs.execute( " select zdry from uf_qzyjhqb where lcid ='"+ requestid +"' and zdry='"+nodeid+"'" );
        if(rs.next()){
            isAssignhandler = true;
        }
        return isAssignhandler;
    }


    /**
     * 获取流程终止状态
     * @param requestid
     * @return
     */
    public static String getWorkflowIsStop(String requestid){
        String isstopped = "";
        RecordSet rs = new RecordSet();
        rs.executeQuery(" select isstopped from workflow_requestbase where requestid=?  ",new Object[]{requestid});
        if(rs.next()){
            isstopped = Util.null2String(rs.getString("isstopped"));
        }
        return isstopped;
    }


    /**
     * 获取流程创建人相关信息（待扩展）
     * @param userid
     * @return
     */
    public static Map<String,Object> getWfCreateUserInfo(String userid){
        Map<String,Object> datamap = new HashMap<String,Object>();
        datamap.put("tlevel","");
        datamap.put("deptLevelCode","");
        if(userid != null && !"".equals(userid)){
            //获取人员的一级部门和一级部门名称
            RecordSet rs = new RecordSet();
            rs.executeQuery("   select b.*,deptscalelevelcode,depttypecode,parentsalecode,deptDirectors from hrmresource a, hrmdepartment b,hrmdepartmentdefined c " +
                    " where a.departmentid=b.id and b.id=c.deptid and a.id=? ",new Object[]{userid});
            if(rs.next()){
                String tlevel = Util.null2String(rs.getString("tlevel"));
                String deptLevelCode = Util.null2String(rs.getString("deptscalelevelcode"));
                String deptTypeCode = Util.null2String(rs.getString("depttypecode"));
                String parentsalecode = Util.null2String(rs.getString("parentsalecode"));
                String deptDirectors = Util.null2String(rs.getString("deptDirectors"));
                datamap.put("tlevel",tlevel);
                datamap.put("deptLevelCode",deptLevelCode);
                datamap.put("deptTypeCode",deptTypeCode);
                datamap.put("parentsalecode",parentsalecode);
                datamap.put("deptDirectors",getUserInfo(deptDirectors));

            }
        }
        return  datamap;

    }


    public static List<Map<String,String>> getUserInfo(String userids){
        List userList = new ArrayList();
        if(!"".equals(userids)){
            try {
                ResourceComInfo resourceComInfo = new ResourceComInfo();
                String userarr[] = userids.split(",");
                int length = userarr.length;
                for(int i=0;i<length;i++){
                    String lastname = resourceComInfo.getLastname(userarr[i]);
                    String seclevel = resourceComInfo.getSeclevel(userarr[i]);
                    String workcode = resourceComInfo.getWorkcode(userarr[i]);

                    Map<String,String> userInfo = new HashMap<String,String>();
                    userInfo.put("id",userarr[i]);
                    userInfo.put("name",lastname);
                    userInfo.put("seclevel",seclevel);
                    userInfo.put("workcode",workcode);
                    userList.add(userInfo);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return userList;
    }



    /**
     * 根据人员获取查询公文发起数据sql
     * @param userid
     * @return
     */
    public static String getOdocCreateDataSql(int userid,int type){
        String retSql = "";
        if(userid==1){//管理员可以发起所有流程
            retSql += " select * from uf_gwfq order by showorder ";
        }else {
            String sql = " select h.id,h.departmentid,d.depttypecode from hrmresource h " +
                    " left join hrmdepartmentdefined d on h.departmentid = d.deptid " +
                    " where h.id=? or h.belongto=? ";
            RecordSet rs = new RecordSet();
            rs.executeQuery(sql,new Object[]{userid,userid});
            while(rs.next()){
                String id = Util.null2String(rs.getString("id"));
                String departmentid = Util.null2String(rs.getString("departmentid"));
                String depttypecode = Util.null2String(rs.getString("depttypecode"));

                retSql += " select color,b.id lcid,img,typename,zh,htlx,showorder from uf_gwfq a " +
                        " left join workflow_base b on a.lcid=b.unnumber where isvalid=1 and gwlx="+type+" and  ( depttypecode like '%"+depttypecode+"%' " +
                        " or instr(','||bm||',' , ',"+departmentid+",')>0 " +
                        " or instr(','||tsry||',' , ',"+id+",')>0  )  union ";
            }
        }
        if(!"".equals(retSql) && retSql.lastIndexOf("union")>0){
            retSql = retSql.substring(0,retSql.lastIndexOf("union"));
            retSql = " select * from ( "+retSql+") order by showorder ";
        }
        return retSql;
    }


    /**
     * 根据人员获取查询公文发起数据sql
     * @param user
     * @return
     */
    public static String getOdocTypeCountSql(User user){
        String  retSql = "";
        if(user.getUID()==1){
            retSql = " select id,type_name,nvl(count,0) count from odoc_odoctype a left join (" +
                    " select count(1) count,wz from uf_gwky group by wz ) b on a.id=b.wz ";
        }else{
            int userid = user.getUID();
            int deptid = user.getUserDepartment();
            int szjg = getTopDept(deptid);
            String alluserids = userid+"";
            String sqlWhere = " and (sysyr=1 or instr(','||syry||',' , ',"+userid+",')>0 " +
                    " or instr(','||sybm||',' , ',"+deptid+",')>0 or instr(','||syjg||',' , ',"+szjg+",')>0 ";

            String sql = " select h.id,h.departmentid from hrmresource h " +
                    " left join hrmdepartmentdefined d on h.departmentid = d.deptid " +
                    " where h.belongto=? ";
            RecordSet rs = new RecordSet();
            rs.executeQuery(sql,new Object[]{userid});
            while(rs.next()){
                int tempuid = Util.getIntValue(rs.getString("id"));
                int temdeptid = Util.getIntValue(rs.getString("departmentid"));
                int temszjg = getTopDept(deptid);
                alluserids += ","+tempuid;

                sqlWhere += " or instr(','||syry||',' , ',"+tempuid+",')>0  or instr(','||sybm||',' , ',"+temdeptid+",')>0 " +
                        " or instr(','||syjg||',' , ',"+temszjg+",')>0 ";

            }

            rs.execute(" select distinct groupid from  hrmgroupmembers  where userid in("+alluserids+") ");
            while(rs.next()){
                String groupid = Util.null2String(rs.getString("groupid"));
                sqlWhere += " or instr(','||syqz||',' , ',"+groupid+",')>0 ";

            }
            sqlWhere += ")";
            retSql = " select id,type_name,nvl(count,0)count from odoc_odoctype a " +
                    " left join ( select count(1) count,wz from uf_gwky where wz is not null "+sqlWhere+" group by wz ) b " +
                    " on a.id=b.wz order by showorder ";
        }
        return retSql;
    }


    /**
     * 根据部门查询一级部门id
     * @param deptid
     * @return
     */
    public static int getTopDept(int deptid){
        RecordSet rs = new RecordSet();
        String sql = " select * from (  select t.* from HrmDepartment t " +
                " start with t.id=? connect by prior t.supdepid=t.id " +
                " ) where SUPDEPID is null or SUPDEPID=0 ";
        rs.executeQuery(sql,new Object[]{deptid});
        rs.next();
        int topDeptid = rs.getInt("id");
        return topDeptid;
    }




    /**
     * 判断公文流程是否有创建权限
     * @return
     */
    public static boolean hasOdocWfCreatePermission(int htlx,String wfunnumber,User user){

        int userid = user.getUID();
        int departmentid = user.getUserDepartment();
        String depttypecode = "";

        RecordSet rs = new RecordSet();
        rs.executeQuery( " select depttypecode from hrmdepartmentdefined where deptid=? ",new Object[]{departmentid});
        if(rs.next()){
            depttypecode = Util.null2String(rs.getString("depttypecode"));
        }

        String htlxSqlWhere = "";
        if(htlx>0){
            htlxSqlWhere += " and htlx="+htlx;
        }

        String sql = "select * from uf_gwfq where lcid='"+wfunnumber+"'" +htlxSqlWhere+
                " and ( instr(','||bm||',' , ',"+departmentid+",')>0  or instr(','||tsry||',' , ',"+userid+",')>0 " +
                "  or depttypecode like '%"+depttypecode+"%'  )";
        rs.execute(sql);
        if(rs.next()){
            return true;
        }
        return false;
    }



    /**
     * 查询当前流程为操作者
     * @param requestid
     * @return
     */
    public String getUnoperators(String requestid,String userid){
        User user = User.getUser(Integer.parseInt(userid),0);
        String language = user.getLanguage()+"";
        ResourceComInfo rc = null;
        try {
            rc = new ResourceComInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<String> unoperatorTypes = Util.TokenizerString(this.getUnOperatorSet(userid), ",");
        String isremarkStr = " (1 = 2 or ";
        //--------------------处理isremark条件----------------------
        if (unoperatorTypes.contains("1")) {//节点操作者
            isremarkStr += " (isremark = 0 or (isremark = 4 and viewtype = 0 and preisremark = 0) or (isremark = 1 and takisremark = '2')) or ";
        } else if (unoperatorTypes.contains("2")) {//转办操作者
            isremarkStr += " (isremark = 0 and (takisremark is null or takisremark=0) and handleforwardid > 0) or ";
        }

        if (unoperatorTypes.contains("4") && unoperatorTypes.contains("5")) {
            isremarkStr += " (isremark in(8,9,11) or (isremark = 4 and viewtype = 0 and preisremark in(8,9))) or ";
        } else if (unoperatorTypes.contains("4")) {//抄送操作者
            isremarkStr += " (isremark in(8,9) or (isremark =4 and viewtype = 0 and preisremark in(8,9))) or ";
        } else if (unoperatorTypes.contains("5")) {//传阅操作者
            isremarkStr += " (isremark in(11)) or ";
        }

        if (unoperatorTypes.contains("3")) {//转发操作者
            isremarkStr += " (isremark = 1 and (takisremark <>'2' or takisremark is null)) or ";
        }
        if (unoperatorTypes.contains("6")) {//其他操作者--协办、超时干预到指定对象
            isremarkStr += " (isremark in(5,7)) or ";
        }
        isremarkStr += " 1=2)";
        //--------------------处理isremark条件----------------------
        //--------------------分页----------------------
        String returnStr = "";
        List<String> unOperators = new ArrayList<>();
        RecordSet rs = new RecordSet();
        rs.execute("select userid,usertype,agenttype,agentorbyagentid,isremark,showorder,id,groupid from workflow_currentoperator where islasttimes =1 and requestid = " + requestid + " and " + isremarkStr + " order by isremark,groupid,showorder asc ,id asc");

        //--------------------分页----------------------
        while (rs.next()) {
            //去除重复
            String key = rs.getString("userid") + ":" + rs.getString("usertype") + ":" + rs.getString("agenttype") + ":" + rs.getString("agentorbyagentid");
            if (unOperators.contains(key)) {
                continue;
            } else {
                unOperators.add(key);
            }
            if (rs.getInt("agenttype") == 2) {
                returnStr += Util.formatMultiLang(rc.getResourcename(rs.getString("userid")), language)+"（"+Util.formatMultiLang(rc.getResourcename(rs.getString("agentorbyagentid")), language) + "授权）"  + " ";
                //判断是否被代理者,如果是，则不显示该记录
            } else if (rs.getInt("agenttype") == 1 && rs.getInt("isremark") == 4) {
                continue;
            } else {
                returnStr += Util.formatMultiLang(rc.getResourcename(rs.getString("userid")), language) + " ";
            }
        }
        return returnStr;

    }

    /**
     * 获取显示哪些类型签字
     * @param userid
     * @return
     */
    public String getUnOperatorSet(String userid){
        String unoperatorType = "";
        RequestDefaultComInfo rdComInfo = new RequestDefaultComInfo();
        unoperatorType = Util.null2String(rdComInfo.getUnoperatorType(userid));
        if("".equals(unoperatorType)){
            unoperatorType = "1,2,3,4,5,6";//默认显示全部类型
        }

        return unoperatorType;
    }


    /**
     * 查询授权人的工号
     * @param requestid
     * @param operatorid
     * @return
     */
    public String getAgentInfo(String requestid,String operatorid,String nodeid){
        String bagentCodes = "";
        try {
            RecordSet rs = new RecordSet();
            ResourceComInfo resourceComInfo = new ResourceComInfo();

            String sql = " select userid,usertype,agenttype,agentorbyagentid from workflow_currentoperator " +
                    " where requestid=? and userid=? and nodeid=? ";
            rs.executeQuery(sql,new Object[]{requestid,operatorid,nodeid});
            while(rs.next()){
                int agentorbyagentid = rs.getInt("agentorbyagentid");
                if(agentorbyagentid>0){
                    String bagentcode = resourceComInfo.getWorkcode(agentorbyagentid+"");
                    bagentCodes += bagentcode+",";
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        if(!"".equals(bagentCodes)){
            bagentCodes = bagentCodes.substring(0,bagentCodes.length()-1);
        }
        return bagentCodes;

    }


    /**
     * 根据requestid查询表名
     * @param requestid
     * @return
     */
    public static String getTableName(String requestid){
        String tablename = "";
        if(!"".equals(requestid)){
            String sql = " select tablename from workflow_base a,workflow_bill b,workflow_requestbase c \n" +
                    " where a.formid=b.id and a.id=c.workflowid and c.requestid=? ";
            RecordSet rs = new RecordSet();
            rs.executeQuery(sql,requestid);
            if(rs.next()){
                tablename = com.weaver.general.Util.null2String(rs.getString("tablename"));
            }
        }

        return tablename;
    }


    public static void saveMultiUserTypeData(int requestid, HttpServletRequest request){
        BaseBean bb = new BaseBean();
        Enumeration enu = request.getParameterNames();
        while(enu.hasMoreElements()){
            String paraName = (String)enu.nextElement();
            if(paraName.contains("groupInfo") && paraName.startsWith("field")){

                String paraValue = request.getParameter(paraName);
                JSONObject groupJsonObj = JSONObject.parseObject(paraValue);
                String fieldid = groupJsonObj.getString("fieldid");
                String fieldval = request.getParameter(fieldid);
                String fieldvalMD5 = Util.getEncrypt(fieldval);
                Set<Map.Entry<String, Object>> entrySet = groupJsonObj.entrySet();
                fieldid = fieldid.substring(5);


                ConnStatement statement = null;
                try {
                    statement = new ConnStatement();
                    //更新的顺序：先删除再添加
                    statement.setStatementSql("delete from workflow_reqbrowextrainfo where requestid=? and fieldid=?");
                    statement.setInt(1, requestid);
                    statement.setString(2, fieldid);
                    statement.executeUpdate();



                    for (Map.Entry<String, Object> entry : entrySet) {
                        String key = entry.getKey();
                        String fieldgroupstr = (String) entry.getValue();
                        bb.writeLog("MultiUserTypeHandleCmd requestid=="+requestid+" key=="+key+"  fieldgroupstr=="+fieldgroupstr);
                        String[] grouparry = fieldgroupstr.split("\\|");
                        if (grouparry.length < 3) {
                            continue;
                        }

                        statement.setStatementSql("insert into workflow_reqbrowextrainfo(requestid, fieldid, type, typeid, ids, md5)  values (?, ?, ?, ?, ?, ?)");
                        statement.setInt(1, requestid);
                        statement.setString(2, fieldid);
                        statement.setInt(3, Util.getIntValue(grouparry[0]));
                        statement.setInt(4, Util.getIntValue(grouparry[1]));
                        statement.setString(5, grouparry[2]);
                        statement.setString(6, fieldvalMD5);
                        statement.executeUpdate();
                        bb.writeLog("insert into workflow_reqbrowextrainfo(requestid, fieldid, type, typeid, ids, md5)  " +
                                "values"+requestid+"|"+fieldid+"|"+grouparry[0]+"|"+grouparry[1]+"|"+grouparry[2]+"|"+fieldvalMD5);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    statement.close();
                }
            }

        }
    }

    /**
     * 查询流程部门历史名称
     * @param requestid
     * @param fieldid
     * @param fieldvalue
     * @return
     */
    public static String getWfHistoryDeptName(String requestid,String fieldid,String fieldvalue){
        String showname = "";
        RecordSet rs = new RecordSet();
        String sql = "select parsejson(valuesshow,"+fieldvalue+") showname from record_formfield_history  where requestid =? and fieldid=? ";
        rs.executeQuery(sql,new Object[]{requestid,fieldid});
        if(rs.next()){
            showname = Util.null2String(rs.getString("showname"));
        }
        return showname;

    }




    public static void main(String[] args) {
        System.out.println(createPlaceHolder(4));
    }

}
