chore: initialize qiming workspace repository
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>platform-system</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>system-application</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 打包插件 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<!-- 打包配置:必须在对应目录下创建repack.xml的打包配置文件 -->
|
||||
<descriptor>src/main/resources/assemblies/repack.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- install插件,定制在mvn install过程使用哪个jar包安装到本地 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>install-file</id>
|
||||
<goals>
|
||||
<goal>install-file</goal>
|
||||
</goals>
|
||||
<phase>install</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!-- install配置,指定将哪个目录下的jar包install为这个工程的jar -->
|
||||
<file>${project.build.directory}/${project.build.finalName}-repack.jar</file>
|
||||
<!--
|
||||
install配置,指定将install的jar打包使用的pom.xml文件,
|
||||
即其他依赖这个jar包的工程按照哪个pom.xml文件来解析依赖
|
||||
-->
|
||||
<pomFile>src/main/resources/install-pom.xml</pomFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- deploy插件,定制在mvn deploy过程使用哪个jar包发布到仓库 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>deploy-file</id>
|
||||
<goals>
|
||||
<goal>deploy-file</goal>
|
||||
</goals>
|
||||
<!-- 跳过默认的发布包 -->
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!-- deploy配置,指定将哪个目录下的jar包发布为这个工程的jar -->
|
||||
<file>${project.build.directory}/${project.build.finalName}-repack.jar</file>
|
||||
<!-- 发布地址 -->
|
||||
<url>http://local-maven.space.com/repository/maven-snapshots/</url>
|
||||
<repositoryId>nexus-snapshots</repositoryId>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>${project.artifactId}</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<!--
|
||||
deploy配置,指定将deploy的jar打包使用的pom.xml文件,
|
||||
即其他依赖这个jar包的工程按照哪个pom.xml文件来解析依赖
|
||||
-->
|
||||
<pomFile>src/main/resources/install-pom.xml</pomFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.xspaceagi.system.api;
|
||||
|
||||
import com.xspaceagi.system.application.service.SysUserPermissionCacheService;
|
||||
import com.xspaceagi.system.sdk.permission.IPermissionCacheRpcSerivce;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限缓存 RPC 实现(供内部模块调用)
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PermissionCacheRpcServiceImpl implements IPermissionCacheRpcSerivce {
|
||||
|
||||
@Resource
|
||||
private SysUserPermissionCacheService sysUserPermissionCacheService;
|
||||
|
||||
@Override
|
||||
public void clearCacheAllByTenant(Long tenantId) {
|
||||
sysUserPermissionCacheService.clearCacheAllByTenant(tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCacheByTenantAndUserIds(Long tenantId, List<Long> userIds) {
|
||||
sysUserPermissionCacheService.clearCacheByTenantAndUserIds(tenantId, userIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.xspaceagi.system.api;
|
||||
|
||||
import com.xspaceagi.system.application.service.SysDataPermissionApplicationService;
|
||||
import com.xspaceagi.system.sdk.permission.IUserDataPermissionRpcService;
|
||||
import com.xspaceagi.system.sdk.service.dto.MergedGroupDataPermissionDto;
|
||||
import com.xspaceagi.system.sdk.service.dto.UserDataPermissionDto;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户数据权限查询接口实现(供内部模块 RPC 调用)
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserDataPermissionRpcServiceImpl implements IUserDataPermissionRpcService {
|
||||
|
||||
@Resource
|
||||
private SysDataPermissionApplicationService sysDataPermissionApplicationService;
|
||||
|
||||
@Override
|
||||
public UserDataPermissionDto getUserDataPermission(Long userId) {
|
||||
return sysDataPermissionApplicationService.getUserDataPermission(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergedGroupDataPermissionDto getMergedGroupDataPermission(List<Long> groupIds) {
|
||||
return sysDataPermissionApplicationService.getMergedGroupDataPermission(groupIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.xspaceagi.system.api;
|
||||
|
||||
import com.xspaceagi.system.domain.service.UserMetricDomainService;
|
||||
import com.xspaceagi.system.infra.dao.entity.UserMetric;
|
||||
import com.xspaceagi.system.sdk.server.IUserMetricRpcService;
|
||||
import com.xspaceagi.system.sdk.service.dto.PeriodType;
|
||||
import com.xspaceagi.system.sdk.service.dto.PeriodUtils;
|
||||
import com.xspaceagi.system.sdk.service.dto.UserMetricDto;
|
||||
import com.xspaceagi.system.spec.common.RequestContext;
|
||||
import com.xspaceagi.system.spec.enums.PeriodTypeEnum;
|
||||
import com.xspaceagi.system.spec.tenant.thread.TenantFunctions;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 用户计量服务 RPC 接口实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserMetricRpcServiceImpl implements IUserMetricRpcService {
|
||||
|
||||
@Resource
|
||||
private UserMetricDomainService userMetricDomainService;
|
||||
|
||||
public void incrementMetric(Long userId, String bizType, String periodType, String period, BigDecimal delta) {
|
||||
PeriodTypeEnum periodTypeEnum = PeriodTypeEnum.fromCode(periodType);
|
||||
if (periodTypeEnum == null) {
|
||||
throw new IllegalArgumentException("Invalid period type: " + periodType);
|
||||
}
|
||||
userMetricDomainService.incrementValue(userId, bizType, periodTypeEnum, period, delta);
|
||||
}
|
||||
|
||||
public void incrementMetricCurrent(Long userId, String bizType, String periodType, BigDecimal delta) {
|
||||
String period = PeriodUtils.getCurrentPeriod(periodType);
|
||||
incrementMetric(userId, bizType, periodType, period, delta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void incrementMetricAllPeriods(Long tenantId, Long userId, String bizType, BigDecimal delta) {
|
||||
boolean hasContext = RequestContext.get() != null;
|
||||
if (!hasContext) {
|
||||
RequestContext.set(RequestContext.builder()
|
||||
.tenantId(tenantId)
|
||||
.build());
|
||||
}
|
||||
try {
|
||||
incrementMetricCurrent(userId, bizType, PeriodType.YEAR, delta);
|
||||
incrementMetricCurrent(userId, bizType, PeriodType.MONTH, delta);
|
||||
incrementMetricCurrent(userId, bizType, PeriodType.DAY, delta);
|
||||
incrementMetricCurrent(userId, bizType, PeriodType.HOUR, delta);
|
||||
} finally {
|
||||
if (!hasContext) {
|
||||
RequestContext.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal queryMetricCurrent(Long tenantId, Long userId, String bizType, String periodType) {
|
||||
PeriodTypeEnum periodTypeEnum = PeriodTypeEnum.fromCode(periodType);
|
||||
if (periodTypeEnum == null) {
|
||||
throw new IllegalArgumentException("Invalid period type: " + periodType);
|
||||
}
|
||||
String period = PeriodUtils.getCurrentPeriod(periodType);
|
||||
UserMetric userMetric = TenantFunctions.callWithIgnoreCheck(() -> userMetricDomainService.queryByUniqueKey(tenantId, userId, bizType, periodTypeEnum, period));
|
||||
return userMetric != null ? userMetric.getValue() : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private UserMetricDto convert(UserMetric userMetric) {
|
||||
if (userMetric == null) {
|
||||
return null;
|
||||
}
|
||||
UserMetricDto dto = new UserMetricDto();
|
||||
BeanUtils.copyProperties(userMetric, dto);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.xspaceagi.system.api;
|
||||
|
||||
import com.xspaceagi.system.application.service.UserApplicationService;
|
||||
import com.xspaceagi.system.domain.service.UserDomainService;
|
||||
import com.xspaceagi.system.infra.dao.entity.User;
|
||||
import com.xspaceagi.system.sdk.server.IUserRpcService;
|
||||
import com.xspaceagi.system.sdk.service.dto.UserDetailDto;
|
||||
import com.xspaceagi.system.spec.common.UserContext;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务查询接口实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserRpcServiceImpl implements IUserRpcService {
|
||||
|
||||
|
||||
@Resource
|
||||
private UserDomainService userDomainService;
|
||||
@Autowired
|
||||
private UserApplicationService userApplicationService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserContext> queryUserListByIds(List<Long> userIds) {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
var userList = this.userDomainService.queryUserListByIds(userIds);
|
||||
|
||||
var userInfoList = userList.stream().map(this::convertFromUser).toList();
|
||||
|
||||
|
||||
return userInfoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetailDto queryUserDetailByName(String userName) {
|
||||
User user = userDomainService.queryByUserName(userName);
|
||||
if (user == null) {
|
||||
user = userDomainService.queryByEmail(userName);
|
||||
}
|
||||
if (user == null) {
|
||||
user = userDomainService.queryByPhone(userName);
|
||||
}
|
||||
if (user != null) {
|
||||
UserDetailDto userDetailDto = new UserDetailDto();
|
||||
BeanUtils.copyProperties(user, userDetailDto);
|
||||
return userDetailDto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetailDto queryUserDetailById(Long userId) {
|
||||
User user = userDomainService.queryById(userId);
|
||||
if (user != null) {
|
||||
UserDetailDto userDetailDto = new UserDetailDto();
|
||||
BeanUtils.copyProperties(user, userDetailDto);
|
||||
return userDetailDto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private UserContext convertFromUser(User user) {
|
||||
|
||||
var status = User.Status.Enabled == user.getStatus() ? 1 : -1;
|
||||
|
||||
return UserContext.builder()
|
||||
.userId(user.getId())
|
||||
.avatar(user.getAvatar())
|
||||
.userName(user.getUserName())
|
||||
.nickName(user.getNickName())
|
||||
.email(user.getEmail())
|
||||
.phone(user.getPhone())
|
||||
.status(status)
|
||||
.orgId(null)
|
||||
.orgName(null)
|
||||
.roleType(1)
|
||||
.tenantId(user.getTenantId())
|
||||
.tenantName(null)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserDynamicCode(Long userId) {
|
||||
return userApplicationService.getUserDynamicCode(userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* api layer.
|
||||
*/
|
||||
package com.xspaceagi.system.api;
|
||||
@@ -0,0 +1,32 @@
|
||||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
|
||||
<id>repack</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<!--
|
||||
重新打包需要包含的jar包,这个过程会解压所有的jar包并按照jar的规则重新组合成一个jar包
|
||||
这里需要包含当前这个工程 ,格式是{groupId}:{artifactId}
|
||||
-->
|
||||
<includes>
|
||||
<!-- 包含项目自己 -->
|
||||
<include>com.xspaceagi:system-api</include>
|
||||
<include>com.xspaceagi:system-application</include>
|
||||
<include>com.xspaceagi:system-domain</include>
|
||||
<include>com.xspaceagi:system-infra</include>
|
||||
<include>com.xspaceagi:system-spec</include>
|
||||
</includes>
|
||||
<!-- 打包结果目录:/ 表示target/ -->
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<!-- 是否解压依赖 -->
|
||||
<unpack>true</unpack>
|
||||
<!-- 打包的scope -->
|
||||
<!-- <scope>system</scope>-->
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>system-api</artifactId>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>system-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user