diff --git a/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/Plugins.java b/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/Plugins.java index 31cd1e6d..79a21438 100644 --- a/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/Plugins.java +++ b/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/Plugins.java @@ -7,7 +7,9 @@ import com.actionsoft.apps.listener.PluginListener; import com.actionsoft.apps.resource.AppContext; import com.actionsoft.apps.resource.plugin.profile.ASLPPluginProfile; import com.actionsoft.apps.resource.plugin.profile.AWSPluginProfile; +import com.actionsoft.apps.resource.plugin.profile.AtFormulaPluginProfile; import com.awspaas.user.apps.docview.CreateFileRecord; +import com.awspaas.user.apps.docview_plugin.at.QueryUserFileSql; /** * @author LHY @@ -18,6 +20,7 @@ public class Plugins implements PluginListener { public List register(AppContext context) { List list = new ArrayList<>(); //注册监听器 + list.add(new AtFormulaPluginProfile("模型阅览", "@queryUserFileSql(*uid)", QueryUserFileSql.class.getName(), "模型预览权限sql片段", "根据用户信息,通过文件阅览表(BO_EU_PAL_DOC_VIEW)中,该用户有权阅读的sql片段。针对待阅文件列表、已阅文件列表使用")); list.add(new ASLPPluginProfile("PushFileToXpage", CreateFileRecord.class.getName(),"推送待阅文件到xpage门户", null)); return list; } diff --git a/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/at/QueryUserFileSql.java b/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/at/QueryUserFileSql.java new file mode 100644 index 00000000..89bc494b --- /dev/null +++ b/com.awspaas.user.apps.docview/src/com/awspaas/user/apps/docview_plugin/at/QueryUserFileSql.java @@ -0,0 +1,140 @@ +package com.awspaas.user.apps.docview_plugin.at; + +import com.actionsoft.bpms.commons.at.AbstExpression; +import com.actionsoft.bpms.commons.at.ExpressionContext; +import com.actionsoft.bpms.org.cache.DepartmentCache; +import com.actionsoft.bpms.org.cache.UserCache; +import com.actionsoft.bpms.org.cache.UserMapCache; +import com.actionsoft.bpms.org.model.DepartmentModel; +import com.actionsoft.bpms.org.model.UserMapModel; +import com.actionsoft.bpms.org.model.UserModel; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.exception.AWSExpressionException; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Created with IntelliJ IDEA. + * + * @Author: yuandongqiang + * @Date: 2025/7/26 + * @Description: + */ +public class QueryUserFileSql extends AbstExpression { + public QueryUserFileSql(ExpressionContext atContext, String expressionValue) { + super(atContext, expressionValue); + } + + @Override + public String execute(String s) throws AWSExpressionException { + String uid = getParameter(s, 1); + if (uid == null) { + return ""; + } + UserModel userModel = UserCache.getModel(uid); + if (userModel == null) { + return ""; + } + String level = userModel.getExt2(); // 职级 + String positionNo = userModel.getPositionNo(); // 岗位 + + // 校验关键字段 + if (level == null || positionNo == null) { + // 记录日志并返回空字符串 + System.err.println("用户职级或岗位为空"); + return ""; + } + + Set deptIdSet = new HashSet<>(); + + try { + String mainDeptId = userModel.getDepartmentId(); + if (mainDeptId != null) { + deptIdSet.addAll(getParentDeptList(mainDeptId)); + } + + List userMapModels = UserMapCache.getMapListOfUser(userModel.getUID()); + if (userMapModels != null) { + for (UserMapModel userMapModel : userMapModels) { + String deptId = userMapModel.getDepartmentId(); + if (deptId != null) { + deptIdSet.addAll(getParentDeptList(deptId)); + } + } + } + } catch (Exception e) { + System.err.println("获取用户部门失败"); + e.printStackTrace(); + return ""; + } + + // 构造 SQL 模板中的条件部分 + String orgInClause = String.join("%' OR READINGSCOPE_ORG LIKE '%", deptIdSet); + String orgsql = "(READINGSCOPE_ORG LIKE '%" + orgInClause + "%')"; + String postsql = "READINGSCOPE_POST LIKE '%" + positionNo + "%'"; + String levelsql = "READINGSCOPE_LEVEL ='" + level + "'"; + + String sql = "ISFULLCOMPANY = '1'\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NOT NULL AND READINGSCOPE_POST IS NOT NULL AND READINGSCOPE_LEVEL IS NOT NULL\n" + + " AND (\n" + + " ({ORGSQL} AND {LEVELSQL} ) OR {POSTSQL}\n" + + " )\n" + + " )\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NOT NULL AND READINGSCOPE_POST IS NOT NULL AND READINGSCOPE_LEVEL IS NULL\n" + + " AND ({ORGSQL} OR {POSTSQL})\n" + + " )\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NOT NULL AND READINGSCOPE_POST IS NULL AND READINGSCOPE_LEVEL IS NOT NULL\n" + + " AND ({ORGSQL} AND {LEVELSQL})\n" + + " )\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NULL AND READINGSCOPE_POST IS NOT NULL AND READINGSCOPE_LEVEL IS NOT NULL\n" + + " AND ({POSTSQL} OR {LEVELSQL})\n" + + " )\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NULL AND READINGSCOPE_POST IS NULL AND READINGSCOPE_LEVEL IS NOT NULL\n" + + " AND {LEVELSQL}\n" + + " )\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NULL AND READINGSCOPE_POST IS NOT NULL AND READINGSCOPE_LEVEL IS NULL\n" + + " AND {POSTSQL}\n" + + " )\n" + + " OR (\n" + + " READINGSCOPE_ORG IS NOT NULL AND READINGSCOPE_POST IS NULL AND READINGSCOPE_LEVEL IS NULL\n" + + " AND {ORGSQL}\n" + + " )"; + + sql = sql.replace("{ORGSQL}", orgsql) + .replace("{POSTSQL}", postsql) + .replace("{LEVELSQL}", levelsql); + + return sql; + } + + /** + * 获取当前部门和所有上级部门的集合 + * + * @param deptId 部门ID + * @return 部门集合 + */ + public Set getParentDeptList(String deptId) { + Set deptIdSet = new HashSet<>(); + DepartmentModel deptModel = DepartmentCache.getModel(deptId); + if (deptModel == null) { + return deptIdSet; + } + deptIdSet.add(deptId); + String parentDeptId = deptModel.getPathIdOfCache(); + String[] ids = parentDeptId.split("/"); + for (int i = 0; i < ids.length; i++) { + if (UtilString.isNotEmpty(ids[i])) { + deptIdSet.add(ids[i]); + } + } + return deptIdSet; + } +}