using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Google.Protobuf.WellKnownTypes; using ServerCore; using ServerBase; using ServerCommon.Cache; using META_ID = System.UInt32; using LAND_AUCTION_NUBER = System.Int32; using USER_GUID = System.String; namespace ServerCommon { //============================================================================================= // 랜드별 LandAuctionResult.Successed (낙찰)된 경매 정보 //============================================================================================= public class LandAuctionRecordAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute { [JsonProperty] public META_ID LandMetaId { get; set; } = 0; // 경매 대상 LandData Meta Id [JsonProperty] public LAND_AUCTION_NUBER AuctionNumber { get; set; } = 0; // 경매 번호 public LandAuctionRecordAttribute(EntityBase owner) : base(owner) { } public override IEntityAttributeTransactor onNewEntityAttributeTransactor() { return new LandAuctionRecordAttributeTransactor(getOwner()); } public override void onClear() { LandMetaId = 0; AuctionNumber = 0; getAttributeState().reset(); } public override EntityAttributeBase onCloned() { var cloned = new LandAuctionRecordAttribute(getOwner()); cloned.deepCopyFromBase(this); cloned.LandMetaId = LandMetaId; cloned.AuctionNumber = AuctionNumber; return cloned; } public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true) { var result = new Result(); var owner = getOwner(); NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!"); //===================================================================================== // Attribute => try pending Doc //===================================================================================== var try_pending_doc = getTryPendingDocBase() as LandAuctionRecordDoc; if (null == try_pending_doc) { var to_copy_doc = new LandAuctionRecordDoc(LandMetaId, AuctionNumber); var origin_doc = getOriginDocBase(); if (null != origin_doc) { to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc); } try_pending_doc = to_copy_doc; setTryPendingDocBase(try_pending_doc); } var record_attrib = try_pending_doc.getAttrib(); NullReferenceCheckHelper.throwIfNull(record_attrib, () => $"record_attrib is null !!! - {owner.toBasicString()}"); record_attrib.LandMetaId = LandMetaId; record_attrib.AuctionNumber = AuctionNumber; 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(LandDoc).Name; var land_doc_base = docBase as LandDoc; if (null == land_doc_base) { err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, land_doc_base is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } //===================================================================================== // New Doc => Origin Doc //===================================================================================== syncOriginDocBaseWithNewDoc(land_doc_base); //===================================================================================== // Doc => Attribute //===================================================================================== var record_attrib = land_doc_base.getAttrib(); NullReferenceCheckHelper.throwIfNull(record_attrib, () => "record_attrib is null !!!"); LandMetaId = record_attrib.LandMetaId; AuctionNumber = record_attrib.AuctionNumber; 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 record_attribute = otherEntityAttribute as LandAuctionRecordAttribute; if (null == record_attribute) { err_msg = $"Failed to cast LandAuctionRecordAttribute !!!, record_attribute is null - {owner.toBasicString()}"; result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg); Log.getLogger().error(result.toBasicString()); return result; } LandMetaId = record_attribute.LandMetaId; AuctionNumber = record_attribute.AuctionNumber; //===================================================================================== // Attribute Try Pending Doc => Origin Doc //===================================================================================== var try_pending_doc = record_attribute.getTryPendingDocBase() as LandAuctionRecordDoc; if (null != try_pending_doc) { record_attribute.resetTryPendingDocBase(); syncOriginDocBaseWithNewDoc(try_pending_doc); } var origin_doc_base = getOriginDocBase(); if (null == origin_doc_base) { // DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!! return result; } var record_attrib = origin_doc_base.getAttrib(); NullReferenceCheckHelper.throwIfNull(record_attrib, () => $"record_attrib is null !!! - {owner.toBasicString()}"); record_attrib.LandMetaId = LandMetaId; record_attrib.AuctionNumber = AuctionNumber; return result; } } public class LandAuctionRecordAttributeTransactor : EntityAttributeTransactorBase, ICopyEntityAttributeTransactorFromEntityAttribute { public LandAuctionRecordAttributeTransactor(EntityBase owner) : base(owner) { } public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase) { var err_msg = string.Empty; var to_cast_string = typeof(LandAuctionRegistryAttribute).Name; var copy_from_record_attribute = entityAttributeBase as LandAuctionRecordAttribute; if (null == copy_from_record_attribute) { err_msg = $"Failed to cast LandAuctionRecordAttribute !!!, copy_from_record_attribute is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } var copy_to_record_attribute = getClonedEntityAttribute() as LandAuctionRecordAttribute; if (null == copy_to_record_attribute) { err_msg = $"Failed to cast LandAuctionRecordAttribute !!!, copy_to_record_attribute is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } copy_to_record_attribute.LandMetaId = copy_from_record_attribute.LandMetaId; copy_to_record_attribute.AuctionNumber = copy_from_record_attribute.AuctionNumber; return true; } } }