Skip to content

Commit

Permalink
feat:add imaotai.core
Browse files Browse the repository at this point in the history
  • Loading branch information
bingtianyiyan committed Jul 16, 2024
1 parent e73a905 commit 7155367
Show file tree
Hide file tree
Showing 35 changed files with 309 additions and 289 deletions.
92 changes: 92 additions & 0 deletions IMaoTai.Core/CommonX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Newtonsoft.Json;
using System.Configuration;

namespace IMaoTai.Core
{
public class CommonX
{
public const string CacheDir = "cache";

// 内部使用缓存文件
public static string _productListFile = Path.Combine(CacheDir, "productList.json");

public static string _sessionIdFile = Path.Combine(CacheDir, "mtSessionId.txt");

// 商店共用缓存文件
public static string StoreListFile = Path.Combine(CacheDir, "storeList.json");

//用户信息缓存
public static string UserListFile = Path.Combine(CacheDir, "userList.json");

//日志信息缓存
public static string LogListFile = Path.Combine(CacheDir, "logList.json");

/// <summary>
/// 订单数据库表名
/// </summary>
public const string OrderDatabasePath = "cache/imaotai.db";

/// <summary>
/// 订单数据库连接字符串
/// </summary>
public static string OrderDatabaseConnectStr = ConfigurationManager.AppSettings["DefaultConnStr"] ?? "Data Source=cache/imaotai.db;";

public static string DbType = ConfigurationManager.AppSettings["DbType"] ?? "Sqlite";

//是否启用本地文件存储
public static bool LoadFromFile = ConfigurationManager.AppSettings["LoadFromFile"].ToString() == "1";

/// <summary>
/// 获取Freesql数据库类型
/// </summary>
/// <returns></returns>
public static FreeSql.DataType GetFreeSqlDataType()
{
if (DbType == FreeSql.DataType.MySql.ToString())
{
return FreeSql.DataType.MySql;
}
else if (DbType == FreeSql.DataType.Oracle.ToString())
{
return FreeSql.DataType.Oracle;
}
else if (DbType == FreeSql.DataType.SqlServer.ToString())
{
return FreeSql.DataType.SqlServer;
}
return FreeSql.DataType.Sqlite;
}

/// <summary>
/// 茅台会话ID
/// </summary>
public static string MtSessionId = "";

public static void WriteCache(string filename, string content)
{
var path = Path.Combine(CacheDir, filename);
File.WriteAllText(path, content);
}

public static List<T> GetListFromFile<T>(string path) where T : class
{
if (File.Exists(path))
{
var json = File.ReadAllText(path);
var result = JsonConvert.DeserializeObject<List<T>>(json);
return result;
}
return new List<T>();
}

public static void WriteDataToCache<T>(string path, List<T> list)
{
File.WriteAllText(path, JsonConvert.SerializeObject(list));
}

public static void FileContentClear(string path, string content)
{
File.WriteAllText(path, content);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using IMaoTai.Entity;
using IMaoTai.Core.Entity;

namespace IMaoTai.Domain
namespace IMaoTai.Core.Domain
{
/// <summary>
/// 预约项目页面对应的VM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using IMaoTai.Entity;
using IMaoTai.Core.Entity;

namespace IMaoTai.Domain
namespace IMaoTai.Core.Domain
{
/// <summary>
/// 日志用户控件的ViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using IMaoTai.Entity;
using IMaoTai.Core.Entity;

namespace IMaoTai.Domain
namespace IMaoTai.Core.Domain
{
/// <summary>
/// 门店列表Page的ViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using IMaoTai.Entity;
using IMaoTai.Core.Entity;

namespace IMaoTai.Domain
namespace IMaoTai.Core.Domain
{
/// <summary>
/// 用户管理 - 搜索的condition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace IMaoTai.Entity
namespace IMaoTai.Core.Entity
{
/// <summary>
/// I茅台预约商品信息
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FreeSql.DataAnnotations;

namespace IMaoTai.Entity
namespace IMaoTai.Core.Entity
{
/// <summary>
/// 日志的模型
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace IMaoTai.Entity
namespace IMaoTai.Core.Entity
{
public class MapPoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace IMaoTai.Entity
namespace IMaoTai.Core.Entity
{
public class ProductEntity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FreeSql.DataAnnotations;
using Newtonsoft.Json.Linq;

namespace IMaoTai.Entity
namespace IMaoTai.Core.Entity
{
/// <summary>
/// 店铺的实体类
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FreeSql.DataAnnotations;
using Newtonsoft.Json.Linq;

namespace IMaoTai.Entity
namespace IMaoTai.Core.Entity
{
public class UserEntity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using FreeSql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;

namespace IMaoTai.Helpers
namespace IMaoTai.Core.Helpers
{
public static class ExtensionHelper
public static class ExtensionHelper
{
public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
{
Expand All @@ -25,10 +19,9 @@ public static IEnumerable<T> WhereIf<T>(this IEnumerable<T> query, bool conditio
return condition ? query.Where(predicate) : query;
}

public static IEnumerable<T> PageSkipAndTake<T>(this IEnumerable<T> query, int skip,int takeSize)
public static IEnumerable<T> PageSkipAndTake<T>(this IEnumerable<T> query, int skip, int takeSize)
{
return query.Skip((skip - 1) * takeSize).Take(takeSize);
}

}
}
}
Loading

0 comments on commit 7155367

Please sign in to comment.