using langguanApi.Extensions.AutoDI; using langguanApi.Model; using langguanApi.Model.Dto; using Mapster; using System.Linq.Expressions; namespace langguanApi.Service { [ServiceInjection(InjectionType.Transient)] public class DeviceService : BaseService { public DeviceService(IConfiguration config) : base(config, nameof(Device)) { } /// /// 新加 /// /// /// public async Task Add(DeviceDto input) { if (await Exist(input)) { return new ApiResult { code = 1, msg = $"已经存在名称为:{input.Name}" }; } var entity = input.Adapt(); if (entity != null) { await base.CreateAsync(entity); return new ApiResult { code = 0, msg = "" }; } return new ApiResult { code = -1, msg = "" }; ; } /// /// 是否存在 /// /// /// public async Task Exist(DeviceDto input) { var entity = input.Adapt(); Expression> exp = filter => filter.deviceMN == entity.deviceMN; return await base.Exist(exp); } /// /// 更新 /// /// /// public async Task update(DeviceDto input) { var entity = input.Adapt(); await base.UpdateAsync(entity.Id, entity); return new ApiResult { code = 0, msg = "" }; } /// /// remove /// /// /// public async Task remove(IEnumerable ids) { if (ids.Any()) { foreach (var item in ids) { var entity = await base.GetAsync(item); entity.IsDelete = true; await base.UpdateAsync(entity.Id, entity); } return new ApiResult { code = 0, msg = "" }; } return new ApiResult { code = -1, msg = "" }; } // 通过devicemn获取设备信息 public async Task GetByDeviceMN(string deviceMN) { Expression> exp = filter => filter.deviceMN == deviceMN && filter.IsDelete == false; return (await base.GetListWithExp(exp)).FirstOrDefault(); } /// /// 分页取数据 /// /// /// public async Task GetPage(reqpage input) { Expression> exp = filter => filter.Name.Contains(input.key) && filter.IsDelete == false; return await base.GetPager(new ReqPaing() { pageSize = input.pageSize, current = input.current }, exp); } } }