| | |
| | | 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; |
| | |
| | | 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) : base(Db) |
| | | public OperationSysServer(IOperationSysRepository operation, IMapper mapper, UserManager userManager) : base(Db) |
| | | { |
| | | _operation = operation; //日志 |
| | | _mapper = mapper; //automapper |
| | | _userManager = userManager; |
| | | } |
| | | |
| | | |
| | | ///// <summary> |
| | | ///// 查询操作日志 |
| | | ///// </summary> |
| | | ///// <param name="menuName">菜单名称</param> |
| | | ///// <param name="type">类型</param> |
| | | ///// <param name="msg">内容</param> |
| | | ///// <param name="startTime">开始日期</param> |
| | | ///// <param name="endTime">结束日期</param> |
| | | ///// <param name="page"></param> |
| | | ///// <param name="limit"></param> |
| | | ///// <param name="count"></param> |
| | | ///// <returns></returns> |
| | | //public List<OperationDto> GetOperationSysList(string menuName, string type, string msg, string startTime, string endTime, int page, int limit, out int count) |
| | | //{ |
| | | // try |
| | | // { |
| | | // Expression<Func<LogOperationSys, bool>> item = Expressionable.Create<LogOperationSys>() |
| | | // .AndIF(!string.IsNullOrWhiteSpace(menuName), it => it.MenuName.Contains(menuName.Trim())) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(msg), it => it.Msg.Contains(msg.Trim())) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(startTime), it => it.CreateTime >= Convert.ToDateTime(startTime)) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(endTime), it => it.CreateTime <= Convert.ToDateTime(startTime).AddDays(1)) |
| | | // .ToExpression();//注意 这一句 不能少 |
| | | |
| | | // var data = GetAllWhereAsync(item) |
| | | // .Includes(x => x.TypeInfo) |
| | | // .Includes(x => x.CreateUserInfo) |
| | | // .Includes(x => x.UpdateUserInfo).ToList(); |
| | | // count = data.Count; |
| | | // return data.Select(m => new OperationDto() |
| | | // { |
| | | // Id = m.Id, |
| | | // ParentNo = m.ParentNo, |
| | | // MenuNo = m.MenuNo, |
| | | // MenuName = m.MenuName, |
| | | // FkNo = m.FkNo, |
| | | // Type = m.TypeInfo == null ? "" : m.TypeInfo.DictName, |
| | | // Msg = m.Msg, |
| | | // CreateTime = m.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | // CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.UserName, |
| | | // UpdateTime = m.UpdateTime == null ? "" : ((DateTime)m.UpdateTime).ToString("yyyy-MM-dd HH:mm:ss"), |
| | | // UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.UserName |
| | | // }).ToList(); |
| | | // } |
| | | // catch (Exception e) |
| | | // { |
| | | // throw new Exception(e.Message); |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 添加操作日志 |
| | |
| | | /// <param name="menuNo">菜单号</param> |
| | | /// <param name="parentNo">模块号</param> |
| | | /// <returns></returns> |
| | | public List<OperationDto> GetSysOperationList(string menuName, string type, string msg, string menuNo, string parentNo) |
| | | public async Task<SqlSugarPagedList> GetSysOperationList(GetOperationVm model) |
| | | { |
| | | List<OperationDto> operationlist = _operation.GetSysOperationList(menuName, type, msg, menuNo, parentNo); |
| | | return operationlist; |
| | | 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> |
| | |
| | | //捕获异常 |
| | | try |
| | | { |
| | | var parentNo = _operation.GetMenuList(parentName).MenuNo; |
| | | var menuNo = _operation.GetMenuList(menuName).MenuNo; |
| | | 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; |
| | | } |
| | |
| | | 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 List<SysDictionary> GetDicTypeList(string dicName) |
| | | public async Task<List<SysDictionary>> GetDicTypeList(string dicName) |
| | | { |
| | | List<SysDictionary> diclist = _operation.GetDicTypeList( dicName); |
| | | return diclist; |
| | | 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(); |
| | | } |
| | | } |
| | | } |