1. 统一包名修改
This commit is contained in:
54
zt-framework/zt-spring-boot-starter-biz-business/pom.xml
Normal file
54
zt-framework/zt-spring-boot-starter-biz-business/pom.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>zt-spring-boot-starter-biz-business</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-module-system-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-spring-boot-starter-security</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-spring-boot-starter-biz-data-permission</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-module-infra-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- RPC 远程调用相关 -->
|
||||
<dependency>
|
||||
<groupId>com.zt.plat</groupId>
|
||||
<artifactId>zt-spring-boot-starter-rpc</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.zt.plat.framework.business.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*
|
||||
* 附件上传 Controller 注解,
|
||||
* 1. 标记附件列表上传在 requestBody 中的 Key 值,
|
||||
* 2. 标记当前 controller 中业务创建请求后返回的业务主键 Key 值,
|
||||
* 2. 标记会开启业务提交时,前置校验操作用户唯一部门
|
||||
* 3. 标记当前 controller 所属的业务来源
|
||||
*/
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
public @interface FileUploadController {
|
||||
/**
|
||||
* 附件列表上传在 requestBody 中的 Key 值
|
||||
*/
|
||||
String filesKey() default "files";
|
||||
|
||||
/**
|
||||
* 附件名称在 requestBody 中的 Key 值
|
||||
*/
|
||||
String fileNameKey() default "name";
|
||||
|
||||
/**
|
||||
* 附件 ID 在 requestBody 中的 Key 值
|
||||
*/
|
||||
String fileIdKey() default "id";
|
||||
|
||||
/**
|
||||
* 业务来源
|
||||
* 例如:bpm、oa、hr 等
|
||||
*/
|
||||
String source() default "default";
|
||||
|
||||
/**
|
||||
* 业务创建请求后返回的业务主键 Key 值
|
||||
*/
|
||||
String primaryKey() default "data.id";
|
||||
|
||||
/**
|
||||
* 业务创建请求后返回的业务编码 Key 值
|
||||
*/
|
||||
String codeKey() default "data.code";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.zt.plat.framework.business.config;
|
||||
|
||||
import com.zt.plat.framework.business.filter.FileUploadFilter;
|
||||
import com.zt.plat.framework.business.interceptor.BusinessHeaderInterceptor;
|
||||
import com.zt.plat.framework.business.interceptor.FileUploadHeaderInterceptor;
|
||||
import com.zt.plat.framework.web.config.CloudWebAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
@AutoConfiguration(after = CloudWebAutoConfiguration.class)
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||
public class CloudBusinessAutoConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 只拦截增删改和 set 相关的 url
|
||||
registry.addInterceptor(new BusinessHeaderInterceptor())
|
||||
.addPathPatterns("/**/add**", "/**/create**", "/**/update**", "/**/edit**", "/**/set**");
|
||||
registry.addInterceptor(new FileUploadHeaderInterceptor())
|
||||
.addPathPatterns("/**/add**", "/**/create**", "/**/update**", "/**/edit**", "/**/set**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<FileUploadFilter> businessHeaderFilter() {
|
||||
return new FilterRegistrationBean<>(new FileUploadFilter());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zt.plat.framework.business.controller;
|
||||
|
||||
import com.zt.plat.framework.business.annotation.FileUploadController;
|
||||
import com.zt.plat.framework.business.vo.FileUploadInfoVO;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
|
||||
public abstract class AbstractFileUploadController {
|
||||
protected static String FILE_UPLOAD_SOURCE = "";
|
||||
@GetMapping("/upload-info")
|
||||
@Operation(summary = "获取文件上传 source 配置值")
|
||||
public CommonResult<FileUploadInfoVO> getFileUploadSource() {
|
||||
FileUploadInfoVO vo = new FileUploadInfoVO();
|
||||
vo.setSource(FILE_UPLOAD_SOURCE);
|
||||
return success(vo);
|
||||
}
|
||||
|
||||
protected static void setFileUploadInfo(FileUploadController annotation) {
|
||||
FILE_UPLOAD_SOURCE = annotation.source();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.zt.plat.framework.business.core.util;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.zt.plat.framework.common.pojo.CompanyDeptInfo;
|
||||
import com.zt.plat.framework.security.core.LoginUser;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.singleton;
|
||||
import static com.zt.plat.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
public class BusinessDeptHandleUtil {
|
||||
public static Set<CompanyDeptInfo> getBelongCompanyAndDept(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
String companyId = request.getHeader("visit-company-id");
|
||||
String deptId = request.getHeader("visit-dept-id");
|
||||
LoginUser loginUser = Optional.ofNullable(getLoginUser()).orElse(new LoginUser().setInfo(new HashMap<>()));
|
||||
Set<CompanyDeptInfo> companyDeptSet = JSONUtil.parseArray(loginUser.getInfo().getOrDefault(LoginUser.INFO_KEY_COMPANY_DEPT_SET, "[]")).stream()
|
||||
.map(obj -> JSONUtil.toBean((JSONObject) obj, CompanyDeptInfo.class))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 1. 有 companyId
|
||||
if (companyId != null && !companyId.isBlank()) {
|
||||
// 根据请求头中的公司 ID 过滤出当前用户的公司部门信息
|
||||
Set<CompanyDeptInfo> companyDeptSetByCompanyId = companyDeptSet.stream().filter(companyDeptInfo -> companyDeptInfo.getCompanyId().toString().equals(companyId)).collect(Collectors.toSet());
|
||||
if (companyDeptSetByCompanyId.isEmpty()) {
|
||||
// 当前公司下没有部门
|
||||
CompanyDeptInfo data = new CompanyDeptInfo();
|
||||
data.setCompanyId(Long.valueOf(companyId));
|
||||
data.setDeptId(0L);
|
||||
return new HashSet<>(singleton(data));
|
||||
}
|
||||
// 如果有 deptId,校验其是否属于该 companyId
|
||||
if (deptId != null) {
|
||||
boolean valid = companyDeptSetByCompanyId.stream().anyMatch(info -> String.valueOf(info.getDeptId()).equals(deptId));
|
||||
if (!valid) {
|
||||
return null;
|
||||
}else{
|
||||
// 部门存在,放行
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
return companyDeptSetByCompanyId;
|
||||
}
|
||||
// 2. 没有公司信息,尝试唯一性自动推断
|
||||
// 如果当前用户下只有一个公司和部门的对于关系
|
||||
if (companyDeptSet.size() == 1) {
|
||||
CompanyDeptInfo companyDeptInfo = companyDeptSet.iterator().next();
|
||||
return new HashSet<>(singleton(companyDeptInfo));
|
||||
} else {
|
||||
return companyDeptSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.zt.plat.framework.business.core.util;
|
||||
|
||||
import com.zt.plat.module.system.api.user.dto.AdminUserRespDTO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户与部门一对多改动,此处统一处理用户与部门关系
|
||||
* @author chenbowen
|
||||
*/
|
||||
public class DeptUtil {
|
||||
/**
|
||||
* 从用户信息中获取唯一 deptId (现阶段取第一个,后续如有特殊规则统一调整此处即可)
|
||||
*/
|
||||
public static Long getDeptId(AdminUserRespDTO adminUserRespDTO) {
|
||||
List<Long> deptIds = Optional.ofNullable(adminUserRespDTO.getDeptIds()).orElse(new ArrayList<>());
|
||||
return deptIds.stream().findFirst().orElse(0L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.zt.plat.framework.business.enums;
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
public interface FileUploadConstants {
|
||||
// 是否业务请求
|
||||
String IS_UPLOAD_REQUEST = "isUploadRequest";
|
||||
// request 中附件列表的 Key 值,支持多层级引用 如 data.files
|
||||
String FILES_KEY = "fileKey";
|
||||
String FILE_NAME_KEY = "fileNameKey";
|
||||
String FILE_ID_KEY = "fileIdKey";
|
||||
|
||||
// request 中业务来源的
|
||||
String FILE_SOURCE = "fileSource";
|
||||
// request 中业务创建请求后返回的业务主键 Key 值,支持多层级引用 如 data.businessPrimaryKey
|
||||
String FILE_REL_PRIMARY_KEY = "fileRelPrimaryKey";
|
||||
String FILE_REL_CODE_KEY = "fileRelCode";
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
package com.zt.plat.framework.business.framework;
|
||||
|
||||
import com.zt.plat.framework.datapermission.core.rule.company.CompanyDataPermissionRuleCustomizer;
|
||||
import com.zt.plat.framework.datapermission.core.rule.dept.DeptDataPermissionRuleCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class BusinessDataPermissionConfiguration {
|
||||
@Bean
|
||||
public CompanyDataPermissionRuleCustomizer sysCompanyDataPermissionRuleCustomizer() {
|
||||
return rule -> {
|
||||
// companyId
|
||||
rule.addCompanyColumn("demo_contract", "company_id");
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DeptDataPermissionRuleCustomizer businessDeptDataPermissionRuleCustomizer() {
|
||||
return rule -> {
|
||||
// dept
|
||||
rule.addDeptColumn("demo_contract", "dept_id");
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.zt.plat.framework.business.framework.rpc;
|
||||
|
||||
import com.zt.plat.module.infra.api.businessfile.BusinessFileApi;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @author chenbowen
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableFeignClients(clients = BusinessFileApi.class)
|
||||
public class CloudBusinessRpcAutoConfiguration {
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user