Bladeren bron

同步WMS数据修改

Murphy 2 jaren geleden
bovenliggende
commit
aa9f02bd2a

+ 16 - 0
MicroServices/Business/Business.Application/Quartz/IWMSJobService.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    public interface IWMSJobService
+    {
+        /// <summary>
+        /// 定时同步mysql数据到mongodb中
+        /// </summary>
+        void SyncWMSData();
+    }
+}

+ 37 - 0
MicroServices/Business/Business.Application/Quartz/WMSJob.cs

@@ -0,0 +1,37 @@
+using Business.Quartz;
+using Quartz;
+using System.Threading.Tasks;
+using Business.SyncDataManagement;
+using Quartz;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    public class WMSJob : IJob
+    {
+
+        /// <summary>
+        /// 同步数据到mongodb服务
+        /// </summary>
+        public readonly SyncWMSDataAppService _syncDataAppservice;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public WMSJob(SyncWMSDataAppService syncDataAppservice)
+        {
+            _syncDataAppservice = syncDataAppservice;
+        }
+        public Task Execute(IJobExecutionContext context)
+        {
+            _syncDataAppservice.SyncWMSDataToMySQL();
+
+            return Task.CompletedTask;
+        }
+    }
+}

+ 33 - 0
MicroServices/Business/Business.Application/Quartz/WMSJobService.cs

@@ -0,0 +1,33 @@
+using Business.SyncDataManagement;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Quartz
+{
+    public class WMSJobService : IWMSJobService
+    {
+        /// <summary>
+        /// 同步数据到mongodb服务
+        /// </summary>
+        public readonly SyncWMSDataAppService _syncDataAppservice;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public WMSJobService(SyncWMSDataAppService syncDataAppservice)
+        {
+            _syncDataAppservice = syncDataAppservice;
+        }
+
+        /// <summary>
+        /// 定时同步mysql数据到mongodb中
+        /// </summary>
+        public void SyncWMSData()
+        {
+            _syncDataAppservice.SyncWMSDataToMySQL();
+        }
+    }
+}

+ 2 - 2
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -2516,8 +2516,8 @@ namespace Business.ResourceExamineManagement
                             ItemNum =a.ComponentItem,
                             QtyFrom = 0,
                             QtyTo = 0,
-                            LocationFrom="",
-                            LocationTo= LocationTo,
+                            LocationFrom= LocationTo,
+                            LocationTo="",
                             WorkOrd = item.WorkOrds,
                             QtyOrd = item.OrdQty*a.Qty,
                             IsActive = true

+ 0 - 1
MicroServices/Business/Business.Application/SyncDataManagement/SyncMySQLDataAppService.cs

@@ -172,7 +172,6 @@ namespace Business.SyncDataManagement
         /// <exception cref="NotImplementedException"></exception>
         public async void SyncBaseDataToMongoDB()
         {
-
             //同步物料Bom数据
             var icBoms = _mysql_ic_bom.GetListAsync().Result;
             if (icBoms.Count > 0)

+ 553 - 0
MicroServices/Business/Business.Application/SyncDataManagement/SyncWMSDataAppService.cs

@@ -0,0 +1,553 @@
+using Business.Core.Utilities;
+using Business.EntityFrameworkCore;
+using Business.EntityFrameworkCore.SqlRepositories;
+using Business.Model.MES.IC;
+using Business.Model.Sale;
+using Business.Model.SRM;
+using EFCore.BulkExtensions;
+using Microsoft.EntityFrameworkCore;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using Volo.Abp.Application.Services;
+using Volo.Abp.Domain.Repositories;
+
+namespace Business.SyncDataManagement
+{
+    /// <summary>
+    /// 同步mysql数据到mongodb
+    /// </summary>
+    public class SyncWMSDataAppService : ApplicationService
+    {
+        #region 服务
+        /// <summary>
+        /// 物料bom
+        /// </summary>
+        private IRepository<ic_bom, long> _mysql_ic_bom;
+
+        /// <summary>
+        /// 物料bom子表
+        /// </summary>
+        private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
+
+        /// <summary>
+        /// 物料
+        /// </summary>
+        private IRepository<ic_item, long> _mysql_ic_item;
+
+        /// <summary>
+        /// 供应商
+        /// </summary>
+        private IRepository<srm_supplier, long> _mysql_srm_supplier;
+
+        /// <summary>
+        /// 物料采购计划表
+        /// </summary>
+        private IRepository<ic_plan, long> _mysql_ic_plan;
+
+        /// <summary>
+        /// 物料工厂明细表
+        /// </summary>
+        private IRepository<ic_factory_details, long> _mysql_ic_factory_details;
+
+        /// <summary>
+        /// 物料采购报价单
+        /// </summary>
+        private IRepository<srm_purchase, long> _mysql_srm_purchase;
+
+        /// <summary>
+        /// 物料采购报价单
+        /// </summary>
+        private IRepository<crm_customer, long> _mysql_crm_customer;
+
+        /// <summary>
+        /// 销售订单
+        /// </summary>
+        private IRepository<crm_seorder, long> _mysql_crm_seorder;
+
+        /// <summary>
+        /// 销售订单明细
+        /// </summary>
+        private IRepository<crm_seorderentry, long> _mysql_crm_seorderentry;
+
+        /// <summary>
+        /// 雪花算法
+        /// </summary>
+        SnowFlake help = new SnowFlake();
+        private readonly BusinessDbContext _businessDbContext;
+        private readonly ISqlRepository<CustMaster> _custMaster;
+        private readonly ISqlRepository<SuppMaster> _suppMaster;
+        private readonly ISqlRepository<ConsigneeAddressMaster> _consigneeAddressMaster;
+        private readonly ISqlRepository<ItemMaster> _itemMaster;
+        private readonly ISqlRepository<ProductStructureMaster> _productStructureMaster;
+        #endregion
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public SyncWMSDataAppService(
+            IRepository<ic_bom, long> mysql_ic_bom,
+            IRepository<ic_bom_child, long> mysql_ic_bom_child,
+            IRepository<ic_check, long> mysql_ic_check,
+            IRepository<ic_item, long> mysql_ic_item,
+            IRepository<srm_supplier, long> mysql_srm_supplier,
+            IRepository<ic_factory_details, long> mysql_ic_factory_details,
+            IRepository<srm_purchase, long> mysql_srm_purchase,
+            IRepository<ic_plan, long> mysql_ic_plan,
+            IRepository<crm_customer, long> mysql_crm_customer,
+            IRepository<crm_seorder, long> mysql_crm_seorder,
+            IRepository<crm_seorderentry, long> mysql_crm_seorderentry,
+            ISqlRepository<CustMaster> custMaster,
+            ISqlRepository<SuppMaster> suppMaster,
+            ISqlRepository<ConsigneeAddressMaster> consigneeAddressMaster,
+            ISqlRepository<ItemMaster> itemMaster,
+            ISqlRepository<ProductStructureMaster> productStructureMaster,
+            BusinessDbContext businessDbContext
+         )
+        {
+            _mysql_ic_bom = mysql_ic_bom;
+            _mysql_ic_bom_child = mysql_ic_bom_child;
+            _mysql_ic_item = mysql_ic_item;
+            _mysql_srm_supplier = mysql_srm_supplier;
+            _mysql_ic_factory_details = mysql_ic_factory_details;
+            _mysql_srm_purchase = mysql_srm_purchase;
+            _mysql_ic_plan = mysql_ic_plan;
+            _mysql_crm_customer = mysql_crm_customer;
+            _mysql_crm_seorder = mysql_crm_seorder;
+            _mysql_crm_seorderentry = mysql_crm_seorderentry;
+            _custMaster = custMaster;
+            _suppMaster = suppMaster;
+            _consigneeAddressMaster = consigneeAddressMaster;
+            _itemMaster = itemMaster;
+            _productStructureMaster = productStructureMaster;
+            _businessDbContext = businessDbContext;
+        }
+
+        /// <summary>
+        /// 同步WMS基础数据到MySQL
+        /// </summary>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public void SyncWMSDataToMySQL()
+        {
+            //SyncCustMaster();
+            //SyncSuppMaster();
+            //SyncSalesOrdMaster();
+            //SyncSalesOrdMasterEntry();
+            //SyncItemMaster();
+            SyncBom();
+        }
+        //同步客户
+        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();
+                        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();
+                        ItemsAdd.Add(supplier);
+                    }
+                }
+                _businessDbContext.BulkInsert(ItemsAdd);
+            }
+        }
+        ////同步销售订单
+        //public void SyncSalesOrdMaster()
+        //{
+        //    var customerList = _mysql_crm_customer.GetListAsync().Result;
+        //    var saleOrderList = _mysql_crm_seorder.GetListAsync().Result;
+        //    var ItemMasterDS = _repository.SelectDataBaseBySql("SELECT A.SalesOrd,C.SortName AS CustomName,A.SoldTo AS Cust,A.OrdDate,A.RequiredDate,A.Sequence,A.Curr,A.ExchRate,A.Salesperson1,A.Project,B.Descr AS ProjectName,A.[Domain] from SalesOrdMaster A INNER JOIN CustMaster C ON A.SoldTo=C.Cust and A.[Domain]=C.[Domain]\r\nLEFT JOIN ProjectMaster B On A.Project=B.Project AND A.[Domain]=B.[Domain] ", "SalesOrdMaster");
+        //    List<crm_seorder> ItemsAdd = new List<crm_seorder>();
+        //    List<crm_seorder> ItemsUpdate = new List<crm_seorder>();
+        //    if (ItemMasterDS != null && ItemMasterDS.Tables.Count > 0 && ItemMasterDS.Tables[0].Rows.Count > 0)
+        //    {
+        //        for (int i = 0; i < ItemMasterDS.Tables[0].Rows.Count; i++)
+        //        {
+        //            long domain = Convert.ToInt64(ItemMasterDS.Tables[0].Rows[i]["Domain"].ToString());
+        //            long factory_id = domain % 1000;
+        //            long tenant_id = domain - factory_id;
+        //            var custno = ItemMasterDS.Tables[0].Rows[i]["Cust"].ToString();
+        //            var cust = customerList.Find(a => a.customer_no == custno && a.factory_id == factory_id && a.tenant_id == tenant_id);
+        //            long? custom_id = cust is null ? cust.Id : null;
+        //            var saleorder = saleOrderList.Find(x => x.bill_no == ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString() && x.tenant_id == factory_id && x.factory_id == tenant_id);
+        //            if (saleorder is null)
+        //            {
+        //                var order = new crm_seorder
+        //                {
+        //                    bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString(),
+        //                    custom_id = custom_id,
+        //                    custom_name = ItemMasterDS.Tables[0].Rows[i]["CustomName"].ToString(),
+        //                    custom_no = ItemMasterDS.Tables[0].Rows[i]["Cust"].ToString(),
+        //                    //custom_level = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? "外购" : "自制",
+        //                    date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                    rdate = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"],
+        //                    //urgent = "",
+        //                    currency = ItemMasterDS.Tables[0].Rows[i]["Curr"].ToString() == "RMB" ? 1 : 0,
+        //                    exchange_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                    //biller = ItemMasterDS.Tables[0].Rows[i]["NetWeightUM"].ToString(),
+        //                    //emp_no = (decimal)ItemMasterDS.Tables[0].Rows[i]["Length"],
+        //                    emp_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    //auditor = (decimal)ItemMasterDS.Tables[0].Rows[i]["Height"],
+        //                    //audit_date = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? 1 : 0,
+        //                    //status = 1,
+        //                    //closed = "",
+        //                    //op_time = 1,
+        //                    bill_from = "",
+        //                    //project_name = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["LotSerialControl"]) == true ? 1 : 0,
+        //                    //project_code = "",
+        //                    out_stock_type = 1,//TODO
+        //                    //sale_dept_id = "",
+        //                    //sale_dept_name = 1,
+        //                    //sale_dept_code = 1,
+        //                    //create_dept = 1
+        //                    factory_id = factory_id,
+        //                    tenant_id = tenant_id
+        //                };
+        //                order.GenerateNewId();
+        //                ItemsAdd.Add(order);
+        //            }
+        //            else
+        //            {
+        //                saleorder.bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString();
+        //                saleorder.custom_id = custom_id;
+        //                saleorder.custom_name = ItemMasterDS.Tables[0].Rows[i]["CustomName"].ToString();
+        //                saleorder.custom_no = ItemMasterDS.Tables[0].Rows[i]["Cust"].ToString();
+        //                //custom_level = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? "外购" : "自制",
+        //                saleorder.date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"];
+        //                saleorder.rdate = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"];
+        //                saleorder.urgent = (int?)ItemMasterDS.Tables[0].Rows[i]["Sequence"];
+        //                saleorder.currency = ItemMasterDS.Tables[0].Rows[i]["Curr"].ToString() == "RMB" ? 1 : 0;
+        //                saleorder.exchange_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"];
+        //                //biller = ItemMasterDS.Tables[0].Rows[i]["NetWeightUM"].ToString(),
+        //                //emp_no = (decimal)ItemMasterDS.Tables[0].Rows[i]["Length"],
+        //                saleorder.emp_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString();
+        //                //auditor = (decimal)ItemMasterDS.Tables[0].Rows[i]["Height"],
+        //                //audit_date = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? 1 : 0,
+        //                //status = 1,
+        //                //closed = "",
+        //                //op_time = 1,
+        //                saleorder.bill_from = "";
+        //                saleorder.project_name = ItemMasterDS.Tables[0].Rows[i]["ProjectName"].ToString();
+        //                saleorder.project_code = ItemMasterDS.Tables[0].Rows[i]["Project"].ToString();
+        //                saleorder.out_stock_type = 1;//TODO
+        //                //sale_dept_id = "",
+        //                //sale_dept_name = 1,
+        //                //sale_dept_code = 1,
+        //                //create_dept = 1
+        //                ItemsUpdate.Add(saleorder);
+        //            }
+        //        }
+        //        //_businessDbContext.crm_seorder.Delete();
+        //        _businessDbContext.crm_seorder.BulkInsert(ItemsAdd);
+        //        _businessDbContext.crm_seorder.BulkUpdate(ItemsUpdate);
+        //    }
+        //}
+
+        ////同步销售订单明细
+        //public void SyncSalesOrdMasterEntry()
+        //{
+        //    var saleOrderEntryList = _mysql_crm_seorderentry.GetListAsync().Result;
+        //    var saleOrderList = _mysql_crm_seorder.GetListAsync().Result;
+        //    var ItemMasterDS = _repository.SelectDataBaseBySql("SELECT A.SalesOrd,A.Line,C.Descr,C.Descr1,A.ItemNum,A.UM,A.QtyOrded,A.Price,A.Disc,A.RequiredDate,A.Remark,B.CustPO,A.CustItem,A.Status,A.QtyShipped,A.QtyReturned,B.Contract,A.Domain from SalesOrdDetail A INNER JOIN SalesOrdMaster B On A.SalesOrd=B.SalesOrd and A.[Domain]=B.[Domain] INNER JOIN ItemMaster C on A.ItemNum=C.ItemNum and A.[Domain]=C.[Domain]", "SalesOrdDetail");
+        //    List<crm_seorderentry> ItemsAdd = new List<crm_seorderentry>();
+        //    List<crm_seorderentry> ItemsUpdate = new List<crm_seorderentry>();
+        //    if (ItemMasterDS != null && ItemMasterDS.Tables.Count > 0 && ItemMasterDS.Tables[0].Rows.Count > 0)
+        //    {
+        //        for (int i = 0; i < ItemMasterDS.Tables[0].Rows.Count; i++)
+        //        {
+        //            long domain = Convert.ToInt64(ItemMasterDS.Tables[0].Rows[i]["Domain"].ToString());
+        //            long factory_id = domain % 1000;
+        //            long tenant_id = domain - factory_id;
+        //            var bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString();
+        //            var seorder = saleOrderList.Find(a => a.bill_no == bill_no && a.factory_id == factory_id && a.tenant_id == tenant_id);
+        //            long? seorder_id = seorder is null ? seorder.Id : null;
+        //            var saleorderentry = saleOrderEntryList.Find(x => x.bill_no == bill_no && x.tenant_id == factory_id && x.factory_id == tenant_id);
+        //            if (saleorderentry is null)
+        //            {
+        //                var entry = new crm_seorderentry
+        //                {
+        //                    seorder_id = seorder_id,
+        //                    bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString(),
+        //                    entry_seq = (int?)ItemMasterDS.Tables[0].Rows[i]["Line"],
+        //                    item_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString(),
+        //                    item_name = ItemMasterDS.Tables[0].Rows[i]["Descr"].ToString(),
+        //                    specification = ItemMasterDS.Tables[0].Rows[i]["Descr1"].ToString(),
+        //                    //urgent = (int?)ItemMasterDS.Tables[0].Rows[i]["PLPriority"],
+        //                    bom_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString(),
+        //                    unit = ItemMasterDS.Tables[0].Rows[i]["UM"].ToString(),
+        //                    qty = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyOrded"],
+        //                    //price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"],
+        //                    //tax_price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                    //tax_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                    amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"],
+        //                    //discount_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                    discount_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Disc"],
+        //                    //total_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                    plan_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"],
+        //                    //date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                    //planner_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    //planner_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    remark = ItemMasterDS.Tables[0].Rows[i]["Remark"].ToString(),
+        //                    //soure_bill_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    custom_order_bill_no = ItemMasterDS.Tables[0].Rows[i]["CustPO"].ToString(),
+        //                    //custom_order_entryid = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    //sys_capacity_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                    //adjust_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                    //mrp_closed = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                    custom_order_itemno = ItemMasterDS.Tables[0].Rows[i]["CustItem"].ToString(),
+        //                    state = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["Status"]),//TODO
+        //                    deliver_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyShipped"],
+        //                    returned_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyReturned"],
+        //                    //se_reject_reason = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    //out_stock_type = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                    //is_checked = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                    //sys_material_date = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                    contract_no = ItemMasterDS.Tables[0].Rows[i]["Contract"].ToString(),
+        //                    //create_dept = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"])
+        //                    factory_id = factory_id,
+        //                    tenant_id = tenant_id
+        //                };
+        //                entry.GenerateNewId();
+        //                ItemsAdd.Add(entry);
+        //            }
+        //            else
+        //            {
+        //                saleorderentry.seorder_id = seorder_id;
+        //                saleorderentry.bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString();
+        //                saleorderentry.entry_seq = (int?)ItemMasterDS.Tables[0].Rows[i]["Line"];
+        //                saleorderentry.item_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString();
+        //                saleorderentry.item_name = ItemMasterDS.Tables[0].Rows[i]["Descr"].ToString();
+        //                saleorderentry.specification = ItemMasterDS.Tables[0].Rows[i]["Descr1"].ToString();
+        //                //urgent = (int?)ItemMasterDS.Tables[0].Rows[i]["PLPriority"],
+        //                saleorderentry.bom_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString();
+        //                saleorderentry.unit = ItemMasterDS.Tables[0].Rows[i]["UM"].ToString();
+        //                saleorderentry.qty = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyOrded"];
+        //                //price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"],
+        //                //tax_price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                //tax_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                saleorderentry.amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"];
+        //                //discount_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                saleorderentry.discount_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Disc"];
+        //                //total_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                saleorderentry.plan_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"];
+        //                //date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                //planner_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                //planner_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                saleorderentry.remark = ItemMasterDS.Tables[0].Rows[i]["Remark"].ToString();
+        //                //soure_bill_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                saleorderentry.custom_order_bill_no = ItemMasterDS.Tables[0].Rows[i]["CustPO"].ToString();
+        //                //custom_order_entryid = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                //sys_capacity_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                //adjust_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
+        //                //mrp_closed = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                saleorderentry.custom_order_itemno = ItemMasterDS.Tables[0].Rows[i]["CustItem"].ToString();
+        //                saleorderentry.state = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["Status"]);//TODO
+        //                //rnumber = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                //deliver_notice_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
+        //                saleorderentry.deliver_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyShipped"];
+        //                saleorderentry.returned_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyReturned"];
+        //                //se_reject_reason = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                //out_stock_type = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
+        //                //is_checked = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                //sys_material_date = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
+        //                saleorderentry.contract_no = ItemMasterDS.Tables[0].Rows[i]["Contract"].ToString();
+        //                //create_dept = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"])
+        //                ItemsUpdate.Add(saleorderentry);
+        //            }
+        //        }
+        //        //_businessDbContext.crm_seorder.Delete();
+        //        _businessDbContext.crm_seorderentry.BulkInsert(ItemsAdd);
+        //        _businessDbContext.crm_seorderentry.BulkUpdate(ItemsUpdate);
+
+        //    }
+        //}
+
+        //同步物料
+        public void SyncItemMaster()
+        {
+            var ic_itemList = _mysql_ic_item.GetListAsync(a=>a.tenant_id==1000 && a.factory_id==1001).Result;
+            var custList = _itemMaster.Select(a => a.IsActive);
+            List<ic_item> ItemsAdd = new List<ic_item>();
+            if (custList != null && custList.Count > 0)
+            {
+                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);
+                    if (ic_item == null)
+                    {
+                        ItemsAdd.Add(new ic_item(help.NextId())
+                        {
+                            number = custList[i].ItemNum, //物料编码
+                            name = custList[i].Descr, //物料名称
+                            model = custList[i].Descr1,//规格型号
+                            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_name = custList[i].PurMfg == "P" ? "外购" : "自制",//物料属性名称
+                            unit = custList[i].UM,//单位
+                            item_level = 0,//物料等级
+                            source = "",//来源
+                            iskeyitem = custList[i].IsMainMas ? 1 : 0,//是否关键件
+                            net_weight = (decimal)custList[i].NetWeight,//净重
+                            maund = custList[i].NetWeightUM,//重量单位
+                            length = (decimal)custList[i].Length,//长度
+                            width = (decimal)custList[i].Width,//宽度
+                            height = (decimal)custList[i].Height,//高度
+                            allowpur = custList[i].PurMfg == "P" ? 1 : 0,//允许采购
+                            allowsale = 1,//允许销售
+                            allowmanu = custList[i].PurMfg == "L" ? 1 : 0,//允许生产
+                            allowout = 1,//允许委外
+                            allowbatch = custList[i].LotSerialControl ? 1 : 0,//批号管理
+                            allowserial = custList[i].LotSerialControl ? 1 : 0,//序列号管理
+                            photo = "",//图片
+                            enable_warning = 1,//启用预警
+                            factory_id = 1001,
+                            tenant_id = 1000,
+                            IsDeleted=false
+                        });
+                    }
+                }
+            }
+            _businessDbContext.BulkInsert(ItemsAdd);
+        }
+
+        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 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 item = ic_itemList.Find(a => a.number == c);
+                    var ItemList = wmsBomList.Where(a=>a.ParentItem ==c);
+                    long domain = Convert.ToInt64(ItemList.First().Domain);
+                    long factory_id = domain % 1000;
+                    long tenant_id = domain - factory_id;
+                    var bom = new ic_bom()
+                    {
+                        bom_number = c,
+                        icitem_id = item==null ? help.NextId() : item.Id,
+                        item_name= item==null? "" : item.name,
+                        item_number =c,
+                        version= ItemList.First().Refs,
+                        factory_id = 1001,
+                        tenant_id = 1000,
+                        IsDeleted=false
+                    };
+                    bom.GenerateNewId();
+                    ItemsAdd.Add(bom);
+
+                    foreach(var child in ItemList)
+                    {
+                        var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
+                        var bomchild = new ic_bom_child()
+                        {
+                            bom_id= bom.Id,
+                            bom_number=bom.bom_number,
+                            icitem_id= itemchild==null ?long.MinValue : item.Id,
+                            item_number= child.ComponentItem,
+                            item_name= itemchild==null? "" : item.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
+                        };
+                        bomchild.GenerateNewId();
+                        childItemsAdd.Add(bomchild);
+                    }
+                }
+                _businessDbContext.BulkInsert(ItemsAdd);
+                _businessDbContext.BulkInsert(childItemsAdd);
+            }
+        }
+    }
+}

+ 10 - 1
MicroServices/Business/Business.Host/BusinessHostModule.cs

@@ -113,7 +113,7 @@ namespace Business
                 q.AddTrigger(opts => opts
                     .ForJob(jobKey)
                     .WithIdentity("SyncDataJob-trigger")
-                    .WithCronSchedule("0 01 01 * * ?")
+                    .WithCronSchedule("0 40 9 * * ?")
                     .WithDescription("定时同步MySQL基础数据到MongoDB"));
 
                 var NLogJobKey = new JobKey("NLogJob");
@@ -134,6 +134,15 @@ namespace Business
                     .WithCronSchedule("0 01 01 * * ?")
                     .WithDescription("定时处理金蝶同步到Ext数据库的数据"));
 
+                var WMSJobKey = new JobKey("WMSJob");
+                q.AddJob<WMSJob>(opts => opts.WithIdentity(WMSJobKey));
+
+                q.AddTrigger(opts => opts
+                    .ForJob(WMSJobKey)
+                    .WithIdentity("WMSJob-trigger")
+                    .WithCronSchedule("0 34 11 * * ?")
+                    .WithDescription("定时同步WMS物料订单等基础数据到MySQL"));
+
                 //var ProductionScheduleJobKey = new JobKey("ProductionScheduleJob");
                 //q.AddJob<ProductionScheduleJob>(opts => opts.WithIdentity(ProductionScheduleJobKey));
 

+ 101 - 0
MicroServices/Business/Bussiness.Model/MES/IC/ConsigneeAddressMaster.cs

@@ -0,0 +1,101 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+namespace Business.Model.MES.IC
+{
+    /// <summary>
+    /// 供应商客户地址表
+    /// </summary>
+    [Comment("供应商客户地址表")]
+    public class ConsigneeAddressMaster
+    {
+        /// <summary>
+        /// 主键
+        /// </summary>
+        [Comment("主键")]
+        [Key]
+        public int RecID { get; set; }
+
+        /// <summary>
+        /// 地址编码
+        /// </summary>
+        [Comment("地址编码")]
+        public string? Address { get; set; }
+
+        /// <summary>
+        /// 域名
+        /// </summary>
+        [Comment("域名")]
+        public string? Domain { get; set; }
+
+        /// <summary>
+        /// 类型:区分客户(Cust)和供应商(Supp)
+        /// </summary>
+        [Comment("类型:区分客户(Cust)和供应商(Supp)")]
+        public string? Typed { get; set; }
+
+        /// <summary>
+        /// 名称
+        /// </summary>
+        [Comment("名称")]
+        public string? Name { get; set; }
+
+        /// <summary>
+        /// 联系电话
+        /// </summary>
+        [Comment("联系电话")]
+        public string? Telephone { get; set; }
+
+        /// <summary>
+        /// 邮箱
+        /// </summary>
+        [Comment("邮箱")]
+        public string? AttentionEmail { get; set; }
+
+        /// <summary>
+        /// 邮政编码
+        /// </summary>
+        [Comment("邮政编码")]
+        public string? Post { get; set; }
+
+        /// <summary>
+        /// 国家
+        /// </summary>
+        [Comment("国家")]
+        public string? Country { get; set; }
+
+        /// <summary>
+        /// 城市
+        /// </summary>
+        [Comment("城市")]
+        public string? City { get; set; }
+
+        /// <summary>
+        /// 区
+        /// </summary>
+        [Comment("区")]
+        public string? State { get; set; }
+
+        /// <summary>
+        /// 地址
+        /// </summary>
+        [Comment("地址")]
+        public string? Address1 { get; set; }
+
+        /// <summary>
+        /// 联系人
+        /// </summary>
+        [Comment("联系人")]
+        public string? Attention1 { get; set; }
+
+        /// <summary>
+        /// 是否有效:1-有效;0-无效
+        /// </summary>
+        [Comment("是否有效")]
+        public Boolean IsActive { get; set; }
+    }
+}

+ 67 - 0
MicroServices/Business/Bussiness.Model/MES/IC/CustMaster.cs

@@ -0,0 +1,67 @@
+using Business.Model;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Model.MES.IC
+{
+    /// <summary>
+    /// 客户主表
+    /// </summary>
+    [Comment("客户主表")]
+    public class CustMaster
+    {
+        /// <summary>
+        /// 主键
+        /// </summary>
+        [Comment("主键")]
+        [Key]
+        public int RecID { get; set; }
+
+        /// <summary>
+        /// 域名
+        /// </summary>
+        [Comment("域名")]
+        public string? Domain { get; set; }
+
+        /// <summary>
+        /// 客户代码
+        /// </summary>
+        [Comment("客户代码")]
+        public string? Cust { get; set; }
+
+        /// <summary>
+        /// 简称
+        /// </summary>
+        [Comment("简称")]
+        public string? SortName { get; set; }
+
+        /// <summary>
+        /// 币别
+        /// </summary>
+        [Comment("币别")]
+        public string? Curr { get; set; }
+
+        /// <summary>
+        /// 销售人员
+        /// </summary>
+        [Comment("销售人员")]
+        public string? Salesperson1 { get; set; }
+
+        /// <summary>
+        /// 发货提前期
+        /// </summary>
+        [Comment("发货提前期")]
+        public string? CustShippingLT { get; set; }
+
+        /// <summary>
+        /// 是否有效:1-有效;0-无效
+        /// </summary>
+        [Comment("是否有效")]
+        public Boolean IsActive { get; set; }
+    }
+}

+ 12 - 0
MicroServices/Business/Bussiness.Model/MES/IC/ItemMaster.cs

@@ -58,6 +58,18 @@ namespace Business.Model.MES.IC
         [Comment("状态")]
         public string? Location { get; set; }
 
+        public string? Descr { get; set; }
+        public string? Descr1 { get; set; }
+        public string? PurMfg { get; set; }
+        public Boolean IsMainMas { get; set; }
+
+        public decimal? NetWeight { get; set; }
+        public string? NetWeightUM { get; set; }
+        public decimal? Length { get; set; }
+        public decimal? Width { get; set; }
+        public decimal? Height { get; set; }
+        public Boolean LotSerialControl { get; set; }
+
         /// <summary>
         /// 是否有效:1-有效;0-无效
         /// </summary>

+ 30 - 0
MicroServices/Business/Bussiness.Model/MES/IC/ProductStructureMaster.cs

@@ -56,7 +56,37 @@ namespace Business.Model.MES.IC
         [Comment("数量")]
         public decimal Qty { get; set; }
 
+        /// <summary>
+        /// 序列号
+        /// </summary>
+        [Comment("序列号")]
+        public int SequenceNum { get; set; }
+
+        /// <summary>
+        /// 开始生效
+        /// </summary>
+        [Comment("开始生效")]
+        public DateTime? StartEff { get; set; }
+
 
+        /// <summary>
+        /// 终止生效
+        /// </summary>
+        [Comment("终止生效")]
+        public DateTime? EndEff { get; set; }
+
+
+        /// <summary>
+        /// 版本
+        /// </summary>
+        [Comment("版本")]
+        public string? Refs { get; set; }
+
+        /// <summary>
+        /// 单位
+        /// </summary>
+        [Comment("单位")]
+        public string? UM { get; set; }
 
         /// <summary>
         /// 是否有效:1-有效;0-无效

+ 67 - 0
MicroServices/Business/Bussiness.Model/MES/IC/SuppMaster.cs

@@ -0,0 +1,67 @@
+using Business.Model;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Model.MES.IC
+{
+    /// <summary>
+    /// 供应商主表
+    /// </summary>
+    [Comment("供应商主表")]
+    public class SuppMaster
+    {
+        /// <summary>
+        /// 主键
+        /// </summary>
+        [Comment("主键")]
+        [Key]
+        public int RecID { get; set; }
+
+        /// <summary>
+        /// 域名
+        /// </summary>
+        [Comment("域名")]
+        public string? Domain { get; set; }
+
+        /// <summary>
+        /// 供应商代码
+        /// </summary>
+        [Comment("供应商代码")]
+        public string? Supp { get; set; }
+
+        /// <summary>
+        /// 简称
+        /// </summary>
+        [Comment("简称")]
+        public string? SortName { get; set; }
+
+        /// <summary>
+        /// 币别
+        /// </summary>
+        [Comment("币别")]
+        public string? Curr { get; set; }
+
+        /// <summary>
+        /// 类型
+        /// </summary>
+        [Comment("类型")]
+        public string? Type { get; set; }
+
+        /// <summary>
+        /// 支付方式
+        /// </summary>
+        [Comment("支付方式")]
+        public string? CrTerms { get; set; }
+
+        /// <summary>
+        /// 是否有效:1-有效;0-无效
+        /// </summary>
+        [Comment("是否有效")]
+        public Boolean IsActive { get; set; }
+    }
+}