using Business.Core.Utilities; using Business.EntityFrameworkCore; using Business.Model.Ext; using Business.Model.MES.IC; using Business.Model.SRM; using EFCore.BulkExtensions; using NLog; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace Business.Quartz { //处理Ext数据库表 public class ExtJobService: ApplicationService { SnowFlake help = new SnowFlake(); private IRepository _kd_material; private IRepository _ic_item; private IRepository _srm_purchase; private readonly BusinessDbContext _businessDbContext; private readonly BusinessExtDbContext _businessExtDbContext; public ExtJobService( IRepository kd_material, IRepository ic_item, IRepository srm_purchase, BusinessDbContext businessDbContext, BusinessExtDbContext businessExtDbContext ) { _kd_material= kd_material; _ic_item= ic_item; _srm_purchase = srm_purchase; _businessDbContext = businessDbContext; _businessExtDbContext = businessExtDbContext; } /// /// 处理物料 /// public async void DoExt() { await DoMaterial(); //DoBom(); } /// /// 处理物料 /// public async Task DoMaterial() { var extMaterials=_kd_material.GetListAsync(); var ic_items = _ic_item.GetListAsync(p => p.factory_id == 10101 && p.org_id == 101 && p.tenant_id == 101); var srm_purchases = _srm_purchase.GetListAsync(p => p.factory_id == 10101 && p.org_id == 101 && p.tenant_id == 101); List ic_itemListAdd = new List(); List ic_itemListUpdate = new List(); List srm_purchaseListAdd = new List(); List srm_purchaseListUpdate = new List(); List ext_xrefList = new List(); if (extMaterials != null) { extMaterials.Result.ForEach(ext => { if (ic_items != null && ic_items.Result.Exists(a => a.number == ext.FNumber)) { var ic_item = ic_items.Result.FirstOrDefault(a => a.number == ext.FNumber); if (ic_item != null) { ic_item.number = ext.FNumber; ic_item.name = ext.FName_2052; ic_item.model = ext.FSpecification_2052; ic_item.full_name = ext.FDescription_2052; ic_item.fms_number = ext.FOldNumber; //0.配置类 1. 2.委外加工 3.外购 4.虚拟件 ic_item.erp_cls = ext.FErpClsID == "配置类" ? 0 : ext.FErpClsID == "自制" ? 1 : ext.FErpClsID == "委外" ? 2 : ext.FErpClsID == "外购" ? 3 : ext.FErpClsID == "虚拟" ? 4 : ext.FErpClsID == "费用" ? 5 : ext.FErpClsID == "服务" ? 6 : -1; ic_item.source = ext.FDataSource; ic_item.iskeyitem = ext.FIsKitting == "是" ? 1 : 0; ic_item.gross_weight = ext.FGROSSWEIGHT; ic_item.net_weight = ext.FNETWEIGHT; ic_item.maund = ext.FWEIGHTUNITID_Name; ic_item.cubic_measure = ext.FVOLUMEUNITID_Name; ic_item.length = ext.FLENGTH; ic_item.width = ext.FWIDTH; ic_item.height = ext.FHEIGHT; ic_item.size = ext.FVOLUME; ic_item.allowpur = ext.FIsPurchase == "是" ? 1 : 0; ic_item.allowsale = ext.FIsSale == "是" ? 1 : 0; ic_item.allowmanu = ext.FIsProduce == "是" ? 1 : 0; ic_item.allowout = ext.FIsSubContract == "是" ? 1 : 0; ic_item.allowbatch = ext.F_SFJLPCH == "是" ? 1 : 0; ic_item.product_line = ext.F_CPX_Name; ic_item.minpackqty = ext.FIncreaseQty; ic_item.fix_leadtime = ext.FFixLeadTime; ic_item.plan_trategy = ext.FPlanningStrategy == "MRP" ? 1 : 0; ic_item.order_trategy = ext.FOrderPolicy == "LFL(批对批)" ? 1 : 0; ic_item.order_inter_val = ext.FOrderIntervalTime; ic_item.lead_time = ext.FVarLeadTime; ic_item.bat_change_economy = ext.FVarLeadTimeLotSize; ic_item.order_point = ext.FReOrderGood; ic_item.secinv = ext.FPlanSafeStockQty; ic_itemListUpdate.Add(ic_item); ext_xrefList.Add(new ext_xref { dop_table_name = "ic_item", dop_id = ic_item.Id, dop_col1_name = "number", dop_col1_value = ic_item.number, other_sys_name = "kd", other_table_name = "in_kd_material", other_id = ext.Id, other_col1_name = "FNumber", other_col1_value = ext.FNumber }); var srm_purchase = srm_purchases.Result.FirstOrDefault(a => a.icitem_id == ic_item.Id); if (srm_purchase != null) { srm_purchase.icitem_name = ic_item.name; srm_purchase.purchgroup = ext.FPurchaseGroupId_Name; srm_purchase.purcher = ext.FPurchaserId_Name; srm_purchase.purchase_unit = ext.FPurchaseUnitId_Name; srm_purchaseListUpdate.Add(srm_purchase); } } } else { ic_item item = new ic_item(help.NextId()); item.number = ext.FNumber; item.name = ext.FName_2052; item.model = ext.FSpecification_2052; item.full_name = ext.FDescription_2052; item.fms_number = ext.FOldNumber; //0.配置类 1. 2.委外加工 3.外购 4.虚拟件 item.erp_cls = ext.FErpClsID == "配置类" ? 0 : ext.FErpClsID == "自制" ? 1 : ext.FErpClsID == "委外" ? 2 : ext.FErpClsID == "外购" ? 3 : ext.FErpClsID == "虚拟" ? 4 : ext.FErpClsID == "费用" ? 5 : ext.FErpClsID == "服务" ? 6 : -1; item.source = ext.FDataSource; item.iskeyitem = ext.FIsKitting == "是" ? 1 : 0; item.gross_weight = ext.FGROSSWEIGHT; item.net_weight = ext.FNETWEIGHT; item.maund = ext.FWEIGHTUNITID_Name; item.cubic_measure = ext.FVOLUMEUNITID_Name; item.length = ext.FLENGTH; item.width = ext.FWIDTH; item.height = ext.FHEIGHT; item.size = ext.FVOLUME; item.allowpur = ext.FIsPurchase == "是" ? 1 : 0; item.allowsale = ext.FIsSale == "是" ? 1 : 0; item.allowmanu = ext.FIsProduce == "是" ? 1 : 0; item.allowout = ext.FIsSubContract == "是" ? 1 : 0; item.allowbatch = ext.F_SFJLPCH == "是" ? 1 : 0; item.tenant_id = 101;//TODO item.factory_id = 10101;//TODO item.org_id = 101;//TODO item.IsDeleted = false;//TODO item.is_equipment = 0; item.item_level = 0; item.picktype = 0; item.enable_warning = 0; item.batch_manager = 0; item.product_line = ext.F_CPX_Name; item.production_leadtime = 0; item.stock_leadtime = 0; item.transportation_leadtime = 0; item.order_leadtime = 0; item.minpackqty = ext.FIncreaseQty; item.minorderqty = 0; item.fix_leadtime = ext.FFixLeadTime; item.plan_trategy = ext.FPlanningStrategy == "MRP" ? 1 : 0; item.order_trategy = ext.FOrderPolicy == "LFL(批对批)" ? 1 : 0; item.order_inter_val = ext.FOrderIntervalTime; item.lead_time = ext.FVarLeadTime; item.bat_change_economy = ext.FVarLeadTimeLotSize; item.order_point = ext.FReOrderGood; item.secinv = ext.FPlanSafeStockQty; ic_itemListAdd.Add(item); ext_xrefList.Add(new ext_xref { dop_table_name = "ic_item", dop_id = item.Id, dop_col1_name = "number", dop_col1_value = item.number, other_sys_name = "kd", other_table_name = "in_kd_material", other_id = ext.Id, other_col1_name = "FNumber", other_col1_value = ext.FNumber }); srm_purchaseListAdd.Add(new srm_purchase(help.NextId()) { icitem_id = item.Id, icitem_name = item.name, currency_type = ext.FCurrencyId_Name == "人民币" ? 1 : 0,//TODO tenant_id = 101,//TODO factory_id = 10101,////TODO org_id = 101,//TODO IsDeleted = false,//TODO supplier_id = 0, purchgroup = ext.FPurchaseGroupId_Name, purcher = ext.FPurchaserId_Name, purchase_unit = ext.FPurchaseUnitId_Name }); } }); if (ic_itemListAdd.Count > 0) { //await _ic_item.InsertManyAsync(ic_itemListAdd); _businessDbContext.BulkInsert(ic_itemListAdd); } if (ic_itemListUpdate.Count > 0) { //await _ic_item.UpdateManyAsync(ic_itemListUpdate); _businessDbContext.BulkUpdate(ic_itemListUpdate); } if (srm_purchaseListAdd.Count > 0) { //await _ic_item_pur.InsertManyAsync(ic_item_purListAdd); _businessDbContext.BulkInsert(srm_purchaseListAdd); } if (srm_purchaseListUpdate.Count > 0) { //await _ic_item_pur.UpdateManyAsync(ic_item_purListUpdate); _businessDbContext.BulkUpdate(srm_purchaseListUpdate); } if (ext_xrefList.Count > 0) { //await _ext_xref.UpdateManyAsync(ext_xrefList); _businessExtDbContext.BulkInsert(ext_xrefList); } } } /// /// 处理物料清单 /// public void DoBom() { LogManager.Configuration.Install(new NLog.Config.InstallationContext()); } } }