You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.4 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Extensions
* 59de67c2-e9f9-4aac-b985-ba5c001f9f88
*
* WenJY
* wenjy@mesnac.com
* 2024-04-15 09:53:53
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Extensions
{
public static class SqlsugarSetup
{
/// <summary>
/// 注册SqlSugar
/// </summary>
/// <param name="services"></param>
public static void AddSqlSugarSetup(this IServiceCollection services)
{
services.AddSingleton<ISqlSugarClient>(x =>
{
var appConfig = x.GetService<AppConfig>();
var connectConfigList = new List<ConnectionConfig>();
if (appConfig.sqlConfig != null)
{
foreach (var item in appConfig.sqlConfig)
{
#region 加载sqlite数据库地址
if (item.configId == "local")
{
item.connStr = $"Data Source={System.Environment.CurrentDirectory}//data//data.db";
}
#endregion
var config = new ConnectionConfig()
{
ConfigId = item.configId,
DbType = (DbType)item.dbType,
ConnectionString = item.connStr,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
};
connectConfigList.Add(config);
}
}
SqlSugarScope Db = new SqlSugarScope(connectConfigList, db =>
{
db.Aop.OnLogExecuting = (sql, pars) => { };
});
return Db;
});
//缓存本机配置
services.AddSingleton<List<BaseConfigInfo>>(x =>
{
var service = x.GetService<IBaseConfigInfoService>();
// var info = service.Query(x => x.IsFlag == 1);
var info = service.Query();
return info;
});
//缓存托盘队列
services.AddSingleton<List<RealPalletTask>>(x =>
{
var service = x.GetService<IRealPalletTaskService>();
var info = service.Query();
return info;
});
//缓存条码队列
services.AddSingleton<List<RealBarCodeTask>>(x =>
{
var service = x.GetService<IRealBarCodeTaskService>();
var info = service.Query();
return info;
});
}
}
}