|
|
using Dapper;
|
|
|
using Estsh.Core.Base;
|
|
|
using Estsh.Core.Dapper;
|
|
|
using Estsh.Core.Mes.IRepositories;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Repositories;
|
|
|
using System.Collections;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 作者:jack.jia
|
|
|
* 创建时间:2022/06/08
|
|
|
* 描述:针对winform客户端通用的数据处理仓库
|
|
|
*
|
|
|
* *************************************************************************************************/
|
|
|
namespace Estsh.Core.Mes.Repositories
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 部门管理
|
|
|
/// </summary>
|
|
|
public class DataHandleRepository : BaseRepository<BaseEntity>, IDataHandleRepository
|
|
|
{
|
|
|
public DataHandleRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取单个值
|
|
|
/// </summary>
|
|
|
/// <param name="body"></param>
|
|
|
/// <returns></returns>
|
|
|
public object getScalar(RequestBody body)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
if (body.Params != null && body.Params.Count > 0)
|
|
|
{
|
|
|
return dbConn.ExecuteScalar(body.cmd, body.Params);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return dbConn.ExecuteScalar(body.cmd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取数据列表
|
|
|
/// </summary>
|
|
|
/// <param name="body"></param>
|
|
|
/// <returns></returns>
|
|
|
public IEnumerable<dynamic> GetEntityList(RequestBody body)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
if (body.Params != null && body.Params.Count > 0)
|
|
|
{
|
|
|
return dbConn.Query(body.cmd, body.Params);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return dbConn.Query(body.cmd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行更新、删除等操作
|
|
|
/// </summary>
|
|
|
/// <param name="body"></param>
|
|
|
/// <returns></returns>
|
|
|
public int Execute(RequestBody body)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
|
|
|
if (body.Params != null && body.Params.Count > 0)
|
|
|
{
|
|
|
return dbConn.Execute(body.cmd, body.Params);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return dbConn.Execute(body.cmd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 执行存储过程
|
|
|
/// </summary>
|
|
|
/// <param name="body"></param>
|
|
|
/// <returns></returns>
|
|
|
public Hashtable ExecuteSotreProcedure(RequestBody body)
|
|
|
{
|
|
|
using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
|
|
|
{
|
|
|
dbConn.Open();
|
|
|
Hashtable result = new Hashtable();
|
|
|
if (body.Params != null && body.Params.Count > 0)
|
|
|
{
|
|
|
DynamicParameters paras = new DynamicParameters();
|
|
|
foreach (var item in body.Params)
|
|
|
{
|
|
|
paras.Add(item.Key, item.Value);
|
|
|
}
|
|
|
|
|
|
foreach (var item in body.OutParams)
|
|
|
{
|
|
|
if (item.Value.GetType().Name.Equals(typeof(string).Name))
|
|
|
{
|
|
|
paras.Add(item.Key, null, DbType.String, ParameterDirection.Output, int.Parse(item.Value.ToString()));
|
|
|
}
|
|
|
else if (item.Value.GetType().Name.Equals(typeof(int).Name))
|
|
|
{
|
|
|
paras.Add(item.Key, 0, DbType.Int32, ParameterDirection.Output);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
paras.Add(item.Key, item.Value, DbType.String, ParameterDirection.Output);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
IEnumerable<dynamic> dataList = dbConn.Query(body.cmd, paras, commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
foreach (var item in body.OutParams)
|
|
|
{
|
|
|
if (item.Value.GetType().Name.Equals(typeof(string).Name))
|
|
|
{
|
|
|
body.OutParams[item.Key] = paras.Get<string>(item.Key);
|
|
|
}
|
|
|
else if (item.Value.GetType().Name.Equals(typeof(int).Name))
|
|
|
{
|
|
|
body.OutParams[item.Key] = paras.Get<int>(item.Key);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Add("dataList", dataList);
|
|
|
result.Add("outParams", body.OutParams);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
IEnumerable<dynamic> dataList = dbConn.Query(body.cmd,null, commandType: CommandType.StoredProcedure);
|
|
|
result.Add("dataList", dataList);
|
|
|
result.Add("outParams", body.OutParams);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|