show_matrix.jsp 18.9 KB
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="com.engine.hrm.cmd.matrix.biz.MatrixinfoComInfo" %>
<%@ page import="com.engine.hrm.cmd.matrix.biz.chain.MatrixCondition" %>
<%@ page import="com.engine.hrm.cmd.matrix.listnew.MatrixUtilToolCmd" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.moduledetach.ManageDetachComInfo" %>
<%@ page import="weaver.matrix.MatrixManager" %>
<%@ page import="weaver.systeminfo.systemright.CheckSubCompanyRight" %>
<%@ page import="weaver.matrix.MatrixUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="java.util.Map.Entry" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.ArrayList" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%

    try {
        String userid = Util.null2String(request.getParameter("userid"));
        if(userid.length() == 0){
            out.println("param userid is null:<br/>");
            return ;
        }
        String matrixid = Util.null2String(request.getParameter("matrixid"));
        if(matrixid.length() == 0){
            out.println("param matrixid is null:<br/>");
            return ;
        }
        MatrixUtilToolCmd matrixUtilToolCmd = new MatrixUtilToolCmd();

        User user = new User(Util.getIntValue(userid));
        //可维护列和条件控制集合
        Map<String,Object> condition_col_map = new HashMap<>();
        //0表示没有操作按钮的权限,1表示有操作按钮的权限
        String hasright = "0";
        MatrixManager matrixManager = new MatrixManager();
        MatrixinfoComInfo matrixinfoComInfo = new MatrixinfoComInfo();
        MatrixCondition matrixCondition = matrixManager.getMatrixConditionByMaintUser(userid, matrixid);
        out.print("getMatrixDataByMaintDetach:userid:"+userid+":matrixid:"+matrixid+"::"+ JSON
                .toJSONString(matrixCondition)+"<br/>");
        String issystemStr = matrixinfoComInfo.getIssystem(matrixid);
        boolean isSystem = false;
        if("1".equalsIgnoreCase(issystemStr) || "2".equalsIgnoreCase(issystemStr)){
            isSystem = true;
        }
        out.print("getMatrixDataByMaintDetach:isSystem:"+isSystem+"<br/>");
        //是否需要受到机构权限控制,这个是做数据字段 只读可编辑控制用的
        boolean needDetachControll = false;
        //是否开启分权,并且设置了机构权限 这个只是做数据筛选的,拼接sql用的
        boolean needDetach = false;

        ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo();
        boolean hrmdetachable = manageDetachComInfo.isUseHrmManageDetach();//是否开启了人力资源模块的管理分权
        CheckSubCompanyRight checkSubCompanyRight = new CheckSubCompanyRight();

        boolean hasMenuRight = HrmUserVarify.checkUserRight("Matrix:Maint", new User(Util.getIntValue(userid)));
        //当前矩阵所属subcompanyid
        String subcompanyid = matrixinfoComInfo.getSubcompanyid(matrixid);
        out.print("getMatrixDataByMaintDetach:hasMenuRight:"+hasMenuRight+"<br/>");
        String subcompanyids = "";
        int operatelevel= -1;
        int systemOperatelevel= -1;
        out.print("getMatrixDataByMaintDetach:hrmdetachable:"+hrmdetachable+"<br/>");
        if(hrmdetachable){
            out.print("getMatrixDataByMaintDetach:matrixinfoComInfo:subcompanyid:"+subcompanyid+"<br/>");
            //机构权限里有一个机构的级别是编辑,完全控制的,都表示按钮可操作
            operatelevel=checkSubCompanyRight.ChkComRightByUserRightCompanyId(Util.getIntValue(userid),"Matrix:Maint",Util.getIntValue(subcompanyid,-1));
            out.print("getMatrixDataByMaintDetach:operatelevel:"+operatelevel+"<br/>");

            int[] arrSubcompanyids = checkSubCompanyRight.getSubComByUserRightId(Util.getIntValue(userid),"Matrix:Maint");
            out.print("getMatrixDataByMaintDetach:arrSubcompanyids:"+JSON
                    .toJSONString(arrSubcompanyids)+"<br/>");

            if(!"1".equalsIgnoreCase(userid)){
                for(int i=0;arrSubcompanyids!=null&&i<arrSubcompanyids.length;i++){
                    needDetach = true;
                    int tmp_subid = arrSubcompanyids[i];
                    int tmp_operatelevel=checkSubCompanyRight.ChkComRightByUserRightCompanyId(Util.getIntValue(userid),"Matrix:Maint",tmp_subid);
                    if(tmp_operatelevel > systemOperatelevel){
//              系统矩阵的级别就是取所有可以维护的机构里的最大操作级别
                        systemOperatelevel = tmp_operatelevel;
                    }
                    if(subcompanyids.length()>0){
                        subcompanyids+=",";
                    }
                    subcompanyids += tmp_subid;
                }
            }else{
                operatelevel = 2;
                hasright = "1";
            }
        }else{
            if(hasMenuRight){
                hasright = "1";
            }
        }
        out.print("getMatrixDataByMaintDetach:subcompanyids:"+subcompanyids+"<br/>");

        condition_col_map.put("needDetach",needDetach);
        condition_col_map.put("detach_subids",","+subcompanyids+",");
        if(subcompanyids.length() > 0 && subcompanyid.length() > 0 && (","+subcompanyids+",").indexOf(","+subcompanyid+",") > -1){
            needDetachControll = true;
            condition_col_map.put("operatelevel",operatelevel);
            condition_col_map.put("needDetachControll",needDetachControll);
        }
        if(isSystem){
            operatelevel = systemOperatelevel;
        }
        if(operatelevel > 0){
            hasright = "1";
        }
        //根据feildname生成可维护列的map集合
        Map<String, List<String>> fieldname_list_map = new HashMap<>();

        boolean hasSetCol = false;
        List<Map<String, String>> fieldInfos = MatrixUtilToolCmd.getMatrixJsonById(matrixid,true,false);
        String condition_sql = "";
        //条件字段是否有设置总部,只要有设置总部表示数据都可见
        boolean isAll = false;
        if(matrixCondition != null){
            isAll = matrixCondition.isAll();
            hasSetCol = true;
            if(isAll){
                condition_col_map.put("isAll", "1");
            }else{
                condition_col_map.put("isAll", "0");
            }
            condition_col_map.put("hasSetCol", true);
            String colids = matrixCondition.getColids();
            condition_col_map.put("colids", colids);
            if(colids.length() > 0){
                //如果设置了可维护列
                if(operatelevel > 0){
                    //机构权限是可编辑+,那么就可以显示所有的列
                    condition_col_map.put("colids", "");
                }
            }
        }
//      通过sql 来过滤数据 矩阵数据过滤
        StringBuffer sql_col_where=new StringBuffer("");
        //矩阵浏览按钮数据过滤,拼接sqlwhere
        Map<String,String> sql_type_where= new HashMap<>();
        if(fieldInfos.size() > 0) {
            //条件字段数据是取合集的
            for (int i = 0; i < fieldInfos.size(); i++) {
                Map<String, String> fieldInfoMap = fieldInfos.get(i);
                String htmltype = fieldInfoMap.get("htmltype");
                String fieldname = fieldInfoMap.get("fieldlable");
                String type = fieldInfoMap.get("type");
                if("1".equalsIgnoreCase(type)){
                    //数据字段不考虑
                    continue;
                }
                out.print("getMatrixDataByMaintDetach:fieldname:"+fieldname+":sql_col_where:"+sql_col_where+"<br/>");
                if("1".equalsIgnoreCase(htmltype)){
//            人力资源
                    if(hasSetCol && !isAll){
                        List<String> resids = matrixCondition.getResids();
                        if(resids != null && !resids.isEmpty()){
                            matrixUtilToolCmd.bindConditionSql(resids,fieldname,sql_col_where,htmltype,sql_type_where);
                            fieldname_list_map.put(fieldname, resids);
                        }
                    }else if(isAll){
                        if(sql_col_where.length() > 0){
                            sql_col_where.append(" or 1=1 ");
                        }else{
                            sql_col_where.append(" 1=1 ");
                        }
                    }
                    if(needDetach){
                        matrixUtilToolCmd.bindDetachSql(subcompanyids, fieldname, sql_col_where,"res",htmltype,sql_type_where);
                    }
                }else if("4".equalsIgnoreCase(htmltype)){
//            部门
                    if(hasSetCol && !isAll){
                        List<String> deptids = matrixCondition.getDeptids();
                        if(deptids != null && !deptids.isEmpty()){
                            matrixUtilToolCmd.bindConditionSql(deptids,fieldname,sql_col_where, htmltype, sql_type_where);
                            fieldname_list_map.put(fieldname, deptids);
                        }
                    }else if(isAll){
                        if(sql_col_where.length() > 0){
                            sql_col_where.append(" or 1=1 ");
                        }else{
                            sql_col_where.append(" 1=1 ");
                        }
                    }
                    if(needDetach){
                        matrixUtilToolCmd.bindDetachSql(subcompanyids, fieldname, sql_col_where, "dept", "dept", sql_type_where);
                    }
                }else if("164".equalsIgnoreCase(htmltype)){
//            分部
                    if(hasSetCol && !isAll){
                        List<String> subids = matrixCondition.getSubids();
                        if(subids != null && !subids.isEmpty()){
                            matrixUtilToolCmd.bindConditionSql(subids,fieldname,sql_col_where, htmltype, sql_type_where);
                            fieldname_list_map.put(fieldname, subids);
                        }
                    }else if(isAll){
                        if(sql_col_where.length() > 0){
                            sql_col_where.append(" or 1=1 ");
                        }else{
                            sql_col_where.append(" 1=1 ");
                        }
                    }
                    if(needDetach){
                        matrixUtilToolCmd.bindDetachSql(subcompanyids, fieldname, sql_col_where, "sub", htmltype, sql_type_where);
                    }
                }else if("24".equalsIgnoreCase(htmltype)){
//            岗位
                    if(hasSetCol && !isAll){
                        List<String> jobids = matrixCondition.getJobids();
                        if(jobids != null && !jobids.isEmpty()){
                            matrixUtilToolCmd.bindConditionSql(jobids,fieldname,sql_col_where, htmltype, sql_type_where);
                            fieldname_list_map.put(fieldname, jobids);
                        }
                    }else if(isAll){
                        if(sql_col_where.length() > 0){
                            sql_col_where.append(" or 1=1 ");
                        }else{
                            sql_col_where.append(" 1=1 ");
                        }
                    }
                }else if("8".equalsIgnoreCase(htmltype)){
//            项目
                    if(hasSetCol && !isAll){
                        List<String> prjids = matrixCondition.getPrjids();
                        if(prjids != null && !prjids.isEmpty()){
                            matrixUtilToolCmd.bindConditionSql(prjids,fieldname,sql_col_where, htmltype, sql_type_where);
                            fieldname_list_map.put(fieldname, prjids);
                        }
                    }else if(isAll){
                        if(sql_col_where.length() > 0){
                            sql_col_where.append(" or 1=1 ");
                        }else{
                            sql_col_where.append(" 1=1 ");
                        }
                    }
                }else if("7".equalsIgnoreCase(htmltype)){
//            客户
                    if(hasSetCol && !isAll){
                        List<String> crmids = matrixCondition.getCrmids();
                        if(crmids != null && !crmids.isEmpty()){
                            matrixUtilToolCmd.bindConditionSql(crmids,fieldname,sql_col_where, htmltype, sql_type_where);
                            fieldname_list_map.put(fieldname, crmids);
                        }
                    }else if(isAll){
                        if(sql_col_where.length() > 0){
                            sql_col_where.append(" or 1=1 ");
                        }else{
                            sql_col_where.append(" 1=1 ");
                        }
                    }
                }
            }
        }
        if(sql_col_where.length() > 0){
            condition_sql = "and ("+sql_col_where.toString()+")";
            condition_col_map.put("condition_sql", condition_sql);
        }
        if(!sql_type_where.isEmpty()){
            condition_col_map.put("sql_type_where", sql_type_where);
        }
        if(!hrmdetachable){
            if(hasMenuRight){
                condition_col_map.put("condition_sql", "");
                condition_col_map.put("colids", "");
            }
        }
        if("1".equalsIgnoreCase(hasright)){
            condition_col_map.put("hassaveright", "1");
        }else{
            //如果维护者维护了,且有数据,那么就可以做保存
            if(!fieldname_list_map.isEmpty()){
                condition_col_map.put("hassaveright", "1");
            }else if(hasSetCol){
                condition_col_map.put("hassaveright", "1");
                //如果条件字段是空的,表示是可以维护所有的
                condition_col_map.put("isAll", "1");
            }
        }

        condition_col_map.put("fieldname_list_map", fieldname_list_map);
        condition_col_map.put("hasright", hasright);
        condition_col_map.put("hrmdetachable", hrmdetachable);
        condition_col_map.put("operatelevel", operatelevel);
        condition_col_map.put("systemOperatelevel", systemOperatelevel);
        out.print("getMatrixDataByMaintDetach:condition_col_map:"+condition_col_map+"<br/>");

        Map<String, Map<String, String>>  fieldinfos=MatrixUtil.getFieldDetail(matrixid);
        out.print("getMatrixDataByMaintDetach:fieldinfos:"+fieldinfos+"<br/>");
        List<Map<String, Object>> dataitems = new ArrayList<>();
        if(condition_sql.length() > 0){
            int columncount;
            String sql = "select * from "+ MatrixUtil.MATRIXPREFIX+matrixid+" where 1=1 "+condition_sql;
            out.print("getMatrixDataByMaintDetach:sql:"+sql+"<br/>");
            RecordSet rs = new RecordSet();
            rs.executeQuery(sql);
            while (rs.next()){
                Map<String,Object> item=new HashMap<String,Object>();
                columncount=rs.getColCounts();
                //取值字段是否可以编辑,只要条件字段有一个是可编辑的,那么取值字段就是都可以编辑的
                boolean hasConditionEditable = false;
                //取值字段存下
                Map<String,String> dataMap=new HashMap<String,String>();
                //添加列值
                for(int i=0;i<columncount;i++) {
                    String uuid = rs.getString("uuid");
                    String tempstr = rs.getColumnName(i + 1);
                    if(!"".equals(tempstr)) {
                        tempstr = tempstr.toLowerCase();
                    }
                    if("uuid".equals(tempstr) || "dataorder".equals(tempstr)){
                      continue;
                    }
                    String tmpId = rs.getString(tempstr);
                    String value = "";
                    Map<String, String> fieldinfo = fieldinfos.get(tempstr);
                    String fieldtype = fieldinfo.get("type");
                    //如果设置了可维护列,则默认所有的单元格都不允许编辑,只有可维护列范围内的数据才可以编辑
                    if("0".equalsIgnoreCase(fieldtype) && hasSetCol){
                        item.put(tempstr+"_editable", "0");
                    }
                    //记录下取值字段
                    if("1".equalsIgnoreCase(fieldtype)){
                        dataMap.put(tempstr+"_editable", "1");
                        item.put(tempstr+"_editable", "1");
                        if(isSystem){
                            if(needDetach){
                                if(systemOperatelevel < 1){
                                    item.put(tempstr+"_editable", "0");
                                }
                            }
                        }else{
                            if(needDetachControll){
                                if(operatelevel < 1){
                                    item.put(tempstr+"_editable", "0");
                                }
                            }
                        }
                    }
                    if(needDetachControll){
                        if("0".equalsIgnoreCase(fieldtype)){
                            if(operatelevel > 0){
                                hasConditionEditable = true;
                                item.put(tempstr+"_editable", "1");
                            }else{
                                item.put(tempstr+"_editable", "0");
                            }
                        }
                    }else{
                        if("1".equalsIgnoreCase(hasright)){
                            hasConditionEditable = true;
                            item.put(tempstr+"_editable", "1");
                        }
                    }
                    if(fieldname_list_map.get(tempstr) != null){
                        List<String> fielddatas = fieldname_list_map.get(tempstr);
                        if(fielddatas.contains(tmpId)){
                            hasConditionEditable = true;
                        }
                    }else if(isAll){
                        hasConditionEditable = true;
                    }
                    item.put(tempstr, tmpId);
                }

                String replcaceval= "";
                if(hasConditionEditable){
                    replcaceval = "1";
                }else{
                    replcaceval = "0";
                }
                Set<Entry<String, String>> setData = dataMap.entrySet();
                for(Map.Entry<String,String> me : setData){
                    String setKey = me.getKey();
                    item.replace(setKey,replcaceval);
                }
                out.print("getMatrixDataByMaintDetach:item:"+item+"<br/>");
                dataitems.add(item);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.print(e.getMessage());
    }

%>