diff --git a/.drone.yml b/.drone.yml index 45f7168..0a1d109 100644 --- a/.drone.yml +++ b/.drone.yml @@ -96,10 +96,7 @@ trigger: - code-gen - custom-query - sentinel-dashboard - - sentinel-dashboard-pro - - code-gen-test-mysql - workflow - - flowable event: - push \ No newline at end of file diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/MenuController.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/MenuController.java index 5ad6311..89ddf41 100644 --- a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/MenuController.java +++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/MenuController.java @@ -70,8 +70,9 @@ public class MenuController { return Result.ok(optionMenuVo); } - @ApiOperation("获取树形接口的option") + @ApiOperation("菜单详情") @GetMapping("/info/{menuId}") + @PreAuthorize("@ss.hasPermission('admin:menu:info')") public Result info(@PathVariable Long menuId) { ObjectUtils.checkPk(menuId); MenuVo menu = menuService.searchByMenuId(menuId); diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/UserController.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/UserController.java index a8cb041..c4e3418 100644 --- a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/UserController.java +++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/UserController.java @@ -76,7 +76,7 @@ public class UserController { return Result.ok(userChooseList); } - @ApiOperation("获取用户列表") + @ApiOperation("获取用户详情") @GetMapping("/info/{userId}") @PreAuthorize("@ss.hasPermission('admin:user:info')") public Result info(@PathVariable Long userId) { @@ -200,7 +200,7 @@ public class UserController { } - @ApiOperation("建立角色用户绑定关系") + @ApiOperation("建立岗位用户绑定关系") @PutMapping("/bind/post") @PreAuthorize("@ss.hasPermission('admin:user:bindPost')") @Log(title = "建立角色用户绑定关系", businessType = BusinessType.UPDATE) diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/IpBack.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/IpBack.java new file mode 100644 index 0000000..b0aa6e4 --- /dev/null +++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/IpBack.java @@ -0,0 +1,38 @@ +package cn.fateverse.admin.entity; + +import cn.fateverse.admin.vo.IpBackVo; +import cn.fateverse.common.core.annotaion.EnableAutoField; +import cn.fateverse.common.core.entity.BaseEntity; +import lombok.Data; + +/** + * @author Clay + * @date 2023-10-22 + */ +@Data +@EnableAutoField +public class IpBack extends BaseEntity { + /** + * 主键id + */ + private Long id; + /** + * ip地址 + */ + private String ipAddr; + /** + * ip类型 ipv4 ipv6 + */ + private String type; + + public IpBackVo toIPBackVo(){ + return IpBackVo.builder() + .id(id) + .ipAddr(ipAddr) + .type(type) + .createTime(getCreateTime()) + .remark(getRemark()) + .build(); + } + +} diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/vo/MappingSwitchVo.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/vo/MappingSwitchVo.java index ebb3ae7..721421f 100644 --- a/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/vo/MappingSwitchVo.java +++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/entity/vo/MappingSwitchVo.java @@ -87,19 +87,23 @@ public class MappingSwitchVo { private String operName; public static MappingSwitchVo toMappingSwitchVo(MappingSwitchInfo mappingSwitchInfo) { - return MappingSwitchVo.builder() + MappingSwitchVo mappingSwitchVo = MappingSwitchVo.builder() .key(mappingSwitchInfo.getKey()) .applicationName(mappingSwitchInfo.getApplicationName()) .className(mappingSwitchInfo.getClassName()) .description(mappingSwitchInfo.getDescription()) .methodName(mappingSwitchInfo.getMethodName()) .uris(mappingSwitchInfo.getUris()) - .type(mappingSwitchInfo.getType().toString()) .httpMethods(mappingSwitchInfo.getHttpMethods()) .state(mappingSwitchInfo.getState()) .operName(mappingSwitchInfo.getOperName()) .operTime(mappingSwitchInfo.getOperTime()) .build(); + MappingSwitchInfo.MappingSwitchType switchType = mappingSwitchInfo.getType(); + if (switchType != null) { + mappingSwitchVo.setType(switchType.name()); + } + return mappingSwitchVo; } diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/OnlineUserServiceImpl.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/OnlineUserServiceImpl.java index e502d9c..fff6f7e 100644 --- a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/OnlineUserServiceImpl.java +++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/OnlineUserServiceImpl.java @@ -1,5 +1,6 @@ package cn.fateverse.admin.service.impl; +import cn.fateverse.admin.entity.Dept; import cn.fateverse.common.core.entity.PageInfo; import cn.fateverse.common.core.result.page.TableDataInfo; import cn.fateverse.common.core.utils.TableSupport; @@ -35,7 +36,7 @@ public class OnlineUserServiceImpl implements OnlineUserService { * todo 现阶段一次性将所有用户全部返回,后期想办法进行分页操作 * * @param place - * @param username + * @param username 用户名 * @return */ @Override @@ -72,19 +73,25 @@ public class OnlineUserServiceImpl implements OnlineUserService { @Override public void force(String tokenId) { redisTemplate.delete(CacheConstants.LOGIN_TOKEN_KEY + tokenId); + redisTemplate.delete(CacheConstants.ROUTE_CACHE_KEY + tokenId); } private OnlineUser toOnlineUser(LoginUser user) { - return OnlineUser.builder() + OnlineUser onlineUser = OnlineUser.builder() .tokenId(user.getUuid()) .username(user.getUsername()) - .deptName(user.getUser().getDept().getDeptName()) .ipAddr(user.getIpddr()) .loginLocation(user.getLoginLocation()) .browser(user.getBrowser()) .os(user.getOs()) .loginTime(new Date(user.getLoginTime())) .build(); + + Dept dept = user.getUser().getDept(); + if (dept != null) { + onlineUser.setDeptName(dept.getDeptName()); + } + return onlineUser; } diff --git a/admin/admin-biz/src/main/resources/mapper/MenuMapper.xml b/admin/admin-biz/src/main/resources/mapper/MenuMapper.xml index 47cb8ff..ae9b968 100644 --- a/admin/admin-biz/src/main/resources/mapper/MenuMapper.xml +++ b/admin/admin-biz/src/main/resources/mapper/MenuMapper.xml @@ -61,13 +61,38 @@ diff --git a/auth/src/main/java/cn/fateverse/auth/service/impl/LoginServiceImpl.java b/auth/src/main/java/cn/fateverse/auth/service/impl/LoginServiceImpl.java index eb5ee91..bfd8e1c 100644 --- a/auth/src/main/java/cn/fateverse/auth/service/impl/LoginServiceImpl.java +++ b/auth/src/main/java/cn/fateverse/auth/service/impl/LoginServiceImpl.java @@ -31,6 +31,7 @@ import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; import javax.annotation.Resource; import java.util.ArrayList; @@ -156,11 +157,15 @@ public class LoginServiceImpl implements LoginService { @Override public List getMenuRouterByUserId() { - List result = (List) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId()); + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (ObjectUtils.isEmpty(loginUser)){ + throw new CustomException("获取用户信息失败!"); + } + List result = (List) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid()); if (result == null || result.isEmpty()) { - RLock lock = redissonClient.getLock(CacheConstants.ROUTE_CACHE_KEY + "lock:" + SecurityUtils.getUserId()); + RLock lock = redissonClient.getLock(CacheConstants.ROUTE_CACHE_KEY + "lock:" + loginUser.getUuid()); try { - result = (List) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId()); + result = (List) redisTemplate.opsForValue().get(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid()); if (result == null || result.isEmpty()) { result = menuService.selectMenuRouterByUserId(SecurityUtils.getUserId()); if (result == null || result.isEmpty()) { @@ -168,7 +173,7 @@ public class LoginServiceImpl implements LoginService { // throw new CustomException("获取路由异常!"); return new ArrayList<>(); } - redisTemplate.opsForValue().set(CacheConstants.ROUTE_CACHE_KEY + SecurityUtils.getUserId(),result,30, TimeUnit.MINUTES); + redisTemplate.opsForValue().set(CacheConstants.ROUTE_CACHE_KEY + loginUser.getUuid(), result, 30, TimeUnit.MINUTES); } } finally { if (lock.isLocked() && lock.isHeldByCurrentThread()) { diff --git a/common/common-core/src/main/java/cn/fateverse/common/core/constant/CacheConstants.java b/common/common-core/src/main/java/cn/fateverse/common/core/constant/CacheConstants.java index da569d4..bd13717 100644 --- a/common/common-core/src/main/java/cn/fateverse/common/core/constant/CacheConstants.java +++ b/common/common-core/src/main/java/cn/fateverse/common/core/constant/CacheConstants.java @@ -14,7 +14,7 @@ public class CacheConstants { /** * 路由缓存地址 */ - public static final String ROUTE_CACHE_KEY = "router_key:"; + public static final String ROUTE_CACHE_KEY = "router:key:"; /** * 登录用户 redis key */ diff --git a/common/common-dubbo/pom.xml b/common/common-dubbo/pom.xml index e6537a9..50a654f 100644 --- a/common/common-dubbo/pom.xml +++ b/common/common-dubbo/pom.xml @@ -12,11 +12,15 @@ common-dubbo - 3.0.3 + 3.2.1 UTF-8 + + cn.fateverse + common-core + org.apache.dubbo dubbo-registry-nacos @@ -45,6 +49,12 @@ org.apache.dubbo dubbo-spring-boot-starter ${dubbo.version} + + + com.alibaba.fastjson2 + fastjson2 + + diff --git a/common/common-log/src/main/java/cn/fateverse/common/log/LogAutoConfiguration.java b/common/common-log/src/main/java/cn/fateverse/common/log/LogAutoConfiguration.java index 005a4e8..26b0e44 100644 --- a/common/common-log/src/main/java/cn/fateverse/common/log/LogAutoConfiguration.java +++ b/common/common-log/src/main/java/cn/fateverse/common/log/LogAutoConfiguration.java @@ -6,6 +6,7 @@ import cn.fateverse.common.log.service.OperationService; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; /** @@ -17,13 +18,13 @@ import org.springframework.context.annotation.Bean; public class LogAutoConfiguration { @Bean - public LogAspect logAspect(){ + public LogAspect logAspect() { return new LogAspect(); } @Bean - public OperationService operationService(OperationProperties properties) { - return new OperationService(properties); + public OperationService operationService(OperationProperties properties, Environment environment) { + return new OperationService(properties, environment); } } diff --git a/common/common-log/src/main/java/cn/fateverse/common/log/aspect/LogAspect.java b/common/common-log/src/main/java/cn/fateverse/common/log/aspect/LogAspect.java index 8986fd8..cd1a62d 100644 --- a/common/common-log/src/main/java/cn/fateverse/common/log/aspect/LogAspect.java +++ b/common/common-log/src/main/java/cn/fateverse/common/log/aspect/LogAspect.java @@ -47,7 +47,7 @@ public class LogAspect { @Around("@within(log) || @annotation(log)") - public Object before(ProceedingJoinPoint point, Log log) throws Throwable { + public Object around(ProceedingJoinPoint point, Log log) throws Throwable { long startTime = System.currentTimeMillis(); try { Object proceed = point.proceed(point.getArgs()); diff --git a/common/common-log/src/main/java/cn/fateverse/common/log/service/OperationService.java b/common/common-log/src/main/java/cn/fateverse/common/log/service/OperationService.java index 3348e02..09cc235 100644 --- a/common/common-log/src/main/java/cn/fateverse/common/log/service/OperationService.java +++ b/common/common-log/src/main/java/cn/fateverse/common/log/service/OperationService.java @@ -11,10 +11,12 @@ import com.alibaba.fastjson2.JSON; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.core.env.Environment; import org.springframework.scheduling.annotation.Async; import org.springframework.util.ObjectUtils; import javax.annotation.PostConstruct; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -35,14 +37,23 @@ public class OperationService { @DubboReference private DubboLogService logService; + + private final String applicationName; + private final OperationProperties properties; private final List operationLogListCache; - public OperationService(OperationProperties properties) { + public OperationService(OperationProperties properties, Environment environment) { this.properties = properties; this.operationLogListCache = new ArrayList<>(properties.getCacheSize()); + String applicationName = environment.getProperty("spring.application.name"); + if (ObjectUtils.isEmpty(applicationName)) { + log.error("applicationName can not be null"); + throw new RuntimeException("applicationName can not be null"); + } + this.applicationName = applicationName; } @@ -62,6 +73,7 @@ public class OperationService { @Async public void asyncExecute(OperationLog operationLog, Object jsonResult, Throwable e, Long time) { operationLog.setState(BusinessState.SUCCESS.ordinal()); + operationLog.setApplicationName(applicationName); // 返回参数 if (jsonResult instanceof Result) { Result result = (Result) jsonResult; diff --git a/common/common-seata/pom.xml b/common/common-seata/pom.xml index 2fdabbd..782ba98 100644 --- a/common/common-seata/pom.xml +++ b/common/common-seata/pom.xml @@ -23,6 +23,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-seata + + + com.alibaba + fastjson + + io.seata diff --git a/common/common-security/pom.xml b/common/common-security/pom.xml index a1b3f92..d6159a0 100644 --- a/common/common-security/pom.xml +++ b/common/common-security/pom.xml @@ -27,6 +27,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + com.alibaba + fastjson + + diff --git a/common/common-security/src/main/java/cn/fateverse/common/security/service/TokenService.java b/common/common-security/src/main/java/cn/fateverse/common/security/service/TokenService.java index b8f70e7..d837632 100644 --- a/common/common-security/src/main/java/cn/fateverse/common/security/service/TokenService.java +++ b/common/common-security/src/main/java/cn/fateverse/common/security/service/TokenService.java @@ -118,6 +118,7 @@ public class TokenService { if (!StrUtil.isEmpty(token)) { String userKey = getTokenKey(token); redisTemplate.delete(userKey); + redisTemplate.delete(CacheConstants.ROUTE_CACHE_KEY + token); } } diff --git a/gateway/pom.xml b/gateway/pom.xml index 79ffb34..ee7b72e 100644 --- a/gateway/pom.xml +++ b/gateway/pom.xml @@ -27,6 +27,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-sentinel + + + com.alibaba + fastjson + + diff --git a/log/log-api/src/main/java/cn/fateverse/log/entity/OperationLog.java b/log/log-api/src/main/java/cn/fateverse/log/entity/OperationLog.java index d4b18ff..c8d15d2 100644 --- a/log/log-api/src/main/java/cn/fateverse/log/entity/OperationLog.java +++ b/log/log-api/src/main/java/cn/fateverse/log/entity/OperationLog.java @@ -27,6 +27,11 @@ public class OperationLog implements Serializable { */ private Long userId; + /** + * 应用名称 + */ + private String applicationName; + /** * 操作模块 */ diff --git a/log/log-api/src/main/java/cn/fateverse/log/query/OperationLogQuery.java b/log/log-api/src/main/java/cn/fateverse/log/query/OperationLogQuery.java index 27d8349..7bb5cc9 100644 --- a/log/log-api/src/main/java/cn/fateverse/log/query/OperationLogQuery.java +++ b/log/log-api/src/main/java/cn/fateverse/log/query/OperationLogQuery.java @@ -1,7 +1,6 @@ package cn.fateverse.log.query; import cn.fateverse.common.core.entity.QueryTime; -import io.swagger.annotations.ApiModel; import lombok.Data; @@ -12,7 +11,6 @@ import lombok.Data; * @Version: V2.0 */ @Data -@ApiModel("日志查询实体") public class OperationLogQuery extends QueryTime { /** @@ -20,6 +18,8 @@ public class OperationLogQuery extends QueryTime { */ private String title; + private String applicationName; + /** * 操作人员 */ diff --git a/log/log-api/src/main/java/cn/fateverse/log/vo/OperationLogVo.java b/log/log-api/src/main/java/cn/fateverse/log/vo/OperationLogVo.java index 3b67251..129ef45 100644 --- a/log/log-api/src/main/java/cn/fateverse/log/vo/OperationLogVo.java +++ b/log/log-api/src/main/java/cn/fateverse/log/vo/OperationLogVo.java @@ -32,6 +32,8 @@ public class OperationLogVo implements Serializable { */ private String title; + private String applicationName; + /** * 业务类型(0其它 1新增 2修改 3删除) */ @@ -111,6 +113,7 @@ public class OperationLogVo implements Serializable { public static OperationLogVo toOperationLogVo(OperationLog operationLog) { return OperationLogVo.builder() .operId(operationLog.getOperId()) + .applicationName(operationLog.getApplicationName()) .title(operationLog.getTitle()) .businessType(operationLog.getBusinessType()) .method(operationLog.getMethod()) diff --git a/log/log-biz/src/main/java/cn/fateverse/log/controller/OperationLogController.java b/log/log-biz/src/main/java/cn/fateverse/log/controller/OperationLogController.java index ce804bf..595bb9a 100644 --- a/log/log-biz/src/main/java/cn/fateverse/log/controller/OperationLogController.java +++ b/log/log-biz/src/main/java/cn/fateverse/log/controller/OperationLogController.java @@ -2,12 +2,9 @@ package cn.fateverse.log.controller; import cn.fateverse.common.core.result.Result; import cn.fateverse.common.core.result.page.TableDataInfo; -import cn.fateverse.common.security.annotation.Anonymity; import cn.fateverse.log.query.OperationLogQuery; import cn.fateverse.log.service.OperationService; import cn.fateverse.log.vo.OperationLogVo; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -19,7 +16,6 @@ import org.springframework.web.bind.annotation.*; * @author Clay * @date 2022/11/1 */ -@Api(tags = "操作日志管理") @Slf4j @RestController @RequestMapping("/log") @@ -31,13 +27,7 @@ public class OperationLogController { this.operationService = operationService; } - /** - * @param operationLogQuery - * @return - */ @GetMapping("/list") - @Anonymity - @ApiOperation("查询日志信息") @PreAuthorize("@ss.hasPermission('admin:log:list')") public Result> SearchLog(OperationLogQuery operationLogQuery) { TableDataInfo dataTable = operationService.search(operationLogQuery); @@ -45,7 +35,6 @@ public class OperationLogController { } @GetMapping("/{operId}") - @ApiOperation("查询日志信息") @PreAuthorize("@ss.hasPermission('admin:log:list')") public Result SearchLog(@PathVariable Long operId) { OperationLogVo operationLogVo = operationService.select(operId); @@ -53,7 +42,6 @@ public class OperationLogController { } @DeleteMapping("/{operIds}") - @ApiOperation("操作日志删除") @PreAuthorize("@ss.hasPermission('admin:log:del')") public Result OperationInfoRemove(@PathVariable Long[] operIds) { if (operIds.length == 0) { diff --git a/log/log-biz/src/main/resources/mapper/OperationMapper.xml b/log/log-biz/src/main/resources/mapper/OperationMapper.xml index 88ba3ce..664229b 100644 --- a/log/log-biz/src/main/resources/mapper/OperationMapper.xml +++ b/log/log-biz/src/main/resources/mapper/OperationMapper.xml @@ -7,6 +7,7 @@ + @@ -24,15 +25,35 @@ + + select oper_id, + title, + application_name, + business_type, + method, + request_method, + operator_type, + oper_name, + dept_name, + oper_url, + oper_ip, + oper_location, + state, + oper_time, + consume_time + from sys_operation_log + + insert into sys_operation_log - (oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, + (oper_id, title, application_name, business_type, method, request_method, operator_type, oper_name, dept_name, + oper_url, oper_ip, oper_location, oper_param, json_result, state, error_msg, error_stack_trace, oper_time, consume_time) values - (#{log.operId}, #{log.title}, #{log.businessType}, #{log.method}, #{log.requestMethod}, #{log.operatorType}, - #{log.operName}, + (#{log.operId}, #{log.title}, #{log.applicationName}, #{log.businessType}, #{log.method}, + #{log.requestMethod}, #{log.operatorType},#{log.operName}, #{log.deptName}, #{log.operUrl}, #{log.operIp}, #{log.operLocation}, #{log.operParam}, #{log.jsonResult}, #{log.state}, #{log.errorMsg}, #{log.errorStackTrace}, #{log.operTime}, #{log.consumeTime}) @@ -41,15 +62,16 @@ - select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, - oper_ip, oper_location, state, oper_time, consume_time - from sys_operation_log + and title like concat('%',#{operation.title},'%') + + and application_name like concat('%',#{operation.applicationName},'%') + and oper_name like concat('%',#{operation.operName},'%') @@ -125,6 +151,9 @@ and title like concat('%',#{operation.title},'%') + + and application_name like concat('%',#{operation.applicationName},'%') + and oper_name like concat('%',#{operation.operName},'%') @@ -153,6 +182,7 @@