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

118 lines
4.2 KiB

// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using System.ComponentModel;
using Admin.NET.Bodk.Cells.Entities;
using Admin.NET.Bodk.Cells.Models;
using Admin.NET.Core;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
namespace Admin.NET.Bodk.Cells;
[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Cell", Description = "细胞服务")]
public class CellService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<CellEntity> _repository;
private readonly UserManager _userManager;
public CellService(SqlSugarRepository<CellEntity> repository, UserManager userManager)
{
_repository = repository;
_userManager = userManager;
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "GetList"), HttpPost]
[DisplayName("GetList")]
public async Task<SqlSugarPagedList<Cell>> GetList(CellQueryInput queryInput)
{
return await _repository.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(queryInput.BoxBarCode),
m => queryInput.BoxBarCode != null && m.BoxBarCode.Contains(queryInput.BoxBarCode))
.WhereIF(!string.IsNullOrWhiteSpace(queryInput.TubeBarcode),
m => queryInput.TubeBarcode != null && m.BoxBarCode.Contains(queryInput.TubeBarcode))
.WhereIF(queryInput.CustomerId is not null, m => m.CustomerId == queryInput.CustomerId)
.WhereIF(queryInput.DeviceId is not null, m => m.DeviceId == queryInput.DeviceId)
.WhereIF(queryInput.CellType is not null, m => m.CellType == queryInput.CellType)
.Where(m => _userManager.OrgId == m.OrgId)
.Select<Models.Cell>((u) => new Models.Cell()
{
Id = u.Id,
TubeBarcode = u.TubeBarcode,
BoxBarCode = u.BoxBarCode,
CellType = u.CellType,
CustomerId = u.CustomerId,
DeviceId = u.DeviceId,
Circle = u.Circle,
Column = u.Column,
Layer = u.Layer,
DepositTime = u.DepositTime,
ExpirationTime = u.ExpirationTime,
Activity = u.Activity,
Density = u.Density,
Capacity = u.Capacity
})
.ToPagedListAsync(queryInput.Page, queryInput.PageSize);
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[DisplayName("Add")]
public async Task<long?> AddCell(CellInput input)
{
return await _repository.InsertReturnBigIdentityAsync(new CellEntity()
{
TubeBarcode = input.TubeBarcode,
BoxBarCode = input.BoxBarCode,
CellType = input.CellType,
CustomerId = input.CustomerId,
DeviceId = input.DeviceId,
Circle = input.Circle,
Column = input.Column,
Layer = input.Layer,
DepositTime = input.DepositTime,
ExpirationTime = input.ExpirationTime,
Activity = input.Activity,
Density = input.Density,
Capacity = input.Capacity
});
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "Update"), HttpPost]
[DisplayName("Update")]
public async Task UpdateCell(CellInput input)
{
await _repository.UpdateAsync(new CellEntity()
{
Id = input.Id,
TubeBarcode = input.TubeBarcode,
BoxBarCode = input.BoxBarCode,
CellType = input.CellType,
CustomerId = input.CustomerId,
DeviceId = input.DeviceId,
Circle = input.Circle,
Column = input.Column,
Layer = input.Layer,
DepositTime = input.DepositTime,
ExpirationTime = input.ExpirationTime,
Activity = input.Activity,
Density = input.Density,
Capacity = input.Capacity
});
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "Delete"), HttpPost]
[DisplayName("Delete")]
public async Task DeleteCell(long? id)
{
await _repository.DeleteByIdAsync(id);
}
}