diff --git a/src/main/java/com/xdap/self_development/config/AuthorizationWebConfig.java b/src/main/java/com/xdap/self_development/config/AuthorizationWebConfig.java new file mode 100644 index 0000000..34d7f61 --- /dev/null +++ b/src/main/java/com/xdap/self_development/config/AuthorizationWebConfig.java @@ -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/**"); + } +} \ No newline at end of file diff --git a/src/main/java/com/xdap/self_development/controller/form/ParameterForm.java b/src/main/java/com/xdap/self_development/controller/form/ParameterForm.java index c3d790c..40a830a 100644 --- a/src/main/java/com/xdap/self_development/controller/form/ParameterForm.java +++ b/src/main/java/com/xdap/self_development/controller/form/ParameterForm.java @@ -77,4 +77,9 @@ public class ParameterForm { * 操作 */ private String operation; + + /** + * 是否为数值 + */ + private String isNumber; } diff --git a/src/main/java/com/xdap/self_development/domain/enums/AuthorizationClassEnum.java b/src/main/java/com/xdap/self_development/domain/enums/AuthorizationClassEnum.java new file mode 100644 index 0000000..822d745 --- /dev/null +++ b/src/main/java/com/xdap/self_development/domain/enums/AuthorizationClassEnum.java @@ -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; +} diff --git a/src/main/java/com/xdap/self_development/domain/pojo/ParameterPojo.java b/src/main/java/com/xdap/self_development/domain/pojo/ParameterPojo.java index 7afc3e1..40164cf 100644 --- a/src/main/java/com/xdap/self_development/domain/pojo/ParameterPojo.java +++ b/src/main/java/com/xdap/self_development/domain/pojo/ParameterPojo.java @@ -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)", "非必填,如果参数来源为'数据平台手工录入'则必填;部门必须为研发总院的部门,如‘研发部’", diff --git a/src/main/java/com/xdap/self_development/intercept/AuthorizationInterceptor.java b/src/main/java/com/xdap/self_development/intercept/AuthorizationInterceptor.java new file mode 100644 index 0000000..341d779 --- /dev/null +++ b/src/main/java/com/xdap/self_development/intercept/AuthorizationInterceptor.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/com/xdap/self_development/listener/SheetDataListener.java b/src/main/java/com/xdap/self_development/listener/SheetDataListener.java index 4fd168a..d96cd93 100644 --- a/src/main/java/com/xdap/self_development/listener/SheetDataListener.java +++ b/src/main/java/com/xdap/self_development/listener/SheetDataListener.java @@ -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 { @@ -95,6 +96,12 @@ public class SheetDataListener implements ReadListener { return; } + if (data.getIsNumber() == null + || (!Objects.equals(data.getIsNumber(), "数值") + && !Objects.equals(data.getIsNumber(), "非数值"))) { + data.setIsNumber("非数值"); + } + cachedDataList.add(data); // 达到批处理大小时提前处理 diff --git a/src/main/java/com/xdap/self_development/service/AuthService.java b/src/main/java/com/xdap/self_development/service/AuthService.java new file mode 100644 index 0000000..37f0f62 --- /dev/null +++ b/src/main/java/com/xdap/self_development/service/AuthService.java @@ -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); +} diff --git a/src/main/java/com/xdap/self_development/service/impl/AnalysisCommonParametersServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/AnalysisCommonParametersServiceImpl.java index 97e7c31..c780a8b 100644 --- a/src/main/java/com/xdap/self_development/service/impl/AnalysisCommonParametersServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/AnalysisCommonParametersServiceImpl.java @@ -108,7 +108,7 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame // 按权限过滤 List 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()); } diff --git a/src/main/java/com/xdap/self_development/service/impl/AuthServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/AuthServiceImpl.java new file mode 100644 index 0000000..4b9a0fe --- /dev/null +++ b/src/main/java/com/xdap/self_development/service/impl/AuthServiceImpl.java @@ -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 menuParamViews = modelRoleService.selectPersByUser(userId); + // 过滤检查是否为管理员 + List isAdmin = menuParamViews.stream().filter(item -> + item.getIsAdmin() != null && item.getIsAdmin() == 1) + .collect(Collectors.toList()); + if (!isAdmin.isEmpty()) { + return; + } + // 过滤检查是否有相关权限 + List collected = menuParamViews.stream() + .map(MenuParamView::getPermissionPath).collect(Collectors.toList()); + if (!collected.contains(classEnum.getPermissionPath())) { + throw new CommonException("您没有" + classEnum.getPermissionPath() + "的操作权限"); + } + } +} diff --git a/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java index cd6ba97..d08855a 100644 --- a/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/ParameterServiceImpl.java @@ -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()); } /**