Browse Source

Merge branch 'dev' of http://123.60.180.165:4647/ZZYDOP/DOPCore into dev

# Conflicts:
#	MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
tangdi 3 years ago
parent
commit
21b4cc38a6
67 changed files with 968 additions and 98 deletions
  1. 15 0
      .gitignore
  2. 1 0
      MicroServices/Business/Business.Application/Business.Application.csproj
  3. 20 0
      MicroServices/Business/Business.Application/Quartz/LogHostedService.cs
  4. 34 0
      MicroServices/Business/Business.Application/Quartz/NLogJob.cs
  5. 7 2
      MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
  6. 4 0
      MicroServices/Business/Business.Core/Business.Core.csproj
  7. 70 0
      MicroServices/Business/Business.Core/Utilities/NLogHelper.cs
  8. 72 24
      MicroServices/Business/Business.Core/Utilities/QRcodeHelper.cs
  9. 8 0
      MicroServices/Business/Business.Host/Business.Host.csproj
  10. 20 1
      MicroServices/Business/Business.Host/BusinessHostModule.cs
  11. 7 2
      MicroServices/Business/Business.Host/Program.cs
  12. 1 0
      MicroServices/Business/Business.Host/appsettings.json
  13. 73 0
      MicroServices/Business/Business.Host/nlog.config
  14. 53 7
      MicroServices/Business/Business.HttpApi/Controllers/QRcodeController.cs
  15. 4 1
      MicroServices/Business/Business.HttpApi/Controllers/TestController.cs
  16. 3 3
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturing.Application.Contracts.csproj
  17. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingApplicationContractsModule.cs
  18. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/FileInfoDto.cs
  19. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/GetFileInputDto.cs
  20. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/IDigitalManufacturingAppService.cs
  21. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissionDefinitionProvider.cs
  22. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissions.cs
  23. 4 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturing.Application.csproj
  24. 3 3
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationAutoMapperProfile.cs
  25. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationModule.cs
  26. 13 6
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingManagement/DigitalManufacturingAppService.cs
  27. 20 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/LogHostedService.cs
  28. 28 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/NLogJob.cs
  29. 14 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Core/DigitalManufacturing.Core.csproj
  30. 70 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Core/NLogHelper.cs
  31. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturing.Domain.csproj
  32. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturingDomainModule.cs
  33. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Enums/Enums.cs
  34. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileInfo.cs
  35. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileManager.cs
  36. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/DigitalManufacturing.EntityFrameworkCore.csproj
  37. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContext.cs
  38. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContextModelCreatingExtensions.cs
  39. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingEntityFrameworkCoreModule.cs
  40. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/DOP/DOPController.cs
  41. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/HomeController.cs
  42. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/Kanban/KanbanController.cs
  43. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/MES/MESController.cs
  44. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/QMS/QMSController.cs
  45. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/AndonController.cs
  46. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/SIMController.cs
  47. 2 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/WMS/WMSController.cs
  48. 10 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturing.Host.csproj
  49. 36 2
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturingHostModule.cs
  50. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContext.cs
  51. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContextFactory.cs
  52. 7 4
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Program.cs
  53. 1 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Startup.cs
  54. 2 1
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/appsettings.json
  55. 69 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.Host/nlog.config
  56. 6 0
      MicroServices/DigitalManufacturing/DigitalManufacturing.sln
  57. 3 0
      MicroServices/Procurement/Procurement.Application/Procurement.Application.csproj
  58. 7 1
      MicroServices/Procurement/Procurement.Application/ProcurementManagement/ProcurementAppService.cs
  59. 20 0
      MicroServices/Procurement/Procurement.Application/Quartz/LogHostedService.cs
  60. 28 0
      MicroServices/Procurement/Procurement.Application/Quartz/NLogJob.cs
  61. 70 0
      MicroServices/Procurement/Procurement.Core/NLogHelper.cs
  62. 15 0
      MicroServices/Procurement/Procurement.Core/Procurement.Core.csproj
  63. 2 0
      MicroServices/Procurement/Procurement.Host/Procurement.Host.csproj
  64. 34 0
      MicroServices/Procurement/Procurement.Host/ProcurementHostModule.cs
  65. 2 1
      MicroServices/Procurement/Procurement.Host/Program.cs
  66. 69 0
      MicroServices/Procurement/Procurement.Host/nlog.config
  67. 6 0
      MicroServices/Procurement/Procurement.sln

+ 15 - 0
.gitignore

@@ -1981,3 +1981,18 @@ MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/Spire
 MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/runtimes/unix/lib/netcoreapp2.0/System.Drawing.Common.dll
 MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/runtimes/win/lib/netcoreapp2.0/Microsoft.Win32.SystemEvents.dll
 MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/runtimes/win/lib/netcoreapp2.0/System.Drawing.Common.dll
+MicroServices/Business/Bussiness.ApplicationTest/bin/Debug/net6.0/Mongo2Go.dll
+MicroServices/Business/Bussiness.Domain.Test/bin/Debug/net6.0/Mongo2Go.dll
+MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/Mongo2Go.dll
+MicroServices/Business/Bussiness.ApplicationTest/bin/Debug/net6.0/SQLitePCLRaw.provider.e_sqlite3.dll
+MicroServices/Business/Bussiness.ApplicationTest/bin/Debug/net6.0/ThoughtWorks.QRCode.dll
+MicroServices/Business/Bussiness.ApplicationTest/bin/Debug/net6.0/runtimes/linux-s390x/native/libe_sqlite3.so
+MicroServices/Business/Bussiness.ApplicationTest/bin/Debug/net6.0/runtimes/osx-arm64/native/libe_sqlite3.dylib
+MicroServices/Business/Bussiness.Domain.Test/bin/Debug/net6.0/SQLitePCLRaw.provider.e_sqlite3.dll
+MicroServices/Business/Bussiness.Domain.Test/bin/Debug/net6.0/ThoughtWorks.QRCode.dll
+MicroServices/Business/Bussiness.Domain.Test/bin/Debug/net6.0/runtimes/linux-s390x/native/libe_sqlite3.so
+MicroServices/Business/Bussiness.Domain.Test/bin/Debug/net6.0/runtimes/osx-arm64/native/libe_sqlite3.dylib
+MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/SQLitePCLRaw.provider.e_sqlite3.dll
+MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/ThoughtWorks.QRCode.dll
+MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/runtimes/linux-s390x/native/libe_sqlite3.so
+MicroServices/Business/Bussiness.EntityFrameworkCore.Test/bin/Debug/net6.0/runtimes/osx-arm64/native/libe_sqlite3.dylib

+ 1 - 0
MicroServices/Business/Business.Application/Business.Application.csproj

@@ -11,6 +11,7 @@
 
   <ItemGroup>
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.7.1" />
+    <PackageReference Include="NLog" Version="5.1.2" />
     <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.0" />
     <PackageReference Include="Volo.Abp.Http.Client.IdentityModel" Version="6.0.0" />

+ 20 - 0
MicroServices/Business/Business.Application/Quartz/LogHostedService.cs

@@ -0,0 +1,20 @@
+using Microsoft.Extensions.Hosting;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+    public class LogHostedService
+    {
+        public void LogInstall()
+        {
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+        }
+    }
+}

+ 34 - 0
MicroServices/Business/Business.Application/Quartz/NLogJob.cs

@@ -0,0 +1,34 @@
+using Business.SyncDataManagement;
+using Quartz;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    public class NLogJob : IJob
+    {
+
+        /// <summary>
+        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+        /// </summary>
+        public readonly LogHostedService _logHostedService;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public NLogJob(LogHostedService logHostedService)
+        {
+            _logHostedService = logHostedService;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _logHostedService.LogInstall();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 7 - 2
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -22,7 +22,9 @@ using System.Linq;
 using System.Linq.Dynamic.Core;
 using System.Threading.Tasks;
 using Volo.Abp.Application.Services;
+using Volo.Abp.DependencyInjection;
 using Volo.Abp.Domain.Repositories;
+using Volo.Abp.MultiTenancy;
 
 namespace Business.ResourceExamineManagement
 {
@@ -30,11 +32,11 @@ namespace Business.ResourceExamineManagement
     /// 资源检查
     /// </summary>
     //[Authorize(BusinessPermissions.ResourceExamine.Default)]
-    public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
+    public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService, ITransientDependency
     {
         #region 服务
         SnowFlake help = new SnowFlake();
-
+        private readonly ICurrentTenant _currentTenant;
         /// <summary>
         /// 工艺路径
         /// </summary>
@@ -270,6 +272,7 @@ namespace Business.ResourceExamineManagement
             PretreatmentAppService pretreatmentAppService,
             CalcBomViewAppService calcbomviewAppService,
             PurchaseOrderAppService purchaseOrderAppService,
+            ICurrentTenant currentTenant,
             MorderAppService morderAppService
             )
         {
@@ -317,6 +320,7 @@ namespace Business.ResourceExamineManagement
             _pretreatmentAppService = pretreatmentAppService;
             _CalcBomViewAppService = calcbomviewAppService;
             _purchaseOrderAppService = purchaseOrderAppService;
+            _currentTenant = currentTenant;
             _morderAppService = morderAppService;
         }
         #endregion
@@ -349,6 +353,7 @@ namespace Business.ResourceExamineManagement
             crm_seorder sorder = _mysql_crm_seorder.GetListAsync(p => p.tenant_id == input.tenantId && p.factory_id == input.factoryId && p.Id == input.sorderId && !p.IsDeleted).Result.FirstOrDefault();
             if (sorder == null)
             {
+                new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "订单数据不存在", _currentTenant.Id.ToString());
                 throw new NotImplementedException("订单数据不存在!");
             }
             //获取订单行数据

+ 4 - 0
MicroServices/Business/Business.Core/Business.Core.csproj

@@ -11,8 +11,12 @@
     <PackageReference Include="MongoDB.Driver" Version="2.19.0" />
     <PackageReference Include="MongoDB.Driver.Core" Version="2.19.0" />
     <PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Spire.Barcode" Version="3.5.0" />
     <PackageReference Include="Spire.PDF" Version="4.11.3" />
+    <PackageReference Include="ThoughtWorks.QRCode" Version="1.1.0" />
     <PackageReference Include="Volo.Abp.Ddd.Domain" Version="6.0.0" />
   </ItemGroup>
 

+ 70 - 0
MicroServices/Business/Business.Core/Utilities/NLogHelper.cs

@@ -0,0 +1,70 @@
+using NLog;
+
+namespace Business.Core.Utilities
+{
+    /// <summary>
+    /// Nlog日志帮助类
+    /// </summary>
+    public class NLogHelper
+    {
+        #region 初始化
+        readonly Logger _logger;
+
+        private NLogHelper(Logger logger)
+        {
+            this._logger = logger;
+        }
+
+        /// <summary>
+        /// 自定义Logger,否则用默认的GetCurrentClassLogger
+        /// </summary>
+        /// <param name="name"></param>
+        public NLogHelper(string name) : this(LogManager.GetLogger(name))
+        {
+        }
+
+        /// <summary>
+        /// 默认 ${logger} (Default 文件夹下)
+        /// </summary>
+        public static NLogHelper Default { get; private set; }
+        static NLogHelper()
+        {
+            Default = new NLogHelper(LogManager.GetCurrentClassLogger());
+        }
+        #endregion
+
+        /// <summary>
+        /// 日志写入,默认info等级
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName,string Msg,string TenantId="")
+        {
+            LogEventInfo logEventInfo=new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = LogLevel.Info;
+            _logger.Log(logEventInfo);
+        }
+
+        /// <summary>
+        /// 日志写入,自己传日志类别
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="Level">日志级别</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg,LogLevel Level, string TenantId = "")
+        {
+            
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = Level;
+            _logger.Log(logEventInfo);
+        }
+    }
+}

+ 72 - 24
MicroServices/Business/Business.Core/Utilities/QRcodeHelper.cs

@@ -1,6 +1,7 @@
 using SharpCompress.Common;
-using Spire.Barcode;
+//using Spire.Barcode;
 using Spire.Pdf;
+using Spire.Pdf.Barcode;
 using Spire.Pdf.Graphics;
 using System;
 using System.Collections.Generic;
@@ -8,6 +9,7 @@ using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using ThoughtWorks.QRCode.Codec;
 using static System.Formats.Asn1.AsnWriter;
 
 namespace Business.Core.Utilities
@@ -20,9 +22,40 @@ namespace Business.Core.Utilities
         /// <summary>
         /// 生成二维码
         /// </summary>
-        /// <param name="filePath"></param>
-        /// <param name="context"></param>
-        public void GenerateQrCode(string filePath, string context)
+        /// <param name="context">二维码内容</param>
+        public Image GenerateQrCode(string context)
+        {
+            //使用ThoughtWorks.QRCode.Codec生成二维码
+            QRCodeEncoder qRCode = new QRCodeEncoder();
+            qRCode.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;          //编码方式(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字)
+            qRCode.QRCodeScale = 2;                                            //大小(值越大生成的二维码图片像素越高)-值越大,二维码图片越大
+            qRCode.QRCodeVersion = 0;                                          //版本(注意:设置为0主要是防止编码的字符串太长时发生错误)
+            qRCode.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;      //错误效验、错误更正(有4个等级)
+            qRCode.QRCodeBackgroundColor = Color.White;                        //背景色
+            qRCode.QRCodeForegroundColor = Color.Black;                        //前景色
+            System.Drawing.Bitmap bt = qRCode.Encode(context, Encoding.UTF8);
+
+            //bt.Save("二维码文件保存路径");//如果需要保存二维码,则返回文件路径即可
+            return bt;
+        }
+
+        /// <summary>
+        /// 生成条形码
+        /// </summary>
+        /// <param name="context">条形码内容</param>
+        public void GenerateBarcode(string context)
+        {
+            
+        }
+
+        /// <summary>
+        /// Pdf文档添加二维码
+        /// </summary>
+        /// <param name="filePath">文件路径</param>
+        /// <param name="context">二维码内容</param>
+        /// <param name="x">x轴偏移量</param>
+        /// <param name="y">y轴偏移量</param>
+        public void PdfAddQrCode(string filePath, string context,int x,int y)
         {
             PdfDocument pdf = new PdfDocument();
             //读取文件
@@ -30,38 +63,53 @@ namespace Business.Core.Utilities
             PdfPageBase pb = pdf.Pages.Add();
             pdf.Pages.Remove(pb);
 
-            //使用Spire.Barcode的BarcodeSettings和BarcodeGenerator类创建二维码图形
-            Spire.Barcode.BarcodeSettings settings = new BarcodeSettings();
-            settings.Type = BarCodeType.QRCode;
-            settings.Data = context;
-            settings.X = 0.7f;
-            settings.LeftMargin = 0;
-            settings.ShowText = false;
-            settings.AutoResize=true;
-            settings.ShowCheckSumChar = false;
-            settings.QRCodeECL = QRCodeECL.Q;
-            settings.QRCodeDataMode = QRCodeDataMode.Numeric;
-            Spire.Barcode.BarCodeGenerator generator = new BarCodeGenerator(settings);
-            Image image = generator.GenerateImage(new Size(20,20));
+            //生成二维码
+            Image image = GenerateQrCode(context);
 
-            //绘制二维码图形到PDF
+            //循环每一页,绘制二维码图形到PDF
             PdfImage pdfImage = PdfImage.FromImage(image);
             for (int i = 0; i < pdf.Pages.Count; i++)
             {
                 var page = pdf.Pages[i];
-                page.Canvas.DrawImage(pdfImage, page.Size.Width - pdfImage.Width + 9, 0);
+                //自定义位置
+                page.Canvas.DrawImage(pdfImage, x, y);
             }
-
             //保存文档
             pdf.SaveToFile(filePath);
         }
 
         /// <summary>
-        /// 生成条形码
+        /// Pdf文档添加条形码
         /// </summary>
-        public void GenerateBarcode()
-        { 
-        
+        /// <param name="filePath">文件路径</param>
+        /// <param name="context">挑衅码内容</param>
+        /// <param name="x">x轴偏移量</param>
+        /// <param name="y">y轴偏移量</param>
+        public void PdfAddBarcode(string filePath, string context, int x, int y)
+        {
+            PdfDocument pdf = new PdfDocument();
+            //读取文件
+            pdf.LoadFromFile(filePath);
+            PdfPageBase pb = pdf.Pages.Add();
+            pdf.Pages.Remove(pb);
+            //生成条形码
+            PdfCode39Barcode pdfCode = new PdfCode39Barcode(context);   //构造条形码内容
+            pdfCode.BarcodeToTextGapHeight = 2f;
+            pdfCode.TextDisplayLocation = TextLocation.Bottom;          //条形码文字位置
+            pdfCode.BarHeight = 40;                                     //高度
+            pdfCode.NarrowBarWidth = 0.5f;                              //宽度比例
+            pdfCode.TextColor = Color.Black;                            //文字颜色
+
+            //绘制条形码图形到PDF
+            for (int i = 0; i < pdf.Pages.Count; i++)
+            {
+                var page = pdf.Pages[i];
+                //自定义位置
+                pdfCode.Draw(page, new Point(x, y));
+            }
+            //保存文档
+            pdf.SaveToFile(filePath);
         }
+
     }
 }

+ 8 - 0
MicroServices/Business/Business.Host/Business.Host.csproj

@@ -16,6 +16,8 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.3" />
+    <PackageReference Include="NLog.Database" Version="5.1.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
     <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
@@ -40,4 +42,10 @@
     <Folder Include="wwwroot\" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Content Update="nlog.config">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
 </Project>

+ 20 - 1
MicroServices/Business/Business.Host/BusinessHostModule.cs

@@ -1,5 +1,6 @@
 using Autofac.Core;
 using Business.Core.MongoDBHelper;
+using Business.Core.Utilities;
 using Business.EntityFrameworkCore;
 using Business.MultiTenancy;
 using Business.Quartz;
@@ -11,8 +12,13 @@ using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
 using Microsoft.OpenApi.Models;
+using NLog;
+using NLog.Extensions.Logging;
+using NLog.Web;
 using Quartz;
+using Serilog.Events;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -93,11 +99,15 @@ namespace Business
 
         private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
         {
+            //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
+            LogHostedService logHostedService = new LogHostedService();
+            logHostedService.LogInstall();
+
             context.Services.AddQuartz(q =>
             {
                 q.UseMicrosoftDependencyInjectionScopedJobFactory();
                 // Just use the name of your job that you created in the Jobs folder.
-                var jobKey = new JobKey("DemoJob");
+                var jobKey = new JobKey("SyncDataJob");
                 q.AddJob<SyncMySQLDataJob>(opts => opts.WithIdentity(jobKey));
 
                 q.AddTrigger(opts => opts
@@ -105,6 +115,15 @@ namespace Business
                     .WithIdentity("DemoJob-trigger")
                     .WithCronSchedule("0 45 11 * * ?")
                     .WithDescription("定时同步MySQL基础数据到MongoDB"));
+
+                var NLogJobKey = new JobKey("NLogJob");
+                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(NLogJobKey)
+                    .WithIdentity("DemoJob-trigger")
+                    .WithCronSchedule("0 0 0 * * ?")
+                    .WithDescription("定时创建NLog日志按月分表"));
             });
             context.Services.AddQuartzServer(options =>
             {

+ 7 - 2
MicroServices/Business/Business.Host/Program.cs

@@ -1,8 +1,10 @@
 using System;
 using System.IO;
+using Business.Core.MongoDBHelper;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Hosting;
+using NLog.Web;
 using Serilog;
 using Serilog.Events;
 using Serilog.Sinks.Elasticsearch;
@@ -18,6 +20,7 @@ namespace Business
                 .AddJsonFile("appsettings.json")
                 .AddEnvironmentVariables()
                 .Build();
+            NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
 
             Log.Logger = new LoggerConfiguration()
 #if DEBUG
@@ -44,7 +47,8 @@ namespace Business
             }
             finally
             {
-                Log.CloseAndFlush();
+                //Log.CloseAndFlush();
+                NLog.LogManager.Shutdown();
             }
         }
 
@@ -55,6 +59,7 @@ namespace Business
                     webBuilder.UseStartup<Startup>();
                 })
                 .UseAutofac()
-                .UseSerilog();
+                //.UseSerilog()
+                .UseNLog();
     }
 }

+ 1 - 0
MicroServices/Business/Business.Host/appsettings.json

@@ -4,6 +4,7 @@
   },
   "ConnectionStrings": {
     "Default": "Server=123.60.180.165;Database=dopbiz;Uid=root; Pwd=5heng=uN;Allow User Variables=true",
+    "DOPLog": "Server=123.60.180.165;Database=doplog;Uid=root; Pwd=5heng=uN;Allow User Variables=true",
     "MongoDB": "mongodb://zzydop:h1Q$us3r@123.60.180.165/",
     "DBName": "dopbase"
   },

+ 73 - 0
MicroServices/Business/Business.Host/nlog.config

@@ -0,0 +1,73 @@
+<?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"
+      autoReload="true"
+	  throwExceptions="true"
+      internalLogLevel="Info"
+      internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Bussiness.txt">
+	<extensions>
+		<add assembly="NLog.Web.AspNetCore"/>
+	</extensions>
+	<!-- 定义变量当前应用程序名称 -->
+	<variable name="AppName" value="Bussiness" />
+	<!-- 日志输出目标 -->
+	<targets>
+		<!--把日志输出到控制台 -->
+		<target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline}      ${message}${exception:format=tostring}" />
+		<!-- 把日志记录到文件(通用) -->
+		<target xsi:type="File" name="allfile" fileName="${basedir}\..\Log\${date:format=yyyyMM}\${var:AppName}-all-${shortdate}.txt" encoding="UTF-8"
+            archiveFileName="${basedir}\..\Log\WMSAPI-all-${shortdate}.{#}.txt" archiveAboveSize="10485760"
+            layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
+		<!--把日志输出到数据库 -->
+		<target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}`  (
+					`id` bigint NOT NULL AUTO_INCREMENT,
+					`createtime` datetime NOT NULL,
+					`appname` varchar(50) NOT NULL,
+					`modulename` varchar(50)  NULL,
+					`level` varchar(50) NOT NULL,
+					`logger` varchar(1024) NULL DEFAULT NULL,
+					`msg` text NULL,
+					`userid` varchar(50) NULL DEFAULT NULL,
+					`url` varchar(1024) NULL DEFAULT NULL,
+					`ip` varchar(255) NULL DEFAULT NULL,
+					`tenantId` varchar(50) NULL,
+					PRIMARY KEY (`id`) USING BTREE
+					);
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
+			</commandText>
+			<parameter name="@CreateTime" layout="${longdate}" />
+			<parameter name="@AppName" layout="${var:AppName}" />
+			<parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
+			<parameter name="@Level" layout="${level}" />
+			<parameter name="@Logger" layout="${logger}" allowDbNull="true" />
+			<parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
+			<parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
+			<parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
+			<parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
+            <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
+		</target>
+	</targets>
+
+	<!-- 日志输出规则 -->
+	<rules>
+		<!--All logs, including from Microsoft-->
+		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
+
+		<!--Output hosting lifetime messages to console target for faster startup detection -->
+		<logger name="Microsoft.Hosting.Lifetime" minlevel="Debug" writeTo="allfile,database" final="true" />
+		<logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" writeTo="allfile,database" final="true" />
+
+		<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
+		<logger name="Microsoft.*" maxlevel="Info" final="true" />
+		<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
+
+		<logger name="*" minlevel="Trace" writeTo="allfile,database" />
+	</rules>
+</nlog>

+ 53 - 7
MicroServices/Business/Business.HttpApi/Controllers/QRcodeController.cs

@@ -7,6 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using Volo.Abp.AspNetCore.Mvc;
 using Volo.Abp;
+using System.Drawing;
 
 namespace Business.Controllers
 {
@@ -15,20 +16,65 @@ namespace Business.Controllers
     /// </summary>
     [RemoteService]
     [Area("Business")]
-    [Route("api/business/qrcode")]
+    [Route("api/business/codehelper")]
     public class QRcodeController : AbpController
     {
         /// <summary>
-        /// 雪花算法
+        /// 生成二维码
         /// </summary>
-        /// <returns></returns>
+        /// <param name="context">二维码内容</param>
         [HttpGet]
-        public void GenerateQrCode()
+        [Route("generate_qrcode")]
+        public Image GenerateQrCode(string context)
         {
+            //二维码帮助类
             QRcodeHelper qRcode = new QRcodeHelper();
-            string filePath = @"D:\test\销售出库单.pdf";
-            string context = "AXSCK230201473";
-            qRcode.GenerateQrCode(filePath, context);
+            //生成二维码
+            return qRcode.GenerateQrCode(context);
+        }
+
+        ///// <summary>
+        ///// 生成条形码
+        ///// </summary>
+        ///// <param name="context">条形码内容</param>
+        //[HttpGet]
+        //[Route("generate_barcode")]
+        //public void GenerateBarcode(string context)
+        //{
+        //    QRcodeHelper qRcode = new QRcodeHelper();
+        //    qRcode.GenerateBarcode(context);
+        //}
+
+        /// <summary>
+        /// Pdf文档添加二维码
+        /// </summary>
+        /// <param name="filePath">文件路径</param>
+        /// <param name="context">二维码内容</param>
+        /// <param name="x">x轴偏移量</param>
+        /// <param name="y">y轴偏移量</param>
+        [HttpGet]
+        [Route("pdfaddqrcode")]
+        public void PdfAddQrCode(string filePath, string context, int x, int y)
+        {
+            //二维码帮助类
+            QRcodeHelper qRcode = new QRcodeHelper();
+            //生成二维码
+            qRcode.PdfAddQrCode(filePath, context, x, y);
+        }
+
+        /// <summary>
+        /// Pdf文档添加条形码
+        /// </summary>
+        /// <param name="filePath">文件路径</param>
+        /// <param name="context">挑衅码内容</param>
+        /// <param name="x">x轴偏移量</param>
+        /// <param name="y">y轴偏移量</param>
+        [HttpGet]
+        [Route("pdfaddbarcode")]
+        public void PdfAddBarcode(string filePath, string context, int x, int y)
+        {
+            QRcodeHelper qRcode = new QRcodeHelper();
+            qRcode.PdfAddBarcode(filePath, context, x, y);
         }
     }
 }

+ 4 - 1
MicroServices/Business/Business.HttpApi/Controllers/TestController.cs

@@ -1,4 +1,5 @@
-using Business.Test;
+using Business.Core.Utilities;
+using Business.Test;
 using Microsoft.AspNetCore.Mvc;
 using System.Collections.Generic;
 using System.Linq;
@@ -44,6 +45,8 @@ namespace Business.Controllers
         [Route("user-count")]
         public Task<long> GetUserCount()
         {
+            NLogHelper.Default.WriteLog("TestController", "默认logger","");
+            new NLogHelper("TestController").WriteLog("TestController", "自定义logger","");
             return _testAppService.GetUserCount();
         }
 

+ 3 - 3
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturing.Application.Contracts.csproj

@@ -4,11 +4,11 @@
     <TargetFramework>net6.0</TargetFramework>
     <RootNamespace>DigitalManufacturing</RootNamespace>
     <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-    <PackageId>XCZ.Procurement.Application.Contracts</PackageId>
+    <PackageId>XCZ.DigitalManufacturing.Application.Contracts</PackageId>
     <Version>0.1.1</Version>
     <Authors>XCZ</Authors>
-    <Product>Procurement</Product>
-    <Description>Procurement服务Application.Contracts远程依赖</Description>
+    <Product>DigitalManufacturing</Product>
+    <Description>DigitalManufacturing服务Application.Contracts远程依赖</Description>
     <PackageProjectUrl>https://github.com/WilliamXu96/ABP-MicroService</PackageProjectUrl>
     <RepositoryUrl>https://github.com/WilliamXu96/ABP-MicroService</RepositoryUrl>
   </PropertyGroup>

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingApplicationContractsModule.cs

@@ -6,7 +6,7 @@ using Volo.Abp.PermissionManagement;
 using Volo.Abp.Validation.Localization;
 using Volo.Abp.VirtualFileSystem;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
        typeof(AbpLocalizationModule),

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/FileInfoDto.cs

@@ -1,7 +1,7 @@
 using System;
 using Volo.Abp.Application.Dtos;
 
-namespace Procurement.FileManagement.Dto
+namespace DigitalManufacturing.FileManagement.Dto
 {
     public class FileInfoDto : EntityDto<Guid>
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/Dto/GetFileInputDto.cs

@@ -1,6 +1,6 @@
 using Volo.Abp.Application.Dtos;
 
-namespace Procurement.FileManagement.Dto
+namespace DigitalManufacturing.FileManagement.Dto
 {
     public class GetFileInputDto : PagedAndSortedResultRequestDto
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/DigitalManufacturingManagement/IDigitalManufacturingAppService.cs

@@ -1,4 +1,4 @@
-using Procurement.FileManagement.Dto;
+using DigitalManufacturing.FileManagement.Dto;
 using Microsoft.AspNetCore.Http;
 using System.ComponentModel.DataAnnotations;
 using System.Threading.Tasks;

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissionDefinitionProvider.cs

@@ -3,7 +3,7 @@ using Volo.Abp.Authorization.Permissions;
 using Volo.Abp.Localization;
 using Volo.Abp.MultiTenancy;
 
-namespace Procurement.Permissions
+namespace DigitalManufacturing.Permissions
 {
     public class DigitalManufacturingPermissionDefinitionProvider: PermissionDefinitionProvider
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application.Contracts/Permissions/DigitalManufacturingPermissions.cs

@@ -1,4 +1,4 @@
-namespace Procurement.Permissions
+namespace DigitalManufacturing.Permissions
 {
     public static class DigitalManufacturingPermissions
     {

+ 4 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturing.Application.csproj

@@ -2,16 +2,19 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="6.0.0" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.0" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\DigitalManufacturing.Application.Contracts\DigitalManufacturing.Application.Contracts.csproj" />
+    <ProjectReference Include="..\DigitalManufacturing.Core\DigitalManufacturing.Core.csproj" />
     <ProjectReference Include="..\DigitalManufacturing.Domain\DigitalManufacturing.Domain.csproj" />
   </ItemGroup>
 

+ 3 - 3
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationAutoMapperProfile.cs

@@ -1,8 +1,8 @@
 using AutoMapper;
-using Procurement.FileManagement.Dto;
-using Procurement.Models;
+using DigitalManufacturing.FileManagement.Dto;
+using DigitalManufacturing.Models;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     public class DigitalManufacturingApplicationAutoMapperProfile : Profile
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingApplicationModule.cs

@@ -1,7 +1,7 @@
 using Volo.Abp.AutoMapper;
 using Volo.Abp.Modularity;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
         typeof(DigitalManufacturingDomainModule),

+ 13 - 6
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/DigitalManufacturingManagement/DigitalManufacturingAppService.cs

@@ -1,6 +1,7 @@
-using Procurement.Enums;
-using Procurement.FileManagement.Dto;
-using Procurement.Models;
+using DigitalManufacturing.Core;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.FileManagement.Dto;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore;
@@ -14,21 +15,25 @@ using System.Threading.Tasks;
 using Volo.Abp;
 using Volo.Abp.Application.Dtos;
 using Volo.Abp.Application.Services;
+using Volo.Abp.DependencyInjection;
 using Volo.Abp.Domain.Repositories;
-using FileInfo = Procurement.Models.FileInfo;
+using Volo.Abp.MultiTenancy;
+using FileInfo = DigitalManufacturing.Models.FileInfo;
 
 namespace DigitalManufacturing.DigitalManufacturingManagement
 {
-    public class DigitalManufacturingAppService : ApplicationService, IDigitalManufacturingAppService
+    public class DigitalManufacturingAppService : ApplicationService, IDigitalManufacturingAppService, ITransientDependency
     {
+        private readonly ICurrentTenant _currentTenant;
         private readonly IRepository<FileInfo, Guid> _repository;
         private readonly FileManager _fileManager;
         string[] pictureFormatArray = { ".png", ".jpg", ".jpeg", ".gif", ".PNG", ".JPG", ".JPEG", ".GIF" };
 
-        public DigitalManufacturingAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager)
+        public DigitalManufacturingAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager, ICurrentTenant currentTenant)
         {
             _repository = repository;
             _fileManager = fileManager;
+            _currentTenant = currentTenant;
         }
 
         public async Task<PagedResultDto<FileInfoDto>> GetAll(GetFileInputDto input)
@@ -52,6 +57,8 @@ namespace DigitalManufacturing.DigitalManufacturingManagement
             //限制100M
             if (file.Length > 104857600)
             {
+                NLogHelper.Default.WriteLog("GetAll", "上传文件过大", _currentTenant.Id.ToString());
+                new NLogHelper("DigitalManufacturingAppService").WriteLog("GetAll", "自定义logger", _currentTenant.Id.ToString());
                 throw new BusinessException("上传文件过大");
             }
             //文件格式

+ 20 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/LogHostedService.cs

@@ -0,0 +1,20 @@
+using Microsoft.Extensions.Hosting;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace DigitalManufacturing.Quartz
+{
+    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+    public class LogHostedService
+    {
+        public void LogInstall()
+        {
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+        }
+    }
+}

+ 28 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Application/Quartz/NLogJob.cs

@@ -0,0 +1,28 @@
+using Quartz;
+using System.Threading.Tasks;
+
+namespace DigitalManufacturing.Quartz
+{
+    public class NLogJob : IJob
+    {
+
+        /// <summary>
+        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+        /// </summary>
+        public readonly LogHostedService _logHostedService;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public NLogJob(LogHostedService logHostedService)
+        {
+            _logHostedService = logHostedService;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _logHostedService.LogInstall();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 14 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Core/DigitalManufacturing.Core.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+  </ItemGroup>
+
+</Project>

+ 70 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Core/NLogHelper.cs

@@ -0,0 +1,70 @@
+using NLog;
+
+namespace DigitalManufacturing.Core
+{
+    /// <summary>
+    /// Nlog日志帮助类
+    /// </summary>
+    public class NLogHelper
+    {
+        #region 初始化
+        readonly Logger _logger;
+
+        private NLogHelper(Logger logger)
+        {
+            this._logger = logger;
+        }
+
+        /// <summary>
+        /// 自定义Logger,否则用默认的GetCurrentClassLogger
+        /// </summary>
+        /// <param name="name"></param>
+        public NLogHelper(string name) : this(LogManager.GetLogger(name))
+        {
+        }
+
+        /// <summary>
+        /// 默认 ${logger} (Default 文件夹下)
+        /// </summary>
+        public static NLogHelper Default { get; private set; }
+        static NLogHelper()
+        {
+            Default = new NLogHelper(LogManager.GetCurrentClassLogger());
+        }
+        #endregion
+
+        /// <summary>
+        /// 日志写入,默认info等级
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg, string TenantId = "")
+        {
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = LogLevel.Info;
+            _logger.Log(logEventInfo);
+        }
+
+        /// <summary>
+        /// 日志写入,自己传日志类别
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="Level">日志级别</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg, LogLevel Level, string TenantId = "")
+        {
+
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = Level;
+            _logger.Log(logEventInfo);
+        }
+    }
+}

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturing.Domain.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/DigitalManufacturingDomainModule.cs

@@ -1,7 +1,7 @@
 using Volo.Abp.Localization;
 using Volo.Abp.Modularity;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
         typeof(AbpLocalizationModule)

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Enums/Enums.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace Procurement.Enums
+namespace DigitalManufacturing.Enums
 {
     public enum FileType
     {

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileInfo.cs

@@ -1,10 +1,10 @@
-using Procurement.Enums;
+using DigitalManufacturing.Enums;
 using System;
 using Volo.Abp;
 using Volo.Abp.Domain.Entities.Auditing;
 using Volo.Abp.MultiTenancy;
 
-namespace Procurement.Models
+namespace DigitalManufacturing.Models
 {
     public class FileInfo : AuditedAggregateRoot<Guid>, ISoftDelete, IMultiTenant
     {

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Domain/Models/FileManager.cs

@@ -1,10 +1,10 @@
-using Procurement.Enums;
+using DigitalManufacturing.Enums;
 using System;
 using System.Threading.Tasks;
 using Volo.Abp.Domain.Repositories;
 using Volo.Abp.Domain.Services;
 
-namespace Procurement.Models
+namespace DigitalManufacturing.Models
 {
     public class FileManager : DomainService
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/DigitalManufacturing.EntityFrameworkCore.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContext.cs

@@ -1,4 +1,4 @@
-using Procurement.Models;
+using DigitalManufacturing.Models;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
@@ -6,7 +6,7 @@ using System.Text;
 using Volo.Abp.Data;
 using Volo.Abp.EntityFrameworkCore;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     [ConnectionStringName("Default")]
     public class DigitalManufacturingDbContext : AbpDbContext<DigitalManufacturingDbContext>

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingDbContextModelCreatingExtensions.cs

@@ -1,4 +1,4 @@
-using Procurement.Models;
+using DigitalManufacturing.Models;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
@@ -6,7 +6,7 @@ using System.Text;
 using Volo.Abp;
 using Volo.Abp.EntityFrameworkCore.Modeling;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     public static class DigitalManufacturingDbContextModelCreatingExtensions
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.EntityFrameworkCore/EntityFrameworkCore/DigitalManufacturingEntityFrameworkCoreModule.cs

@@ -3,7 +3,7 @@ using Volo.Abp.EntityFrameworkCore;
 using Volo.Abp.Modularity;
 using Volo.Abp.PermissionManagement.EntityFrameworkCore;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     [DependsOn(
         typeof(DigitalManufacturingDomainModule),

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/DOP/DOPController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/HomeController.cs

@@ -1,7 +1,7 @@
 using Microsoft.AspNetCore.Mvc;
 using Volo.Abp.AspNetCore.Mvc;
 
-namespace Procurement.Controllers
+namespace DigitalManufacturing.Controllers
 {
     public class HomeController : AbpController
     {

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/Kanban/KanbanController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/MES/MESController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/QMS/QMSController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/AndonController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/SIM/SIMController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 2 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Controllers/WMS/WMSController.cs

@@ -1,5 +1,5 @@
-using Procurement.Enums;
-using Procurement.Models;
+using DigitalManufacturing.Enums;
+using DigitalManufacturing.Models;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;

+ 10 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturing.Host.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
-    <RootNamespace>Procurement</RootNamespace>
+    <RootNamespace>DigitalManufacturing</RootNamespace>
   </PropertyGroup>
 
   <ItemGroup>
@@ -13,6 +13,9 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.3" />
+    <PackageReference Include="NLog.Database" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
     <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
@@ -33,4 +36,10 @@
     <Folder Include="wwwroot\Images\" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Content Update="nlog.config">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+
 </Project>

+ 36 - 2
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/DigitalManufacturingHostModule.cs

@@ -1,4 +1,4 @@
-using Procurement.EntityFrameworkCore;
+using DigitalManufacturing.EntityFrameworkCore;
 using Microsoft.AspNetCore.Authentication.JwtBearer;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Cors;
@@ -25,8 +25,10 @@ using Volo.Abp.Modularity;
 using Volo.Abp.MultiTenancy;
 using Volo.Abp.Threading;
 using Volo.Abp.VirtualFileSystem;
+using DigitalManufacturing.Quartz;
+using Quartz;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     [DependsOn(
         typeof(AbpAutofacModule),
@@ -55,6 +57,38 @@ namespace Procurement
             ConfigureCors(context, configuration);
             //ConfigureRedis(context, configuration, hostingEnvironment);
             ConfigureSwaggerServices(context);
+            ConfigureQuartz(context, configuration);
+        }
+
+        private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
+        {
+            //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
+            LogHostedService logHostedService = new LogHostedService();
+            logHostedService.LogInstall();
+
+            context.Services.AddQuartz(q =>
+            {
+                q.UseMicrosoftDependencyInjectionScopedJobFactory();
+    
+                var NLogJobKey = new JobKey("NLogJob");
+                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(NLogJobKey)
+                    .WithIdentity("DemoJob-trigger")
+                    .WithCronSchedule("0 0 0 * * ?")
+                    .WithDescription("定时创建NLog日志按月分表"));
+            });
+            context.Services.AddQuartzServer(options =>
+            {
+                // when shutting down we want jobs to complete gracefully
+                options.WaitForJobsToComplete = true;
+            });
+            //context.Services.AddQuartzHostedService(options =>
+            //{
+            //    // when shutting down we want jobs to complete gracefully
+            //    options.WaitForJobsToComplete = true;
+            //});
         }
 
         private void ConfigureConventionalControllers()

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContext.cs

@@ -5,7 +5,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using Volo.Abp.EntityFrameworkCore;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     public class DigitalManufacturingMigrationDbContext : AbpDbContext<DigitalManufacturingMigrationDbContext>
     {

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/EntityFrameworkCore/DigitalManufacturingMigrationDbContextFactory.cs

@@ -7,7 +7,7 @@ using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
 
-namespace Procurement.EntityFrameworkCore
+namespace DigitalManufacturing.EntityFrameworkCore
 {
     public class DigitalManufacturingMigrationDbContextFactory : IDesignTimeDbContextFactory<DigitalManufacturingMigrationDbContext>
     {

+ 7 - 4
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Program.cs

@@ -3,10 +3,11 @@ using System.IO;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Hosting;
+using NLog.Web;
 using Serilog;
 using Serilog.Events;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     public class Program
     {
@@ -17,7 +18,7 @@ namespace Procurement
                 .AddJsonFile("appsettings.json")
                 .AddEnvironmentVariables()
                 .Build();
-
+            NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
             Log.Logger = new LoggerConfiguration()
 #if DEBUG
                 .MinimumLevel.Debug()
@@ -32,7 +33,7 @@ namespace Procurement
 
             try
             {
-                Log.Information("Starting Procurement.Host");
+                Log.Information("Starting DigitalManufacturing.Host");
                 CreateHostBuilder(args).Build().Run();
                 return 0;
             }
@@ -44,6 +45,7 @@ namespace Procurement
             finally
             {
                 Log.CloseAndFlush();
+                NLog.LogManager.Shutdown();
             }
         }
 
@@ -54,6 +56,7 @@ namespace Procurement
                     webBuilder.UseStartup<Startup>();
                 })
                 .UseAutofac()
-                .UseSerilog();
+                .UseSerilog()
+                .UseNLog();
     }
 }

+ 1 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/Startup.cs

@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
 
-namespace Procurement
+namespace DigitalManufacturing
 {
     public class Startup
     {

+ 2 - 1
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/appsettings.json

@@ -3,7 +3,8 @@
     "CorsOrigins": "http://localhost:9527"
   },
   "ConnectionStrings": {
-    "Default": "Server=123.60.180.165;Database=dopbiz;Uid=root; Pwd=5heng=uN;Allow User Variables=True;sslMode=None;"
+    "Default": "Server=123.60.180.165;Database=dopbiz;Uid=root; Pwd=5heng=uN;Allow User Variables=True;sslMode=None;",
+    "DOPLog": "Server=123.60.180.165;Database=doplog;Uid=root; Pwd=5heng=uN;Allow User Variables=true"
   },
   "Redis": {
     "Configuration": "192.168.1.191"

+ 69 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.Host/nlog.config

@@ -0,0 +1,69 @@
+<?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"
+      autoReload="true"
+	  throwExceptions="true"
+      internalLogLevel="Info"
+      internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Bussiness.txt">
+	<extensions>
+		<add assembly="NLog.Web.AspNetCore"/>
+	</extensions>
+	<!-- 定义变量当前应用程序名称 -->
+	<variable name="AppName" value="Bussiness" />
+	<!-- 日志输出目标 -->
+	<targets>
+		<!--把日志输出到控制台 -->
+		<target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline}      ${message}${exception:format=tostring}" />
+		<!--把日志输出到数据库 -->
+		<target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}`  (
+					`id` bigint NOT NULL AUTO_INCREMENT,
+					`createtime` datetime NOT NULL,
+					`appname` varchar(50) NOT NULL,
+					`modulename` varchar(50)  NULL,
+					`level` varchar(50) NOT NULL,
+					`logger` varchar(1024) NULL DEFAULT NULL,
+					`msg` text NULL,
+					`userid` varchar(50) NULL DEFAULT NULL,
+					`url` varchar(1024) NULL DEFAULT NULL,
+					`ip` varchar(255) NULL DEFAULT NULL,
+					`tenantId` varchar(50) NULL,
+					PRIMARY KEY (`id`) USING BTREE
+					);
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
+			</commandText>
+			<parameter name="@CreateTime" layout="${longdate}" />
+			<parameter name="@AppName" layout="${var:AppName}" />
+			<parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
+			<parameter name="@Level" layout="${level}" />
+			<parameter name="@Logger" layout="${logger}" allowDbNull="true" />
+			<parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
+			<parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
+			<parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
+			<parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
+            <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
+		</target>
+	</targets>
+
+	<!-- 日志输出规则 -->
+	<rules>
+		<!--All logs, including from Microsoft-->
+		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
+
+		<!--Output hosting lifetime messages to console target for faster startup detection -->
+		<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole,database" final="true" />
+		<logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" final="true" />
+
+		<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
+		<logger name="Microsoft.*" maxlevel="Info" final="true" />
+		<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
+
+		<logger name="*" minlevel="Trace" writeTo="lifetimeConsole,database" />
+	</rules>
+</nlog>

+ 6 - 0
MicroServices/DigitalManufacturing/DigitalManufacturing.sln

@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalManufacturing.Applic
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalManufacturing.EntityFrameworkCore", "DigitalManufacturing.EntityFrameworkCore\DigitalManufacturing.EntityFrameworkCore.csproj", "{1938B13A-4806-487A-A374-1C66D750F133}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalManufacturing.Core", "DigitalManufacturing.Core\DigitalManufacturing.Core.csproj", "{596E8B63-69DC-4AA9-B644-512F3E85DACE}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{1938B13A-4806-487A-A374-1C66D750F133}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.Build.0 = Release|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{596E8B63-69DC-4AA9-B644-512F3E85DACE}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 3 - 0
MicroServices/Procurement/Procurement.Application/Procurement.Application.csproj

@@ -6,12 +6,15 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="6.0.0" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.0" />
   </ItemGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\Procurement.Application.Contracts\Procurement.Application.Contracts.csproj" />
+    <ProjectReference Include="..\Procurement.Core\Procurement.Core.csproj" />
     <ProjectReference Include="..\Procurement.Domain\Procurement.Domain.csproj" />
   </ItemGroup>
 

+ 7 - 1
MicroServices/Procurement/Procurement.Application/ProcurementManagement/ProcurementAppService.cs

@@ -16,19 +16,23 @@ using Volo.Abp.Application.Dtos;
 using Volo.Abp.Application.Services;
 using Volo.Abp.Domain.Repositories;
 using FileInfo = Procurement.Models.FileInfo;
+using Volo.Abp.MultiTenancy;
+using Procurement.Core;
 
 namespace Procurement.FileManagement
 {
     public class ProcurementAppService : ApplicationService, IProcurementAppService
     {
+        private readonly ICurrentTenant _currentTenant;
         private readonly IRepository<FileInfo, Guid> _repository;
         private readonly FileManager _fileManager;
         string[] pictureFormatArray = { ".png", ".jpg", ".jpeg", ".gif", ".PNG", ".JPG", ".JPEG", ".GIF" };
 
-        public ProcurementAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager)
+        public ProcurementAppService(IRepository<FileInfo, Guid> repository, FileManager fileManager, ICurrentTenant currentTenant)
         {
             _repository = repository;
             _fileManager = fileManager;
+            _currentTenant = currentTenant;
         }
 
         public async Task<PagedResultDto<FileInfoDto>> GetAll(GetFileInputDto input)
@@ -52,6 +56,8 @@ namespace Procurement.FileManagement
             //限制100M
             if (file.Length > 104857600)
             {
+                new NLogHelper("ProcurementAppService").WriteLog("Upload", "上传文件过大",NLog.LogLevel.Error,_currentTenant.Id.ToString());
+                NLogHelper.Default.WriteLog("Upload", "上传文件过大", _currentTenant.Id.ToString());
                 throw new BusinessException("上传文件过大");
             }
             //文件格式

+ 20 - 0
MicroServices/Procurement/Procurement.Application/Quartz/LogHostedService.cs

@@ -0,0 +1,20 @@
+using Microsoft.Extensions.Hosting;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Procurement.Quartz
+{
+    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+    public class LogHostedService
+    {
+        public void LogInstall()
+        {
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+        }
+    }
+}

+ 28 - 0
MicroServices/Procurement/Procurement.Application/Quartz/NLogJob.cs

@@ -0,0 +1,28 @@
+using Quartz;
+using System.Threading.Tasks;
+
+namespace Procurement.Quartz
+{
+    public class NLogJob : IJob
+    {
+
+        /// <summary>
+        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
+        /// </summary>
+        public readonly LogHostedService _logHostedService;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public NLogJob(LogHostedService logHostedService)
+        {
+            _logHostedService = logHostedService;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _logHostedService.LogInstall();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 70 - 0
MicroServices/Procurement/Procurement.Core/NLogHelper.cs

@@ -0,0 +1,70 @@
+using NLog;
+
+namespace Procurement.Core
+{
+    /// <summary>
+    /// Nlog日志帮助类
+    /// </summary>
+    public class NLogHelper
+    {
+        #region 初始化
+        readonly Logger _logger;
+
+        private NLogHelper(Logger logger)
+        {
+            this._logger = logger;
+        }
+
+        /// <summary>
+        /// 自定义Logger,否则用默认的GetCurrentClassLogger
+        /// </summary>
+        /// <param name="name"></param>
+        public NLogHelper(string name) : this(LogManager.GetLogger(name))
+        {
+        }
+
+        /// <summary>
+        /// 默认 ${logger} (Default 文件夹下)
+        /// </summary>
+        public static NLogHelper Default { get; private set; }
+        static NLogHelper()
+        {
+            Default = new NLogHelper(LogManager.GetCurrentClassLogger());
+        }
+        #endregion
+
+        /// <summary>
+        /// 日志写入,默认info等级
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName,string Msg,string TenantId="")
+        {
+            LogEventInfo logEventInfo=new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = LogLevel.Info;
+            _logger.Log(logEventInfo);
+        }
+
+        /// <summary>
+        /// 日志写入,自己传日志类别
+        /// </summary>
+        /// <param name="ModuleName">模块名称</param>
+        /// <param name="Msg">日志内容</param>
+        /// <param name="Level">日志级别</param>
+        /// <param name="TenantId">租户Id</param>
+        public void WriteLog(string ModuleName, string Msg,LogLevel Level, string TenantId = "")
+        {
+            
+            LogEventInfo logEventInfo = new LogEventInfo();
+            logEventInfo.Properties["ModuleName"] = ModuleName;
+            logEventInfo.Properties["Msg"] = Msg;
+            logEventInfo.Properties["TenantId"] = TenantId;
+            logEventInfo.Level = Level;
+            _logger.Log(logEventInfo);
+        }
+    }
+}

+ 15 - 0
MicroServices/Procurement/Procurement.Core/Procurement.Core.csproj

@@ -0,0 +1,15 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="NLog" Version="5.1.2" />
+    <PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
+  </ItemGroup>
+
+</Project>

+ 2 - 0
MicroServices/Procurement/Procurement.Host/Procurement.Host.csproj

@@ -13,6 +13,8 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.3" />
+    <PackageReference Include="NLog.Database" Version="5.1.2" />
+    <PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
     <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
     <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />

+ 34 - 0
MicroServices/Procurement/Procurement.Host/ProcurementHostModule.cs

@@ -25,6 +25,8 @@ using Volo.Abp.Modularity;
 using Volo.Abp.MultiTenancy;
 using Volo.Abp.Threading;
 using Volo.Abp.VirtualFileSystem;
+using Procurement.Quartz;
+using Quartz;
 
 namespace Procurement
 {
@@ -55,6 +57,7 @@ namespace Procurement
             ConfigureCors(context, configuration);
             //ConfigureRedis(context, configuration, hostingEnvironment);
             ConfigureSwaggerServices(context);
+            ConfigureQuartz(context, configuration);
         }
 
         private void ConfigureConventionalControllers()
@@ -142,6 +145,37 @@ namespace Procurement
                 });
         }
 
+        private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
+        {
+            //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
+            LogHostedService logHostedService = new LogHostedService();
+            logHostedService.LogInstall();
+
+            context.Services.AddQuartz(q =>
+            {
+                q.UseMicrosoftDependencyInjectionScopedJobFactory();
+  
+                var NLogJobKey = new JobKey("NLogJob");
+                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(NLogJobKey)
+                    .WithIdentity("DemoJob-trigger")
+                    .WithCronSchedule("0 0 0 * * ?")
+                    .WithDescription("定时创建NLog日志按月分表"));
+            });
+            context.Services.AddQuartzServer(options =>
+            {
+                // when shutting down we want jobs to complete gracefully
+                options.WaitForJobsToComplete = true;
+            });
+            //context.Services.AddQuartzHostedService(options =>
+            //{
+            //    // when shutting down we want jobs to complete gracefully
+            //    options.WaitForJobsToComplete = true;
+            //});
+        }
+
         private void ConfigureLocalization()
         {
             Configure<AbpLocalizationOptions>(options =>

+ 2 - 1
MicroServices/Procurement/Procurement.Host/Program.cs

@@ -17,7 +17,7 @@ namespace Procurement
                 .AddJsonFile("appsettings.json")
                 .AddEnvironmentVariables()
                 .Build();
-
+            NLog.Extensions.Logging.ConfigSettingLayoutRenderer.DefaultConfiguration = configuration;
             Log.Logger = new LoggerConfiguration()
 #if DEBUG
                 .MinimumLevel.Debug()
@@ -44,6 +44,7 @@ namespace Procurement
             finally
             {
                 Log.CloseAndFlush();
+                NLog.LogManager.Shutdown();
             }
         }
 

+ 69 - 0
MicroServices/Procurement/Procurement.Host/nlog.config

@@ -0,0 +1,69 @@
+<?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"
+      autoReload="true"
+	  throwExceptions="true"
+      internalLogLevel="Info"
+      internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Procurement.txt">
+	<extensions>
+		<add assembly="NLog.Web.AspNetCore"/>
+	</extensions>
+	<!-- 定义变量当前应用程序名称 -->
+	<variable name="AppName" value="Procurement" />
+	<!-- 日志输出目标 -->
+	<targets>
+		<!--把日志输出到控制台 -->
+		<target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline}      ${message}${exception:format=tostring}" />
+		<!--把日志输出到数据库 -->
+		<target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
+			<install-command ignoreFailures="true">
+				<text>
+					<!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
+					CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}`  (
+					`id` bigint NOT NULL AUTO_INCREMENT,
+					`createtime` datetime NOT NULL,
+					`appname` varchar(50) NOT NULL,
+					`modulename` varchar(50)  NULL,
+					`level` varchar(50) NOT NULL,
+					`logger` varchar(1024) NULL DEFAULT NULL,
+					`msg` text NULL,
+					`userid` varchar(50) NULL DEFAULT NULL,
+					`url` varchar(1024) NULL DEFAULT NULL,
+					`ip` varchar(255) NULL DEFAULT NULL,
+					`tenantId` varchar(50) NULL,
+					PRIMARY KEY (`id`) USING BTREE
+					);
+				</text>
+			</install-command>
+			<commandText>
+				INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
+			</commandText>
+			<parameter name="@CreateTime" layout="${longdate}" />
+			<parameter name="@AppName" layout="${var:AppName}" />
+			<parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
+			<parameter name="@Level" layout="${level}" />
+			<parameter name="@Logger" layout="${logger}" allowDbNull="true" />
+			<parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
+			<parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
+			<parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
+			<parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
+            <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
+		</target>
+	</targets>
+
+	<!-- 日志输出规则 -->
+	<rules>
+		<!--All logs, including from Microsoft-->
+		<!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
+
+		<!--Output hosting lifetime messages to console target for faster startup detection -->
+		<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole,database" final="true" />
+		<logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" final="true" />
+
+		<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
+		<logger name="Microsoft.*" maxlevel="Info" final="true" />
+		<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
+
+		<logger name="*" minlevel="Trace" writeTo="lifetimeConsole,database" />
+	</rules>
+</nlog>

+ 6 - 0
MicroServices/Procurement/Procurement.sln

@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Procurement.Application", "
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Procurement.EntityFrameworkCore", "Procurement.EntityFrameworkCore\Procurement.EntityFrameworkCore.csproj", "{1938B13A-4806-487A-A374-1C66D750F133}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Procurement.Core", "Procurement.Core\Procurement.Core.csproj", "{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{1938B13A-4806-487A-A374-1C66D750F133}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1938B13A-4806-487A-A374-1C66D750F133}.Release|Any CPU.Build.0 = Release|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{604C3CC6-AEDF-433F-8DDC-630E0B0552AF}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE