diff --git a/Data/Report_Dry.cs b/Data/Report_Dry.cs new file mode 100644 index 0000000..d289e21 --- /dev/null +++ b/Data/Report_Dry.cs @@ -0,0 +1,66 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +/// +/// 干混机报表 +/// + +public partial class Report_Dry { + + /// + /// 主键标识 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 车次 + /// + + public int? Batch { get; set; } + + /// + /// 是第几台干混机 + /// + + public int? dryNo { get; set; } + + /// + /// 计划编码 + /// + + public int? planCode { get; set; } + + /// + /// 计划名称 + /// + + public string planName { get; set; } = string.Empty; + + /// + /// 设备编号 + /// + + public int? recipeCode { get; set; } + + /// + /// 配方名称 + /// + + public string recipeName { get; set; } = string.Empty; + + /// + /// 记录时间 + /// + + public DateTime? recordTime { get; set; } + + /// + /// 报表标识 + /// + + public string reportId { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/Data/Report_DryDos_Detail.cs b/Data/Report_DryDos_Detail.cs new file mode 100644 index 0000000..4548923 --- /dev/null +++ b/Data/Report_DryDos_Detail.cs @@ -0,0 +1,62 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +public partial class Report_DryDos_Detail { + + /// + /// 主键 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 实际公差 + /// + + public double? actToler { get; set; } + + /// + /// 实际重量 + /// + + public double? actValue { get; set; } + + /// + /// 批次号 + /// + + public int? batch { get; set; } + + /// + /// 设备编号 + /// + + public int? eqNo { get; set; } + + /// + /// 物料代码 + /// + + public int? matCode { get; set; } + + + public DateTime? recordTime { get; set; } + + + public string reportId { get; set; } = string.Empty; + + /// + /// 设定公差 + /// + + public double? setToler { get; set; } + + /// + /// 设定重量 + /// + + public double? setValue { get; set; } + +} \ No newline at end of file diff --git a/Data/Report_DryMixer_Detail.cs b/Data/Report_DryMixer_Detail.cs new file mode 100644 index 0000000..35bb88c --- /dev/null +++ b/Data/Report_DryMixer_Detail.cs @@ -0,0 +1,68 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +public partial class Report_DryMixer_Detail { + + /// + /// 主键标识 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 动作 + /// + + public double? actCode { get; set; } + + /// + /// 设备编号 + /// + + public int? eqNo { get; set; } + + /// + /// 批次 + /// + + public int? mixBatch { get; set; } + + /// + /// 速度 + /// + + public double? mixSpeed { get; set; } + + /// + /// 步号 + /// + + public int? mixStep { get; set; } + + /// + /// 温度 + /// + + public double? mixTemp { get; set; } + + /// + /// 时间 + /// + + public double? mixTime { get; set; } + + /// + /// 记录时间 + /// + + public DateTime? recordTime { get; set; } + + /// + /// 报表标识 + /// + + public string reportId { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/Data/Report_Gel.cs b/Data/Report_Gel.cs new file mode 100644 index 0000000..01b4eec --- /dev/null +++ b/Data/Report_Gel.cs @@ -0,0 +1,38 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +public partial class Report_Gel { + + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 车次 + /// + + public int? Batch { get; set; } + + + public int? gelNo { get; set; } + + + public int? planCode { get; set; } + + + public string planName { get; set; } = string.Empty; + + + public int? recipeCode { get; set; } + + + public string recipeName { get; set; } = string.Empty; + + + public DateTime? recordTime { get; set; } + + + public string reportId { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/Data/Report_GelDoser_Detail.cs b/Data/Report_GelDoser_Detail.cs new file mode 100644 index 0000000..7af93cb --- /dev/null +++ b/Data/Report_GelDoser_Detail.cs @@ -0,0 +1,78 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +/// +/// 干混机报表 +/// + +public partial class Report_GelDoser_Detail { + + /// + /// 主键标识 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 实际公差 + /// + + public double? actToLer { get; set; } + + /// + /// 实际重量 + /// + + public double? actValue { get; set; } + + /// + /// 批次号 + /// + + public int? batch { get; set; } + + /// + /// 设备编号 + /// + + public int? eqNo { get; set; } + + /// + /// 1 糊化机 2 hotWater 3 coolWater + /// + + public int? kinds { get; set; } + + /// + /// 物料代码 + /// + + public int? matCode { get; set; } + + /// + /// 记录时间 + /// + + public DateTime? recordTime { get; set; } + + /// + /// 报表标识 + /// + + public string reportId { get; set; } = string.Empty; + + /// + /// 设定公差 + /// + + public double? setToler { get; set; } + + /// + /// 设定重量 + /// + + public double? setValue { get; set; } + +} \ No newline at end of file diff --git a/Data/Report_GelMixing_Detail.cs b/Data/Report_GelMixing_Detail.cs new file mode 100644 index 0000000..7757466 --- /dev/null +++ b/Data/Report_GelMixing_Detail.cs @@ -0,0 +1,68 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +public partial class Report_GelMixing_Detail { + + /// + /// 主键标识 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 动作 + /// + + public int? actCode { get; set; } + + /// + /// 设备编号 + /// + + public int? eqNo { get; set; } + + /// + /// 批次 + /// + + public int? mixBatch { get; set; } + + /// + /// 速度 + /// + + public double? mixSpeed { get; set; } + + /// + /// 步号 + /// + + public int? mixStep { get; set; } + + /// + /// 温度 + /// + + public double? mixTemp { get; set; } + + /// + /// 时间 + /// + + public int? mixTime { get; set; } + + /// + /// 记录时间 + /// + + public DateTime? recordTime { get; set; } + + /// + /// 报表标识 + /// + + public string reportId { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/Data/Report_WetMixer.cs b/Data/Report_WetMixer.cs new file mode 100644 index 0000000..75f4625 --- /dev/null +++ b/Data/Report_WetMixer.cs @@ -0,0 +1,69 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +/// +/// 干混机报表 +/// + +public partial class Report_WetMixer { + + /// + /// 主键标识 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 车次 + /// + + public int? Batch { get; set; } + + /// + /// 计划代码 + /// + + public int? planCode { get; set; } + + /// + /// 计划名称 + /// + + public string planName { get; set; } = string.Empty; + + /// + /// 配方编码 + /// + + public int? recipeCode { get; set; } + + /// + /// 配方名称 + /// + + public string recipeName { get; set; } = string.Empty; + + /// + /// 记录时间 + /// + + public DateTime? recordTime { get; set; } + + /// + /// 报表标识 + /// + + public string reportId { get; set; } = string.Empty; + + + public DateTime? reportTime { get; set; } + + /// + /// 设备编号 + /// + + public int? WetNo { get; set; } + +} \ No newline at end of file diff --git a/Data/Report_WetMixer_Detail.cs b/Data/Report_WetMixer_Detail.cs new file mode 100644 index 0000000..475dd56 --- /dev/null +++ b/Data/Report_WetMixer_Detail.cs @@ -0,0 +1,77 @@ +using Chloe.Annotations; + +namespace WorkerSynReport.Data; + +public partial class Report_WetMixer_Detail { + + /// + /// 主键标识 + /// + [Column(IsPrimaryKey = true)] + [AutoIncrement] + public int objId { get; set; } + + /// + /// 动作 + /// + + public int? actCode { get; set; } + + + public double? actTolerence { get; set; } + + /// + /// mix编号 + /// + + public double? actWeight { get; set; } + + /// + /// 设备编号 + /// + + public int? eqNo { get; set; } + + /// + /// 批次 + /// + + public int? mixBatch { get; set; } + + /// + /// 速度 + /// + + public double? mixSpeed { get; set; } + + /// + /// 步号 + /// + + public int? mixStep { get; set; } + + /// + /// 温度 + /// + + public double? mixTemp { get; set; } + + /// + /// 时间 + /// + + public int? mixTime { get; set; } + + /// + /// 记录时间 + /// + + public DateTime? recordTime { get; set; } + + /// + /// 报表标识 + /// + + public string reportId { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/DbContextLocal.cs b/DbContextLocal.cs new file mode 100644 index 0000000..5adde01 --- /dev/null +++ b/DbContextLocal.cs @@ -0,0 +1,11 @@ +using Chloe.SqlServer; + +namespace WorkerSynReport; + +public class DbContextLocal : MsSqlContext, IDbContextLocal +{ + public DbContextLocal(string connString) : base(connString) + { + + } +} \ No newline at end of file diff --git a/IDbContextA.cs b/IDbContextA.cs new file mode 100644 index 0000000..63e6806 --- /dev/null +++ b/IDbContextA.cs @@ -0,0 +1,22 @@ +using Chloe; +using Chloe.SqlServer; + +namespace WorkerSynReport; + +public interface IDbContextLocal:IDbContext +{ + +} + +public interface IDbContextHttp : IDbContext +{ + +} + +public class DbContextHttp : MsSqlContext, IDbContextHttp +{ + public DbContextHttp(string connString) : base(connString) + { + + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 5ba50d8..60c5983 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,26 @@ +using NewLife.Extensions.Hosting.AgentService; +using NewLife.Log; using WorkerSynReport; +XTrace.UseConsole(); + IHost host = Host.CreateDefaultBuilder(args) .ConfigureServices(services => { + + services.AddScoped(a => new DbContextLocal("Data Source=127.0.0.1;Initial Catalog=CWSSHG;user=sa;password=123456;")); + + services.AddScoped(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;")); + + services.AddHostedService(); }) + .UseAgentService(options => + { + options.ServiceName = "报表数据"; + options.DisplayName = "Worker服务测试"; + options.Description = "Worker服务的应用"; + }) .Build(); await host.RunAsync(); diff --git a/Worker.cs b/Worker.cs index 9bdf6db..b6654be 100644 --- a/Worker.cs +++ b/Worker.cs @@ -1,21 +1,68 @@ +using System.Collections.Immutable; +using WorkerSynReport.Data; + namespace WorkerSynReport { public class Worker : BackgroundService { private readonly ILogger _logger; - public Worker(ILogger logger) + + + private readonly IServiceScopeFactory _scopeFactory; + + public Worker(ILogger logger, IServiceScopeFactory scopeFactory) { _logger = logger; + this._scopeFactory = scopeFactory; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { + await SynWetMixer(); + + _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); - await Task.Delay(1000, stoppingToken); + await Task.Delay(1000*30, stoppingToken); } } + + private async Task SynWetMixer() + { + + _logger.LogInformation("定时器开始"); + using var scope = _scopeFactory.CreateScope(); + var services = scope.ServiceProvider; + using IDbContextLocal? dbContextLocal = services.GetService(); + using IDbContextHttp? dbContextHttp = services.GetService(); + + var reportId=await dbContextHttp!.Query() + .OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync(); + + + var objId=await dbContextLocal.Query().Where(x => x.reportId == reportId) + .Select(x => x.objId).FirstOrDefaultAsync(); + if (objId>0) + { + List lsMain = new List(); + List lsMainDetail = new List(); + var list= await dbContextLocal.Query().Where(x => x.objId > objId).ToListAsync(); + foreach (var eMixer in list) + { + lsMain.Add(eMixer); + lsMainDetail.AddRange(await dbContextLocal.Query().Where(x => x.reportId==eMixer.reportId).ToListAsync()); + } + + if (lsMain.Any()) + { + _logger.LogInformation("插入数据:{Data}",lsMain.Count); + await dbContextHttp.InsertRangeAsync(lsMain); + await dbContextHttp.InsertRangeAsync(lsMainDetail); + } + } + + } } } diff --git a/WorkerSynReport.csproj b/WorkerSynReport.csproj index a0bfcaf..e3bf833 100644 --- a/WorkerSynReport.csproj +++ b/WorkerSynReport.csproj @@ -8,6 +8,11 @@ + + + + +