From f4fc787d790545612c09edfc7602a7cdb044324a Mon Sep 17 00:00:00 2001 From: wenjy Date: Sun, 14 Jan 2024 14:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Common/ExpressionExtensions.cs | 151 ++++++++++ SlnMesnac.Common/SlnMesnac.Common.csproj | 8 + SlnMesnac.Config/AppConfig.cs | 28 ++ SlnMesnac.Config/SlnMesnac.Config.csproj | 12 + SlnMesnac.Model/SlnMesnac.Model.csproj | 12 + SlnMesnac.Model/domain/BaseMaterialInfo.cs | 284 ++++++++++++++++++ SlnMesnac.Model/domain/BaseUser.cs | 108 +++++++ SlnMesnac.Quartz/Job/Job2.cs | 25 ++ SlnMesnac.Quartz/Job/MyJob.cs | 25 ++ SlnMesnac.Quartz/QuartzSetUp.cs | 32 ++ SlnMesnac.Quartz/SlnMesnac.Quartz.csproj | 13 + SlnMesnac.Repository/Repository.cs | 20 ++ .../SlnMesnac.Repository.csproj | 19 ++ SlnMesnac.Repository/SqlsugarSetup.cs | 63 ++++ .../service/IBaseMaterialService.cs | 39 +++ .../service/IBaseUserService.cs | 23 ++ .../service/Impl/BaseMaterialServiceImpl.cs | 111 +++++++ .../service/Impl/BaseUserServiceImpl.cs | 55 ++++ SlnMesnac.Serilog/SerilogExtensions.cs | 39 +++ SlnMesnac.Serilog/SlnMesnac.Serilog.csproj | 18 ++ SlnMesnac.sln | 61 ++++ .../Controllers/BaseMaterialInfoController.cs | 90 ++++++ SlnMesnac/Controllers/BaseUserController.cs | 80 +++++ SlnMesnac/Controllers/JobController.cs | 61 ++++ SlnMesnac/Program.cs | 32 ++ SlnMesnac/Properties/launchSettings.json | 30 ++ SlnMesnac/SlnMesnac.csproj | 22 ++ SlnMesnac/Startup.cs | 121 ++++++++ SlnMesnac/appsettings.Development.json | 8 + SlnMesnac/appsettings.json | 15 + 30 files changed, 1605 insertions(+) create mode 100644 SlnMesnac.Common/ExpressionExtensions.cs create mode 100644 SlnMesnac.Common/SlnMesnac.Common.csproj create mode 100644 SlnMesnac.Config/AppConfig.cs create mode 100644 SlnMesnac.Config/SlnMesnac.Config.csproj create mode 100644 SlnMesnac.Model/SlnMesnac.Model.csproj create mode 100644 SlnMesnac.Model/domain/BaseMaterialInfo.cs create mode 100644 SlnMesnac.Model/domain/BaseUser.cs create mode 100644 SlnMesnac.Quartz/Job/Job2.cs create mode 100644 SlnMesnac.Quartz/Job/MyJob.cs create mode 100644 SlnMesnac.Quartz/QuartzSetUp.cs create mode 100644 SlnMesnac.Quartz/SlnMesnac.Quartz.csproj create mode 100644 SlnMesnac.Repository/Repository.cs create mode 100644 SlnMesnac.Repository/SlnMesnac.Repository.csproj create mode 100644 SlnMesnac.Repository/SqlsugarSetup.cs create mode 100644 SlnMesnac.Repository/service/IBaseMaterialService.cs create mode 100644 SlnMesnac.Repository/service/IBaseUserService.cs create mode 100644 SlnMesnac.Repository/service/Impl/BaseMaterialServiceImpl.cs create mode 100644 SlnMesnac.Repository/service/Impl/BaseUserServiceImpl.cs create mode 100644 SlnMesnac.Serilog/SerilogExtensions.cs create mode 100644 SlnMesnac.Serilog/SlnMesnac.Serilog.csproj create mode 100644 SlnMesnac.sln create mode 100644 SlnMesnac/Controllers/BaseMaterialInfoController.cs create mode 100644 SlnMesnac/Controllers/BaseUserController.cs create mode 100644 SlnMesnac/Controllers/JobController.cs create mode 100644 SlnMesnac/Program.cs create mode 100644 SlnMesnac/Properties/launchSettings.json create mode 100644 SlnMesnac/SlnMesnac.csproj create mode 100644 SlnMesnac/Startup.cs create mode 100644 SlnMesnac/appsettings.Development.json create mode 100644 SlnMesnac/appsettings.json diff --git a/SlnMesnac.Common/ExpressionExtensions.cs b/SlnMesnac.Common/ExpressionExtensions.cs new file mode 100644 index 0000000..0a0e879 --- /dev/null +++ b/SlnMesnac.Common/ExpressionExtensions.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Linq; +using System.Text; + +namespace SlnMesnac.Common +{ + /// + /// 谓词表达式构建器 + /// + public static class ExpressionExtensions + { + /// + /// 创建一个值恒为 true 的表达式。 + /// + /// 表达式方法类型 + /// 一个值恒为 true 的表达式。 + public static Expression> True() { return p => true; } + + /// + /// 创建一个值恒为 false 的表达式。 + /// + /// 表达式方法类型 + /// 一个值恒为 false 的表达式。 + public static Expression> False() { return f => false; } + + /// + /// 使用 Expression.OrElse 的方式拼接两个 System.Linq.Expression。 + /// + /// 表达式方法类型 + /// 左边的 System.Linq.Expression 。 + /// 右边的 System.Linq.Expression。 + /// 拼接完成的 System.Linq.Expression。 + public static Expression Or(this Expression left, Expression right) + { + return MakeBinary(left, right, Expression.OrElse); + } + + /// + /// 使用 Expression.AndAlso 的方式拼接两个 System.Linq.Expression。 + /// + /// 表达式方法类型 + /// 左边的 System.Linq.Expression 。 + /// 右边的 System.Linq.Expression。 + /// 拼接完成的 System.Linq.Expression。 + public static Expression And(this Expression left, Expression right) + { + return MakeBinary(left, right, Expression.AndAlso); + } + + /// + /// 使用自定义的方式拼接两个 System.Linq.Expression。 + /// + /// 表达式方法类型 + /// 左边的 System.Linq.Expression 。 + /// 右边的 System.Linq.Expression。 + /// + /// 拼接完成的 System.Linq.Expression。 + private static Expression MakeBinary(this Expression left, Expression right, Func func) + { + return MakeBinary((LambdaExpression)left, right, func) as Expression; + } + + /// + /// 拼接两个 + /// System.Linq.Expression + /// ,两个 + /// System.Linq.Expression + /// 的参数必须完全相同。 + /// + /// 左边的 + /// System.Linq.Expression + /// + /// 右边的 + /// System.Linq.Expression + /// + /// 表达式拼接的具体逻辑 + /// 拼接完成的 + /// System.Linq.Expression + /// + private static LambdaExpression MakeBinary(this LambdaExpression left, LambdaExpression right, Func func) + { + var data = Combinate(right.Parameters, left.Parameters).ToArray(); + + right = ParameterReplace.Replace(right, data) as LambdaExpression; + + return Expression.Lambda(func(left.Body, right.Body), left.Parameters.ToArray()); + } + + /// + /// 合并参数 + /// + /// + /// + /// + /// + private static IEnumerable> Combinate(IEnumerable left, IEnumerable right) + { + var a = left.GetEnumerator(); + var b = right.GetEnumerator(); + while (a.MoveNext() && b.MoveNext()) + yield return new KeyValuePair(a.Current, b.Current); + } + } + + internal sealed class ParameterReplace : ExpressionVisitor + { + public static Expression Replace(Expression e, IEnumerable> paramList) + { + var item = new ParameterReplace(paramList); + return item.Visit(e); + } + + private readonly Dictionary _parameters; + + public ParameterReplace(IEnumerable> paramList) + { + _parameters = paramList.ToDictionary(p => p.Key, p => p.Value, new ParameterEquality()); + } + + protected override Expression VisitParameter(ParameterExpression p) + { + ParameterExpression result; + if (_parameters.TryGetValue(p, out result)) + return result; + return base.VisitParameter(p); + } + + #region class: ParameterEquality + private class ParameterEquality : IEqualityComparer + { + public bool Equals(ParameterExpression x, ParameterExpression y) + { + if (x == null || y == null) + return false; + + return x.Type == y.Type; + } + + public int GetHashCode(ParameterExpression obj) + { + if (obj == null) + return 0; + + return obj.Type.GetHashCode(); + } + } + #endregion + } +} diff --git a/SlnMesnac.Common/SlnMesnac.Common.csproj b/SlnMesnac.Common/SlnMesnac.Common.csproj new file mode 100644 index 0000000..8ef8970 --- /dev/null +++ b/SlnMesnac.Common/SlnMesnac.Common.csproj @@ -0,0 +1,8 @@ + + + + netstandard2.1 + enable + + + diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs new file mode 100644 index 0000000..19030b3 --- /dev/null +++ b/SlnMesnac.Config/AppConfig.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.Options; +using System; + +namespace SlnMesnac.Config +{ + /// + /// 系统配置 + /// + public class AppConfig : IOptions + { + /// + /// 日志文件路径 + /// + public string logPath { get; set; } + + /// + /// MES 数据库连接字符串 + /// + public string mesConnStr { get; set; } + + /// + /// MCS 数据库连接字符串 + /// + public string mcsConnStr { get; set; } + + public AppConfig Value => this; + } +} diff --git a/SlnMesnac.Config/SlnMesnac.Config.csproj b/SlnMesnac.Config/SlnMesnac.Config.csproj new file mode 100644 index 0000000..5ed17ce --- /dev/null +++ b/SlnMesnac.Config/SlnMesnac.Config.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.1 + enable + + + + + + + diff --git a/SlnMesnac.Model/SlnMesnac.Model.csproj b/SlnMesnac.Model/SlnMesnac.Model.csproj new file mode 100644 index 0000000..4f9d9b5 --- /dev/null +++ b/SlnMesnac.Model/SlnMesnac.Model.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.1 + enable + + + + + + + diff --git a/SlnMesnac.Model/domain/BaseMaterialInfo.cs b/SlnMesnac.Model/domain/BaseMaterialInfo.cs new file mode 100644 index 0000000..333aa8c --- /dev/null +++ b/SlnMesnac.Model/domain/BaseMaterialInfo.cs @@ -0,0 +1,284 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using System.Xml.Linq; + +namespace SlnMesnac.Model.domain +{ + [SugarTable("BasMaterial"), TenantAttribute("mes")] + [DataContract(Name = "BasMaterial 物料信息")] + public class BaseMaterialInfo + { + /// + /// + /// + [SugarColumn(ColumnName = "ObjID", IsPrimaryKey = true)] + public int ObjID { get; set; } + /// + /// 大类+小类+规格+胶代码或最后4顺序号 + /// + [SugarColumn(ColumnName = "MaterialCode")] + public string MaterialCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MajorTypeID")] + public int? MajorTypeID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MinorTypeID")] + public string MinorTypeID { get; set; } + /// + /// + /// 默认值: ('') + /// + [SugarColumn(ColumnName = "RubCode")] + public string RubCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MaterialName")] + public string MaterialName { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MaterialOtherName")] + public string MaterialOtherName { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MaterialSimpleName")] + public string MaterialSimpleName { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "ProductMaterialCode")] + public string ProductMaterialCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MaterialLevel")] + public string MaterialLevel { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MaterialGroup")] + public string MaterialGroup { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "UserCode")] + public string UserCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "PlanPrice")] + public decimal? PlanPrice { get; set; } + /// + /// 具体到县级市,长度为6,国外的只具体国家 + /// + [SugarColumn(ColumnName = "ProductArea")] + public string ProductArea { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MinStock")] + public decimal? MinStock { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "MaxStock")] + public decimal? MaxStock { get; set; } + /// + /// 千克,克,块,桶,升 + /// + [SugarColumn(ColumnName = "UnitID")] + public int? UnitID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "StaticUnitID")] + public int? StaticUnitID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "StaticUnitCoefficient")] + public decimal? StaticUnitCoefficient { get; set; } + /// + /// 显为百分比 + /// + [SugarColumn(ColumnName = "CheckPermitError")] + public decimal? CheckPermitError { get; set; } + /// + /// 按小时计算 + /// + [SugarColumn(ColumnName = "MaxParkTime")] + public decimal? MaxParkTime { get; set; } + /// + /// 小时计算 + /// + [SugarColumn(ColumnName = "MinParkTime")] + public decimal? MinParkTime { get; set; } + /// + /// + /// 默认值: (getdate()) + /// + [SugarColumn(ColumnName = "DefineDate")] + public DateTime? DefineDate { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "StandardCode")] + public string StandardCode { get; set; } + /// + /// + /// 默认值: ((1)) + /// + [SugarColumn(ColumnName = "StaticClass")] + public int? StaticClass { get; set; } + /// + /// + /// 默认值: ((0)) + /// + [SugarColumn(ColumnName = "IsEqualMaterial")] + public string IsEqualMaterial { get; set; } + /// + /// + /// 默认值: ((0)) + /// + [SugarColumn(ColumnName = "IsPutJar")] + public string IsPutJar { get; set; } + /// + /// + /// 默认值: ((1)) + /// + [SugarColumn(ColumnName = "IsQualityRateCount")] + public string IsQualityRateCount { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "ERPCode")] + public string ERPCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "Remark")] + public string Remark { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "DeleteFlag")] + public string DeleteFlag { get; set; } + /// + /// + /// 默认值: ((0)) + /// + [SugarColumn(ColumnName = "ValidDate")] + public decimal ValidDate { get; set; } + /// + /// + /// 默认值: ((0)) + /// + [SugarColumn(ColumnName = "ValidDateB")] + public decimal ValidDateB { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "SAPMaterialCode")] + public string SAPMaterialCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "SAPMaterialShortCode")] + public string SAPMaterialShortCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "ERPCode_Bak")] + public string ErpcodeBak { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "OperSourceTemp")] + public string OperSourceTemp { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "IsQualityrateCountBak")] + public int? IsQualityrateCountBak { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "CMaterialLevel")] + public string CMaterialLevel { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "CMaterialGroup")] + public string CMaterialGroup { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "XBStock")] + public decimal? XBStock { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "HFCode")] + public string HFCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "HFCode2")] + public string HFCode2 { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "UNITName")] + public string UNITName { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "KFACSTATUS")] + public string Kfacstatus { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "Ordertype")] + public string Ordertype { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "CreateDate")] + public string CreateDate { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "UpdateDate")] + public string UpdateDate { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "UnAudit")] + public string UnAudit { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "ChkStand")] + public string ChkStand { get; set; } + /// + /// 1 KG 2 PC 3 标准KG + /// 默认值: ((1)) + /// + [SugarColumn(ColumnName = "SapUpUnit")] + public int? SapUpUnit { get; set; } + /// + /// 是否为轨道事业部物料:0:不是,1:是 + /// + [SugarColumn(ColumnName = "IsGDMaterial")] + public int? IsGDMaterial { get; set; } + } +} diff --git a/SlnMesnac.Model/domain/BaseUser.cs b/SlnMesnac.Model/domain/BaseUser.cs new file mode 100644 index 0000000..c6f3e28 --- /dev/null +++ b/SlnMesnac.Model/domain/BaseUser.cs @@ -0,0 +1,108 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Security.Principal; +using System.Text; +using System.Xml.Linq; + +namespace SlnMesnac.Model.domain +{ + /// + /// 系统基础资料-人员基础资料 yuany + /// + [SugarTable("BasUser"), TenantAttribute("mes")] + [DataContract(Name = "BaseUser 人员基础资料")] + public class BaseUser + { + /// + /// + /// + [SugarColumn(ColumnName = "ObjID", IsPrimaryKey = true, IsIdentity = true)] + public int ObjID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "UserName")] + public string UserName { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "UserPWD")] + public string UserPWD { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "RealName")] + public string RealName { get; set; } + /// + /// + /// 默认值: ((1)) + /// + [SugarColumn(ColumnName = "Sex")] + public int? Sex { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "Telephone")] + public string Telephone { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "WorkBarcode")] + public string WorkBarcode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "DeptCode")] + public string DeptCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "WorkID")] + public int? WorkID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "ShiftID")] + public int? ShiftID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "WorkShopID")] + public int? WorkShopID { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "HRCode")] + public string HRCode { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "ERPCode")] + public string ERPCode { get; set; } + /// + /// + /// 默认值: ((0)) + /// + [SugarColumn(ColumnName = "DeleteFlag")] + public string DeleteFlag { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "Remark")] + public string Remark { get; set; } + /// + /// + /// 默认值: ((1)) + /// + [SugarColumn(ColumnName = "IsEmployee")] + public string IsEmployee { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "RecordTime")] + public DateTime? RecordTime { get; set; } + } +} + diff --git a/SlnMesnac.Quartz/Job/Job2.cs b/SlnMesnac.Quartz/Job/Job2.cs new file mode 100644 index 0000000..47791ce --- /dev/null +++ b/SlnMesnac.Quartz/Job/Job2.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.Logging; +using Quartz; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Quartz.Job +{ + internal class Job2 : IJob + { + private readonly ILogger _logger; + + public Job2(ILogger logger) + { + _logger = logger; + } + + public Task Execute(IJobExecutionContext context) + { + _logger.LogInformation($"执行Job2:{DateTime.Now.ToString("HH:mm:ss")}"); + return Task.CompletedTask; + } + } +} diff --git a/SlnMesnac.Quartz/Job/MyJob.cs b/SlnMesnac.Quartz/Job/MyJob.cs new file mode 100644 index 0000000..67fe4cb --- /dev/null +++ b/SlnMesnac.Quartz/Job/MyJob.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.Logging; +using Quartz; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Quartz.Job +{ + public class MyJob : IJob + { + private readonly ILogger _logger; + + public MyJob(ILogger logger) + { + _logger = logger; + } + + public Task Execute(IJobExecutionContext context) + { + _logger.LogInformation($"执行MyJob:{DateTime.Now.ToString("HH:mm:ss")}"); + return Task.CompletedTask; + } + } +} diff --git a/SlnMesnac.Quartz/QuartzSetUp.cs b/SlnMesnac.Quartz/QuartzSetUp.cs new file mode 100644 index 0000000..94bc14d --- /dev/null +++ b/SlnMesnac.Quartz/QuartzSetUp.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.DependencyInjection; +using Quartz; +using SlnMesnac.Quartz.Job; +using System; + +namespace SlnMesnac.Quartz +{ + public static class QuartzSetUp + { + [Obsolete] + public static void AddQuartzSetUp(this IServiceCollection services) + { + services.AddQuartz(q => + { + q.UseMicrosoftDependencyInjectionJobFactory(); + + q.ScheduleJob(trigger => + trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例:每3s执行一次 + ); + + q.ScheduleJob(trigger => + trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例:每5s执行一次 + ); + }); + + services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true); + + services.AddSingleton(provider => provider.GetRequiredService().GetScheduler().Result); + + } + } +} diff --git a/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj b/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj new file mode 100644 index 0000000..1040f6c --- /dev/null +++ b/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.1 + enable + + + + + + + + diff --git a/SlnMesnac.Repository/Repository.cs b/SlnMesnac.Repository/Repository.cs new file mode 100644 index 0000000..31856b6 --- /dev/null +++ b/SlnMesnac.Repository/Repository.cs @@ -0,0 +1,20 @@ +using SqlSugar; +using System; + +namespace SlnMesnac.Repository +{ + public class Repository : SimpleClient where T : class, new() + { + public ITenant itenant = null;//多租户事务、GetConnection、IsAnyConnection等功能 + + public Repository(ISqlSugarClient db) + { + itenant = db.AsTenant();//用来处理事务 + base.Context = db.AsTenant().GetConnectionScopeWithAttr();//获取子Db + + //如果不想通过注入多个仓储 + //用到ChangeRepository或者Db.GetMyRepository需要看标题4写法 + } + + } +} \ No newline at end of file diff --git a/SlnMesnac.Repository/SlnMesnac.Repository.csproj b/SlnMesnac.Repository/SlnMesnac.Repository.csproj new file mode 100644 index 0000000..b733819 --- /dev/null +++ b/SlnMesnac.Repository/SlnMesnac.Repository.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.1 + enable + + + + + + + + + + + + + + diff --git a/SlnMesnac.Repository/SqlsugarSetup.cs b/SlnMesnac.Repository/SqlsugarSetup.cs new file mode 100644 index 0000000..3b2addb --- /dev/null +++ b/SlnMesnac.Repository/SqlsugarSetup.cs @@ -0,0 +1,63 @@ +using Microsoft.Extensions.DependencyInjection; +using SlnMesnac.Config; +using SlnMesnac.Repository.service; +using SlnMesnac.Repository.service.Impl; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository +{ + public static class SqlsugarSetup + { + /// + /// 注册SqlSugar + /// + /// + public static void AddSqlSugarSetup(this IServiceCollection services) + { + services.AddSingleton(x => + { + var appConfig = x.GetService(); + SqlSugarScope Db = new SqlSugarScope(new List() + { + new ConnectionConfig() + { + ConfigId = "mes", + DbType = DbType.SqlServer, + ConnectionString = appConfig.mesConnStr, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + }, + new ConnectionConfig() + { + ConfigId = "mcs", + DbType = DbType.Oracle, + ConnectionString = appConfig.mcsConnStr, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + } + }, + db => + { + db.Aop.OnLogExecuting = (sql, pars) => { }; + }); + + return Db; + }); + } + + /// + /// 注册Repository、Service服务 + /// + /// + public static void AddServices(this IServiceCollection services) + { + //services.AddSingleton>(); + services.AddSingleton(typeof(Repository<>)); + services.AddSingleton(); + services.AddSingleton(); + } + } +} diff --git a/SlnMesnac.Repository/service/IBaseMaterialService.cs b/SlnMesnac.Repository/service/IBaseMaterialService.cs new file mode 100644 index 0000000..638d67e --- /dev/null +++ b/SlnMesnac.Repository/service/IBaseMaterialService.cs @@ -0,0 +1,39 @@ +using SlnMesnac.Model.domain; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service +{ + public interface IBaseMaterialService + { + + /// + /// 获取所有的物料信息 + /// + /// + List GetMaterialInfos(); + + /// + /// 通过物料编码获取物料信息 + /// + /// + /// + BaseMaterialInfo GetMaterialInfoByMaterialCode(string materialCode); + + /// + /// 通过SAP物料编码获取物料信息 + /// + /// + /// + BaseMaterialInfo GetMaterialInfoBySapMaterialCode(string sapMaterialCode); + + /// + /// 通过物料类别获取物料信息 + /// + /// 物料大类 + /// 物料细类 + /// + List GetMaterialInfosByMaterialType(int majorTypeId, string minorTypeId); + } +} diff --git a/SlnMesnac.Repository/service/IBaseUserService.cs b/SlnMesnac.Repository/service/IBaseUserService.cs new file mode 100644 index 0000000..35bbea0 --- /dev/null +++ b/SlnMesnac.Repository/service/IBaseUserService.cs @@ -0,0 +1,23 @@ +using SlnMesnac.Model.domain; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service +{ + public interface IBaseUserService + { + /// + /// 获取用户信息 + /// + /// + List GetUsers(); + + /// + /// 验证添加用户信息,有一个错误时进行回滚 + /// + /// + /// + bool InsertUsers(List users); + } +} diff --git a/SlnMesnac.Repository/service/Impl/BaseMaterialServiceImpl.cs b/SlnMesnac.Repository/service/Impl/BaseMaterialServiceImpl.cs new file mode 100644 index 0000000..8985d53 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/BaseMaterialServiceImpl.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Model.domain; +using SlnMesnac.Common; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text; + +namespace SlnMesnac.Repository.service.Impl +{ + public class BaseMaterialServiceImpl : IBaseMaterialService + { + private Repository _repository; + + private ILogger _logger; + + public BaseMaterialServiceImpl(Repository repository, ILogger logger) + { + _repository = repository; + _logger = logger; + } + + /// + /// 通过物料编码获取物料信息 + /// + /// + /// + public BaseMaterialInfo GetMaterialInfoByMaterialCode(string materialCode) + { + BaseMaterialInfo materialInfo = null; + try + { + materialInfo = _repository.GetFirst(x => x.MaterialCode == materialCode); + } + catch (Exception ex) + { + _logger.LogError($"根据物料编号获取物料信息异常:{ex.Message}"); + } + return materialInfo; + } + + /// + /// 通过SAP物料编码获取物料信息 + /// + /// + /// + public BaseMaterialInfo GetMaterialInfoBySapMaterialCode(string sapMaterialCode) + { + BaseMaterialInfo materialInfo = null; + try + { + materialInfo = _repository.GetFirst(x => x.SAPMaterialCode == sapMaterialCode); + } + catch (Exception ex) + { + _logger.LogError($"根据SAP物料编号获取物料信息异常:{ex.Message}"); + } + return materialInfo; + } + + /// + /// 获取所有的物料信息 + /// + /// + public List GetMaterialInfos() + { + List materialInfos = null; + try + { + materialInfos = _repository.GetList(); + } + catch (Exception ex) + { + _logger.LogError($"获取物料信息异常:{ex.Message}"); + } + return materialInfos; + } + + /// + /// 通过物料类别获取物料信息 + /// + /// 物料大类 + /// 物料细类 + /// + public List GetMaterialInfosByMaterialType(int majorTypeId, string minorTypeId) + { + List materialInfos = null; + try + { + Expression> exp = x => true; + + if (majorTypeId != 0) + { + exp = exp.And(x => x.MajorTypeID == majorTypeId); + } + else if (!string.IsNullOrEmpty(minorTypeId)) + { + exp = exp.And(x => x.MinorTypeID == minorTypeId); + } + + materialInfos = _repository.GetList(exp); + } + catch (Exception ex) + { + _logger.LogError($"通过物料类型获取物料信息异常:{ex.Message}"); + } + return materialInfos; + } + } +} + diff --git a/SlnMesnac.Repository/service/Impl/BaseUserServiceImpl.cs b/SlnMesnac.Repository/service/Impl/BaseUserServiceImpl.cs new file mode 100644 index 0000000..942774b --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/BaseUserServiceImpl.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Model.domain; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Repository.service.Impl +{ + public class BaseUserServiceImpl : IBaseUserService + { + private readonly ILogger _logger; + + private readonly Repository _rep; + + public BaseUserServiceImpl(ILogger logger, Repository rep) + { + _logger = logger; + _rep = rep; + } + + + public List GetUsers() + { + List users = null; + try + { + users = _rep.GetList(); + } + catch (Exception ex) + { + _logger.LogError($"获取用户信息异常{ex.Message}"); + } + return users; + } + + public bool InsertUsers(List users) + { + bool result = false; + try + { + _rep.AsTenant().BeginTran(); + + result = _rep.InsertRange(users); + + _rep.AsTenant().CommitTran(); + } + catch (Exception ex) + { + _rep.AsTenant().RollbackTran(); + _logger.LogError($"用户信息添加异常:{ex.Message}"); + } + return result; + } + } +} diff --git a/SlnMesnac.Serilog/SerilogExtensions.cs b/SlnMesnac.Serilog/SerilogExtensions.cs new file mode 100644 index 0000000..559fd0a --- /dev/null +++ b/SlnMesnac.Serilog/SerilogExtensions.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Serilog; +using Serilog.Events; +using SlnMesnac.Config; +using System; +using System.IO; + +namespace SlnMesnac.Serilog +{ + /// + /// Serilog + /// + public static class SerilogExtensions + { + public static IApplicationBuilder UseSerilogExtensions(this IApplicationBuilder app) + { + //启用Serilog中间件 + app.UseSerilogRequestLogging(); + + #region 通过配置文件读取日志存放位置 + var appConfig = app.ApplicationServices.GetService(); + var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; + #endregion + + Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() + .WriteTo.File(Path.Combine(logPath, "Info.log"), LogEventLevel.Information, fileSizeLimitBytes: 5 * 1024) + .WriteTo.File(Path.Combine(logPath, "Error.log"), LogEventLevel.Error, fileSizeLimitBytes: 5 * 1024) + .WriteTo.File(Path.Combine(logPath, "Warn.log"), LogEventLevel.Warning, fileSizeLimitBytes: 5 * 1024) + //.WriteTo.File(Path.Combine(logPath, "Debug.log"), LogEventLevel.Debug, fileSizeLimitBytes: 5 * 1024) + .CreateLogger(); + app.UseSerilogRequestLogging(); + + Log.Information($"项目初始化完成,日志存放路径:{appConfig.logPath}"); + + return app; + } + } +} diff --git a/SlnMesnac.Serilog/SlnMesnac.Serilog.csproj b/SlnMesnac.Serilog/SlnMesnac.Serilog.csproj new file mode 100644 index 0000000..2377389 --- /dev/null +++ b/SlnMesnac.Serilog/SlnMesnac.Serilog.csproj @@ -0,0 +1,18 @@ + + + + netstandard2.1 + enable + + + + + + + + + + + + + diff --git a/SlnMesnac.sln b/SlnMesnac.sln new file mode 100644 index 0000000..a273972 --- /dev/null +++ b/SlnMesnac.sln @@ -0,0 +1,61 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac", "SlnMesnac\SlnMesnac.csproj", "{19445879-B3F3-4C76-A670-EFAE9E25BAB4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Common", "SlnMesnac.Common\SlnMesnac.Common.csproj", "{BB71F26A-7007-423E-83E9-7A3BAC25E934}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Config", "SlnMesnac.Config\SlnMesnac.Config.csproj", "{6EF7F087-7149-4689-885C-E0D05E1A9AA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Model", "SlnMesnac.Model\SlnMesnac.Model.csproj", "{9EC081B6-971F-418C-A40C-5B8AD2E27417}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Repository", "SlnMesnac.Repository\SlnMesnac.Repository.csproj", "{C892C06A-496B-43B6-AEC7-AF9D70778C0C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Quartz", "SlnMesnac.Quartz\SlnMesnac.Quartz.csproj", "{12ED397C-951E-411C-9C43-CDABA79CA45B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Serilog", "SlnMesnac.Serilog\SlnMesnac.Serilog.csproj", "{DEE2F305-733C-47C8-891C-502121ABAD00}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Release|Any CPU.Build.0 = Release|Any CPU + {BB71F26A-7007-423E-83E9-7A3BAC25E934}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BB71F26A-7007-423E-83E9-7A3BAC25E934}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BB71F26A-7007-423E-83E9-7A3BAC25E934}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BB71F26A-7007-423E-83E9-7A3BAC25E934}.Release|Any CPU.Build.0 = Release|Any CPU + {6EF7F087-7149-4689-885C-E0D05E1A9AA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6EF7F087-7149-4689-885C-E0D05E1A9AA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6EF7F087-7149-4689-885C-E0D05E1A9AA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6EF7F087-7149-4689-885C-E0D05E1A9AA8}.Release|Any CPU.Build.0 = Release|Any CPU + {9EC081B6-971F-418C-A40C-5B8AD2E27417}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9EC081B6-971F-418C-A40C-5B8AD2E27417}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9EC081B6-971F-418C-A40C-5B8AD2E27417}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9EC081B6-971F-418C-A40C-5B8AD2E27417}.Release|Any CPU.Build.0 = Release|Any CPU + {C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Release|Any CPU.Build.0 = Release|Any CPU + {12ED397C-951E-411C-9C43-CDABA79CA45B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12ED397C-951E-411C-9C43-CDABA79CA45B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12ED397C-951E-411C-9C43-CDABA79CA45B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12ED397C-951E-411C-9C43-CDABA79CA45B}.Release|Any CPU.Build.0 = Release|Any CPU + {DEE2F305-733C-47C8-891C-502121ABAD00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEE2F305-733C-47C8-891C-502121ABAD00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEE2F305-733C-47C8-891C-502121ABAD00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEE2F305-733C-47C8-891C-502121ABAD00}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D414D640-C2DE-44E2-930E-DD095881CDC1} + EndGlobalSection +EndGlobal diff --git a/SlnMesnac/Controllers/BaseMaterialInfoController.cs b/SlnMesnac/Controllers/BaseMaterialInfoController.cs new file mode 100644 index 0000000..57d541b --- /dev/null +++ b/SlnMesnac/Controllers/BaseMaterialInfoController.cs @@ -0,0 +1,90 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service; + +namespace SlnMesnac.Controllers +{ + /// + /// 物料信息 + /// + [Route("api/[controller]")] + [ApiController] + public class BaseMaterialInfoController + { + private ILogger _logger; + + private IBaseMaterialService _service; + + /// + /// + /// + /// + /// + public BaseMaterialInfoController(ILogger logger, IBaseMaterialService service) + { + _logger = logger; + _service = service; + } + + /// + /// 获取物料信息 + /// + /// + [HttpGet] + public IEnumerable Get() + { + IEnumerable materialInfos = null; + try + { + materialInfos = _service.GetMaterialInfos(); + } + catch (Exception ex) + { + _logger.LogError($"获取物料信息接口调用异常:{ex.Message}"); + } + return materialInfos; + } + + /// + /// 根据物料编号获取物料信息 + /// + /// 物料编号 + /// + [HttpGet("Get/{materialCode}")] + public BaseMaterialInfo GetMaterialInfoByMaterialCode(string materialCode) + { + BaseMaterialInfo materialInfo = null; + try + { + materialInfo = _service.GetMaterialInfoByMaterialCode(materialCode); + } + catch (Exception ex) + { + _logger.LogError($"根据物料编号获取物料信息接口调用异常:{ex.Message}"); + } + return materialInfo; + } + + /// + /// 通过物料类别获取物料信息 + /// + /// 物料大类 + /// 物料细类 + /// + [HttpGet("Get/{majorTypeId}/{minorTypeId}")] + public IEnumerable GetMaterialInfosByMaterialType(int majorTypeId, string minorTypeId) + { + IEnumerable materialInfos = null; + try + { + materialInfos = _service.GetMaterialInfosByMaterialType(majorTypeId, minorTypeId); + } + catch (Exception ex) + { + _logger.LogError($"通过物料类别获取物料信息接口调用异常:{ex.Message}"); + } + return materialInfos; + } + } +} diff --git a/SlnMesnac/Controllers/BaseUserController.cs b/SlnMesnac/Controllers/BaseUserController.cs new file mode 100644 index 0000000..a59c154 --- /dev/null +++ b/SlnMesnac/Controllers/BaseUserController.cs @@ -0,0 +1,80 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service; + +namespace SlnMesnac.Controllers +{ + /// + /// 人员基础信息 + /// + [Route("api/[controller]")] + [ApiController] + public class BaseUserController : ControllerBase + { + private readonly ILogger _logger; + + private readonly IBaseUserService _service; + + /// + /// + /// + /// + /// + public BaseUserController(ILogger logger, IBaseUserService service) + { + _logger = logger; + _service = service; + } + + /// + /// 获取人员基础信息 + /// + /// + [HttpGet] + public IEnumerable Get() + { + IEnumerable users = null; + try + { + users = _service.GetUsers(); + } + catch (Exception ex) + { + _logger.LogError($"获取用户信息接口调用异常:{ex.Message}"); + } + return users; + } + + /// + /// 通过用户名称获取指定用户信息 + /// + /// 用户名称 + /// + [HttpGet("Gets/{userName}")] + public IEnumerable GetUserByUserName(string userName) + { + IEnumerable users = null; + try + { + users = _service.GetUsers(); + } + catch (Exception ex) + { + _logger.LogError($"获取用户信息接口调用异常:{ex.Message}"); + } + return users; + } + + /// + /// 添加用户信息 + /// + /// 用户列表 + /// + [HttpPut] + public bool InsertUserInfo(List users) + { + return _service.InsertUsers(users); + } + } +} diff --git a/SlnMesnac/Controllers/JobController.cs b/SlnMesnac/Controllers/JobController.cs new file mode 100644 index 0000000..e0be503 --- /dev/null +++ b/SlnMesnac/Controllers/JobController.cs @@ -0,0 +1,61 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Quartz; + +namespace SlnMesnac.Controllers +{ + /// + /// 任务调度 + /// + [ApiController] + [Route("api/[controller]")] + public class JobController + { + private readonly IScheduler _scheduler; + + /// + /// + /// + /// + public JobController(IScheduler scheduler) + { + _scheduler = scheduler; + } + + /// + /// 启动任务 + /// + /// 任务名称 + /// 任务分组 + /// + [HttpPost("start")] + public async Task StartJob(string jobName, string groupName) + { + // 检查调度器是否已经启动 + if (!_scheduler.IsStarted) + { + await _scheduler.Start(); + } + + var myJobKey = new JobKey(jobName, groupName); + await _scheduler.ResumeJob(myJobKey); + + return "Job started successfully."; + } + + /// + /// 停止任务 + /// + /// 任务名称 + /// 任务分组 + /// + [HttpPost("stop")] + public async Task StopJob(string jobName, string groupName) + { + var myJobKey = new JobKey(jobName, groupName); + await _scheduler.PauseJob(myJobKey); + + return "Job stopped successfully."; + } + } +} \ No newline at end of file diff --git a/SlnMesnac/Program.cs b/SlnMesnac/Program.cs new file mode 100644 index 0000000..b76cbf2 --- /dev/null +++ b/SlnMesnac/Program.cs @@ -0,0 +1,32 @@ +using Serilog; + +namespace SlnMesnac +{ + /// + /// + /// + public class Program + { + /// + /// Main + /// + /// + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + /// + /// CreateHostBuilder + /// + /// + /// + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .UseSerilog() + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} \ No newline at end of file diff --git a/SlnMesnac/Properties/launchSettings.json b/SlnMesnac/Properties/launchSettings.json new file mode 100644 index 0000000..3f9dcb9 --- /dev/null +++ b/SlnMesnac/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:32147", + "sslPort": 44302 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + //"launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "SlnMesnac": { + "commandName": "Project", + "launchBrowser": true, + //"launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SlnMesnac/SlnMesnac.csproj b/SlnMesnac/SlnMesnac.csproj new file mode 100644 index 0000000..9e05945 --- /dev/null +++ b/SlnMesnac/SlnMesnac.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + True + + + + + + + + + + + + + + + diff --git a/SlnMesnac/Startup.cs b/SlnMesnac/Startup.cs new file mode 100644 index 0000000..bb3ea97 --- /dev/null +++ b/SlnMesnac/Startup.cs @@ -0,0 +1,121 @@ +using Microsoft.OpenApi.Models; +using Serilog; +using Serilog.Events; +using SlnMesnac.Config; +using SlnMesnac.Quartz; +using SlnMesnac.Repository; +using SlnMesnac.Serilog; +using System.Runtime.Serialization; + +namespace SlnMesnac +{ + /// + /// + /// + public class Startup + { + /// + /// + /// + /// + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + /// + /// + /// + public IConfiguration Configuration { get; } + + /// + /// This method gets called by the runtime. Use this method to add services to the container. + /// + /// + [Obsolete] + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + + //配置Swagger + services.AddSwaggerGen(swagger => + { + //自定义接口信息 + swagger.SwaggerDoc("V1.0", new OpenApiInfo + { + Title = "MES Web Api", + Version = "V1.0", + Description = $"API版本V1.0", + Contact = new OpenApiContact + { + Name = "MES Web Api", + Email = "wenjy@mesnac.com" + } + }); + + //自定义实体别名 + swagger.CustomSchemaIds(type => type.GetCustomAttributes(typeof(DataContractAttribute), true) + .Cast() + .FirstOrDefault()?.Name); + + //配置Action名称 + var path = Path.Combine(AppContext.BaseDirectory, "SlnMesnac.xml"); + swagger.IncludeXmlComments(path, true); // true : 显示控制器层注释 + swagger.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序,如果有多个,就可以看见效果了。 + }); + + //注册配置类 + services.AddSingleton(provider => + { + var configuration = provider.GetService(); + return configuration.GetSection("AppConfig").Get(); + + }); + + //注册SqlSugar + services.AddSqlSugarSetup(); + + //注册服务 + services.AddServices(); + + //注册任务调度 + services.AddQuartzSetUp(); + } + + /// + /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + /// + /// + /// + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + //启用Swagger中间件 + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/V1.0/swagger.json", "MES Web Api V1.0"); + c.RoutePrefix = ""; + }); + + //启用Serilog中间件 + app.UseSerilogExtensions(); + + //app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + + } + } +} diff --git a/SlnMesnac/appsettings.Development.json b/SlnMesnac/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/SlnMesnac/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/SlnMesnac/appsettings.json b/SlnMesnac/appsettings.json new file mode 100644 index 0000000..d05c71e --- /dev/null +++ b/SlnMesnac/appsettings.json @@ -0,0 +1,15 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "AppConfig": { + "logPath": "E:\\桌面\\日常代码\\SlnMesnac\\SlnMesnac\\bin\\Debug\\net6.0", + "mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS", + "mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma" + } +}