update 字典表增加扩展字段

This commit is contained in:
2021-05-20 17:49:52 +08:00
parent 4e733db8ed
commit e7fea323bd
5 changed files with 56 additions and 8 deletions

View File

@@ -30,6 +30,9 @@ namespace Ewide.Core
[Comment("编码")]
public string Code { get; set; }
[Comment("扩展编码以json形式存储")]
public string ExtCode { get; set; }
/// <summary>
/// 排序
/// </summary>

View File

@@ -3889,6 +3889,11 @@
编码
</summary>
</member>
<member name="P:Ewide.Core.Service.DictDataInput.ExtCode">
<summary>
扩展编码
</summary>
</member>
<member name="P:Ewide.Core.Service.DictDataInput.Sort">
<summary>
排序

View File

@@ -23,6 +23,11 @@ namespace Ewide.Core.Service
/// </summary>
public virtual string Code { get; set; }
/// <summary>
/// 扩展编码
/// </summary>
public virtual string ExtCode { get; set; }
/// <summary>
/// 排序
/// </summary>

View File

@@ -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<SysDictData>();
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<SysDictData>();
await _sysDictDataRep.UpdateAsync(dictData, ignoreNullValues: true);
}
@@ -159,13 +164,14 @@ namespace Ewide.Core.Service
public async Task<dynamic> 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<object>(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<object>(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;
}
}
}