多线程

This commit is contained in:
qianhao.xu 2024-08-30 14:55:43 +08:00
parent f6922adcb2
commit c675d60dcd

View File

@ -234,7 +234,7 @@ namespace DOAN.Service.MES.ERP
List<CustDevMesInventory> ERPInventories = Context.AsTenant()
.QueryableWithAttr<CustDevMesInventory>().ToList();
//清空表
@ -258,10 +258,10 @@ namespace DOAN.Service.MES.ERP
material.Id = XueHua;
material.CreatedBy = "ERP";
material.CreatedTime = DateTime.Now;
}
// return Context.AsTenant().InsertableWithAttr(materialLists).ExecuteCommand();
// return Context.AsTenant().InsertableWithAttr(materialLists).ExecuteCommand();
return childDb.Fastest<BaseMaterialList>().PageSize(100000).BulkCopy(materialLists);
}
@ -272,14 +272,15 @@ namespace DOAN.Service.MES.ERP
/// <returns></returns>
public int SynchERPBOM()
{
//ERP中的BOM
List<CustDevMesBom> ERPBoms = Context.AsTenant().QueryableWithAttr<CustDevMesBom>().ToList();
//清空表 耗时17s
var childDb = Context.AsTenant().GetConnectionWithAttr<BaseMaterialBom>();
Task.Run(() =>
{
Context.AsTenant().DeleteableWithAttr<BaseMaterialBom>().ExecuteCommand();
var childDb = Context.AsTenant().GetConnectionWithAttr<BaseMaterialBom>();//线程安全用GetConnectionWithAttrScope
//清空表 耗时17s
childDb.Deleteable<BaseMaterialBom>().ExecuteCommand();
childDb.Ado.ExecuteCommand("ALTER TABLE base_material_bom AUTO_INCREMENT = 1");
// 配置局部映射规则
TypeAdapterConfig<CustDevMesBom, BaseMaterialBom>.NewConfig()
@ -305,7 +306,7 @@ namespace DOAN.Service.MES.ERP
}
// return Context.AsTenant().InsertableWithAttr(baseMaterialBoms).ExecuteCommand();
childDb.Fastest<BaseMaterialBom>().PageSize(100000).BulkCopy(baseMaterialBoms);
childDb.Fastest<BaseMaterialBom>().PageSize(100000).BulkCopy(baseMaterialBoms);
});
return 1;