초기커밋
This commit is contained in:
303
ServerCommon/Entity/Attribute/BuildingAttribute.cs
Normal file
303
ServerCommon/Entity/Attribute/BuildingAttribute.cs
Normal file
@@ -0,0 +1,303 @@
|
||||
using Amazon.S3.Model;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
|
||||
using BUILDING_GUID = System.String;
|
||||
using META_ID = System.UInt32;
|
||||
using USER_GUID = System.String;
|
||||
|
||||
|
||||
namespace ServerCommon
|
||||
{
|
||||
public class BuildingAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty]
|
||||
public BUILDING_GUID BuildingGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public META_ID BuildingMetaId { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public string BuildingName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string OwnerUserGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public CurrencyType RentalCurrencyType { get; set; } = CurrencyType.None;
|
||||
|
||||
[JsonProperty]
|
||||
public double RentalCurrencyAmount { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public bool IsRentalOpen { get; set; } = false;
|
||||
|
||||
public bool IsLoadFromDb = false;
|
||||
|
||||
|
||||
public BuildingAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void newEntityAttribute()
|
||||
{
|
||||
BuildingGuid = System.Guid.NewGuid().ToString("N");
|
||||
base.newEntityAttribute();
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new BuildingAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
BuildingGuid = string.Empty;
|
||||
BuildingMetaId = 0;
|
||||
BuildingName = string.Empty;
|
||||
Description = string.Empty;
|
||||
OwnerUserGuid = string.Empty;
|
||||
RentalCurrencyType = CurrencyType.None;
|
||||
RentalCurrencyAmount = 0;
|
||||
IsRentalOpen = false;
|
||||
IsLoadFromDb = false;
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new BuildingAttribute(getOwner());
|
||||
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
cloned.BuildingGuid = BuildingGuid;
|
||||
cloned.BuildingMetaId = BuildingMetaId;
|
||||
cloned.BuildingName = BuildingName;
|
||||
cloned.Description = Description;
|
||||
cloned.OwnerUserGuid = OwnerUserGuid;
|
||||
cloned.RentalCurrencyType = RentalCurrencyType;
|
||||
cloned.RentalCurrencyAmount = RentalCurrencyAmount;
|
||||
cloned.IsRentalOpen = IsRentalOpen;
|
||||
cloned.IsLoadFromDb = IsLoadFromDb;
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var owner = getOwner();
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as BuildingDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new BuildingDoc(BuildingMetaId);
|
||||
|
||||
var origin_doc = getOriginDocBase<BuildingAttribute>();
|
||||
if (null != origin_doc)
|
||||
{
|
||||
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
try_pending_doc = to_copy_doc;
|
||||
|
||||
setTryPendingDocBase(try_pending_doc);
|
||||
}
|
||||
|
||||
var building_attrib = try_pending_doc.getAttrib<BuildingAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_attrib, () => $"building_attrib is null !!!");
|
||||
|
||||
building_attrib.BuildingGuid = BuildingGuid;
|
||||
building_attrib.BuildingMetaId = BuildingMetaId;
|
||||
building_attrib.BuildingName = BuildingName;
|
||||
building_attrib.Description = Description;
|
||||
building_attrib.OwnerUserGuid = OwnerUserGuid;
|
||||
building_attrib.RentalCurrencyType = RentalCurrencyType;
|
||||
building_attrib.RentalCurrencyAmount = RentalCurrencyAmount;
|
||||
building_attrib.IsRentalOpen = IsRentalOpen;
|
||||
|
||||
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(BuildingDoc).Name;
|
||||
|
||||
var building_doc_base = docBase as BuildingDoc;
|
||||
if (null == building_doc_base)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, building_doc_base is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<BuildingAttribute>(building_doc_base);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var building_attrib = building_doc_base.getAttrib<BuildingAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_attrib, () => $"building_attrib is null !!!");
|
||||
|
||||
BuildingGuid = building_attrib.BuildingGuid;
|
||||
BuildingMetaId = building_attrib.BuildingMetaId;
|
||||
BuildingName = building_attrib.BuildingName;
|
||||
Description = building_attrib.Description;
|
||||
OwnerUserGuid = building_attrib.OwnerUserGuid;
|
||||
RentalCurrencyType = building_attrib.RentalCurrencyType;
|
||||
RentalCurrencyAmount = building_attrib.RentalCurrencyAmount;
|
||||
IsRentalOpen = building_attrib.IsRentalOpen;
|
||||
IsLoadFromDb = true;
|
||||
|
||||
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 building_attribute = otherEntityAttribute as BuildingAttribute;
|
||||
if (null == building_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast BuildingAttribute !!!, building_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BuildingGuid = building_attribute.BuildingGuid;
|
||||
BuildingMetaId = building_attribute.BuildingMetaId;
|
||||
BuildingName = building_attribute.BuildingName;
|
||||
Description = building_attribute.Description;
|
||||
OwnerUserGuid = building_attribute.OwnerUserGuid;
|
||||
RentalCurrencyType = building_attribute.RentalCurrencyType;
|
||||
RentalCurrencyAmount = building_attribute.RentalCurrencyAmount;
|
||||
IsRentalOpen = building_attribute.IsRentalOpen;
|
||||
IsLoadFromDb = building_attribute.IsLoadFromDb;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
|
||||
var try_pending_doc = building_attribute.getTryPendingDocBase() as AccountBaseDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
building_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<BuildingAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<BuildingAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_attrib = origin_doc_base.getAttrib<BuildingAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_attrib, () => $"building_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
building_attrib.BuildingGuid = BuildingGuid;
|
||||
building_attrib.BuildingMetaId = BuildingMetaId;
|
||||
building_attrib.BuildingName = BuildingName;
|
||||
building_attrib.Description = Description;
|
||||
building_attrib.OwnerUserGuid = OwnerUserGuid;
|
||||
building_attrib.RentalCurrencyType = RentalCurrencyType;
|
||||
building_attrib.RentalCurrencyAmount = RentalCurrencyAmount;
|
||||
building_attrib.IsRentalOpen = IsRentalOpen;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class BuildingAttributeTransactor : EntityAttributeTransactorBase<BuildingAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public BuildingAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(BuildingAttribute).Name;
|
||||
|
||||
var copy_from_building_attribute = entityAttributeBase as BuildingAttribute;
|
||||
if (null == copy_from_building_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_building_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_building_attribute = getClonedEntityAttribute() as BuildingAttribute;
|
||||
if (null == copy_to_building_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_building_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_building_attribute.BuildingGuid = copy_from_building_attribute.BuildingGuid;
|
||||
copy_to_building_attribute.BuildingMetaId = copy_from_building_attribute.BuildingMetaId;
|
||||
copy_to_building_attribute.BuildingName = copy_from_building_attribute.BuildingName;
|
||||
copy_to_building_attribute.Description = copy_from_building_attribute.Description;
|
||||
copy_to_building_attribute.OwnerUserGuid = copy_from_building_attribute.OwnerUserGuid;
|
||||
copy_to_building_attribute.RentalCurrencyType = copy_from_building_attribute.RentalCurrencyType;
|
||||
copy_to_building_attribute.RentalCurrencyAmount = copy_from_building_attribute.RentalCurrencyAmount;
|
||||
copy_to_building_attribute.IsRentalOpen = copy_from_building_attribute.IsRentalOpen;
|
||||
copy_to_building_attribute.IsLoadFromDb = copy_from_building_attribute.IsLoadFromDb;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user