Files
wcs/WCS.WebApi/Program.cs
hehaibing-1996 f9db16ee55 1.记录日志优化 清空日志间隔调整为10日 减小日志存储内容
2.发送任务限制优化 工位上小车已送走后允许重新发送任务
2025-03-14 08:29:18 +08:00

124 lines
4.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using WCS.BLL.Config;
using WCS.BLL.DbModels;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.BLL.Services.Service;
using WCS.DAL.Db;
using WCS.WebApi;
using WCS.WebApi.Controllers;
namespace WebApi
{
public class Program
{
public static void Main(string[] args)
{
try
{
//初始化websocket
WebSoceketManager.InitWebSocket();
//初始化数据库
DbInit.InitDb();
//初始化配置文件
LocalFile.SaveConfig();
//报警信息重发线程
WarningManager.StartWarningMessageThread();
//赛特公司AGV后台线程
AGVManager.InitBackgroundThread();
////盟讯公司后台线程
//if (LocalFile.Config.IsMx)
//{
// MXBackgroundThread.InitBackgroundThread();
// var str = string.Empty;
// MXBackgroundThread.SendDingDingMsg($"【{LocalFile.Config.GroupName}】后台服务启动成功", new List<string> { "104379" }, ref str);
//}
//清理后台文本日志
Task.Run(async () =>
{
while (true)
{
try
{
//清理三个月以前的日志
WCS.BLL.Logs.Clear(TimeSpan.FromDays(10));
//清理1个月前的接口请求日志
DbHelp.dbLog.Deleteable<SystemApiLogRecord>()
.Where(t => t.ResponseTime < DateTime.Now.AddMonths(-1))
.ExecuteCommand();
//每一天执行一次
await Task.Delay(1000 * 60 * 60 * 24);
}
catch (Exception ex)
{
}
}
});
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IInstoreService, InstoreService>();
builder.Services.AddScoped<IOutstoreService, OutstoreService>();
builder.Services.AddScoped<IHomerService, HomerService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IInterfaceRecordService, InterfaceRecordService>();
builder.Services.AddScoped<IMatBaseInfoService, MatBaseInfoService>();
builder.Services.AddScoped<IMatInventoryDetailService, MatInventoryDetailService>();
builder.Services.AddScoped<IStoreInfoService, StoreInfoService>();
builder.Services.AddScoped<IStockTakingService, StockTakingService>();
builder.Services.AddScoped<ISelfCheckService, SelfCheckService>();
builder.Services.AddScoped<IWarningService, WarningService>();
builder.Services.AddScoped<IInOutRecordService, InOutRecordService>();
builder.Services.AddScoped<IUploadService, UploadService>();
builder.Services.AddScoped<ILocationInfoService, LocationInfoService>();
builder.Services.AddScoped<IMatDetailCurrentInfoService, MatDetailCurrentInfoService>();
builder.Services.AddScoped<IBatchBindMatDetailService, BatchBindMatDetailService>();
builder.Services.AddScoped<IPDAShelfLocationBindUnbindService, PDAShelfLocationBindUnbindService>();
//生成物料码、生成单据码采用单例模式
builder.Services.AddSingleton<IGenerateService, GenerateService>();
builder.Services.AddSingleton<IPDAMatBindService, PDAMatBindService>();
var app = builder.Build();
app.UseMiddleware<RequestResponseLoggingMiddleware>();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
app.Run("http://0.0.0.0:8888");//0.0.0.0表示仅接收ipv4
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}