초기커밋
This commit is contained in:
252
ServerCommon/Entity/Attribute/BuildingRentalHistoryAttribute.cs
Normal file
252
ServerCommon/Entity/Attribute/BuildingRentalHistoryAttribute.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
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 BuildingRentalHistoryAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty]
|
||||
public int BuildingMetaId { get; set; }
|
||||
[JsonProperty]
|
||||
public int Floor { get; set; } = 0;
|
||||
[JsonProperty]
|
||||
public string RenteeUserGuid { get; set; } = string.Empty;
|
||||
[JsonProperty]
|
||||
public DateTime RentalTime { get; set; } = new();
|
||||
[JsonProperty]
|
||||
public int RentalPeriod { get; set; } = 0;
|
||||
|
||||
|
||||
public BuildingRentalHistoryAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void newEntityAttribute()
|
||||
{
|
||||
base.newEntityAttribute();
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new BuildingRentalHistoryAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
BuildingMetaId = 0;
|
||||
Floor = 0;
|
||||
RenteeUserGuid = string.Empty;
|
||||
RentalTime = new();
|
||||
RentalPeriod = 0;
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var cloned = new BuildingRentalHistoryAttribute(getOwner());
|
||||
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
cloned.BuildingMetaId = BuildingMetaId;
|
||||
cloned.Floor = Floor;
|
||||
cloned.RenteeUserGuid = RenteeUserGuid;
|
||||
cloned.RentalTime = RentalTime;
|
||||
cloned.RentalPeriod = RentalPeriod;
|
||||
|
||||
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 BuildingRentalHistoryDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new BuildingRentalHistoryDoc(BuildingMetaId, RentalTime.ToTimestamp());
|
||||
|
||||
var origin_doc = getOriginDocBase<BuildingRentalHistoryAttribute>();
|
||||
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<BuildingRentalHistoryAttrib>();
|
||||
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.RenteeUserGuid = RenteeUserGuid;
|
||||
to_copy_doc_attrib.RentalTime = RentalTime;
|
||||
to_copy_doc_attrib.RentalPeriod = RentalPeriod;
|
||||
|
||||
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(BuildingRentalHistoryDoc).Name;
|
||||
|
||||
var building_rental_history_doc_base = docBase as BuildingRentalHistoryDoc;
|
||||
if (null == building_rental_history_doc_base)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, building_rental_history_doc_base is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<BuildingRentalHistoryAttribute>(building_rental_history_doc_base);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var doc_attrib = building_rental_history_doc_base.getAttrib<BuildingRentalHistoryAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => $"doc_attrib is null !!!");
|
||||
|
||||
BuildingMetaId = doc_attrib.BuildingMetaId;
|
||||
Floor = doc_attrib.Floor;
|
||||
RenteeUserGuid = doc_attrib.RenteeUserGuid;
|
||||
RentalTime = doc_attrib.RentalTime;
|
||||
RentalPeriod = doc_attrib.RentalPeriod;
|
||||
|
||||
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_rental_history_attribute = otherEntityAttribute as BuildingRentalHistoryAttribute;
|
||||
if (null == building_rental_history_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast BuildingRentalHistoryAttribute !!!, building_rental_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BuildingMetaId = building_rental_history_attribute.BuildingMetaId;
|
||||
Floor = building_rental_history_attribute.Floor;
|
||||
RenteeUserGuid = building_rental_history_attribute.RenteeUserGuid;
|
||||
RentalTime = building_rental_history_attribute.RentalTime;
|
||||
RentalPeriod = building_rental_history_attribute.RentalPeriod;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = building_rental_history_attribute.getTryPendingDocBase() as BuildingRentalHistoryDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
building_rental_history_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<BuildingRentalHistoryAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<BuildingRentalHistoryAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_rental_history_attrib = origin_doc_base.getAttrib<BuildingRentalHistoryAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_rental_history_attrib, () => $"building_rental_attrib is null !!!");
|
||||
|
||||
building_rental_history_attrib.BuildingMetaId = BuildingMetaId;
|
||||
building_rental_history_attrib.Floor = Floor;
|
||||
building_rental_history_attrib.RenteeUserGuid = RenteeUserGuid;
|
||||
building_rental_history_attrib.RentalTime = RentalTime;
|
||||
building_rental_history_attrib.RentalPeriod = RentalPeriod;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class BuildingRentalHistoryAttributeTransactor : EntityAttributeTransactorBase<BuildingRentalHistoryAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public BuildingRentalHistoryAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(BuildingRentalHistoryAttribute).Name;
|
||||
|
||||
var copy_from_building_rental_history_attribute = entityAttributeBase as BuildingRentalHistoryAttribute;
|
||||
if (null == copy_from_building_rental_history_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_building_rental_history_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_building_rental_history_attribute = getClonedEntityAttribute() as BuildingRentalHistoryAttribute;
|
||||
if (null == copy_to_building_rental_history_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_building_rental_history_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_building_rental_history_attribute.BuildingMetaId = copy_from_building_rental_history_attribute.BuildingMetaId;
|
||||
copy_to_building_rental_history_attribute.Floor = copy_from_building_rental_history_attribute.Floor;
|
||||
copy_to_building_rental_history_attribute.RenteeUserGuid = copy_from_building_rental_history_attribute.RenteeUserGuid;
|
||||
copy_to_building_rental_history_attribute.RentalTime = copy_from_building_rental_history_attribute.RentalTime;
|
||||
copy_to_building_rental_history_attribute.RentalPeriod = copy_from_building_rental_history_attribute.RentalPeriod;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user