using System; using System.Collections.Generic; using System.Linq; using System.Text; using Model.ModelDto.LogDto; using SqlSugar; using WMS.DAL; using WMS.Entity.Context; using WMS.Entity.LogEntity; using WMS.Entity.SysEntity; using WMS.IBLL.ILogServer; namespace WMS.BLL.LogServer { public class OperationASNServer:DbHelper, IOperationASNServer { private static readonly SqlSugarScope Db = DataContext.Db; public OperationASNServer():base(Db) { } public List GetLogOperationAsnList(string menuName, string type, string msg, string startTime, string endTime, int page, int limit, out int count) { try { var item = Expressionable.Create() .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(endTime).AddDays(1)) .ToExpression();//注意 这一句 不能少 var total = 0; var list = GetAllWhereAsync(item) .LeftJoin((it, dic) => it.Type == dic.Id.ToString()) .LeftJoin((it, dic, users) => it.CreateUser == users.Id) .Select((it, dic, users) => new OperationDto() { Id = it.Id, ParentNo = it.ParentNo, MenuNo = it.MenuNo, MenuName = it.MenuName, FkNo = it.FkNo, Type = dic.DictName, Msg = it.Msg, CreateTime = it.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), CreateUserName = users.RealName, }) .OrderByDescending(it => it.CreateTime) .ToOffsetPage(page, limit, ref total); count = total; return list.OrderByDescending(m=>m.CreateTime).ToList(); } catch (Exception e) { throw new Exception(e.Message); } } public bool AddLogOperationAsn(string parentNo, string menuName, string fkNo, string type, string msg, int userId) { try { var menu = Db.Queryable().Where(m => m.IsDel == "0").ToList(); var dic = Db.Queryable().Where(m => m.ParentNo == "LogType" && m.IsDel == "0").ToList(); var typeId = dic.FirstOrDefault(m => m.DictName == type); var s = msg.Length; var n = Add(new LogOperationASN() { ParentNo = menu.FirstOrDefault(m => m.MenuName == parentNo) == null ? "" : menu.First(m => m.MenuName == parentNo).MenuNo, MenuNo = menu.FirstOrDefault(m => m.MenuName == menuName) == null ? "" : menu.First(m => m.MenuName == menuName).MenuNo, MenuName = $"{parentNo}-{menuName}", FkNo = fkNo, Type = typeId == null ? "" : typeId.Id.ToString(), Msg = msg, CreateUser = userId }); return n > 0; } catch (Exception e) { throw new Exception(e.Message); } } public bool AddLogOperationPdaAsn(string parentNo, string menuName, string fkNo, string type, string msg, int userId,string model,string kuai) { try { var menu = Db.Queryable().Where(m => m.IsDel == "0").ToList(); var dic = Db.Queryable().Where(m => m.ParentNo == "LogType" && m.IsDel == "0").ToList(); var typeId = dic.FirstOrDefault(m => m.DictName == type); var s = msg.Length; var n = Add(new LogOperationASN() { ParentNo = menu.FirstOrDefault(m => m.MenuName == parentNo) == null ? "" : menu.First(m => m.MenuName == parentNo).MenuNo, MenuNo = menu.FirstOrDefault(m => m.MenuName == menuName) == null ? "" : menu.First(m => m.MenuName == menuName).MenuNo, MenuName = $"{parentNo}-{menuName}", FkNo = fkNo, Type = typeId == null ? "" : typeId.Id.ToString(), Msg = msg, CreateUser = userId }); return n > 0; } catch (Exception e) { throw new Exception(e.Message); } } #region 数据归档 /// /// 获取操作记录 /// /// public List GetArchivingLogOperationList(string comeFrom, string menuName, string type, string msg, string startTime, string endTime, int page, int limit, out int count) { try { string sqlString = string.Empty; string sqlCount = string.Empty; string sqlPub = string.Empty; if (string.IsNullOrEmpty(comeFrom)) { comeFrom = "0"; } string tableName = string.Empty; if (comeFrom == "0") { tableName = "ArchivingOperationSys"; } else if (comeFrom == "1") { tableName = "ArchivingOperationASN"; } else if (comeFrom == "2") { tableName = "ArchivingOperationSo"; } else if (comeFrom == "3") { tableName = "ArchivingOperationCr"; } sqlCount += $"SELECT COUNT(tb1.ID) FROM {tableName} AS tb1 "; sqlString += $"select tb1.Id,tb1.ParentNo,tb1.MenuNo,tb1.MenuName,tb1.FkNo,tb1.Msg,tb1.CreateTime ,tb2.DictName as Type,tb3.RealName as CreateUserName from {tableName} as tb1 "; sqlPub += "left join SysDictionary as tb2 on tb1.Type=tb2.Id "; sqlPub += "left join SysUserInfor as tb3 on tb1.CreateUser=tb3.Id "; sqlPub += $"where tb1.IsDel = '0'"; if (!string.IsNullOrEmpty(menuName)) { sqlPub += $"AND tb1.MenuName like '%{menuName.Trim()}%' "; } if (!string.IsNullOrEmpty(type)) { sqlPub += $"AND tb1.Type = {int.Parse(type)} "; } if (!string.IsNullOrEmpty(msg)) { sqlPub += $"AND tb1.Msg like '%{msg.Trim()}%' "; } if (!string.IsNullOrEmpty(startTime)) { sqlPub += $"AND tb1.CreateTime >= '{Convert.ToDateTime(startTime)}' "; } if (!string.IsNullOrEmpty(endTime)) { sqlPub += $"AND tb1.CreateTime <= '{Convert.ToDateTime(endTime)}' "; } sqlCount += sqlPub; sqlPub += " order by tb1.CreateTime desc "; if (page == 0) { page = 1; } sqlString += sqlPub + $" offset {((page - 1) * limit)} rows fetch next {limit} rows only;"; var com = new Common(); count = com.GetRowCount(sqlCount); var modelList = Db.Ado.SqlQuery(sqlString); return modelList; } catch (Exception e) { throw new Exception(e.Message); } } #endregion } }