Просмотр исходного кода

Merge branch 'dev' of http://123.60.180.165:4647/ZZYDOP/DOPCore into dev

zhengly 2 лет назад
Родитель
Сommit
bee22a434f
32 измененных файлов с 1497 добавлено и 814 удалено
  1. 6 4
      MicroServices/Business/Business.Application.Contracts/Business.Application.Contracts.csproj
  2. 2 7
      MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/Dto/POGroupDto.cs
  3. 23 1
      MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/IResourceExamineAppService.cs
  4. 41 0
      MicroServices/Business/Business.Application.Contracts/SystemJob/ISystemJobAppService.cs
  5. 0 16
      MicroServices/Business/Business.Application.Contracts/Test/ITestAppService.cs
  6. 0 34
      MicroServices/Business/Business.Application/Quartz/ExtJob.cs
  7. 0 251
      MicroServices/Business/Business.Application/Quartz/ExtJobService.cs
  8. 0 16
      MicroServices/Business/Business.Application/Quartz/IQuartzJobService.cs
  9. 0 16
      MicroServices/Business/Business.Application/Quartz/IWMSJobService.cs
  10. 0 20
      MicroServices/Business/Business.Application/Quartz/LogHostedService.cs
  11. 0 34
      MicroServices/Business/Business.Application/Quartz/NLogJob.cs
  12. 0 38
      MicroServices/Business/Business.Application/Quartz/ProductionScheduleJob.cs
  13. 0 33
      MicroServices/Business/Business.Application/Quartz/QuartzJobService.cs
  14. 0 34
      MicroServices/Business/Business.Application/Quartz/SyncMySQLDataJob.cs
  15. 0 29
      MicroServices/Business/Business.Application/Quartz/WMSJob.cs
  16. 0 33
      MicroServices/Business/Business.Application/Quartz/WMSJobService.cs
  17. 4 11
      MicroServices/Business/Business.Application/ResourceExamineManagement/CalcBomViewAppService.cs
  18. 3 3
      MicroServices/Business/Business.Application/ResourceExamineManagement/ProductExamineAppService.cs
  19. 54 49
      MicroServices/Business/Business.Application/ResourceExamineManagement/ProductionScheduleAppService.cs
  20. 147 47
      MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
  21. 1 1
      MicroServices/Business/Business.Application/SaleForecastManagement/MonthlyCapacityLoadAppService.cs
  22. 1061 0
      MicroServices/Business/Business.Application/SystemJobManagement/SystemJobAppService.cs
  23. 24 44
      MicroServices/Business/Business.Host/BusinessHostModule.cs
  24. 3 3
      MicroServices/Business/Business.Host/Startup.cs
  25. 6 4
      MicroServices/Business/Business.HttpApi/Business.HttpApi.csproj
  26. 44 4
      MicroServices/Business/Business.HttpApi/Controllers/ResourceExamineController.cs
  27. 1 8
      MicroServices/Business/Business.HttpApi/Controllers/SerialNumberController.cs
  28. 67 0
      MicroServices/Business/Business.HttpApi/Controllers/SystemJobController.cs
  29. 0 60
      MicroServices/Business/Business.HttpApi/Controllers/TestController.cs
  30. 0 11
      MicroServices/Business/Business.HttpApi/Models/Test/TestModel.cs
  31. 9 2
      MicroServices/Business/Bussiness.Model/Base/BaseEntity.cs
  32. 1 1
      MicroServices/Business/QuartzSettings/task_job.json

+ 6 - 4
MicroServices/Business/Business.Application.Contracts/Business.Application.Contracts.csproj

@@ -18,6 +18,12 @@
     <WarningLevel>0</WarningLevel>
   </PropertyGroup>
 
+  <ItemGroup>
+    <Compile Remove="MES\**" />
+    <EmbeddedResource Remove="MES\**" />
+    <None Remove="MES\**" />
+  </ItemGroup>
+
   <ItemGroup>
     <None Remove="Localization\Business\cs.json" />
     <None Remove="Localization\Business\en.json" />
@@ -42,8 +48,4 @@
     <ProjectReference Include="..\Bussiness.MongoModel\Business.MongoModel.csproj" />
   </ItemGroup>
 
-  <ItemGroup>
-    <Folder Include="MES\" />
-  </ItemGroup>
-
 </Project>

+ 2 - 7
MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/Dto/POGroupDto.cs

@@ -10,14 +10,9 @@ namespace Business.ResourceExamineManagement.Dto
     public class POGroupDto
     {
         /// <summary>
-        /// 0销售 1计划
+        /// 供应商ID
         /// </summary>
-        public int Type { get; set; }
-
-        /// <summary>
-        /// 外购  委外
-        /// </summary>
-        public int erp_cls { get; set; }
+        public long supplier_id { get; set; }
 
         /// <summary>
         /// 供应类别

+ 23 - 1
MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/IResourceExamineAppService.cs

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
 using Volo.Abp.Application.Dtos;
 using Volo.Abp.Application.Services;
 using Business.ResourceExamineManagement.Dto;
+using Business.Dto;
 
 namespace Business.ResourceExamineManagement
 {
@@ -69,10 +70,31 @@ namespace Business.ResourceExamineManagement
         void AutoCreateBomBillInterface();
 
         /// <summary>
-        /// 下达领料
+        /// Pr自动合并
         /// </summary>
         /// <param name="workOrds"></param>
         /// <returns></returns>
         void PrAutoMerge();
+
+        /// <summary>
+        /// Pr手动合并
+        /// </summary>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        Task<string> PrMerge(string ids);
+
+        /// <summary>
+        /// Pr自动审核
+        /// </summary>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        Task<string> PrAutoApprove();
+
+        /// <summary>
+        /// Pr手动审核
+        /// </summary>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        Task<string> PrApprove(string ids);
     }
 }

+ 41 - 0
MicroServices/Business/Business.Application.Contracts/SystemJob/ISystemJobAppService.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Business;
+using Business.ResourceExamineManagement;
+using Business.SystemJob;
+using Volo.Abp.Application.Services;
+
+namespace Business.SystemJob
+{
+    /// <summary>
+    /// 系统定时任务
+    /// </summary>
+    public interface ISystemJobAppService : IApplicationService
+    {
+        /// <summary>
+        /// 定时同步WMS物料订单等基础数据到MySQL
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        string SyncWMSDataToMySQLJob();
+
+        /// <summary>
+        /// 定时创建NLog日志按月分表
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        string LogInstallJob();
+
+        /// <summary>
+        /// 定时同步MySQL基础数据到MongoDB
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        string SyncBaseDataToMongoDBJob();
+
+        string DoProductShceduleJob();
+    }
+}

+ 0 - 16
MicroServices/Business/Business.Application.Contracts/Test/ITestAppService.cs

@@ -1,16 +0,0 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Volo.Abp.Application.Services;
-
-namespace Business.Test
-{
-    public interface ITestAppService: IApplicationService
-    {
-        Task<string> TestApi(string name);
-
-        Task<long> GetUserCount();
-
-        //Task<dynamic> GetMenuTree();
-
-    }
-}

+ 0 - 34
MicroServices/Business/Business.Application/Quartz/ExtJob.cs

@@ -1,34 +0,0 @@
-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 ExtJob : IJob
-    {
-
-        /// <summary>
-        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
-        /// </summary>
-        public readonly ExtJobService _extJobService;
-
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        public ExtJob(ExtJobService extJobService)
-        {
-            _extJobService = extJobService;
-        }
-        public Task Execute(IJobExecutionContext context)
-        {
-            _extJobService.DoExt();
-
-            return Task.CompletedTask;
-        }
-    }
-}

+ 0 - 251
MicroServices/Business/Business.Application/Quartz/ExtJobService.cs

@@ -1,251 +0,0 @@
-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<in_kd_material, long> _kd_material;
-        private IRepository<ic_item, long> _ic_item;
-        private IRepository<srm_purchase, long> _srm_purchase;
-        private readonly BusinessDbContext _businessDbContext;
-        private readonly BusinessExtDbContext _businessExtDbContext;
-
-        public ExtJobService(
-         IRepository<in_kd_material, long> kd_material,
-         IRepository<ic_item, long> ic_item,
-         IRepository<srm_purchase, long> srm_purchase,
-         BusinessDbContext businessDbContext,
-         BusinessExtDbContext businessExtDbContext
-         )
-        {
-            _kd_material= kd_material;
-            _ic_item= ic_item;
-            _srm_purchase = srm_purchase;
-            _businessDbContext = businessDbContext;
-            _businessExtDbContext = businessExtDbContext;
-        }
-
-        /// <summary>
-        /// 处理物料
-        /// </summary>
-        public async void DoExt()
-        {
-           await DoMaterial();
-            //DoBom();
-        }
-
-        /// <summary>
-        /// 处理物料
-        /// </summary>
-        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_item> ic_itemListAdd = new List<ic_item>();
-            List<ic_item> ic_itemListUpdate = new List<ic_item>();
-            List<srm_purchase> srm_purchaseListAdd = new List<srm_purchase>();
-            List<srm_purchase> srm_purchaseListUpdate = new List<srm_purchase>();
-            List<ext_xref> ext_xrefList = new List<ext_xref>();
-            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);
-                }
-            }
-        }
-        /// <summary>
-        /// 处理物料清单
-        /// </summary>
-        public void DoBom()
-        {
-            LogManager.Configuration.Install(new NLog.Config.InstallationContext());
-        }
-    }
-}

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

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

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

@@ -1,16 +0,0 @@
-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();
-    }
-}

+ 0 - 20
MicroServices/Business/Business.Application/Quartz/LogHostedService.cs

@@ -1,20 +0,0 @@
-using Microsoft.Extensions.Hosting;
-using NLog;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Business.Quartz
-{
-    //Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
-    public class LogHostedService
-    {
-        public void LogInstall()
-        {
-            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
-        }
-    }
-}

+ 0 - 34
MicroServices/Business/Business.Application/Quartz/NLogJob.cs

@@ -1,34 +0,0 @@
-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 NLogJob : IJob
-    {
-
-        /// <summary>
-        /// Nlog日志按月分表,需要每天凌晨检查是否存在表,不存在就要新建表,程序启动的时候也要检查一次。类似初始化
-        /// </summary>
-        public readonly LogHostedService _logHostedService;
-
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        public NLogJob(LogHostedService logHostedService)
-        {
-            _logHostedService = logHostedService;
-        }
-        public Task Execute(IJobExecutionContext context)
-        {
-            _logHostedService.LogInstall();
-
-            return Task.CompletedTask;
-        }
-    }
-}

+ 0 - 38
MicroServices/Business/Business.Application/Quartz/ProductionScheduleJob.cs

@@ -1,38 +0,0 @@
-using Quartz;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Business.Quartz
-{
-    /// <summary>
-    /// 排产定时任务
-    /// </summary>
-    public class ProductionScheduleJob : IJob
-    {
-        public readonly ProductionScheduleAppService _appService;
-
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        public ProductionScheduleJob(ProductionScheduleAppService appService)
-        {
-            _appService = appService;
-        }
-
-        /// <summary>
-        /// 执行
-        /// </summary>
-        /// <param name="context"></param>
-        /// <returns></returns>
-        /// <exception cref="NotImplementedException"></exception>
-        public Task Execute(IJobExecutionContext context)
-        {
-            _appService.DoExt();
-
-            return Task.CompletedTask;
-        }
-    }
-}

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

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

+ 0 - 34
MicroServices/Business/Business.Application/Quartz/SyncMySQLDataJob.cs

@@ -1,34 +0,0 @@
-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 SyncMySQLDataJob : IJob
-    {
-
-        /// <summary>
-        /// 同步数据到mongodb服务
-        /// </summary>
-        public readonly SyncMySQLDataAppService _syncDataAppservice;
-
-        /// <summary>
-        /// 构造函数
-        /// </summary>
-        public SyncMySQLDataJob(SyncMySQLDataAppService syncDataAppservice)
-        {
-            _syncDataAppservice = syncDataAppservice;
-        }
-        public Task Execute(IJobExecutionContext context)
-        {
-            _syncDataAppservice.SyncBaseDataToMongoDB();
-
-            return Task.CompletedTask;
-        }
-    }
-}

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

@@ -1,29 +0,0 @@
-using Business.SyncDataManagement;
-using Quartz;
-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;
-        }
-    }
-}

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

@@ -1,33 +0,0 @@
-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();
-        }
-    }
-}

+ 4 - 11
MicroServices/Business/Business.Application/ResourceExamineManagement/CalcBomViewAppService.cs

@@ -1165,11 +1165,10 @@ namespace Business.ResourceExamineManagement
         private SRMPRDto CreateSRMPR(BomChildExamineDto returnlist, long tenantId, long factoryid, long bangId, int orderType, List<ICItemLeadTimeDto> iCItemLeadTimes, List<mo_srm_purchase> supplierList, List<mo_ic_item> planList, DateTime deliveryDate, crm_seorderentry sentrys)
         {
             SRMPRDto sRMPR = new SRMPRDto();
-            var leadTime = iCItemLeadTimes.Find(x => x.item_id == returnlist.item_id);
             var supplier = supplierList.Where(x => x.icitem_id == returnlist.item_id).ToList();//默认取第一个供应商
             var plan = planList.Find(x => x.mysql_id == returnlist.item_id);
             sRMPR.srm_Pr_Main = new List<mo_srm_pr_main>();
-            if (leadTime == null || !supplier.Any() || plan == null)
+            if (!supplier.Any() || plan == null)
             {
                 sRMPR.lastStartTmie = DateTime.Now.AddDays(7);//减去提前期
                 return sRMPR;
@@ -1178,12 +1177,6 @@ namespace Business.ResourceExamineManagement
 
             supplier.ForEach(x =>
             {
-                //提前期随机数,金额随机数
-                leadTime.order_leadtime = plan.order_leadtime;
-                leadTime.transportation_leadtime = plan.transportation_leadtime;
-                leadTime.stock_leadtime = plan.stock_leadtime;
-                leadTime.production_leadtime = plan.production_leadtime;
-
                 x.netpurchase_price = rnd.Next(1, 100);
                 x.taxrate = 0.13m;//固定13%增值税
                 mo_srm_pr_main srm_Pr = new mo_srm_pr_main();
@@ -1209,8 +1202,8 @@ namespace Business.ResourceExamineManagement
                 srm_Pr.pr_ssend_date = DateTime.Now;//系统建议下单日期
                 srm_Pr.pr_sarrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//系统建议到达日期(建议到货日期)
                 srm_Pr.pr_psend_date = DateTime.Now;//计划下单日期
-                srm_Pr.pr_parrive_date = DateTime.Now.AddDays((double)leadTime.order_leadtime).AddDays((double)leadTime.transportation_leadtime);//计划到达日期
-                srm_Pr.pr_rarrive_date = DateTime.Now.AddDays((double)leadTime.order_leadtime).AddDays((double)leadTime.transportation_leadtime);//需求到货日期
+                srm_Pr.pr_parrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//计划到达日期
+                srm_Pr.pr_rarrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//需求到货日期
                 srm_Pr.pr_sysprice = returnlist.lack_qty * x.netpurchase_price * (1 + x.taxrate);//系统价格(含税)
                 srm_Pr.pr_orderprice = returnlist.lack_qty * x.netpurchase_price * (1 + x.taxrate);//订单价格(含税)
                 srm_Pr.pr_price = x.netpurchase_price;//采购净价(不含税)
@@ -1229,7 +1222,7 @@ namespace Business.ResourceExamineManagement
                     srm_Pr.sentry_id = sentrys.Id;
                 }
                 //_srm_pr_main.InsertOne(srm_Pr);
-                decimal? totalLeadTime = leadTime.transportation_leadtime + leadTime.stock_leadtime + leadTime.production_leadtime + leadTime.order_leadtime;
+                decimal? totalLeadTime = plan.transportation_leadtime + plan.stock_leadtime + plan.production_leadtime + plan.order_leadtime;
                 srm_Pr.totalLeadTime= totalLeadTime;
                 srm_Pr.create_time = DateTime.Now;
                 srm_Pr.create_by_name = "admin";

+ 3 - 3
MicroServices/Business/Business.Application/ResourceExamineManagement/ProductExamineAppService.cs

@@ -78,7 +78,7 @@ namespace Business.ResourceExamineManagement
             }
             //获取当前产品的工艺路线:主产线,最后一道工序
             var curRoutingOps = routingOps.Where(p => p.RoutingCode == param.ItemNum && p.ParentOp == 0).OrderByDescending(p => p.Op).ToList();
-            if (curRoutingOps.Count() == 0)
+            if (curRoutingOps.Count == 0)
             {
                 return planEnd;
             }
@@ -91,7 +91,7 @@ namespace Business.ResourceExamineManagement
             }
             //获取产线工作日历
             var curCalendars = calendarWorks.Where(p => p.ProdLine == curProdLine.Line).ToList();
-            if (curCalendars.Count() == 0 || curCalendars.Count() != 7)
+            if (curCalendars.Count == 0 || curCalendars.Count != 7)
             {
                 return planEnd;
             }
@@ -212,7 +212,7 @@ namespace Business.ResourceExamineManagement
                 //获取主线最后一道工序
                 List<PeriodSequenceDet> schedules = new List<PeriodSequenceDet>();
                 var routings = routingOps.Where(p => p.RoutingCode == item.item_number && p.ParentOp == 0).OrderBy(p=>p.Op).ToList();
-                if (routings.Count() != 0)
+                if (routings.Count != 0)
                 {
                     //获取产线
                     var prodLine = prodLines.FirstOrDefault(p => p.Part == item.item_number && p.Op == routings.Last().Op);

+ 54 - 49
MicroServices/Business/Business.Application/Quartz/ProductionScheduleAppService.cs → MicroServices/Business/Business.Application/ResourceExamineManagement/ProductionScheduleAppService.cs

@@ -16,7 +16,7 @@ using System.Transactions;
 using Volo.Abp.Application.Services;
 using Volo.Abp.MultiTenancy;
 
-namespace Business.Quartz
+namespace Business.ResourceExamineManagement
 {
     /// <summary>
     /// 生产排产服务
@@ -121,19 +121,19 @@ namespace Business.Quartz
             ISqlRepository<HolidayMaster> holidayMaster,
             ICurrentTenant currentTenant
             )
-        { 
-            _itemMaster= itemMaster;
-            _workOrdMaster= workOrdMaster;
-            _workOrdDetail= workOrdDetail;
-            _workOrdRouting= workOrdRouting;
+        {
+            _itemMaster = itemMaster;
+            _workOrdMaster = workOrdMaster;
+            _workOrdDetail = workOrdDetail;
+            _workOrdRouting = workOrdRouting;
             _prodLineDetail = prodLineDetail;
             _periodSequenceDet = periodSequenceDet;
-            _scheduleResultOpMaster= scheduleResultOpMaster;
-            _invMaster= invMaster;
-            _shopCalendarWorkCtr= shopCalendarWorkCtr;
-            _qualityLineWorkDetail= qualityLineWorkDetail;
+            _scheduleResultOpMaster = scheduleResultOpMaster;
+            _invMaster = invMaster;
+            _shopCalendarWorkCtr = shopCalendarWorkCtr;
+            _qualityLineWorkDetail = qualityLineWorkDetail;
             _holidayMaster = holidayMaster;
-            _currentTenant= currentTenant;
+            _currentTenant = currentTenant;
         }
         #endregion
 
@@ -153,12 +153,12 @@ namespace Business.Quartz
         /// <returns></returns>
         public async Task DoProductShcedule(List<WorkOrdMaster> workOrds)
         {
-            if (workOrds.Count() == 0)//定时任务调用时,需要获取工单数据
+            if (workOrds.Count == 0)//定时任务调用时,需要获取工单数据
             {
                 //1、获取需要排产的工单:Status为空且IsActive==1
                 workOrds = _workOrdMaster.Select(p => string.IsNullOrEmpty(p.Status) && p.IsActive);
             }
-            if (workOrds.Count() == 0)//没有工单需要排产
+            if (workOrds.Count == 0)//没有工单需要排产
             {
                 return;
             }
@@ -171,11 +171,11 @@ namespace Business.Quartz
             List<ProdLineDetail> prodLines = _prodLineDetail.Select(p => workOrds.Select(m => m.ItemNum).Contains(p.Part) && p.Domain == "1001" && p.IsActive);
             List<string> lines = prodLines.Select(p => p.Line).ToList();
             //获取生产周期数据
-            List<PeriodSequenceDet> dbPeriodSequences = _periodSequenceDet.Select(p=> lines.Contains(p.Line) && p.PlanDate >= earlist && p.Domain == "1001" && p.IsActive);
+            List<PeriodSequenceDet> dbPeriodSequences = _periodSequenceDet.Select(p => lines.Contains(p.Line) && p.PlanDate >= earlist && p.Domain == "1001" && p.IsActive);
             //获取当前日期往后的排产记录数据
             List<ScheduleResultOpMaster> dbSchedules = _scheduleResultOpMaster.Select(p => lines.Contains(p.Line) && p.WorkDate >= earlist && p.Domain == "1001");
             //获取工作日历数据
-            calendars = _shopCalendarWorkCtr.Select(p=>p.Domain == "1001" && p.IsActive);
+            calendars = _shopCalendarWorkCtr.Select(p => p.Domain == "1001" && p.IsActive);
             //获取产线休息记录数据
             qualityLines = _qualityLineWorkDetail.Select(p => p.Domain == "1001" && p.IsActive);
             //获取节假日记录数据
@@ -201,16 +201,16 @@ namespace Business.Quartz
 
                 //工序预处理:确定每层级工序对应的产线
                 List<WorkOrdRoutingDto> routingDtos = ProcPretreatment(item, workOrdRoutings.Where(p => p.WorkOrd == item.WorkOrd).ToList(), prodLines, allResults);
-                
+
                 //排产前的数据校验
-                if (routingDtos.Count() == 0)//没有维护主工序
+                if (routingDtos.Count == 0)//没有维护主工序
                 {
                     //记录排产异常原因
-                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<"+ item.WorkOrd + ">的工序数据维护错误", _currentTenant.Id.ToString());
+                    new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的工序数据维护错误", _currentTenant.Id.ToString());
                     continue;
                 }
                 //校验每层级工序是否都维护了产线
-                if (routingDtos.Exists(p=> string.IsNullOrEmpty(p.Line)))
+                if (routingDtos.Exists(p => string.IsNullOrEmpty(p.Line)))
                 {
                     //记录排产异常原因
                     new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "工单<" + item.WorkOrd + ">的产线数据维护错误", _currentTenant.Id.ToString());
@@ -221,7 +221,7 @@ namespace Business.Quartz
                 foreach (var rut in routingDtos)
                 {
                     var lineCals = calendars.Where(p => p.ProdLine == rut.Line).ToList();
-                    if (lineCals.Select(p=>p.WeekDay).Distinct().Count() !=7)
+                    if (lineCals.Select(p => p.WeekDay).Distinct().Count() != 7)
                     {
                         flag = true;
                         break;
@@ -242,20 +242,21 @@ namespace Business.Quartz
             }
             using (TransactionScope scope = new TransactionScope())
             {
-                try {
+                try
+                {
                     //记录排产数据
                     /*_workOrdMaster.Update(workOrds);*/
                     _periodSequenceDet.Insert(periodSequenceDtls);
                     _scheduleResultOpMaster.Insert(scheduleMasters);
                     scope.Complete();
                 }
-                catch(Exception ex)
+                catch (Exception ex)
                 {
                     new NLogHelper("ProductionScheduleAppService").WriteLog("DoProductShcedule", "记录排产数据失败:" + ex.Message, _currentTenant.Id.ToString());
                     scope.Dispose();
                 }
             }
-            
+
         }
 
         /// <summary>
@@ -265,7 +266,7 @@ namespace Business.Quartz
         /// <param name="routingDtos">每层级工序对应的产线信息,从小到大排序</param>
         /// <param name="periodsDet">生产周期</param>
         /// <param name="scheduleResults">排产结果</param>
-        public void LineSchedule(WorkOrdMaster workOrd,List<WorkOrdRoutingDto> routingDtos,List<PeriodSequenceDet> periodsDet, List<ScheduleResultOpMaster> scheduleResults)
+        public void LineSchedule(WorkOrdMaster workOrd, List<WorkOrdRoutingDto> routingDtos, List<PeriodSequenceDet> periodsDet, List<ScheduleResultOpMaster> scheduleResults)
         {
             //生产周期
             List<PeriodSequenceDet> curSequences = new List<PeriodSequenceDet>();
@@ -273,7 +274,7 @@ namespace Business.Quartz
             List<ScheduleResultOpMaster> curScheduleRsts = new List<ScheduleResultOpMaster>();
             //产线排产开始时间
             List<LineStartDto> lineStarts = new List<LineStartDto>();
-            
+
             //循环产线,排产
             foreach (var item in routingDtos)
             {
@@ -431,8 +432,8 @@ namespace Business.Quartz
         /// <param name="curCalendars"></param>
         /// <param name="curQtyDtls"></param>
         /// <returns></returns>
-        public LineScheduledDto GetScheduledPoint(WorkOrdRoutingDto routingDto,DateTime startTime, List<ShopCalendarWorkCtr> curCalendars, List<QualityLineWorkDetail> curQtyDtls)
-        { 
+        public LineScheduledDto GetScheduledPoint(WorkOrdRoutingDto routingDto, DateTime startTime, List<ShopCalendarWorkCtr> curCalendars, List<QualityLineWorkDetail> curQtyDtls)
+        {
             LineScheduledDto scheduledDto = new LineScheduledDto();
             //当天排产开始时间
             scheduledDto.StartTime = startTime;
@@ -503,12 +504,13 @@ namespace Business.Quartz
                     //获取下一个工作日开始时间
                     actStart = GetNextWorkDay(weekDay, startTime, curCalendars);
                 }
-                else {//开始时间位于当天的休息时间段
+                else
+                {//开始时间位于当天的休息时间段
                     foreach (var item in workPoints)
                     {
                         //获取下一个时间段
-                        var next = workPoints.First(p=>p.Level == item.Level + 1);
-                        if (item.EndPoint < startTime &&  startTime < next.StartPoint)
+                        var next = workPoints.First(p => p.Level == item.Level + 1);
+                        if (item.EndPoint < startTime && startTime < next.StartPoint)
                         {
                             actStart = next.StartPoint;
                             break;
@@ -601,7 +603,7 @@ namespace Business.Quartz
         /// <param name="curCalendars">当前产线工作日历</param>
         /// <param name="curQtyDtls">当前产线休息记录</param>
         /// <returns></returns>
-        public DateTime DealChildStartTime(DateTime startTime,decimal setupTime, List<ShopCalendarWorkCtr> curCalendars, List<QualityLineWorkDetail> curQtyDtls)
+        public DateTime DealChildStartTime(DateTime startTime, decimal setupTime, List<ShopCalendarWorkCtr> curCalendars, List<QualityLineWorkDetail> curQtyDtls)
         {
             //提前期转换成分钟
             decimal needMinute = setupTime * 60;
@@ -629,7 +631,7 @@ namespace Business.Quartz
             //剩余提前期
             needMinute -= curMins;
             //获取前层级时间段
-            var prePoints = workPoints.Where(p => p.Level < curPoint.Level).OrderByDescending(p=>p.Level).ToList();
+            var prePoints = workPoints.Where(p => p.Level < curPoint.Level).OrderByDescending(p => p.Level).ToList();
             bool flag = true;//标志位
             foreach (var item in prePoints)
             {
@@ -654,7 +656,7 @@ namespace Business.Quartz
                 //获取前一个工作日
                 perStartTime = GetPreWorkDay(perStartTime, curCalendars);
                 //获取前一个工作日的工作时间段数据,倒序排
-                workPoints = DealWorkDayToLevels(perStartTime, shopCal, curQtyDtls).OrderByDescending(p=>p.Level).ToList();
+                workPoints = DealWorkDayToLevels(perStartTime, shopCal, curQtyDtls).OrderByDescending(p => p.Level).ToList();
                 //当天的工作时长(分钟)
                 decimal sumWorkMins = workPoints.Sum(p => p.WorkMinutes);
                 if (sumWorkMins >= needMinute)//当天可用提前期满足
@@ -671,7 +673,8 @@ namespace Business.Quartz
                     }
                     flag = false;
                 }
-                else {
+                else
+                {
                     //当天可用提前期不满足
                     needMinute -= sumWorkMins;
                 }
@@ -695,7 +698,7 @@ namespace Business.Quartz
             DateTime nextDate = startTime.Date.AddDays(1);
             //下一天是周几
             int nextWeekDay = (weekDay + 1) % 7;
-            var calendar = curCalendars.FirstOrDefault(p=>p.WeekDay == nextWeekDay);
+            var calendar = curCalendars.FirstOrDefault(p => p.WeekDay == nextWeekDay);
             string strStart = calendar.ShiftsStart1.ToString("0.00").Replace(".", ":");
             //判断下一天是否是工作日
             if (nextWeekDay == 0 || nextWeekDay == 6)//下一天是周六或者周日,需要判断是否调班,需要加班
@@ -773,7 +776,7 @@ namespace Business.Quartz
             int weekDay = (int)startTime.DayOfWeek;
             //计算当天的开工时间点,停工时间点
             string strStart = shopCal.ShiftsStart1.ToString("0.00").Replace(".", ":");
-            DateTime dayStartPoint = Convert.ToDateTime(date + " "+ strStart);
+            DateTime dayStartPoint = Convert.ToDateTime(date + " " + strStart);
             DateTime dayEndPoint = dayStartPoint.AddHours(Convert.ToDouble(shopCal.ShiftsHours1));
             //工作时间段
             List<LineWorkPointDto> workPoints = new List<LineWorkPointDto>();
@@ -787,7 +790,7 @@ namespace Business.Quartz
             foreach (var item in curQtyDtls)
             {
                 DateTime endPoint = Convert.ToDateTime(date + " " + item.RestTimePoint);
-                dto.EndPoint= endPoint;
+                dto.EndPoint = endPoint;
                 span = dto.EndPoint - dto.StartPoint;
                 dto.WorkMinutes = (decimal)span.TotalMinutes;
                 workPoints.Add(dto);
@@ -814,14 +817,14 @@ namespace Business.Quartz
         /// <param name="prodLines">产线</param>
         /// <param name="schedules">当前工单对应产品的排产记录</param>
         /// <returns></returns>
-        public List<WorkOrdRoutingDto> ProcPretreatment(WorkOrdMaster workOrd,List<WorkOrdRouting> woRuntings, List<ProdLineDetail> prodLines, List<ScheduleResultOpMaster> schedules)
+        public List<WorkOrdRoutingDto> ProcPretreatment(WorkOrdMaster workOrd, List<WorkOrdRouting> woRuntings, List<ProdLineDetail> prodLines, List<ScheduleResultOpMaster> schedules)
         {
             List<WorkOrdRoutingDto> routingDtos = new List<WorkOrdRoutingDto>();
             //当前工单计划开始时间(默认加两天)
             DateTime planStart = workOrd.OrdDate.GetValueOrDefault().AddDays(2);
             //取主工序(第一层级工序)
-            var firsts = woRuntings.Where(p =>p.ParentOp == 0).OrderByDescending(p => p.OP).ToList();
-            if (firsts.Count() == 0)
+            var firsts = woRuntings.Where(p => p.ParentOp == 0).OrderByDescending(p => p.OP).ToList();
+            if (firsts.Count == 0)
             {
                 return routingDtos;
             }
@@ -834,19 +837,20 @@ namespace Business.Quartz
             dto.ChdParentOps = new List<int>();
             //获取当前层级工序中有子级的工序集合
             var childs = woRuntings.Where(p => firsts.Select(m => m.OP).Contains(p.ParentOp)).Select(m => m.ParentOp).Distinct().ToList();
-            if (childs.Count() > 0)
+            if (childs.Count > 0)
             {
                 dto.ChdParentOps = childs;
             }
             //主工序对应的产线(目前只考虑一个产品对应一条产线的情况)
             var line = prodLines.Where(p => p.Part == lastOp.ItemNum && p.Op == lastOp.OP).FirstOrDefault();
-            if (line != null) {
+            if (line != null)
+            {
                 dto.Line = line.Line;
                 dto.Rate = line.Rate;
                 dto.SetupTime = 0;
                 //获取产线占用结束时间
                 var schedule = schedules.Where(p => p.Line == line.Line).OrderByDescending(p => p.WorkEndTime).FirstOrDefault();
-                dto.StartTime = schedule == null ? planStart : (schedule.WorkEndTime <= planStart ? planStart : schedule.WorkEndTime);
+                dto.StartTime = schedule == null ? planStart : schedule.WorkEndTime <= planStart ? planStart : schedule.WorkEndTime;
             }
             routingDtos.Add(dto);
 
@@ -867,8 +871,8 @@ namespace Business.Quartz
         public void RecursionProc(List<WorkOrdRouting> woRuntings, List<WorkOrdRouting> preLevels, int level, List<WorkOrdRoutingDto> routingDtos, List<ProdLineDetail> prodLines)
         {
             //获取当前层级工序
-            var curLevels = woRuntings.Where(p => preLevels.Select(m=>m.OP).Contains(p.ParentOp)).ToList();
-            if (curLevels.Count() == 0)
+            var curLevels = woRuntings.Where(p => preLevels.Select(m => m.OP).Contains(p.ParentOp)).ToList();
+            if (curLevels.Count == 0)
             {
                 return;
             }
@@ -877,8 +881,9 @@ namespace Business.Quartz
             foreach (var item in parentOps)
             {
                 var dto = new WorkOrdRoutingDto();
-                var lastOp = curLevels.Where(p=>p.ParentOp == item).OrderByDescending(m=>m.OP).FirstOrDefault();
-                if (lastOp == null){
+                var lastOp = curLevels.Where(p => p.ParentOp == item).OrderByDescending(m => m.OP).FirstOrDefault();
+                if (lastOp == null)
+                {
                     continue;
                 }
                 dto.Op = lastOp.OP;
@@ -887,7 +892,7 @@ namespace Business.Quartz
                 dto.ChdParentOps = new List<int>();
                 //获取当前层级工序中有子级的工序集合
                 var childs = woRuntings.Where(p => curLevels.Where(p => p.ParentOp == item).Select(m => m.OP).Contains(p.ParentOp)).Select(m => m.ParentOp).Distinct().ToList();
-                if (childs.Count() > 0)
+                if (childs.Count > 0)
                 {
                     dto.ChdParentOps = childs;
                 }
@@ -902,7 +907,7 @@ namespace Business.Quartz
                 routingDtos.Add(dto);
             }
             //递归
-            RecursionProc(woRuntings, curLevels, level + 1, routingDtos,prodLines);
+            RecursionProc(woRuntings, curLevels, level + 1, routingDtos, prodLines);
         }
     }
 }

+ 147 - 47
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -15,7 +15,6 @@ using Business.MongoModel.Production;
 using Business.MongoModel.SRM;
 using Business.MongoModel.Tech;
 using Business.PriorityManagement;
-using Business.Quartz;
 using Business.ResourceExamineManagement.Dto;
 using EFCore.BulkExtensions;
 using Microsoft.EntityFrameworkCore;
@@ -543,7 +542,7 @@ namespace Business.ResourceExamineManagement
                 }
                 
                 //获取订单行数据
-                sentrys = await _mysql_crm_seorderentry.GetListAsync(p => input.sorderId.Contains(p.seorder_id.GetValueOrDefault()) && !p.IsDeleted);
+                sentrys = await _mysql_crm_seorderentry.GetListAsync(p => input.sorderId.Contains(p.seorder_id.GetValueOrDefault()) && (p.progress=="1" || p.progress == "2") && !p.IsDeleted);
                 if (!sentrys.Any())
                 {
                     new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "订单行数据不存在", _currentTenant.Id.ToString());
@@ -553,7 +552,7 @@ namespace Business.ResourceExamineManagement
             }
             else {
                 //获取订单行数据
-                sentrys = await _mysql_crm_seorderentry.GetListAsync(p => input.sorderId.Contains(p.Id) && !p.IsDeleted);
+                sentrys = await _mysql_crm_seorderentry.GetListAsync(p => input.sorderId.Contains(p.Id) && (p.progress == "1" || p.progress == "2") && !p.IsDeleted);
                 if (!sentrys.Any())
                 {
                     new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "订单行数据不存在", _currentTenant.Id.ToString());
@@ -934,33 +933,33 @@ namespace Business.ResourceExamineManagement
         }
 
         //PR手动合并
-        public string PrMerge(string ids)
+        public async Task<string> PrMerge(string ids)
         {
             //物料、供应商为相同才允许合并。
             var idList = AnalysisIdList(ids);
             List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => idList.Contains(s.Id)).Result;
             if (prlist.Where(s => s.state == 0).Count() > 0)
             {
-                return "所选包含已关闭采购申请,请重新选择。";
+                return JsonConvert.SerializeObject("所选包含已关闭采购申请,请重新选择。");
             }
             if (prlist.Where(s => s.state == 2).Count() > 0)
             {
-                return "所选包含已提交评审采购申请,请重新选择。";
+                return JsonConvert.SerializeObject("所选包含已提交评审采购申请,请重新选择。");
             }
             if (prlist.Where(s => s.state == 4).Count() > 0)
             {
-                return "所选包含已评审通过采购申请,请重新选择。";
+                return JsonConvert.SerializeObject("所选包含已评审通过采购申请,请重新选择。");
             }
             if (prlist.Any())
             {
                 var list = prlist.GroupBy(s => new { s.icitem_id, s.pr_purchaseid });
                 if (list.Count() > 1)
                 {
-                    return "所选行的物料编码,供应商名称必须相同";
+                    return JsonConvert.SerializeObject("所选行的物料编码,供应商名称必须相同");
                 }
             }
             else {
-                return "所选采购申请单未找到,请刷新界面重新操作。";
+                return JsonConvert.SerializeObject("所选采购申请单未找到,请刷新界面重新操作。");
             }
 
             srm_pr_main srm_Pr = help.DeepCopy(prlist[0]);
@@ -972,11 +971,11 @@ namespace Business.ResourceExamineManagement
                 srm_Pr.pr_mono = mes_morder.morder_no;//关联工单号
                 srm_Pr.entity_id = 1;//工单行号
             }*/
-            /*srm_Pr.pr_purchaseid = prlist[0].pr_purchaseid;//供应商id  
+            srm_Pr.pr_purchaseid = prlist[0].pr_purchaseid;//供应商id  
             srm_Pr.pr_purchasenumber = prlist[0].pr_purchasenumber;//供应商编码
             srm_Pr.pr_purchasename = prlist[0].pr_purchasename;//供应商名称
             srm_Pr.pr_purchaser = prlist[0].pr_purchaser;//采购员
-            srm_Pr.pr_purchaser_num = "";//采购员工号(采购信息表)*/
+            srm_Pr.pr_purchaser_num = "";//采购员工号(采购信息表)*//*
             srm_Pr.pr_rqty = prlist.Sum(s => s.pr_rqty);//需求数量
             srm_Pr.pr_aqty = prlist.Sum(s => s.pr_aqty);//申请数量
             srm_Pr.pr_sqty = prlist.Sum(s => s.pr_sqty);//建议数量
@@ -1007,16 +1006,16 @@ namespace Business.ResourceExamineManagement
                 {
                     _businessDbContext.BulkUpdate(prlist);
                     _businessDbContext.BulkInsert(new List<srm_pr_main> { srm_Pr });
-                    unitOfWork.CompleteAsync();
+                    await unitOfWork.CompleteAsync();
                 }
                 catch (Exception e)
                 {
                     new NLogHelper("ResourceExamineAppService").WriteLog("PrMerge", "采购申请单合并数据更新失败:" + e.Message, _currentTenant.Id.ToString());
                     unitOfWork.Dispose();
-                    return e.Message;
+                    return JsonConvert.SerializeObject(e.Message);
                 }
             }
-            return "ok";
+            return JsonConvert.SerializeObject("ok");
         }
 
         //PR自动合并
@@ -1043,11 +1042,13 @@ namespace Business.ResourceExamineManagement
             {
                 bool bl = pr.sentry_id == null ? true : false;
                 //找到是否生成了新的PR
-                var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id && (s.sentry_id == null) == bl);
+                //var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id && (s.sentry_id == null) == bl);
+                var newPr = insetPrList.Find(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id);
                 if (newPr == null)
                 {
                     //有多条才进行合并
-                    var ilist = prlist.Where(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id && (s.sentry_id == null) == bl).ToList();
+                    //var ilist = prlist.Where(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id && (s.sentry_id == null) == bl).ToList();
+                    var ilist = prlist.Where(s => s.pr_purchaseid == pr.pr_purchaseid && s.icitem_id == pr.icitem_id).ToList();
                     if (ilist.Count > 1)
                     {
                         var icitem = ic_Items.Find(s => s.Id == pr.icitem_id);
@@ -1063,6 +1064,7 @@ namespace Business.ResourceExamineManagement
                         decimal day = 0;
                         if (icitem != null)
                         {
+                            //目前只加入了下单前置(天)
                             day += icitem.order_leadtime.GetValueOrDefault();
                         }
                         newPr.pr_rarrive_date = starttime;//需求到货日期
@@ -1075,11 +1077,12 @@ namespace Business.ResourceExamineManagement
                         newPr.pr_orderprice = newPr.pr_rqty * pr.pr_price * (1 + pr.pr_rate);//订单价格(含税)
                         ilist.ForEach(s => { s.refer_pr_billno = newPr.pr_billno; });
                         insetPrList.Add(newPr);
+                        ilist.ForEach(s => { s.state = 0; });
                         updatePrList.AddRange(ilist);
                     }
                 }
             }
-            updatePrList.ForEach(s => { s.state = 0; });
+            
             #region 此逻辑是处理按每周几送货实现,先屏蔽
             /*foreach (var pr in moPrlist)
             {
@@ -1153,6 +1156,7 @@ namespace Business.ResourceExamineManagement
             }
         }
 
+
         /// <summary>
         /// 解析按周频率送货方式
         /// </summary>
@@ -1224,29 +1228,31 @@ namespace Business.ResourceExamineManagement
             return weekOfYear;
         }*/
 
-        //PR动审核
-        public async void PrApprove()
+        //PR动审核
+        public async Task<string> PrAutoApprove()
         {
             //直接按间隔多少天一次来处理数据,定时任务按周四来考虑。
             DateTime toTime = new DateTime(2023, 7, 6);
             DateTime starttime = toTime.AddDays(1);
             DateTime endtime = toTime.AddDays(8);
-            List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => s.pr_rarrive_date >= starttime && s.pr_rarrive_date <= endtime && (s.state == 1 || s.state == 3)).Result;
-            
+            List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => s.pr_rarrive_date >= starttime && s.pr_rarrive_date <= endtime && (s.state == 1|| s.state == 2 || s.state == 3)).Result;
+
             if (prlist.Any())
             {
-                List<srm_supplier> itemsupplierList = new List<srm_supplier>();
                 List<srm_purchase> purchaselist = _mysql_srm_purchase.GetListAsync(s => prlist.Select(c => c.icitem_id).Contains(s.icitem_id) && prlist.Select(c => c.pr_purchaseid).Contains(s.supplier_id)).Result;
+                List<srm_supplier> itemsupplierList = _mysql_srm_supplier.GetListAsync(s => prlist.Select(c => c.pr_purchaseid).Contains(s.Id)).Result;
                 List<ic_item> ic_Items = _mysql_ic_item.GetListAsync(s => prlist.Select(c => c.icitem_id).Contains(s.Id)).Result;
                 PoActionListDto poaction = new PoActionListDto();
+                param.tenantId = prlist[0].tenant_id;
+                param.factoryId = prlist[0].factory_id.GetValueOrDefault();
                 AutoCreatePOFromPR(prlist, ic_Items, itemsupplierList, purchaselist, poaction);
-
                 using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
                 {
                     try
                     {
                         if (poaction.poMain.Any())
                         {
+                            _businessDbContext.BulkUpdate(prlist);
                             _businessDbContext.BulkInsert(poaction.poMain);
                         }
                         if (poaction.polist.Any())
@@ -1275,12 +1281,95 @@ namespace Business.ResourceExamineManagement
                     catch (Exception e)
                     {
                         unitOfWork.Dispose();
-                        new NLogHelper("ResourceExamineAppService").WriteLog("OrderKittingCheck", "工单检查数据更新失败:" + e.Message, _currentTenant.Id.ToString());
+                        new NLogHelper("ResourceExamineAppService").WriteLog("PrApprove", "采购申请单合并失败:" + e.Message, _currentTenant.Id.ToString());
+                        return JsonConvert.SerializeObject("合并失败,请联系管理员。");
+                    }
+                }
+                return JsonConvert.SerializeObject("ok");
+            }
+            else
+            {
+                return JsonConvert.SerializeObject("没有需要审核的采购申请单。");
+            }
+        }
+
+        /// <summary>
+        /// //PR手动审核
+        /// </summary>
+        /// <param name="ids"></param>
+        /// <returns></returns>
+        public async Task<string> PrApprove(string ids)
+        {
+            //物料、供应商为相同才允许合并。
+            var idList = AnalysisIdList(ids);
+            List<srm_pr_main> prlist = _mysql_srm_pr_main.GetListAsync(s => idList.Contains(s.Id)).Result;
+            if (!prlist.Any())
+            {
+                return JsonConvert.SerializeObject("所选采购申请单未找到,请刷新界面重新操作。");
+            }
+            if (prlist.Where(s => s.state == 0).Count() > 0)
+            {
+                return JsonConvert.SerializeObject("所选包含已关闭采购申请,请重新选择。");
+            }
+            if (prlist.Where(s => s.state == 3).Count() > 0)
+            {
+                return JsonConvert.SerializeObject("所选包含评审未通过采购申请,请重新选择。");
+            }
+            List<srm_purchase> purchaselist = _mysql_srm_purchase.GetListAsync(s => prlist.Select(c => c.icitem_id).Contains(s.icitem_id) && prlist.Select(c => c.pr_purchaseid).Contains(s.supplier_id)).Result;
+            List<srm_supplier> itemsupplierList = _mysql_srm_supplier.GetListAsync(s => prlist.Select(c => c.pr_purchaseid).Contains(s.Id)).Result;
+            var purclist = purchaselist.GroupBy(s => new { s.supplier_type, s.supplier_id });
+            if (purclist.Count() > 1)
+            {
+                return JsonConvert.SerializeObject("采购申请单的采购类别必须相同。");
+            }
+            List<ic_item> ic_Items = _mysql_ic_item.GetListAsync(s => prlist.Select(c => c.icitem_id).Contains(s.Id)).Result;
+            PoActionListDto poaction = new PoActionListDto();
+            param.tenantId = prlist[0].tenant_id;
+            param.factoryId = prlist[0].factory_id.GetValueOrDefault();
+            AutoCreatePOFromPR(prlist, ic_Items, itemsupplierList, purchaselist, poaction);
+            using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
+            {
+                try
+                {
+                    if (poaction.poMain.Any())
+                    {
+                        _businessDbContext.BulkUpdate(prlist);
+                        _businessDbContext.BulkInsert(poaction.poMain);
                     }
+                    if (poaction.polist.Any())
+                    {
+                        _businessDbContext.BulkInsert(poaction.polist);
+                    }
+                    if (poaction.poOccupiesList.Any())
+                    {
+                        _businessDbContext.BulkInsert(poaction.poOccupiesList);
+                    }
+
+                    if (poaction.poMasterList.Any())
+                    {
+                        _purOrdMaster.Insert(poaction.poMasterList);
+                        //快开平台用自增列RecId关联,所以需要插入后再查给明细表赋相应的值
+                        List<string> nbrs = poaction.poMasterList.Select(a => a.PurOrd).ToList();
+                        var nbrList = _purOrdMaster.Select(a => a.Domain == "1001" && nbrs.Contains(a.PurOrd));
+                        poaction.poDetailList.ForEach(c =>
+                        {
+                            c.PurOrdRecID = nbrList.Where(a => a.PurOrd == c.PurOrd).First().RecID;
+                        });
+                        _purOrdDetail.Insert(poaction.poDetailList);
+                    }
+                    await unitOfWork.CompleteAsync();
+                }
+                catch (Exception e)
+                {
+                    unitOfWork.Dispose();
+                    new NLogHelper("ResourceExamineAppService").WriteLog("PrApprove", "采购申请单合并失败:" + e.Message, _currentTenant.Id.ToString());
+                    return JsonConvert.SerializeObject("合并失败,请联系管理员。");
                 }
             }
+            return JsonConvert.SerializeObject("ok");
         }
 
+
         private List<long> AnalysisIdList(string ids)
         {
             if (string.IsNullOrEmpty(ids))
@@ -1615,6 +1704,8 @@ namespace Business.ResourceExamineManagement
         /// <returns></returns>
         public async Task DbSnapShot(long tenantId, long factoryId, long bangid,List<b_bom_pretreatment> pretreatments)
         {
+            //TODO:申老师明确后续需要调整 根据需要使用的字段,来同步表数据。
+            
             //同步物料库存数据  根据预处理,来只找出部分数据同步。
             List<long> itemIds = pretreatments.Select(s => s.item_id.GetValueOrDefault()).ToList();
             //var icitemStokc = _mysql_ic_item_stock.GetListAsync(p => p.tenant_id == tenantId && p.factory_id == factoryId).Result;
@@ -1847,18 +1938,23 @@ namespace Business.ResourceExamineManagement
             //此逻辑已经在PR按周合并了。这一块直接转PO_list,然后根据此类型,再生成PO
             foreach (var item in list)
             {
-                int type = item.sentry_id == null ? 1 : 0;
                 var pur = purchaselist.Find(s => s.supplier_id == item.pr_purchaseid && s.icitem_id == item.icitem_id);
-                POGroupDto poDto = pOGroupDtos.Find(s => s.supplier_type == pur.supplier_type && s.Type == type && s.erp_cls == item.pr_type.GetValueOrDefault());
+                if (pur == null)
+                {
+                    //无货源清单的PR不处理
+                    continue;
+                }
+                POGroupDto poDto = pOGroupDtos.Find(s => s.supplier_type == pur.supplier_type && s.supplier_id == item.pr_purchaseid);
                 if (poDto == null)
                 {
                     poDto = new POGroupDto();
-                    poDto.Type = type;
-                    poDto.erp_cls = item.pr_type.GetValueOrDefault();//委外  外购
+                    poDto.supplier_id = item.pr_purchaseid.GetValueOrDefault();
                     poDto.supplier_type = pur.supplier_type;
                     poDto.polist = new List<srm_po_list>();
                     pOGroupDtos.Add(poDto);
                 }
+                item.state = 0;
+
                 srm_po_list podetail = new srm_po_list();
                 podetail.GenerateNewId(help.NextId());
                 podetail.pr_id = item.Id;
@@ -1902,6 +1998,7 @@ namespace Business.ResourceExamineManagement
                 po_Main.state = 0;
                 po_Main.po_note = "";
                 po_Main.po_order_type = 1;
+                po_Main.po_total = 0;
                 po_Main.currency = pr.currencytype;
                 po_Main.bill_type = poType;
                 po_Main.supplier_id = pr.pr_purchaseid;
@@ -1930,25 +2027,28 @@ namespace Business.ResourceExamineManagement
                     {
                         clist.ForEach(c =>
                         {
-                            srm_po_occupy srm_Po_Occupy = new srm_po_occupy();
-                            srm_Po_Occupy.GenerateNewId(help.NextId());
-                            //srm_Po_Occupy.bang_id = bangid;
-                            srm_Po_Occupy.morder_mo = c.pr_mono;
-                            srm_Po_Occupy.qty = c.pr_aqty;
-                            srm_Po_Occupy.eid = c.sentry_id;
-                            srm_Po_Occupy.polist_id = p.Id;
-                            srm_Po_Occupy.polist_row = p.polist_row;
-                            srm_Po_Occupy.type = MorderEnum.Zyjc_Type;//TODO:类型未知
-                            srm_Po_Occupy.stime = p.create_time;
-                            srm_Po_Occupy.etime = p.rarrdate;
-                            srm_Po_Occupy.state = 1;
-                            srm_Po_Occupy.tenant_id = param.tenantId;//取销售子表企业ID
-                            srm_Po_Occupy.factory_id = param.factoryId;
-                            srm_Po_Occupy.create_time = DateTime.Now;
-                            srm_Po_Occupy.create_by_name = "admin";
-                            srm_Po_Occupy.update_time = DateTime.Now;
-                            srm_Po_Occupy.update_by_name = "admin";
-                            poaction.poOccupiesList.Add(srm_Po_Occupy);
+                            if (!string.IsNullOrEmpty(c.pr_mono))
+                            {
+                                srm_po_occupy srm_Po_Occupy = new srm_po_occupy();
+                                srm_Po_Occupy.GenerateNewId(help.NextId());
+                                //srm_Po_Occupy.bang_id = bangid;
+                                srm_Po_Occupy.morder_mo = c.pr_mono;
+                                srm_Po_Occupy.qty = c.pr_aqty;
+                                srm_Po_Occupy.eid = c.sentry_id;
+                                srm_Po_Occupy.polist_id = p.Id;
+                                srm_Po_Occupy.polist_row = p.polist_row;
+                                srm_Po_Occupy.type = MorderEnum.Zyjc_Type;//TODO:类型未知
+                                srm_Po_Occupy.stime = p.create_time;
+                                srm_Po_Occupy.etime = p.rarrdate;
+                                srm_Po_Occupy.state = 1;
+                                srm_Po_Occupy.tenant_id = param.tenantId;//取销售子表企业ID
+                                srm_Po_Occupy.factory_id = param.factoryId;
+                                srm_Po_Occupy.create_time = DateTime.Now;
+                                srm_Po_Occupy.create_by_name = "admin";
+                                srm_Po_Occupy.update_time = DateTime.Now;
+                                srm_Po_Occupy.update_by_name = "admin";
+                                poaction.poOccupiesList.Add(srm_Po_Occupy);
+                            }
                         });
                     }
                     

+ 1 - 1
MicroServices/Business/Business.Application/SaleForecastManagement/MonthlyCapacityLoadAppService.cs

@@ -162,7 +162,7 @@ namespace Business.SaleForecastManagement
                 var curLines = lines.Where(p=>p.Part == std.ItemNumber).OrderBy(p => p.Line).ToList();
                 //过滤产线
                 var distLines = curLines.Select(p => p.Line).Distinct().ToList();
-                if (distLines.Count() == 0)
+                if (distLines.Count == 0)
                 {
                     new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("CapacityAnalysis", "物料【" + std.ItemNumber + "】没有维护产线数据", _currentTenant.Id.ToString());
                     return "NO|物料【" + std.ItemNumber + "】没有维护产线数据,请维护后再发布!";

+ 1061 - 0
MicroServices/Business/Business.Application/SystemJobManagement/SystemJobAppService.cs

@@ -0,0 +1,1061 @@
+using Abp.Application.Services;
+using Abp.Dependency;
+using Business.Business.Dto;
+using Business.Core.MongoDBHelper;
+using Business.Core.Utilities;
+using Business.Dto;
+using Business.EntityFrameworkCore;
+using Business.EntityFrameworkCore.SqlRepositories;
+using Business.Model.MES.IC;
+using Business.Model.Production;
+using Business.Model.Sale;
+using Business.Model.SRM;
+using Business.Model.Tech;
+using Business.MongoModel.MES.IC;
+using Business.MongoModel.SRM;
+using Business.MongoModel.Tech;
+using Business.ResourceExamineManagement;
+using Business.SystemJob;
+using EFCore.BulkExtensions;
+using NLog;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Transactions;
+using Volo.Abp.Domain.Repositories;
+using Volo.Abp.MultiTenancy;
+
+namespace Business.SystemJobManagement
+{
+    public class SystemJobAppService : ApplicationService, ISystemJobAppService
+    {
+        /// <summary>
+        /// 物料bom
+        /// </summary>
+        private IRepository<ic_bom, long> _mysql_ic_bom;
+        private readonly IMongoDB<mo_ic_bom> _ic_bom;
+
+        /// <summary>
+        /// 物料bom子表
+        /// </summary>
+        private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
+        private readonly IMongoDB<mo_ic_bom_child> _ic_bom_child;
+
+        /// <summary>
+        /// 物料
+        /// </summary>
+        private IRepository<ic_item, long> _mysql_ic_item;
+        private readonly IMongoDB<mo_ic_item> _ic_item;
+
+        /// <summary>
+        /// 供应商
+        /// </summary>
+        private IRepository<srm_supplier, long> _mysql_srm_supplier;
+        private readonly IMongoDB<mo_srm_supplier> _srm_supplier;
+
+        /// <summary>
+        /// 物料采购报价单
+        /// </summary>
+        private IRepository<srm_purchase, long> _mysql_srm_purchase;
+        private readonly IMongoDB<mo_srm_purchase> _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;
+
+        /// <summary>
+        /// 替代群组
+        /// </summary>
+        private readonly IMongoDB<mo_ic_substitute> _ic_substitute;
+        private IRepository<ic_substitute, long> _mysql_ic_substitute;
+
+        /// <summary>
+        /// 物料替代多群组
+        /// </summary>
+        private readonly IMongoDB<mo_ic_substitute_group> _ic_substitute_group;
+        private IRepository<ic_substitute_group, long> _mysql_ic_substitute_group;
+
+        /// <summary>
+        /// 物料替代多群组明细
+        /// </summary>
+        private readonly IMongoDB<mo_ic_substitute_group_detail> _ic_substitute_group_detail;
+        private IRepository<ic_substitute_group_detail, long> _mysql_ic_substitute_group_detail;
+
+        /// <summary>
+        /// 工艺路径
+        /// </summary>
+        private readonly IMongoDB<mo_mes_technique> _mes_technique;
+        private IRepository<mes_technique, long> _mysql_mes_technique;
+
+        /// <summary>
+        /// 工序
+        /// </summary>
+        private readonly IMongoDB<mo_mes_process> _mes_process;
+        private IRepository<mes_process, long> _mysql_mes_process;
+
+        /// <summary>
+        /// 工艺路径关联工序
+        /// </summary>
+        private readonly IMongoDB<mo_mes_tech_process> _mes_tech_process;
+        private IRepository<mes_tech_process, long> _mysql_mes_tech_process;
+
+
+
+        /// <summary>
+        /// 工单
+        /// </summary>
+        private ISqlRepository<WorkOrdMaster> _workOrdMaster;
+
+        /// <summary>
+        /// 工单物料明细
+        /// </summary>
+        private ISqlRepository<WorkOrdDetail> _workOrdDetail;
+
+        /// <summary>
+        /// 工单工艺路线明细
+        /// </summary>
+        private ISqlRepository<WorkOrdRouting> _workOrdRouting;
+
+        /// <summary>
+        /// 库存主数据
+        /// </summary>
+        private ISqlRepository<InvMaster> _invMaster;
+
+        /// <summary>
+        /// 生产线明细
+        /// </summary>
+        private ISqlRepository<ProdLineDetail> _prodLineDetail;
+
+        /// <summary>
+        /// 生产周期明细
+        /// </summary>
+        private ISqlRepository<PeriodSequenceDet> _periodSequenceDet;
+
+        /// <summary>
+        /// 排产结果明细
+        /// </summary>
+        private ISqlRepository<ScheduleResultOpMaster> _scheduleResultOpMaster;
+
+        /// <summary>
+        /// 工作日历数据
+        /// </summary>
+        private ISqlRepository<ShopCalendarWorkCtr> _shopCalendarWorkCtr;
+
+        /// <summary>
+        /// 产线休息时间记录表
+        /// </summary>
+        private ISqlRepository<QualityLineWorkDetail> _qualityLineWorkDetail;
+
+        /// <summary>
+        /// 节假日记录表
+        /// </summary>
+        private ISqlRepository<HolidayMaster> _holidayMaster;
+
+
+        private readonly ICurrentTenant _currentTenant;
+
+        /// <summary>
+        /// 工作日历数据
+        /// </summary>
+        private List<ShopCalendarWorkCtr> calendars;
+
+        /// <summary>
+        /// 产线休息记录数据
+        /// </summary>
+        private List<QualityLineWorkDetail> qualityLines;
+
+        /// <summary>
+        /// 节假日记录数据
+        /// </summary>
+        private List<HolidayMaster> holidays;
+
+        /// <summary>
+        /// 生产排产
+        /// </summary>
+        private readonly ProductionScheduleAppService _productionScheduleAppService;
+
+        public SystemJobAppService(
+         IRepository<ic_bom, long> mysql_ic_bom,
+         IRepository<ic_bom_child, long> mysql_ic_bom_child,
+         IRepository<ic_item, long> mysql_ic_item,
+         IRepository<srm_supplier, long> mysql_srm_supplier,
+         IRepository<srm_purchase, long> mysql_srm_purchase,
+         IRepository<crm_customer, long> mysql_crm_customer,
+         IRepository<crm_seorder, long> mysql_crm_seorder,
+         IRepository<crm_seorderentry, long> mysql_crm_seorderentry,
+         IRepository<ic_substitute, long> mysql_ic_substitute,
+         IRepository<ic_substitute_group, long> mysql_ic_substitute_group,
+         IRepository<ic_substitute_group_detail, long> mysql_ic_substitute_group_detail,
+         IRepository<mes_technique, long> mysql_mes_technique,
+         IRepository<mes_process, long> mysql_mes_process,
+         IRepository<mes_tech_process, long> mysql_mes_tech_process,
+         ISqlRepository<CustMaster> custMaster,
+         ISqlRepository<SuppMaster> suppMaster,
+         ISqlRepository<ConsigneeAddressMaster> consigneeAddressMaster,
+         ISqlRepository<ItemMaster> itemMaster,
+         ISqlRepository<ProductStructureMaster> productStructureMaster,
+         ISqlRepository<WorkOrdMaster> workOrdMaster,
+         ISqlRepository<WorkOrdDetail> workOrdDetail,
+        ISqlRepository<WorkOrdRouting> workOrdRouting,
+        ISqlRepository<ProdLineDetail> prodLineDetail,
+        ISqlRepository<PeriodSequenceDet> periodSequenceDet,
+        ISqlRepository<ScheduleResultOpMaster> scheduleResultOpMaster,
+        ISqlRepository<InvMaster> invMaster,
+        ISqlRepository<ShopCalendarWorkCtr> shopCalendarWorkCtr,
+        ISqlRepository<QualityLineWorkDetail> qualityLineWorkDetail,
+        ISqlRepository<HolidayMaster> holidayMaster,
+        ICurrentTenant currentTenant,
+         IMongoDB<mo_ic_bom> ic_bom,
+         IMongoDB<mo_ic_bom_child> ic_bom_child,
+         IMongoDB<mo_ic_item> ic_item,
+         IMongoDB<mo_ic_substitute> ic_substitute,
+         IMongoDB<mo_ic_substitute_group> ic_substitute_group,
+         IMongoDB<mo_ic_substitute_group_detail> ic_substitute_group_detail,
+         IMongoDB<mo_srm_supplier> srm_supplier,
+         IMongoDB<mo_mes_technique> mes_technique,
+         IMongoDB<mo_mes_process> mes_process,
+         IMongoDB<mo_mes_tech_process> mes_tech_process,
+         IMongoDB<mo_srm_purchase> srm_purchase,
+         ProductionScheduleAppService productionScheduleAppService,
+         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_srm_purchase = mysql_srm_purchase;
+            _mysql_crm_customer = mysql_crm_customer;
+            _mysql_crm_seorder = mysql_crm_seorder;
+            _mysql_crm_seorderentry = mysql_crm_seorderentry;
+            _mysql_ic_substitute = mysql_ic_substitute;
+            _mysql_ic_substitute_group = mysql_ic_substitute_group;
+            _mysql_ic_substitute_group_detail = mysql_ic_substitute_group_detail;
+            _mysql_mes_technique = mysql_mes_technique;
+            _mysql_mes_process = mysql_mes_process;
+            _mysql_mes_tech_process = mysql_mes_tech_process;
+            _custMaster = custMaster;
+            _suppMaster = suppMaster;
+            _consigneeAddressMaster = consigneeAddressMaster;
+            _itemMaster = itemMaster;
+            _productStructureMaster = productStructureMaster;
+            _ic_bom = ic_bom;
+            _ic_bom_child = ic_bom_child;
+            _ic_item = ic_item;
+            _ic_substitute = ic_substitute;
+            _ic_substitute_group = ic_substitute_group;
+            _ic_substitute_group_detail = ic_substitute_group_detail;
+            _srm_supplier = srm_supplier;
+            _mes_technique = mes_technique;
+            _mes_process = mes_process;
+            _mes_tech_process = mes_tech_process;
+            _srm_purchase = srm_purchase;
+            _businessDbContext = businessDbContext;
+            _itemMaster = itemMaster;
+            _workOrdMaster = workOrdMaster;
+            _workOrdDetail = workOrdDetail;
+            _workOrdRouting = workOrdRouting;
+            _prodLineDetail = prodLineDetail;
+            _periodSequenceDet = periodSequenceDet;
+            _scheduleResultOpMaster = scheduleResultOpMaster;
+            _invMaster = invMaster;
+            _shopCalendarWorkCtr = shopCalendarWorkCtr;
+            _qualityLineWorkDetail = qualityLineWorkDetail;
+            _holidayMaster = holidayMaster;
+            _currentTenant = currentTenant;
+            _productionScheduleAppService = productionScheduleAppService;
+        }
+
+        public string SyncWMSDataToMySQLJob()
+        {
+            try
+            {
+                //SyncCustMaster();
+                //SyncSuppMaster();
+                //SyncSalesOrdMaster();
+                //SyncSalesOrdMasterEntry();
+                //SyncItemMaster();
+                //SyncBom();
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+            return "同步完成";
+        }
+
+        public string LogInstallJob()
+        {
+            try
+            {
+                LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+            return "任务执行成功";
+
+        }
+
+        public string SyncBaseDataToMongoDBJob()
+        {
+            try
+            {
+                //物料采购报价单
+                //var srm_purchase = _mysql_srm_purchase.GetListAsync().Result;
+                //if (srm_purchase.Count > 0)
+                //{
+                //    //先清空表数据
+                //    _srm_purchase.Delete(p => p.mysql_id != -1);
+                //    List<mo_srm_purchase> mosrm_purchase = ObjectMapper.Map<List<srm_purchase>, List<mo_srm_purchase>>(srm_purchase);
+                //    mosrm_purchase.ForEach(s => s.id = help.NextId());
+                //    _srm_purchase.InsertMany(mosrm_purchase);
+                //}
+                /*//同步物料BOM明细数据
+                var icbom_childs = _mysql_ic_bom_child.GetListAsync().Result;
+                if (icbom_childs.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_bom_child.Delete(p => p.mysql_id != -1);
+                    var moIcbom_childs = ObjectMapper.Map<List<ic_bom_child>, List<mo_ic_bom_child>>(icbom_childs);
+                    moIcbom_childs.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_bom_child.InsertMany(moIcbom_childs);
+                }*/
+
+                /*//同步物料Bom数据
+                var icBoms = _mysql_ic_bom.GetListAsync().Result;
+                if (icBoms.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_bom.Delete(p => p.mysql_id != -1);
+                    var moIcBoms = ObjectMapper.Map<List<ic_bom>, List<mo_ic_bom>>(icBoms);
+                    moIcBoms.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_bom.InsertMany(moIcBoms);
+                }
+
+                //同步物料BOM明细数据
+                var icbom_childs = _mysql_ic_bom_child.GetListAsync().Result;
+                if (icbom_childs.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_bom_child.Delete(p => p.mysql_id != -1);
+                    var moIcbom_childs = ObjectMapper.Map<List<ic_bom_child>, List<mo_ic_bom_child>>(icbom_childs);
+                    moIcbom_childs.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_bom_child.InsertMany(moIcbom_childs);
+                }
+
+                ////工厂物料明细表
+                //var ic_factory_details = _mysql_ic_factory_details.GetListAsync().Result;
+                //if (ic_factory_details.Count > 0)
+                //{
+                //    //先清空表数据
+                //    await _ic_factory_details.Delete(p => p.mysql_id != -1);
+                //    var moIc_factory_details = ObjectMapper.Map<List<ic_factory_details>, List<mo_ic_factory_details>>(ic_factory_details);
+                //    moIc_factory_details.ForEach(s => s.id = help.NextId());
+                //    await _ic_factory_details.InsertMany(moIc_factory_details);
+                //}
+
+                //同步物料数据
+                var icItems = _mysql_ic_item.GetListAsync().Result;
+                if (icItems.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_item.Delete(p => p.mysql_id != -1);
+                    var moIcItems = ObjectMapper.Map<List<ic_item>, List<mo_ic_item>>(icItems);
+                    moIcItems.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_item.InsertMany(moIcItems);
+                }
+
+                //同步替代群组数据
+                var subtitutes = _mysql_ic_substitute.GetListAsync().Result;
+                if (subtitutes.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_substitute.Delete(p => p.mysql_id != -1);
+                    var moSubtitutes = ObjectMapper.Map<List<ic_substitute>, List<mo_ic_substitute>>(subtitutes);
+                    moSubtitutes.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_substitute.InsertMany(moSubtitutes);
+                }
+
+                //同步物料替代多群组数据
+                var subAlls = _mysql_ic_substitute_group.GetListAsync().Result;
+                if (subAlls.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_substitute_group.Delete(p => p.mysql_id != -1);
+                    var moSubAlls = ObjectMapper.Map<List<ic_substitute_group>, List<mo_ic_substitute_group>>(subAlls);
+                    moSubAlls.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_substitute_group.InsertMany(moSubAlls);
+                }
+
+                //同步物料替代多群组明细数据
+                var subAllDtls = _mysql_ic_substitute_group_detail.GetListAsync().Result;
+                if (subAllDtls.Count > 0)
+                {
+                    //先清空表数据
+                    await _ic_substitute_group_detail.Delete(p => p.mysql_id != -1);
+                    var moSubAllDtls = ObjectMapper.Map<List<ic_substitute_group_detail>, List<mo_ic_substitute_group_detail>>(subAllDtls);
+                    moSubAllDtls.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _ic_substitute_group_detail.InsertMany(moSubAllDtls);
+                }
+
+                //同步供应商数据
+                var suppliers = _mysql_srm_supplier.GetListAsync().Result;
+                if (suppliers.Count > 0)
+                {
+                    //先清空表数据
+                    await _srm_supplier.Delete(p => p.mysql_id != -1);
+                    var moSuppliers = ObjectMapper.Map<List<srm_supplier>, List<mo_srm_supplier>>(suppliers);
+                    moSuppliers.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _srm_supplier.InsertMany(moSuppliers);
+                }
+
+                //同步工艺路径数据
+                var techs = _mysql_mes_technique.GetListAsync().Result;
+                if (techs.Count > 0)
+                {
+                    //先清空表数据
+                    await _mes_technique.Delete(p => p.mysql_id != -1);
+                    var moTechs = ObjectMapper.Map<List<mes_technique>, List<mo_mes_technique>>(techs);
+                    moTechs.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _mes_technique.InsertMany(moTechs);
+                }
+
+                //同步工序数据
+                var processes = _mysql_mes_process.GetListAsync().Result;
+                if (suppliers.Count > 0)
+                {
+                    //先清空表数据
+                    await _mes_process.Delete(p => p.mysql_id != -1);
+                    var moProcesses = ObjectMapper.Map<List<mes_process>, List<mo_mes_process>>(processes);
+                    moProcesses.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _mes_process.InsertMany(moProcesses);
+                }
+
+                //同步工艺关联工序数据
+                var tech_procs = _mysql_mes_tech_process.GetListAsync().Result;
+                if (tech_procs.Count > 0)
+                {
+                    //先清空表数据
+                    await _mes_tech_process.Delete(p => p.mysql_id != -1);
+                    var moTech_procs = ObjectMapper.Map<List<mes_tech_process>, List<mo_mes_tech_process>>(tech_procs);
+                    moTech_procs.ForEach(s => s.id = help.NextId());
+                    //插入数据
+                    await _mes_tech_process.InsertMany(moTech_procs);
+                }
+
+
+                ////物料采购计划表
+                //var ic_plan = _mysql_ic_plan.GetListAsync().Result;
+                //if (ic_plan.Count > 0)
+                //{
+                //    //先清空表数据
+                //    await _ic_plan.Delete(p => p.mysql_id != -1);
+                //    var moIc_plan = ObjectMapper.Map<List<ic_plan>, List<mo_ic_plan>>(ic_plan);
+                //    moIc_plan.ForEach(s => s.id = help.NextId());
+                //    await _ic_plan.InsertMany(moIc_plan);
+                //}
+
+                //物料采购报价单
+                var srm_purchase = _mysql_srm_purchase.GetListAsync().Result;
+                if (srm_purchase.Count > 0)
+                {
+                    //先清空表数据
+                    await _srm_purchase.Delete(p => p.mysql_id != -1);
+                    var mosrm_purchase = ObjectMapper.Map<List<srm_purchase>, List<mo_srm_purchase>>(srm_purchase);
+                    mosrm_purchase.ForEach(s => s.id = help.NextId());
+                    await _srm_purchase.InsertMany(mosrm_purchase);
+                }*/
+
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+            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 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()
+        //{
+        //    bool isAll = true;//是否同步所有物料
+        //    var ic_itemList = _mysql_ic_item.GetListAsync(a => a.tenant_id == 1000 && a.factory_id == 1001).Result;
+        //    List<ItemMaster> custList = new List<ItemMaster>();
+        //    if (isAll)
+        //    {
+        //        custList = _itemMaster.Select(a => a.IsActive && a.Domain == "1001");
+        //    }
+        //    else
+        //    {
+        //        //格努产品编码同步子级物料
+        //        List<string> childItems = GetChildItemNumber("", new List<string>());
+        //        custList = _itemMaster.Select(a => a.IsActive && a.Domain == "1001" && childItems.Distinct().Contains(a.ItemNum));
+        //    }
+        //    List<ic_item> ItemsAdd = new List<ic_item>();
+        //    List<srm_purchase> srm_purchaseAdd = new List<srm_purchase>();
+        //    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)
+        //            {
+        //                long itemId = help.NextId();
+        //                ItemsAdd.Add(new ic_item(itemId)
+        //                {
+        //                    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 = 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_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" ? "自制" : "外购",
+        //                    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,
+
+
+        //                    batch_manager = custList[i].LotSerialControl ? 1 : 0,
+        //                    minorderqty = custList[i].MinOrd,
+        //                    minpackqty = 1,
+        //                    ordissu_days = 1,
+        //                    transportation_leadtime = 3,
+        //                    stock_leadtime = 1,
+        //                    production_leadtime = 4,
+        //                    order_leadtime = 4,
+
+        //                    fix_leadtime = 1,
+        //                    order_inter_val = 1,
+        //                    lead_time = 1,
+        //                    bat_change_economy = 1,
+        //                    total_tqq = 1,
+        //                    order_point = 1,
+        //                    secinv = 1,
+        //                    secinv_ratio = 1,
+        //                    self_inspection_date = 1,
+        //                    Warehousing_date = 1,
+        //                    Shipping_date = 3,
+        //                });
+        //                srm_purchaseAdd.Add(new srm_purchase(help.NextId())
+        //                {
+        //                    icitem_id = itemId,
+        //                    icitem_name = custList[i].Descr,
+        //                    sourcelist_number = "HYQD12064",
+        //                    supplier_id = 10101000051,
+        //                    supplier_number = "",
+        //                    supplier_name = "广州市伟正金属构件有限公司",
+        //                    purchgroup = "",
+        //                    purcher = "",
+        //                    purchase_unit = "",
+        //                    netpurchase_price = 1,
+        //                    taxrate = 0.13m,
+        //                    currency_type = 1,
+        //                    order_rector_name = "",
+        //                    order_rector_num = "",
+        //                    factory_code = "",
+        //                    order_dept = "",
+        //                    order_price = 13,
+        //                    sale_price = 130,
+        //                    qty_min = 10,
+        //                    batch_append_qty = 10,
+        //                    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;
+        //}
+
+        public string DoProductShceduleJob()
+        {
+            try
+            {
+                _productionScheduleAppService.DoExt();
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+            return "任务执行成功";
+
+        }
+    }
+}

+ 24 - 44
MicroServices/Business/Business.Host/BusinessHostModule.cs

@@ -1,10 +1,7 @@
-using Autofac.Core;
-using Business.Core.MongoDBHelper;
-using Business.Core.Utilities;
+using Business.Core.MongoDBHelper;
 using Business.EntityFrameworkCore;
 using Business.MultiTenancy;
-using Business.Quartz;
-using GZY.Quartz.MUI.EFContext;
+using Bussiness.MongoDB;
 using GZY.Quartz.MUI.Extensions;
 using Microsoft.AspNetCore.Authentication.JwtBearer;
 using Microsoft.AspNetCore.Builder;
@@ -15,13 +12,9 @@ using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
 using Microsoft.OpenApi.Models;
 using NLog;
-using NLog.Extensions.Logging;
-using NLog.Web;
 using Quartz;
-using Serilog.Events;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -35,14 +28,11 @@ using Volo.Abp.AspNetCore.Mvc;
 using Volo.Abp.AspNetCore.Serilog;
 using Volo.Abp.Autofac;
 using Volo.Abp.Caching;
-using Volo.Abp.Data;
 using Volo.Abp.EntityFrameworkCore.MySQL;
 using Volo.Abp.Localization;
 using Volo.Abp.Modularity;
 using Volo.Abp.MultiTenancy;
-using Volo.Abp.Threading;
 using Volo.Abp.VirtualFileSystem;
-using Bussiness.MongoDB;
 
 namespace Business
 {
@@ -105,48 +95,38 @@ namespace Business
         private void ConfigureQuartz(ServiceConfigurationContext context, IConfiguration configuration)
         {
             //程序启动执行一次日志分表检查,可以自己初始化避免需要部署脚本
-            LogHostedService logHostedService = new LogHostedService();
-            logHostedService.LogInstall();
+            LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
 
             context.Services.AddQuartz(q =>
             {
-                q.UseMicrosoftDependencyInjectionScopedJobFactory();
-                // Just use the name of your job that you created in the Jobs folder.
-                var jobKey = new JobKey("SyncDataJob");
-                q.AddJob<SyncMySQLDataJob>(opts => opts.WithIdentity(jobKey));
-
-                q.AddTrigger(opts => opts
-                    .ForJob(jobKey)
-                    .WithIdentity("SyncDataJob-trigger")
-                    .WithCronSchedule("0 38 10 * * ?")
-                    .WithDescription("定时同步MySQL基础数据到MongoDB"));
+                //q.UseMicrosoftDependencyInjectionScopedJobFactory();
+                //// Just use the name of your job that you created in the Jobs folder.
+                //var jobKey = new JobKey("SyncDataJob");
+                //q.AddJob<SyncMySQLDataJob>(opts => opts.WithIdentity(jobKey));
 
-                var NLogJobKey = new JobKey("NLogJob");
-                q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
-
-                q.AddTrigger(opts => opts
-                    .ForJob(NLogJobKey)
-                    .WithIdentity("NLogJob-trigger")
-                    .WithCronSchedule("0 01 01 * * ?")
-                    .WithDescription("定时创建NLog日志按月分表"));
+                //q.AddTrigger(opts => opts
+                //    .ForJob(jobKey)
+                //    .WithIdentity("SyncDataJob-trigger")
+                //    .WithCronSchedule("0 38 10 * * ?")
+                //    .WithDescription("定时同步MySQL基础数据到MongoDB"));
 
-                //var ExtJobKey = new JobKey("ExtJob");
-                //q.AddJob<ExtJob>(opts => opts.WithIdentity(ExtJobKey));
+                //var NLogJobKey = new JobKey("NLogJob");
+                //q.AddJob<NLogJob>(opts => opts.WithIdentity(NLogJobKey));
 
                 //q.AddTrigger(opts => opts
-                //    .ForJob(ExtJobKey)
-                //    .WithIdentity("ExtJob-trigger")
+                //    .ForJob(NLogJobKey)
+                //    .WithIdentity("NLogJob-trigger")
                 //    .WithCronSchedule("0 01 01 * * ?")
-                //    .WithDescription("定时处理金蝶同步到Ext数据库的数据"));
+                //    .WithDescription("定时创建NLog日志按月分表"));
 
-                var WMSJobKey = new JobKey("WMSJob");
-                q.AddJob<WMSJob>(opts => opts.WithIdentity(WMSJobKey));
+                //var WMSJobKey = new JobKey("WMSJob");
+                //q.AddJob<WMSJob>(opts => opts.WithIdentity(WMSJobKey));
 
-                q.AddTrigger(opts => opts
-                    .ForJob(WMSJobKey)
-                    .WithIdentity("WMSJob-trigger")
-                    .WithCronSchedule("0 32 15 * * ?")
-                    .WithDescription("定时同步WMS物料订单等基础数据到MySQL"));
+                //q.AddTrigger(opts => opts
+                //    .ForJob(WMSJobKey)
+                //    .WithIdentity("WMSJob-trigger")
+                //    .WithCronSchedule("0 32 15 * * ?")
+                //    .WithDescription("定时同步WMS物料订单等基础数据到MySQL"));
 
                 //var ProductionScheduleJobKey = new JobKey("ProductionScheduleJob");
                 //q.AddJob<ProductionScheduleJob>(opts => opts.WithIdentity(ProductionScheduleJobKey));

+ 3 - 3
MicroServices/Business/Business.Host/Startup.cs

@@ -1,7 +1,7 @@
 using Business.Core.MongoDBHelper;
 using Business.EntityFrameworkCore.SqlRepositories;
-using Business.Quartz;
-using GZY.Quartz.MUI.Extensions;
+using Business.SystemJob;
+using Business.SystemJobManagement;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.DependencyInjection;
@@ -18,7 +18,7 @@ namespace Business
             services.AddScoped(typeof(IMongoDB<>), typeof(MongoDBTools<>));
             services.AddScoped(typeof(ISqlRepository<>), typeof(SqlRepository<>));
             services.AddScoped<Config>();
-            services.AddScoped<LogHostedService>();
+            services.AddScoped(typeof(ISystemJobAppService), typeof(SystemJobAppService));
             services.AddScoped<GZY.Quartz.MUI.Areas.MyFeature.Pages.MainModel>();
         }
 

+ 6 - 4
MicroServices/Business/Business.HttpApi/Business.HttpApi.csproj

@@ -14,6 +14,12 @@
     <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
   </PropertyGroup>
 
+  <ItemGroup>
+    <Compile Remove="Controllers\MES\**" />
+    <EmbeddedResource Remove="Controllers\MES\**" />
+    <None Remove="Controllers\MES\**" />
+  </ItemGroup>
+
   <ItemGroup>
     <PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="6.0.3" />
     <PackageReference Include="XCZ.FlowManagement.HttpApi" Version="1.3.0" />
@@ -24,8 +30,4 @@
     <ProjectReference Include="..\Business.Application.Contracts\Business.Application.Contracts.csproj" />
   </ItemGroup>
 
-  <ItemGroup>
-    <Folder Include="Controllers\MES\" />
-  </ItemGroup>
-
 </Project>

+ 44 - 4
MicroServices/Business/Business.HttpApi/Controllers/ResourceExamineController.cs

@@ -1,6 +1,10 @@
-using Business.ResourceExamineManagement;
+using Business.Dto;
+using Business.ResourceExamineManagement;
 using Business.ResourceExamineManagement.Dto;
 using Microsoft.AspNetCore.Mvc;
+using MongoDB.Bson.IO;
+using Newtonsoft.Json;
+using Org.BouncyCastle.Asn1.Ocsp;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -55,7 +59,7 @@ namespace Business.Controllers
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
-        [HttpGet]
+        [HttpPost]
         [Route("receiveresult")]
         public Task<string> ReceiveResult(string ids, int type)
         {
@@ -122,15 +126,51 @@ namespace Business.Controllers
         }
 
         /// <summary>
-        /// 资源检查结果评审
+        /// Pr自动合并
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
-        [HttpGet]
+        [HttpPost]
         [Route("PrAutoMerge")]
         public void PrAutoMerge()
         {
             _ResourceExamineAppService.PrAutoMerge();
         }
+
+        /// <summary>
+        /// Pr手动合并
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("PrMerge")]
+        public Task<string> PrMerge(string ids)
+        {
+            return _ResourceExamineAppService.PrMerge(ids);
+        }
+
+        /// <summary>
+        /// Pr自动审核
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("PrAutoApprove")]
+        public Task<string> PrAutoApprove()
+        {
+            return _ResourceExamineAppService.PrAutoApprove();
+        }
+
+        /// <summary>
+        /// Pr手动审核
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("PrApprove")]
+        public Task<string> PrApprove(string ids)
+        {
+            return _ResourceExamineAppService.PrApprove(ids);
+        }
     }
 }

+ 1 - 8
MicroServices/Business/Business.HttpApi/Controllers/SerialNumberController.cs

@@ -1,14 +1,7 @@
-using Business.Core.Utilities;
-using Business.ResourceExamineManagement;
+using Business.ResourceExamineManagement;
 using Microsoft.AspNetCore.Mvc;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using Volo.Abp;
 using Volo.Abp.AspNetCore.Mvc;
-using static Business.Permissions.BusinessPermissions;
 
 namespace Business.Controllers
 {

+ 67 - 0
MicroServices/Business/Business.HttpApi/Controllers/SystemJobController.cs

@@ -0,0 +1,67 @@
+using Business.SystemJob;
+using Microsoft.AspNetCore.Mvc;
+using Volo.Abp;
+using Volo.Abp.AspNetCore.Mvc;
+
+namespace Business.Controllers
+{
+    /// <summary>
+    /// 系统定时任务接口
+    /// </summary>
+    [RemoteService]
+    [Area("Business")]
+    [Route("api/business/systemquartzjob")]
+    public class SystemJobController : AbpController
+    {
+        private readonly ISystemJobAppService _SystemJobAppService;
+
+        public SystemJobController(ISystemJobAppService SystemJobAppService)
+        {
+            _SystemJobAppService = SystemJobAppService;
+        }
+
+        /// <summary>
+        /// 定时同步WMS物料订单等基础数据到MySQL
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("syncwmsdatatomysql")]
+        public string SyncWMSDataToMySQL()
+        {
+            return _SystemJobAppService.SyncWMSDataToMySQLJob();
+        }
+
+        /// <summary>
+        /// 定时创建NLog日志按月分表
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("loginstall")]
+        public string LogInstall()
+        {
+            return _SystemJobAppService.LogInstallJob();
+        }
+
+        /// <summary>
+        /// 定时同步MySQL基础数据到MongoDB
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("syncbasedatatomongodb")]
+        public string SyncBaseDataToMongoDB()
+        {
+            return _SystemJobAppService.SyncBaseDataToMongoDBJob();
+        }
+
+        /// <summary>
+        /// 排产
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("DoProductShcedule")]
+        public string DoProductShcedule()
+        {
+            return _SystemJobAppService.DoProductShceduleJob();
+        }
+    }
+}

+ 0 - 60
MicroServices/Business/Business.HttpApi/Controllers/TestController.cs

@@ -1,60 +0,0 @@
-using Business.Core.Utilities;
-using Business.Test;
-using Microsoft.AspNetCore.Mvc;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Threading.Tasks;
-
-namespace Business.Controllers
-{
-    [Area("business")]
-    [Route("api/business/test")]
-    public class TestController: BusinessController
-    {
-        private readonly ITestAppService _testAppService;
-
-        public TestController(ITestAppService testAppService)
-        {
-            _testAppService = testAppService;
-        }
-
-        [HttpGet]
-        public async Task<string> GetAsync(string str)
-        {
-            return await _testAppService.TestApi(str);
-        }
-
-        [HttpGet]
-        [Route("classes")]
-        public List<string> GetClasses()
-        {
-            var theList = Assembly.GetExecutingAssembly().GetTypes()
-                      .Where(t => t.Namespace == "Business.Models.Test")
-                      .ToList();
-
-            foreach (var the in theList)
-            {
-                var type = the.GetProperties();
-            }
-
-            return null;
-        }
-
-        [HttpGet]
-        [Route("user-count")]
-        public Task<long> GetUserCount()
-        {
-            NLogHelper.Default.WriteLog("TestController", "默认logger","");
-            new NLogHelper("TestController").WriteLog("TestController", "自定义logger","");
-            return _testAppService.GetUserCount();
-        }
-
-        //[HttpGet]
-        //[Route("menu-tree")]
-        //public Task<dynamic> GetMenuTree()
-        //{
-        //    return _testAppService.GetMenuTree();
-        //}
-    }
-}

+ 0 - 11
MicroServices/Business/Business.HttpApi/Models/Test/TestModel.cs

@@ -1,11 +0,0 @@
-using System;
-
-namespace Business.Models.Test
-{
-    public class TestModel
-    {
-        public string Name { get; set; }
-
-        public DateTime BirthDate { get; set; }
-    }
-}

+ 9 - 2
MicroServices/Business/Bussiness.Model/Base/BaseEntity.cs

@@ -70,12 +70,19 @@ namespace Business.Model
         public virtual DateTime? update_time { get; set; }
 
         /// <summary>
-        /// 企业ID
+        /// 租户ID
         /// </summary>
         [Required]
-        [Comment("企业ID")]
+        [Comment("租户ID")]
         public virtual long tenant_id { get; set; }
 
+       /* /// <summary>
+        /// 公司ID
+        /// </summary>
+        [Required]
+        [Comment("公司ID")]
+        public virtual long company_id { get; set; }*/
+
         /// <summary>
         /// 工厂ID
         /// </summary>

+ 1 - 1
MicroServices/Business/QuartzSettings/task_job.json

@@ -1 +1 @@
-[{"TaskName":"测试定时任务","GroupName":"测试","Interval":"0 0 0 * * ?","ApiUrl":"http://123.60.180.165:8028/api/business/serialnumber","Describe":null,"LastRunTime":"2023-06-12T15:32:57","Status":6,"TaskType":2,"ApiRequestType":"GET","ApiAuthKey":null,"ApiAuthValue":null,"ApiParameter":"421240081346629","DllClassName":null,"DllActionName":null,"id":1,"timeflag":null,"changetime":null},{"TaskName":"定时任务","GroupName":"分组2","Interval":"0 0 10,14,16 * * ? ","ApiUrl":"http://123.60.180.165:8028/api/business/addon/demo","Describe":"测试定时任务,勿删","LastRunTime":"2023-06-12T15:31:30","Status":6,"TaskType":2,"ApiRequestType":"GET","ApiAuthKey":null,"ApiAuthValue":null,"ApiParameter":null,"DllClassName":null,"DllActionName":null,"id":2,"timeflag":null,"changetime":null}]
+[{"TaskName":"定时同步WMS物料订单等基础数据到MySQL","GroupName":"systemquartzjob","Interval":"0 32 15 * * ?","ApiUrl":"http://123.60.180.165:8028/api/business/systemquartzjob/syncwmsdatatomysql","Describe":"系统定时任务,勿删勿动","LastRunTime":null,"Status":6,"TaskType":2,"ApiRequestType":"GET","ApiAuthKey":null,"ApiAuthValue":null,"ApiParameter":null,"DllClassName":null,"DllActionName":null,"id":4,"timeflag":null,"changetime":null},{"TaskName":"定时同步MySQL基础数据到MongoDB","GroupName":"systemquartzjob","Interval":"0 38 10 * * ?","ApiUrl":"http://123.60.180.165:8028/api/business/systemquartzjob/syncbasedatatomongodb","Describe":"系统定时任务,勿删勿动","LastRunTime":null,"Status":6,"TaskType":2,"ApiRequestType":"GET","ApiAuthKey":null,"ApiAuthValue":null,"ApiParameter":null,"DllClassName":null,"DllActionName":null,"id":6,"timeflag":null,"changetime":null},{"TaskName":"定时创建NLog日志按月分表","GroupName":"systemquartzjob","Interval":"0 01 01 * * ?","ApiUrl":"http://123.60.180.165:8028/api/business/systemquartzjob/loginstall","Describe":"系统定时任务,勿删勿动","LastRunTime":null,"Status":6,"TaskType":2,"ApiRequestType":"GET","ApiAuthKey":null,"ApiAuthValue":null,"ApiParameter":null,"DllClassName":null,"DllActionName":null,"id":5,"timeflag":null,"changetime":null}]