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

93 lines
3.7 KiB

3 months ago
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using System.ComponentModel;
using Admin.NET.Bodk.Core;
using Admin.NET.Bodk.Genetic.Entities.Tumors;
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace Admin.NET.Bodk.Genetic;
[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Tumor", Description = "肿瘤服务")]
public class TumorService(
UserManager userManager,
SysOrgService sysOrgService,
SysUserService sysUserService,
SqlSugarRepository<TumorEntity> tumorRepository,
SqlSugarRepository<TumorGeneLocusEntity> tumorGeneLocusRepository,
SqlSugarRepository<GeneLocusRiskEntity> geneLocusRiskRepository,
SqlSugarRepository<GeneLocusEntity> geneLocusRepository,
SqlSugarRepository<GeneTypeEntity> geneTypeRepository)
: ServiceBase(userManager, sysOrgService, sysUserService)
{
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
[DisplayName("获取肿瘤信息")]
public async Task<TumorEntity?> GetTumor(string code)
{
var tumor = await tumorRepository.AsQueryable()
.FirstAsync(t => t.Code == code);
if (tumor is null)
throw Oops.Oh("肿瘤Code不存在");
var locusIds = await tumorGeneLocusRepository.AsQueryable()
.Where(tl => tl.TumorId == tumor.Id).Select(l => l.LocusId).ToListAsync();
var geneLoci = await geneLocusRepository.AsQueryable()
.Where(gl => locusIds.Contains(gl.Id)).ToListAsync();
foreach (var geneLocus in geneLoci)
{
var riskIds = await geneLocusRiskRepository.AsQueryable()
.Where(r => r.LocusId == geneLocus.Id).Select(r => r.RiskId).ToListAsync();
geneLocus.Types = await geneTypeRepository.AsQueryable()
.Where(t => riskIds.Contains(t.Id)).ToListAsync();
}
tumor.GeneLoci = geneLoci;
return tumor;
}
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
[DisplayName("添加一条肿瘤记录")]
public async Task AddTumor(TumorEntity tumor)
{
var db = tumorRepository.Context;
try
{
await db.Ado.BeginTranAsync();
var tumorId = await db.Insertable(tumor).ExecuteReturnSnowflakeIdAsync();
tumor.Id = tumorId;
foreach (var geneLocus in tumor.GeneLoci)
{
var locusId = await db.Insertable(geneLocus).ExecuteReturnSnowflakeIdAsync();
var tumorGeneLocusEntity = new TumorGeneLocusEntity()
{
LocusId = locusId,
TumorId = tumorId
};
await db.Insertable(tumorGeneLocusEntity).ExecuteCommandAsync();
foreach (var risk in geneLocus.Types)
{
var riskId = await db.Insertable(risk).ExecuteReturnSnowflakeIdAsync();
var geneLocusRiskEntity = new GeneLocusRiskEntity()
{
RiskId = riskId,
LocusId = locusId
};
await db.Insertable(geneLocusRiskEntity).ExecuteCommandAsync();
}
}
await db.Ado.CommitTranAsync();
}
catch
{
await db.Ado.RollbackTranAsync();
throw;
}
}
}