|
|
@@ -0,0 +1,138 @@
|
|
|
+//using Dapper;
|
|
|
+//using MySql.Data.MySqlClient;
|
|
|
+//using System;
|
|
|
+//using System.Collections.Generic;
|
|
|
+//using System.Data;
|
|
|
+//using System.Linq;
|
|
|
+//using System.Text;
|
|
|
+//using System.Threading.Tasks;
|
|
|
+
|
|
|
+//namespace Winsoft.GOV.XF.WebApi.WXCore.DBProvider
|
|
|
+//{
|
|
|
+// public class DBConfig
|
|
|
+// {
|
|
|
+// public static string DefaultConnectionString { get; set; }
|
|
|
+// }
|
|
|
+// public class BaseDBProvider<T>
|
|
|
+// {
|
|
|
+// #region instance
|
|
|
+// private static object lockObj = new object();
|
|
|
+// private static string createWXUser = "CREATE TABLE IF NOT EXISTS `wxuser` (" +
|
|
|
+// " `id` INT GENERATED ALWAYS AS(0)," +
|
|
|
+// " `openid` VARCHAR(64) NOT NULL," +
|
|
|
+// " `mobile` VARCHAR(11) NULL," +
|
|
|
+// " `email` VARCHAR(100) NULL," +
|
|
|
+// " UNIQUE INDEX `openid_UNIQUE` (`openid` ASC)," +
|
|
|
+// " PRIMARY KEY(`id`));";
|
|
|
+// private static string createWXBatch = "CREATE TABLE IF NOT EXISTS `wxbatch` (" +
|
|
|
+// " `id` VARCHAR(64) NOT NULL," +
|
|
|
+// " `decribe` VARCHAR(500) NULL," +
|
|
|
+// " PRIMARY KEY(`id`));";
|
|
|
+// private static string createWXResource = "CREATE TABLE IF NOT EXISTS `wxresource` (" +
|
|
|
+// " `id` VARCHAR(64) NOT NULL," +
|
|
|
+// " `batchId` VARCHAR(64) NOT NULL," +
|
|
|
+// " `url` VARCHAR(500) NULL," +
|
|
|
+// " PRIMARY KEY(`id`));";
|
|
|
+
|
|
|
+
|
|
|
+// protected static void CreateInstance<K>(ref K singleInstance) where K : BaseDBProvider<T>, new()
|
|
|
+// {
|
|
|
+// if (singleInstance == null)
|
|
|
+// {
|
|
|
+// lock (lockObj)
|
|
|
+// {
|
|
|
+// if (singleInstance == null)
|
|
|
+// {
|
|
|
+// singleInstance = new K();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// #endregion
|
|
|
+
|
|
|
+// #region connection
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// public BaseDBProvider()
|
|
|
+// {
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="connectionStr"></param>
|
|
|
+// /// <returns></returns>
|
|
|
+// protected IDbConnection GetDbConnection()
|
|
|
+// {
|
|
|
+// var connection = new MySqlConnection
|
|
|
+// {
|
|
|
+// ConnectionString = DBConfig.DefaultConnectionString
|
|
|
+// };
|
|
|
+// connection.Open();
|
|
|
+// return connection;
|
|
|
+// }
|
|
|
+
|
|
|
+// protected string BuildTotalSQL(string sql)
|
|
|
+// {
|
|
|
+// var selectCount = new StringBuilder("SELECT COUNT(1) from (");
|
|
|
+// return
|
|
|
+// selectCount.Append(sql + ") as t")
|
|
|
+// .ToString();
|
|
|
+// }
|
|
|
+// /// <summary>
|
|
|
+// /// </summary>
|
|
|
+// /// <param name="total"></param>
|
|
|
+// /// <param name="sql"></param>
|
|
|
+// /// <param name="pageIndex">内部索引从0开始,页码从1开始</param>
|
|
|
+// /// <code>
|
|
|
+// /// if (pageIndex - 1 >= 0)
|
|
|
+// /// {
|
|
|
+// /// pageIndex = pageIndex - 1;
|
|
|
+// /// }
|
|
|
+// /// </code>
|
|
|
+// /// <param name="pageSize"></param>
|
|
|
+// /// <param name="param"></param>
|
|
|
+// /// <param name="areaCode"></param>
|
|
|
+// /// <returns></returns>
|
|
|
+// //protected PagedResult<T> GetPagedList(string sql, int pageIndex, int pageSize, object param)
|
|
|
+// //{
|
|
|
+// // long total = 0;
|
|
|
+// // pageIndex -= 1;
|
|
|
+// // if (pageIndex < 0)
|
|
|
+// // {
|
|
|
+// // pageIndex = 0;
|
|
|
+// // }
|
|
|
+// // if (pageSize <= 0)
|
|
|
+// // {
|
|
|
+// // pageSize = 20;
|
|
|
+// // }
|
|
|
+// // using (IDbConnection connection = GetDbConnection())
|
|
|
+// // {
|
|
|
+// // string totalSql = BuildTotalSQL(sql);
|
|
|
+// // total = connection.Query<long>(totalSql, param).FirstOrDefault();
|
|
|
+// // var list = connection.Query<T>(String.Format(sql + " limit {0},{1}", pageIndex * pageSize, pageSize), param);
|
|
|
+
|
|
|
+// // return new PagedResult<T>(list, pageIndex + 1, pageSize, total);
|
|
|
+
|
|
|
+// // }
|
|
|
+// //}
|
|
|
+
|
|
|
+// protected IEnumerable<T> GetItemList(string sql, int itemIndex, int pageSize, object param)
|
|
|
+// {
|
|
|
+// if (itemIndex < 0)
|
|
|
+// {
|
|
|
+// itemIndex = 0;
|
|
|
+// }
|
|
|
+// if (pageSize <= 0)
|
|
|
+// {
|
|
|
+// pageSize = 20;
|
|
|
+// }
|
|
|
+// using (IDbConnection connection = GetDbConnection())
|
|
|
+// {
|
|
|
+// var list = connection.Query<T>(String.Format(sql + " limit {0},{1}", itemIndex, pageSize), param);
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// #endregion
|
|
|
+// }
|
|
|
+//}
|