194 lines
6.4 KiB
C#
194 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace ServerCommon;
|
|
|
|
|
|
|
|
public class RepeatQuestAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty()]
|
|
public DateTime m_next_allocate_time { get; set; } = new();
|
|
[JsonProperty()]
|
|
public Int32 m_is_checking { get; set; } = 0; //0 : not check, 1: checking
|
|
|
|
|
|
public RepeatQuestAttribute(EntityBase owner) : base(owner)
|
|
{
|
|
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
m_next_allocate_time = new();
|
|
m_is_checking = 0;
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var result = new Result();
|
|
|
|
var repeat_quest_attribute = owner.getEntityAttribute<RepeatQuestAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(repeat_quest_attribute, () => $"repeat_quest_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
var user_attribute = owner.getRootParent().getEntityAttribute<UserAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
USER_GUID user_guid = user_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as RepeatQuestDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new RepeatQuestDoc(user_guid);
|
|
|
|
var origin_doc = getOriginDocBase<RepeatQuestAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var to_copy_repeat_quest_attrib = try_pending_doc.getAttrib<RepeatQuestAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_repeat_quest_attrib, () => $"to_copy_repeat_quest_attrib is null !!!");
|
|
|
|
to_copy_repeat_quest_attrib.m_next_allocate_time = m_next_allocate_time;
|
|
to_copy_repeat_quest_attrib.m_is_checking = m_is_checking;
|
|
|
|
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 override EntityAttributeBase onCloned()
|
|
{
|
|
var cloned = new RepeatQuestAttribute(getOwner());
|
|
cloned.deepCopyFromBase(this);
|
|
|
|
cloned.m_next_allocate_time = m_next_allocate_time;
|
|
cloned.m_is_checking = m_is_checking;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
|
{
|
|
var result = new Result();
|
|
|
|
var owner = getOwner();
|
|
ArgumentNullException.ThrowIfNull(owner);
|
|
|
|
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;
|
|
}
|
|
var other_attribute = otherEntityAttribute as RepeatQuestAttribute;
|
|
if (null == other_attribute)
|
|
{
|
|
err_msg = $"Failed to cast QuestAttribute !!!, other_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// OtherAttribute => Attribute
|
|
//=====================================================================================
|
|
m_next_allocate_time = other_attribute.m_next_allocate_time;
|
|
m_is_checking = other_attribute.m_is_checking;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = other_attribute.getTryPendingDocBase() as RepeatQuestDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
other_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<RepeatQuestAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<RepeatQuestAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var repeat_quest_attrib = origin_doc_base.getAttrib<RepeatQuestAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(repeat_quest_attrib, () => $"repeat_quest_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
repeat_quest_attrib.m_next_allocate_time = m_next_allocate_time;
|
|
repeat_quest_attrib.m_is_checking = m_is_checking;
|
|
|
|
return result;
|
|
}
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase customDoc)
|
|
{
|
|
return true;
|
|
}
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new RepeatQuestAttributeTransactor(getOwner());
|
|
}
|
|
}
|
|
|
|
public class RepeatQuestAttributeTransactor : EntityAttributeTransactorBase<RepeatQuestAttribute>
|
|
{
|
|
public RepeatQuestAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorBaseFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
//아직 미사용
|
|
Log.getLogger().info("copyEntityDbTransactBaseFromEntityAttribute call");
|
|
|
|
return true;
|
|
}
|
|
}
|