fix 表更新
This commit is contained in:
@@ -139,12 +139,12 @@ public class SqlSugarPack : BaseAppPack
|
||||
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
// using var scope = app.ApplicationServices.CreateScope();
|
||||
// var db = scope.ServiceProvider.GetService<IDbContext>();
|
||||
//
|
||||
// db.Client.DbMaintenance.CreateDatabase();
|
||||
// db.Client.CodeFirst.InitTables<LocalBalanceRecordEntity, LocalGainfoEntity, LocalGainfoMealEntity, LocalBusinessPlaceEntity>();
|
||||
// db.Client.CodeFirst.InitTables<LocalBusinessShiftEntity, LocalDeviceRegistryEntity, LocalDeviceEntity, LocalBusinessPlaceShiftRelationshipEntity, LocalBusinessShiftMealRelationshipEntity>();
|
||||
// db.Client.CodeFirst.InitTables<LocalCanteenSettingEntity, LocalDepartmentEntity>();
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var db = scope.ServiceProvider.GetService<IDbContext>();
|
||||
|
||||
db.Client.DbMaintenance.CreateDatabase();
|
||||
db.Client.CodeFirst.InitTables<LocalBalanceRecordEntity, LocalGainfoEntity, LocalGainfoMealEntity, LocalBusinessPlaceEntity>();
|
||||
db.Client.CodeFirst.InitTables<LocalBusinessShiftEntity, LocalDeviceRegistryEntity, LocalDeviceEntity, LocalBusinessPlaceShiftRelationshipEntity, LocalBusinessShiftMealRelationshipEntity>();
|
||||
db.Client.CodeFirst.InitTables<LocalCanteenSettingEntity, LocalDepartmentEntity>();
|
||||
}
|
||||
}
|
||||
@@ -39,48 +39,58 @@ public class DataDownloadService : IDataDownloadService
|
||||
|
||||
var factories = factory.Split(',');
|
||||
|
||||
await TruncateAsync();
|
||||
|
||||
foreach (var item in factories)
|
||||
await _dbContext.Client.Ado.BeginTranAsync();
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("正在下载{factory}", item);
|
||||
if (!await _dbContext.Queryable<LocalDepartmentEntity>().AnyAsync())
|
||||
await TruncateAsync();
|
||||
|
||||
foreach (var item in factories)
|
||||
{
|
||||
await DownloadAsync<LocalDepartmentEntity>(item);
|
||||
}
|
||||
|
||||
await DownloadAsync<LocalDeviceEntity>(item);
|
||||
await DownloadAsync<LocalDeviceRegistryEntity>(item);
|
||||
|
||||
await DownloadAsync<LocalBusinessPlaceEntity>(item);
|
||||
await DownloadAsync<LocalBusinessShiftEntity>(item);
|
||||
await DownloadAsync<LocalBusinessPlaceShiftRelationshipEntity>(item);
|
||||
await DownloadAsync<LocalBusinessShiftMealRelationshipEntity>(item);
|
||||
|
||||
if (!await _dbContext.Queryable<LocalGainfoEntity>().Where(x => x.Factory == item).AnyAsync())
|
||||
{
|
||||
await DownloadAsync<LocalGainfoEntity>(item);
|
||||
}
|
||||
|
||||
if (!await _dbContext.Queryable<LocalGainfoMealEntity>().AnyAsync())
|
||||
{
|
||||
foreach (var currentItem in factories)
|
||||
_logger.LogInformation("正在下载{factory}", item);
|
||||
if (!await _dbContext.Queryable<LocalDepartmentEntity>().AnyAsync())
|
||||
{
|
||||
await DownloadAsync<LocalGainfoMealEntity>(currentItem);
|
||||
await DownloadAsync<LocalDepartmentEntity>(item);
|
||||
}
|
||||
|
||||
await DownloadAsync<LocalDeviceEntity>(item);
|
||||
await DownloadAsync<LocalDeviceRegistryEntity>(item);
|
||||
|
||||
await DownloadAsync<LocalBusinessPlaceEntity>(item);
|
||||
await DownloadAsync<LocalBusinessShiftEntity>(item);
|
||||
await DownloadAsync<LocalBusinessPlaceShiftRelationshipEntity>(item);
|
||||
await DownloadAsync<LocalBusinessShiftMealRelationshipEntity>(item);
|
||||
|
||||
if (!await _dbContext.Queryable<LocalGainfoEntity>().Where(x => x.Factory == item).AnyAsync())
|
||||
{
|
||||
await DownloadAsync<LocalGainfoEntity>(item);
|
||||
}
|
||||
|
||||
if (!await _dbContext.Queryable<LocalGainfoMealEntity>().AnyAsync())
|
||||
{
|
||||
foreach (var currentItem in factories)
|
||||
{
|
||||
await DownloadAsync<LocalGainfoMealEntity>(currentItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("部门{count}", await _dbContext.Queryable<LocalDepartmentEntity>().CountAsync());
|
||||
_logger.LogInformation("设备{count}", await _dbContext.Queryable<LocalDeviceEntity>().CountAsync());
|
||||
_logger.LogInformation("设备注册信息{count}", await _dbContext.Queryable<LocalDeviceRegistryEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点{count}", await _dbContext.Queryable<LocalBusinessPlaceEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点餐别{count}", await _dbContext.Queryable<LocalBusinessShiftEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点餐别对照{count}", await _dbContext.Queryable<LocalBusinessPlaceShiftRelationshipEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点餐别餐次对照{count}", await _dbContext.Queryable<LocalBusinessShiftMealRelationshipEntity>().CountAsync());
|
||||
_logger.LogInformation("档案{count}", await _dbContext.Queryable<LocalGainfoEntity>().CountAsync());
|
||||
_logger.LogInformation("余额{count}", await _dbContext.Queryable<LocalGainfoMealEntity>().CountAsync());
|
||||
_logger.LogInformation("下载完成");
|
||||
_logger.LogInformation("部门{count}", await _dbContext.Queryable<LocalDepartmentEntity>().CountAsync());
|
||||
_logger.LogInformation("设备{count}", await _dbContext.Queryable<LocalDeviceEntity>().CountAsync());
|
||||
_logger.LogInformation("设备注册信息{count}", await _dbContext.Queryable<LocalDeviceRegistryEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点{count}", await _dbContext.Queryable<LocalBusinessPlaceEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点餐别{count}", await _dbContext.Queryable<LocalBusinessShiftEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点餐别对照{count}", await _dbContext.Queryable<LocalBusinessPlaceShiftRelationshipEntity>().CountAsync());
|
||||
_logger.LogInformation("营业点餐别餐次对照{count}", await _dbContext.Queryable<LocalBusinessShiftMealRelationshipEntity>().CountAsync());
|
||||
_logger.LogInformation("档案{count}", await _dbContext.Queryable<LocalGainfoEntity>().CountAsync());
|
||||
_logger.LogInformation("余额{count}", await _dbContext.Queryable<LocalGainfoMealEntity>().CountAsync());
|
||||
_logger.LogInformation("下载完成");
|
||||
await _dbContext.Client.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _dbContext.Client.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DownloadAsync<T>(string factory) where T : class, new()
|
||||
|
||||
Reference in New Issue
Block a user