操控平台后端代码
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.

69 lines
2.4 KiB

using System.ComponentModel;
using Admin.Bodk.Device.Entities;
using Admin.Bodk.Device.Entities.Dto;
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.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace Admin.Bodk.Device.Services;
/// <summary>
/// 基地管理服务
/// </summary>
[ApiDescriptionSettings(Order = 2)]
public class BaseService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<Entities.Base> _baseRep;
private readonly SqlSugarRepository<Entities.Support> _supportRep;
public BaseService(SqlSugarRepository<Entities.Base> baseRep, SqlSugarRepository<Entities.Support> supportRep)
{
_baseRep = baseRep;
_supportRep = supportRep;
}
/// <summary>
/// 获取基地信息列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[DisplayName("获取基地信息列表")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
public async Task<SqlSugarPagedList<BaseOutput>> PostList(BaseInput input)
{
return await _baseRep.AsQueryable()
.Select((u) => new BaseOutput
{
Id = u.Id,
Name = u.Name,
Address = u.Address,
Remark = u.Remark,
Phone = u.Phone,
SupportList =SqlFunc.Subqueryable<Support>().Where(tc => tc.BaseId == u.Id).ToList()
})
.ToPagedListAsync(input.Page, input.PageSize);
}
/// <summary>
/// 增加基地
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[UnitOfWork]
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[DisplayName("增加客户")]
public async Task<long> AddCustomer(BaseAddInput input)
{
if(input is null) throw Oops.Oh("参数不能为空");
var customer = input.Adapt<Entities.Base>();
var newEquipment = await (_baseRep).AsInsertable(customer).ExecuteReturnEntityAsync();
return newEquipment.Id;
}
}