Ver código fonte

业务电子签章调整

sangwenwei 11 meses atrás
pai
commit
fbb4481cd9

+ 137 - 0
src/main/java/com/jeeplus/common/service/BaseService.java

@@ -56,6 +56,18 @@ public abstract class BaseService {
     }
 
     /**
+     * 数据范围过滤(仅适用于业务电子签章)
+     *
+     * @param user        当前用户对象,通过“entity.getCurrentUser()”获取
+     * @param officeAlias 机构表别名,多个用“,”逗号隔开。
+     * @param userAlias   用户表别名,多个用“,”逗号隔开,传递空,忽略此参数
+     * @return 标准连接条件对象
+     */
+    public static String dataScopeFilterReportSig(User user, String officeAlias, String userAlias, String sAlias, String menuId) {
+        return genReportSigSqlString("menu1_",user, menuId,sAlias, "and");
+    }
+
+    /**
      * 数据范围过滤
      *
      * @param user        当前用户对象,通过“entity.getCurrentUser()”获取
@@ -186,6 +198,131 @@ public abstract class BaseService {
         }
     }
 
+    public static String genReportSigSqlString(String prefix, User user, String menuId,String sAlias, String logic) {
+        if (user.isAdmin()) {
+            return "";
+        }
+        Jedis jedis = null;
+        try {
+            jedis = JedisUtils.getResource();
+            StringBuilder sqlString = new StringBuilder();
+            String sql = jedis.hget( prefix+ user.getCompany().getId() + "_" + user.getId(), menuId);
+            if (StringUtils.isNotBlank(sql)) {
+                //return sql;
+            }
+            // 进行权限过滤,多个岗位权限范围之间为或者关系。
+            List<Role> fnlRoleList = new ArrayList<>();
+            List<Role> selfRoleList = new ArrayList<>();
+            List<Role> roleList = UserUtils.getRolesByMenu(user, menuId);
+            if (roleList != null && roleList.size() > 0) {
+                for (Role role : roleList) {
+                    if (Role.DATA_SCOPE_COMPANY_AND_CHILD.equals(role.getDataScope())) {
+                        fnlRoleList.clear();
+                        fnlRoleList.add(role);
+                        break;
+                    } else if (!Role.DATA_SCOPE_SELF.equals(role.getDataScope())) {
+                        fnlRoleList.add(role);
+                    } else {
+                        selfRoleList.add(role);
+                    }
+                }
+            }
+            Set<String> officeSet = new HashSet<>();
+            for (Role r : fnlRoleList) {
+                if (Role.DATA_SCOPE_COMPANY_AND_CHILD.equals(r.getDataScope())) {
+                    if(StringUtils.isBlank(sAlias)){
+                        return logic + "1=1";
+                    }
+                    sqlString.append(logic + " a.company_id = '" + r.getCompany().getId() + "'");
+                    return sqlString.toString();
+                }
+                if (Role.DATA_SCOPE_COMPANY.equals(r.getDataScope())) {
+                    if(null == r.getBranchCompany()){
+                        sqlString.append(logic + " a.company_id = '" + r.getCompany().getId() + "'");
+                        return sqlString.toString();
+                    }
+                    //查询分公司的所有部门
+                    String key = BRANCH_OFFICE_PREFIX + r.getBranchCompany().getId();
+                    String s = jedis.get(key);
+                    List<String> officeIds = null;
+                    if (StringUtils.isBlank(s)) {
+                        officeIds = UserUtils.findBranchOfficeId(r.getBranchCompany());
+                    } else {
+                        officeIds = JSON.parseArray(s, String.class);
+                    }
+                    if (officeIds != null && officeIds.size() > 0) {
+                        jedis.set(key, JSON.toJSONString(officeIds));
+                        jedis.expire(key, 60 * 60 * 8);
+                        officeSet.addAll(officeIds);
+                    }
+                    continue;
+                }
+                if (Role.DATA_SCOPE_OFFICE_AND_CHILD.equals(r.getDataScope())) {
+                    //查询当前部门的所有子部门
+                    String key = CHILD_OFFICE_PREFIX + r.getOffice().getId();
+                    String s = jedis.get(key);
+                    List<String> officeIds = new ArrayList<>();
+                    if (StringUtils.isBlank(s)) {
+                        officeIds = UserUtils.findChildOfficeId(r.getOffice());
+                    } else {
+                        officeIds = JSON.parseArray(s, String.class);
+                    }
+                    officeIds.add(r.getOffice().getId());
+                    jedis.set(key, JSON.toJSONString(officeIds));
+                    jedis.expire(key, 60 * 60 * 8);
+                    officeSet.addAll(officeIds);
+                    continue;
+                }
+                if (Role.DATA_SCOPE_OFFICE.equals(r.getDataScope())) {
+                    officeSet.add(r.getOffice().getId());
+                    continue;
+                }
+            }
+            //所有部门权限
+            if (officeSet != null) {
+                if (officeSet.size() > 1) {
+                    sqlString.append("a.office_id in (");
+                    for (String s : officeSet) {
+                        sqlString.append("'" + s + "',");
+                    }
+                    sqlString.deleteCharAt(sqlString.length() - 1);
+                    sqlString.append(")");
+                } else if (officeSet.size() == 1) {
+                    for (String s : officeSet) {
+                        sqlString.append("a.office_id ='" + s + "'");
+                    }
+                }
+            }
+            //所有个人权限
+            for (int i = 0; i < selfRoleList.size(); i++) {
+                Role role = selfRoleList.get(i);
+                if (officeSet.contains(role.getOffice().getId())) {
+                    continue;
+                }
+                if (i > 0 || sqlString.length() > 0) {
+                    sqlString.append("or ");
+                }
+                //当角色为签章人员时,追加为当前登陆人部门id
+                if (role.getEnname().equals("qzry")){
+                    sqlString.append("(a.office_id='" + user.getOffice().getId() + "' and a.create_by='" + user.getId() + "')");
+                }else {
+                    sqlString.append("(a.office_id='" + role.getOffice().getId() + "' and a.create_by='" + user.getId() + "')");
+
+                }
+            }
+
+            if (StringUtils.isNotBlank(sqlString.toString())) {
+                sql = logic+" (" + sqlString.toString() + ")";
+                jedis.hset(prefix + user.getCompany().getId() + "_" + user.getId(), menuId, sql);
+            }
+            return sql;
+        } catch (Exception e) {
+            return "and a.company_id='" + user.getCompany().getId() + "' and a.create_by='" + user.getId() + "'";
+        } finally {
+            JedisUtils.returnResource(jedis);
+        }
+    }
+
     public static String genInvoiceSqlString(String prefix, User user, String menuId,String sAlias, String logic) {
         if (user.isAdmin()) {
             return "";

+ 1 - 1
src/main/java/com/jeeplus/modules/signature/projectReportSignatureWork/service/ProjectReportSignatureWorkService.java

@@ -228,7 +228,7 @@ public class ProjectReportSignatureWorkService extends CrudService<ProjectReport
                 if (user.getOffice().getId().equals("d8cf33fafd2d4f04a603e89f7e28e54c")){
                     projectReportSignature.getSqlMap().put("sztd", "and a.office_id = 'd8cf33fafd2d4f04a603e89f7e28e54c'");
                 }else {
-                    dataScopeSql = dataScopeFilter(projectReportSignature.getCurrentUser(), "o", "u", "s", MenuStatusEnum.PROJECT_REPORT_WORK.getValue());
+                    dataScopeSql = dataScopeFilterReportSig(projectReportSignature.getCurrentUser(), "o", "u", "s", MenuStatusEnum.PROJECT_REPORT_WORK.getValue());
                     projectReportSignature.getSqlMap().put("dsf", dataScopeSql);
                 }