mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-23 12:27:20 +08:00
# 2022-04-10
### 1.4.4开源社区版: 无 ### 0.3.5 专业版: 【新增】增加用户操作日志,可记录接口也可记录后台,同时支持本地存储或数据库存储。支持配置文件开启。 【新增】数据库增加用户操作日志表。 【优化】优化反射获取所有Controller 和Action的全局方法,增加缓存设置。 【优化】优化记录IP请求数据的中间件。 【修复】修复ios下用户充值余额的功能不显示的情况。 【修复】修复我的余额面板列表中右侧三角无反应的问题。 【修复】修复代理中心下线人数和订单数量统计错误的问题。#I51OUC
This commit is contained in:
@@ -345,7 +345,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
public AdminUiCallBack GetAllControllerAndActionByAssembly()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var data = AdminsControllerPermission.GetAllControllerAndActionByAssembly();
|
||||
var data = AdminsControllerPermission.GetCacheCoreCmsControllerPermission();
|
||||
jm.data = data.OrderBy(u => u.name).ToList();
|
||||
jm.code = 0;
|
||||
jm.msg = "获取成功";
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2022/4/10 0:27:47
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户操作日志
|
||||
///</summary>
|
||||
[Description("用户操作日志")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize]
|
||||
public class SysUserOperationLogController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly ISysUserOperationLogServices _sysUserOperationLogServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
///</summary>
|
||||
public SysUserOperationLogController(IWebHostEnvironment webHostEnvironment
|
||||
,ISysUserOperationLogServices sysUserOperationLogServices
|
||||
)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_sysUserOperationLogServices = sysUserOperationLogServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
// POST: Api/SysUserOperationLog/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
||||
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
||||
var where = PredicateBuilder.True<SysUserOperationLog>();
|
||||
//获取排序字段
|
||||
var orderField = Request.Form["orderField"].FirstOrDefault();
|
||||
|
||||
Expression<Func<SysUserOperationLog, object>> orderEx = orderField switch
|
||||
{
|
||||
"id" => p => p.id,"userName" => p => p.userName,"userNickName" => p => p.userNickName,"userId" => p => p.userId,"ip" => p => p.ip,"apiPath" => p => p.apiPath,"beginTime" => p => p.beginTime,"endTime" => p => p.endTime,"opTime" => p => p.opTime,"requestMethod" => p => p.requestMethod,"requestData" => p => p.requestData,"responseBodyData" => p => p.responseBodyData,"agent" => p => p.agent,"actionName" => p => p.actionName,"actionDescription" => p => p.actionDescription,"controllerName" => p => p.controllerName,"controllerDescription" => p => p.controllerDescription,"statusCode" => p => p.statusCode,"createTime" => p => p.createTime,"dataSources" => p => p.dataSources,
|
||||
_ => p => p.id
|
||||
};
|
||||
|
||||
//设置排序方式
|
||||
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
||||
var orderBy = orderDirection switch
|
||||
{
|
||||
"asc" => OrderByType.Asc,
|
||||
"desc" => OrderByType.Desc,
|
||||
_ => OrderByType.Desc
|
||||
};
|
||||
//查询筛选
|
||||
|
||||
// int
|
||||
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
||||
if (id > 0)
|
||||
{
|
||||
where = where.And(p => p.id == id);
|
||||
}
|
||||
//用户登录账号 nvarchar
|
||||
var userName = Request.Form["userName"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(userName))
|
||||
{
|
||||
where = where.And(p => p.userName.Contains(userName));
|
||||
}
|
||||
//用户登录昵称 nvarchar
|
||||
var userNickName = Request.Form["userNickName"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(userNickName))
|
||||
{
|
||||
where = where.And(p => p.userNickName.Contains(userNickName));
|
||||
}
|
||||
//用户序列 nvarchar
|
||||
var userId = Request.Form["userId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (userId > 0)
|
||||
{
|
||||
where = where.And(p => p.id == id);
|
||||
}
|
||||
//IP地址 nvarchar
|
||||
var ip = Request.Form["ip"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(ip))
|
||||
{
|
||||
where = where.And(p => p.ip.Contains(ip));
|
||||
}
|
||||
//请求地址 nvarchar
|
||||
var apiPath = Request.Form["apiPath"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(apiPath))
|
||||
{
|
||||
where = where.And(p => p.apiPath.Contains(apiPath));
|
||||
}
|
||||
//开始时间 datetime
|
||||
var beginTime = Request.Form["beginTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(beginTime))
|
||||
{
|
||||
if (beginTime.Contains("到"))
|
||||
{
|
||||
var dts = beginTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.beginTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.beginTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = beginTime.ObjectToDate();
|
||||
where = where.And(p => p.beginTime > dt);
|
||||
}
|
||||
}
|
||||
//结束时间 datetime
|
||||
var endTime = Request.Form["endTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(endTime))
|
||||
{
|
||||
if (endTime.Contains("到"))
|
||||
{
|
||||
var dts = endTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.endTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.endTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = endTime.ObjectToDate();
|
||||
where = where.And(p => p.endTime > dt);
|
||||
}
|
||||
}
|
||||
//耗时 nvarchar
|
||||
var opTime = Request.Form["opTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(opTime))
|
||||
{
|
||||
where = where.And(p => p.opTime.Contains(opTime));
|
||||
}
|
||||
//请求方式 nvarchar
|
||||
var requestMethod = Request.Form["requestMethod"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(requestMethod))
|
||||
{
|
||||
where = where.And(p => p.requestMethod.Contains(requestMethod));
|
||||
}
|
||||
//请求数据 nvarchar
|
||||
var requestData = Request.Form["requestData"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(requestData))
|
||||
{
|
||||
where = where.And(p => p.requestData.Contains(requestData));
|
||||
}
|
||||
//返回数据 nvarchar
|
||||
var responseBodyData = Request.Form["responseBodyData"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(responseBodyData))
|
||||
{
|
||||
where = where.And(p => p.responseBodyData.Contains(responseBodyData));
|
||||
}
|
||||
//代理渠道 nvarchar
|
||||
var agent = Request.Form["agent"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(agent))
|
||||
{
|
||||
where = where.And(p => p.agent.Contains(agent));
|
||||
}
|
||||
//动作方法名称 nvarchar
|
||||
var actionName = Request.Form["actionName"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(actionName))
|
||||
{
|
||||
where = where.And(p => p.actionName.Contains(actionName));
|
||||
}
|
||||
//动作方法描述 nvarchar
|
||||
var actionDescription = Request.Form["actionDescription"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(actionDescription))
|
||||
{
|
||||
where = where.And(p => p.actionDescription.Contains(actionDescription));
|
||||
}
|
||||
//控制器名称 nvarchar
|
||||
var controllerName = Request.Form["controllerName"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(controllerName))
|
||||
{
|
||||
where = where.And(p => p.controllerName.Contains(controllerName));
|
||||
}
|
||||
//控制器名称 nvarchar
|
||||
var controllerDescription = Request.Form["controllerDescription"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(controllerDescription))
|
||||
{
|
||||
where = where.And(p => p.controllerDescription.Contains(controllerDescription));
|
||||
}
|
||||
//状态码 int
|
||||
var statusCode = Request.Form["statusCode"].FirstOrDefault().ObjectToInt(0);
|
||||
if (statusCode > 0)
|
||||
{
|
||||
where = where.And(p => p.statusCode == statusCode);
|
||||
}
|
||||
//创建时间 datetime
|
||||
var createTime = Request.Form["createTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(createTime))
|
||||
{
|
||||
if (createTime.Contains("到"))
|
||||
{
|
||||
var dts = createTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = createTime.ObjectToDate();
|
||||
where = where.And(p => p.createTime > dt);
|
||||
}
|
||||
}
|
||||
//数据来源 nvarchar
|
||||
var dataSources = Request.Form["dataSources"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(dataSources))
|
||||
{
|
||||
where = where.And(p => p.dataSources.Contains(dataSources));
|
||||
}
|
||||
//获取数据
|
||||
var list = await _sysUserOperationLogServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.count = list.TotalCount;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
// POST: Api/SysUserOperationLog/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除数据============================================================
|
||||
// POST: Api/SysUserOperationLog/DoDelete/10
|
||||
/// <summary>
|
||||
/// 单选删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("单选删除")]
|
||||
public async Task<AdminUiCallBack> DoDelete([FromBody]FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _sysUserOperationLogServices.ExistsAsync(p => p.id == entity.id, true);
|
||||
if (!model)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
var bl = await _sysUserOperationLogServices.DeleteByIdAsync(entity.id);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 批量删除============================================================
|
||||
// POST: Api/SysUserOperationLog/DoBatchDelete/10,11,20
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("批量删除")]
|
||||
public async Task<AdminUiCallBack> DoBatchDelete([FromBody]FMArrayIntIds entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await _sysUserOperationLogServices.DeleteByIdsAsync(entity.id);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 预览数据============================================================
|
||||
// POST: Api/SysUserOperationLog/GetDetails/10
|
||||
/// <summary>
|
||||
/// 预览数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("预览数据")]
|
||||
public async Task<AdminUiCallBack> GetDetails([FromBody]FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _sysUserOperationLogServices.QueryByIdAsync(entity.id, false);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user