From 2b02ec496939e37ad5f0b1d605aa732367ec6502 Mon Sep 17 00:00:00 2001 From: ky_xiaz <574434302@qq.com> Date: Thu, 20 May 2021 09:12:27 +0800 Subject: [PATCH 1/2] Update dataType --- Api/Ewide.Core/Entity/SysDictType.cs | 12 +++++ Api/Ewide.Core/Ewide.Core.xml | 31 +++++++++++++ .../Service/Dict/Dto/DictTypeInput.cs | 6 ++- .../Service/Dict/SysDictDataService.cs | 25 +++++++++-- .../Service/Dict/SysDictTypeService.cs | 44 +++++++++++++++---- Api/Ewide.Core/Util/XmlSerializerUtil.cs | 4 +- 6 files changed, 107 insertions(+), 15 deletions(-) diff --git a/Api/Ewide.Core/Entity/SysDictType.cs b/Api/Ewide.Core/Entity/SysDictType.cs index 79b4434..867e5d2 100644 --- a/Api/Ewide.Core/Entity/SysDictType.cs +++ b/Api/Ewide.Core/Entity/SysDictType.cs @@ -15,6 +15,18 @@ namespace Ewide.Core [Comment("字典类型表")] public class SysDictType : DEntityBase, IEntityTypeBuilder { + /// + /// 父Id + /// + [Comment("父Id")] + [Column("Pid", TypeName = "varchar(36)")] + public string Pid { get; set; } + + /// + /// 父Ids + /// + [Comment("父Ids")] + public string Pids { get; set; } /// /// 名称 /// diff --git a/Api/Ewide.Core/Ewide.Core.xml b/Api/Ewide.Core/Ewide.Core.xml index 5275165..3da9f82 100644 --- a/Api/Ewide.Core/Ewide.Core.xml +++ b/Api/Ewide.Core/Ewide.Core.xml @@ -680,6 +680,16 @@ 字典类型表 + + + 父Id + + + + + 父Ids + + 名称 @@ -3994,6 +4004,11 @@ 状态(字典 0正常 1停用 2删除) + + + 父Id + + 名称 @@ -4056,6 +4071,13 @@ + + + 删除字典值 id数组传入 + + + + 更新字典值 @@ -4162,6 +4184,15 @@ + + + 创建Pids格式 + 如果pid是0顶级节点,pids就是 [0]; + 如果pid不是顶级节点,pids就是 pid菜单的 pids + [pid] + , + + + + 附属机构和职位参数 diff --git a/Api/Ewide.Core/Service/Dict/Dto/DictTypeInput.cs b/Api/Ewide.Core/Service/Dict/Dto/DictTypeInput.cs index 40e6366..9920495 100644 --- a/Api/Ewide.Core/Service/Dict/Dto/DictTypeInput.cs +++ b/Api/Ewide.Core/Service/Dict/Dto/DictTypeInput.cs @@ -35,6 +35,11 @@ namespace Ewide.Core.Service public class AddDictTypeInput : DictTypeInput { + + /// + /// 父Id + /// + public string Pid { get; set; } /// /// 名称 /// @@ -44,7 +49,6 @@ namespace Ewide.Core.Service /// /// 编码 /// - [Required(ErrorMessage = "字典类型编码不能为空")] public override string Code { get; set; } } diff --git a/Api/Ewide.Core/Service/Dict/SysDictDataService.cs b/Api/Ewide.Core/Service/Dict/SysDictDataService.cs index 6e9859d..a659532 100644 --- a/Api/Ewide.Core/Service/Dict/SysDictDataService.cs +++ b/Api/Ewide.Core/Service/Dict/SysDictDataService.cs @@ -21,9 +21,10 @@ namespace Ewide.Core.Service public class SysDictDataService : ISysDictDataService, IDynamicApiController, ITransient { private readonly IRepository _sysDictDataRep; // 字典类型表仓储 - - public SysDictDataService(IRepository sysDictDataRep) + private readonly IRepository _sysDictTypeRep; + public SysDictDataService(IRepository sysDictDataRep, IRepository sysDictTypeRep) { + _sysDictTypeRep = sysDictTypeRep; _sysDictDataRep = sysDictDataRep; } @@ -68,7 +69,9 @@ namespace Ewide.Core.Service { var isExist = await _sysDictDataRep.AnyAsync(u => (u.Code == input.Code || u.Value == input.Value) && u.TypeId == input.TypeId, false); if (isExist) throw Oops.Oh(ErrorCode.D3003); - + //datatype 的code 为null 则不能添加 + var dataType = _sysDictTypeRep.Where(s => s.Id == input.TypeId).FirstOrDefault(); + if (string.IsNullOrEmpty(dataType.Code)) throw new Exception("此处类型不能添加数据"); var dictData = input.Adapt(); await _sysDictDataRep.InsertAsync(dictData); } @@ -86,7 +89,21 @@ namespace Ewide.Core.Service await dictData.DeleteAsync(); } - + /// + /// 删除字典值 id数组传入 + /// + /// + /// + [HttpPost("/sysDictData/deleteBatch")] + public async Task DeleteDictDataBatch(List idList) + { + var dictDataList = await _sysDictDataRep.Where(s => idList.Contains(s.Id)).ToListAsync(); + if (dictDataList.Count == 0) throw Oops.Oh(ErrorCode.D3004); + dictDataList.ForEach(s => + { + s.DeleteAsync(); + }); + } /// /// 更新字典值 /// diff --git a/Api/Ewide.Core/Service/Dict/SysDictTypeService.cs b/Api/Ewide.Core/Service/Dict/SysDictTypeService.cs index c40da1c..5532c86 100644 --- a/Api/Ewide.Core/Service/Dict/SysDictTypeService.cs +++ b/Api/Ewide.Core/Service/Dict/SysDictTypeService.cs @@ -93,10 +93,13 @@ namespace Ewide.Core.Service [HttpPost("/sysDictType/add")] public async Task AddDictType(AddDictTypeInput input) { - var isExist = await _sysDictTypeRep.AnyAsync(u => u.Name == input.Name || u.Code == input.Code, false); + var isExist = await _sysDictTypeRep.AnyAsync(u => u.Name == input.Name, false); if (isExist) throw Oops.Oh(ErrorCode.D3001); - + var dictTypeEntity = _sysDictTypeRep.Where(s => s.Pid == input.Pid).FirstOrDefault(); + if (dictTypeEntity != null && dictTypeEntity.Code != null) throw new Exception("此类型下不能添加子类型"); var dictType = input.Adapt(); + dictType.Pids = await CreateNewPids(input.Pid); + if (input.Code == string.Empty) dictType.Code = null; await _sysDictTypeRep.InsertAsync(dictType); } @@ -125,15 +128,19 @@ namespace Ewide.Core.Service [HttpPost("/sysDictType/edit"),] public async Task UpdateDictType(UpdateDictTypeInput input) { - var isExist = await _sysDictTypeRep.AnyAsync(u => u.Id == input.Id, false); - if (!isExist) throw Oops.Oh(ErrorCode.D3000); - - // 排除自己并且判断与其他是否相同 - isExist = await _sysDictTypeRep.AnyAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id, false); - if (isExist) throw Oops.Oh(ErrorCode.D3001); + if (input.Id == input.Pid) throw Oops.Oh(ErrorCode.D4006); + var result = _sysDictTypeRep.Where(u => u.Id == input.Id).Select(s => new { s.Name, s.Id, s.Code }).ToList().First(); + if (result == null) throw Oops.Oh(ErrorCode.D3000); + if (result.Name == input.Name) throw Oops.Oh(ErrorCode.D3001); + // 如果是编辑,父id不能为自己的子节点 + //var childIdList = await _sysDictTypeRep.DetachedEntities.Where(u => u.Pids.Contains(input.Id.ToString())) + // .Select(u => u.Id).ToListAsync(); + //if (childIdList.Contains(input.Pid)) throw Oops.Oh(ErrorCode.D4006); var dictType = input.Adapt(); - await _sysDictTypeRep.UpdateAsync(dictType, ignoreNullValues: true); + dictType.Pids = await CreateNewPids(input.Pid); + dictType.Code = input.Code == string.Empty ? null : input.Code; + await dictType.UpdateIncludeAsync(new string[] { nameof(SysDictType.Pid), nameof(SysDictType.Pids), nameof(SysDictType.Name), nameof(SysDictType.Code), nameof(SysDictType.Sort), nameof(SysDictType.Remark) }, false); } /// @@ -185,5 +192,24 @@ namespace Ewide.Core.Service }).ToList() }).ToListAsync(); } + /// + /// 创建Pids格式 + /// 如果pid是0顶级节点,pids就是 [0]; + /// 如果pid不是顶级节点,pids就是 pid菜单的 pids + [pid] + , + /// + /// + /// + private async Task CreateNewPids(string pid) + { + if (pid.Equals(System.Guid.Empty.ToString())) + { + return "[" + System.Guid.Empty + "],"; + } + else + { + var dtype = await _sysDictTypeRep.DetachedEntities.FirstOrDefaultAsync(u => u.Id == pid); + return dtype.Pids + "[" + pid + "],"; + } + } } } diff --git a/Api/Ewide.Core/Util/XmlSerializerUtil.cs b/Api/Ewide.Core/Util/XmlSerializerUtil.cs index e12b8bf..d40573a 100644 --- a/Api/Ewide.Core/Util/XmlSerializerUtil.cs +++ b/Api/Ewide.Core/Util/XmlSerializerUtil.cs @@ -123,6 +123,8 @@ namespace Ewide.Core.Util { if (item.Name == currentAssemblyName) { + var queryList = item.GetDirectories().Where(s => s.Name == appConfigPath); + if (!queryList.Any()) item.CreateSubdirectory(appConfigPath); targetPath = item.GetDirectories(appConfigPath).FirstOrDefault().FullName; break; } @@ -150,7 +152,7 @@ namespace Ewide.Core.Util foreach (Type type in types) { //if (type.Name.EndsWith("SeedData")) - if(type.Name.EndsWith("SysEmpExtOrgPos")) + if (type.Name.EndsWith("SysEmpExtOrgPos")) { object obHelper = Activator.CreateInstance(type); MethodInfo methodinfo = type.GetMethod("HasData"); From 345caae2d2e5b83a1cbd2bcb5a91b4191479cd3c Mon Sep 17 00:00:00 2001 From: ky_xiaz <574434302@qq.com> Date: Thu, 20 May 2021 09:16:55 +0800 Subject: [PATCH 2/2] some little Update --- Api/Ewide.Core/Service/Dict/SysDictDataService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Api/Ewide.Core/Service/Dict/SysDictDataService.cs b/Api/Ewide.Core/Service/Dict/SysDictDataService.cs index a659532..d7c7568 100644 --- a/Api/Ewide.Core/Service/Dict/SysDictDataService.cs +++ b/Api/Ewide.Core/Service/Dict/SysDictDataService.cs @@ -92,7 +92,7 @@ namespace Ewide.Core.Service /// /// 删除字典值 id数组传入 /// - /// + /// /// [HttpPost("/sysDictData/deleteBatch")] public async Task DeleteDictDataBatch(List idList)