You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.6 KiB
132 lines
4.6 KiB
5 months ago
|
using System.ComponentModel;
|
||
|
using Admin.Bodk.Device.Entities.equipment;
|
||
|
using Admin.Bodk.Device.Entities.TaskChain;
|
||
|
using Admin.NET.Core;
|
||
|
using Furion.DatabaseAccessor;
|
||
|
using Furion.DependencyInjection;
|
||
|
using Furion.DynamicApiController;
|
||
|
using Furion.FriendlyException;
|
||
|
using Mapster;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using SqlSugar;
|
||
|
|
||
|
namespace Admin.Bodk.Device.Services;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 设备管理服务
|
||
|
/// </summary>
|
||
|
[ApiDescriptionSettings(Order = 2)]
|
||
3 months ago
|
public class DeviceService : IDynamicApiController, ITransient
|
||
5 months ago
|
{
|
||
3 months ago
|
private readonly SqlSugarRepository<Entities.Device.Device> _repository;
|
||
5 months ago
|
|
||
|
private readonly SqlSugarRepository<TaskChain> _taskChainRepository;
|
||
|
|
||
3 months ago
|
public DeviceService(SqlSugarRepository<Entities.Device.Device> repository, SqlSugarRepository<TaskChain> taskChainRepository)
|
||
5 months ago
|
{
|
||
|
_repository = repository;
|
||
|
_taskChainRepository = taskChainRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取设备列表
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[DisplayName("获取设备列表")]
|
||
3 months ago
|
public async Task<SqlSugarPagedList<EquipmentDto>> PostList(DeviceInpt input)
|
||
5 months ago
|
{
|
||
|
return await _repository.AsQueryable()
|
||
|
// .LeftJoin<TaskChain.TaskChain>((u, a) => u.Id == a.EquipmentId)
|
||
3 months ago
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name),
|
||
|
m => m.Name != null && m.Name.Contains(input.Name))
|
||
5 months ago
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Type), m => m.Type == input.Type)
|
||
|
.Select((u) => new EquipmentDto
|
||
|
{
|
||
|
Id = u.Id,
|
||
3 months ago
|
Name = u.Name,
|
||
5 months ago
|
Type = u.Type,
|
||
3 months ago
|
BaseName = u.BaseName,
|
||
|
PicUrl = u.PicUrl,
|
||
|
LiquidNitrogenHeight = u.LiquidNitrogenHeight,
|
||
|
Temperature = u.Temperature,
|
||
|
Humidity = u.Humidity,
|
||
|
Address = u.Address,
|
||
5 months ago
|
Remark = u.Remark,
|
||
|
Code = u.Code,
|
||
|
Ip = u.Ip,
|
||
|
Status = u.Status,
|
||
|
CreateTime = u.CreateTime,
|
||
3 months ago
|
//TaskChainList =SqlFunc.Subqueryable<TaskChain>().Where(tc => tc.EquipmentId == u.Id).ToList()
|
||
5 months ago
|
})
|
||
|
.ToPagedListAsync(input.Page, input.PageSize);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 增加设备
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[UnitOfWork]
|
||
|
[ApiDescriptionSettings(Name = "Add"), HttpPost]
|
||
|
[DisplayName("增加设备")]
|
||
|
public async Task<long> AddEquipment(EquipmentDto input)
|
||
|
{
|
||
|
if(input is null) throw Oops.Oh("参数不能为空");
|
||
3 months ago
|
var equipment = input.Adapt<Entities.Device.Device>();
|
||
5 months ago
|
// if( a is double b)
|
||
|
// {
|
||
|
// Console.WriteLine(b);
|
||
|
// }
|
||
|
var newEquipment = await _repository.AsInsertable(equipment).ExecuteReturnEntityAsync();
|
||
3 months ago
|
// if (input?.TaskChainList is { Count: > 0 })
|
||
|
// {
|
||
|
// foreach (var taskChain in input.TaskChainList)
|
||
|
// {
|
||
|
// taskChain.EquipmentId = newEquipment.Id;
|
||
|
// await _taskChainRepository.AsInsertable(taskChain).ExecuteReturnEntityAsync();
|
||
|
// }
|
||
|
// }
|
||
5 months ago
|
input.Id = newEquipment.Id;
|
||
|
return newEquipment.Id;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新设备
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[UnitOfWork]
|
||
|
[ApiDescriptionSettings(Name = "Update"), HttpPost]
|
||
|
[DisplayName("更新设备")]
|
||
|
public async Task Update(EquipmentDto input)
|
||
|
{
|
||
|
_taskChainRepository.AsDeleteable().Where(tc => tc.EquipmentId == input.Id).ExecuteCommand();
|
||
3 months ago
|
// if (input?.TaskChainList is { Count: > 0 })
|
||
|
// {
|
||
|
// foreach (var taskChain in input.TaskChainList)
|
||
|
// {
|
||
|
// taskChain.EquipmentId = input.Id;
|
||
|
// await _taskChainRepository.AsInsertable(taskChain).ExecuteReturnEntityAsync();
|
||
|
// }
|
||
|
// }
|
||
|
await _repository.AsUpdateable(input.Adapt<Entities.Device.Device>())
|
||
|
.UpdateColumns(m => new { m.Type, m.Name, m.Remark, m.Code })
|
||
5 months ago
|
.ExecuteCommandAsync();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除设备
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[UnitOfWork]
|
||
|
[ApiDescriptionSettings(Name = "Delete"), HttpPost]
|
||
|
[DisplayName("删除设备")]
|
||
|
public async Task Delete(DeleteEquipmentInput input)
|
||
|
{
|
||
|
var user = await _repository.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh("设备不存在");
|
||
|
|
||
|
await _repository.DeleteAsync(user);
|
||
|
}
|
||
|
}
|