146 lines
4.9 KiB
C#
146 lines
4.9 KiB
C#
using Dapper;
|
|
using Repository.BackendRepository.Interface;
|
|
using Repository.BaseRepository.Interface;
|
|
using Repository.Helper;
|
|
using Repository.Services.Implement;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Repository.BackendRepository.Implement
|
|
{
|
|
public class BackendRepository : BaseRepository.Implement.BaseRepository, IBackendRepository
|
|
{
|
|
private BackgroundService backgroundService;
|
|
public BackendRepository(IDatabaseHelper databaseHelper) : base(databaseHelper)
|
|
{
|
|
UseDB = "MYSQL";
|
|
//con = databaseHelper.GetMSSqlConnection();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增記錄人員操作記錄
|
|
/// </summary>
|
|
/// <param name="dict"></param>
|
|
/// <param name="Table_name"></param>
|
|
public void InsertOperatorLog(Dictionary<string, object> dict, string Table_name)
|
|
{
|
|
List<string> results = new List<string>();
|
|
|
|
using (IDbConnection conn = GetDbConnection())
|
|
{
|
|
conn.Open();
|
|
using (var trans = conn.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
List<string> properties = dict.Keys.ToList();
|
|
string sql = InsertGenerateString(properties, Table_name);
|
|
conn.Execute(sql, dict, trans);
|
|
trans.Commit();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
trans.Rollback();
|
|
throw exception;
|
|
}
|
|
finally
|
|
{
|
|
conn.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手動加入資料至背景派送
|
|
/// </summary>
|
|
/// <param name="building_ip"></param>
|
|
/// <param name="building_guid"></param>
|
|
/// <param name="target_table"></param>
|
|
/// <param name="mode"></param>
|
|
/// <param name="parameter"></param>
|
|
/// <returns></returns>
|
|
public async Task ManualInsertBackgroundServiceTask(string building_ip, string building_guid, string target_table, string mode, List<Dictionary<string, object>> parameter = null)
|
|
{
|
|
List<string> results = new List<string>();
|
|
|
|
using (IDbConnection conn = GetDbConnection())
|
|
{
|
|
conn.Open();
|
|
using (var trans = conn.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
backgroundService = new BackgroundService(conn, trans);
|
|
await backgroundService.AddTask("", "", target_table, mode, parameter);
|
|
|
|
trans.Commit();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
trans.Rollback();
|
|
throw exception;
|
|
}
|
|
finally
|
|
{
|
|
conn.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手動加入檔案背至景派送
|
|
/// </summary>
|
|
/// <param name="building_ip"></param>
|
|
/// <param name="building_guid"></param>
|
|
/// <param name="target_table"></param>
|
|
/// <param name="fileInfos"></param>
|
|
/// <returns></returns>
|
|
public async Task ManualInsertFileBackgroundServiceTask(string building_ip, string building_guid, string target_table, List<Models.FileInfo> fileInfos)
|
|
{
|
|
List<string> results = new List<string>();
|
|
|
|
using (IDbConnection conn = GetDbConnection())
|
|
{
|
|
conn.Open();
|
|
using (var trans = conn.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
var file_json = JsonSerializer.Serialize(fileInfos);
|
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>()
|
|
{
|
|
{ "@target_files", file_json }
|
|
};
|
|
|
|
backgroundService = new BackgroundService(conn, trans);
|
|
await backgroundService.AddTask("", "", target_table, fileInfos);
|
|
|
|
trans.Commit();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
trans.Rollback();
|
|
throw exception;
|
|
}
|
|
finally
|
|
{
|
|
conn.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task<string> GetDbAllString()
|
|
{
|
|
return "DBNAme:" + GetDbConnection().ConnectionString + " " + GetDbConnection().Database;
|
|
}
|
|
}
|
|
}
|