using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.Model; using Amazon.DynamoDBv2.DocumentModel; using Google.Protobuf.WellKnownTypes; using ServerCore; using ServerBase; using SESSION_ID = System.Int32; using WORLD_ID = System.UInt32; using META_ID = System.UInt32; using ENTITY_GUID = System.String; using ACCOUNT_ID = System.String; using OWNER_GUID = System.String; using USER_GUID = System.String; using CHARACTER_GUID = System.String; using ITEM_GUID = System.String; using System.Runtime.InteropServices; namespace ServerCommon { public class LandAuctionRefundBidPriceAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc { [JsonProperty] public USER_GUID BidUserGuid { get; set; } = string.Empty; // 입찰 유저 식별키 [JsonProperty] public META_ID LandMetaId { get; set; } = 0; // Land Meta Id [JsonProperty] public Int32 AuctionNumber { get; set; } = 0; // LandMetaId 기준 경매 번호 1 ~ [JsonProperty] public LandAuctionBidType LastBidType { get; set; } = 0; // 마지막 입찰의 종류 [JsonProperty] public CurrencyType BidCurrencyType { get; set; } = CurrencyType.None; // 입찰 재화의 종류 [JsonProperty] public double LastBidPrice { get; set; } = 0; // 마지막 입찰금 [JsonProperty] public double RefundableNormalBidPrice { get; set; } = 0; // 본인의 일반 환급 가능한 입찰금 [JsonProperty] public double RefundableBlindBidPrice { get; set; } = 0; // 본인의 블라인드 환급 가능한 입찰금 public LandAuctionRefundBidPriceAttribute(EntityBase owner) : base(owner) { } public override IEntityAttributeTransactor onNewEntityAttributeTransactor() { return new LandAuctionRefundBidPriceAttributeTransactor(getOwner()); } public override void onClear() { BidUserGuid = string.Empty; LandMetaId = 0; AuctionNumber = 0; LastBidType = LandAuctionBidType.None; BidCurrencyType = CurrencyType.None; LastBidPrice = 0; RefundableNormalBidPrice = 0; RefundableBlindBidPrice = 0; getAttributeState().reset(); } public override EntityAttributeBase onCloned() { var cloned = new LandAuctionRefundBidPriceAttribute(getOwner()); cloned.deepCopyFromBase(this); cloned.BidUserGuid = string.Empty; cloned.LandMetaId = LandMetaId; cloned.AuctionNumber = AuctionNumber; cloned.LastBidType = LastBidType; cloned.BidCurrencyType = BidCurrencyType; cloned.LastBidPrice = LastBidPrice; cloned.RefundableNormalBidPrice = RefundableNormalBidPrice; cloned.RefundableBlindBidPrice = RefundableBlindBidPrice; return cloned; } public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true) { var result = new Result(); var owner = getOwner() as UserBase; NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!"); //===================================================================================== // Attribute => try pending Doc //===================================================================================== var try_pending_doc = getTryPendingDocBase() as LandAuctionRefundBidPriceDoc; if (null == try_pending_doc) { var to_copy_doc = new LandAuctionRefundBidPriceDoc(BidUserGuid, 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 refund_bid_price_attrib = try_pending_doc.getAttrib(); NullReferenceCheckHelper.throwIfNull(refund_bid_price_attrib, () => $"refund_bid_price_attrib is null !!! - {owner.toBasicString()}"); refund_bid_price_attrib.BidUserGuid = BidUserGuid; refund_bid_price_attrib.LandMetaId = LandMetaId; refund_bid_price_attrib.AuctionNumber = AuctionNumber; refund_bid_price_attrib.LastBidType = LastBidType; refund_bid_price_attrib.BidCurrencyType = BidCurrencyType; refund_bid_price_attrib.LastBidPrice = LastBidPrice; refund_bid_price_attrib.RefundableNormalBidPrice = RefundableNormalBidPrice; refund_bid_price_attrib.RefundableBlindBidPrice = RefundableBlindBidPrice; 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(LandAuctionRefundBidPriceDoc).Name; var refund_bid_price_doc = docBase as LandAuctionRefundBidPriceDoc; if (null == refund_bid_price_doc) { err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, refund_bid_price_doc is null :{to_cast_string}"; Log.getLogger().error(err_msg); return false; } //===================================================================================== // New Doc => Origin Doc //===================================================================================== syncOriginDocBaseWithNewDoc(refund_bid_price_doc); //===================================================================================== // Doc => Attribute //===================================================================================== var refund_bid_price_attrib = refund_bid_price_doc.getAttrib(); NullReferenceCheckHelper.throwIfNull(refund_bid_price_attrib, () => "refund_bid_price_attrib is null !!!"); BidUserGuid = refund_bid_price_attrib.BidUserGuid; LandMetaId = refund_bid_price_attrib.LandMetaId; AuctionNumber = refund_bid_price_attrib.AuctionNumber; LastBidType = refund_bid_price_attrib.LastBidType; BidCurrencyType = refund_bid_price_attrib.BidCurrencyType; LastBidPrice = refund_bid_price_attrib.LastBidPrice; RefundableNormalBidPrice = refund_bid_price_attrib.RefundableNormalBidPrice; RefundableBlindBidPrice = refund_bid_price_attrib.RefundableBlindBidPrice; return true; } public Result copyFromOtherEntityAttribute(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 refund_bid_price_attribute = otherEntityAttribute as LandAuctionRefundBidPriceAttribute; if (null == refund_bid_price_attribute) { err_msg = $"Failed to cast LandAuctionRefundBidPriceAttribute !!!, refund_bid_price_attribute is null"; result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg); Log.getLogger().error(result.toBasicString()); return result; } BidUserGuid = refund_bid_price_attribute.BidUserGuid; LandMetaId = refund_bid_price_attribute.LandMetaId; AuctionNumber = refund_bid_price_attribute.AuctionNumber; LastBidType = refund_bid_price_attribute.LastBidType; BidCurrencyType = refund_bid_price_attribute.BidCurrencyType; LastBidPrice = refund_bid_price_attribute.LastBidPrice; RefundableNormalBidPrice = refund_bid_price_attribute.RefundableNormalBidPrice; RefundableBlindBidPrice = refund_bid_price_attribute.RefundableBlindBidPrice; //===================================================================================== // Attribute Try Pending Doc => Origin Doc //===================================================================================== var try_pending_doc = refund_bid_price_attribute.getTryPendingDocBase() as LandAuctionRefundBidPriceDoc; if (null != try_pending_doc) { refund_bid_price_attribute.resetTryPendingDocBase(); syncOriginDocBaseWithNewDoc(try_pending_doc); } var origin_doc_base = getOriginDocBase(); if (null == origin_doc_base) { // DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!! return result; } var refund_bid_price_attrib = origin_doc_base.getAttrib(); NullReferenceCheckHelper.throwIfNull(refund_bid_price_attrib, () => $"refund_bid_price_attrib is null !!! - {owner.toBasicString()}"); refund_bid_price_attrib.BidUserGuid = BidUserGuid; refund_bid_price_attrib.LandMetaId = LandMetaId; refund_bid_price_attrib.AuctionNumber = AuctionNumber; refund_bid_price_attrib.LastBidType = LastBidType; refund_bid_price_attrib.BidCurrencyType = BidCurrencyType; refund_bid_price_attrib.LastBidPrice = LastBidPrice; refund_bid_price_attrib.RefundableNormalBidPrice = RefundableNormalBidPrice; refund_bid_price_attrib.RefundableBlindBidPrice = RefundableBlindBidPrice; return result; } public override string toBasicString() { return base.toBasicString() + $" LandMetaId:{LandMetaId}, AuctionNumber:{AuctionNumber}, BidUserGuid:{BidUserGuid}"; } } public class LandAuctionRefundBidPriceAttributeTransactor : EntityAttributeTransactorBase { public LandAuctionRefundBidPriceAttributeTransactor(EntityBase owner) : base(owner) { } } }