mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-02 04:57:16 +08:00
新增:个人中心新增查询操作日志功能,优化日志表结构,并支持关闭记录内网 IP 操作
This commit is contained in:
@@ -21,13 +21,13 @@ import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 操作日志
|
||||
* 系统日志上下文
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/25 8:59
|
||||
*/
|
||||
@Data
|
||||
public class OperationLog {
|
||||
public class LogContext {
|
||||
|
||||
/**
|
||||
* 操作人
|
||||
@@ -43,5 +43,4 @@ public class OperationLog {
|
||||
* 异常
|
||||
*/
|
||||
private Exception exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.model.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import org.springdoc.api.annotations.ParameterObject;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 分页查询条件
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/15 10:59
|
||||
*/
|
||||
@Data
|
||||
@ParameterObject
|
||||
@Schema(description = "分页查询条件")
|
||||
public class PageQuery implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
@Schema(description = "页码")
|
||||
private int page;
|
||||
|
||||
/**
|
||||
* 每页记录数
|
||||
*/
|
||||
@Schema(description = "每页记录数")
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* 排序条件
|
||||
*/
|
||||
@Schema(description = "排序条件", example = "sort=published,desc&sort=title,asc")
|
||||
private String[] sort;
|
||||
|
||||
/** 默认页码:1 */
|
||||
private static final int DEFAULT_PAGE = 1;
|
||||
|
||||
/** 默认每页记录数:int 最大值 */
|
||||
private static final int DEFAULT_SIZE = Integer.MAX_VALUE;
|
||||
private static final String DELIMITER = ",";
|
||||
|
||||
public PageQuery() {
|
||||
this.page = DEFAULT_PAGE;
|
||||
this.size = DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析排序条件为 Spring 分页排序实体
|
||||
*
|
||||
* @return Spring 分页排序实体
|
||||
*/
|
||||
public Sort getSort() {
|
||||
if (ArrayUtil.isEmpty(sort)) {
|
||||
return Sort.unsorted();
|
||||
}
|
||||
|
||||
List<Sort.Order> orders = new ArrayList<>(sort.length);
|
||||
if (sort[0].contains(DELIMITER)) {
|
||||
// e.g "sort=published,desc&sort=title,asc"
|
||||
for (String s : sort) {
|
||||
String[] sortArr = s.split(DELIMITER);
|
||||
Sort.Order order = new Sort.Order(Sort.Direction.valueOf(sortArr[1].toUpperCase()), sortArr[0]);
|
||||
orders.add(order);
|
||||
}
|
||||
} else {
|
||||
// e.g "sort=published,desc"
|
||||
Sort.Order order = new Sort.Order(Sort.Direction.valueOf(sort[1].toUpperCase()), sort[0]);
|
||||
orders.add(order);
|
||||
}
|
||||
return Sort.by(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于分页查询条件转换为 MyBatis Plus 分页条件
|
||||
*
|
||||
* @param <T>
|
||||
* 列表数据类型
|
||||
* @return MyBatis Plus 分页条件
|
||||
*/
|
||||
public <T> IPage<T> toPage() {
|
||||
Page<T> mybatisPage = new Page<>(this.getPage(), this.getSize());
|
||||
Sort pageSort = this.getSort();
|
||||
if (CollUtil.isNotEmpty(pageSort)) {
|
||||
for (Sort.Order order : pageSort) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
orderItem.setAsc(order.isAscending());
|
||||
orderItem.setColumn(StrUtil.toUnderlineCase(order.getProperty()));
|
||||
mybatisPage.addOrder(orderItem);
|
||||
}
|
||||
}
|
||||
return mybatisPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.model.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
|
||||
/**
|
||||
* 分页信息
|
||||
*
|
||||
* @param <V>
|
||||
* 列表数据类型
|
||||
* @author Charles7c
|
||||
* @since 2023/1/14 23:40
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(description = "分页信息")
|
||||
public class PageInfo<V> {
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
@Schema(description = "列表数据")
|
||||
private List<V> list;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
@Schema(description = "总记录数")
|
||||
private long total;
|
||||
|
||||
/**
|
||||
* 基于 MyBatis Plus 分页数据构建分页信息,并将源数据转换为指定类型数据
|
||||
*
|
||||
* @param page
|
||||
* MyBatis Plus 分页数据
|
||||
* @param targetClass
|
||||
* 目标类型 Class 对象
|
||||
* @param <T>
|
||||
* 源列表数据类型
|
||||
* @param <V>
|
||||
* 目标列表数据类型
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <T, V> PageInfo<V> build(IPage<T> page, Class<V> targetClass) {
|
||||
if (page == null) {
|
||||
return null;
|
||||
}
|
||||
PageInfo<V> pageInfo = new PageInfo<>();
|
||||
pageInfo.setList(BeanUtil.copyToList(page.getRecords(), targetClass));
|
||||
pageInfo.setTotal(page.getTotal());
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于 MyBatis Plus 分页数据构建分页信息
|
||||
*
|
||||
* @param page
|
||||
* MyBatis Plus 分页数据
|
||||
* @param <V>
|
||||
* 列表数据类型
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <V> PageInfo<V> build(IPage<V> page) {
|
||||
if (page == null) {
|
||||
return null;
|
||||
}
|
||||
PageInfo<V> pageInfo = new PageInfo<>();
|
||||
pageInfo.setList(page.getRecords());
|
||||
pageInfo.setTotal(pageInfo.getTotal());
|
||||
return pageInfo;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package top.charles7c.cnadmin.common.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
@@ -36,9 +35,7 @@ import org.springframework.http.HttpStatus;
|
||||
@Data
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Schema(description = "响应信息")
|
||||
public class R<V extends Serializable> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public class R<V> {
|
||||
|
||||
/** 是否成功 */
|
||||
@Schema(description = "是否成功")
|
||||
@@ -72,39 +69,39 @@ public class R<V extends Serializable> implements Serializable {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> ok() {
|
||||
public static <V> R<V> ok() {
|
||||
return new R<>(true, SUCCESS_CODE, "操作成功", null);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> ok(V data) {
|
||||
public static <V> R<V> ok(V data) {
|
||||
return new R<>(true, SUCCESS_CODE, "操作成功", data);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> ok(String msg) {
|
||||
public static <V> R<V> ok(String msg) {
|
||||
return new R<>(true, SUCCESS_CODE, msg, null);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> ok(String msg, V data) {
|
||||
public static <V> R<V> ok(String msg, V data) {
|
||||
return new R<>(true, SUCCESS_CODE, msg, data);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> fail() {
|
||||
public static <V> R<V> fail() {
|
||||
return new R<>(false, FAIL_CODE, "操作失败", null);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> fail(String msg) {
|
||||
public static <V> R<V> fail(String msg) {
|
||||
return new R<>(false, FAIL_CODE, msg, null);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> fail(V data) {
|
||||
public static <V> R<V> fail(V data) {
|
||||
return new R<>(false, FAIL_CODE, "操作失败", data);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> fail(String msg, V data) {
|
||||
public static <V> R<V> fail(String msg, V data) {
|
||||
return new R<>(false, FAIL_CODE, msg, data);
|
||||
}
|
||||
|
||||
public static <V extends Serializable> R<V> fail(int code, String msg) {
|
||||
public static <V> R<V> fail(int code, String msg) {
|
||||
return new R<>(false, code, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user