diff --git a/Admin.Bodk.Device/Services/SupportService.cs b/Admin.Bodk.Device/Services/SupportService.cs index b1ece11..0145cf6 100644 --- a/Admin.Bodk.Device/Services/SupportService.cs +++ b/Admin.Bodk.Device/Services/SupportService.cs @@ -71,8 +71,11 @@ public class SupportService : IDynamicApiController, ITransient Density = "1*10^7个/ml", Capacity = "1.8ml", Type = 1, Location = "松山湖", LastOperationTime = null, DeviceInfo = new DeviceInfo() { - DeviceId = 23223232, PicUrl = "", LiquidNitrogenHeight = cache?.LiquidHeight, Temperature = cache?.TankTopTemperature, - Humidity = $"{cache?.CavityHumidity.ToString("0.0")}%", Address = "广东省东莞市松山湖园区科技二路宏远新智汇1栋", + 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栋", Name = "M9_01", CellBaseInfo = new CellBaseInfo() { BaseName = "松山湖", BaseId = 13545 } } }); diff --git a/Admin.NET.Bodk.Cells/CellService.cs b/Admin.NET.Bodk.Cells/CellService.cs index c4b38d6..ffecf94 100644 --- a/Admin.NET.Bodk.Cells/CellService.cs +++ b/Admin.NET.Bodk.Cells/CellService.cs @@ -114,4 +114,5 @@ public class CellService : IDynamicApiController, ITransient { await _repository.DeleteByIdAsync(id); } + } \ No newline at end of file diff --git a/Admin.NET.Bodk.Customer/CustomerService.cs b/Admin.NET.Bodk.Customer/CustomerService.cs index 29bace9..b3a2f6c 100644 --- a/Admin.NET.Bodk.Customer/CustomerService.cs +++ b/Admin.NET.Bodk.Customer/CustomerService.cs @@ -70,7 +70,9 @@ public class CustomerService( IsDelete = u.IsDelete, CreateUserId = u.CreateUserId, UpdateUserId = u.UpdateUserId, - UpdateUserName = u.UpdateUserName + UpdateUserName = u.UpdateUserName, + VoiceUrl = u.VoiceUrl, + ImageUrl = u.ImageUrl }) .ToPagedListAsync(input.Page, input.PageSize); } diff --git a/Admin.NET.Bodk.Device/Controllers/DeviceController.cs b/Admin.NET.Bodk.Device/Controllers/DeviceController.cs index f0f703a..ac5315b 100644 --- a/Admin.NET.Bodk.Device/Controllers/DeviceController.cs +++ b/Admin.NET.Bodk.Device/Controllers/DeviceController.cs @@ -14,7 +14,7 @@ using NewLife.Caching; namespace Admin.NET.Bodk.Device.Controllers; -[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" },Name = "DeviceOld",Description = "设备接口服务")] +[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" },Name = "Device",Description = "设备接口服务")] public class DeviceController : IDynamicApiController, ITransient { private readonly ICache _cache; diff --git a/Admin.NET.Bodk.Device/DeviceService.cs b/Admin.NET.Bodk.Device/DeviceService.cs index 559cf18..44054ce 100644 --- a/Admin.NET.Bodk.Device/DeviceService.cs +++ b/Admin.NET.Bodk.Device/DeviceService.cs @@ -25,55 +25,55 @@ public class DeviceService( ICache cache) : ServiceBase(userManager, sysOrgService, sysUserService), ITransient { - [ApiDescriptionSettings(Name = "Page"), HttpPost] - [DisplayName("获取设备分页列表")] - public async Task> Page(DeviceQueryInput queryInput) - { - var queryable = await GetDataOutOfOrg(repository.AsQueryable()); - return await queryable.WhereIF(!string.IsNullOrWhiteSpace(queryInput.SerialNumber), - u => queryInput.SerialNumber != null && u.SerialNumber.Contains(queryInput.SerialNumber)) - .WhereIF(!string.IsNullOrWhiteSpace(queryInput.Name), - u => queryInput.Name != null && u.Name.Contains(queryInput.Name)) - .WhereIF(!string.IsNullOrWhiteSpace(queryInput.Name), - u => queryInput.Name != null && u.Name.Contains(queryInput.Name)) - .WhereIF(queryInput.Id is not null, u => u.Id == queryInput.Id) - .WhereIF(queryInput.DeviceType is not null, u => u.DeviceType == queryInput.DeviceType) - .Select(u => u.Adapt()) - .Mapper(u => u.Online = cache.Get($"bodk:device:{u.SerialNumber}:summary:online")) - .WhereIF(queryInput.Online is not null, u => u.Online == queryInput.Online) - .ToPagedListAsync(queryInput.Page, queryInput.PageSize); - } - - [ApiDescriptionSettings(Name = "Add"), HttpPost] - [DisplayName("新增设备")] - public async Task AddDevice(AddDeviceInput input) - { - var isExist = await repository.AsQueryable().AnyAsync(u => u.SerialNumber == input.SerialNumber); - if (isExist) throw Oops.Oh(ErrorCodeEnum.Device1000); - var entity = input.Adapt(); - entity.OrgId = UserManager.OrgId; - return await repository.InsertReturnBigIdentityAsync(entity); - } - - [ApiDescriptionSettings(Name = "Update"), HttpPost] - [DisplayName("更新设备")] - public async Task UpdateDevice(UpdateDeviceInput input) - { - var isExist = await repository.AsQueryable().AnyAsync(u => u.Id == input.Id); - if (!isExist) throw Oops.Oh("要更新的设备不存在"); - var entity = await repository.GetByIdAsync(input.Id); - entity.DeviceType = input.DeviceType ?? entity.DeviceType; - entity.Name = input.Name ?? entity.Name; - entity.OrgId = input.OrgId ?? entity.OrgId; - await repository.UpdateAsync(entity); - } - - [ApiDescriptionSettings(Name = "Delete"), HttpPost] - [DisplayName("删除设备")] - public async Task DeleteDevice(long id) - { - var isExist = await repository.AsQueryable().AnyAsync(u => u.Id == id); - if (!isExist) throw Oops.Oh("要删除的设备不存在"); - await repository.DeleteByIdAsync(id); - } + // [ApiDescriptionSettings(Name = "Page"), HttpPost] + // [DisplayName("获取设备分页列表")] + // public async Task> Page(DeviceQueryInput queryInput) + // { + // var queryable = await GetDataOutOfOrg(repository.AsQueryable()); + // return await queryable.WhereIF(!string.IsNullOrWhiteSpace(queryInput.SerialNumber), + // u => queryInput.SerialNumber != null && u.SerialNumber.Contains(queryInput.SerialNumber)) + // .WhereIF(!string.IsNullOrWhiteSpace(queryInput.Name), + // u => queryInput.Name != null && u.Name.Contains(queryInput.Name)) + // .WhereIF(!string.IsNullOrWhiteSpace(queryInput.Name), + // u => queryInput.Name != null && u.Name.Contains(queryInput.Name)) + // .WhereIF(queryInput.Id is not null, u => u.Id == queryInput.Id) + // .WhereIF(queryInput.DeviceType is not null, u => u.DeviceType == queryInput.DeviceType) + // .Select(u => u.Adapt()) + // .Mapper(u => u.Online = cache.Get($"bodk:device:{u.SerialNumber}:summary:online")) + // .WhereIF(queryInput.Online is not null, u => u.Online == queryInput.Online) + // .ToPagedListAsync(queryInput.Page, queryInput.PageSize); + // } + // + // [ApiDescriptionSettings(Name = "Add"), HttpPost] + // [DisplayName("新增设备")] + // public async Task AddDevice(AddDeviceInput input) + // { + // var isExist = await repository.AsQueryable().AnyAsync(u => u.SerialNumber == input.SerialNumber); + // if (isExist) throw Oops.Oh(ErrorCodeEnum.Device1000); + // var entity = input.Adapt(); + // entity.OrgId = UserManager.OrgId; + // return await repository.InsertReturnBigIdentityAsync(entity); + // } + // + // [ApiDescriptionSettings(Name = "Update"), HttpPost] + // [DisplayName("更新设备")] + // public async Task UpdateDevice(UpdateDeviceInput input) + // { + // var isExist = await repository.AsQueryable().AnyAsync(u => u.Id == input.Id); + // if (!isExist) throw Oops.Oh("要更新的设备不存在"); + // var entity = await repository.GetByIdAsync(input.Id); + // entity.DeviceType = input.DeviceType ?? entity.DeviceType; + // entity.Name = input.Name ?? entity.Name; + // entity.OrgId = input.OrgId ?? entity.OrgId; + // await repository.UpdateAsync(entity); + // } + // + // [ApiDescriptionSettings(Name = "Delete"), HttpPost] + // [DisplayName("删除设备")] + // public async Task DeleteDevice(long id) + // { + // var isExist = await repository.AsQueryable().AnyAsync(u => u.Id == id); + // if (!isExist) throw Oops.Oh("要删除的设备不存在"); + // await repository.DeleteByIdAsync(id); + // } } \ No newline at end of file diff --git a/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs b/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs index af9c8b9..2713095 100644 --- a/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs +++ b/Admin.NET.Bodk.Genetic/Entities/GeneticTestResultEntity.cs @@ -12,17 +12,22 @@ public class GeneticTestResultEntity : EntityBase { public long CustomerId { get; set; } - public string Code { get; set; } + [SugarColumn(IsNullable = true)] + public string? Code { get; set; } - public string TestType { get; set; } + [SugarColumn(IsNullable = true)] + public string? TestType { get; set; } public string Barcode { get; set; } - public GeneticTestStatus Status { get; set; } + [SugarColumn(IsNullable = true)] + public GeneticTestStatus? Status { get; set; } - public DateTime GenerationTime { get; set; } + [SugarColumn(IsNullable = true)] + public DateTime? GenerationTime { get; set; } - public DateTime CollectionTime { get; set; } + [SugarColumn(IsNullable = true)] + public DateTime? CollectionTime { get; set; } } public enum GeneticTestStatus diff --git a/Admin.NET.Bodk.Genetic/GeneticTestService.cs b/Admin.NET.Bodk.Genetic/GeneticTestService.cs index fcea783..2a86272 100644 --- a/Admin.NET.Bodk.Genetic/GeneticTestService.cs +++ b/Admin.NET.Bodk.Genetic/GeneticTestService.cs @@ -143,7 +143,7 @@ public class GeneticTestService : IDynamicApiController, ITransient AverageRiskScore = i.AverageRiskScore, Genetics = i.Genetics, Growth = i.Growth, - GeneticTestResultId =input.Id + GeneticTestResultId = input.Id }).ToArray()); } } @@ -156,4 +156,18 @@ public class GeneticTestService : IDynamicApiController, ITransient await _resultRepository.DeleteByIdAsync(id); await _itemRepository.DeleteAsync(i => i.GeneticTestResultId == id); } + + [ApiDescriptionSettings(Name = "Bind"), HttpPost] + [DisplayName("Bind")] + 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 new file mode 100644 index 0000000..f36e83c --- /dev/null +++ b/Admin.NET.Bodk.Genetic/Models/BindGeneticTestBarcode.cs @@ -0,0 +1,12 @@ +// 大名科技(天津)有限公司版权所有 电话: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.Project/ProjectService.cs b/Admin.NET.Bodk.Project/ProjectService.cs index fa3f76f..a62d37c 100644 --- a/Admin.NET.Bodk.Project/ProjectService.cs +++ b/Admin.NET.Bodk.Project/ProjectService.cs @@ -5,9 +5,11 @@ using Admin.NET.Bodk.Core; using Admin.NET.Core; using Admin.NET.Core.Service; +using Microsoft.AspNetCore.Mvc; namespace Admin.NET.Bodk.Project; +[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Project", Description = "项目服务列表")] public class ProjectService(UserManager userManager, SysOrgService sysOrgService, SysUserService sysUserService) : ServiceBase(userManager, sysOrgService, sysUserService) { diff --git a/Admin.NET.Core/Entity/SysOrg.cs b/Admin.NET.Core/Entity/SysOrg.cs index 174dfca..c752b03 100644 --- a/Admin.NET.Core/Entity/SysOrg.cs +++ b/Admin.NET.Core/Entity/SysOrg.cs @@ -91,4 +91,11 @@ public class SysOrg : EntityTenant /// [SugarColumn(IsIgnore = true)] public bool Disabled { get; set; } + + [SugarColumn(IsNullable = true, ColumnDataType = "TEXT")] + public string? Position { get; set; } + + [SugarColumn(IsArray = true)] public long[]? ServiceIds { get; set; } + + [SugarColumn(IsIgnore = true)] public List? Services { get; set; } } \ No newline at end of file diff --git a/Admin.NET.Core/Entity/SysStationService.cs b/Admin.NET.Core/Entity/SysStationService.cs new file mode 100644 index 0000000..d481361 --- /dev/null +++ b/Admin.NET.Core/Entity/SysStationService.cs @@ -0,0 +1,15 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core; + +[SysTable] +public class SysStationService : EntityBase +{ + public string Name { get; set; } + + public string Icon { get; set; } + + public string Description { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Core/Service/Org/Dto/Area.cs b/Admin.NET.Core/Service/Org/Dto/Area.cs new file mode 100644 index 0000000..94e72e7 --- /dev/null +++ b/Admin.NET.Core/Service/Org/Dto/Area.cs @@ -0,0 +1,25 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core.Service; + +public class AreaOutput:SysOrg +{ + public List? Factories { get; set; } +} + +public class AddAreaInput +{ + public long Pid { get; set; } + + public string Name { get; set; } + + public string Code { get; set; } + + public long DirectorId { get; set; } + + public string? Remark { get; set; } + + +} \ No newline at end of file diff --git a/Admin.NET.Core/Service/Org/Dto/Factory.cs b/Admin.NET.Core/Service/Org/Dto/Factory.cs new file mode 100644 index 0000000..5fb26c3 --- /dev/null +++ b/Admin.NET.Core/Service/Org/Dto/Factory.cs @@ -0,0 +1,15 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core.Service; + +public class FactoryOutput : SysOrg +{ + public List Stations { get; set; } +} + +public class AddFactoryInput : AddAreaInput +{ + public string Position { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Core/Service/Org/Dto/Station.cs b/Admin.NET.Core/Service/Org/Dto/Station.cs new file mode 100644 index 0000000..d572d41 --- /dev/null +++ b/Admin.NET.Core/Service/Org/Dto/Station.cs @@ -0,0 +1,14 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core.Service; + +public class StationOutput : SysOrg +{ +} + +public class AddStationInput : AddAreaInput +{ + public List? Services { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Core/Service/Org/Dto/StationService.cs b/Admin.NET.Core/Service/Org/Dto/StationService.cs new file mode 100644 index 0000000..b4cf6ab --- /dev/null +++ b/Admin.NET.Core/Service/Org/Dto/StationService.cs @@ -0,0 +1,10 @@ +// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995 +// +// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证 + +namespace Admin.NET.Core.Service; + +public class StationServiceInput +{ + public long Id { get; set; } +} \ No newline at end of file diff --git a/Admin.NET.Core/Service/Org/SysOrgService.cs b/Admin.NET.Core/Service/Org/SysOrgService.cs index d418f7e..d870377 100644 --- a/Admin.NET.Core/Service/Org/SysOrgService.cs +++ b/Admin.NET.Core/Service/Org/SysOrgService.cs @@ -1,4 +1,3 @@ - namespace Admin.NET.Core.Service; /// @@ -42,7 +41,8 @@ public class SysOrgService : IDynamicApiController, ITransient var iSugarQueryable = _sysOrgRep.AsQueryable().OrderBy(u => u.OrderNo); // 带条件筛选时返回列表数据 - if (!string.IsNullOrWhiteSpace(input.Name) || !string.IsNullOrWhiteSpace(input.Code) || !string.IsNullOrWhiteSpace(input.Type)) + if (!string.IsNullOrWhiteSpace(input.Name) || !string.IsNullOrWhiteSpace(input.Code) || + !string.IsNullOrWhiteSpace(input.Type)) { return await iSugarQueryable.WhereIF(userOrgIdList.Count > 0, u => userOrgIdList.Contains(u.Id)) .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) @@ -58,7 +58,8 @@ public class SysOrgService : IDynamicApiController, ITransient } else { - orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, userOrgIdList.Select(d => (object)d).ToArray()); + orgTree = await iSugarQueryable.ToTreeAsync(u => u.Children, u => u.Pid, input.Id, + userOrgIdList.Select(d => (object)d).ToArray()); // 递归禁用没权限的机构(防止用户修改或创建无权的机构和用户) HandlerOrgTree(orgTree, userOrgIdList); } @@ -69,6 +70,7 @@ public class SysOrgService : IDynamicApiController, ITransient sysOrg.Children = orgTree; orgTree = new List { sysOrg }; } + return orgTree; } @@ -148,6 +150,7 @@ public class SysOrgService : IDynamicApiController, ITransient DeleteAllUserOrgCache(sysOrg.Id, input.Pid); } } + if (input.Id == input.Pid) throw Oops.Oh(ErrorCodeEnum.D2001); @@ -246,14 +249,17 @@ public class SysOrgService : IDynamicApiController, ITransient var userId = long.Parse(userOrgKey.Substring(CacheConst.KeyUserOrg)); if (userOrgs.Contains(orgId) || userOrgs.Contains(orgPid)) { - SqlSugarFilter.DeleteUserOrgCache(userId, _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); + SqlSugarFilter.DeleteUserOrgCache(userId, + _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); } + if (orgPid == 0) { var dataScope = _sysCacheService.Get($"{CacheConst.KeyRoleMaxDataScope}{userId}"); if (dataScope == (int)DataScopeEnum.All) { - SqlSugarFilter.DeleteUserOrgCache(userId, _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); + SqlSugarFilter.DeleteUserOrgCache(userId, + _sysOrgRep.Context.CurrentConnectionConfig.ConfigId.ToString()); } } } @@ -275,7 +281,8 @@ public class SysOrgService : IDynamicApiController, ITransient if (orgIdList == null || orgIdList.Count < 1) { // 本人创建机构集合 - var orgList0 = await _sysOrgRep.AsQueryable().Where(u => u.CreateUserId == userId).Select(u => u.Id).ToListAsync(); + var orgList0 = await _sysOrgRep.AsQueryable().Where(u => u.CreateUserId == userId).Select(u => u.Id) + .ToListAsync(); // 扩展机构集合 var orgList1 = await _sysUserExtOrgService.GetUserExtOrgList(userId); // 角色机构集合 @@ -287,6 +294,7 @@ public class SysOrgService : IDynamicApiController, ITransient orgIdList.Add(_userManager.OrgId); _sysCacheService.Set($"{CacheConst.KeyUserOrg}{userId}", orgIdList, TimeSpan.FromDays(7)); // 存缓存 } + return orgIdList; } @@ -340,7 +348,8 @@ public class SysOrgService : IDynamicApiController, ITransient } // 缓存当前用户最大角色数据范围 - _sysCacheService.Set(CacheConst.KeyRoleMaxDataScope + _userManager.UserId, strongerDataScopeType, TimeSpan.FromDays(7)); + _sysCacheService.Set(CacheConst.KeyRoleMaxDataScope + _userManager.UserId, strongerDataScopeType, + TimeSpan.FromDays(7)); // 根据角色集合获取机构集合 var roleOrgIdList = await _sysRoleOrgService.GetRoleOrgIdList(customDataScopeRoleIdList); @@ -373,6 +382,7 @@ public class SysOrgService : IDynamicApiController, ITransient { orgIdList.Add(orgId); } + return orgIdList; } @@ -387,4 +397,146 @@ 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; + } + + /// + /// 增加基地 + /// + /// + /// + [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, + }).ExecuteReturnEntityAsync(); + return newOrg.Id; + } } \ No newline at end of file diff --git a/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj b/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj index 97740f8..9ef3eaf 100644 --- a/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj +++ b/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj @@ -43,6 +43,7 @@ +