초기커밋
This commit is contained in:
289
ServerCommon/Entity/Attribute/SystemMetaMailAttribute.cs
Normal file
289
ServerCommon/Entity/Attribute/SystemMetaMailAttribute.cs
Normal file
@@ -0,0 +1,289 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
|
||||
|
||||
using MAIL_GUID = System.String;
|
||||
using USER_GUID = System.String;
|
||||
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
|
||||
public class SystemMetaMailAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty("mail_id")]
|
||||
public Int32 MailId { get; set; } = 0;
|
||||
|
||||
[JsonProperty("sender_nickname")]
|
||||
public List<OperationSystemMessage> SenderNickName { get; set; } = new();
|
||||
|
||||
[JsonProperty("title")]
|
||||
public List<OperationSystemMessage> Title { get; set; } = new();
|
||||
|
||||
[JsonProperty("text")]
|
||||
public List<OperationSystemMessage> Text { get; set; } = new();
|
||||
|
||||
[JsonProperty("start_time")]
|
||||
public DateTime StartTime { get; set; } = new();
|
||||
|
||||
[JsonProperty("end_time")]
|
||||
public DateTime EndTime { get; set; } = new();
|
||||
|
||||
[JsonProperty("item_list")]
|
||||
public List<MailItem> ItemList { get; set; } = new();
|
||||
|
||||
|
||||
public SystemMetaMailAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
MailId = 0;
|
||||
SenderNickName = new();
|
||||
Title = new();
|
||||
Text = new();
|
||||
StartTime = new();
|
||||
EndTime = new();
|
||||
ItemList = new List<MailItem>();
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new SystemMailAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new SystemMetaMailAttribute(getOwner());
|
||||
cloned.MailId = MailId;
|
||||
cloned.SenderNickName = SenderNickName;
|
||||
cloned.Title = Title;
|
||||
cloned.Text = Text;
|
||||
cloned.StartTime = StartTime;
|
||||
cloned.EndTime = EndTime;
|
||||
cloned.ItemList = ItemList.Select(x => new MailItem() { ItemId = x.ItemId, Count = x.Count }).ToList();
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var result = new Result();
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as SystemMetaMailDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new SystemMetaMailDoc(MailId.ToString());
|
||||
|
||||
var origin_doc = getOriginDocBase<SystemMetaMailAttribute>();
|
||||
if (null != origin_doc)
|
||||
{
|
||||
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
try_pending_doc = to_copy_doc;
|
||||
|
||||
setTryPendingDocBase(try_pending_doc);
|
||||
}
|
||||
|
||||
var system_meta_mail_attrib = try_pending_doc.getAttrib<SystemMetaMailAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(system_meta_mail_attrib, () => $"system_meta_mail_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
system_meta_mail_attrib.MailId = MailId;
|
||||
system_meta_mail_attrib.SenderNickName = SenderNickName;
|
||||
system_meta_mail_attrib.Title = Title;
|
||||
system_meta_mail_attrib.Text = Text;
|
||||
system_meta_mail_attrib.StartTime = StartTime;
|
||||
system_meta_mail_attrib.EndTime = EndTime;
|
||||
system_meta_mail_attrib.ItemList = ItemList.Select(x => new MailItem() { ItemId = x.ItemId, Count = x.Count }).ToList();
|
||||
|
||||
if (false == isForQuery)
|
||||
{
|
||||
return (result, try_pending_doc);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Doc QueryType 반영
|
||||
//=====================================================================================
|
||||
(result, var to_query_doc) = await applyDoc4Query(try_pending_doc);
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, to_query_doc);
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(SystemMetaMailDoc).Name;
|
||||
|
||||
var system_meta_mail_doc = docBase as SystemMetaMailDoc;
|
||||
if (null == system_meta_mail_doc)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, system_meta_mail_doc is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<SystemMetaMailAttribute>(system_meta_mail_doc);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var system_meta_mail_attrib = system_meta_mail_doc.getAttrib<SystemMetaMailAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(system_meta_mail_attrib, () => $"system_meta_mail_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
if (system_meta_mail_attrib == null)
|
||||
{
|
||||
err_msg = $"Failed to get system mail attrib : {nameof(SystemMetaMailAttrib)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
MailId = system_meta_mail_attrib.MailId;
|
||||
SenderNickName = system_meta_mail_attrib.SenderNickName;
|
||||
Title = system_meta_mail_attrib.Title;
|
||||
Text = system_meta_mail_attrib.Text;
|
||||
StartTime = system_meta_mail_attrib.StartTime;
|
||||
EndTime = system_meta_mail_attrib.EndTime;
|
||||
ItemList = system_meta_mail_attrib.ItemList.Select(x => new MailItem() { ItemId = x.ItemId, Count = x.Count }).ToList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
||||
{
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (null == otherEntityAttribute)
|
||||
{
|
||||
err_msg = $"Invalid Param !!!, otherEntityAttribute is null";
|
||||
result.setFail(ServerErrorCode.FunctionParamNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// OtherAttribute => Attribute
|
||||
//=====================================================================================
|
||||
var system_mail_attribute = otherEntityAttribute as SystemMetaMailAttribute;
|
||||
if (null == system_mail_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast SystemMailAttribute !!!, system_mail_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
MailId = MailId;
|
||||
SenderNickName = system_mail_attribute.SenderNickName;
|
||||
Title = system_mail_attribute.Title;
|
||||
Text = system_mail_attribute.Text;
|
||||
StartTime = system_mail_attribute.StartTime;
|
||||
EndTime = system_mail_attribute.EndTime;
|
||||
ItemList = system_mail_attribute.ItemList.Select(x => new MailItem() { ItemId = x.ItemId, Count = x.Count }).ToList();
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = system_mail_attribute.getTryPendingDocBase() as SystemMetaMailDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
system_mail_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<SystemMetaMailAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<SystemMetaMailAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var system_meta_mail_attrib = origin_doc_base.getAttrib<SystemMetaMailAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(system_meta_mail_attrib, () => $"system_meta_mail_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
system_meta_mail_attrib.MailId = MailId;
|
||||
system_meta_mail_attrib.SenderNickName = SenderNickName;
|
||||
system_meta_mail_attrib.Title = Title;
|
||||
system_meta_mail_attrib.Text = Text;
|
||||
system_meta_mail_attrib.StartTime = StartTime;
|
||||
system_meta_mail_attrib.EndTime = EndTime;
|
||||
system_meta_mail_attrib.ItemList = ItemList.Select(x => new MailItem() { ItemId = x.ItemId, Count = x.Count }).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class SystemMailAttributeTransactor : EntityAttributeTransactorBase<SystemMetaMailAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public SystemMailAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(SystemMetaMailAttribute).Name;
|
||||
|
||||
var copy_from_system_mail_attribute = entityAttributeBase as SystemMetaMailAttribute;
|
||||
if (null == copy_from_system_mail_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_system_mail_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_system_mail_attribute = getClonedEntityAttribute() as SystemMetaMailAttribute;
|
||||
if (null == copy_to_system_mail_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_system_mail_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_system_mail_attribute.MailId = copy_from_system_mail_attribute.MailId;
|
||||
copy_to_system_mail_attribute.SenderNickName = copy_from_system_mail_attribute.SenderNickName;
|
||||
copy_to_system_mail_attribute.Title = copy_from_system_mail_attribute.Title;
|
||||
copy_to_system_mail_attribute.Text = copy_from_system_mail_attribute.Text;
|
||||
copy_to_system_mail_attribute.StartTime = copy_from_system_mail_attribute.StartTime;
|
||||
copy_to_system_mail_attribute.EndTime = copy_from_system_mail_attribute.EndTime;
|
||||
copy_to_system_mail_attribute.ItemList = copy_from_system_mail_attribute.ItemList.Select(x => new MailItem() { ItemId = x.ItemId, Count = x.Count}).ToList();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user