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

173 lines
6.6 KiB

2 months ago
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using System.ComponentModel;
using Admin.NET.Bodk.Genetic.Entities;
using Admin.NET.Bodk.Genetic.Models;
using Admin.NET.Core;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using Nest;
using SqlSugar;
namespace Admin.NET.Bodk.Genetic;
[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Genetic", Description = "基因检测服务")]
public class GeneticTestService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<GeneticTestResultEntity> _resultRepository;
private readonly SqlSugarRepository<GeneticItemTestResultEntity> _itemRepository;
public GeneticTestService(SqlSugarRepository<GeneticTestResultEntity> resultRepository,
SqlSugarRepository<GeneticItemTestResultEntity> itemRepository)
{
_resultRepository = resultRepository;
_itemRepository = itemRepository;
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "GetList"), HttpPost]
[DisplayName("GetList")]
public async Task<SqlSugarPagedList<GeneticTestResultOutput>> GetList(GeneticTestResultQueryInput queryInput)
{
return await _resultRepository.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(queryInput.Code),
m => queryInput.Code != null && m.Code.Contains(queryInput.Code))
.WhereIF(!string.IsNullOrWhiteSpace(queryInput.Barcode),
m => queryInput.Barcode != null && m.Code.Contains(queryInput.Barcode))
.WhereIF(queryInput.CustomerId is not null, m => m.CustomerId == queryInput.CustomerId)
.WhereIF(queryInput.Status is not null,
m => m.Status == queryInput.Status)
.Select<GeneticTestResultOutput>((u) => new Models.GeneticTestResultOutput()
{
Id = u.Id,
CustomerId = u.CustomerId,
Code = u.Code,
Status = u.Status,
Barcode = u.Barcode,
GenerationTime = u.GenerationTime,
CollectionTime = u.CollectionTime,
CreateTime = u.CreateTime,
CreateUserId = u.CreateUserId,
CreateUserName = u.CreateUserName,
UpdateTime = u.UpdateTime,
UpdateUserId = u.UpdateUserId,
UpdateUserName = u.UpdateUserName,
TestType = u.TestType,
IsDelete = u.IsDelete
})
.Mapper(r =>
{
r.Items = _itemRepository.AsQueryable().Where(i => i.GeneticTestResultId == r.Id)
.Select(i => new GeneticItemOutput()
{
RiskLevel = i.RiskLevel,
CreateUserId = i.CreateUserId,
CreateUserName = i.CreateUserName,
CreateTime = i.CreateTime,
UpdateUserId = i.UpdateUserId,
UpdateUserName = i.UpdateUserName,
UpdateTime = i.UpdateTime,
GeneticTestResultId = i.GeneticTestResultId,
IsDelete = i.IsDelete,
RiskScore = i.RiskScore,
Growth = i.Growth,
AverageRiskScore = i.AverageRiskScore,
Genetics = i.Genetics,
Name = i.Name
}).ToList();
})
.ToPagedListAsync(queryInput.Page, queryInput.PageSize);
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[DisplayName("Add")]
public async Task<long?> AddGeneticTestResult(GeneticTestResultInput input)
{
var id = await _resultRepository.InsertReturnSnowflakeIdAsync(new GeneticTestResultEntity()
{
CustomerId = input.CustomerId,
Code = input.Code,
Status = input.Status,
Barcode = input.Barcode,
GenerationTime = input.GenerationTime,
CollectionTime = input.CollectionTime,
TestType = input.TestType
});
if (input.Items is not null)
{
await _itemRepository.InsertRangeAsync(input.Items.Select(i => new GeneticItemTestResultEntity()
{
Name = i.Name,
RiskScore = i.RiskScore,
RiskLevel = i.RiskLevel,
AverageRiskScore = i.AverageRiskScore,
Genetics = i.Genetics,
Growth = i.Growth,
GeneticTestResultId = id
}).ToArray());
}
return id;
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "Update"), HttpPost]
[DisplayName("Update")]
public async Task UpdateGeneticTestResult(GeneticTestResultUpdateInput input)
{
await _resultRepository.UpdateAsync(new GeneticTestResultEntity()
{
Id = input.Id,
CustomerId = input.CustomerId,
Code = input.Code,
Status = input.Status,
Barcode = input.Barcode,
GenerationTime = input.GenerationTime,
TestType = input.TestType,
CollectionTime = input.CollectionTime
});
if (input.Items is not null)
{
await _itemRepository.DeleteAsync(i => i.GeneticTestResultId == input.Id);
await _itemRepository.InsertRangeAsync(input.Items.Select(i => new GeneticItemTestResultEntity()
{
Name = i.Name,
RiskScore = i.RiskScore,
RiskLevel = i.RiskLevel,
AverageRiskScore = i.AverageRiskScore,
Genetics = i.Genetics,
Growth = i.Growth,
2 months ago
GeneticTestResultId = input.Id
2 months ago
}).ToArray());
}
}
[UnitOfWork]
[ApiDescriptionSettings(Name = "Delete"), HttpPost]
[DisplayName("Delete")]
public async Task DeleteGeneticTestResult(long? id)
{
await _resultRepository.DeleteByIdAsync(id);
await _itemRepository.DeleteAsync(i => i.GeneticTestResultId == id);
}
2 months ago
[ApiDescriptionSettings(Name = "Bind"), HttpPost]
[DisplayName("Bind")]
public async Task<long> BindGeneticTestBarcode(BindGeneticTestBarcodeInput input)
{
var entity = new GeneticTestResultEntity()
{
CustomerId = input.CustomerId,
Barcode = input.Barcode,
Status = GeneticTestStatus.Sampled
};
var id = await _resultRepository.InsertReturnSnowflakeIdAsync(entity);
return id;
}
2 months ago
}