From 284ad0bb084fa9338c519b762e68d4520afd7f66 Mon Sep 17 00:00:00 2001 From: anerx <512464164@qq.com> Date: Tue, 13 Aug 2024 09:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Admin.Bodk.Device/Entities/Dto/Base.cs | 10 +- Admin.Bodk.Device/Entities/Dto/SupportDto.cs | 4 + Admin.Bodk.Device/Services/BaseService.cs | 2 + Admin.Bodk.Device/Services/SupportService.cs | 5 +- .../Entities/GeneticItemTestResultEntity.cs | 27 --- .../Entities/GeneticTestResultEntity.cs | 48 ---- .../Entities/Reports/GeneTestingReportEntity.cs | 42 ++++ .../Reports/GeneTestingTumorLocusReportEntity.cs | 22 ++ .../Reports/GeneTestingTumorReportEntity.cs | 25 ++ .../Entities/Tumors/GeneLocusEntity.cs | 17 ++ .../Entities/Tumors/GeneLocusRiskEntity.cs | 15 ++ .../Entities/Tumors/GeneTypeEntity.cs | 16 ++ .../Entities/Tumors/TumorEntity.cs | 18 ++ .../Entities/Tumors/TumorGeneLocusEntity.cs | 15 ++ Admin.NET.Bodk.Genetic/GeneReportService.cs | 255 +++++++++++++++++++++ Admin.NET.Bodk.Genetic/GeneticTestService.cs | 176 -------------- .../Models/BindGeneticTestBarcode.cs | 12 - Admin.NET.Bodk.Genetic/Models/Genetic.cs | 18 -- Admin.NET.Bodk.Genetic/Models/GeneticItem.cs | 26 --- Admin.NET.Bodk.Genetic/Models/GeneticTestResult.cs | 62 ----- .../Models/Reports/AddReportInput.cs | 65 ++++++ Admin.NET.Bodk.Genetic/Models/Reports/BindInput.cs | 12 + .../Models/Reports/ReportOutput.cs | 85 +++++++ Admin.NET.Bodk.Genetic/TumorService.cs | 93 ++++++++ .../Entities/StationExtEntity.cs | 2 +- Admin.NET.Core/Entity/SysOrg.cs | 16 +- Admin.NET.Core/SeedData/SysOrgSeedData.cs | 3 +- Admin.NET.Core/Service/File/SysFileService.cs | 49 ++-- Admin.NET.Core/Service/Org/Dto/Area.cs | 13 ++ Admin.NET.Core/Service/Org/SysOrgService.cs | 49 +++- .../Service/Org/SysStationServiceService.cs | 10 + 31 files changed, 820 insertions(+), 392 deletions(-) delete mode 100644 Admin.NET.Bodk.Genetic/Entities/GeneticItemTestResultEntity.cs delete mode 100644 Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingReportEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorLocusReportEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorReportEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusRiskEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Tumors/GeneTypeEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Tumors/TumorEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/Entities/Tumors/TumorGeneLocusEntity.cs create mode 100644 Admin.NET.Bodk.Genetic/GeneReportService.cs delete mode 100644 Admin.NET.Bodk.Genetic/GeneticTestService.cs delete mode 100644 Admin.NET.Bodk.Genetic/Models/BindGeneticTestBarcode.cs delete mode 100644 Admin.NET.Bodk.Genetic/Models/Genetic.cs delete mode 100644 Admin.NET.Bodk.Genetic/Models/GeneticItem.cs delete mode 100644 Admin.NET.Bodk.Genetic/Models/GeneticTestResult.cs create mode 100644 Admin.NET.Bodk.Genetic/Models/Reports/AddReportInput.cs create mode 100644 Admin.NET.Bodk.Genetic/Models/Reports/BindInput.cs create mode 100644 Admin.NET.Bodk.Genetic/Models/Reports/ReportOutput.cs create mode 100644 Admin.NET.Bodk.Genetic/TumorService.cs create mode 100644 Admin.NET.Core/Service/Org/SysStationServiceService.cs diff --git a/Admin.Bodk.Device/Entities/Dto/Base.cs b/Admin.Bodk.Device/Entities/Dto/Base.cs index 62714e3..0b78ff8 100644 --- a/Admin.Bodk.Device/Entities/Dto/Base.cs +++ b/Admin.Bodk.Device/Entities/Dto/Base.cs @@ -4,21 +4,25 @@ namespace Admin.Bodk.Device.Entities.Dto; public class Base { - } + public class BaseInput : BasePageInput { - } + public class BaseOutput { public long Id { get; set; } public string Name { get; set; } public string Address { get; set; } + + public double Latitude { get; set; } + + public double Longitude { get; set; } public string Remark { get; set; } public int Phone { get; set; } public DateTime CreateTime { get; set; } - + public List SupportList { get; set; } } diff --git a/Admin.Bodk.Device/Entities/Dto/SupportDto.cs b/Admin.Bodk.Device/Entities/Dto/SupportDto.cs index faeac4a..28e7c44 100644 --- a/Admin.Bodk.Device/Entities/Dto/SupportDto.cs +++ b/Admin.Bodk.Device/Entities/Dto/SupportDto.cs @@ -48,6 +48,10 @@ public class DeviceInfo public string Humidity { get; set; } public string Address { get; set; } public string Name { get; set; } + + public double Latitude { get; set; } + + public double Longitude { get; set; } public CellBaseInfo CellBaseInfo { get; set; } } diff --git a/Admin.Bodk.Device/Services/BaseService.cs b/Admin.Bodk.Device/Services/BaseService.cs index e74bdea..2f62536 100644 --- a/Admin.Bodk.Device/Services/BaseService.cs +++ b/Admin.Bodk.Device/Services/BaseService.cs @@ -44,6 +44,8 @@ public class BaseService : IDynamicApiController, ITransient Id = u.Id, Name = u.Name, Address = u.Address, + Longitude =113.88596284379673 , + Latitude = 22.961465648223214, Remark = u.Remark, Phone = u.Phone, SupportList =SqlFunc.Subqueryable().Where(tc => tc.BaseId == u.Id).ToList() diff --git a/Admin.Bodk.Device/Services/SupportService.cs b/Admin.Bodk.Device/Services/SupportService.cs index 0145cf6..446caa2 100644 --- a/Admin.Bodk.Device/Services/SupportService.cs +++ b/Admin.Bodk.Device/Services/SupportService.cs @@ -73,9 +73,10 @@ public class SupportService : IDynamicApiController, ITransient { DeviceId = 23223232, PicUrl = "", LiquidNitrogenHeight = cache is null ? 180 : cache.LiquidHeight, Temperature = cache is null ? -195.2 : cache.TankTopTemperature, - Humidity = - cache is null ? "0.01%" : $"{cache.TankTopTemperaturecache?.CavityHumidity.ToString("0.0")}%", Address = "广东省东莞市松山湖园区科技二路宏远新智汇1栋", + Longitude =113.88596284379673 , + Latitude = 22.961465648223214, + Humidity = cache is null ? "0.1%" : $"{cache?.CavityHumidity.ToString("0.0")}%", Name = "M9_01", CellBaseInfo = new CellBaseInfo() { BaseName = "松山湖", BaseId = 13545 } } }); diff --git a/Admin.NET.Bodk.Genetic/Entities/GeneticItemTestResultEntity.cs b/Admin.NET.Bodk.Genetic/Entities/GeneticItemTestResultEntity.cs deleted file mode 100644 index d69a250..0000000 --- a/Admin.NET.Bodk.Genetic/Entities/GeneticItemTestResultEntity.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - -using Admin.NET.Core; -using SqlSugar; - -namespace Admin.NET.Bodk.Genetic.Entities; - -[SugarTable("bodk_genetic_item_test_result")] -public class GeneticItemTestResultEntity : EntityBase -{ - public long GeneticTestResultId { get; set; } - - public string Name { get; set; } - - public float Growth { get; set; } - - public float AverageRiskScore { get; set; } - - public float RiskScore { get; set; } - - public int RiskLevel { get; set; } - - [SugarColumn(IsJson = true, IsNullable = true, ColumnDataType = "TEXT")] - public List? Genetics { get; set; } -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs b/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs deleted file mode 100644 index 2713095..0000000 --- a/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs +++ /dev/null @@ -1,48 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - -using Admin.NET.Core; -using SqlSugar; - -namespace Admin.NET.Bodk.Genetic.Entities; - -[SugarTable("bodk_genetic_test_result")] -public class GeneticTestResultEntity : EntityBase -{ - public long CustomerId { get; set; } - - [SugarColumn(IsNullable = true)] - public string? Code { get; set; } - - [SugarColumn(IsNullable = true)] - public string? TestType { get; set; } - - public string Barcode { get; set; } - - [SugarColumn(IsNullable = true)] - public GeneticTestStatus? Status { get; set; } - - [SugarColumn(IsNullable = true)] - public DateTime? GenerationTime { get; set; } - - [SugarColumn(IsNullable = true)] - public DateTime? CollectionTime { get; set; } -} - -public enum GeneticTestStatus -{ - Sampled = 1, - Sent, - Resampling, - Received, - Analyzing, - ReAnalyzing, - UnderReview, - UnderReviewComplete, - NotPassed, - Completed, - Terminated, - Paused, - Failed -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingReportEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingReportEntity.cs new file mode 100644 index 0000000..8a8f597 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingReportEntity.cs @@ -0,0 +1,42 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Reports; + +[SugarTable("bodk_gene_testing_report")] +public class GeneTestingReportEntity : EntityBase +{ + public long CustomerId { get; set; } + + public string? Barcode { get; set; } + + public string? SampleType { get; set; } + + public string? TestingType { get; set; } + + public string? TestingMethod { get; set; } + + public DateTime? SubmissionTime { get; set; } + + public DateTime? ReportTime { get; set; } + + public bool? SampleQuality { get; set; } + + public bool? DnaExtraction { get; set; } + + public bool? Pcr { get; set; } + + public bool? TofMs { get; set; } + + public bool? GenotypingAnalysis { get; set; } + + public bool? GeneticRiskAssessment { get; set; } + + public bool? Report { get; set; } + + [SugarColumn(IsIgnore = true)] public List? Tumors { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorLocusReportEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorLocusReportEntity.cs new file mode 100644 index 0000000..44bf8a1 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorLocusReportEntity.cs @@ -0,0 +1,22 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Bodk.Genetic.Entities.Tumors; +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Reports; + +[SugarTable("bodk_gene_testing_tumor_locus_report")] +public class GeneTestingTumorLocusReportEntity : EntityBase +{ + public long TumorId { get; set; } + public long LocusId { get; set; } + + public long RiskId { get; set; } + + [SugarColumn(IsIgnore = true)] public GeneLocusEntity? Locus { get; set; } + + [SugarColumn(IsIgnore = true)] public GeneTypeEntity? Risk { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorReportEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorReportEntity.cs new file mode 100644 index 0000000..90ce7c6 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Reports/GeneTestingTumorReportEntity.cs @@ -0,0 +1,25 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Bodk.Genetic.Entities.Tumors; +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Reports; + +[SugarTable("bodk_gene_testing_tumor_report")] +public class GeneTestingTumorReportEntity : EntityBase +{ + public long ReportId { get; set; } + + public long TumorId { get; set; } + + public float RiskScore { get; set; } + + public int RiskLevel { get; set; } + + [SugarColumn(IsIgnore = true)] public TumorEntity? TumorDescription { get; set; } + + [SugarColumn(IsIgnore = true)] public List? Loci { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusEntity.cs new file mode 100644 index 0000000..972f33c --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusEntity.cs @@ -0,0 +1,17 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Tumors; + +[SugarTable("bodk_gene_locus")] +public class GeneLocusEntity:EntityBase +{ + public string Name { get; set; } + public string Position { get; set; } + [SugarColumn(IsIgnore = true)] + public List Types { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusRiskEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusRiskEntity.cs new file mode 100644 index 0000000..94aee39 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneLocusRiskEntity.cs @@ -0,0 +1,15 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Tumors; + +[SugarTable("bodk_gene_locus_risk")] +public class GeneLocusRiskEntity:EntityBase +{ + public long LocusId { get; set; } + public long RiskId { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneTypeEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneTypeEntity.cs new file mode 100644 index 0000000..238fb1c --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Tumors/GeneTypeEntity.cs @@ -0,0 +1,16 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Tumors; + +[SugarTable("bodk_gene_locus_type")] +public class GeneTypeEntity : EntityBase +{ + public string Description { get; set; } + public string GenekType { get; set; } + public bool Risk { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Tumors/TumorEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Tumors/TumorEntity.cs new file mode 100644 index 0000000..0ff6ab3 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Tumors/TumorEntity.cs @@ -0,0 +1,18 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Tumors; + +[SugarTable("bodk_tumor")] +public class TumorEntity : EntityBase +{ + public string Code { get; set; } + public string TumorName { get; set; } + public string Description { get; set; } + public double AvaRiskScore { get; set; } + [SugarColumn(IsIgnore = true)] public List GeneLoci { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/Tumors/TumorGeneLocusEntity.cs b/Admin.NET.Bodk.Genetic/Entities/Tumors/TumorGeneLocusEntity.cs new file mode 100644 index 0000000..2cc70fd --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Entities/Tumors/TumorGeneLocusEntity.cs @@ -0,0 +1,15 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Admin.NET.Bodk.Genetic.Entities.Tumors; + +[SugarTable("bodk_tumor_gene_locus")] +public class TumorGeneLocusEntity:EntityBase +{ + public long TumorId { get; set; } + public long LocusId { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/GeneReportService.cs b/Admin.NET.Bodk.Genetic/GeneReportService.cs new file mode 100644 index 0000000..ad8cca7 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/GeneReportService.cs @@ -0,0 +1,255 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using Admin.NET.Bodk.Core; +using Admin.NET.Bodk.Genetic.Entities.Reports; +using Admin.NET.Bodk.Genetic.Entities.Tumors; +using Admin.NET.Bodk.Genetic.Models.Reports; +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; + +namespace Admin.NET.Bodk.Genetic; + +[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "GeneReport", Description = "基因检测服务")] +public class GeneReportService( + UserManager userManager, + SysOrgService sysOrgService, + SysUserService sysUserService, + SqlSugarRepository geneTestingTumorLocusReportRepository, + SqlSugarRepository reportRepository, + SqlSugarRepository geneTestingTumorReportRepository) + : ServiceBase(userManager, sysOrgService, sysUserService) +{ + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + [DisplayName("Add")] + public async Task AddReport(AddReportInput input) + { + var db = geneTestingTumorLocusReportRepository.Context; + try + { + await db.Ado.BeginTranAsync(); + var entity = new GeneTestingReportEntity() + { + SampleType = input.SampleType, + TestingType = input.TestingType, + TestingMethod = input.TestingMethod, + TofMs = input.TofMs, + GenotypingAnalysis = input.GenotypingAnalysis, + SampleQuality = input.SampleQuality, + GeneticRiskAssessment = input.GeneticRiskAssessment, + Barcode = input.Barcode, + DnaExtraction = input.DnaExtraction, + CustomerId = input.CustomerId, + ReportTime = input.ReportTime, + Report = input.Report, + Pcr = input.Pcr, + SubmissionTime = input.SubmissionTime, + }; + entity = await AddBefore(entity); + var reportId = await db.Insertable(entity).ExecuteReturnSnowflakeIdAsync(); + foreach (var tumor in input.Tumors) + { + var tumorEntity = new GeneTestingTumorReportEntity() + { + TumorId = tumor.TumorId, + RiskScore = tumor.RiskScore, + RiskLevel = tumor.RiskLevel, + ReportId = reportId + }; + tumorEntity = await AddBefore(tumorEntity); + var tumorId = await db.Insertable(tumorEntity).ExecuteReturnSnowflakeIdAsync(); + foreach (var locus in tumor.Loci) + { + var locusEntity = new GeneTestingTumorLocusReportEntity() + { + LocusId = locus.LocusId, + RiskId = locus.RiskId, + TumorId = tumorId + }; + locusEntity = await AddBefore(locusEntity); + await db.Insertable(locusEntity).ExecuteReturnSnowflakeIdAsync(); + } + } + + await db.Ado.CommitTranAsync(); + } + catch + { + await db.Ado.RollbackTranAsync(); + throw; + } + } + + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + [DisplayName("GetList")] + public async Task> GetList([Required] long customerId) + { + var db = reportRepository.Context; + var reports = await db.Queryable() + .Where(r => r.CustomerId == customerId) + .Select(r => new ReportOutput() + { + SampleType = r.SampleType, + TestingType = r.TestingType, + TestingMethod = r.TestingMethod, + TofMs = r.TofMs, + GenotypingAnalysis = r.GenotypingAnalysis, + SampleQuality = r.SampleQuality, + GeneticRiskAssessment = r.GeneticRiskAssessment, + Barcode = r.Barcode, + DnaExtraction = r.DnaExtraction, + CustomerId = r.CustomerId, + Id = r.Id, + ReportTime = r.ReportTime, + Report = r.Report, + Pcr = r.Pcr, + SubmissionTime = r.SubmissionTime + }).ToListAsync(); + foreach (var report in reports) + { + var tumors = await db.Queryable() + .LeftJoin((r, t) => r.TumorId == t.Id) + .Where(r => r.ReportId == report.Id) + .Select((r, t) => new TumorOutput() + { + AvaRiskScore = t.AvaRiskScore, + TumorName = t.TumorName, + Description = t.Description, + Code = t.Code, + RiskScore = r.RiskScore, + RiskLevel = r.RiskLevel, + ReportId = report.Id, + TumorId = r.TumorId, + Id = r.Id, + }).ToListAsync(); + foreach (var tumor in tumors) + { + var loci = await db.Queryable() + .LeftJoin((l, gl) => l.LocusId == gl.Id) + .LeftJoin((l, gl, gt) => l.RiskId == gt.Id) + .Where(l => l.TumorId == tumor.Id) + .Select((l, gl, gt) => new LocusOutput() + { + Description = gt.Description, + Risk = gt.Risk, + GenekType = gt.GenekType, + Position = gl.Position, + LocusName = gl.Name, + Id = l.Id, + }).ToListAsync(); + tumor.Loci = loci; + } + + report.Tumors = tumors; + } + + return reports; + } + + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + [DisplayName("Bind")] + public async Task Bind(BindInput input) + { + GeneTestingReportEntity entity = new GeneTestingReportEntity() + { + CustomerId = input.CustomerId, + Barcode = input.Barcode + }; + entity = await AddBefore(entity); + return await reportRepository.InsertReturnSnowflakeIdAsync(entity); + } + + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + [DisplayName("Update")] + public async Task UpdateReport(UpdateReportInput input) + { + var db = geneTestingTumorLocusReportRepository.Context; + try + { + await db.Ado.BeginTranAsync(); + var entity = new GeneTestingReportEntity() + { + Id = input.Id, + SampleType = input.SampleType, + TestingType = input.TestingType, + TestingMethod = input.TestingMethod, + TofMs = input.TofMs, + GenotypingAnalysis = input.GenotypingAnalysis, + SampleQuality = input.SampleQuality, + GeneticRiskAssessment = input.GeneticRiskAssessment, + Barcode = input.Barcode, + DnaExtraction = input.DnaExtraction, + CustomerId = input.CustomerId, + ReportTime = input.ReportTime, + Report = input.Report, + Pcr = input.Pcr, + SubmissionTime = input.SubmissionTime, + }; + entity = await UpdateBefore(entity); + await db.Updateable(entity).ExecuteCommandAsync(); + foreach (var tumor in input.Tumors) + { + var tumorEntity = new GeneTestingTumorReportEntity() + { + TumorId = tumor.TumorId, + RiskScore = tumor.RiskScore, + RiskLevel = tumor.RiskLevel, + ReportId = input.Id + }; + long tumorId = 0; + if (tumor.Id is null) + { + tumorEntity = await AddBefore(tumorEntity); + tumorId = await db.Insertable(tumorEntity).ExecuteReturnSnowflakeIdAsync(); + } + else + { + tumorEntity.Id=tumor.Id.Value; + tumorEntity = await UpdateBefore(tumorEntity); + await db.Updateable(tumorEntity).ExecuteCommandAsync(); + tumorId = tumor.Id.Value; + } + + foreach (var locus in tumor.Loci) + { + var locusEntity = new GeneTestingTumorLocusReportEntity() + { + LocusId = locus.LocusId, + RiskId = locus.RiskId, + TumorId = tumorId + }; + if (locus.Id is null) + { + locusEntity = await AddBefore(locusEntity); + await db.Insertable(locusEntity).ExecuteReturnSnowflakeIdAsync(); + } + else + { + locusEntity.Id=locus.Id.Value; + locusEntity = await UpdateBefore(locusEntity); + await db.Updateable(locusEntity).ExecuteCommandAsync(); + } + + } + } + + await db.Ado.CommitTranAsync(); + } + catch + { + await db.Ado.RollbackTranAsync(); + throw; + } + } + + // public async Task GetSingle([Required] string barcode) + // { + // } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/GeneticTestService.cs b/Admin.NET.Bodk.Genetic/GeneticTestService.cs deleted file mode 100644 index 4dc4fbb..0000000 --- a/Admin.NET.Bodk.Genetic/GeneticTestService.cs +++ /dev/null @@ -1,176 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话: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.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; -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 _resultRepository; - - private readonly SqlSugarRepository _itemRepository; - - public GeneticTestService(SqlSugarRepository resultRepository, - SqlSugarRepository itemRepository) - { - _resultRepository = resultRepository; - _itemRepository = itemRepository; - } - - [UnitOfWork] - [ApiDescriptionSettings(Name = "GetList"), HttpPost] - [DisplayName("GetList")] - public async Task> 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((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 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, - GeneticTestResultId = input.Id - }).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); - } - - [ApiDescriptionSettings(Name = "Bind"), HttpPost] - [DisplayName("Bind")] - [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] - public async Task BindGeneticTestBarcode(BindGeneticTestBarcodeInput input) - { - var entity = new GeneticTestResultEntity() - { - CustomerId = input.CustomerId, - Barcode = input.Barcode, - Status = GeneticTestStatus.Sampled - }; - var id = await _resultRepository.InsertReturnSnowflakeIdAsync(entity); - return id; - } -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/BindGeneticTestBarcode.cs b/Admin.NET.Bodk.Genetic/Models/BindGeneticTestBarcode.cs deleted file mode 100644 index f36e83c..0000000 --- a/Admin.NET.Bodk.Genetic/Models/BindGeneticTestBarcode.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - -namespace Admin.NET.Bodk.Genetic.Models; - -public class BindGeneticTestBarcodeInput -{ - public string Barcode { get; set; } - - public long CustomerId { get; set; } -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/Genetic.cs b/Admin.NET.Bodk.Genetic/Models/Genetic.cs deleted file mode 100644 index 4cb4559..0000000 --- a/Admin.NET.Bodk.Genetic/Models/Genetic.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - -namespace Admin.NET.Bodk.Genetic.Models; - -public class Genetic -{ - public string Name { get; set; } - - public string Postion { get; set; } - - public bool Risk { get; set; } - - public string Type { get; set; } - - public string Description { get; set; } -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/GeneticItem.cs b/Admin.NET.Bodk.Genetic/Models/GeneticItem.cs deleted file mode 100644 index 5b0f743..0000000 --- a/Admin.NET.Bodk.Genetic/Models/GeneticItem.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - -using Admin.NET.Bodk.Genetic.Entities; - -namespace Admin.NET.Bodk.Genetic.Models; - -public class GeneticItemOutput : GeneticItemTestResultEntity -{ -} - -public class GeneticItemInput -{ - public string Name { get; set; } - - public float Growth { get; set; } - - public float AverageRiskScore { get; set; } - - public float RiskScore { get; set; } - - public int RiskLevel { get; set; } - - public List? Genetics { get; set; } -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/GeneticTestResult.cs b/Admin.NET.Bodk.Genetic/Models/GeneticTestResult.cs deleted file mode 100644 index 84b7967..0000000 --- a/Admin.NET.Bodk.Genetic/Models/GeneticTestResult.cs +++ /dev/null @@ -1,62 +0,0 @@ -// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 -// -// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 - -using Admin.NET.Bodk.Genetic.Entities; -using Admin.NET.Core; - -namespace Admin.NET.Bodk.Genetic.Models; - -public class GeneticTestResultQueryInput : BasePageInput -{ - public long? CustomerId { get; set; } - - public string? Code { get; set; } - - public string? Barcode { get; set; } - - public GeneticTestStatus? Status { get; set; } -} - -public class GeneticTestResultInput -{ - public long CustomerId { get; set; } - - public string Code { get; set; } - - public string Barcode { get; set; } - - public string TestType { get; set; } - - public GeneticTestStatus Status { get; set; } - - public DateTime GenerationTime { get; set; } - - public DateTime CollectionTime { get; set; } - - public List? Items { get; set; } -} - -public class GeneticTestResultUpdateInput : BaseIdInput -{ - public long CustomerId { get; set; } - - public string Code { get; set; } - - public string Barcode { get; set; } - - public string TestType { get; set; } - - public GeneticTestStatus Status { get; set; } - - public DateTime GenerationTime { get; set; } - - public DateTime CollectionTime { get; set; } - - public List? Items { get; set; } -} - -public class GeneticTestResultOutput : GeneticTestResultEntity -{ - public List? Items { get; set; } -} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/Reports/AddReportInput.cs b/Admin.NET.Bodk.Genetic/Models/Reports/AddReportInput.cs new file mode 100644 index 0000000..5b1ff54 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Models/Reports/AddReportInput.cs @@ -0,0 +1,65 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; + +namespace Admin.NET.Bodk.Genetic.Models.Reports; + +public class AddReportInput +{ + public long CustomerId { get; set; } + + public string? Barcode { get; set; } + + public string? SampleType { get; set; } + + public string? TestingType { get; set; } + + public string? TestingMethod { get; set; } + + public DateTime? SubmissionTime { get; set; } + + public DateTime? ReportTime { get; set; } + + public bool? SampleQuality { get; set; } + + public bool? DnaExtraction { get; set; } + + public bool? Pcr { get; set; } + + public bool? TofMs { get; set; } + + public bool? GenotypingAnalysis { get; set; } + + public bool? GeneticRiskAssessment { get; set; } + + public bool? Report { get; set; } + + public List Tumors { get; set; } = []; +} + +public class AddTumorReportInput +{ + public long? Id { get; set; } + public long TumorId { get; set; } + + public float RiskScore { get; set; } + + public int RiskLevel { get; set; } + + public List Loci { get; set; } = []; +} + +public class AddTumorLocusReportInput +{ + public long? Id { get; set; } + public long LocusId { get; set; } + + public long RiskId { get; set; } +} + +public class UpdateReportInput : AddReportInput +{ + public long Id { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/Reports/BindInput.cs b/Admin.NET.Bodk.Genetic/Models/Reports/BindInput.cs new file mode 100644 index 0000000..4370e40 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Models/Reports/BindInput.cs @@ -0,0 +1,12 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Bodk.Genetic.Models.Reports; + +public class BindInput +{ + public string Barcode { get; set; } + + public long CustomerId { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Models/Reports/ReportOutput.cs b/Admin.NET.Bodk.Genetic/Models/Reports/ReportOutput.cs new file mode 100644 index 0000000..537420a --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Models/Reports/ReportOutput.cs @@ -0,0 +1,85 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using System.ComponentModel.DataAnnotations; +using Admin.NET.Core; + +namespace Admin.NET.Bodk.Genetic.Models.Reports; + +public class QueryReportInput : BasePageInput +{ + [Required(ErrorMessage = "客户Id不能为空")] public long CustomerId { get; set; } +} + +public class ReportOutput +{ + public long Id { get; set; } + public long CustomerId { get; set; } + + public string? Barcode { get; set; } + + public string? SampleType { get; set; } + + public string? TestingType { get; set; } + + public string? TestingMethod { get; set; } + + public DateTime? SubmissionTime { get; set; } + + public DateTime? ReportTime { get; set; } + + public bool? SampleQuality { get; set; } + + public bool? DnaExtraction { get; set; } + + public bool? Pcr { get; set; } + + public bool? TofMs { get; set; } + + public bool? GenotypingAnalysis { get; set; } + + public bool? GeneticRiskAssessment { get; set; } + + public bool? Report { get; set; } + + public List Tumors { get; set; } = new List(); +} + +public class TumorOutput +{ + public long Id { get; set; } + + public long ReportId { get; set; } + + public long TumorId { get; set; } + + public string Code { get; set; } + + public string TumorName { get; set; } + + public string Description { get; set; } + + public double RiskScore { get; set; } + + public double AvaRiskScore { get; set; } + + public int RiskLevel { get; set; } + + public List Loci { get; set; } = []; +} + +public class LocusOutput +{ + public long Id { get; set; } + + public string Description { get; set; } + + public string GenekType { get; set; } + + public bool Risk { get; set; } + + public string LocusName { get; set; } + + public string Position { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/TumorService.cs b/Admin.NET.Bodk.Genetic/TumorService.cs new file mode 100644 index 0000000..b29f8f1 --- /dev/null +++ b/Admin.NET.Bodk.Genetic/TumorService.cs @@ -0,0 +1,93 @@ +// 大名科技(天津)有限公司版权所有 电话: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 tumorRepository, + SqlSugarRepository tumorGeneLocusRepository, + SqlSugarRepository geneLocusRiskRepository, + SqlSugarRepository geneLocusRepository, + SqlSugarRepository geneTypeRepository) + : ServiceBase(userManager, sysOrgService, sysUserService) +{ + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + [DisplayName("获取肿瘤信息")] + public async Task 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; + } + } +} \ No newline at end of file diff --git a/Admin.NET.Bodk.Project/Entities/StationExtEntity.cs b/Admin.NET.Bodk.Project/Entities/StationExtEntity.cs index e1ea052..01909c1 100644 --- a/Admin.NET.Bodk.Project/Entities/StationExtEntity.cs +++ b/Admin.NET.Bodk.Project/Entities/StationExtEntity.cs @@ -14,6 +14,6 @@ public class StationExtEntity : EntityBase public long OrgId { get; set; } - [SugarColumn(IsArray = true, ColumnDataType = "long", Length = 1000, IsNullable = true)] + [SugarColumn(IsArray = true, IsNullable = true)] public long[]? ServiceIds { get; set; } } \ No newline at end of file diff --git a/Admin.NET.Core/Entity/SysOrg.cs b/Admin.NET.Core/Entity/SysOrg.cs index c752b03..059919b 100644 --- a/Admin.NET.Core/Entity/SysOrg.cs +++ b/Admin.NET.Core/Entity/SysOrg.cs @@ -2,6 +2,8 @@ // // 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 +using System.Text.Json; + namespace Admin.NET.Core; /// @@ -95,7 +97,19 @@ public class SysOrg : EntityTenant [SugarColumn(IsNullable = true, ColumnDataType = "TEXT")] public string? Position { get; set; } - [SugarColumn(IsArray = true)] public long[]? ServiceIds { get; set; } + [SugarColumn(ColumnDataType = "json")] public string ServiceIdsJson { get; set; } [SugarColumn(IsIgnore = true)] public List? Services { get; set; } + + [SugarColumn(IsIgnore = true)] + public List? ServiceIds + { + get + { + if (string.IsNullOrWhiteSpace(ServiceIdsJson)) + return null; + return JsonSerializer.Deserialize>(ServiceIdsJson); + } + set { ServiceIdsJson = JsonSerializer.Serialize(value); } + } } \ No newline at end of file diff --git a/Admin.NET.Core/SeedData/SysOrgSeedData.cs b/Admin.NET.Core/SeedData/SysOrgSeedData.cs index 38aa0b5..e4c50d5 100644 --- a/Admin.NET.Core/SeedData/SysOrgSeedData.cs +++ b/Admin.NET.Core/SeedData/SysOrgSeedData.cs @@ -20,7 +20,8 @@ public class SysOrgSeedData : ISqlSugarEntitySeedData new SysOrg { Id = 1300000000101, Pid = 0, Name = "博工科技", Code = "1", Type = "101", Level = 1, - CreateTime = DateTime.Parse("2022-02-10 00:00:00"), Remark = "松山湖基地", TenantId = 1300000000001 + CreateTime = DateTime.Parse("2022-02-10 00:00:00"), Remark = "松山湖基地", TenantId = 1300000000001, + ServiceIds = new List() } }; } diff --git a/Admin.NET.Core/Service/File/SysFileService.cs b/Admin.NET.Core/Service/File/SysFileService.cs index 3154282..b8fc58a 100644 --- a/Admin.NET.Core/Service/File/SysFileService.cs +++ b/Admin.NET.Core/Service/File/SysFileService.cs @@ -4,6 +4,7 @@ using Aliyun.OSS.Util; using Furion.VirtualFileServer; +using Nest; using OnceMi.AspNetCore.OSS; namespace Admin.NET.Core.Service; @@ -44,8 +45,10 @@ public class SysFileService : IDynamicApiController, ITransient { return await _sysFileRep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.FileName), u => u.FileName.Contains(input.FileName.Trim())) - .WhereIF(!string.IsNullOrWhiteSpace(input.StartTime.ToString()) && !string.IsNullOrWhiteSpace(input.EndTime.ToString()), - u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime) + .WhereIF( + !string.IsNullOrWhiteSpace(input.StartTime.ToString()) && + !string.IsNullOrWhiteSpace(input.EndTime.ToString()), + u => u.CreateTime >= input.StartTime && u.CreateTime <= input.EndTime) .OrderBy(u => u.CreateTime, OrderByType.Desc) .ToPagedListAsync(input.Page, input.PageSize); } @@ -70,7 +73,8 @@ public class SysFileService : IDynamicApiController, ITransient /// /// /// - private async Task UploadFileFromBase64(string strBase64, string fileName, string contentType, string? path) + private async Task UploadFileFromBase64(string strBase64, string fileName, string contentType, + string? path) { byte[] fileData = Convert.FromBase64String(strBase64); var ms = new MemoryStream(); @@ -113,8 +117,10 @@ public class SysFileService : IDynamicApiController, ITransient { filelist.Add(await UploadFile(file, "")); } + return filelist; } + /// /// 根据文件Id或Url下载 @@ -129,14 +135,17 @@ public class SysFileService : IDynamicApiController, ITransient if (_OSSProviderOptions.IsEnable) { var filePath = string.Concat(file.FilePath, "/", file.Id.ToString() + file.Suffix); - var stream = await (await _OSSService.PresignedGetObjectAsync(file.BucketName.ToString(), filePath, 5)).GetAsStreamAsync(); - return new FileStreamResult(stream.Stream, "application/octet-stream") { FileDownloadName = fileName + file.Suffix }; + var stream = await (await _OSSService.PresignedGetObjectAsync(file.BucketName.ToString(), filePath, 5)) + .GetAsStreamAsync(); + return new FileStreamResult(stream.Stream, "application/octet-stream") + { FileDownloadName = fileName + file.Suffix }; } else { var filePath = Path.Combine(file.FilePath, file.Id.ToString() + file.Suffix); var path = Path.Combine(App.WebHostEnvironment.WebRootPath, filePath); - return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName + file.Suffix }; + return new FileStreamResult(new FileStream(path, FileMode.Open), "application/octet-stream") + { FileDownloadName = fileName + file.Suffix }; } } @@ -194,11 +203,13 @@ public class SysFileService : IDynamicApiController, ITransient if (_OSSProviderOptions.IsEnable) { - await _OSSService.RemoveObjectAsync(file.BucketName.ToString(), string.Concat(file.FilePath, "/", $"{input.Id}{file.Suffix}")); + await _OSSService.RemoveObjectAsync(file.BucketName.ToString(), + string.Concat(file.FilePath, "/", $"{input.Id}{file.Suffix}")); } else { - var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, file.FilePath, input.Id.ToString() + file.Suffix); + var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, file.FilePath, + input.Id.ToString() + file.Suffix); if (File.Exists(filePath)) File.Delete(filePath); } @@ -250,12 +261,15 @@ public class SysFileService : IDynamicApiController, ITransient { fileMd5 = OssUtils.ComputeContentMd5(fileStream, fileStream.Length); } + /* * Mysql8 中如果使用了 utf8mb4_general_ci 之外的编码会出错,尽量避免在条件里使用.ToString() * 因为 Squsugar 并不是把变量转换为字符串来构造SQL语句,而是构造了CAST(123 AS CHAR)这样的语句,这样这个返回值是utf8mb4_general_ci,所以容易出错。 */ var strSizeKb = sizeKb.ToString(); - var sysFile = await _sysFileRep.GetFirstAsync(u => u.FileMd5 == fileMd5 && (u.SizeKb == null || u.SizeKb == strSizeKb)); + var sysFile = + await _sysFileRep.GetFirstAsync( + u => u.FileMd5 == fileMd5 && (u.SizeKb == null || u.SizeKb == strSizeKb)); if (sysFile != null) return sysFile; } @@ -287,6 +301,7 @@ public class SysFileService : IDynamicApiController, ITransient if (suffix == ".jpe") suffix = ".jpg"; } + if (string.IsNullOrWhiteSpace(suffix)) throw Oops.Oh(ErrorCodeEnum.D8003); @@ -304,25 +319,28 @@ public class SysFileService : IDynamicApiController, ITransient FileMd5 = fileMd5, }; - var finalName = newFile.Id + suffix; // 文件最终名称 + newFile.FileName = newFile.Id + suffix; // 文件最终名称 if (_OSSProviderOptions.IsEnable) { newFile.Provider = Enum.GetName(_OSSProviderOptions.Provider); - var filePath = string.Concat(path, "/", finalName); + var filePath = string.Concat(path, "/", newFile.FileName); await _OSSService.PutObjectAsync(newFile.BucketName, filePath, file.OpenReadStream()); // http://<你的bucket名字>.oss.aliyuncs.com/<你的object名字> // 生成外链地址 方便前端预览 switch (_OSSProviderOptions.Provider) { case OSSProvider.Aliyun: - newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{newFile.BucketName}.{_OSSProviderOptions.Endpoint}/{filePath}"; + case OSSProvider.HuaweiCloud: + newFile.Url = + $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{newFile.BucketName}.{_OSSProviderOptions.Endpoint}/{filePath}"; break; case OSSProvider.Minio: // 获取Minio文件的下载或者预览地址 // newFile.Url = await GetMinioPreviewFileUrl(newFile.BucketName, filePath);// 这种方法生成的Url是有7天有效期的,不能这样使用 // 需要在MinIO中的Buckets开通对 Anonymous 的readonly权限 - newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{_OSSProviderOptions.Endpoint}/{newFile.BucketName}/{filePath}"; + newFile.Url = + $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{_OSSProviderOptions.Endpoint}/{newFile.BucketName}/{filePath}"; break; } } @@ -333,7 +351,7 @@ public class SysFileService : IDynamicApiController, ITransient if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath); - var realFile = Path.Combine(filePath, finalName); + var realFile = Path.Combine(filePath, newFile.FileName); //IDetector detector; using (var stream = File.Create(realFile)) { @@ -356,6 +374,7 @@ public class SysFileService : IDynamicApiController, ITransient host += "/"; newFile.Url = $"{host}{newFile.FilePath}/{newFile.Id + newFile.Suffix}"; } + await _sysFileRep.AsInsertable(newFile).ExecuteCommandAsync(); return newFile; } @@ -389,6 +408,7 @@ public class SysFileService : IDynamicApiController, ITransient var fileId = Path.GetFileNameWithoutExtension(user.Avatar); await DeleteFile(new DeleteFileInput { Id = long.Parse(fileId) }); } + await sysUserRep.UpdateAsync(u => new SysUser() { Avatar = sysFile.Url }, u => u.Id == user.Id); return sysFile; } @@ -411,6 +431,7 @@ public class SysFileService : IDynamicApiController, ITransient var fileId = Path.GetFileNameWithoutExtension(user.Signature); await DeleteFile(new DeleteFileInput { Id = long.Parse(fileId) }); } + await sysUserRep.UpdateAsync(u => new SysUser() { Signature = sysFile.Url }, u => u.Id == user.Id); return sysFile; } diff --git a/Admin.NET.Core/Service/Org/Dto/Area.cs b/Admin.NET.Core/Service/Org/Dto/Area.cs index 94e72e7..07a8aa1 100644 --- a/Admin.NET.Core/Service/Org/Dto/Area.cs +++ b/Admin.NET.Core/Service/Org/Dto/Area.cs @@ -9,6 +9,19 @@ public class AreaOutput:SysOrg public List? Factories { get; set; } } +public class QueryAreaInput +{ + /// + /// 名称 + /// + public string Name { get; set; } + + /// + /// 编码 + /// + public string Code { get; set; } +} + public class AddAreaInput { public long Pid { get; set; } diff --git a/Admin.NET.Core/Service/Org/SysOrgService.cs b/Admin.NET.Core/Service/Org/SysOrgService.cs index d870377..09fbf43 100644 --- a/Admin.NET.Core/Service/Org/SysOrgService.cs +++ b/Admin.NET.Core/Service/Org/SysOrgService.cs @@ -445,6 +445,53 @@ public class SysOrgService : IDynamicApiController, ITransient return newOrg.Id; } + // public async Task> GetUserAreaList(QueryAreaInput input) + // { + // var userOrgIdList = await GetUserOrgIdList(); + // var iSugarQueryable = _sysOrgRep.AsQueryable().OrderBy(u => u.OrderNo) + // .Where(a => a.Type == "Area"); + // var orgTree = new List(); + // if (_userManager.SuperAdmin) + // { + // orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id); + // } + // else + // { + // orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, + // userOrgIdList.Select(d => (object)d).ToArray()); + // // 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户) + // HandlerOrgTree(orgTree, userOrgIdList); + // } + // + // var sysOrg = await _sysOrgRep.GetSingleAsync(u => u.Id == input.Id); + // if (sysOrg != null) + // { + // sysOrg.Children = orgTree; + // orgTree = new List { sysOrg }; + // } + // + // return orgTree; + // if (!string.IsNullOrWhiteSpace(input.Name) || !string.IsNullOrWhiteSpace(input.Code)) + // { + // return await iSugarQueryable.WhereIF(userOrgIdList.Count > 0, u => userOrgIdList.Contains(u.Id)) + // .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) + // .WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code == input.Code) + // .Select(a => a.Adapt()) + // .Mapper(a => + // { + // a.Factories = a.Children.Where(c => c.Type == "Factory").Select(s => s.Adapt()) + // .Select(t => + // { + // t.Stations = t.Children.Where(c => c.Type == "Station") + // .Select(s => s.Adapt()).ToList(); + // return t; + // }) + // .ToList(); + // }) + // .ToListAsync(); + // } + // } + /// /// 增加基地 /// @@ -535,7 +582,7 @@ public class SysOrgService : IDynamicApiController, ITransient Type = "Station", Remark = input.Remark, DirectorId = input.DirectorId, - ServiceIds = ids, + ServiceIds = ids?.ToList(), }).ExecuteReturnEntityAsync(); return newOrg.Id; } diff --git a/Admin.NET.Core/Service/Org/SysStationServiceService.cs b/Admin.NET.Core/Service/Org/SysStationServiceService.cs new file mode 100644 index 0000000..df3cbf7 --- /dev/null +++ b/Admin.NET.Core/Service/Org/SysStationServiceService.cs @@ -0,0 +1,10 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core.Service; + +public class SysStationServiceService: IDynamicApiController, ITransient +{ + +} \ No newline at end of file