package com.engine.htsc.wdzx.dao;

import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WdzxTreeNodeDao {



    /*
     * @title getmodelfreenode
     * @remark 根据requestid获取建模表里自由节点的数据
     * @author xf
     * @Params：
       * @param: requestid
     * @updateTime 2021/9/15
     * @return: java.lang.String
     **/
    public  static String getmodelfreenode(String requestid) {
        String value="";
        String sql= "select wm_concat_old(freenode) as id from uf_qzyjhqb where 1=1";
        Map<String,String> map=new HashMap<>();
        map.put("lcid",requestid);
       Map<String,Object> returnmap=JAVATools.GetTableToMap(sql,map);
        if(returnmap!=null && returnmap.size()>0){
            value=Util.null2String(returnmap.get("id"));
        }
        return value;
    }

    /*
     * @title getfreenode
     * @remark 根据requestid获取自由节点的ids
     * @author xf
     * @Params：
       * @param: requestid
     * @updateTime 2021/9/14
     * @return: java.lang.String
     **/
    public  static String getfreenode(String requestid) {
        String value="";
        String sql= "select wm_concat_old(id) as id from workflow_freenode where 1=1" ;
        Map<String,String> map=new HashMap<>();
        map.put("requestid",requestid);
        Map<String,Object> returnmap=JAVATools.GetTableToMap(sql,map);
        if(returnmap!=null && returnmap.size()>0){
            value=Util.null2String(returnmap.get("id"));
        }
        return value;
    }

    /*
     * @title Inertmodel
     * @remark 插入建模uf_qzyjhqb
     * @author xf
     * @Params：
       * @param: map
     * @updateTime 2021/9/14
     * @return: boolean
     **/
    public  static boolean Inertmodel(Map<String,String> map){
        String tablename="uf_qzyjhqb";
        return JAVATools.Excetesql(map,tablename);
    }

    /**
     * @title getbmfzr
     * @remark 获取建模表里部门负责人的ids
     * @author xf
     * @Params：
       * @param: requestid
     * @param: bmfzrs
     * @updateTime 2021/9/15
     * @return: java.lang.String
     */
    public static String getbmfzr(String requestid,String bmfzrs){
        String value="";
        bmfzrs=JAVATools.getpreventsql(bmfzrs);
        String sql=" select wm_concat_old(id) as id from workflow_freenode where to_char(operatorids) in ("+bmfzrs+") ";
        Map<String,String> map=new HashMap<>();
        map.put("requestid",requestid);
        Map<String,Object> retrunmap= JAVATools.GetTableToMap(sql,map);
        if(retrunmap!=null && retrunmap.size()>0){
            value= Util.null2String(map.get("id"));
        }
        return value;

    }
    /**
     * @title getzdrys
     * @remark 根据requestid获取uf_qzyjhqb的id的数据
     * @author xf
     * @Params：
       * @param: requestid
     * @param: zdrys
     * @updateTime 2021/9/15
     * @return: java.lang.String
     */
    public static String getzdrys(String requestid,String zdrys){
        String value="";
        zdrys=JAVATools.getpreventsql(zdrys);
        String sql=  " select wm_concat_old(id) as id from workflow_freenode where  to_char(operatorids) in ("+zdrys+")";
        Map<String,String> map=new HashMap<>();
        map.put("requestid",requestid);
        Map<String,Object> retrunmap= JAVATools.GetTableToMap(sql,map);
        if(retrunmap!=null && retrunmap.size()>0){
            value= Util.null2String(map.get("id"));
        }
        return value;

    }
    /*
     * @title getListStr
     * @remark 根据requestid获取uf_qzyjhqb的id的数据
     * @author xf
     * @Params：
       * @param: requestid
     * @updateTime 2021/9/15
     * @return: java.util.List
     **/
    public static List getListStr(String requestid){
        String sql="select id from uf_qzyjhqb where 1=1 ";
        Map<String,String> mapstr=new HashMap<>();
        mapstr.put("requestid",requestid);
        return JAVATools.GetTableToListMap(sql,mapstr);
    }



    /*
     * @title getListStr
     * @remark 根据requestid获取uf_qzyjhqb的id的数据
     * @author xf
     * @Params：
     * @param: requestid
     * @updateTime 2021/9/15
     * @return: java.util.List
     **/

    public static String getfgsfkg(String userid){

        if("".equals(userid)){
            return "";
        }
        String sqlfgs="select DECODE(de.deptTypeCode,'JGLX04',d.supdepid,'JGLX09',d.supdepid,'JGLX03',d.id) as cid from hrmdepartment d,hrmdepartmentdefined de,hrmresource h where d.id=de.deptid and h.departmentid=de.deptid and h.id="+userid;
        Map<String,Object> fgsmap= JAVATools.GetTableToMap(sqlfgs,null);
        if("".equals(fgsmap)){
            return "";
        }
        String newdeptid=Util.null2String(fgsmap.get("cid"));
        if("".equals(newdeptid)){
            return "";
        }
        String gwid=new PropBean().getPropName("jgxt.fs.gwid");
        String sql="select ry from uf_lcgwry where   xzlc='jgxtsq' and xzgw='"+gwid+"' ";

        Map<String,String> mapstr=new HashMap<>();
        mapstr.put("jg",newdeptid);
        Map<String,Object> returnmap= JAVATools.GetTableToMap(sql,mapstr);
        if(returnmap==null || returnmap.size()<=0){
            return "";
        }
        return Util.null2String(returnmap.get("ry"));
    }


    public static Map<String,Object> gettablemap(String requestid){

        String tablename=JAVATools.getMaintable(requestid);
        String sql="select * from  "+tablename+" where 1=1 ";
        Map<String,String> mapstr=new HashMap<>();
        mapstr.put("requestid",requestid);
        Map<String,Object> returnmap= JAVATools.GetTableToMap(sql,mapstr);
        if(returnmap==null || returnmap.size()<=0){
            return null;
        }
        return returnmap;
    }


}
