修改权限和添加字段(部分)

This commit is contained in:
zjh 2026-04-03 19:14:51 +08:00
parent 1dc576d435
commit 18da2f2bc9
10 changed files with 132 additions and 2 deletions

View File

@ -0,0 +1,21 @@
package com.xdap.self_development.config;
import com.xdap.self_development.intercept.AuthorizationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class AuthorizationWebConfig implements WebMvcConfigurer {
@Autowired
private AuthorizationInterceptor authorizationInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authorizationInterceptor)
.addPathPatterns("/api/**")
.excludePathPatterns("/api/login", "/api/public/**");
}
}

View File

@ -77,4 +77,9 @@ public class ParameterForm {
* 操作
*/
private String operation;
/**
* 是否为数值
*/
private String isNumber;
}

View File

@ -0,0 +1,20 @@
package com.xdap.self_development.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum AuthorizationClassEnum {
TEMPLATE_EDIT(0, "参数模板管理"),
YC_ENGINE_EDIT(1, "玉柴发动机数据"),
OTH_ENGINE_EDIT(2, "竞品发动机数据"),
REPORT_EDIT(3, "对标报告"),
BASIC_DATA_EDIT(4, "基础管理模块"),
AUTH_EDIT(5, "权限");
private final Integer code;
private final String permissionPath;
}

View File

@ -79,6 +79,13 @@ public class ParameterPojo extends MpaasBasePojo {
@ExcelProperty("单位")
@ColumnWidth(15)
private String unit;
/**
* 标明参数值是否为数值
*/
@ExcelProperty("参数值类型")
private String isNumber;
/**
* 参数来源
*/
@ -144,6 +151,7 @@ public class ParameterPojo extends MpaasBasePojo {
"非必填",
"必填",
"非必填",
"非必填,用于标明参数值是否为数值,如需填写,填入数值或非数值,不填入默认非数值类型",
"必填并且为下列之一数据平台手工录入、TC分类表、公式计算",
"非必填,如果参数来源为'公式计算'则必填。填写规范:参数名可以是中文、数字、大小写字母、中文括号 ``必须以中文开头,不能包含运算符和英文括号;参数名也可以是数字;支持圆周率,必须是小写的`π`,不支持`Π`;负号 `-` 可作为操作数前缀。公式示例:π*(直径(内径)/2)*(直径(内径)/2)",
"非必填,如果参数来源为'数据平台手工录入'则必填;部门必须为研发总院的部门,如‘研发部’",

View File

@ -0,0 +1,22 @@
package com.xdap.self_development.intercept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.security.auth.message.config.AuthConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class AuthorizationInterceptor implements HandlerInterceptor {
@Autowired
private AuthConfig authConfig;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return true;
}
}

View File

@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
public class SheetDataListener implements ReadListener<ParameterPojo> {
@ -95,6 +96,12 @@ public class SheetDataListener implements ReadListener<ParameterPojo> {
return;
}
if (data.getIsNumber() == null
|| (!Objects.equals(data.getIsNumber(), "数值")
&& !Objects.equals(data.getIsNumber(), "非数值"))) {
data.setIsNumber("非数值");
}
cachedDataList.add(data);
// 达到批处理大小时提前处理

View File

@ -0,0 +1,10 @@
package com.xdap.self_development.service;
import com.xdap.self_development.domain.enums.AuthorizationClassEnum;
public interface AuthService {
/**
* 验证用户是否有操作权限
*/
void checkUserAuthorization(String userId, AuthorizationClassEnum classEnum);
}

View File

@ -108,7 +108,7 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
// 按权限过滤
List<ParameterPojo> parameters = engineParamDetailService.selectParamByIsUserId(modelParams, userId);
return parameters.stream()
.filter(x -> x.getUnit() != null && !"/".equals(x.getUnit()))
.filter(x -> Objects.equals(x.getIsNumber(), "数值"))
.map(ParameterPojo::getParameterName).distinct().collect(Collectors.toList());
}

View File

@ -0,0 +1,36 @@
package com.xdap.self_development.service.impl;
import com.xdap.self_development.domain.enums.AuthorizationClassEnum;
import com.xdap.self_development.domain.view.MenuParamView;
import com.xdap.self_development.exception.CommonException;
import com.xdap.self_development.service.AuthService;
import com.xdap.self_development.service.ModelRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class AuthServiceImpl implements AuthService {
@Autowired
private ModelRoleService modelRoleService;
@Override
public void checkUserAuthorization(String userId, AuthorizationClassEnum classEnum) {
List<MenuParamView> menuParamViews = modelRoleService.selectPersByUser(userId);
// 过滤检查是否为管理员
List<MenuParamView> isAdmin = menuParamViews.stream().filter(item ->
item.getIsAdmin() != null && item.getIsAdmin() == 1)
.collect(Collectors.toList());
if (!isAdmin.isEmpty()) {
return;
}
// 过滤检查是否有相关权限
List<String> collected = menuParamViews.stream()
.map(MenuParamView::getPermissionPath).collect(Collectors.toList());
if (!collected.contains(classEnum.getPermissionPath())) {
throw new CommonException("您没有" + classEnum.getPermissionPath() + "的操作权限");
}
}
}

View File

@ -443,7 +443,8 @@ public class ParameterServiceImpl implements ParameterService {
handleParameterChange("单位名", originalParameter.getUnit(), updatedParameter.getUnit()) +
handleParameterChange("参数来源", originalParameter.getParameterSource(), updatedParameter.getParameterSource()) +
handleParameterChange("公式或编号", originalParameter.getNumberOrFormula(), updatedParameter.getNumberOrFormula()) +
handleParameterChange("部门名", originalParameter.getDepartment(), updatedParameter.getDepartment());
handleParameterChange("部门名", originalParameter.getDepartment(), updatedParameter.getDepartment()) +
handleParameterChange("是否为数值类型", originalParameter.getIsNumber(), updatedParameter.getIsNumber());
}
/**