using CZFW.Framework.Logic; using CZFW.Framework.Model.Entity; using CZFW.Framework.Model.ViewModel; using CZKJ.GBRS2.Entity; using CZKJ.GBRS2.Enum; using CZKJ.GBRS2.Interface; using System.Collections.Generic; using System.Linq; namespace CZKJ.GBRS2.Logic { public class ProductLogic : LogicBase, IProduct { public ResultModel EditStatus(int id, int status) { string sql = $"update cz_gbrs2_product set Status={status} where id={id}"; var res = ExcuteSql(sql); return res; } public IList GetCountList(IList idList, int count) { var productList = new List(); foreach (var list in idList.Select(item => DbContext.Set().Where(x => x.TypeId == item&&x.Status == (int)ProductStatusEnum.上线).OrderByDescending(x => x.SortOrder).Take(count).ToList())) { productList.AddRange(list); } return productList; } public IList GetList(int pageIndex, int pageSize, out int rowsCount, int? parentId, int? typeId, string keywords) { var queryable = Queryable; if (parentId.HasValue) { var idList = DbContext.Set().Where(x => x.ParentId == parentId).Select(x => x.Id).ToList(); queryable = queryable.Where(x => idList.Contains(x.TypeId)); } if (typeId.HasValue) { queryable = queryable.Where(x => x.TypeId == typeId); } if (!string.IsNullOrWhiteSpace(keywords)) { queryable = queryable.Where(x => x.Title.Contains(keywords) || x.Summary.Contains(keywords)); } rowsCount = queryable.Count(); var list = queryable.Join(DbContext.Set(), x => x.TypeId, y => y.Id, (x, y) => new { x, y.Name }).OrderByDescending(x => x.x.SortOrder).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return list.Select(x => new ProductEntity { Id = x.x.Id, Image = x.x.Image, MainImage=x.x.MainImage, MobileMainImage=x.x.MobileMainImage, Title = x.x.Title, TypeName = x.Name, Summary = x.x.Summary, SortOrder = x.x.SortOrder, PublishTime = x.x.PublishTime, Status = x.x.Status, StatusName = x.x.Status == (int)ProductStatusEnum.上线?"上线":"下线" }).ToList(); } public IList GetSearchResult(string keywords, int pageIndex, int pageSize, out int rowsCount) { var queryable = Queryable.Where(x => x.Title.Contains(keywords) || x.Summary.Contains(keywords)&&x.Status == (int)ProductStatusEnum.上线); rowsCount = queryable.Count(); var result = queryable.Join(DbContext.Set(), x => x.TypeId, y => y.Id, (x, y) => new { x, y.Name }).Select(x => new { x.x.Title, x.x.PublishTime, TypeName = x.Name, x.x.Id }).OrderByDescending(x => x.PublishTime).Skip((pageIndex - 1) * pageSize).Take(pageSize); return result.ToList().Select(x => new ProductEntity { Id = x.Id, Title = x.Title, PublishTime = x.PublishTime, TypeName = x.TypeName }).ToList(); } } }