mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-22 03:49:35 +08:00
修改了数据库初始化逻辑
This commit is contained in:
parent
e77ac767ef
commit
09bfa8dc58
@ -1,11 +1,13 @@
|
|||||||
|
using System.Data;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||||
using Milimoe.FunGame.Core.Api.Utility;
|
using Milimoe.FunGame.Core.Api.Utility;
|
||||||
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Core.Interface;
|
using Milimoe.FunGame.Core.Interface;
|
||||||
using Milimoe.FunGame.Core.Library.Common.Addon;
|
using Milimoe.FunGame.Core.Library.Common.Addon;
|
||||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||||
|
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||||
using Oshima.Core.Configs;
|
using Oshima.Core.Configs;
|
||||||
using Oshima.Core.Constant;
|
using Oshima.Core.Constant;
|
||||||
using Oshima.FunGame.OshimaServers.Service;
|
using Oshima.FunGame.OshimaServers.Service;
|
||||||
@ -30,9 +32,196 @@ namespace Oshima.FunGame.WebAPI
|
|||||||
{
|
{
|
||||||
if (input == "test")
|
if (input == "test")
|
||||||
{
|
{
|
||||||
FunGameController controller = new(new Logger<FunGameController>(new LoggerFactory()));
|
//FunGameController controller = new(new Logger<FunGameController>(new LoggerFactory()));
|
||||||
Controller.WriteLine(Controller.JSON.GetObject<string>(controller.ShowDailyStore(1)) ?? "test");
|
//Controller.WriteLine(Controller.JSON.GetObject<string>(controller.ShowDailyStore(1)) ?? "test");
|
||||||
|
|
||||||
|
using SQLHelper? sql = Controller.GetSQLHelper();
|
||||||
|
if (sql != null)
|
||||||
|
{
|
||||||
|
sql.NewTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//sql.Execute(StoreQuery.Insert_Store(sql, "测试商店1", null, null));
|
||||||
|
//sql.Execute(GoodsQuery.Insert_Goods(sql, "测试商品1", "测试商品描述1", 110));
|
||||||
|
//sql.Execute(GoodsQuery.Insert_Goods(sql, "测试商品2", "测试商品描述2", 120));
|
||||||
|
//sql.Execute(GoodsQuery.Insert_Goods(sql, "测试商品3", "测试商品描述3", 130));
|
||||||
|
//sql.Execute(StoreGoodsQuery.Insert_StoreGoods(sql, 1, 1));
|
||||||
|
//sql.Execute(StoreGoodsQuery.Insert_StoreGoods(sql, 1, 2));
|
||||||
|
//sql.Execute(StoreGoodsQuery.Insert_StoreGoods(sql, 1, 3));
|
||||||
|
//sql.Execute(GoodItemsQuery.Insert_GoodItem(sql, 1, (long)AccessoryID.攻击之爪50));
|
||||||
|
//sql.Execute(GoodItemsQuery.Insert_GoodItem(sql, 2, (long)ConsumableID.小经验书));
|
||||||
|
//sql.Execute(GoodItemsQuery.Insert_GoodItem(sql, 3, (long)SpecialItemID.技能卷轴));
|
||||||
|
//sql.Execute(GoodPricesQuery.Insert_GoodPrice(sql, 1, General.GameplayEquilibriumConstant.InGameCurrency, 110));
|
||||||
|
//sql.Execute(GoodPricesQuery.Insert_GoodPrice(sql, 2, General.GameplayEquilibriumConstant.InGameCurrency, 120));
|
||||||
|
//sql.Execute(GoodPricesQuery.Insert_GoodPrice(sql, 3, General.GameplayEquilibriumConstant.InGameCurrency, 130));
|
||||||
|
|
||||||
|
//sql.Execute(StoreQuery.Insert_Store(sql, "测试商店2", null, null));
|
||||||
|
//sql.Execute(GoodsQuery.Insert_Goods(sql, "测试商品4", "测试商品描述4", 111));
|
||||||
|
//sql.Execute(GoodsQuery.Insert_Goods(sql, "测试商品5", "测试商品描述5", 122));
|
||||||
|
//sql.Execute(GoodsQuery.Insert_Goods(sql, "测试商品6", "测试商品描述6", 133));
|
||||||
|
//sql.Execute(StoreGoodsQuery.Insert_StoreGoods(sql, 2, 4));
|
||||||
|
//sql.Execute(StoreGoodsQuery.Insert_StoreGoods(sql, 2, 5));
|
||||||
|
//sql.Execute(StoreGoodsQuery.Insert_StoreGoods(sql, 2, 6));
|
||||||
|
//sql.Execute(GoodItemsQuery.Insert_GoodItem(sql, 4, (long)AccessoryID.攻击之爪20));
|
||||||
|
//sql.Execute(GoodItemsQuery.Insert_GoodItem(sql, 5, (long)ConsumableID.中经验书));
|
||||||
|
//sql.Execute(GoodItemsQuery.Insert_GoodItem(sql, 6, (long)SpecialItemID.智慧之果));
|
||||||
|
//sql.Execute(GoodPricesQuery.Insert_GoodPrice(sql, 4, General.GameplayEquilibriumConstant.InGameCurrency, 111));
|
||||||
|
//sql.Execute(GoodPricesQuery.Insert_GoodPrice(sql, 5, General.GameplayEquilibriumConstant.InGameCurrency, 122));
|
||||||
|
//sql.Execute(GoodPricesQuery.Insert_GoodPrice(sql, 6, General.GameplayEquilibriumConstant.InGameCurrency, 133));
|
||||||
|
|
||||||
|
// 单一商店测试
|
||||||
|
|
||||||
|
Store store = new("");
|
||||||
|
sql.ExecuteDataSet(StoreQuery.Select_StoreById(sql, 1));
|
||||||
|
if (sql.Success)
|
||||||
|
{
|
||||||
|
DataRow dr = sql.DataSet.Tables[0].Rows[0];
|
||||||
|
store.Id = (long)dr[StoreQuery.Column_Id];
|
||||||
|
store.Name = (string)dr[StoreQuery.Column_StoreName];
|
||||||
|
if (dr[StoreQuery.Column_StartTime] != DBNull.Value)
|
||||||
|
{
|
||||||
|
store.StartTime = (DateTime)dr[StoreQuery.Column_StartTime];
|
||||||
}
|
}
|
||||||
|
if (dr[StoreQuery.Column_EndTime] != DBNull.Value)
|
||||||
|
{
|
||||||
|
store.EndTime = (DateTime)dr[StoreQuery.Column_EndTime];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Goods> goodsList = [];
|
||||||
|
|
||||||
|
sql.ExecuteDataSet(GoodsQuery.Select_AllGoodsWithItemAndPrice(sql, 1));
|
||||||
|
if (sql.Success)
|
||||||
|
{
|
||||||
|
goodsList.AddRange(GetGoods(sql.DataSet));
|
||||||
|
}
|
||||||
|
DataSet ds2 = sql.ExecuteDataSet(GoodsQuery.Select_AllGoodsWithItemAndPrice(sql, 2));
|
||||||
|
if (sql.Success)
|
||||||
|
{
|
||||||
|
goodsList.AddRange(GetGoods(sql.DataSet));
|
||||||
|
}
|
||||||
|
DataSet ds3 = sql.ExecuteDataSet(GoodsQuery.Select_AllGoodsWithItemAndPrice(sql, 3));
|
||||||
|
if (sql.Success)
|
||||||
|
{
|
||||||
|
goodsList.AddRange(GetGoods(sql.DataSet));
|
||||||
|
}
|
||||||
|
foreach (Goods goods in goodsList)
|
||||||
|
{
|
||||||
|
store.Goods.Add(goods.Id, goods);
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.WriteLine(store.ToString());
|
||||||
|
|
||||||
|
// 所有商店测试
|
||||||
|
|
||||||
|
List<Store> stores = [];
|
||||||
|
|
||||||
|
sql.ExecuteDataSet(StoreQuery.Select_AllGoodsInStore(sql));
|
||||||
|
if (sql.Success)
|
||||||
|
{
|
||||||
|
DataSet ds = sql.DataSet;
|
||||||
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||||
|
{
|
||||||
|
Store storeTemp = new("")
|
||||||
|
{
|
||||||
|
Id = (long)dr["StoreId"],
|
||||||
|
Name = (string)dr[StoreQuery.Column_StoreName]
|
||||||
|
};
|
||||||
|
if (stores.FirstOrDefault(s => s.Id == storeTemp.Id) is Store store2)
|
||||||
|
{
|
||||||
|
storeTemp = store2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stores.Add(storeTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Goods goods = new()
|
||||||
|
{
|
||||||
|
Id = (long)dr["GoodsId"],
|
||||||
|
Name = (string)dr["GoodsName"],
|
||||||
|
Description = (string)dr[GoodsQuery.Column_Description],
|
||||||
|
Stock = Convert.ToInt32(dr[GoodsQuery.Column_Stock])
|
||||||
|
};
|
||||||
|
Item item = Factory.OpenFactory.GetInstance<Item>((long)dr[GoodItemsQuery.Column_ItemId], "", []);
|
||||||
|
goods.Items.Add(item);
|
||||||
|
string currency = (string)dr[GoodPricesQuery.Column_Currency];
|
||||||
|
double price = (double)dr[GoodPricesQuery.Column_Price];
|
||||||
|
goods.Prices.Add(currency, price);
|
||||||
|
|
||||||
|
storeTemp.Goods.Add(goods.Id, goods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Store store2 in stores)
|
||||||
|
{
|
||||||
|
Controller.WriteLine(store2.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
sql.Rollback();
|
||||||
|
Controller.Error(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
sql.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Goods> GetGoods(DataSet ds)
|
||||||
|
{
|
||||||
|
DataSetToString(ds);
|
||||||
|
List<Goods> list = [];
|
||||||
|
|
||||||
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||||
|
{
|
||||||
|
Goods goods = new()
|
||||||
|
{
|
||||||
|
Id = (long)dr[GoodsQuery.Column_Id],
|
||||||
|
Name = (string)dr[GoodsQuery.Column_Name],
|
||||||
|
Description = (string)dr[GoodsQuery.Column_Description],
|
||||||
|
Stock = Convert.ToInt32(dr[GoodsQuery.Column_Stock])
|
||||||
|
};
|
||||||
|
Item item = Factory.OpenFactory.GetInstance<Item>((long)dr[GoodItemsQuery.Column_ItemId], "", []);
|
||||||
|
goods.Items.Add(item);
|
||||||
|
string currency = (string)dr[GoodPricesQuery.Column_Currency];
|
||||||
|
double price = (double)dr[GoodPricesQuery.Column_Price];
|
||||||
|
goods.Prices.Add(currency, price);
|
||||||
|
list.Add(goods);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string DataSetToString(DataSet ds)
|
||||||
|
{
|
||||||
|
if (ds == null || ds.Tables.Count == 0)
|
||||||
|
{
|
||||||
|
return "DataSet is null or empty.";
|
||||||
|
}
|
||||||
|
|
||||||
|
string result = "";
|
||||||
|
foreach (DataTable table in ds.Tables)
|
||||||
|
{
|
||||||
|
result += $"Table Name: {table.TableName}\n";
|
||||||
|
foreach (DataColumn column in table.Columns)
|
||||||
|
{
|
||||||
|
result += $"{column.ColumnName}\t";
|
||||||
|
}
|
||||||
|
result += "\n";
|
||||||
|
foreach (DataRow row in table.Rows)
|
||||||
|
{
|
||||||
|
foreach (object? item in row.ItemArray)
|
||||||
|
{
|
||||||
|
result += $"{item}\t";
|
||||||
|
}
|
||||||
|
result += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AfterLoad(WebAPIPluginLoader loader, params object[] objs)
|
public override void AfterLoad(WebAPIPluginLoader loader, params object[] objs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user