Files
wcs/WCS.BLL/Manager/DbInit.cs
hehaibing-1996 dd25815c03 1.修改物料绑定功能
2.增加数据修改记录表和对应的操作数据的时候增加记录
2025-02-24 15:36:58 +08:00

120 lines
5.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.Config;
using WCS.BLL.DbModels;
using WCS.BLL.HardWare;
using WCS.DAL;
using WCS.DAL.Db;
using WCS.DAL.Db.AuthDb;
using WCS.DAL.DbModels;
namespace WCS.BLL.Manager
{
public static class DbInit
{
public static void InitDb()
{
Logs.Write("【初始化数据库】开始", LogsType.StartBoot);
//初始化数据库对象
if (LocalFile.Config.IsMx)
{
DbHelp.db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = LocalFile.Config.DataDbPath,
DbType = DbType.SqlServer,//[Sqlite]安装[System.Data.SQLite];
IsAutoCloseConnection = true
}, db =>
{
db.Aop.OnError = ex =>
{
};
});
//sqlserver保存接口日志时因为每个字段要限制长度当接口返回内容长度过长会报错
//DbHelp.dbLog = new SqlSugarScope(new ConnectionConfig()
//{
// ConnectionString = LocalFile.Config.LogDbPath,
// DbType = DbType.SqlServer,//[Sqlite]安装[System.Data.SQLite];
// IsAutoCloseConnection = true
//}, db =>
//{
// db.Aop.OnError = ex =>
// {
// };
//});
AuthDbHelp.db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = LocalFile.Config.AuthDbPath,
DbType = DbType.SqlServer,//[Sqlite]安装[System.Data.SQLite];
IsAutoCloseConnection = true
}, db =>
{
db.Aop.OnError = ex =>
{
};
});
Logs.Write("【初始化数据库】MX", LogsType.StartBoot);
}
//手动修改后台配置后再进行CodeFirst 数据库的生成、表的生成
//如果不配置此参数 每次启动都会持续几十秒才能成功启动后端
//if (LocalFile.Config.IsResetDBOrTable)//开发阶段暂时屏蔽初始化限制
{
#region
DbHelp.db.DbMaintenance.CreateDatabase();
//新部署时 日志需要建表 不然没得接口记录
DbHelp.dbLog.DbMaintenance.CreateDatabase();
Logs.Write("【初始化数据库】创建数据库", LogsType.StartBoot);
DbHelp.db.CodeFirst.InitTables(typeof(ShelfInfo), typeof(MatBaseInfo), typeof(ShelfTypeInfo)
, typeof(LocationInfo), typeof(LocationAreaInfo), typeof(MatDetailCurrentInfo), typeof(OrderTypeInfo)
, typeof(MatDetailStocktakingInfo), typeof(AgvTask),typeof(MatDetailHistoryInfo)
, typeof(InventoryDetail), typeof(OutOrder), typeof(OutOrderDetail), typeof(OutOrderMatDetail)
, typeof(MatInfo), typeof(StoreInfo)
, typeof(StockTakingOrder), typeof(StockTakingOrderMatDetail), typeof(InOutRecord)
, typeof(DocumentSerialNumber), typeof(MatInfoLog)
, typeof(AppVersion)
);
Logs.Write("【初始化数据库】db业务数据库建表", LogsType.StartBoot);
DbHelp.dbLog.CodeFirst.InitTables(typeof(SystemApiLogRecord));
Logs.Write("【初始化数据库】dblog日志数据库建表", LogsType.StartBoot);
//初始化单据序列号数据
if (!DbHelp.db.Queryable<DocumentSerialNumber>().Any())
{
var outDocumentSerialNumber = new DocumentSerialNumber()
{
DocumentType = DocumentTypeEnum.,
UpdateDate = DateTime.Now,
CurrentSerialNumber = 0
};
var stockTakingDocumentSerialNumber = new DocumentSerialNumber()
{
DocumentType = DocumentTypeEnum.,
UpdateDate = DateTime.Now,
CurrentSerialNumber = 0
};
DbHelp.db.Insertable(outDocumentSerialNumber).ExecuteCommand();
DbHelp.db.Insertable(stockTakingDocumentSerialNumber).ExecuteCommand();
}
Logs.Write("【初始化数据库】DocumentSerialNumber", LogsType.StartBoot);
//初始化权限数据库
AuthDbHelp.InitDb();
#endregion
LocalFile.Config.IsResetDBOrTable = false;
LocalFile.SaveConfig();
}
Logs.Write("【初始化数据库】结束", LogsType.StartBoot);
}
}
}