Administrator
2 years ago
7 changed files with 188 additions and 19 deletions
@ -0,0 +1,149 @@ |
|||||
|
using Dapper; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Data; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Repositories.Dapper; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount |
||||
|
{ |
||||
|
public class FisOutputDapperRepository : DapperRepository<SettleAccountDbContext>, ITransientDependency |
||||
|
{ |
||||
|
|
||||
|
|
||||
|
public FisOutputDapperRepository(IDbContextProvider<SettleAccountDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
[UnitOfWork(false)] |
||||
|
public virtual bool Execute(string server,string billnum, string date) |
||||
|
{ |
||||
|
string sqlString = |
||||
|
"DECLARE\t@return_value int\n" + |
||||
|
"EXEC\t@return_value = [dbo].[p_wms_output_jit]\n" + |
||||
|
"@billnum = N'{1}',\n" + |
||||
|
"@type = 0,\n" + |
||||
|
"@date = N'{2}'\n" + |
||||
|
"SELECT\t'Return Value' = @return_value\n"; |
||||
|
|
||||
|
string _sql = string.Format(sqlString,server, billnum, date); |
||||
|
var _query = DbConnection.ExecuteScalar(_sql, null, null, 1200, System.Data.CommandType.Text); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
public virtual async Task<List<T>> GetListBySqlAsync<T>(string sql, bool isTrans = false) |
||||
|
{ |
||||
|
if (isTrans) |
||||
|
{ |
||||
|
IDbConnection conn = await GetDbConnectionAsync(); |
||||
|
IDbTransaction trans = await GetDbTransactionAsync(); |
||||
|
return (await conn.QueryAsync<T>(sql, null, trans)) |
||||
|
.ToList(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
IDbConnection conn = await GetDbConnectionAsync(); |
||||
|
return (await conn.QueryAsync<T>(sql)) |
||||
|
.ToList(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<T> GetSingleBySqlAsync<T>(string sql, bool isTrans = false) |
||||
|
{ |
||||
|
if (isTrans) |
||||
|
{ |
||||
|
IDbConnection conn = await GetDbConnectionAsync(); |
||||
|
IDbTransaction trans = await GetDbTransactionAsync(); |
||||
|
return await conn.QuerySingleOrDefaultAsync<T>(sql, null, trans); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
IDbConnection conn = await GetDbConnectionAsync(); |
||||
|
return await conn.QuerySingleOrDefaultAsync<T>(sql); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public virtual async Task<int> ExecuteSqlAsync(string sql, object obj = null, bool isTrans = false) |
||||
|
{ |
||||
|
if (isTrans) |
||||
|
{ |
||||
|
//return await DbConnection.ExecuteAsync("update People set Name = @NewName", new { NewName = name }, DbTransaction);
|
||||
|
IDbConnection conn = await GetDbConnectionAsync(); |
||||
|
IDbTransaction trans = await GetDbTransactionAsync(); |
||||
|
return await conn.ExecuteAsync(sql, obj, trans); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
//return await DbConnection.ExecuteAsync("update People set Name = @NewName", new { NewName = name }, DbTransaction);
|
||||
|
IDbConnection conn = await GetDbConnectionAsync(); |
||||
|
return await conn.ExecuteAsync(sql, obj); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
#region 同步方法
|
||||
|
public virtual List<T> GetListBySql<T>(string sql, bool isTrans = false) |
||||
|
{ |
||||
|
if (isTrans) |
||||
|
{ |
||||
|
IDbConnection conn = GetDbConnectionAsync().GetAwaiter().GetResult(); |
||||
|
IDbTransaction trans = GetDbTransactionAsync().GetAwaiter().GetResult(); |
||||
|
return (conn.Query<T>(sql, null, trans)) |
||||
|
.ToList(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
IDbConnection conn = (IDbConnection)GetDbConnectionAsync().GetAwaiter().GetResult(); |
||||
|
return (conn.Query<T>(sql)) |
||||
|
.ToList(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public virtual T GetSingleBySql<T>(string sql, bool isTrans = false) |
||||
|
{ |
||||
|
if (isTrans) |
||||
|
{ |
||||
|
IDbConnection conn = GetDbConnectionAsync().GetAwaiter().GetResult(); |
||||
|
IDbTransaction trans = GetDbTransactionAsync().GetAwaiter().GetResult(); |
||||
|
return conn.QuerySingleOrDefault<T>(sql, null, trans); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
IDbConnection conn = (IDbConnection)GetDbConnectionAsync().GetAwaiter().GetResult(); |
||||
|
return conn.QuerySingleOrDefault<T>(sql); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public virtual int ExecuteSql(string sql, object obj = null, bool isTrans = false) |
||||
|
{ |
||||
|
if (isTrans) |
||||
|
{ |
||||
|
IDbConnection conn = GetDbConnectionAsync().GetAwaiter().GetResult(); |
||||
|
IDbTransaction trans = GetDbTransactionAsync().GetAwaiter().GetResult(); |
||||
|
return conn.Execute(sql, obj, trans); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
IDbConnection conn = (IDbConnection)GetDbConnectionAsync().GetAwaiter().GetResult(); |
||||
|
return conn.Execute(sql, obj); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#endregion
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue