초기커밋
This commit is contained in:
235
ServerCommon/Entity/Attribute/BeaconShopProfileAttribute.cs
Normal file
235
ServerCommon/Entity/Attribute/BeaconShopProfileAttribute.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
using Newtonsoft.Json;
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
|
||||
using USER_GUID = System.String;
|
||||
using BEACON_GUID = System.String;
|
||||
|
||||
|
||||
namespace ServerCommon
|
||||
{
|
||||
public class BeaconShopProfileAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty]
|
||||
public BEACON_GUID BeaconGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public Int32 DailyRegisterCount { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime RegisterUpdateDay { get; set; } = new();
|
||||
|
||||
|
||||
public BeaconShopProfileAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
BeaconGuid = string.Empty;
|
||||
DailyRegisterCount = 0;
|
||||
RegisterUpdateDay = new();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new BeaconShopProfileAttribute(getOwner());
|
||||
cloned.BeaconGuid = BeaconGuid;
|
||||
cloned.DailyRegisterCount = DailyRegisterCount;
|
||||
cloned.RegisterUpdateDay = RegisterUpdateDay;
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new BeaconShopProfileAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as BeaconShopProfileDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new BeaconShopProfileDoc(BeaconGuid);
|
||||
|
||||
var origin_doc = getOriginDocBase<BeaconShopProfileAttribute>();
|
||||
if (null != origin_doc)
|
||||
{
|
||||
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
try_pending_doc = to_copy_doc;
|
||||
|
||||
setTryPendingDocBase(try_pending_doc);
|
||||
}
|
||||
|
||||
var to_copy_doc_attrib = try_pending_doc.getAttrib<BeaconShopProfileAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!!");
|
||||
|
||||
to_copy_doc_attrib.BeaconGuid = BeaconGuid;
|
||||
to_copy_doc_attrib.DailyRegisterCount = DailyRegisterCount;
|
||||
to_copy_doc_attrib.RegisterUpdateDay = RegisterUpdateDay;
|
||||
|
||||
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(BeaconShopProfileDoc).Name;
|
||||
|
||||
var beacon_shop_profile_doc_base = docBase as BeaconShopProfileDoc;
|
||||
if (null == beacon_shop_profile_doc_base)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, beacon_shop_profile_doc_base is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<BeaconShopProfileAttribute>(beacon_shop_profile_doc_base);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var doc_attrib = beacon_shop_profile_doc_base.getAttrib<BeaconShopProfileAttrib>();
|
||||
if (doc_attrib == null)
|
||||
{
|
||||
err_msg = $"Failed to get beacon_shop attrib : {nameof(BeaconShopProfileAttrib)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
BeaconGuid = doc_attrib.BeaconGuid;
|
||||
DailyRegisterCount = doc_attrib.DailyRegisterCount;
|
||||
RegisterUpdateDay = doc_attrib.RegisterUpdateDay;
|
||||
|
||||
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 beacon_shop_profile_attribute = otherEntityAttribute as BeaconShopProfileAttribute;
|
||||
if (null == beacon_shop_profile_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast Attribute !!!, beacon_shop_profile_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BeaconGuid = beacon_shop_profile_attribute.BeaconGuid;
|
||||
DailyRegisterCount = beacon_shop_profile_attribute.DailyRegisterCount;
|
||||
RegisterUpdateDay = beacon_shop_profile_attribute.RegisterUpdateDay;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = beacon_shop_profile_attribute.getTryPendingDocBase() as BeaconShopProfileDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
beacon_shop_profile_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<BeaconShopProfileAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<BeaconShopProfileAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var beacon_shop_profile_attrib = origin_doc_base.getAttrib<BeaconShopProfileAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(beacon_shop_profile_attrib, () => $"beacon_shop_profile_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
beacon_shop_profile_attrib.BeaconGuid = BeaconGuid;
|
||||
beacon_shop_profile_attrib.DailyRegisterCount = DailyRegisterCount;
|
||||
beacon_shop_profile_attrib.RegisterUpdateDay = RegisterUpdateDay;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public class BeaconShopProfileAttributeTransactor : EntityAttributeTransactorBase<BeaconShopProfileAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public BeaconShopProfileAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(BeaconShopProfileAttribute).Name;
|
||||
|
||||
var copy_from_attribute = entityAttributeBase as BeaconShopProfileAttribute;
|
||||
if (null == copy_from_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_attribute = getClonedEntityAttribute() as BeaconShopProfileAttribute;
|
||||
if (null == copy_to_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_attribute.BeaconGuid = copy_from_attribute.BeaconGuid;
|
||||
copy_to_attribute.DailyRegisterCount = copy_from_attribute.DailyRegisterCount;
|
||||
copy_to_attribute.RegisterUpdateDay = copy_from_attribute.RegisterUpdateDay;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user