diff --git a/Admin.NET.Application/Configuration/Database.json b/Admin.NET.Application/Configuration/Database.json index 5e5401a..fc081da 100644 --- a/Admin.NET.Application/Configuration/Database.json +++ b/Admin.NET.Application/Configuration/Database.json @@ -7,8 +7,8 @@ "ConnectionConfigs": [ { //"ConfigId": "1300000000001", // 默认库标识-禁止修改 - "DbType": "Sqlite", // MySql、SqlServer、Sqlite、Oracle、PostgreSQL、Dm、Kdbndp、Oscar、MySqlConnector、Access、OpenGauss、QuestDB、HG、ClickHouse、GBase、Odbc、Custom - "ConnectionString": "DataSource=./Admin.NET.db", // 库连接字符串 + "DbType": "MySql", // MySql、SqlServer、Sqlite、Oracle、PostgreSQL、Dm、Kdbndp、Oscar、MySqlConnector、Access、OpenGauss、QuestDB、HG、ClickHouse、GBase、Odbc、Custom + "ConnectionString": "server=113.45.158.49;Database=test_bodk_cloud_db;Uid=root;Pwd=Bodk365@mysql", // 库连接字符串 //"SlaveConnectionConfigs": [ // 读写分离/主从 // { // "HitRate": 10, diff --git a/Admin.NET.Bodk.Genetic/GeneReportService.cs b/Admin.NET.Bodk.Genetic/GeneReportService.cs index ad8cca7..0bd0dbe 100644 --- a/Admin.NET.Bodk.Genetic/GeneReportService.cs +++ b/Admin.NET.Bodk.Genetic/GeneReportService.cs @@ -11,6 +11,7 @@ using Admin.NET.Bodk.Genetic.Models.Reports; using Admin.NET.Core; using Admin.NET.Core.Service; using Furion.FriendlyException; +using Mapster; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -35,23 +36,24 @@ public class GeneReportService( 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, - }; + var entity = input.Adapt(); + // 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) diff --git a/Admin.NET.Bodk.Project/Entities/AreaExtEntity.cs b/Admin.NET.Bodk.Project/Entities/AreaExtEntity.cs index 13c6aac..8ee5137 100644 --- a/Admin.NET.Bodk.Project/Entities/AreaExtEntity.cs +++ b/Admin.NET.Bodk.Project/Entities/AreaExtEntity.cs @@ -8,7 +8,7 @@ using SqlSugar; namespace Admin.NET.Bodk.Project.Entities; [SugarTable("bodk_org_area_ext")] -public class AreaExtEntity : EntityBase +public class AreaExtEntity : EntityBaseData { public long OrgId { get; set; } } \ No newline at end of file diff --git a/Admin.NET.Core/Entity/IDataAuth.cs b/Admin.NET.Core/Entity/IDataAuth.cs new file mode 100644 index 0000000..1a8e1b3 --- /dev/null +++ b/Admin.NET.Core/Entity/IDataAuth.cs @@ -0,0 +1,10 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core; + +public interface IDataAuth +{ + long OrgId { 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 059919b..5f40cff 100644 --- a/Admin.NET.Core/Entity/SysOrg.cs +++ b/Admin.NET.Core/Entity/SysOrg.cs @@ -97,19 +97,14 @@ public class SysOrg : EntityTenant [SugarColumn(IsNullable = true, ColumnDataType = "TEXT")] public string? Position { get; set; } - [SugarColumn(ColumnDataType = "json")] public string ServiceIdsJson { get; set; } + [SugarColumn(IsNullable = true, ColumnDescription = "服务列表", IsArray = true)] + public long[]? ServiceIds { 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); } - } + [SugarColumn(IsNullable = true, ColumnDescription = "经度")] + public decimal? Longitude { get; set; } + + [SugarColumn(IsNullable = true, ColumnDescription = "维度")] + public decimal? Latitude { get; set; } } \ No newline at end of file diff --git a/Admin.NET.Core/SeedData/SysOrgSeedData.cs b/Admin.NET.Core/SeedData/SysOrgSeedData.cs index e4c50d5..74bdfca 100644 --- a/Admin.NET.Core/SeedData/SysOrgSeedData.cs +++ b/Admin.NET.Core/SeedData/SysOrgSeedData.cs @@ -20,8 +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, - ServiceIds = new List() + CreateTime = DateTime.Parse("2022-02-10 00:00:00"), Remark = "总机构", TenantId = 1300000000001, + ServiceIds =[] } }; } diff --git a/Admin.NET.Core/Service/Org/SysOrgService.cs b/Admin.NET.Core/Service/Org/SysOrgService.cs index 09fbf43..8f2d7d0 100644 --- a/Admin.NET.Core/Service/Org/SysOrgService.cs +++ b/Admin.NET.Core/Service/Org/SysOrgService.cs @@ -48,18 +48,33 @@ public class SysOrgService : IDynamicApiController, ITransient .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) .WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code == input.Code) .WhereIF(!string.IsNullOrWhiteSpace(input.Type), u => u.Type == input.Type) + .Mapper(o => + { + o.Services = SqlFunc.Subqueryable() + .WhereIF(o.ServiceIds is not null, s => o.ServiceIds.Contains(s.Id)).ToList(); + }) .ToListAsync(); } var orgTree = new List(); if (_userManager.SuperAdmin) { - orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id); + orgTree = await iSugarQueryable + .Mapper(o => + { + o.Services = SqlFunc.Subqueryable() + .WhereIF(o.ServiceIds is not null, s => o.ServiceIds.Contains(s.Id)).ToList(); + }).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()); + orgTree = await iSugarQueryable.Mapper(o => + { + o.Services = SqlFunc.Subqueryable() + .WhereIF(o.ServiceIds is not null, s => o.ServiceIds.Contains(s.Id)).ToList(); + }) + .ToTreeAsync(u => u.Children, u => u.Pid, input.Id, + userOrgIdList.Select(d => (object)d).ToArray()); // 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户) HandlerOrgTree(orgTree, userOrgIdList); } @@ -119,7 +134,7 @@ public class SysOrgService : IDynamicApiController, ITransient DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); else if (input.Pid == 0) DeleteAllUserOrgCache(0, 0); - + input.ServiceIds = input.Services?.Select(u => u.Id).ToArray(); var newOrg = await _sysOrgRep.AsInsertable(input.Adapt()).ExecuteReturnEntityAsync(); return newOrg.Id; } @@ -397,193 +412,4 @@ public class SysOrgService : IDynamicApiController, ITransient var orgTreeList = await _sysOrgRep.AsQueryable().ToChildListAsync(u => u.Pid, pid, true); return orgTreeList.Select(u => u.Id).ToList(); } - - - /// - /// 增加区域 - /// - /// - /// - [ApiDescriptionSettings(Name = "AddArea"), HttpPost] - [DisplayName("增加区域")] - public async Task AddArea(AddAreaInput input) - { - if (!_userManager.SuperAdmin && input.Pid == 0) - throw Oops.Oh(ErrorCodeEnum.D2009); - - if (await _sysOrgRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code)) - throw Oops.Oh(ErrorCodeEnum.D2002); - - if (!_userManager.SuperAdmin && input.Pid != 0) - { - // 新增机构父Id不是0,则进行权限校验 - var orgIdList = await GetUserOrgIdList(); - // 新增机构的父机构不在自己的数据范围内 - if (orgIdList.Count < 1 || !orgIdList.Contains(input.Pid)) - throw Oops.Oh(ErrorCodeEnum.D2003); - } - - // 删除与此父机构有关的用户机构缓存 - var pOrg = await _sysOrgRep.GetFirstAsync(u => u.Id == input.Pid); - if (pOrg != null) - DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); - else if (input.Pid == 0) - DeleteAllUserOrgCache(0, 0); - - var newOrg = await _sysOrgRep.AsInsertable(new SysOrg() - { - Pid = input.Pid, - Status = StatusEnum.Enable, - CreateUserId = _userManager.UserId, - CreateUserName = _userManager.Account, - Name = input.Name, - Code = input.Code, - Type = "Area", - Remark = input.Remark, - DirectorId = input.DirectorId - }).ExecuteReturnEntityAsync(); - 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(); - // } - // } - - /// - /// 增加基地 - /// - /// - /// - [ApiDescriptionSettings(Name = "AddFactory"), HttpPost] - [DisplayName("增加基地")] - public async Task AddFactory(AddFactoryInput input) - { - if (!_userManager.SuperAdmin && input.Pid == 0) - throw Oops.Oh(ErrorCodeEnum.D2009); - - if (await _sysOrgRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code)) - throw Oops.Oh(ErrorCodeEnum.D2002); - - if (!_userManager.SuperAdmin && input.Pid != 0) - { - // 新增机构父Id不是0,则进行权限校验 - var orgIdList = await GetUserOrgIdList(); - // 新增机构的父机构不在自己的数据范围内 - if (orgIdList.Count < 1 || !orgIdList.Contains(input.Pid)) - throw Oops.Oh(ErrorCodeEnum.D2003); - } - - // 删除与此父机构有关的用户机构缓存 - var pOrg = await _sysOrgRep.GetFirstAsync(u => u.Id == input.Pid); - if (pOrg != null) - DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); - else if (input.Pid == 0) - DeleteAllUserOrgCache(0, 0); - - var newOrg = await _sysOrgRep.AsInsertable(new SysOrg() - { - Pid = input.Pid, - Status = StatusEnum.Enable, - CreateUserId = _userManager.UserId, - CreateUserName = _userManager.Account, - Name = input.Name, - Code = input.Code, - Type = "Factory", - Remark = input.Remark, - DirectorId = input.DirectorId, - Position = input.Position - }).ExecuteReturnEntityAsync(); - return newOrg.Id; - } - - - /// - /// 增加工作站 - /// - /// - /// - [ApiDescriptionSettings(Name = "AddStation"), HttpPost] - [DisplayName("增加工作站")] - public async Task AddStation(AddStationInput input) - { - if (!_userManager.SuperAdmin && input.Pid == 0) - throw Oops.Oh(ErrorCodeEnum.D2009); - - if (await _sysOrgRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code)) - throw Oops.Oh(ErrorCodeEnum.D2002); - - if (!_userManager.SuperAdmin && input.Pid != 0) - { - // 新增机构父Id不是0,则进行权限校验 - var orgIdList = await GetUserOrgIdList(); - // 新增机构的父机构不在自己的数据范围内 - if (orgIdList.Count < 1 || !orgIdList.Contains(input.Pid)) - throw Oops.Oh(ErrorCodeEnum.D2003); - } - - // 删除与此父机构有关的用户机构缓存 - var pOrg = await _sysOrgRep.GetFirstAsync(u => u.Id == input.Pid); - if (pOrg != null) - DeleteAllUserOrgCache(pOrg.Id, pOrg.Pid); - else if (input.Pid == 0) - DeleteAllUserOrgCache(0, 0); - var ids = input.Services?.Select(s => s.Id).ToArray(); - var newOrg = await _sysOrgRep.AsInsertable(new SysOrg() - { - Pid = input.Pid, - Status = StatusEnum.Enable, - CreateUserId = _userManager.UserId, - CreateUserName = _userManager.Account, - Name = input.Name, - Code = input.Code, - Type = "Station", - Remark = input.Remark, - DirectorId = input.DirectorId, - ServiceIds = ids?.ToList(), - }).ExecuteReturnEntityAsync(); - return newOrg.Id; - } } \ No newline at end of file diff --git a/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs b/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs index b52f14b..2885e3a 100644 --- a/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs +++ b/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs @@ -1,4 +1,6 @@ +using Org.BouncyCastle.Asn1.X509.Qualified; + namespace Admin.NET.Core; /// @@ -40,4 +42,5 @@ public class SqlSugarRepository : SimpleClient where T : class, new() if (sqlSugarScopeProviderTenant == null) return; base.Context = sqlSugarScopeProviderTenant; } + } \ No newline at end of file diff --git a/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs b/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs index 293d9eb..57be453 100644 --- a/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs +++ b/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs @@ -1,4 +1,3 @@ - using System.Text.Json; namespace Admin.NET.Core; @@ -21,10 +20,7 @@ public static class SqlSugarSetup // 自定义 SqlSugar 雪花ID算法 SnowFlakeSingle.WorkId = snowIdOpt.WorkerId; - StaticConfig.CustomSnowFlakeFunc = () => - { - return YitIdHelper.NextId(); - }; + StaticConfig.CustomSnowFlakeFunc = () => { return YitIdHelper.NextId(); }; var dbOptions = App.GetConfig("DbConnection", true); dbOptions.ConnectionConfigs.ForEach(SetDbConfig); @@ -44,10 +40,7 @@ public static class SqlSugarSetup services.AddUnitOfWork(); // 事务与工作单元注册 // 初始化数据库表结构及种子数据 - dbOptions.ConnectionConfigs.ForEach(config => - { - InitDatabase(sqlSugar, config); - }); + dbOptions.ConnectionConfigs.ForEach(config => { InitDatabase(sqlSugar, config); }); } /// @@ -110,7 +103,8 @@ public static class SqlSugarSetup var originColor = Console.ForegroundColor; if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase)) Console.ForegroundColor = ConsoleColor.Green; - if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase)) + if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || + sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase)) Console.ForegroundColor = ConsoleColor.Yellow; if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase)) Console.ForegroundColor = ConsoleColor.Red; @@ -121,7 +115,8 @@ public static class SqlSugarSetup db.Aop.OnError = ex => { if (ex.Parametres == null) return; - var log = $"【{DateTime.Now}——错误SQL】\r\n{UtilMethods.GetNativeSql(ex.Sql, (SugarParameter[])ex.Parametres)}\r\n"; + var log = + $"【{DateTime.Now}——错误SQL】\r\n{UtilMethods.GetNativeSql(ex.Sql, (SugarParameter[])ex.Parametres)}\r\n"; var originColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(log); @@ -136,7 +131,9 @@ public static class SqlSugarSetup var fileName = db.Ado.SqlStackTrace.FirstFileName; // 文件名 var fileLine = db.Ado.SqlStackTrace.FirstLine; // 行号 var firstMethodName = db.Ado.SqlStackTrace.FirstMethodName; // 方法名 - var log = $"【{DateTime.Now}——超时SQL】\r\n【所在文件名】:{fileName}\r\n【代码行数】:{fileLine}\r\n【方法名】:{firstMethodName}\r\n" + $"【SQL语句】:{UtilMethods.GetNativeSql(sql, pars)}"; + var log = + $"【{DateTime.Now}——超时SQL】\r\n【所在文件名】:{fileName}\r\n【代码行数】:{fileLine}\r\n【方法名】:{firstMethodName}\r\n" + + $"【SQL语句】:{UtilMethods.GetNativeSql(sql, pars)}"; var originColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(log); @@ -145,18 +142,21 @@ public static class SqlSugarSetup } }; } + // 数据审计 db.Aop.DataExecuting = (oldValue, entityInfo) => { if (entityInfo.OperationType == DataFilterType.InsertByObject) { // 主键(long类型)且没有值的---赋值雪花Id - if (entityInfo.EntityColumnInfo.IsPrimarykey && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long)) + if (entityInfo.EntityColumnInfo.IsPrimarykey && + entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(long)) { var id = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue); if (id == null || (long)id == 0) entityInfo.SetValue(YitIdHelper.NextId()); } + if (entityInfo.PropertyName == nameof(EntityBase.CreateTime)) entityInfo.SetValue(DateTime.Now); if (App.User != null) @@ -193,6 +193,7 @@ public static class SqlSugarSetup } } } + if (entityInfo.OperationType == DataFilterType.UpdateByObject) { if (entityInfo.PropertyName == nameof(EntityBase.UpdateTime)) @@ -250,7 +251,8 @@ public static class SqlSugarSetup }; await db.CopyNew().Insertable(logDiff).ExecuteCommandAsync(); Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(DateTime.Now + $"\r\n*****开始差异日志*****\r\n{Environment.NewLine}{JSON.Serialize(logDiff)}{Environment.NewLine}*****结束差异日志*****\r\n"); + Console.WriteLine(DateTime.Now + + $"\r\n*****开始差异日志*****\r\n{Environment.NewLine}{JSON.Serialize(logDiff)}{Environment.NewLine}*****结束差异日志*****\r\n"); }; } @@ -273,15 +275,22 @@ public static class SqlSugarSetup // 初始化表结构 if (config.TableSettings.EnableInitTable) { - var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false)) - .WhereIF(config.TableSettings.EnableIncreTable, u => u.IsDefined(typeof(IncreTableAttribute), false)).ToList(); + var entityTypes = App.EffectiveTypes.Where(u => + !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false)) + .WhereIF(config.TableSettings.EnableIncreTable, u => u.IsDefined(typeof(IncreTableAttribute), false)) + .ToList(); if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性) - entityTypes = entityTypes.Where(u => u.GetCustomAttributes().Any() || (!u.GetCustomAttributes().Any() && !u.GetCustomAttributes().Any())).ToList(); + entityTypes = entityTypes.Where(u => + u.GetCustomAttributes().Any() || + (!u.GetCustomAttributes().Any() && + !u.GetCustomAttributes().Any())).ToList(); else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库 entityTypes = entityTypes.Where(u => u.GetCustomAttributes().Any()).ToList(); else - entityTypes = entityTypes.Where(u => u.GetCustomAttribute()?.configId.ToString() == config.ConfigId.ToString()).ToList(); // 自定义的库 + entityTypes = entityTypes.Where(u => + u.GetCustomAttribute()?.configId.ToString() == config.ConfigId.ToString()) + .ToList(); // 自定义的库 foreach (var entityType in entityTypes) { @@ -295,15 +304,20 @@ public static class SqlSugarSetup // 初始化种子数据 if (config.SeedSettings.EnableInitSeed) { - var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>)))) - .WhereIF(config.SeedSettings.EnableIncreSeed, u => u.IsDefined(typeof(IncreSeedAttribute), false)).ToList(); + var seedDataTypes = App.EffectiveTypes.Where(u => + !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces() + .Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>)))) + .WhereIF(config.SeedSettings.EnableIncreSeed, u => u.IsDefined(typeof(IncreSeedAttribute), false)) + .ToList(); foreach (var seedType in seedDataTypes) { var entityType = seedType.GetInterfaces().First().GetGenericArguments().First(); if (config.ConfigId.ToString() == SqlSugarConst.MainConfigId) // 默认库(有系统表特性、没有日志表和租户表特性) { - if (entityType.GetCustomAttribute() == null && (entityType.GetCustomAttribute() != null || entityType.GetCustomAttribute() != null)) + if (entityType.GetCustomAttribute() == null && + (entityType.GetCustomAttribute() != null || + entityType.GetCustomAttribute() != null)) continue; } else if (config.ConfigId.ToString() == SqlSugarConst.LogConfigId) // 日志库 @@ -355,8 +369,10 @@ public static class SqlSugarSetup db.DbMaintenance.CreateDatabase(); // 获取所有业务表-初始化租户库表结构(排除系统表、日志表、特定库表) - var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) && - !u.IsDefined(typeof(SysTableAttribute), false) && !u.IsDefined(typeof(LogTableAttribute), false) && !u.IsDefined(typeof(TenantAttribute), false)).ToList(); + var entityTypes = App.EffectiveTypes.Where(u => + !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false) && + !u.IsDefined(typeof(SysTableAttribute), false) && !u.IsDefined(typeof(LogTableAttribute), false) && + !u.IsDefined(typeof(TenantAttribute), false)).ToList(); if (!entityTypes.Any()) return; foreach (var entityType in entityTypes) diff --git a/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj b/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj index 9ef3eaf..e96cca7 100644 --- a/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj +++ b/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj @@ -40,16 +40,6 @@ - - - - - - - - - - PreserveNewest @@ -88,4 +78,11 @@ + + + + + + + diff --git a/Admin.NET.Web.Entry/Admin.NET.db b/Admin.NET.Web.Entry/Admin.NET.db index 4f7b3f8..b2787cf 100644 Binary files a/Admin.NET.Web.Entry/Admin.NET.db and b/Admin.NET.Web.Entry/Admin.NET.db differ diff --git a/Admin.NET.sln b/Admin.NET.sln index 8e8da6e..e1a7656 100644 --- a/Admin.NET.sln +++ b/Admin.NET.sln @@ -42,6 +42,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Cells", "Adm EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Admin.NET.Bodk.Core", "Admin.NET.Bodk.Core\Admin.NET.Bodk.Core.csproj", "{0273F0C6-A22B-494D-AA0B-30628C537FEA}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bodk", "Bodk", "{1B5D6CD4-1BAD-4F3C-9476-24376811BB56}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.NET.Core", "Bodk.NET.Core\Bodk.NET.Core.csproj", "{CE8BF7BE-451F-4421-9C0C-346FC13EBC94}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.NET.Project", "Bodk.NET.Project\Bodk.NET.Project.csproj", "{3964C5ED-A766-4FEB-987A-EC54EADFFAA0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.NET.LocalServer", "Bodk.NET.LocalServer\Bodk.NET.LocalServer.csproj", "{8603F2EA-02DB-4B0D-B65C-B2B436F456DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.NET.Device", "Bodk.NET.Device\Bodk.NET.Device.csproj", "{C31BB5C0-BA31-4283-9FC4-CD3626B95A2F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bodk.NET.Customer", "Bodk.NET.Customer\Bodk.NET.Customer.csproj", "{E00395A2-E491-4788-8C51-58761D705192}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -112,6 +124,26 @@ Global {0273F0C6-A22B-494D-AA0B-30628C537FEA}.Debug|Any CPU.Build.0 = Debug|Any CPU {0273F0C6-A22B-494D-AA0B-30628C537FEA}.Release|Any CPU.ActiveCfg = Release|Any CPU {0273F0C6-A22B-494D-AA0B-30628C537FEA}.Release|Any CPU.Build.0 = Release|Any CPU + {CE8BF7BE-451F-4421-9C0C-346FC13EBC94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE8BF7BE-451F-4421-9C0C-346FC13EBC94}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE8BF7BE-451F-4421-9C0C-346FC13EBC94}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE8BF7BE-451F-4421-9C0C-346FC13EBC94}.Release|Any CPU.Build.0 = Release|Any CPU + {3964C5ED-A766-4FEB-987A-EC54EADFFAA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3964C5ED-A766-4FEB-987A-EC54EADFFAA0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3964C5ED-A766-4FEB-987A-EC54EADFFAA0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3964C5ED-A766-4FEB-987A-EC54EADFFAA0}.Release|Any CPU.Build.0 = Release|Any CPU + {8603F2EA-02DB-4B0D-B65C-B2B436F456DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8603F2EA-02DB-4B0D-B65C-B2B436F456DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8603F2EA-02DB-4B0D-B65C-B2B436F456DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8603F2EA-02DB-4B0D-B65C-B2B436F456DD}.Release|Any CPU.Build.0 = Release|Any CPU + {C31BB5C0-BA31-4283-9FC4-CD3626B95A2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C31BB5C0-BA31-4283-9FC4-CD3626B95A2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C31BB5C0-BA31-4283-9FC4-CD3626B95A2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C31BB5C0-BA31-4283-9FC4-CD3626B95A2F}.Release|Any CPU.Build.0 = Release|Any CPU + {E00395A2-E491-4788-8C51-58761D705192}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E00395A2-E491-4788-8C51-58761D705192}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E00395A2-E491-4788-8C51-58761D705192}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E00395A2-E491-4788-8C51-58761D705192}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -119,6 +151,11 @@ Global GlobalSection(NestedProjects) = preSolution {C4A288D5-0FAA-4F43-9072-B97635D7871D} = {76F70D22-8D53-468E-A3B6-1704666A1D71} {48EFC3A6-BDC0-4D05-819A-B1FB927FA4C8} = {76F70D22-8D53-468E-A3B6-1704666A1D71} + {CE8BF7BE-451F-4421-9C0C-346FC13EBC94} = {1B5D6CD4-1BAD-4F3C-9476-24376811BB56} + {3964C5ED-A766-4FEB-987A-EC54EADFFAA0} = {1B5D6CD4-1BAD-4F3C-9476-24376811BB56} + {8603F2EA-02DB-4B0D-B65C-B2B436F456DD} = {1B5D6CD4-1BAD-4F3C-9476-24376811BB56} + {C31BB5C0-BA31-4283-9FC4-CD3626B95A2F} = {1B5D6CD4-1BAD-4F3C-9476-24376811BB56} + {E00395A2-E491-4788-8C51-58761D705192} = {1B5D6CD4-1BAD-4F3C-9476-24376811BB56} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5CD801D7-984A-4F5C-8FA2-211B7A5EA9F3} diff --git a/Admin.NET.sln.DotSettings b/Admin.NET.sln.DotSettings new file mode 100644 index 0000000..d3bdcf1 --- /dev/null +++ b/Admin.NET.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/Bodk.NET.Core/Bodk.NET.Core.csproj b/Bodk.NET.Core/Bodk.NET.Core.csproj new file mode 100644 index 0000000..619669c --- /dev/null +++ b/Bodk.NET.Core/Bodk.NET.Core.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Bodk.NET.Customer/Bodk.NET.Customer.csproj b/Bodk.NET.Customer/Bodk.NET.Customer.csproj new file mode 100644 index 0000000..619669c --- /dev/null +++ b/Bodk.NET.Customer/Bodk.NET.Customer.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Bodk.NET.Customer/Entities/BodkCustomer.cs b/Bodk.NET.Customer/Entities/BodkCustomer.cs new file mode 100644 index 0000000..e1b18f5 --- /dev/null +++ b/Bodk.NET.Customer/Entities/BodkCustomer.cs @@ -0,0 +1,31 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using Admin.NET.Core; +using SqlSugar; + +namespace Bodk.NET.Customer.Entities; + +[SugarTable("bodk_base_customer", "客户表")] +public class BodkCustomer : EntityBase +{ + [SugarColumn(IsNullable = false, ColumnDescription = "客户名称")] + public virtual string Name { get; set; } + + [SugarColumn(IsNullable = false, ColumnDescription = "身份证号码")] + public virtual string IdCard { get; set; } + + [SugarColumn(IsNullable = false, ColumnDescription = "手机号码")] + public virtual string Phone { get; set; } + + [SugarColumn(IsNullable = false, ColumnDescription = "性别")] + public virtual bool IsMale { get; set; } + + [SugarColumn(IsJson = true, ColumnDescription = "客户从属的机构列表", IsNullable = true)] + public virtual List? OrgIds { get; set; } + + [SugarColumn(IsNullable = true)] public string? ImageUrl { get; set; } + + [SugarColumn(IsNullable = true)] public string? VoiceUrl { get; set; } +} \ No newline at end of file diff --git a/Bodk.NET.Customer/Models/Customer.cs b/Bodk.NET.Customer/Models/Customer.cs new file mode 100644 index 0000000..73096d5 --- /dev/null +++ b/Bodk.NET.Customer/Models/Customer.cs @@ -0,0 +1,85 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using System.ComponentModel.DataAnnotations; +using Admin.NET.Core; +using Bodk.NET.Customer.Entities; + +namespace Bodk.NET.Customer.Models; + +/// +/// 新增客户ID入参 +/// +public class AddCustomerInput : BodkCustomer +{ + private new long Id { get; set; } + + /// + /// 客户姓名 + /// + [Required(ErrorMessage = "客户姓名不能为空")] + public override string Name { get; set; } + + /// + /// 客户身份证号 + /// + [Required(ErrorMessage = "客户身份证号不能为空")] + public override string IdCard { get; set; } + + /// + /// 客户性别 + /// + [Required(ErrorMessage = "客户性别不能为空")] + public override bool IsMale { get; set; } + + /// + /// 客户手机号 + /// + [Required(ErrorMessage = "客户手机号不能为空")] + public override string Phone { get; set; } +} + +/// +/// 更新客户ID入参 +/// +public class UpdateCustomerInput : BodkCustomer +{ + /// + /// 客户Id + /// + [Required(ErrorMessage = "客户Id不能为空")] + public override long Id { get; set; } +} + +/// +/// 分页获取客户列表入参 +/// +public class PageCustomerInput : BasePageInput +{ + /// + /// 组织机构Id列表 + /// + public long[]? OrgIds { get; set; } +} + +/// +/// 查询单个客户入参 +/// +public class SingleCustomerInput +{ + /// + /// 名称 + /// + public string? Name { get; set; } + + /// + /// 身份证号 + /// + public string? IdCard { get; set; } + + /// + /// 手机号 + /// + public string? Phone { get; set; } +} \ No newline at end of file diff --git a/Bodk.NET.Customer/Services/CustomerService.cs b/Bodk.NET.Customer/Services/CustomerService.cs new file mode 100644 index 0000000..1c491c7 --- /dev/null +++ b/Bodk.NET.Customer/Services/CustomerService.cs @@ -0,0 +1,86 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +using System.ComponentModel; +using Admin.NET.Core; +using Bodk.NET.Customer.Entities; +using Bodk.NET.Customer.Models; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Furion.FriendlyException; +using Mapster; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Bodk.NET.Customer.Services; + +/// +/// 客户接口控制器 +/// +[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Customer", Description = "客户接口")] +public class CustomerService(SqlSugarRepository repository) : IDynamicApiController, ITransient +{ + /// + /// 新增客户 + /// + /// + [ApiDescriptionSettings(Name = "Add"), HttpPost] + [DisplayName("Add")] + [Authorize(AuthenticationSchemes = + JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + public async Task AddCustomer(AddCustomerInput input) + { + var entity = input.Adapt(); + bool exist = await CheckCustomerExist(entity); + if (exist) + throw Oops.Oh("该用户已存在"); + return await repository.InsertReturnSnowflakeIdAsync(entity); + } + + /// + /// 更新客户 + /// + /// + [ApiDescriptionSettings(Name = "Update"), HttpPost] + [DisplayName("Update")] + [Authorize(AuthenticationSchemes = + JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + public async Task UpdateCustomer(UpdateCustomerInput input) + { + var entity = input.Adapt(); + bool exist = await CheckCustomerExist(input.Id); + if (!exist) + throw Oops.Oh("该用户不存在"); + await repository.UpdateAsync(entity); + } + + /// + /// 获取客户列表 + /// + /// + [ApiDescriptionSettings(Name = "Update"), HttpPost] + [DisplayName("Update")] + [Authorize(AuthenticationSchemes = + JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] + public async Task PageCustomer(UpdateCustomerInput input) + { + var entity = input.Adapt(); + bool exist = await CheckCustomerExist(input.Id); + if (!exist) + throw Oops.Oh("该用户不存在"); + await repository.UpdateAsync(entity); + } + + private async Task CheckCustomerExist(BodkCustomer entity) + { + return await repository.AsQueryable().AnyAsync(u => u.IdCard == entity.IdCard) + || await repository.AsQueryable().AnyAsync(u => u.Phone == entity.Phone); + } + + private Task CheckCustomerExist(long id) + { + return repository.AsQueryable().AnyAsync(u => u.Id == id); + } +} \ No newline at end of file diff --git a/Bodk.NET.Device/Bodk.NET.Device.csproj b/Bodk.NET.Device/Bodk.NET.Device.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/Bodk.NET.Device/Bodk.NET.Device.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Bodk.NET.LocalServer/Bodk.NET.LocalServer.csproj b/Bodk.NET.LocalServer/Bodk.NET.LocalServer.csproj new file mode 100644 index 0000000..619669c --- /dev/null +++ b/Bodk.NET.LocalServer/Bodk.NET.LocalServer.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Bodk.NET.Project/Bodk.NET.Project.csproj b/Bodk.NET.Project/Bodk.NET.Project.csproj new file mode 100644 index 0000000..fe947e6 --- /dev/null +++ b/Bodk.NET.Project/Bodk.NET.Project.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + obj\Debug\Bodk.NET.Project.xml + + + + + + + + + + + +