221 lines
8.6 KiB
C#
221 lines
8.6 KiB
C#
using Newtonsoft.Json;
|
|
using ServerCore; using ServerBase;
|
|
using USER_GUID = System.String;
|
|
using META_ID = System.UInt32;
|
|
|
|
namespace ServerCommon
|
|
{
|
|
public class AiChatAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty]
|
|
public DateTime LastIncentiveProvideTime { get; set; } = new();
|
|
|
|
public AiChatAttribute(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
LastIncentiveProvideTime = new();
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var cloned = new AiChatAttribute(getOwner());
|
|
cloned.LastIncentiveProvideTime = LastIncentiveProvideTime;
|
|
return cloned;
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new AiChatAttributeTransactor(getOwner());
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null");
|
|
|
|
var root_parent = owner.getRootParent();
|
|
NullReferenceCheckHelper.throwIfNull(root_parent, () => "root_parent is null");
|
|
|
|
var acoount_attribute = owner.getRootParent().getEntityAttribute<AccountAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(acoount_attribute, () => "acoount_attribute is null");
|
|
|
|
USER_GUID user_guid = acoount_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as AiChatDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new AiChatDoc(user_guid);
|
|
var origin_doc = getOriginDocBase<AiChatAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var ai_chat_attrib = try_pending_doc.getAttrib<AiChatAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(ai_chat_attrib, () => $"ai_chat_attrib is null !!!");
|
|
|
|
ai_chat_attrib.LastIncentiveProvideTime = LastIncentiveProvideTime;
|
|
|
|
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, to_query_doc);
|
|
}
|
|
|
|
return (result, to_query_doc);
|
|
}
|
|
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(AiChatDoc).Name;
|
|
|
|
var ai_chat_doc_base = docBase as AiChatDoc;
|
|
if (null == ai_chat_doc_base)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, ai_chat_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<AiChatAttribute>(ai_chat_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Doc, Attribute
|
|
//=====================================================================================
|
|
var ai_chat_attrib = ai_chat_doc_base.getAttrib<AiChatAttrib>();
|
|
if (ai_chat_attrib == null)
|
|
{
|
|
err_msg = $"Failed to get ai chat attrib : {nameof(AiChatAttrib)}";
|
|
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
LastIncentiveProvideTime = ai_chat_attrib.LastIncentiveProvideTime;
|
|
|
|
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 ai_chat_attribute = otherEntityAttribute as AiChatAttribute;
|
|
if (null == ai_chat_attribute)
|
|
{
|
|
err_msg = $"Failed to cast Attribute !!!, ai_chat_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
LastIncentiveProvideTime = ai_chat_attribute.LastIncentiveProvideTime;
|
|
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = ai_chat_attribute.getTryPendingDocBase() as AiChatDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
ai_chat_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<AiChatAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<AiChatAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var ai_chat_attrib = origin_doc_base.getAttrib<AiChatAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(ai_chat_attrib, () => $"ai_chat_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
ai_chat_attrib.LastIncentiveProvideTime = LastIncentiveProvideTime;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
public class AiChatAttributeTransactor : EntityAttributeTransactorBase<AiChatAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public AiChatAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(AiChatAttribute).Name;
|
|
|
|
var copy_from_attribute = entityAttributeBase as AiChatAttribute;
|
|
if (null == copy_from_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_ai_chat_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
var copy_to_attribute = getClonedEntityAttribute() as AiChatAttribute;
|
|
if (null == copy_to_attribute)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_ai_chat_attribute is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
copy_to_attribute.LastIncentiveProvideTime = copy_from_attribute.LastIncentiveProvideTime;
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|