using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using AutoMapper;
|
using Model.ModelDto.LogDto;
|
using Model.ModelVm.LogVm;
|
using SqlSugar;
|
using Utility;
|
using WMS.DAL;
|
using WMS.Entity.Context;
|
using WMS.Entity.LogEntity;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.ILogServer;
|
using WMS.IDAL.ILogInterface;
|
|
namespace WMS.BLL.LogServer
|
{
|
public class OperationSysServer : DbHelper<LogOperationSys>, IOperationSysServer
|
{
|
private readonly IOperationSysRepository _operation;
|
private readonly IMapper _mapper;
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
private readonly UserManager _userManager;
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="operation">日志</param>
|
/// <param name="mapper">automapper</param>
|
public OperationSysServer(IOperationSysRepository operation, IMapper mapper, UserManager userManager) : base(Db)
|
{
|
_operation = operation; //日志
|
_mapper = mapper; //automapper
|
_userManager = userManager;
|
}
|
|
/// <summary>
|
/// 添加操作日志
|
/// </summary>
|
/// <param name="parentNo">模块号</param>
|
/// <param name="menuNo">菜单号</param>
|
/// <param name="menuName">菜单名称</param>
|
/// <param name="fkNo">数据编号</param>
|
/// <param name="type">类型 添加 修改 删除 停用 启用</param>
|
/// <param name="msg">操作</param>
|
/// <param name="userId"></param>
|
/// <returns></returns>
|
public async Task<bool> AddOperationSys(string parentNo, string menuNo, string menuName, string fkNo, string type, string msg, int userId)
|
{
|
try
|
{
|
var num = await AddAsync(new LogOperationSys()
|
{
|
ParentNo = parentNo,
|
MenuNo = menuNo,
|
MenuName = menuName,
|
FkNo = fkNo,
|
Type = type,
|
Msg = msg,
|
CreateUser = userId
|
});
|
if (num > 0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
/// <summary>
|
/// 获取系统操作日志数据列表
|
/// </summary>
|
/// <param name="menuName">菜单名称</param>
|
/// <param name="type">操作类型</param>
|
/// <param name="msg">操作内容</param>
|
/// <param name="menuNo">菜单号</param>
|
/// <param name="parentNo">模块号</param>
|
/// <returns></returns>
|
public async Task<SqlSugarPagedList> GetSysOperationList(GetOperationVm model)
|
{
|
return await Db.Queryable<LogOperationSys>()
|
.LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id)
|
.LeftJoin<SysFunctionMenu>((a, b, c) => a.ParentNo == c.MenuNo)
|
.LeftJoin<SysDictionary>((a, b, c, d) => SqlFunc.ToInt32(a.Type) == d.Id)
|
.Where(a => a.IsDel == "0")
|
.WhereIF(!string.IsNullOrEmpty(model.MenuName), a => a.MenuName.Contains(model.MenuName))
|
.WhereIF(!string.IsNullOrEmpty(model.Type), a => a.Type == model.Type)
|
.WhereIF(!string.IsNullOrEmpty(model.Msg), a => a.Msg.Contains(model.Msg))
|
.WhereIF(!string.IsNullOrEmpty(model.MenuNo), a => a.MenuNo == model.MenuNo)
|
.Where((a, b, c, d) => a.ParentNo == SqlFunc.Subqueryable<SysFunctionMenu>().Where(e => e.IsDel == "0" && e.MenuName == model.ParentNo).Select(e => e.MenuNo))
|
.Select<OperationDto>((a, b, c, d) => new OperationDto()
|
{
|
Id = a.Id,
|
CreateUserName = b.RealName,
|
TypeName = d.DictName,
|
}, true)
|
.ToPagedListAsync(model.Page, model.Limit);
|
}
|
|
/// <summary>
|
/// 新增系统操作日志
|
/// </summary>
|
/// <param name="parentName">模块号</param>
|
/// <param name="menuName">菜单号</param>
|
/// <param name="fkNo">数据编号</param>
|
/// <param name="type">操作类型</param>
|
/// <param name="msg">操作内容</param>
|
/// <param name="createuser">创建人</param>
|
/// <returns></returns>
|
public async Task<int> InsertOperation(string parentName, string menuName, string fkNo, string type, string msg, int createuser)
|
{
|
//捕获异常
|
try
|
{
|
var parentNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == parentName && s.IsDel == "0"))?.MenuNo;
|
var menuNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == menuName && s.IsDel == "0"))?.MenuNo;
|
int i = await _operation.InsertOperation(parentNo, menuNo, parentName + "-" + menuName, fkNo, type, msg, createuser);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("新增操作日志异常", ex);
|
}
|
}
|
/// <summary>
|
/// 新增系统操作日志
|
/// </summary>
|
/// <param name="parentName">模块号</param>
|
/// <param name="menuName">菜单号</param>
|
/// <param name="fkNo">数据编号</param>
|
/// <param name="type">操作类型</param>
|
/// <param name="msg">操作内容</param>
|
/// <param name="createuser">创建人</param>
|
/// <returns></returns>
|
public async Task<int> InsertOperation(OperationInputVm input)
|
{
|
input.ParentNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == input.ParentName && s.IsDel == "0"))?.MenuNo;
|
input.MenuNo = (await Db.Queryable<SysFunctionMenu>().FirstAsync(s => s.MenuName == input.MenuName && s.IsDel == "0"))?.MenuNo;
|
input.Type = (await Db.Queryable<SysDictionary>().FirstAsync(s => s.DictName == input.TypeName && s.IsDel == "0"))?.Id.ToString();
|
input.CreateUser = _userManager.UserId;
|
input.CreateTime = DateTime.Now;
|
return await Db.Insertable<LogOperationSys>(input).ExecuteCommandAsync();
|
}
|
/// <summary>
|
/// 获取类型菜单
|
/// </summary>
|
/// <param name="dicName">字典名称</param>
|
/// <returns></returns>
|
public async Task<List<SysDictionary>> GetDicTypeList(string dicName)
|
{
|
return await Db.Queryable<SysDictionary>()
|
.Where(s => s.IsDel == "0")
|
.Where(s => s.ParentNo == SqlFunc.Subqueryable<SysDictionary>().Where(c => c.DictName == dicName).Select(c => c.DictNo))
|
.ToListAsync();
|
}
|
}
|
}
|