添加项目文件。
This commit is contained in:
96
SamplePre.DAL/DAL/LogDal.cs
Normal file
96
SamplePre.DAL/DAL/LogDal.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Dapper;
|
||||
using Models.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using System.Windows.Documents;
|
||||
|
||||
namespace DataDAL.DBContext
|
||||
{
|
||||
public class LogDal
|
||||
{
|
||||
|
||||
public LogDal()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存日志
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="sysDict"></param>
|
||||
/// <returns></returns>
|
||||
public int SaveLog(run_log_info runLogInfo)
|
||||
{
|
||||
|
||||
//using (IDbConnection dbConnection = new DapperDBContext().Connection)
|
||||
//{
|
||||
// dbConnection.Open();
|
||||
|
||||
// string insertSql = @"insert into run_log_info ( id,run_date
|
||||
// ,log_level
|
||||
// ,log_content,log_type
|
||||
// )
|
||||
// values(@id,@run_date
|
||||
// ,@log_level
|
||||
// ,@log_content ,@log_type
|
||||
// )";
|
||||
|
||||
|
||||
// var item = dbConnection.QueryFirstOrDefault<run_log_info>(insertSql, runLogInfo);
|
||||
|
||||
return 1;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询日志信息
|
||||
/// </summary>
|
||||
public List<run_log_info> QueryLogByDate(DateTime dt1,DateTime dt2)
|
||||
{
|
||||
using (IDbConnection dbConnection = new DapperDBContext().Connection)
|
||||
{
|
||||
dbConnection.Open();
|
||||
|
||||
string querySql = "select * from run_log_info where run_date >= @dt1 and run_date <= @dt2";
|
||||
|
||||
List<run_log_info> data = dbConnection.Query<run_log_info>(querySql, new { dt1 = dt1,dt2 = dt2 }).ToList();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 查询二维码开始编号
|
||||
///// </summary>
|
||||
//public string QueryQrcode()
|
||||
//{
|
||||
// using (IDbConnection dbConnection = new BaseDBContext().Connection)
|
||||
// {
|
||||
// dbConnection.Open();
|
||||
|
||||
// string qrcode = "";
|
||||
|
||||
// List<sys_dict> data = dbConnection.Query<sys_dict>("select * from sys_dict where data_type='二维码编号'").ToList();
|
||||
// if (data.Count > 0)
|
||||
// {
|
||||
// qrcode = (int.Parse(data[0].data_value) + 1).ToString("0000");
|
||||
// }
|
||||
// return qrcode;
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
72
SamplePre.DAL/DAL/SOPDal.cs
Normal file
72
SamplePre.DAL/DAL/SOPDal.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using Dapper;
|
||||
using DataDAL.DBContext;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.DAL.DBContext;
|
||||
using SamplePre.Models.Ext;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Dapper.SqlMapper;
|
||||
|
||||
namespace SamplePre.DAL
|
||||
{
|
||||
public class SOPDal
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取标准下的动作,动作中包含参数
|
||||
/// </summary>
|
||||
/// <param name="standId"></param>
|
||||
/// <returns></returns>
|
||||
public List<sys_standard_action_ext> QueryStandardProcessByStandardId(string standId)
|
||||
{
|
||||
using (IDbConnection dbConnection = new DapperDBContext().Connection)
|
||||
{
|
||||
dbConnection.Open();
|
||||
|
||||
string querySql = @"
|
||||
SELECT
|
||||
a.*,
|
||||
b.action_name,
|
||||
b.action_unit,
|
||||
e.data_value AS action_unit_name,
|
||||
b.remark,
|
||||
c.all_param
|
||||
FROM
|
||||
sys_standard_action a
|
||||
LEFT JOIN sys_action b ON a.process_id = b.id
|
||||
LEFT JOIN sys_dict e ON b.action_unit = e.id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
x.action_id,
|
||||
x.action_seqno,
|
||||
GROUP_CONCAT( CONCAT( y.title, ':', x.data_value, y.unit ) SEPARATOR ',' ) AS all_param
|
||||
FROM
|
||||
sys_standard_action_parm x
|
||||
LEFT JOIN sys_parm y ON x.parm_id = y.id
|
||||
WHERE
|
||||
x.standard_id = @standId
|
||||
GROUP BY
|
||||
x.action_id,
|
||||
x.action_seqno
|
||||
) c ON a.process_id = c.action_id
|
||||
AND a.process_no = c.action_seqno
|
||||
WHERE
|
||||
a.standard_id = @standId
|
||||
ORDER BY a.process_no
|
||||
";
|
||||
|
||||
List<sys_standard_action_ext> data = dbConnection.Query<sys_standard_action_ext>(querySql, new { standId = standId }).ToList();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
24
SamplePre.DAL/DAL/SampleSequenceDal.cs
Normal file
24
SamplePre.DAL/DAL/SampleSequenceDal.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Dapper;
|
||||
using DataDAL.DBContext;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.DAL.DBContext;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Dapper.SqlMapper;
|
||||
|
||||
namespace SamplePre.DAL
|
||||
{
|
||||
public class SampleSequenceDal
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
59
SamplePre.DAL/DAL/SystemDal.cs
Normal file
59
SamplePre.DAL/DAL/SystemDal.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Dapper;
|
||||
using DataDAL.DBContext;
|
||||
using Models.Models;
|
||||
using SamplePre.DAL.DBContext;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePre.DAL
|
||||
{
|
||||
public class SystemDal
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户数据
|
||||
/// </summary>
|
||||
/// <param name="standId"></param>
|
||||
/// <returns></returns>
|
||||
public List<config_user_ext> QueryUserData()
|
||||
{
|
||||
using (IDbConnection dbConnection = new DapperDBContext().Connection)
|
||||
{
|
||||
dbConnection.Open();
|
||||
|
||||
string querySql = @"
|
||||
SELECT a.*,b.all_role_names from config_user a
|
||||
LEFT JOIN (
|
||||
|
||||
SELECT
|
||||
x.user_id,
|
||||
|
||||
GROUP_CONCAT(x.role_id SEPARATOR ',') AS all_role_ids,
|
||||
|
||||
GROUP_CONCAT(y.`name` SEPARATOR ',') AS all_role_names
|
||||
FROM
|
||||
config_user_role x
|
||||
LEFT JOIN config_role y ON x.role_id = y.id
|
||||
|
||||
GROUP BY
|
||||
x.user_id
|
||||
|
||||
) b on a.id = b.user_id
|
||||
";
|
||||
|
||||
List<config_user_ext> data = dbConnection.Query<config_user_ext>(querySql).ToList();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
108
SamplePre.DAL/DBContext/DBFactory.cs
Normal file
108
SamplePre.DAL/DBContext/DBFactory.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using Models.Const;
|
||||
using SamplePre.Common;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePre.DAL.DBContext
|
||||
{
|
||||
public class DBFactory
|
||||
{
|
||||
|
||||
#region 单例实例
|
||||
private static readonly Lazy<SqlSugarClient> _lazySqlSugarClient = new Lazy<SqlSugarClient>(() =>
|
||||
{
|
||||
return CreateSqlSugarClient();
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认数据库的SqlSugarClient单例实例
|
||||
/// </summary>
|
||||
public static SqlSugarClient Instance => _lazySqlSugarClient.Value;
|
||||
#endregion
|
||||
|
||||
#region 从App.config读取的配置项(静态构造函数初始化,仅执行一次)
|
||||
private static readonly string _connStr; // 数据库连接字符串
|
||||
private static readonly bool _isAutoCloseConn; // 是否自动关闭连接
|
||||
|
||||
/// <summary>
|
||||
/// 静态构造函数:读取App.config配置,初始化全局参数
|
||||
/// </summary>
|
||||
static DBFactory()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 1. 读取数据库连接字符串(MySQL)
|
||||
|
||||
_connStr = SystemConst.SysConfigInfo.DbConfig.MySql.ConnStr;//"Data Source=localhost;Database=fanghuayuan;AllowLoadLocalInfile=true;User ID=root;Password=123;allowPublicKeyRetrieval=true;pooling=true;port=3306;";
|
||||
|
||||
// 2. 读取SqlSugar全局配置(AppSettings节点)
|
||||
_isAutoCloseConn = true;//Convert.ToBoolean(ConfigurationManager.AppSettings["SqlSugar_IsAutoCloseConnection"]);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("SqlSugar工厂类配置读取失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 核心方法:创建SqlSugarClient并配置全局参数
|
||||
/// <summary>
|
||||
/// 封装SqlSugarClient的创建、数据库配置、全局AOP
|
||||
/// </summary>
|
||||
/// <returns>配置完成的SqlSugarClient实例</returns>
|
||||
private static SqlSugarClient CreateSqlSugarClient()
|
||||
{
|
||||
// 1. 数据库连接核心配置(按需修改DbType:对应连接字符串)
|
||||
var connectionConfig = new ConnectionConfig
|
||||
{
|
||||
ConnectionString = _connStr, // 连接字符串
|
||||
DbType = SqlSugar.DbType.MySql, // 数据库类型:
|
||||
IsAutoCloseConnection = _isAutoCloseConn, // 自动关闭连接(必开,避免连接泄漏)
|
||||
InitKeyType = InitKeyType.Attribute, // 从实体类特性读取主键/自增配置(核心)
|
||||
|
||||
};
|
||||
|
||||
// 2. 创建SqlSugarClient实例
|
||||
var db = new SqlSugarClient(connectionConfig);
|
||||
|
||||
db.Aop.OnError = (ex) =>
|
||||
{
|
||||
string errorLog = $@"【SQL执行异常】{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}
|
||||
【异常信息】{ex.Message}
|
||||
【SQL语句】{ex.Sql}";
|
||||
// 异常日志写入本地文件
|
||||
LoggerHelper.Logger.Error(errorLog);
|
||||
|
||||
};
|
||||
|
||||
return db;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 辅助:手动释放资源(单例模式一般无需调用,程序退出时可选)
|
||||
/// <summary>
|
||||
/// 手动释放SqlSugarClient资源(仅特殊场景使用)
|
||||
/// </summary>
|
||||
public static void DisposeInstance()
|
||||
{
|
||||
if (_lazySqlSugarClient.IsValueCreated)
|
||||
{
|
||||
Instance.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
27
SamplePre.DAL/DBContext/DapperDBContext.cs
Normal file
27
SamplePre.DAL/DBContext/DapperDBContext.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Models.Const;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataDAL.DBContext
|
||||
{
|
||||
public class DapperDBContext
|
||||
{
|
||||
public IDbConnection Connection { get; set; }
|
||||
|
||||
//string connectionString = "Data Source=localhost;Database=fanghuayuan;AllowLoadLocalInfile=true;User ID=root;Password=123;allowPublicKeyRetrieval=true;pooling=true;port=3306;"; //"Data Source=DESKTOP-T4SGEQ7;Initial Catalog=防化院毒素;Integrated Security=True;TrustServerCertificate=True";
|
||||
|
||||
public DapperDBContext()
|
||||
{
|
||||
|
||||
Connection = new MySqlConnection(SystemConst.SysConfigInfo.DbConfig.MySql.ConnStr);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
22
SamplePre.DAL/SamplePre.DAL.csproj
Normal file
22
SamplePre.DAL/SamplePre.DAL.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.0.151" />
|
||||
<PackageReference Include="MySql.Data" Version="9.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="SqlSugar" Version="5.1.4.207" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SamplePre.Common\SamplePre.Common.csproj" />
|
||||
<ProjectReference Include="..\SamplePre.Communication\SamplePre.Communication.csproj" />
|
||||
<ProjectReference Include="..\SamplePre.Models\SamplePre.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user