초기커밋
This commit is contained in:
233
ServerCommon/Entity/Attribute/BuildingProfitAttribute.cs
Normal file
233
ServerCommon/Entity/Attribute/BuildingProfitAttribute.cs
Normal file
@@ -0,0 +1,233 @@
|
||||
using Amazon;
|
||||
using Newtonsoft.Json;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServerCommon
|
||||
{
|
||||
public class BuildingProfitAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty]
|
||||
public int BuildingMetaId { get; set; }
|
||||
[JsonProperty]
|
||||
public int Floor { get; set; }
|
||||
[JsonProperty]
|
||||
public Dictionary<CurrencyType, double> Profits { get; set; } = new();
|
||||
|
||||
public BuildingProfitAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void newEntityAttribute()
|
||||
{
|
||||
base.newEntityAttribute();
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new BuildingProfitAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
BuildingMetaId = 0;
|
||||
Floor = 0;
|
||||
Profits = new();
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new BuildingProfitAttribute(getOwner());
|
||||
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
cloned.BuildingMetaId = BuildingMetaId;
|
||||
cloned.Floor = Floor;
|
||||
cloned.Profits = new(Profits);
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as BuildingProfitDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new BuildingProfitDoc(BuildingMetaId, Floor);
|
||||
|
||||
var origin_doc = getOriginDocBase<BuildingProfitAttribute>();
|
||||
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<BuildingProfitAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!!");
|
||||
|
||||
to_copy_doc_attrib.BuildingMetaId = BuildingMetaId;
|
||||
to_copy_doc_attrib.Floor = Floor;
|
||||
to_copy_doc_attrib.Profits = new(Profits);
|
||||
|
||||
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 err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(BuildingProfitDoc).Name;
|
||||
|
||||
var building_profit_doc_base = docBase as BuildingProfitDoc;
|
||||
if (null == building_profit_doc_base)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, building_profit_doc_base is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<BuildingProfitAttribute>(building_profit_doc_base);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var doc_attrib = building_profit_doc_base.getAttrib<BuildingProfitAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => $"doc_attrib is null !!!");
|
||||
|
||||
BuildingMetaId = doc_attrib.BuildingMetaId;
|
||||
Floor = doc_attrib.Floor;
|
||||
Profits = new(doc_attrib.Profits);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
||||
{
|
||||
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 building_profit_attribute = otherEntityAttribute as BuildingProfitAttribute;
|
||||
if (null == building_profit_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast BuildingProfitAttribute !!!, building_profit_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BuildingMetaId = building_profit_attribute.BuildingMetaId;
|
||||
Floor = building_profit_attribute.Floor;
|
||||
Profits = new(building_profit_attribute.Profits);
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = building_profit_attribute.getTryPendingDocBase() as BuildingProfitDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
building_profit_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<BuildingProfitAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<BuildingProfitAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_profit_attrib = origin_doc_base.getAttrib<BuildingProfitAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_attrib, () => $"building_profit_attrib is null !!!");
|
||||
|
||||
building_profit_attrib.BuildingMetaId = BuildingMetaId;
|
||||
building_profit_attrib.Floor = Floor;
|
||||
building_profit_attrib.Profits = new(Profits);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class BuildingProfitAttributeTransactor : EntityAttributeTransactorBase<BuildingProfitAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public BuildingProfitAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(BuildingProfitAttribute).Name;
|
||||
|
||||
var copy_from_building_profit_attribute = entityAttributeBase as BuildingProfitAttribute;
|
||||
if (null == copy_from_building_profit_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_building_profit_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_building_profit_attribute = getClonedEntityAttribute() as BuildingProfitAttribute;
|
||||
if (null == copy_to_building_profit_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_building_profit_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_building_profit_attribute.BuildingMetaId = copy_from_building_profit_attribute.BuildingMetaId;
|
||||
copy_to_building_profit_attribute.Floor = copy_from_building_profit_attribute.Floor;
|
||||
copy_to_building_profit_attribute.Profits = new(copy_from_building_profit_attribute.Profits);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user