/// <summary> /// 删除 /// </summary> /// <param name="id"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO DeleteExt(System.Guid id) { try { ResultDTO result = new ResultDTO { isSuccess = true, Message = "success" }; ContextSession contextSession = ContextFactory.CurrentThreadContext; var spreadCategory = SpreadCategory.ObjectSet().FirstOrDefault(c => c.Id == id); if (spreadCategory == null) { return(result); } var usedCount = SpreadInfo.ObjectSet().Count(c => c.IsDel == 1 && c.SpreadType == spreadCategory.SpreadType); if (usedCount > 0) { result.ResultCode = 2; result.isSuccess = false; result.Message = "该分类已被使用,无法删除"; } spreadCategory.EntityState = EntityState.Deleted; contextSession.SaveChanges(); return(result); } catch (Exception ex) { LogHelper.Error(string.Format("SpreadCategoryBP.DeleteExt 异常:dto:{0}", id), ex); return(new ResultDTO { ResultCode = -1, Message = "操作失败" }); } }
private Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO validAdd(Jinher.AMP.BTP.Deploy.SpreadCategoryDTO dto) { if (dto == null) { return new ResultDTO { ResultCode = 1, Message = "参数为空" } } ; if (dto.CategoryDesc.IsNullVauleFromWeb()) { return new ResultDTO { ResultCode = 1, Message = "参数为空" } } ; var already = SpreadCategory.ObjectSet().FirstOrDefault(c => c.SpreadType == dto.SpreadType); if (already != null) { return new ResultDTO { ResultCode = 2, Message = "分类编码已存在" } } ; return(new ResultDTO { isSuccess = true, Message = "success" }); }
/// <summary> /// 添加 /// </summary> /// <param name="dto"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddExt(Jinher.AMP.BTP.Deploy.SpreadCategoryDTO dto) { try { var result = validAdd(dto); if (result.ResultCode != 0) { return(result); } ContextSession contextSession = ContextFactory.CurrentThreadContext; var spreadCategory = SpreadCategory.CreateSpreadCategory(); spreadCategory.SpreadType = dto.SpreadType; spreadCategory.SpreaderPercent = dto.SpreaderPercent; spreadCategory.Priority = dto.Priority; spreadCategory.CategoryDesc = dto.Desc; contextSession.SaveChanges(); return(result); } catch (Exception ex) { LogHelper.Error(string.Format("SpreadCategoryBP.AddExt 异常:dto:{0}", JsonHelper.JsonSerializer(dto)), ex); return(new ResultDTO { ResultCode = -1, Message = "操作失败" }); } }
/// <summary> /// 获取推广主类型 /// </summary> /// <param name="search"></param> /// <returns></returns> public ResultDTO <List <SpreadCategoryDTO> > GetSpreadCategoryListExt(Jinher.AMP.BTP.Deploy.CustomDTO.SpreadSearchDTO search) { List <SpreadCategoryDTO> dtos = new List <SpreadCategoryDTO>(); var list = SpreadCategory.ObjectSet().ToList(); if (list.Any()) { dtos.AddRange(list.Select(spreadCategory => spreadCategory.ToEntityData())); } return(new ResultDTO <List <SpreadCategoryDTO> > { isSuccess = true, Data = dtos }); }
public ResultDTO <ListResult <SpreadInfoShowDTO> > GetSpreadInfoListExt(SpreadSearchDTO search) { if (search == null) { return new ResultDTO <ListResult <SpreadInfoShowDTO> > { ResultCode = 1, Message = "参数为空" } } ; if (search.PageIndex == 0) { search.PageIndex = 1; } if (search.PageSize == 0) { search.PageSize = 20; } var query = SpreadInfo.ObjectSet().Where(c => c.IsDel != 1); if (search.SpreadType.HasValue) { query = query.Where(c => c.SpreadType == search.SpreadType.Value); } if (!string.IsNullOrEmpty(search.UserCode)) { query = query.Where(c => c.UserCode.Contains(search.UserCode)); } if (search.SpreadAppId.HasValue && search.SpreadAppId != Guid.Empty) { query = query.Where(c => c.SpreadAppId == search.SpreadAppId.Value); } if (search.IWId.HasValue) { query = query.Where(c => c.IWId == search.IWId.Value); } ListResult <SpreadInfoShowDTO> data = new ListResult <SpreadInfoShowDTO> { List = new List <SpreadInfoShowDTO>() }; data.Count = query.Count(); data.List = query.OrderByDescending(c => c.SubTime).Skip((search.PageIndex - 1) * search.PageSize). Take(search.PageSize).Select(c => new SpreadInfoShowDTO { Id = c.Id, SpreadId = c.SpreadId, Account = c.UserCode, Name = c.Name, SpreadType = c.SpreadType, SpreadAppId = c.SpreadAppId, HotshopId = c.HotshopId, QrCodeUrl = c.QrCodeUrl, SpreadDesc = c.SpreadDesc, SpreadUrl = c.SpreadUrl, SubTime = c.SubTime, IsDel = c.IsDel, HotshopName = "", IsBindWeChatQrCode = false, SpreadAppName = "", SpreadTypeDesc = "", IWCode = c.IWCode, SubSpreadCount = c.SubSpreadCount, DividendPercent = c.DividendPercent }).ToList(); if (data.List.Any()) { var spreadTypes = data.List.Select(c => c.SpreadType).Distinct().ToList(); var spreadCategoryList = SpreadCategory.ObjectSet() .Where(c => spreadTypes.Contains(c.SpreadType)) .Select(m => new SpreadCategoryDTO { SpreadType = m.SpreadType, CategoryDesc = m.CategoryDesc }).ToList(); var ids = data.List.Select(c => c.Id).ToList(); var bindedIds = WeChatQRCode.ObjectSet().Where(c => ids.Contains(c.SpreadInfoId)).Select(m => m.SpreadInfoId).ToList(); var appIds = data.List.Select(c => c.SpreadAppId).Distinct().ToList(); appIds.AddRange(data.List.Select(c => c.HotshopId)); appIds = appIds.Distinct().ToList(); var appDict = APPSV.GetAppNameListByIds(appIds); foreach (var spreadInfoShowDTO in data.List) { if (appDict.ContainsKey(spreadInfoShowDTO.SpreadAppId)) { spreadInfoShowDTO.SpreadAppName = appDict[spreadInfoShowDTO.SpreadAppId]; } if (appDict.ContainsKey(spreadInfoShowDTO.HotshopId)) { spreadInfoShowDTO.HotshopName = appDict[spreadInfoShowDTO.HotshopId]; } var spreadTypeDto = spreadCategoryList.FirstOrDefault(c => c.SpreadType == spreadInfoShowDTO.SpreadType); if (spreadTypeDto != null) { spreadInfoShowDTO.SpreadTypeDesc = spreadTypeDto.CategoryDesc; } if (bindedIds.Contains(spreadInfoShowDTO.Id)) { spreadInfoShowDTO.IsBindWeChatQrCode = true; } } } return(new ResultDTO <ListResult <SpreadInfoShowDTO> > { isSuccess = true, Message = "success", Data = data }); }