✨ SYSTEM:同步 jdk21 boot 最新代码
✨ INFRA:同步 jdk21 boot 最新代码
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
|
||||
import cn.iocoder.yudao.module.system.enums.ApiConstants;
|
||||
import feign.QueryMap;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -21,4 +27,12 @@ public interface OperateLogApi {
|
||||
@Operation(summary = "创建操作日志")
|
||||
CommonResult<Boolean> createOperateLog(@Valid @RequestBody OperateLogCreateReqDTO createReqDTO);
|
||||
|
||||
@PostMapping(PREFIX + "/create-v2")
|
||||
@Operation(summary = "创建操作日志")
|
||||
CommonResult<Boolean> createOperateLogV2(@Valid OperateLogV2CreateReqDTO createReqDTO);
|
||||
|
||||
@PostMapping(PREFIX + "/page")
|
||||
@Operation(summary = "获取指定模块的指定数据的操作日志分页")
|
||||
CommonResult<PageResult<OperateLogV2RespDTO>> getOperateLogPage(@QueryMap OperateLogV2PageReqDTO pageReqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(name = "RPC 服务 - 系统操作日志 Create Request DTO")
|
||||
@Data
|
||||
public class OperateLogV2CreateReqDTO {
|
||||
|
||||
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2" )
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
@Schema(description = "操作模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单")
|
||||
@NotEmpty(message = "操作模块类型不能为空")
|
||||
private String type;
|
||||
@Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单")
|
||||
@NotEmpty(message = "操作名不能为空")
|
||||
private String subType;
|
||||
@Schema(description = "操作模块业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "188")
|
||||
@NotNull(message = "操作模块业务编号不能为空")
|
||||
private Long bizId;
|
||||
@Schema(description = "操作内容", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码")
|
||||
@NotEmpty(message = "操作内容不能为空")
|
||||
private String action;
|
||||
@Schema(description = "拓展字段", example = "{\"orderId\": \"1\"}")
|
||||
private String extra;
|
||||
|
||||
@Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET")
|
||||
@NotEmpty(message = "请求方法名不能为空")
|
||||
private String requestMethod;
|
||||
@Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/order/get")
|
||||
@NotEmpty(message = "请求地址不能为空")
|
||||
private String requestUrl;
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1")
|
||||
@NotEmpty(message = "用户 IP 不能为空")
|
||||
private String userIp;
|
||||
@Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0")
|
||||
@NotEmpty(message = "浏览器 UA 不能为空")
|
||||
private String userAgent;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(name = "RPC 服务 - 操作日志分页 Request DTO")
|
||||
@Data
|
||||
public class OperateLogV2PageReqDTO extends PageParam {
|
||||
|
||||
// TODO @puhui999:应该用 type?
|
||||
@Schema(description = "模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单")
|
||||
private String bizType;
|
||||
|
||||
@Schema(description = "模块数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "188")
|
||||
private Long bizId;
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(name = "RPC 服务 - 系统操作日志 Response DTO")
|
||||
@Data
|
||||
public class OperateLogV2RespDTO {
|
||||
|
||||
@Schema(description = "链路追踪编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
private Long userId;
|
||||
@Schema(description = "用户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
|
||||
private String userName;
|
||||
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2" )
|
||||
private Integer userType;
|
||||
@Schema(description = "操作模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单")
|
||||
private String type;
|
||||
@Schema(description = "操作名", requiredMode = Schema.RequiredMode.REQUIRED, example = "创建订单")
|
||||
private String subType;
|
||||
@Schema(description = "操作模块业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "188")
|
||||
private Long bizId;
|
||||
@Schema(description = "操作内容", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码")
|
||||
private String action;
|
||||
@Schema(description = "拓展字段", example = "{\"orderId\": \"1\"}")
|
||||
private String extra;
|
||||
|
||||
@Schema(description = "请求方法名", requiredMode = Schema.RequiredMode.REQUIRED, example = "GET")
|
||||
private String requestMethod;
|
||||
@Schema(description = "请求地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "/order/get")
|
||||
private String requestUrl;
|
||||
@Schema(description = "用户 IP", requiredMode = Schema.RequiredMode.REQUIRED, example = "127.0.0.1")
|
||||
private String userIp;
|
||||
@Schema(description = "浏览器 UserAgent", requiredMode = Schema.RequiredMode.REQUIRED, example = "Mozilla/5.0")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.api.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
||||
@@ -28,17 +29,28 @@ public interface SocialUserApi {
|
||||
@Operation(summary = "取消绑定社交用户")
|
||||
CommonResult<Boolean> unbindSocialUser(@Valid @RequestBody SocialUserUnbindReqDTO reqDTO);
|
||||
|
||||
@GetMapping(PREFIX + "/get")
|
||||
@Operation(summary = "获得社交用户的绑定用户编号")
|
||||
@GetMapping(PREFIX + "/get-by-user-id")
|
||||
@Operation(summary = "获得社交用户,基于 userId")
|
||||
@Parameters({
|
||||
@Parameter(name = "userType", description = "用户类型", example = "2", required = true),
|
||||
@Parameter(name = "userId", description = "用户编号", example = "1024", required = true),
|
||||
@Parameter(name = "socialType", description = "社交平台的类型", example = "1", required = true),
|
||||
})
|
||||
CommonResult<SocialUserRespDTO> getSocialUserByUserId(@RequestParam("userType") Integer userType,
|
||||
@RequestParam("userId") Long userId,
|
||||
@RequestParam("socialType") Integer socialType);
|
||||
|
||||
@GetMapping(PREFIX + "/get-by-code")
|
||||
@Operation(summary = "获得社交用") // 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常
|
||||
@Parameters({
|
||||
@Parameter(name = "userType", description = "用户类型", example = "2", required = true),
|
||||
@Parameter(name = "socialType", description = "社交平台的类型", example = "1", required = true),
|
||||
@Parameter(name = "code", description = "授权码", required = true, example = "tudou"),
|
||||
@Parameter(name = "state", description = "state", required = true, example = "coke")
|
||||
@Parameter(name = "code", description = "授权码", example = "88888", required = true),
|
||||
@Parameter(name = "state", description = "state", example = "666", required = true),
|
||||
})
|
||||
CommonResult<SocialUserRespDTO> getSocialUser(@RequestParam("userType") Integer userType,
|
||||
@RequestParam("socialType") Integer socialType,
|
||||
@RequestParam("code") String code,
|
||||
@RequestParam("state") String state);
|
||||
CommonResult<SocialUserRespDTO> getSocialUserByCode(@RequestParam("userType") Integer userType,
|
||||
@RequestParam("socialType") Integer socialType,
|
||||
@RequestParam("code") String code,
|
||||
@RequestParam("state") String state);
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,12 @@ public class SocialUserRespDTO {
|
||||
@Schema(description = "社交用户 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "zsw")
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "社交用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "社交用户的头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.jpg")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "关联的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long userId;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public enum SmsSceneEnum implements IntArrayValuable {
|
||||
|
||||
MEMBER_LOGIN(1, "user-sms-login", "会员用户 - 手机号登陆"),
|
||||
MEMBER_UPDATE_MOBILE(2, "user-update-mobile", "会员用户 - 修改手机"),
|
||||
MEMBER_UPDATE_PASSWORD(3, "user-update-mobile", "会员用户 - 修改密码"),
|
||||
MEMBER_UPDATE_PASSWORD(3, "user-update-password", "会员用户 - 修改密码"),
|
||||
MEMBER_RESET_PASSWORD(4, "user-reset-password", "会员用户 - 忘记密码"),
|
||||
|
||||
ADMIN_MEMBER_LOGIN(21, "admin-sms-login", "后台用户 - 手机号登录");
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
|
||||
import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.logger.OperateLogService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||
@Validated
|
||||
@@ -16,6 +28,8 @@ public class OperateLogApiImpl implements OperateLogApi {
|
||||
|
||||
@Resource
|
||||
private OperateLogService operateLogService;
|
||||
@Resource
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> createOperateLog(OperateLogCreateReqDTO createReqDTO) {
|
||||
@@ -23,4 +37,23 @@ public class OperateLogApiImpl implements OperateLogApi {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO) {
|
||||
operateLogService.createOperateLogV2(createReqDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<PageResult<OperateLogV2RespDTO>> getOperateLogPage(OperateLogV2PageReqDTO pageReqVO) {
|
||||
PageResult<OperateLogV2DO> operateLogPage = operateLogService.getOperateLogPage(pageReqVO);
|
||||
if (CollUtil.isEmpty(operateLogPage.getList())) {
|
||||
return success(PageResult.empty());
|
||||
}
|
||||
|
||||
// 获取用户
|
||||
List<AdminUserDO> userList = adminUserService.getUserList(
|
||||
convertSet(operateLogPage.getList(), OperateLogV2DO::getUserId));
|
||||
return success(OperateLogConvert.INSTANCE.convertPage(operateLogPage, userList));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,13 @@ public class SocialUserApiImpl implements SocialUserApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<SocialUserRespDTO> getSocialUser(Integer userType, Integer socialType, String code, String state) {
|
||||
return success(socialUserService.getSocialUser(userType, socialType, code, state));
|
||||
public CommonResult<SocialUserRespDTO> getSocialUserByUserId(Integer userType, Long userId, Integer socialType) {
|
||||
return success(socialUserService.getSocialUserByUserId(userType, userId, socialType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<SocialUserRespDTO> getSocialUserByCode(Integer userType, Integer socialType, String code, String state) {
|
||||
return success(socialUserService.getSocialUserByCode(userType, socialType, code, state));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.system.controller.admin.ip;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.Area;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.IPUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -31,7 +31,7 @@ public class AreaController {
|
||||
public CommonResult<List<AreaNodeRespVO>> getAreaTree() {
|
||||
Area area = AreaUtils.getArea(Area.ID_CHINA);
|
||||
Assert.notNull(area, "获取不到中国");
|
||||
return success(AreaConvert.INSTANCE.convertList(area.getChildren()));
|
||||
return success(BeanUtils.toBean(area.getChildren(), AreaNodeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get-by-ip")
|
||||
|
||||
@@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.system.controller.app.ip;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.Area;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.app.ip.vo.AppAreaNodeRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -28,7 +28,7 @@ public class AppAreaController {
|
||||
public CommonResult<List<AppAreaNodeRespVO>> getAreaTree() {
|
||||
Area area = AreaUtils.getArea(Area.ID_CHINA);
|
||||
Assert.notNull(area, "获取不到中国");
|
||||
return success(AreaConvert.INSTANCE.convertList3(area.getChildren()));
|
||||
return success(BeanUtils.toBean(area.getChildren(), AppAreaNodeRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package cn.iocoder.yudao.module.system.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@@ -12,6 +15,9 @@ import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||
|
||||
@Mapper
|
||||
public interface OperateLogConvert {
|
||||
|
||||
@@ -25,4 +31,19 @@ public interface OperateLogConvert {
|
||||
});
|
||||
}
|
||||
|
||||
default PageResult<OperateLogV2RespDTO> convertPage(PageResult<OperateLogV2DO> operateLogPage, List<AdminUserDO> userList) {
|
||||
return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class).setList(setUserInfo(operateLogPage.getList(), userList));
|
||||
}
|
||||
|
||||
OperateLogV2RespDTO convert(OperateLogV2DO operateLogV2DO);
|
||||
|
||||
default List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
|
||||
Map<Long, AdminUserDO> userMap = convertMap(userList, AdminUserDO::getId);
|
||||
return CollectionUtils.convertList(logList, item -> {
|
||||
OperateLogV2RespDTO respDTO = convert(item);
|
||||
findAndThen(userMap, item.getUserId(), user -> respDTO.setUserName(user.getNickname()));
|
||||
return respDTO;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 操作日志表 V2
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "system_operate_log_v2", autoResultMap = true)
|
||||
@KeySequence("system_operate_log_seq_v2") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OperateLogV2DO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 日志主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 链路追踪编号
|
||||
*
|
||||
* 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。
|
||||
*/
|
||||
private String traceId;
|
||||
/**
|
||||
* 用户编号
|
||||
*
|
||||
* 关联 MemberUserDO 的 id 属性,或者 AdminUserDO 的 id 属性
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*
|
||||
* 关联 {@link UserTypeEnum}
|
||||
*/
|
||||
private Integer userType;
|
||||
/**
|
||||
* 操作模块类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 操作名
|
||||
*/
|
||||
private String subType;
|
||||
/**
|
||||
* 操作模块业务编号
|
||||
*/
|
||||
private Long bizId;
|
||||
/**
|
||||
* 日志内容,记录整个操作的明细
|
||||
*
|
||||
* 例如说,修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。
|
||||
*/
|
||||
private String action;
|
||||
/**
|
||||
* 拓展字段,有些复杂的业务,需要记录一些字段 ( JSON 格式 )
|
||||
*
|
||||
* 例如说,记录订单编号,{ orderId: "1"}
|
||||
*/
|
||||
private String extra;
|
||||
|
||||
/**
|
||||
* 请求方法名
|
||||
*/
|
||||
private String requestMethod;
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String requestUrl;
|
||||
/**
|
||||
* 用户 IP
|
||||
*/
|
||||
private String userIp;
|
||||
/**
|
||||
* 浏览器 UA
|
||||
*/
|
||||
private String userAgent;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface OperateLogV2Mapper extends BaseMapperX<OperateLogV2DO> {
|
||||
|
||||
default PageResult<OperateLogV2DO> selectPage(OperateLogV2PageReqDTO pageReqDTO) {
|
||||
return selectPage(pageReqDTO, new LambdaQueryWrapperX<OperateLogV2DO>()
|
||||
.eqIfPresent(OperateLogV2DO::getType, pageReqDTO.getBizType())
|
||||
.eqIfPresent(OperateLogV2DO::getBizId, pageReqDTO.getBizId())
|
||||
.eqIfPresent(OperateLogV2DO::getUserId, pageReqDTO.getUserId())
|
||||
.orderByDesc(OperateLogV2DO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,4 +34,11 @@ public interface SocialUserBindMapper extends BaseMapperX<SocialUserBindDO> {
|
||||
.eq(SocialUserBindDO::getUserType, userType));
|
||||
}
|
||||
|
||||
default SocialUserBindDO selectByUserIdAndUserTypeAndSocialType(Long userId, Integer userType, Integer socialType) {
|
||||
return selectOne(new LambdaQueryWrapperX<SocialUserBindDO>()
|
||||
.eq(SocialUserBindDO::getUserId, userId)
|
||||
.eq(SocialUserBindDO::getUserType, userType)
|
||||
.eq(SocialUserBindDO::getSocialType, socialType));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -156,9 +156,9 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Override
|
||||
public AuthLoginRespVO socialLogin(AuthSocialLoginReqVO reqVO) {
|
||||
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(),
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUserByCode(UserTypeEnum.ADMIN.getValue(), reqVO.getType(),
|
||||
reqVO.getCode(), reqVO.getState());
|
||||
if (socialUser == null) {
|
||||
if (socialUser == null || socialUser.getUserId() == null) {
|
||||
throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.system.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
|
||||
/**
|
||||
* 操作日志 Service 接口
|
||||
@@ -27,4 +30,21 @@ public interface OperateLogService {
|
||||
*/
|
||||
PageResult<OperateLogDO> getOperateLogPage(OperateLogPageReqVO pageReqVO);
|
||||
|
||||
// ======================= LOG V2 =======================
|
||||
|
||||
/**
|
||||
* 记录操作日志 V2
|
||||
*
|
||||
* @param createReqDTO 创建请求
|
||||
*/
|
||||
void createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO);
|
||||
|
||||
/**
|
||||
* 获得操作日志分页列表
|
||||
*
|
||||
* @param pageReqVO 分页条件
|
||||
* @return 操作日志分页列表
|
||||
*/
|
||||
PageResult<OperateLogV2DO> getOperateLogPage(OperateLogV2PageReqDTO pageReqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,20 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.string.StrUtils;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogV2Mapper;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
@@ -34,6 +38,8 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
|
||||
@Resource
|
||||
private OperateLogMapper operateLogMapper;
|
||||
@Resource
|
||||
private OperateLogV2Mapper operateLogV2Mapper;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
@@ -60,4 +66,17 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
return operateLogMapper.selectPage(pageReqVO, userIds);
|
||||
}
|
||||
|
||||
// ======================= LOG V2 =======================
|
||||
|
||||
@Override
|
||||
public void createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO) {
|
||||
OperateLogV2DO log = BeanUtils.toBean(createReqDTO, OperateLogV2DO.class);
|
||||
operateLogV2Mapper.insert(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<OperateLogV2DO> getOperateLogPage(OperateLogV2PageReqDTO pageReqDTO) {
|
||||
return operateLogV2Mapper.selectPage(pageReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,6 +45,16 @@ public interface SocialUserService {
|
||||
*/
|
||||
void unbindSocialUser(Long userId, Integer userType, Integer socialType, String openid);
|
||||
|
||||
/**
|
||||
* 获得社交用户,基于 userId
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param userId 用户编号
|
||||
* @param socialType 社交平台的类型
|
||||
* @return 社交用户
|
||||
*/
|
||||
SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType);
|
||||
|
||||
/**
|
||||
* 获得社交用户
|
||||
*
|
||||
@@ -56,7 +66,7 @@ public interface SocialUserService {
|
||||
* @param state state
|
||||
* @return 社交用户
|
||||
*/
|
||||
SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state);
|
||||
SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state);
|
||||
|
||||
// ==================== 社交用户 CRUD ====================
|
||||
|
||||
|
||||
@@ -13,20 +13,19 @@ import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import com.xingyuv.jushauth.model.AuthUser;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.AUTH_THIRD_LOGIN_NOT_BIND;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_USER_NOT_FOUND;
|
||||
|
||||
/**
|
||||
@@ -94,18 +93,30 @@ public class SocialUserServiceImpl implements SocialUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state) {
|
||||
public SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType) {
|
||||
// 获得绑定用户
|
||||
SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserIdAndUserTypeAndSocialType(userId, userType, socialType);
|
||||
if (socialUserBind == null) {
|
||||
return null;
|
||||
}
|
||||
// 获得社交用户
|
||||
SocialUserDO socialUser = socialUserMapper.selectById(socialUserBind.getSocialUserId());
|
||||
Assert.notNull(socialUser, "社交用户不能为空");
|
||||
return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(),
|
||||
socialUserBind.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state) {
|
||||
// 获得社交用户
|
||||
SocialUserDO socialUser = authSocialUser(socialType, userType, code, state);
|
||||
Assert.notNull(socialUser, "社交用户不能为空");
|
||||
|
||||
// 如果未绑定的社交用户,则无法自动登录,进行报错
|
||||
// 获得绑定用户
|
||||
SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserTypeAndSocialUserId(userType,
|
||||
socialUser.getId());
|
||||
if (socialUserBind == null) {
|
||||
throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
|
||||
}
|
||||
return new SocialUserRespDTO(socialUser.getOpenid(), socialUserBind.getUserId());
|
||||
return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(),
|
||||
socialUserBind != null ? socialUserBind.getUserId() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -236,8 +236,8 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest {
|
||||
AuthSocialLoginReqVO reqVO = randomPojo(AuthSocialLoginReqVO.class);
|
||||
// mock 方法(绑定的用户编号)
|
||||
Long userId = 1L;
|
||||
when(socialUserService.getSocialUser(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()),
|
||||
eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(new SocialUserRespDTO(randomString(), userId));
|
||||
when(socialUserService.getSocialUserByCode(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()),
|
||||
eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(new SocialUserRespDTO(randomString(), randomString(), randomString(), userId));
|
||||
// mock(用户)
|
||||
AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(userId));
|
||||
when(userService.getUser(eq(userId))).thenReturn(user);
|
||||
|
||||
@@ -147,7 +147,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
||||
socialUserBindMapper.insert(socialUserBind);
|
||||
|
||||
// 调用
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUser(userType, type, code, state);
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUserByCode(userType, type, code, state);
|
||||
// 断言
|
||||
assertEquals(userId, socialUser.getUserId());
|
||||
assertEquals(socialUserDO.getOpenid(), socialUser.getOpenid());
|
||||
|
||||
Reference in New Issue
Block a user