Преглед изворни кода

删除基础数据同步接口,具体实现移到定时任务中

heteng пре 3 година
родитељ
комит
802a8becb6

+ 0 - 32
MicroServices/Business/Business.Application.Contracts/ScheduleTaskManagement/Dto/ResultDto.cs

@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Volo.Abp.Application.Dtos;
-using System.ComponentModel.DataAnnotations;
-namespace Business.ResourceExamineManagement.Dto
-{
-    /// <summary>
-    /// 数据同步返回结果Dto
-    /// </summary>
-    public class ResultDto
-    {
-        /// <summary>
-        /// 开始时间
-        /// </summary>
-        public DateTime start { get; set; }
-
-        /// <summary>
-        /// 结束时间
-        /// </summary>
-        public DateTime end { get; set; }
-
-        /// <summary>
-        /// 结果
-        /// </summary>
-        public bool isSuccess { get; set; }
-
-        /// <summary>
-        /// 异常信息
-        /// </summary>
-        public string msg { get; set; }
-    }
-}

+ 0 - 21
MicroServices/Business/Business.Application.Contracts/ScheduleTaskManagement/IScheduleTaskAppService.cs

@@ -1,21 +0,0 @@
-using Business.ResourceExamineManagement.Dto;
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Volo.Abp.Application.Dtos;
-using Volo.Abp.Application.Services;
-
-namespace Business.ScheduleTaskManagement
-{
-    /// <summary>
-    /// 同步数据
-    /// </summary>
-    public interface IScheduleTaskAppService : IApplicationService
-    {
-        /// <summary>
-        /// 同步基础数据到mongodb
-        /// </summary>
-        /// <returns></returns>
-        Task<ResultDto> SyncBaseDataToMongoDB();
-    }
-}

+ 20 - 2
MicroServices/Business/Business.Application/HangFire/HangFireJobService.cs

@@ -1,4 +1,5 @@
-using System;
+using Business.SyncDataManagement;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -8,8 +9,25 @@ namespace Business.HangFire
 {
     public class HangFireJobService : IHangFireJobService
     {
-        public void SyncDataMySQLData()
+        /// <summary>
+        /// 同步数据到mongodb服务
+        /// </summary>
+        public SyncMySQLDataAppService _syncDataAppservice;
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public HangFireJobService(SyncMySQLDataAppService syncDataAppservice)
+        {
+            _syncDataAppservice = syncDataAppservice;
+        }
+
+        /// <summary>
+        /// 定时同步mysql数据到mongodb中
+        /// </summary>
+        public async void SyncDataMySQLData()
         {
+           await _syncDataAppservice.SyncBaseDataToMongoDB();
         }
     }
 }

+ 3 - 0
MicroServices/Business/Business.Application/HangFire/IHangFireJobService.cs

@@ -8,6 +8,9 @@ namespace Business.HangFire
 {
     public interface IHangFireJobService
     {
+        /// <summary>
+        /// 定时同步mysql数据到mongodb中
+        /// </summary>
         void SyncDataMySQLData();
     }
 }

+ 92 - 109
MicroServices/Business/Business.Application/ScheduleTaskManagement/ScheduleTaskAppService.cs → MicroServices/Business/Business.Application/SyncDataManagement/SyncMySQLDataAppService.cs

@@ -47,12 +47,12 @@ using System.Collections;
 using System.Data.SqlTypes;
 using Bussiness.Model.SystemData;
 
-namespace Business.ScheduleTaskManagement
+namespace Business.SyncDataManagement
 {
     /// <summary>
-    /// 资源检查
+    /// 同步mysql数据到mongodb
     /// </summary>
-    public class ScheduleTaskAppService : ApplicationService, IScheduleTaskAppService
+    public class SyncMySQLDataAppService : ApplicationService
     {
         #region 服务
         /// <summary>
@@ -119,7 +119,7 @@ namespace Business.ScheduleTaskManagement
         /// <summary>
         /// 构造函数
         /// </summary>
-        public ScheduleTaskAppService(
+        public SyncMySQLDataAppService(
             IMongoDB<ic_bom> ic_bom,
             IMongoDB<ic_bom_child> ic_bom_child,
             IMongoDB<ic_item> ic_item,
@@ -169,123 +169,106 @@ namespace Business.ScheduleTaskManagement
         /// </summary>
         /// <returns></returns>
         /// <exception cref="NotImplementedException"></exception>
-        public async Task<ResultDto> SyncBaseDataToMongoDB()
+        public async Task SyncBaseDataToMongoDB()
         {
-            //数据同步返回结果
-            ResultDto result = new ResultDto();
-            result.start = DateTime.Now;
-            try
+            //同步物料Bom数据
+            var icBoms = await _mysql_ic_bom.GetListAsync();
+            if (icBoms.Count > 0)
             {
-                //同步物料Bom数据
-                var icBoms = await _mysql_ic_bom.GetListAsync();
-                if (icBoms.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _ic_bom.DeleteAll();
-                    //插入数据
-                    await _ic_bom.InsertMany(icBoms);
-                }
-
-                //同步物料BOM明细数据
-                var icbom_childs = await _mysql_ic_bom_child.GetListAsync();
-                if (icbom_childs.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _ic_bom_child.DeleteAll();
-                    //插入数据
-                    await _ic_bom_child.InsertMany(icbom_childs);
-                }
-
-                //同步物料数据
-                var icItems = await _mysql_ic_item.GetListAsync();
-                if (icItems.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _ic_item.DeleteAll();
-                    //插入数据
-                    await _ic_item.InsertMany(icItems);
-                }
+                //先清空表数据(删除mongodb中的集合)
+                await _ic_bom.DeleteAll();
+                //插入数据
+                await _ic_bom.InsertMany(icBoms);
+            }
 
-                //同步替代群组数据
-                var subtitutes = await _mysql_ic_substitute.GetListAsync();
-                if (subtitutes.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _ic_substitute.DeleteAll();
-                    //插入数据
-                    await _ic_substitute.InsertMany(subtitutes);
-                }
+            //同步物料BOM明细数据
+            var icbom_childs = await _mysql_ic_bom_child.GetListAsync();
+            if (icbom_childs.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _ic_bom_child.DeleteAll();
+                //插入数据
+                await _ic_bom_child.InsertMany(icbom_childs);
+            }
 
-                //同步物料替代多群组数据
-                var subAlls = await _mysql_ic_substitute_all.GetListAsync();
-                if (subAlls.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _ic_substitute_all.DeleteAll();
-                    //插入数据
-                    await _ic_substitute_all.InsertMany(subAlls);
-                }
+            //同步物料数据
+            var icItems = await _mysql_ic_item.GetListAsync();
+            if (icItems.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _ic_item.DeleteAll();
+                //插入数据
+                await _ic_item.InsertMany(icItems);
+            }
 
-                //同步物料替代群组明细数据
-                var subAllDtls = await _mysql_ic_substitute_all_dtl.GetListAsync();
-                if (subAllDtls.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _ic_substitute_all_dtl.DeleteAll();
-                    //插入数据
-                    await _ic_substitute_all_dtl.InsertMany(subAllDtls);
-                }
+            //同步替代群组数据
+            var subtitutes = await _mysql_ic_substitute.GetListAsync();
+            if (subtitutes.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _ic_substitute.DeleteAll();
+                //插入数据
+                await _ic_substitute.InsertMany(subtitutes);
+            }
 
-                //同步供应商数据
-                var suppliers = await _mysql_srm_supplier.GetListAsync();
-                if (suppliers.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _srm_supplier.DeleteAll();
-                    //插入数据
-                    await _srm_supplier.InsertMany(suppliers);
-                }
+            //同步物料替代多群组数据
+            var subAlls = await _mysql_ic_substitute_all.GetListAsync();
+            if (subAlls.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _ic_substitute_all.DeleteAll();
+                //插入数据
+                await _ic_substitute_all.InsertMany(subAlls);
+            }
 
-                //同步工艺路径数据
-                var techs = await _mysql_mes_technique.GetListAsync();
-                if (techs.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _mes_technique.DeleteAll();
-                    //插入数据
-                    await _mes_technique.InsertMany(techs);
-                }
+            //同步物料替代多群组明细数据
+            var subAllDtls = await _mysql_ic_substitute_all_dtl.GetListAsync();
+            if (subAllDtls.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _ic_substitute_all_dtl.DeleteAll();
+                //插入数据
+                await _ic_substitute_all_dtl.InsertMany(subAllDtls);
+            }
 
-                //同步工序数据
-                var processes = await _mysql_mes_process.GetListAsync();
-                if (suppliers.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _mes_process.DeleteAll();
-                    //插入数据
-                    await _mes_process.InsertMany(processes);
-                }
+            //同步供应商数据
+            var suppliers = await _mysql_srm_supplier.GetListAsync();
+            if (suppliers.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _srm_supplier.DeleteAll();
+                //插入数据
+                await _srm_supplier.InsertMany(suppliers);
+            }
 
-                //同步工艺关联工序数据
-                var tech_procs = await _mysql_mes_tech_process.GetListAsync();
-                if (tech_procs.Count > 0)
-                {
-                    //先清空表数据(删除mongodb中的集合)
-                    await _mes_tech_process.DeleteAll();
-                    //插入数据
-                    await _mes_tech_process.InsertMany(tech_procs);
-                }
+            //同步工艺路径数据
+            var techs = await _mysql_mes_technique.GetListAsync();
+            if (techs.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _mes_technique.DeleteAll();
+                //插入数据
+                await _mes_technique.InsertMany(techs);
+            }
 
-                result.end = DateTime.Now;
-                result.isSuccess = true;
-                return result;
+            //同步工序数据
+            var processes = await _mysql_mes_process.GetListAsync();
+            if (suppliers.Count > 0)
+            {
+                //先清空表数据(删除mongodb中的集合)
+                await _mes_process.DeleteAll();
+                //插入数据
+                await _mes_process.InsertMany(processes);
             }
-            catch (Exception ex)
+
+            //同步工艺关联工序数据
+            var tech_procs = await _mysql_mes_tech_process.GetListAsync();
+            if (tech_procs.Count > 0)
             {
-                result.end = DateTime.Now;
-                result.isSuccess = false;
-                result.msg = ex.Message;
-                return result;
+                //先清空表数据(删除mongodb中的集合)
+                await _mes_tech_process.DeleteAll();
+                //插入数据
+                await _mes_tech_process.InsertMany(tech_procs);
             }
         }
     }

+ 0 - 39
MicroServices/Business/Business.HttpApi/Controllers/ScheduleTaskController.cs

@@ -1,39 +0,0 @@
-using Business.ResourceExamineManagement.Dto;
-using Business.ScheduleTaskManagement;
-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;
-
-namespace Business.Controllers
-{
-    /// <summary>
-    /// 同步数据
-    /// </summary>
-    [RemoteService]
-    [Area("Business")]
-    [Route("api/business/schedule-task")]
-    public class ScheduleTaskController : AbpController
-    {
-        private readonly IScheduleTaskAppService _ScheduleTaskAppService;
-
-        public ScheduleTaskController(IScheduleTaskAppService ScheduleTaskAppService)
-        {
-            _ScheduleTaskAppService = ScheduleTaskAppService;
-        }
-
-        /// <summary>
-        /// 同步基础数据到mongodb
-        /// </summary>
-        /// <returns></returns>
-        [HttpGet]
-        public Task<ResultDto> SyncBaseDataToMongoDB()
-        {
-            return _ScheduleTaskAppService.SyncBaseDataToMongoDB();
-        }
-    }
-}