package com.vci.web.service.impl; import com.vci.client.common.oq.OQTool; import com.vci.common.qt.object.QueryTemplate; import com.vci.common.qt.object.Symbol; import com.vci.constant.IRightConstant; import com.vci.corba.common.PLException; import com.vci.corba.framework.data.CheckValue; import com.vci.corba.framework.data.GrandValue; import com.vci.corba.omd.btm.BizType; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.data.LinkObject; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.corba.omd.lcm.TransitionVO; import com.vci.corba.omd.ltm.LinkType; import com.vci.corba.portal.data.PLAction; import com.vci.dto.AuthResultDTO; import com.vci.dto.OsDataAuthDTO; import com.vci.pagemodel.OpItemVO; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.web.service.OsDataAuthServiceI; import com.vci.web.util.PlatformClientUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; /** * 数据权限的控制器 * @author yuxc * @date 2024-11-25 */ @Service public class OsDataAuthServiceImpl implements OsDataAuthServiceI { @Autowired private PlatformClientUtil platformClientUtil; @Override public BaseResult getData(String typeName) throws PLException { GrandValue[] grandValues = platformClientUtil.getFrameworkService().queryGrand(typeName); // 设置Table列头信息 List tableHeader = new ArrayList(); //获取表头数据 getTableHeader(grandValues, tableHeader, typeName); //列表数据 List rowList = new ArrayList<>(); //获取列表数据 getTableData(grandValues, tableHeader, typeName, rowList); Map actionsMap = getAllActionsByType2(typeName, "business"); OsDataAuthDTO tableData = new OsDataAuthDTO(); tableData.setTableHeader(tableHeader); tableData.setRowList(rowList); tableData.setActionMap(actionsMap); return BaseResult.success(tableData); } /** * 保存数据权限数据 * @return 保存结果 */ @Override public BaseResult saveGrand(List grandValues) throws PLException { boolean isTrue = false; isTrue = platformClientUtil.getFrameworkService() .deleteTypeRuleGrand(grandValues.get(0).identifier.split("_")[0], grandValues.get(0).ruleName); if(!isTrue){ throw new VciBaseException("数据权限删除失败!"); } // save boolean isTrue_add = false; try { isTrue_add = platformClientUtil.getFrameworkService() .saveGrand(grandValues.toArray(new GrandValue[grandValues.size()])); } catch (Exception e) { throw new VciBaseException("数据权限保存失败!"); } if (isTrue_add) { return BaseResult.success("保存成功!"); } return BaseResult.success("保存失败!"); } /** * 删除数据权限 * @param typeName 业务类型 * @param ruleName 规则名称 * @return 删除结果 */ @Override public BaseResult deleteTypeRuleGrand(String typeName, String ruleName) throws PLException { // DataBase boolean isTrue = platformClientUtil.getFrameworkService().deleteTypeRuleGrand(typeName, ruleName); if (!isTrue) { return BaseResult.success("删除失败!"); } return BaseResult.success("删除成功!"); } /** * 查询授权结果 * @param params 查询对象 * @return 授权结果 */ @Override public BaseResult authResult(CheckValue params) { // CheckValue params = new CheckValue(); params.opname = IRightConstant.OPS; if(StringUtils.isBlank(params.objectoid)){ params.objectoid = "22385E82-485C-549D-E2F4-91278E9E0A76"; } List tableHeaders = new ArrayList<>(); List tableValues = new ArrayList<>(); // 操作 List opitems = new ArrayList(); try { String where = platformClientUtil.getFrameworkService().checkRight(params); String[] ops = where.split(":"); //处理列表头 for (String s : ops) { if (s != null && !s.equals("")) { OpItemVO item = new OpItemVO(); String[] op = s.split(","); item.setName(op[0]); item.setValue(op[1]); tableHeaders.add(op[0]); opitems.add(item); } } } catch (Exception e) { e.printStackTrace(); throw new VciBaseException("鉴权出错\n" + e.getLocalizedMessage()); } //处理数据 for (int n = 0; n < opitems.size(); n++) { tableValues.add(opitems.get(n).getValue().equals("1") ? true : false); } AuthResultDTO authResultDTO = new AuthResultDTO(); authResultDTO.setTableValues(tableValues); authResultDTO.setTableHeader(tableHeaders); return BaseResult.success(authResultDTO); } /** * 查询业务对象 * @param btmName 业务类型名称 * @param boFlag 是否为bo类型,true为btm,false为link * @param btmType 业务类型 * @return 查询出的数据 */ @Override public BaseResult queryBusiness(String btmName, boolean boFlag, String btmType) { QueryTemplate qt = new QueryTemplate(); qt.setBtmType(btmName); List clauseList = new ArrayList(); clauseList.add("*"); qt.setClauseList(clauseList); qt.setType(btmType);// 链接link qt.setCondition(null); qt.setId("qt1"); List tableValues = new ArrayList<>(); try { clauseList = new ArrayList<>(Arrays.asList(platformClientUtil.getBtmService().getSysAttributeNames())); clauseList.addAll(Arrays.asList(platformClientUtil.getBtmService().getAttributeNames(btmName))); if (boFlag) { BusinessObject[] result = platformClientUtil.getQueryService().findBTMObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML()); for (int i = 0; i < result.length; i++) { List lineData = new ArrayList<>(); BusinessObject bo = result[i]; AttributeValue[] attList = bo.hisAttrValList; for (int j = 0; j < clauseList.size(); j++) { lineData.add(attList[j].attrVal); // qrTable.setValueAt(attList[j].attrVal, i, j); } tableValues.add(lineData); } } else { List lineData = new ArrayList<>(); LinkObject[] loResult = platformClientUtil.getQueryService().findLTObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML()); for (int i = 0; i < loResult.length; i++) { LinkObject lo = loResult[i]; AttributeValue[] attList = lo.hisAttrValList; for (int j = 0; j < attList.length; j++) { lineData.add(attList[j].attrVal); // qrTable.setValueAt(attList[j], i, j); } tableValues.add(lineData); } } } catch (PLException e) { e.printStackTrace(); } Map resultData = new HashMap<>(); resultData.put("tableHeader", clauseList); resultData.put("tableValues", tableValues); return BaseResult.success(resultData); } //add by caill start 2015 12.18 将查询出来的action放入到map中 private Map getAllActionsByType2(String typeName, String type) throws PLException { Map boActions2 = new HashMap(); boActions2.put("查询", "query"); PLAction[] allActions = platformClientUtil.getUIService().getAllPLActionEntityByType(typeName); if (allActions == null || allActions.length == 0) { return boActions2; } for (int i = 0; i < allActions.length; i++) { if(allActions[i].plTypeType.equals(type)){ boActions2.put(allActions[i].plName,allActions[i].plCode); //将中文显示作为key,英文显示作为value放到map中 } } return boActions2; } private void getTableData(GrandValue[] grandValues, List tableHeader, String typeName, List rowList) throws PLException { // 依据规则名称,规则分类 Map> splitRuleMap = splitRuleByName(grandValues); // 依据规则名称 // int row = 0; // 设置规则记录行数 // ruleModel.setRowCount(splitRuleMap.size()); // add by caill start 2016.1.11 得到btm、link、lifeCyles LinkType[] links = null; LifeCycle lifeCycle = null; BizType btm = null; try { btm = platformClientUtil.getBtmService().getBizTypeByName(typeName); links = platformClientUtil.getLinkTypeService().getLinkTypeByBtmName(btm.name, Symbol.FROM); LifeCycle[] lifeCyles = platformClientUtil.getLifeCycleService().getLifeCycles(); for (int m = 0; m < lifeCyles.length; m++) { if (lifeCyles[m].name.equals(btm.lifeCycle)) { lifeCycle = lifeCyles[m]; break; } } } catch (Throwable e) { e.printStackTrace(); } // add by caill end // ActionConstants act = new ActionConstants(); PLAction[] allActions = platformClientUtil.getUIService().getAllPLActionEntityByType(typeName); // platformClientUtil.getUIService().getAllPLActionEntityByType(typeName); for (Iterator>> iter = splitRuleMap.entrySet().iterator(); iter.hasNext();) { Map.Entry> entry = iter.next(); List rules = entry.getValue(); Map columnData = new HashMap<>(); // 增加页面缓存 // ruleModel.setConditionValue(row, rules); columnData.put("rules",rules); // add by caill start 2015 12.18 将查出的action放到map中,注意不要落下“查询” Map actionMap = new HashMap(); actionMap.put("query", "查询"); // 将操作中的query放入actionMap中 for (int i = 0; i < allActions.length; i++) { if (allActions[i].plTypeType.equals("business")) { actionMap.put(allActions[i].plCode, allActions[i].plName); // 将操作放入actionMap中 } } for (int j = 0; j < links.length; j++) { for (int i = 0; i < allActions.length; i++) { if (allActions[i].plTypeType.equals("link")) { actionMap.put(links[j].name + "." + allActions[i].plCode, links[j].name + "." + allActions[i].plName);// 将关系放入actionMap中 } } actionMap.put(links[j].name + "." + "query", links[j].name + "." + "查询"); // 将关系中的query放入actionMap中 } TransitionVO[] transitions = lifeCycle != null ? lifeCycle.routes : new TransitionVO[0]; for (int j = 0; j < transitions.length; j++) { String name = lifeCycle.name + "." + transitions[j].connect; actionMap.put(name, name); // 将跃迁放入actionMap中 } // add by caill end for (int j = 0; j < rules.size(); j++) { // 规则名和类型 // ruleModel.setValueAt(rules.get(j).ruleName, row, 0); columnData.put("0", rules.get(j).ruleName); if (rules.get(j).ruleType.equals(IRightConstant.RULETYPE__HAS)) { columnData.put("1", "允许规则"); } else if (rules.get(j).ruleType.equals(IRightConstant.RULETYPE__NOTHAS)) { columnData.put("1", "拒绝规则"); } else if (rules.get(j).ruleType.equals(IRightConstant.RULETYPE_ALL_HAS)) { columnData.put("1", "全部有权"); } else { columnData.put("1", "全部无权"); } // 指定的操作赋值 // TableColumnModel columnModel = funclet.getRightMainPanel().getRuleTable().getColumnModel(); int start = rules.get(j).identifier.lastIndexOf("_") + 1; String op = rules.get(j).identifier.substring(start, rules.get(j).identifier.length()); // add by caill start 2015.12.18 遍历map,根据英文名称找到相应的中文名称,并根据中文名称找到对应的列 String headerName = null; Set keys = null; if (actionMap.size() > 0) { keys = actionMap.keySet(); } if (keys.size() != 0) { for (Iterator iterator = keys.iterator(); iterator.hasNext();) { String key = iterator.next(); if (op.equals(key)) { headerName = actionMap.get(key); break; } } } int columnIndex = -1; if (headerName != null) { // columnIndex = columnModel.getColumnIndex(headerName); columnIndex = tableHeader.indexOf(headerName); } // add by caill end // int columnIndex = columnModel.getColumnIndex(op); if (columnIndex >= 0) { // ruleModel.setValueAt(rules.get(j).isGrand == '1' ? true : false, row, columnIndex); columnData.put(String.valueOf(columnIndex), rules.get(j).isGrand == '1' ? true : false); } } // ++row; rowList.add(columnData); } } private void getTableHeader(GrandValue[] grandValues, List tableHeader, String typeName) throws PLException { // 操作信息 List ops = new ArrayList(); for (int i = 0; i < grandValues.length; i++) { int start = grandValues[i].identifier.lastIndexOf("_") + 1; String op = grandValues[i].identifier.substring(start, grandValues[i].identifier.length()); if (!ops.contains(op)) { ops.add(op); } } // 操作信息 String[] operations = ops.toArray(new String[ops.size()]); // List tablerule = new ArrayList(); tableHeader.add("规则名称"); tableHeader.add("规则类型"); PLAction[] allActions = platformClientUtil.getUIService().getAllPLActionEntityByType(typeName); for (int m = 0; m < operations.length; m++) { if (allActions != null && allActions.length != 0) { for (int i = 0; i < allActions.length; i++) { if (allActions[i].plCode.equals(operations[m])) { tableHeader.add(allActions[i].plName); break; } else if (operations[m].endsWith("." + allActions[i].plCode)) { int index = operations[m].indexOf("." + allActions[i].plCode); StringBuilder sb = new StringBuilder(operations[m]); StringBuilder actionChina = sb.replace(index + 1, operations[m].length(), allActions[i].plName); tableHeader.add(actionChina.toString()); break; } else if (operations[m].equals("query")) { tableHeader.add("查询"); // 注意不要落下写死的“查询” break; } else if (operations[m].endsWith(".query")) { int index = operations[m].indexOf(".query"); StringBuilder sb = new StringBuilder(operations[m]); StringBuilder actionChina = sb.replace(index + 1, operations[m].length(), "查询"); tableHeader.add(actionChina.toString()); break; } } } else { if (operations[m].equals("query")) { tableHeader.add("查询"); // 注意不要落下写死的“查询” } if (operations[m].endsWith(".query")) { int index = operations[m].indexOf(".query"); StringBuilder sb = new StringBuilder(operations[m]); StringBuilder actionChina = sb.replace(index + 1, operations[m].length(), "查询"); tableHeader.add(actionChina.toString()); } } } LifeCycle lifeCycle = null; BizType btm = null; try { btm = platformClientUtil.getBtmService().getBizTypeByName(typeName); LifeCycle[] lifeCyles = platformClientUtil.getLifeCycleService().getLifeCycles(); for (int j = 0; j < lifeCyles.length; j++) { if (lifeCyles[j].name.equals(btm.lifeCycle)) { lifeCycle = lifeCyles[j]; break; } } } catch (Throwable e) { e.printStackTrace(); } TransitionVO[] transitions = lifeCycle != null ? lifeCycle.routes : new TransitionVO[0]; for (int j = 0; j < transitions.length; j++) { tableHeader.add(lifeCycle.name + "." + transitions[j].connect); } } private Map> splitRuleByName(GrandValue[] values) { Map> splitRuleMap = new HashMap>(); for (int i = 0; i < values.length; i++) { if (splitRuleMap.get(values[i].ruleName) == null) { List ruleOfOneName = new ArrayList(); ruleOfOneName.add(values[i]); splitRuleMap.put(values[i].ruleName, ruleOfOneName); } else { splitRuleMap.get(values[i].ruleName).add(values[i]); } } return splitRuleMap; } }