diff --git a/Api/Ewide.Core/Entity/SysDictData.cs b/Api/Ewide.Core/Entity/SysDictData.cs index c1ec86c..cd4d698 100644 --- a/Api/Ewide.Core/Entity/SysDictData.cs +++ b/Api/Ewide.Core/Entity/SysDictData.cs @@ -30,6 +30,9 @@ namespace Ewide.Core [Comment("编码")] public string Code { get; set; } + [Comment("扩展编码,以json形式存储")] + public string ExtCode { get; set; } + /// /// 排序 /// diff --git a/Api/Ewide.Core/Ewide.Core.xml b/Api/Ewide.Core/Ewide.Core.xml index 6d76c63..fcb21db 100644 --- a/Api/Ewide.Core/Ewide.Core.xml +++ b/Api/Ewide.Core/Ewide.Core.xml @@ -3889,6 +3889,11 @@ 编码 + + + 扩展编码 + + 排序 diff --git a/Api/Ewide.Core/Service/Dict/Dto/DictDataInput.cs b/Api/Ewide.Core/Service/Dict/Dto/DictDataInput.cs index c0b2191..fbc092b 100644 --- a/Api/Ewide.Core/Service/Dict/Dto/DictDataInput.cs +++ b/Api/Ewide.Core/Service/Dict/Dto/DictDataInput.cs @@ -23,6 +23,11 @@ namespace Ewide.Core.Service /// public virtual string Code { get; set; } + /// + /// 扩展编码 + /// + public virtual string ExtCode { get; set; } + /// /// 排序 /// diff --git a/Api/Ewide.Core/Service/Dict/SysDictDataService.cs b/Api/Ewide.Core/Service/Dict/SysDictDataService.cs index d7c7568..8e756ad 100644 --- a/Api/Ewide.Core/Service/Dict/SysDictDataService.cs +++ b/Api/Ewide.Core/Service/Dict/SysDictDataService.cs @@ -71,7 +71,10 @@ namespace Ewide.Core.Service 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("此处类型不能添加数据"); + if (string.IsNullOrEmpty(dataType.Code)) throw Oops.Oh("此处类型不能添加数据"); + + input.ExtCode = CheckExtCode(input.ExtCode); + var dictData = input.Adapt(); await _sysDictDataRep.InsertAsync(dictData); } @@ -119,6 +122,8 @@ namespace Ewide.Core.Service isExist = await _sysDictDataRep.AnyAsync(u => (u.Value == input.Value || u.Code == input.Code) && u.TypeId == input.TypeId && u.Id != input.Id, false); if (isExist) throw Oops.Oh(ErrorCode.D3003); + input.ExtCode = CheckExtCode(input.ExtCode); + var dictData = input.Adapt(); await _sysDictDataRep.UpdateAsync(dictData, ignoreNullValues: true); } @@ -159,13 +164,14 @@ namespace Ewide.Core.Service public async Task GetDictDataListByDictTypeId(string dictTypeId) { return await _sysDictDataRep.DetachedEntities.Where(u => u.SysDictType.Id == dictTypeId) - .Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort) - .Select(u => new - { - u.Code, - u.Value, - u.Remark - }).ToListAsync(); + .Where(u => u.Status != CommonStatus.DELETED).OrderBy(u => u.Sort) + .Select(u => new + { + u.Code, + u.Value, + ExtCode = String.IsNullOrEmpty(u.ExtCode) ? null : Newtonsoft.Json.JsonConvert.DeserializeObject(u.ExtCode), + u.Remark + }).ToListAsync(); } [NonAction] @@ -183,6 +189,7 @@ namespace Ewide.Core.Service { u.Code, u.Value, + ExtCode = String.IsNullOrEmpty(u.ExtCode) ? null : Newtonsoft.Json.JsonConvert.DeserializeObject(u.ExtCode), u.Remark })); } @@ -202,5 +209,23 @@ namespace Ewide.Core.Service u.Delete(); }); } + + [NonAction] + private string CheckExtCode(string extCode) + { + if (!string.IsNullOrEmpty(extCode)) + { + try + { + if (extCode.StartsWith('{') && extCode.EndsWith('}')) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(Newtonsoft.Json.JsonConvert.DeserializeObject(extCode)); + } + } + catch { } + } + + return null; + } } } diff --git a/Web/src/pages/system/dict/dictdata/index.vue b/Web/src/pages/system/dict/dictdata/index.vue index 25be091..6b2b7bb 100644 --- a/Web/src/pages/system/dict/dictdata/index.vue +++ b/Web/src/pages/system/dict/dictdata/index.vue @@ -28,6 +28,9 @@ + + +