|
|
@@ -4,9 +4,12 @@ using Business.EntityFrameworkCore;
|
|
|
using Business.EntityFrameworkCore.SqlRepositories;
|
|
|
using Business.ResourceExamineManagement;
|
|
|
using Business.SystemJob;
|
|
|
+using EFCore.BulkExtensions;
|
|
|
+using MongoDB.Driver.Linq;
|
|
|
using NLog;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using Volo.Abp.Application.Services;
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
@@ -290,95 +293,97 @@ namespace Business.SystemJobManagement
|
|
|
return "任务执行成功";
|
|
|
}
|
|
|
|
|
|
- ////同步客户
|
|
|
- //public void SyncCustMaster()
|
|
|
- //{
|
|
|
- // var customerList = _mysql_crm_customer.GetListAsync().Result;
|
|
|
- // List<CustMaster> custList = _custMaster.Select(a => a.Domain == "1001" && a.IsActive);
|
|
|
- // var addressList = _consigneeAddressMaster.Select(a => a.Domain == "1001" && a.Typed == "Cust" && a.IsActive);
|
|
|
- // List<crm_customer> ItemsAdd = new List<crm_customer>();
|
|
|
- // if (custList != null && custList.Count > 0)
|
|
|
- // {
|
|
|
- // for (int i = 0; i < custList.Count; i++)
|
|
|
- // {
|
|
|
- // long domain = Convert.ToInt64(custList[i].Domain);
|
|
|
- // long factory_id = domain % 1000;
|
|
|
- // long tenant_id = domain - factory_id;
|
|
|
- // var cust = customerList.Find(x => x.customer_no == custList[i].Cust && x.tenant_id == 1000 && x.factory_id == 1001);
|
|
|
- // if (cust is null)
|
|
|
- // {
|
|
|
- // ConsigneeAddressMaster address = addressList.Find(a => a.Address == custList[i].Cust);
|
|
|
- // var customer = new crm_customer
|
|
|
- // {
|
|
|
- // customer_no = custList[i].Cust,
|
|
|
- // customer_name = address is null ? address.Name : "",
|
|
|
- // telephone = address is null ? address.Telephone : "",
|
|
|
- // email = address is null ? address.AttentionEmail : "",
|
|
|
- // contact = address is null ? address.Attention1 : "",
|
|
|
- // post_code = address is null ? address.Post : "",
|
|
|
- // country = address is null ? address.Country : "",
|
|
|
- // province = address is null ? address.State : "",
|
|
|
- // city = address is null ? address.City : "",
|
|
|
- // region = address is null ? address.State : "",
|
|
|
- // address = address is null ? address.Address1 : "",
|
|
|
- // short_name = custList[i].SortName,
|
|
|
- // carrying_aos = Convert.ToInt32(custList[i].CustShippingLT),
|
|
|
- // currency = custList[i].Curr,
|
|
|
- // employee_name = custList[i].Salesperson1,
|
|
|
- // factory_id = 1001,
|
|
|
- // tenant_id = 1000
|
|
|
- // };
|
|
|
- // customer.GenerateNewId(help.NextId());
|
|
|
- // ItemsAdd.Add(customer);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _businessDbContext.BulkInsert(ItemsAdd);
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- ////同步供应商
|
|
|
- //public void SyncSuppMaster()
|
|
|
- //{
|
|
|
- // var suppList = _mysql_srm_supplier.GetListAsync().Result;
|
|
|
- // List<SuppMaster> custList = _suppMaster.Select(a => a.Domain == "1001" && a.IsActive);
|
|
|
- // var addressList = _consigneeAddressMaster.Select(a => a.Domain == "1001" && a.Typed == "Supp" && a.IsActive);
|
|
|
- // List<srm_supplier> ItemsAdd = new List<srm_supplier>();
|
|
|
- // if (custList != null && custList.Count > 0)
|
|
|
- // {
|
|
|
- // for (int i = 0; i < custList.Count; i++)
|
|
|
- // {
|
|
|
- // long domain = Convert.ToInt64(custList[i].Domain.ToString());
|
|
|
- // long factory_id = domain % 1000;
|
|
|
- // long tenant_id = domain - factory_id;
|
|
|
- // var supp = suppList.Find(x => x.supplier_no == custList[i].Supp.ToString() && x.tenant_id == factory_id && x.factory_id == tenant_id);
|
|
|
- // if (supp is null)
|
|
|
- // {
|
|
|
- // ConsigneeAddressMaster address = addressList.Find(a => a.Address == custList[i].Supp);
|
|
|
- // var supplier = new srm_supplier
|
|
|
- // {
|
|
|
- // supplier_no = custList[i].Supp,
|
|
|
- // supplier_name = address is null ? address.Name : "",
|
|
|
- // supplier_short_name = custList[i].SortName,
|
|
|
- // country = address is null ? address.Country : "",
|
|
|
- // state = address is null ? address.State : "",
|
|
|
- // region = address is null ? address.City : "",
|
|
|
- // contact = address is null ? address.Attention1 : "",
|
|
|
- // telephone = address is null ? address.Telephone : "",
|
|
|
- // post_code = address is null ? address.Post : "",
|
|
|
- // email = address is null ? address.AttentionEmail : "",
|
|
|
- // currency = custList[i].Curr,
|
|
|
- // supply_type = custList[i].Type,
|
|
|
- // settlement = custList[i].CrTerms,
|
|
|
- // factory_id = factory_id,
|
|
|
- // tenant_id = tenant_id
|
|
|
- // };
|
|
|
- // supplier.GenerateNewId(help.NextId());
|
|
|
- // ItemsAdd.Add(supplier);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _businessDbContext.BulkInsert(ItemsAdd);
|
|
|
- // }
|
|
|
- //}
|
|
|
+ //同步客户
|
|
|
+ public void SyncCustMaster()
|
|
|
+ {
|
|
|
+ var customerList = _mysql_crm_customer.GetListAsync().Result;
|
|
|
+ List<CustMaster> custList = _custMaster.Select(a => a.IsActive);
|
|
|
+ var addressList = _consigneeAddressMaster.Select(a => a.Typed == "Cust" && a.IsActive);
|
|
|
+ List<crm_customer> ItemsAdd = new List<crm_customer>();
|
|
|
+ if (custList != null && custList.Count > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < custList.Count; i++)
|
|
|
+ {
|
|
|
+ long domain = Convert.ToInt64(custList[i].Domain);
|
|
|
+ long factory_id = domain;
|
|
|
+ long tenant_id = 1000;
|
|
|
+ var cust = customerList.Find(x => x.customer_no == custList[i].Cust);
|
|
|
+ if (cust is null)
|
|
|
+ {
|
|
|
+ ConsigneeAddressMaster address = addressList.Find(a => a.Address == custList[i].Cust);
|
|
|
+ var customer = new crm_customer
|
|
|
+ {
|
|
|
+ customer_no = custList[i].Cust,
|
|
|
+ customer_name = address is null ? address.Name : "",
|
|
|
+ telephone = address is null ? address.Telephone : "",
|
|
|
+ email = address is null ? address.AttentionEmail : "",
|
|
|
+ contact = address is null ? address.Attention1 : "",
|
|
|
+ post_code = address is null ? address.Post : "",
|
|
|
+ country = address is null ? address.Country : "",
|
|
|
+ province = address is null ? address.State : "",
|
|
|
+ city = address is null ? address.City : "",
|
|
|
+ region = address is null ? address.State : "",
|
|
|
+ address = address is null ? address.Address1 : "",
|
|
|
+ short_name = custList[i].SortName,
|
|
|
+ carrying_aos = Convert.ToInt32(custList[i].CustShippingLT),
|
|
|
+ currency = custList[i].Curr,
|
|
|
+ employee_name = custList[i].Salesperson1,
|
|
|
+ factory_id = factory_id,
|
|
|
+ tenant_id=tenant_id,
|
|
|
+ company_id = tenant_id
|
|
|
+ };
|
|
|
+ customer.GenerateNewId(help.NextId());
|
|
|
+ ItemsAdd.Add(customer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _businessDbContext.BulkInsert(ItemsAdd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //同步供应商
|
|
|
+ public void SyncSuppMaster()
|
|
|
+ {
|
|
|
+ var suppList = _mysql_srm_supplier.GetListAsync().Result;
|
|
|
+ List<SuppMaster> custList = _suppMaster.Select(a => a.IsActive);
|
|
|
+ var addressList = _consigneeAddressMaster.Select(a => a.Typed == "Supp" && a.IsActive);
|
|
|
+ List<srm_supplier> ItemsAdd = new List<srm_supplier>();
|
|
|
+ if (custList != null && custList.Count > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < custList.Count; i++)
|
|
|
+ {
|
|
|
+ long domain = Convert.ToInt64(custList[i].Domain.ToString());
|
|
|
+ long factory_id = domain;
|
|
|
+ long tenant_id = 1000;
|
|
|
+ var supp = suppList.Find(x => x.supplier_no == custList[i].Supp.ToString() && x.company_id == tenant_id && x.factory_id == factory_id);
|
|
|
+ if (supp is null)
|
|
|
+ {
|
|
|
+ ConsigneeAddressMaster address = addressList.Find(a => a.Address == custList[i].Supp);
|
|
|
+ var supplier = new srm_supplier
|
|
|
+ {
|
|
|
+ supplier_no = custList[i].Supp,
|
|
|
+ supplier_name = address is not null ? address.Name : "",
|
|
|
+ supplier_short_name = custList[i].SortName,
|
|
|
+ country = address is not null ? address.Country : "",
|
|
|
+ state = address is not null ? address.State : "",
|
|
|
+ region = address is not null ? address.City : "",
|
|
|
+ contact = address is not null ? address.Attention1 : "",
|
|
|
+ telephone = address is not null ? address.Telephone : "",
|
|
|
+ post_code = address is not null ? address.Post : "",
|
|
|
+ email = address is not null ? address.AttentionEmail : "",
|
|
|
+ currency = custList[i].Curr,
|
|
|
+ supply_type = custList[i].Type,
|
|
|
+ settlement = custList[i].CrTerms,
|
|
|
+ factory_id = factory_id,
|
|
|
+ tenant_id = tenant_id,
|
|
|
+ company_id = tenant_id
|
|
|
+ };
|
|
|
+ supplier.GenerateNewId(help.NextId());
|
|
|
+ ItemsAdd.Add(supplier);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _businessDbContext.BulkInsert(ItemsAdd);
|
|
|
+ }
|
|
|
+ }
|
|
|
//////同步销售订单
|
|
|
////public void SyncSalesOrdMaster()
|
|
|
////{
|
|
|
@@ -590,21 +595,21 @@ namespace Business.SystemJobManagement
|
|
|
//// }
|
|
|
////}
|
|
|
|
|
|
- /*//同步物料
|
|
|
+ //同步物料
|
|
|
public void SyncItemMaster()
|
|
|
{
|
|
|
bool isAll = true;//是否同步所有物料
|
|
|
- var ic_itemList = _mysql_ic_item.GetListAsync(a => a.tenant_id == 1000 && a.factory_id == 1001).Result;
|
|
|
+ var ic_itemList = _mysql_ic_item.GetListAsync().Result;
|
|
|
List<ItemMaster> custList = new List<ItemMaster>();
|
|
|
if (isAll)
|
|
|
{
|
|
|
- custList = _itemMaster.Select(a => a.IsActive && a.Domain == "1001");
|
|
|
+ custList = _itemMaster.Select(a => a.IsActive);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//格努产品编码同步子级物料
|
|
|
List<string> childItems = GetChildItemNumber("", new List<string>());
|
|
|
- custList = _itemMaster.Select(a => a.IsActive && a.Domain == "1001" && childItems.Distinct().Contains(a.ItemNum));
|
|
|
+ custList = _itemMaster.Select(a => a.IsActive && childItems.Distinct().Contains(a.ItemNum));
|
|
|
}
|
|
|
List<ic_item> ItemsAdd = new List<ic_item>();
|
|
|
List<srm_purchase> srm_purchaseAdd = new List<srm_purchase>();
|
|
|
@@ -612,7 +617,7 @@ namespace Business.SystemJobManagement
|
|
|
{
|
|
|
for (int i = 0; i < custList.Count; i++)
|
|
|
{
|
|
|
- var ic_item = ic_itemList.Find(x => x.number == custList[i].ItemNum && x.tenant_id == 1000 && x.factory_id == 1001);
|
|
|
+ var ic_item = ic_itemList.Find(x => x.number == custList[i].ItemNum);
|
|
|
if (ic_item == null)
|
|
|
{
|
|
|
long itemId = help.NextId();
|
|
|
@@ -624,9 +629,9 @@ namespace Business.SystemJobManagement
|
|
|
fversion = "",//版本号
|
|
|
//ext.FErpClsID == "配置类" ? 0 : ext.FErpClsID == "自制" ? 1 : ext.FErpClsID == "委外" ? 2 : ext.FErpClsID == "外购" ? 3 : ext.FErpClsID == "虚拟" ? 4 : ext.FErpClsID == "费用" ? 5 : ext.FErpClsID == "服务" ? 6 : -1;
|
|
|
//erp_cls = custList[i].PurMfg == "P" ? 3 : 1,//物料属性
|
|
|
- erp_cls = custList[i].ItemNum == "1.SD1.D.0056-F" || custList[i].ItemNum == "1.ZC1.D.0001" || custList[i].ItemNum == "1.BW1.D.0030" ? 1 : 3,
|
|
|
+ erp_cls = custList[i].PurMfg == "P" ? 3 : 1,//物料属性
|
|
|
//erp_cls_name = custList[i].PurMfg == "P" ? "外购" : "自制",//物料属性名称
|
|
|
- erp_cls_name = custList[i].ItemNum == "1.SD1.D.0056-F" || custList[i].ItemNum == "1.ZC1.D.0001" || custList[i].ItemNum == "1.BW1.D.0030" ? "自制" : "外购",
|
|
|
+ erp_cls_name = custList[i].PurMfg == "P" ? "外购" : "自制",//物料属性名称
|
|
|
unit = custList[i].UM,//单位
|
|
|
item_level = 0,//物料等级
|
|
|
source = "",//来源
|
|
|
@@ -644,11 +649,12 @@ namespace Business.SystemJobManagement
|
|
|
allowserial = custList[i].LotSerialControl ? 1 : 0,//序列号管理
|
|
|
photo = "",//图片
|
|
|
enable_warning = 1,//启用预警
|
|
|
- factory_id = 1001,
|
|
|
- tenant_id = 1000,
|
|
|
+ factory_id =long.Parse(custList[i].Domain),
|
|
|
+ company_id = 1000,
|
|
|
+ tenant_id=1000,
|
|
|
IsDeleted = false,
|
|
|
clean_leadtime = custList[i].MFGMTTR,
|
|
|
- is_clean= custList[i].IssuePolicy ? 1 : 0,
|
|
|
+ is_clean = custList[i].IssuePolicy ? 1 : 0,
|
|
|
batch_manager = custList[i].LotSerialControl ? 1 : 0,
|
|
|
minorderqty = custList[i].MinOrd,
|
|
|
minpackqty = 1,
|
|
|
@@ -670,7 +676,7 @@ namespace Business.SystemJobManagement
|
|
|
Warehousing_date = 1,
|
|
|
Shipping_date = 3,
|
|
|
});
|
|
|
- srm_purchaseAdd.Add(new srm_purchase(help.NextId())
|
|
|
+ /*srm_purchaseAdd.Add(new srm_purchase(help.NextId())
|
|
|
{
|
|
|
icitem_id = itemId,
|
|
|
icitem_name = custList[i].Descr,
|
|
|
@@ -695,135 +701,140 @@ namespace Business.SystemJobManagement
|
|
|
factory_id = 1001,
|
|
|
tenant_id = 1000,
|
|
|
IsDeleted = false
|
|
|
- });
|
|
|
+ });*/
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
_businessDbContext.BulkInsert(ItemsAdd);
|
|
|
- _businessDbContext.BulkInsert(srm_purchaseAdd);
|
|
|
- }*/
|
|
|
-
|
|
|
- //public void SyncBom()
|
|
|
- //{
|
|
|
- // var ic_bomList = _mysql_ic_bom.GetListAsync(a => a.tenant_id == 1000 && a.factory_id == 1001).Result;
|
|
|
- // var ic_itemList = _mysql_ic_item.GetListAsync(a => a.tenant_id == 1000 && a.factory_id == 1001).Result;
|
|
|
- // var ic_bomchildList = _mysql_ic_bom_child.GetListAsync(a => a.tenant_id == 1000 && a.factory_id == 1001 && (a.bom_number == "1.SD1.D.0056-F" || a.bom_number == "1.ZC1.D.0001" || a.bom_number == "1.BW1.D.0030")).Result;
|
|
|
- // List<ProductStructureMaster> wmsBomList = _productStructureMaster.Select(a => a.Domain == "1001" && (a.ParentItem == "1.SD1.D.0056-F" || a.ParentItem == "1.ZC1.D.0001" || a.ParentItem == "1.BW1.D.0030") && a.IsActive);
|
|
|
- // List<ic_bom> ItemsAdd = new List<ic_bom>();
|
|
|
- // List<ic_bom_child> childItemsAdd = new List<ic_bom_child>();
|
|
|
- // if (wmsBomList != null && wmsBomList.Count > 0)
|
|
|
- // {
|
|
|
- // var ItemMasterDS = wmsBomList.Select(a => a.ParentItem).Distinct().ToList();
|
|
|
- // foreach (var c in ItemMasterDS)
|
|
|
- // {
|
|
|
- // var icbom = ic_bomList.Find(x => x.item_number == c && x.tenant_id == 1000 && x.factory_id == 1001);
|
|
|
- // var ItemList = wmsBomList.Where(a => a.ParentItem == c);
|
|
|
- // var item = ic_itemList.Find(a => a.number == c);
|
|
|
- // if (item == null)
|
|
|
- // {
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // if (icbom == null)
|
|
|
- // {
|
|
|
- // long domain = Convert.ToInt64(ItemList.First().Domain);
|
|
|
- // long factory_id = domain % 1000;
|
|
|
- // long tenant_id = domain - factory_id;
|
|
|
- // var bom = new ic_bom(help.NextId())
|
|
|
- // {
|
|
|
- // bom_number = c,
|
|
|
- // icitem_id = item.Id,
|
|
|
- // item_name = item.name,
|
|
|
- // item_number = c,
|
|
|
- // version = ItemList.First().Refs,
|
|
|
- // factory_id = 1001,
|
|
|
- // tenant_id = 1000,
|
|
|
- // IsDeleted = false,
|
|
|
- // use_status = 1
|
|
|
- // };
|
|
|
- // ItemsAdd.Add(bom);
|
|
|
- // foreach (var child in ItemList)
|
|
|
- // {
|
|
|
- // var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
|
|
|
- // if (itemchild == null) { continue; }
|
|
|
- // var bomchild = new ic_bom_child(help.NextId())
|
|
|
- // {
|
|
|
- // bom_id = bom.Id,
|
|
|
- // bom_number = bom.bom_number,
|
|
|
- // icitem_id = itemchild == null ? long.MinValue : itemchild.Id,
|
|
|
- // item_number = child.ComponentItem,
|
|
|
- // item_name = itemchild == null ? "" : itemchild.name,
|
|
|
- // unit = child.UM,
|
|
|
- // qty = child.Qty,
|
|
|
- // entryid = child.SequenceNum,
|
|
|
- // erp_cls = itemchild == null ? 2 : itemchild.erp_cls,
|
|
|
- // begin_day = child.StartEff,
|
|
|
- // end_day = child.EndEff,
|
|
|
- // child_num = child.SequenceNum,
|
|
|
- // version = child.Refs,
|
|
|
- // factory_id = 1001,
|
|
|
- // tenant_id = 1000,
|
|
|
- // IsDeleted = false,
|
|
|
- // use_status = 1
|
|
|
- // };
|
|
|
- // childItemsAdd.Add(bomchild);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // foreach (var child in ItemList)
|
|
|
- // {
|
|
|
- // var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
|
|
|
- // if (itemchild == null) { continue; }
|
|
|
- // var icbomchild = ic_bomchildList.Find(s => s.bom_number == c && s.item_number == child.ComponentItem);
|
|
|
- // if (icbomchild == null)
|
|
|
- // {
|
|
|
- // var bomchild = new ic_bom_child(help.NextId())
|
|
|
- // {
|
|
|
- // bom_id = icbom.Id,
|
|
|
- // bom_number = icbom.bom_number,
|
|
|
- // icitem_id = itemchild == null ? long.MinValue : itemchild.Id,
|
|
|
- // item_number = child.ComponentItem,
|
|
|
- // item_name = itemchild == null ? "" : itemchild.name,
|
|
|
- // unit = child.UM,
|
|
|
- // qty = child.Qty,
|
|
|
- // entryid = child.SequenceNum,
|
|
|
- // erp_cls = itemchild == null ? 2 : itemchild.erp_cls,
|
|
|
- // begin_day = child.StartEff,
|
|
|
- // end_day = child.EndEff,
|
|
|
- // child_num = child.SequenceNum,
|
|
|
- // version = child.Refs,
|
|
|
- // factory_id = 1001,
|
|
|
- // tenant_id = 1000,
|
|
|
- // IsDeleted = false,
|
|
|
- // use_status = 1
|
|
|
- // };
|
|
|
- // childItemsAdd.Add(bomchild);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
- // }
|
|
|
- // _businessDbContext.BulkInsert(ItemsAdd);
|
|
|
- // _businessDbContext.BulkInsert(childItemsAdd);
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- ////循环获取子级物料编码,包括产品本身,有重复的结果去重即可
|
|
|
- //public List<string> GetChildItemNumber(string itemNum, List<string> list)
|
|
|
- //{
|
|
|
- // list.Add(itemNum);
|
|
|
- // var productStructures = _productStructureMaster.Select(p => p.ParentItem == itemNum && p.Domain == "1001" && p.IsActive);
|
|
|
- // list.AddRange(productStructures.Select(a => a.ComponentItem));
|
|
|
- // foreach (var item in productStructures)
|
|
|
- // {
|
|
|
- // if (item.StructureType.ToUpper() == "X")
|
|
|
- // {
|
|
|
- // GetChildItemNumber(item.ComponentItem, list);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return list;
|
|
|
- //}
|
|
|
+ //_businessDbContext.BulkInsert(srm_purchaseAdd);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SyncBom()
|
|
|
+ {
|
|
|
+ var ic_bomList = _mysql_ic_bom.GetListAsync().Result;
|
|
|
+ var ic_itemList = _mysql_ic_item.GetListAsync().Result;
|
|
|
+ var ic_bomchildList = _mysql_ic_bom_child.GetListAsync().Result;
|
|
|
+ List<ProductStructureMaster> wmsBomList = _productStructureMaster.Select(a => a.IsActive);
|
|
|
+ List<ic_bom> ItemsAdd = new List<ic_bom>();
|
|
|
+ List<ic_bom_child> childItemsAdd = new List<ic_bom_child>();
|
|
|
+ if (wmsBomList != null && wmsBomList.Count > 0)
|
|
|
+ {
|
|
|
+ var ItemMasterDS = wmsBomList.Select(a => a.ParentItem).Distinct().ToList();
|
|
|
+ foreach (var c in ItemMasterDS)
|
|
|
+ {
|
|
|
+ var icbom = ic_bomList.Find(x => x.item_number == c);
|
|
|
+ var ItemList = wmsBomList.Where(a => a.ParentItem == c);
|
|
|
+ var item = ic_itemList.Find(a => a.number == c);
|
|
|
+ if (item == null)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (icbom == null)
|
|
|
+ {
|
|
|
+ long domain = Convert.ToInt64(ItemList.First().Domain);
|
|
|
+ long factory_id = domain % 1000;
|
|
|
+ long tenant_id = domain - factory_id;
|
|
|
+ var bom = new ic_bom(help.NextId())
|
|
|
+ {
|
|
|
+ bom_number = c,
|
|
|
+ icitem_id = item.Id,
|
|
|
+ item_name = item.name,
|
|
|
+ item_number = c,
|
|
|
+ version = ItemList.First().Refs,
|
|
|
+ factory_id = item.factory_id,
|
|
|
+ company_id = item.company_id,
|
|
|
+ tenant_id = item.company_id,
|
|
|
+ IsDeleted = false,
|
|
|
+ use_status = 1
|
|
|
+ };
|
|
|
+ ItemsAdd.Add(bom);
|
|
|
+ foreach (var child in ItemList)
|
|
|
+ {
|
|
|
+ var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
|
|
|
+ if (itemchild == null) { continue; }
|
|
|
+ var bomchild = new ic_bom_child(help.NextId())
|
|
|
+ {
|
|
|
+ bom_id = bom.Id,
|
|
|
+ bom_number = bom.bom_number,
|
|
|
+ icitem_id = itemchild == null ? long.MinValue : itemchild.Id,
|
|
|
+ item_number = child.ComponentItem,
|
|
|
+ item_name = itemchild == null ? "" : itemchild.name,
|
|
|
+ unit = child.UM,
|
|
|
+ qty = child.Qty,
|
|
|
+ entryid = child.SequenceNum,
|
|
|
+ erp_cls = itemchild == null ? 2 : itemchild.erp_cls,
|
|
|
+ begin_day = child.StartEff,
|
|
|
+ end_day = child.EndEff,
|
|
|
+ child_num = child.SequenceNum,
|
|
|
+ version = child.Refs,
|
|
|
+ factory_id = item.factory_id,
|
|
|
+ company_id = item.company_id,
|
|
|
+ tenant_id = item.company_id,
|
|
|
+ IsDeleted = false,
|
|
|
+ Op = child.Op,
|
|
|
+ use_status = 1
|
|
|
+ };
|
|
|
+ childItemsAdd.Add(bomchild);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var child in ItemList)
|
|
|
+ {
|
|
|
+ var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
|
|
|
+ if (itemchild == null) { continue; }
|
|
|
+ var icbomchild = ic_bomchildList.Find(s => s.bom_number == c && s.item_number == child.ComponentItem);
|
|
|
+ if (icbomchild == null)
|
|
|
+ {
|
|
|
+ var bomchild = new ic_bom_child(help.NextId())
|
|
|
+ {
|
|
|
+ bom_id = icbom.Id,
|
|
|
+ bom_number = icbom.bom_number,
|
|
|
+ icitem_id = itemchild == null ? long.MinValue : itemchild.Id,
|
|
|
+ item_number = child.ComponentItem,
|
|
|
+ item_name = itemchild == null ? "" : itemchild.name,
|
|
|
+ unit = child.UM,
|
|
|
+ qty = child.Qty,
|
|
|
+ entryid = child.SequenceNum,
|
|
|
+ erp_cls = itemchild == null ? 2 : itemchild.erp_cls,
|
|
|
+ begin_day = child.StartEff,
|
|
|
+ end_day = child.EndEff,
|
|
|
+ child_num = child.SequenceNum,
|
|
|
+ version = child.Refs,
|
|
|
+ factory_id = item.factory_id,
|
|
|
+ company_id = item.company_id,
|
|
|
+ tenant_id = item.company_id,
|
|
|
+ IsDeleted = false,
|
|
|
+ Op = child.Op,
|
|
|
+ use_status = 1
|
|
|
+ };
|
|
|
+ childItemsAdd.Add(bomchild);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ _businessDbContext.BulkInsert(ItemsAdd);
|
|
|
+ _businessDbContext.BulkInsert(childItemsAdd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //循环获取子级物料编码,包括产品本身,有重复的结果去重即可
|
|
|
+ public List<string> GetChildItemNumber(string itemNum, List<string> list)
|
|
|
+ {
|
|
|
+ list.Add(itemNum);
|
|
|
+ var productStructures = _productStructureMaster.Select(p => p.ParentItem == itemNum && p.Domain == "1001" && p.IsActive);
|
|
|
+ list.AddRange(productStructures.Select(a => a.ComponentItem));
|
|
|
+ foreach (var item in productStructures)
|
|
|
+ {
|
|
|
+ if (item.StructureType.ToUpper() == "X")
|
|
|
+ {
|
|
|
+ GetChildItemNumber(item.ComponentItem, list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
|
|
|
public string DoProductScheduleJob()
|
|
|
{
|