New file |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="SqlSugarCore" Version="5.1.4.93" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <Folder Include="DTO\" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
New file |
| | |
| | | using SqlSugar; |
| | | |
| | | namespace Document.Model |
| | | { |
| | | [SugarTable("Document_UserInfo")] |
| | | public class Document_UserInfo |
| | | { |
| | | /// <summary> |
| | | /// 账号 |
| | | /// </summary> |
| | | [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "账号")] |
| | | public int UserId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 用户名称 |
| | | /// </summary> |
| | | [SugarColumn(Length = 50, ColumnDescription = "用户名称")] |
| | | public string UserName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 是否管理员 |
| | | /// </summary> |
| | | [SugarColumn(ColumnDescription = "是否管理员")] |
| | | public int IsManager { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 是否启用 |
| | | /// </summary> |
| | | [SugarColumn(ColumnDescription = "是否启用")] |
| | | public int IsUsed { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="NLog" Version="5.2.2" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <None Update="NLog.config"> |
| | | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
| | | </None> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8" ?> |
| | | <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"> |
| | | |
| | | <targets> |
| | | |
| | | <target xsi:type="File" name="info_file" fileName="${basedir}/logs/${shortdate}_info.log" layout="${longdate} ${uppercase:${level}} ${message}"/> |
| | | <target xsi:type="File" name="error_file" fileName="${basedir}/logs/${shortdate}_error.log" layout="${longdate} ${uppercase:${level}} ${message} ${exception:stacktrace}" /> |
| | | |
| | | <!-- |
| | | Write events to a file with the date in the filename. |
| | | <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" |
| | | layout="${longdate} ${uppercase:${level}} ${message}" /> |
| | | --> |
| | | </targets> |
| | | |
| | | <rules> |
| | | <logger name="*" minlevel="Info" maxlevel="Info" writeTo="info_file" /> |
| | | <logger name="*" minlevel="Error" maxlevel="Error" writeTo="error_file" /> |
| | | |
| | | <!-- |
| | | Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" |
| | | <logger name="*" minlevel="Debug" writeTo="f" /> |
| | | --> |
| | | </rules> |
| | | </nlog> |
New file |
| | |
| | | using NLog; |
| | | |
| | | namespace Document.Unility |
| | | { |
| | | public class NLogProvider |
| | | { |
| | | |
| | | private NLogProvider() |
| | | { |
| | | logger = LogManager.GetLogger("Logger");//.GetCurrentClassLogger(); |
| | | } |
| | | |
| | | private readonly Logger logger = null; |
| | | private static NLogProvider logProvider = null; |
| | | |
| | | /// <summary> |
| | | /// 静态实例 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static NLogProvider GetInstance() |
| | | { |
| | | if (logProvider == null) |
| | | { |
| | | logProvider = new NLogProvider(); |
| | | } |
| | | return logProvider; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Info |
| | | /// </summary> |
| | | /// <param name="txt"></param> |
| | | public void Info(string txt) |
| | | { |
| | | if (logger != null) |
| | | logger.Info(txt); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Error |
| | | /// </summary> |
| | | /// <param name="er"></param> |
| | | public void Error(Exception er) |
| | | { |
| | | if (logger != null) |
| | | logger.Error(er); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Error |
| | | /// </summary> |
| | | /// <param name="str"></param> |
| | | public void Error(string str) |
| | | { |
| | | if (logger != null) |
| | | logger.Error(str); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | namespace Document.Unility |
| | | { |
| | | /// <summary> |
| | | /// 分页查询条件基类 |
| | | /// </summary> |
| | | public class PageBaseSearch |
| | | { |
| | | /// <summary> |
| | | /// 页码 |
| | | /// </summary> |
| | | public int PageIndex { get; set; } = 1; |
| | | |
| | | /// <summary> |
| | | /// 分页大小 |
| | | /// </summary> |
| | | public int PageSize { get; set; } = 20; |
| | | |
| | | /// <summary> |
| | | /// 开始日期 |
| | | /// </summary> |
| | | public DateTime? StartTime { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 结束日期 |
| | | /// </summary> |
| | | public DateTime? EndTime { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | namespace Document.Unility |
| | | { |
| | | /// <summary> |
| | | /// 分页数据信息 |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | public class PageResult<T> |
| | | { |
| | | /// <summary> |
| | | /// 页码 |
| | | /// </summary> |
| | | public int PageIndex { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 分页大小 |
| | | /// </summary> |
| | | public int PageSize { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 页总数 |
| | | /// </summary> |
| | | public int TotalPage { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 记录总数 |
| | | /// </summary> |
| | | public int TotalCount { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 记录集合 |
| | | /// </summary> |
| | | public List<T> Items { get; set; } = new(); |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | using Furion; |
| | | using SqlSugar; |
| | | |
| | | namespace DocumentServiceAPI.Core |
| | | { |
| | | public class BaseRepository<T> : SimpleClient<T> where T : class,new() |
| | | { |
| | | public BaseRepository(ISqlSugarClient context = null) : base(context) |
| | | { |
| | | base.Context = App.GetService<ISqlSugarClient>();//用手动获取方式支持切换仓储 |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using Document.Unility; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using SqlSugar; |
| | | |
| | | namespace DocumentServiceAPI.Core |
| | | { |
| | | public static class SqlsugarSetup |
| | | { |
| | | public static void AddSqlsugarSetup(this IServiceCollection services, IConfiguration configuration, string dbName = "sqldb") |
| | | { |
| | | //如果多个数数据库传 List<ConnectionConfig> |
| | | var configConnection = new ConnectionConfig() |
| | | { |
| | | DbType = SqlSugar.DbType.SqlServer, |
| | | ConnectionString = configuration.GetConnectionString(dbName), |
| | | IsAutoCloseConnection = true, |
| | | }; |
| | | |
| | | SqlSugarScope sqlSugar = new SqlSugarScope(configConnection, |
| | | db => |
| | | { |
| | | //单例参数配置,所有上下文生效 |
| | | db.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | //Console.WriteLine(sql);//输出sql |
| | | }; |
| | | //SQL报错 |
| | | db.Aop.OnError = (exp) => |
| | | { |
| | | NLogProvider.GetInstance().Error(exp); |
| | | }; |
| | | }); |
| | | |
| | | services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton |
| | | } |
| | | } |
| | | } |