using Furion.DependencyInjection; using Nirvana.Common; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Waste.Domain; namespace Waste.Application { /// /// 垃圾信息管理 /// public class WasteService : IWasteService, ITransient { private readonly ISqlSugarRepository repository; private readonly SqlSugarClient dbClient; public WasteService(ISqlSugarRepository sqlSugarRepository) { repository = sqlSugarRepository; dbClient = repository.Context; } /// /// 删除分类 /// /// /// public async Task DeleteTypeFormAsync(Guid keyValue) { if (!await dbClient.Queryable().AnyAsync(x => x.Id == keyValue)) { return new ResultInfo(ResultState.FAIL, "记录未找到"); } await dbClient.Deleteable().Where(x => x.Id == keyValue).ExecuteCommandAsync(); return new ResultInfo(ResultState.SUCCESS, "删除成功"); } /// /// 分类详情 /// /// /// public async Task DetailTypeAsync(Guid id) { return await dbClient.Queryable().FirstAsync(x => x.Id == id); } /// /// 获取所有分类 /// /// public async Task> GetAllTypeList() { return await dbClient.Queryable().ToListAsync(); } /// /// 垃圾分类列表 /// /// /// public async Task> GetTypeListAsync(QueryParams param) { RefAsync totalnum = 0; var temquery = dbClient.Queryable(); if (param.queryParam != null && param.queryParam.Count > 0) { List conModels = new List(); param.queryParam.ForEach(x => { if (!string.IsNullOrEmpty(x.Value)) { conModels.Add(new ConditionalModel() { FieldName = x.Name, ConditionalType = (ConditionalType)x.Type, FieldValue = x.Value.Trim() }); } }); if (conModels.Count > 0) { temquery = temquery.Where(conModels); } } string sorts = string.Format("{0} {1}", param.sort, param.order); var query = await temquery.OrderBy(sorts) .ToPageListAsync(param.offset, param.limit, totalnum); return new PageParms { page = param.offset, Items = query, totalnum = totalnum, limit = param.limit }; } /// /// 垃圾分类信息提交 /// /// /// public async Task SubmitTypeFormAsync(W_WasteType w_WasteType) { if (w_WasteType.Id != Guid.Empty) { await dbClient.Updateable().SetColumns(x => new W_WasteType { Code = w_WasteType.Code, Name = w_WasteType.Name }).Where(x => x.Id == w_WasteType.Id).ExecuteCommandAsync(); return new ResultInfo(ResultState.SUCCESS, "修改成功"); } else { w_WasteType.CreateTime = DateTime.Now; w_WasteType.Status = (int)StatusType.Enabled; await dbClient.Insertable(w_WasteType).ExecuteCommandAsync(); return new ResultInfo(ResultState.SUCCESS, "添加成功"); } } } }