Initial_commit_SecMPS_v2
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Dapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using VolPro.Core.Const;
|
||||
using VolPro.Core.Enums;
|
||||
|
||||
namespace VolPro.Core.Dapper
|
||||
{
|
||||
public class DapperParseGuidTypeHandler
|
||||
{
|
||||
public static void InitParseGuid()
|
||||
{
|
||||
if (DBType.Name == DbCurrentType.MySql.ToString())
|
||||
{
|
||||
SqlMapper.AddTypeHandler(new DapperParseGuidTypeHandlerMySql());
|
||||
SqlMapper.RemoveTypeMap(typeof(Guid?));
|
||||
}
|
||||
else if (DBType.Name == DbCurrentType.Oracle.ToString())
|
||||
{
|
||||
SqlMapper.AddTypeHandler(new DapperParseGuidTypeHandlerOracle());
|
||||
SqlMapper.RemoveTypeMap(typeof(Guid?));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Dapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VolPro.Core.Const;
|
||||
using VolPro.Core.Enums;
|
||||
|
||||
namespace VolPro.Core.Dapper
|
||||
{
|
||||
public class DapperParseGuidTypeHandlerMySql : SqlMapper.TypeHandler<Guid?>
|
||||
{
|
||||
public override void SetValue(IDbDataParameter parameter, Guid? guid)
|
||||
{
|
||||
parameter.Value = guid.ToString();
|
||||
}
|
||||
|
||||
public override Guid? Parse(object value)
|
||||
{
|
||||
if (value == null || value.ToString() == "")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (value.GetType() == typeof(string))
|
||||
{
|
||||
return new Guid((string)value);
|
||||
}
|
||||
return (Guid)value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Dapper;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VolPro.Core.Dapper
|
||||
{
|
||||
|
||||
public class DapperParseGuidTypeHandlerOracle : TypeHandlerBase<Guid>
|
||||
{
|
||||
public override void SetValue(IDbDataParameter parameter, Guid value)
|
||||
{
|
||||
SetOracleDbTypeOnParameter(parameter, "Raw", 16);
|
||||
parameter.Value = value.ToByteArray();
|
||||
}
|
||||
|
||||
public override Guid Parse(object value)
|
||||
{
|
||||
if (value is byte[] bytearray)
|
||||
{
|
||||
return new Guid(bytearray);
|
||||
}
|
||||
throw new NotImplementedException($"Dont know how to convert a {value.GetType().Name} to a System.Guid.");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class TypeHandlerBase<T> : SqlMapper.TypeHandler<T>
|
||||
{
|
||||
private class DictionaryKey
|
||||
{
|
||||
public Type ParameterType { get; set; }
|
||||
public string OracleTypeName { get; set; }
|
||||
}
|
||||
|
||||
private class DictionaryKeyComparer : IEqualityComparer<DictionaryKey>
|
||||
{
|
||||
public bool Equals(DictionaryKey x, DictionaryKey y)
|
||||
{
|
||||
if (x == null && y != null) return false;
|
||||
if (x != null && y != null) return false;
|
||||
|
||||
return x.ParameterType == y.ParameterType && x.OracleTypeName.Equals(y.OracleTypeName);
|
||||
}
|
||||
|
||||
public int GetHashCode(DictionaryKey obj)
|
||||
{
|
||||
return 17 + obj.ParameterType.GetHashCode() * 23 + obj.OracleTypeName.GetHashCode() * 31;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly ConcurrentDictionary<DictionaryKey, Action<IDbDataParameter>> OracleDbTypeProperty =
|
||||
new ConcurrentDictionary<DictionaryKey, Action<IDbDataParameter>>(new DictionaryKeyComparer());
|
||||
|
||||
protected void SetOracleDbTypeOnParameter(IDbDataParameter parameter, string oracleTypeName, int? length = null)
|
||||
{
|
||||
var setter = OracleDbTypeProperty.GetOrAdd(new DictionaryKey { ParameterType = parameter.GetType(), OracleTypeName = oracleTypeName }, CreateSetTypeAction);
|
||||
setter(parameter);
|
||||
if (length.HasValue)
|
||||
{
|
||||
parameter.Size = length.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Action<IDbDataParameter> CreateSetTypeAction(DictionaryKey key)
|
||||
{
|
||||
Type enumType = key.ParameterType.Assembly.GetType($"{key.ParameterType.Namespace}.OracleDbType");
|
||||
var enumValue = Enum.Parse(enumType, key.OracleTypeName);
|
||||
var inputVariable = Expression.Parameter(typeof(IDbDataParameter));
|
||||
var convertExpression = Expression.Convert(inputVariable, key.ParameterType);
|
||||
|
||||
var expression = Expression.Assign(
|
||||
Expression.PropertyOrField(convertExpression, "OracleDbType"),
|
||||
Expression.Constant(enumValue));
|
||||
|
||||
return Expression.Lambda<Action<IDbDataParameter>>(expression, inputVariable).Compile();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
173
api_sqlsugar/VolPro.Core/Dapper/ISqlDapper.cs
Normal file
173
api_sqlsugar/VolPro.Core/Dapper/ISqlDapper.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Data;
|
||||
//using System.Data.SqlClient;
|
||||
//using System.Linq.Expressions;
|
||||
//using System.Threading.Tasks;
|
||||
//using Dapper;
|
||||
|
||||
//namespace VolPro.Core.Dapper
|
||||
//{
|
||||
// public interface ISqlDapper
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 超时时间(秒)2021.05.05
|
||||
// /// </summary>
|
||||
// /// <param name="timeout"></param>
|
||||
// /// <returns></returns>
|
||||
// ISqlDapper SetTimout(int timeout);
|
||||
// void BeginTransaction(Func<ISqlDapper, bool> action, Action<Exception> error);
|
||||
// List<T> QueryList<T>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// Task<IEnumerable<T>> QueryListAsync<T>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// T QueryFirst<T>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) where T : class;
|
||||
|
||||
// Task<T> QueryFirstAsync<T>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) where T : class;
|
||||
|
||||
// Task<dynamic> QueryDynamicFirstAsync(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// dynamic QueryDynamicFirst(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// Task<dynamic> QueryDynamicListAsync(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// List<dynamic> QueryDynamicList(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// object ExecuteScalar(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// Task<object> ExecuteScalarAsync(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// int ExcuteNonQuery(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// Task<int> ExcuteNonQueryAsync(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// IDataReader ExecuteReader(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
// SqlMapper.GridReader QueryMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// Task<(IEnumerable<T1>, IEnumerable<T2>)> QueryMultipleAsync<T1, T2>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<T1>, List<T2>) QueryMultiple<T1, T2>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// Task<(IEnumerable<T1>, IEnumerable<T2>, IEnumerable<T3>)> QueryMultipleAsync<T1, T2, T3>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<T1>, List<T2>, List<T3>) QueryMultiple<T1, T2, T3>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// Task<(IEnumerable<dynamic>, IEnumerable<dynamic>)> QueryDynamicMultipleAsync(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<dynamic>, List<dynamic>) QueryDynamicMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// Task<(IEnumerable<T1>, IEnumerable<T2>, IEnumerable<T3>, IEnumerable<T4>)> QueryMultipleAsync<T1, T2, T3, T4>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<T1>, List<T2>, List<T3>, List<T4>) QueryMultiple<T1, T2, T3, T4>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// Task<(IEnumerable<T1>, IEnumerable<T2>, IEnumerable<T3>, IEnumerable<T4>, IEnumerable<T5>)> QueryMultipleAsync<T1, T2, T3, T4, T5>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<T1>, List<T2>, List<T3>, List<T4>, List<T5>) QueryMultiple<T1, T2, T3, T4, T5>(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// Task<(IEnumerable<dynamic>, IEnumerable<dynamic>)> QueryDynamicMultipleAsync2(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<dynamic>, List<dynamic>) QueryDynamicMultiple2(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// Task<(IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>)> QueryDynamicMultipleAsync3(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
// (List<dynamic>, List<dynamic>, List<dynamic>) QueryDynamicMultiple3(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// Task<(IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>, IEnumerable<dynamic>)> QueryDynamicMultipleAsync5(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
// (List<dynamic>, List<dynamic>, List<dynamic>, List<dynamic>, List<dynamic>) QueryDynamicMultiple5(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <typeparam name="T"></typeparam>
|
||||
// /// <param name="entities"></param>
|
||||
// /// <param name="updateFileds">指定插入的字段</param>
|
||||
// /// <param name="beginTransaction">是否开启事务</param>
|
||||
// /// <returns></returns>
|
||||
// int Add<T>(T entity, Expression<Func<T, object>> updateFileds = null, bool beginTransaction = false);
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <typeparam name="T"></typeparam>
|
||||
// /// <param name="entities"></param>
|
||||
// /// <param name="updateFileds">指定插入的字段</param>
|
||||
// /// <param name="beginTransaction">是否开启事务</param>
|
||||
// /// <returns></returns>
|
||||
// int AddRange<T>(IEnumerable<T> entities, Expression<Func<T, object>> updateFileds = null, bool beginTransaction = false);
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// sqlserver使用的临时表参数化批量更新,mysql批量更新待发开
|
||||
// /// </summary>
|
||||
// /// <typeparam name="T"></typeparam>
|
||||
// /// <param name="entity">实体必须带主键</param>
|
||||
// /// <param name="updateFileds">指定更新的字段x=new {x.a,x.b}</param>
|
||||
// /// <param name="beginTransaction">是否开启事务</param>
|
||||
// /// <returns></returns>
|
||||
// int Update<T>(T entity, Expression<Func<T, object>> updateFileds = null, bool beginTransaction = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// sqlserver使用的临时表参数化批量更新,mysql批量更新待发开
|
||||
// /// </summary>
|
||||
// /// <typeparam name="T"></typeparam>
|
||||
// /// <param name="entity">实体必须带主键</param>
|
||||
// /// <param name="updateFileds">指定更新的字段x=new {x.a,x.b}</param>
|
||||
// /// <param name="beginTransaction">是否开启事务</param>
|
||||
// /// <returns></returns>
|
||||
// int UpdateRange<T>(IEnumerable<T> entities, Expression<Func<T, object>> updateFileds = null, bool beginTransaction = false);
|
||||
|
||||
// int DelWithKey<T>(params object[] keys);
|
||||
// int DelWithKey<T>(bool beginTransaction = false, params object[] keys);
|
||||
// /// <summary>
|
||||
// /// sqlserver批量写入
|
||||
// /// 使用时DataTable table表字段顺序要和数据库字段顺序一致
|
||||
// /// <summary>
|
||||
// /// mysql批量写入
|
||||
// /// </summary>
|
||||
// /// <param name="table"></param>
|
||||
// /// <param name="tableName"></param>
|
||||
// /// <param name="tmpPath">默认当前下载路径</param>
|
||||
// /// <param name="fileName">默认$"{DateTime.Now.ToString("yyyyMMddHHmmss")}.csv"</param>
|
||||
// /// <returns></returns>
|
||||
// int BulkInsert(DataTable table, string tableName, SqlBulkCopyOptions? sqlBulkCopyOptions = null, string fileName = null, string tmpPath = null);
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <typeparam name="T"></typeparam>
|
||||
// /// <param name="entities"></param>
|
||||
// /// <param name="tableName"></param>
|
||||
// /// <param name="columns">所包含的列</param>
|
||||
// /// <param name="sqlBulkCopyOptions"></param>
|
||||
// /// <param name="fileName"></param>
|
||||
// /// <param name="tmpPath"></param>
|
||||
// /// <returns></returns>
|
||||
// int BulkInsert<T>(List<T> entities, string tableName = null,
|
||||
// Expression<Func<T, object>> columns = null,
|
||||
// SqlBulkCopyOptions? sqlBulkCopyOptions = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 开启事务
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// ISqlDapper BeginTrans();
|
||||
|
||||
// /// <summary>
|
||||
// /// 提交
|
||||
// /// </summary>
|
||||
// void Commit();
|
||||
|
||||
// /// <summary>
|
||||
// /// 回滚
|
||||
// /// </summary>
|
||||
// void Rollback();
|
||||
|
||||
// DataTable QueryDataTable(string sql, object dbParameter, CommandType commandType = CommandType.StoredProcedure);
|
||||
// }
|
||||
//}
|
||||
1002
api_sqlsugar/VolPro.Core/Dapper/SqlDapper.cs
Normal file
1002
api_sqlsugar/VolPro.Core/Dapper/SqlDapper.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user