湿混机

master
我叫锄头 11 months ago
parent 2a19784b03
commit 1919d1a6ee

@ -0,0 +1,66 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
/// <summary>
/// 干混机报表
/// </summary>
public partial class Report_Dry {
/// <summary>
/// 主键标识
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 车次
/// </summary>
public int? Batch { get; set; }
/// <summary>
/// 是第几台干混机
/// </summary>
public int? dryNo { get; set; }
/// <summary>
/// 计划编码
/// </summary>
public int? planCode { get; set; }
/// <summary>
/// 计划名称
/// </summary>
public string planName { get; set; } = string.Empty;
/// <summary>
/// 设备编号
/// </summary>
public int? recipeCode { get; set; }
/// <summary>
/// 配方名称
/// </summary>
public string recipeName { get; set; } = string.Empty;
/// <summary>
/// 记录时间
/// </summary>
public DateTime? recordTime { get; set; }
/// <summary>
/// 报表标识
/// </summary>
public string reportId { get; set; } = string.Empty;
}

@ -0,0 +1,62 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
public partial class Report_DryDos_Detail {
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 实际公差
/// </summary>
public double? actToler { get; set; }
/// <summary>
/// 实际重量
/// </summary>
public double? actValue { get; set; }
/// <summary>
/// 批次号
/// </summary>
public int? batch { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? eqNo { get; set; }
/// <summary>
/// 物料代码
/// </summary>
public int? matCode { get; set; }
public DateTime? recordTime { get; set; }
public string reportId { get; set; } = string.Empty;
/// <summary>
/// 设定公差
/// </summary>
public double? setToler { get; set; }
/// <summary>
/// 设定重量
/// </summary>
public double? setValue { get; set; }
}

@ -0,0 +1,68 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
public partial class Report_DryMixer_Detail {
/// <summary>
/// 主键标识
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 动作
/// </summary>
public double? actCode { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? eqNo { get; set; }
/// <summary>
/// 批次
/// </summary>
public int? mixBatch { get; set; }
/// <summary>
/// 速度
/// </summary>
public double? mixSpeed { get; set; }
/// <summary>
/// 步号
/// </summary>
public int? mixStep { get; set; }
/// <summary>
/// 温度
/// </summary>
public double? mixTemp { get; set; }
/// <summary>
/// 时间
/// </summary>
public double? mixTime { get; set; }
/// <summary>
/// 记录时间
/// </summary>
public DateTime? recordTime { get; set; }
/// <summary>
/// 报表标识
/// </summary>
public string reportId { get; set; } = string.Empty;
}

@ -0,0 +1,38 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
public partial class Report_Gel {
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 车次
/// </summary>
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;
}

@ -0,0 +1,78 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
/// <summary>
/// 干混机报表
/// </summary>
public partial class Report_GelDoser_Detail {
/// <summary>
/// 主键标识
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 实际公差
/// </summary>
public double? actToLer { get; set; }
/// <summary>
/// 实际重量
/// </summary>
public double? actValue { get; set; }
/// <summary>
/// 批次号
/// </summary>
public int? batch { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? eqNo { get; set; }
/// <summary>
/// 1 糊化机 2 hotWater 3 coolWater
/// </summary>
public int? kinds { get; set; }
/// <summary>
/// 物料代码
/// </summary>
public int? matCode { get; set; }
/// <summary>
/// 记录时间
/// </summary>
public DateTime? recordTime { get; set; }
/// <summary>
/// 报表标识
/// </summary>
public string reportId { get; set; } = string.Empty;
/// <summary>
/// 设定公差
/// </summary>
public double? setToler { get; set; }
/// <summary>
/// 设定重量
/// </summary>
public double? setValue { get; set; }
}

@ -0,0 +1,68 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
public partial class Report_GelMixing_Detail {
/// <summary>
/// 主键标识
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 动作
/// </summary>
public int? actCode { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? eqNo { get; set; }
/// <summary>
/// 批次
/// </summary>
public int? mixBatch { get; set; }
/// <summary>
/// 速度
/// </summary>
public double? mixSpeed { get; set; }
/// <summary>
/// 步号
/// </summary>
public int? mixStep { get; set; }
/// <summary>
/// 温度
/// </summary>
public double? mixTemp { get; set; }
/// <summary>
/// 时间
/// </summary>
public int? mixTime { get; set; }
/// <summary>
/// 记录时间
/// </summary>
public DateTime? recordTime { get; set; }
/// <summary>
/// 报表标识
/// </summary>
public string reportId { get; set; } = string.Empty;
}

@ -0,0 +1,69 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
/// <summary>
/// 干混机报表
/// </summary>
public partial class Report_WetMixer {
/// <summary>
/// 主键标识
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 车次
/// </summary>
public int? Batch { get; set; }
/// <summary>
/// 计划代码
/// </summary>
public int? planCode { get; set; }
/// <summary>
/// 计划名称
/// </summary>
public string planName { get; set; } = string.Empty;
/// <summary>
/// 配方编码
/// </summary>
public int? recipeCode { get; set; }
/// <summary>
/// 配方名称
/// </summary>
public string recipeName { get; set; } = string.Empty;
/// <summary>
/// 记录时间
/// </summary>
public DateTime? recordTime { get; set; }
/// <summary>
/// 报表标识
/// </summary>
public string reportId { get; set; } = string.Empty;
public DateTime? reportTime { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? WetNo { get; set; }
}

@ -0,0 +1,77 @@
using Chloe.Annotations;
namespace WorkerSynReport.Data;
public partial class Report_WetMixer_Detail {
/// <summary>
/// 主键标识
/// </summary>
[Column(IsPrimaryKey = true)]
[AutoIncrement]
public int objId { get; set; }
/// <summary>
/// 动作
/// </summary>
public int? actCode { get; set; }
public double? actTolerence { get; set; }
/// <summary>
/// mix编号
/// </summary>
public double? actWeight { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public int? eqNo { get; set; }
/// <summary>
/// 批次
/// </summary>
public int? mixBatch { get; set; }
/// <summary>
/// 速度
/// </summary>
public double? mixSpeed { get; set; }
/// <summary>
/// 步号
/// </summary>
public int? mixStep { get; set; }
/// <summary>
/// 温度
/// </summary>
public double? mixTemp { get; set; }
/// <summary>
/// 时间
/// </summary>
public int? mixTime { get; set; }
/// <summary>
/// 记录时间
/// </summary>
public DateTime? recordTime { get; set; }
/// <summary>
/// 报表标识
/// </summary>
public string reportId { get; set; } = string.Empty;
}

@ -0,0 +1,11 @@
using Chloe.SqlServer;
namespace WorkerSynReport;
public class DbContextLocal : MsSqlContext, IDbContextLocal
{
public DbContextLocal(string connString) : base(connString)
{
}
}

@ -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)
{
}
}

@ -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<IDbContextLocal>(a => new DbContextLocal("Data Source=127.0.0.1;Initial Catalog=CWSSHG;user=sa;password=123456;"));
services.AddScoped<IDbContextHttp>(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;"));
services.AddHostedService<Worker>();
})
.UseAgentService(options =>
{
options.ServiceName = "报表数据";
options.DisplayName = "Worker服务测试";
options.Description = "Worker服务的应用";
})
.Build();
await host.RunAsync();

@ -1,21 +1,68 @@
using System.Collections.Immutable;
using WorkerSynReport.Data;
namespace WorkerSynReport
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
private readonly IServiceScopeFactory _scopeFactory;
public Worker(ILogger<Worker> 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<IDbContextLocal>();
using IDbContextHttp? dbContextHttp = services.GetService<IDbContextHttp>();
var reportId=await dbContextHttp!.Query<Report_WetMixer>()
.OrderByDesc(x => x.objId).Select(x => x.reportId).FirstOrDefaultAsync();
var objId=await dbContextLocal.Query<Report_WetMixer>().Where(x => x.reportId == reportId)
.Select(x => x.objId).FirstOrDefaultAsync();
if (objId>0)
{
List<Report_WetMixer> lsMain = new List<Report_WetMixer>();
List<Report_WetMixer_Detail> lsMainDetail = new List<Report_WetMixer_Detail>();
var list= await dbContextLocal.Query<Report_WetMixer>().Where(x => x.objId > objId).ToListAsync();
foreach (var eMixer in list)
{
lsMain.Add(eMixer);
lsMainDetail.AddRange(await dbContextLocal.Query<Report_WetMixer_Detail>().Where(x => x.reportId==eMixer.reportId).ToListAsync());
}
if (lsMain.Any())
{
_logger.LogInformation("插入数据:{Data}",lsMain.Count);
await dbContextHttp.InsertRangeAsync(lsMain);
await dbContextHttp.InsertRangeAsync(lsMainDetail);
}
}
}
}
}

@ -8,6 +8,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Chloe" Version="5.18.0" />
<PackageReference Include="Chloe.Extension" Version="5.18.0" />
<PackageReference Include="Chloe.SqlServer" Version="5.18.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="NewLife.Core" Version="10.6.2023.1201" />
<PackageReference Include="NewLife.Extensions.Hosting.AgentService" Version="10.6.2023.1201" />
</ItemGroup>
</Project>

Loading…
Cancel
Save