using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Newtonsoft.Json; using ServerCore; using ServerBase; namespace ServerCommon; public class BuildingProfitHistoryAttrib : AttribBase { [JsonProperty("building_meta_id")] public int BuildingMetaId { get; set; } [JsonProperty("floor")] public int Floor { get; set; } = 0; [JsonProperty("profit_time")] public DateTime ProfitTime { get; set; } = new(); [JsonProperty("profit_history_type")] public ProfitHistoryType ProfitHistoryType { get; set; } = ProfitHistoryType.None; [JsonProperty("profit")] public Dictionary Profits { get; set; } = new(); public BuildingProfitHistoryAttrib() : base(typeof(BuildingProfitHistoryAttrib).Name, false) { } } //============================================================================================= // PK(Partition Key) : "building#building_meta_id" // SK(Sort Key) : "profit_history#timestamp" // DocType : BuildingProfitHistoryDoc // BuildingAttrib : {} // ... //============================================================================================= public class BuildingProfitHistoryDoc : DynamoDbDocBase { private static string getPrefixOfPK() { return "building#"; } public static string getPrefixOfSK() { return "profit_history#"; } public BuildingProfitHistoryDoc() : base(typeof(BuildingProfitHistoryAttrib).Name) { appendAttribWrapperAll(); } public BuildingProfitHistoryDoc(int buildingMetaId, Timestamp timestamp) : base(typeof(BuildingProfitHistoryAttrib).Name) { setCombinationKeyForPK(buildingMetaId.ToString()); setCombinationKeyForSK(timestamp.ToString()); appendAttribWrapperAll(); fillUpPrimaryKey(onMakePK(), onMakeSK()); } private void appendAttribWrapperAll() { appendAttribWrapper(new AttribWrapper()); } protected override string onGetPrefixOfPK() { return getPrefixOfPK(); } protected override string onGetPrefixOfSK() { return getPrefixOfSK(); } protected override string onMakeSK() { return $"{onGetPrefixOfSK()}{getCombinationKeyForSK()}"; } protected override ServerErrorCode onCheckAndSetSK(string sortKey) { getPrimaryKey().fillUpSK(sortKey); return ServerErrorCode.Success; } }