public ResponseObject <List <ToDoMgModel> > GetToDoModel(RequestGet requestObject, CurrentUser currentUser) { ResponseObject <List <ToDoMgModel> > responseObject = new ResponseObject <List <ToDoMgModel> >(); responseObject.Code = 0; try { List <ToDoMgModel> result = new List <ToDoMgModel>(); Expression <Func <ToDoMgModel, bool> > queryConditionLam = (x) => x.To == currentUser.UserID && x.CompanyID == currentUser.CompanyID; if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0) { var conditionals = SqlSugarUtil.GetConditionalFull(requestObject.QueryConditions).Where(p => !string.IsNullOrWhiteSpace(p.FieldValue)).ToList(); var whereConditional = ConditionalModelToExpression.BuildExpression <ToDoMgModel>(conditionals); queryConditionLam = queryConditionLam.And(whereConditional); } SortDefinition <ToDoMgModel> sort = null; //排序条件 if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0) { foreach (var item in requestObject.OrderByConditions) { var exp = SqlSugarUtil.GetExpression <ToDoMgModel>(item.Column); if (exp == null) { continue; } if (item.Condition.ToLower() == "asc") { if (sort == null) { sort = Builders <ToDoMgModel> .Sort.Ascending(exp); } else { sort = sort.Ascending(exp); } } else if (item.Condition.ToLower() == "desc") { if (sort == null) { sort = Builders <ToDoMgModel> .Sort.Descending(exp); } else { sort = sort.Descending(exp); } } } } long totalNum = 0; if (requestObject.IsPaging == true) { result = MongoDbUtil.GetDoc <ToDoMgModel>(queryConditionLam, requestObject.PageIndex, requestObject.PageSize, sort, ref totalNum); } else { result = MongoDbUtil.GetDoc <ToDoMgModel>(queryConditionLam, sort).ToList(); } return(ResponseUtil <List <ToDoMgModel> > .SuccessResult(result, totalNum)); } catch (Exception ex) { return(ResponseUtil <List <ToDoMgModel> > .FailResult(null, ex.Message)); } }
/// <summary> /// 获取物料缓存 /// </summary> /// <param name="requestObject"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <ResponseObject <TBMMaterialFileQueryModel, List <TBMMaterialFileCacheModel> > > GetAsync(RequestObject <TBMMaterialFileQueryModel> requestObject, CurrentUser currentUser) { string key = string.Format(CacheKeyString.Material, currentUser.CompanyID); List <TBMMaterialFileCacheModel> result; try { //if (!_memoryCache.TryGetValue(key, out result)) //{ // var tBMMaterialFileQueryList = await GetAllAsync(currentUser); // result = tBMMaterialFileQueryList; // _memoryCache.Set(key, tBMMaterialFileQueryList, new TimeSpan(2, 0, 0, 0));//缓存两天 //} var redis = CacheFactory.Instance(CacheType.Redis); result = redis.GetValueByKey <List <TBMMaterialFileCacheModel> >(key, () => { var tBMMaterialFileQueryList = GetAllAsync(currentUser).Result; return(tBMMaterialFileQueryList); }, 24 * 60 * 60 * 2); //查询条件 if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0) { Expression <Func <TBMMaterialFileCacheModel, bool> > queryConditionLam = (x) => true; var con1 = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "materialcode" && !string.IsNullOrWhiteSpace(p.Content)).FirstOrDefault(); if (con1 != null) { requestObject.QueryConditions.Remove(con1); queryConditionLam = queryConditionLam.And(x => x.MaterialCode.Contains(con1.Content) || x.MaterialName.Contains(con1.Content)); } var con2 = requestObject.QueryConditions.Where(p => p.Column.ToLower() == "materialname" && !string.IsNullOrWhiteSpace(p.Content)).FirstOrDefault(); if (con2 != null) { requestObject.QueryConditions.Remove(con2); queryConditionLam = queryConditionLam.And(x => x.MaterialCode.Contains(con2.Content) || x.MaterialName.Contains(con2.Content)); } var conditionals = SqlSugarUtil.GetConditionalFull(requestObject.QueryConditions).Where(p => !string.IsNullOrWhiteSpace(p.FieldValue)).ToList(); var whereConditional = ConditionalModelToExpression.BuildExpression <TBMMaterialFileCacheModel>(conditionals); queryConditionLam = queryConditionLam.And(whereConditional); result = result.Where(queryConditionLam.Compile()).ToList(); } //排序条件 if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0) { foreach (var item in requestObject.OrderByConditions) { var exp = SqlSugarUtil.GetOrderByLambda <TBMMaterialFileDbModel>(item.Column); if (exp == null) { continue; } if (item.Condition.ToLower() != "asc" && item.Condition.ToLower() != "desc") { continue; } //query.OrderBy($"{item.Column} {item.Condition}"); } } int totalNum = 0; if (requestObject.IsPaging) { totalNum = result.Count(); result = result.OrderBy(p => p.ID).Skip(requestObject.PageSize * (requestObject.PageIndex - 1)).Take(requestObject.PageSize).ToList(); } else { result = result.ToList(); } return(ResponseUtil <TBMMaterialFileQueryModel, List <TBMMaterialFileCacheModel> > .SuccessResult(requestObject, result, totalNum)); } catch (Exception ex) { return(ResponseUtil <TBMMaterialFileQueryModel, List <TBMMaterialFileCacheModel> > .FailResult(requestObject, null, ex.Message)); } }