100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
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<Device>
|
|
{
|
|
public DeviceService(IConfiguration config) : base(config, nameof(Device))
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新加
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<ApiResult> Add(DeviceDto input)
|
|
{
|
|
if (await Exist(input))
|
|
{
|
|
return new ApiResult { code = 1, msg = $"已经存在名称为:{input.Name}" };
|
|
}
|
|
var entity = input.Adapt<Device>();
|
|
if (entity != null)
|
|
{
|
|
await base.CreateAsync(entity);
|
|
return new ApiResult { code = 0, msg = "" };
|
|
}
|
|
return new ApiResult { code = -1, msg = "" }; ;
|
|
}
|
|
/// <summary>
|
|
/// 是否存在
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> Exist(DeviceDto input)
|
|
{
|
|
var entity = input.Adapt<Device>();
|
|
Expression<Func<Device, bool>> exp = filter => filter.deviceMN == entity.deviceMN;
|
|
return await base.Exist(exp);
|
|
}
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<ApiResult> update(DeviceDto input)
|
|
{
|
|
var entity = input.Adapt<Device>();
|
|
await base.UpdateAsync(entity.Id, entity);
|
|
return new ApiResult { code = 0, msg = "" };
|
|
}
|
|
/// <summary>
|
|
/// remove
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
public async Task<ApiResult> remove(IEnumerable<string> 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<Device> GetByDeviceMN(string deviceMN)
|
|
{
|
|
Expression<Func<Device, bool>> exp = filter => filter.deviceMN == deviceMN && filter.IsDelete == false;
|
|
return (await base.GetListWithExp(exp)).FirstOrDefault();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 分页取数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<object> GetPage(reqpage input)
|
|
{
|
|
Expression<Func<Device, bool>> exp = filter => filter.Name.Contains(input.key) && filter.IsDelete == false;
|
|
return await base.GetPager(new ReqPaing()
|
|
{
|
|
pageSize = input.pageSize,
|
|
current = input.current
|
|
}, exp);
|
|
}
|
|
}
|
|
}
|