Murphy 3 лет назад
Родитель
Сommit
6ae251a8d0

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

@@ -0,0 +1,32 @@
+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; }
+    }
+}

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

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

+ 25 - 3
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -372,7 +372,7 @@ namespace Business.ResourceExamineManagement
             long bangid = snow.NextId();
 
             //数据库快照-同步mysql库数据到mongoDB中
-            //await SyncData(input.factoryId,bangid);
+            await SyncData(input.tenantId,input.factoryId,bangid);
 
             //产能检查
             await ProductiveExamine(1353957529328291842, 1000);
@@ -386,10 +386,10 @@ namespace Business.ResourceExamineManagement
         /// 数据库快照
         /// </summary>
         /// <returns></returns>
-        public async Task SyncData(long factoryId, long bangid)
+        public async Task SyncData(long tenantId, long factoryId, long bangid)
         {
             //同步物料库存数据
-            var icitemStokc = _mysql_ic_item_stock.GetListAsync(p => p.factory_id == factoryId).Result;
+            var icitemStokc = _mysql_ic_item_stock.GetListAsync(p => p.tenant_id == tenantId && p.factory_id == factoryId).Result;
             if (icitemStokc.Count > 0)
             {
                 //设置当前计算bangid
@@ -397,6 +397,28 @@ namespace Business.ResourceExamineManagement
                 //插入数据
                 await _ic_item_stock.InsertMany(icitemStokc);
             }
+            ////在制工单占用记录表
+            //var mes_mooccupy = _mysql_mes_mooccupy.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
+            //if (mes_mooccupy.Count > 0)
+            //{
+            //    mes_mooccupy.ForEach(item => { item.bang_id = bangid; });
+            //    await _mes_mooccupy.InsertMany(mes_mooccupy);
+            //}
+            ////工单主表
+            //var mes_morder = _mysql_mes_morder.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
+            //if (mes_morder.Count > 0)
+            //{
+            //    mes_morder.ForEach(item => { item.bang_id = bangid; });
+            //    await _mes_morder.InsertMany(mes_morder);
+            //}
+            ////工单子表
+            //var mes_moentry = _mysql_mes_moentry.GetListAsync(x => x.tenant_id == tenantId && x.factory_id == factoryId).Result;
+            //if (mes_moentry.Count > 0)
+            //{
+            //    mes_moentry.ForEach(item => { item.bang_id = bangid; });
+            //    await _mes_moentry.InsertMany(mes_moentry);
+            //}
+
             //物料BOM
             var icBom = _mysql_ic_bom.GetListAsync(x => x.factory_id == factoryId).Result;
             if (icBom.Count > 0)

+ 292 - 0
MicroServices/Business/Business.Application/ScheduleTaskManagement/ScheduleTaskAppService.cs

@@ -0,0 +1,292 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Dynamic.Core;
+using System.Threading.Tasks;
+using Volo.Abp.Application.Dtos;
+using Volo.Abp.Domain.Repositories;
+using Business.Models;
+using Microsoft.AspNetCore.Authorization;
+using Business.Permissions;
+using XCZ;
+using Business.ResourceExamineManagement.Dto;
+using Bussiness.Model.MES.IC;
+using AutoMapper.Internal.Mappers;
+using Bussiness.Model.Tech;
+using Bussiness.Model.Production;
+using Business.Core.MongoDBHelper;
+using Business.Core.Utilities;
+using Hangfire.Storage.Monitoring;
+using Business.BookManagement.Dto;
+using Volo.Abp.ObjectMapping;
+using Volo.Abp.Application.Services;
+using ZstdSharp.Unsafe;
+using System.Transactions;
+using NUglify.JavaScript.Syntax;
+using System.Linq.Expressions;
+using XCZ.Extensions;
+using System.ComponentModel;
+using System.Reflection.Emit;
+using NUglify.Helpers;
+using Microsoft.AspNetCore.SignalR.Protocol;
+using System.ComponentModel.Design;
+using Volo.Abp.Validation.StringValues;
+using System.Runtime.CompilerServices;
+using MongoDB.Driver;
+using Volo.Abp.Validation.Localization;
+using Hangfire.Annotations;
+using System.Globalization;
+using MongoDB.Driver.Linq;
+using Bussiness.Model.SRM;
+using System.ComponentModel.DataAnnotations;
+using Bussiness.Model.Sale;
+using Amazon.Runtime.Internal.Transform;
+using System.IO.Compression;
+using System.Collections;
+using System.Data.SqlTypes;
+using Bussiness.Model.SystemData;
+
+namespace Business.ScheduleTaskManagement
+{
+    /// <summary>
+    /// 资源检查
+    /// </summary>
+    public class ScheduleTaskAppService : ApplicationService, IScheduleTaskAppService
+    {
+        #region 服务
+        /// <summary>
+        /// 物料bom
+        /// </summary>
+        private readonly IMongoDB<ic_bom> _ic_bom;
+        private IRepository<ic_bom, long> _mysql_ic_bom;
+
+        /// <summary>
+        /// 物料bom子表
+        /// </summary>
+        private readonly IMongoDB<ic_bom_child> _ic_bom_child;
+        private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
+
+        /// <summary>
+        /// 物料
+        /// </summary>
+        private readonly IMongoDB<ic_item> _ic_item;
+        private IRepository<ic_item, long> _mysql_ic_item;
+
+        /// <summary>
+        /// 替代群组
+        /// </summary>
+        private readonly IMongoDB<ic_substitute> _ic_substitute;
+        private IRepository<ic_substitute, long> _mysql_ic_substitute;
+
+        /// <summary>
+        /// 物料替代多群组
+        /// </summary>
+        private readonly IMongoDB<ic_substitute_all> _ic_substitute_all;
+        private IRepository<ic_substitute_all, long> _mysql_ic_substitute_all;
+
+        /// <summary>
+        /// 物料替代多群组明细
+        /// </summary>
+        private readonly IMongoDB<ic_substitute_all_dtl> _ic_substitute_all_dtl;
+        private IRepository<ic_substitute_all_dtl, long> _mysql_ic_substitute_all_dtl;
+
+        /// <summary>
+        /// 供应商
+        /// </summary>
+        private readonly IMongoDB<srm_supplier> _srm_supplier;
+        private IRepository<srm_supplier, long> _mysql_srm_supplier;
+
+        /// <summary>
+        /// 工艺路径
+        /// </summary>
+        private readonly IMongoDB<mes_technique> _mes_technique;
+        private IRepository<mes_technique, long> _mysql_mes_technique;
+
+        /// <summary>
+        /// 工序
+        /// </summary>
+        private readonly IMongoDB<mes_process> _mes_process;
+        private IRepository<mes_process, long> _mysql_mes_process;
+
+        /// <summary>
+        /// 工艺路径关联工序
+        /// </summary>
+        private readonly IMongoDB<mes_tech_process> _mes_tech_process;
+        private IRepository<mes_tech_process, long> _mysql_mes_tech_process;
+        #endregion
+
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public ScheduleTaskAppService(
+            IMongoDB<ic_bom> ic_bom,
+            IMongoDB<ic_bom_child> ic_bom_child,
+            IMongoDB<ic_item> ic_item,
+            IMongoDB<ic_substitute> ic_substitute,
+            IMongoDB<ic_substitute_all> ic_substitute_all,
+            IMongoDB<ic_substitute_all_dtl> ic_substitute_all_dtl,
+            IMongoDB<srm_supplier> srm_supplier,
+            IMongoDB<mes_technique> mes_technique,
+            IMongoDB<mes_process> mes_process,
+            IMongoDB<mes_tech_process> mes_tech_process,
+            IRepository<ic_bom, long> mysql_ic_bom,
+            IRepository<ic_bom_child, long> mysql_ic_bom_child,
+            IRepository<ic_item, long> mysql_ic_item,
+            IRepository<ic_substitute, long> mysql_ic_substitute,
+            IRepository<ic_substitute_all, long> mysql_ic_substitute_all,
+            IRepository<ic_substitute_all_dtl, long> mysql_ic_substitute_all_dtl,
+            IRepository<srm_supplier, long> mysql_srm_supplier,
+            IRepository<mes_technique, long> mysql_mes_technique,
+            IRepository<mes_process, long> mysql_mes_process,
+            IRepository<mes_tech_process, long> mysql_mes_tech_process
+            )
+        {
+            _ic_bom= ic_bom;
+            _ic_bom_child= ic_bom_child;
+            _ic_item= ic_item;
+            _ic_substitute= ic_substitute;
+            _ic_substitute_all= ic_substitute_all;
+            _ic_substitute_all_dtl= ic_substitute_all_dtl;
+            _srm_supplier= srm_supplier;
+            _mes_technique = mes_technique;
+            _mes_process= mes_process;
+            _mes_tech_process = mes_tech_process;
+            _mysql_ic_bom= mysql_ic_bom;
+            _mysql_ic_bom_child= mysql_ic_bom_child;
+            _mysql_ic_item= mysql_ic_item;
+            _mysql_ic_substitute= mysql_ic_substitute;
+            _mysql_ic_substitute_all= mysql_ic_substitute_all;
+            _mysql_ic_substitute_all_dtl= mysql_ic_substitute_all_dtl;
+            _mysql_srm_supplier= mysql_srm_supplier;
+            _mysql_mes_technique= mysql_mes_technique;
+            _mysql_mes_process= mysql_mes_process;
+            _mysql_mes_tech_process= mysql_mes_tech_process;
+        }
+
+        /// <summary>
+        /// 同步基础数据到mongodb
+        /// </summary>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<ResultDto> SyncBaseDataToMongoDB()
+        {
+            //数据同步返回结果
+            ResultDto result = new ResultDto();
+            result.start = DateTime.Now;
+            try
+            {
+                //同步物料Bom数据
+                var icBoms = _mysql_ic_bom.GetListAsync().Result;
+                if (icBoms.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _ic_bom.DeleteAll();
+                    //插入数据
+                    await _ic_bom.InsertMany(icBoms);
+                }
+
+                //同步物料BOM明细数据
+                var icbom_childs = _mysql_ic_bom_child.GetListAsync().Result;
+                if (icbom_childs.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _ic_bom_child.DeleteAll();
+                    //插入数据
+                    await _ic_bom_child.InsertMany(icbom_childs);
+                }
+
+                //同步物料数据
+                var icItems = _mysql_ic_item.GetListAsync().Result;
+                if (icItems.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _ic_item.DeleteAll();
+                    //插入数据
+                    await _ic_item.InsertMany(icItems);
+                }
+
+                //同步替代群组数据
+                var subtitutes = _mysql_ic_substitute.GetListAsync().Result;
+                if (subtitutes.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _ic_substitute.DeleteAll();
+                    //插入数据
+                    await _ic_substitute.InsertMany(subtitutes);
+                }
+
+                //同步物料替代多群组数据
+                var subAlls = _mysql_ic_substitute_all.GetListAsync().Result;
+                if (subAlls.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _ic_substitute_all.DeleteAll();
+                    //插入数据
+                    await _ic_substitute_all.InsertMany(subAlls);
+                }
+
+                //同步物料替代多群组明细数据
+                var subAllDtls = _mysql_ic_substitute_all_dtl.GetListAsync().Result;
+                if (subAllDtls.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _ic_substitute_all_dtl.DeleteAll();
+                    //插入数据
+                    await _ic_substitute_all_dtl.InsertMany(subAllDtls);
+                }
+
+                //同步供应商数据
+                var suppliers = _mysql_srm_supplier.GetListAsync().Result;
+                if (suppliers.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _srm_supplier.DeleteAll();
+                    //插入数据
+                    await _srm_supplier.InsertMany(suppliers);
+                }
+
+                //同步工艺路径数据
+                var techs = _mysql_mes_technique.GetListAsync().Result;
+                if (techs.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _mes_technique.DeleteAll();
+                    //插入数据
+                    await _mes_technique.InsertMany(techs);
+                }
+
+                //同步工序数据
+                var processes = _mysql_mes_process.GetListAsync().Result;
+                if (suppliers.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _mes_process.DeleteAll();
+                    //插入数据
+                    await _mes_process.InsertMany(processes);
+                }
+
+                //同步工艺关联工序数据
+                var tech_procs = _mysql_mes_tech_process.GetListAsync().Result;
+                if (tech_procs.Count > 0)
+                {
+                    //先清空表数据(删除mongodb中的集合)
+                    await _mes_tech_process.DeleteAll();
+                    //插入数据
+                    await _mes_tech_process.InsertMany(tech_procs);
+                }
+
+                result.end = DateTime.Now;
+                result.isSuccess = true;
+                return result;
+            }
+            catch (Exception ex)
+            {
+                result.end = DateTime.Now;
+                result.isSuccess = false;
+                result.msg = ex.Message;
+                return result;
+            }
+        }
+    }
+}

+ 6 - 0
MicroServices/Business/Business.Core/MongoDBHelper/IMongoDB.cs

@@ -92,6 +92,12 @@ namespace Business.Core.MongoDBHelper
         /// <returns></returns>
         Task<DeleteResult> Delete(FilterDefinition<T> filter, bool isOne = false);
 
+        /// <summary>
+        /// 删除数据-直接删除集合,慎用,慎用,慎用
+        /// </summary>
+        /// <returns></returns>
+        Task DeleteAll();
+
         /// <summary>
         /// 根据条件获取结果列表
         /// </summary>

+ 6 - 0
MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/BusinessDbContext.cs

@@ -4,6 +4,7 @@ using Bussiness.Model.MES.IC;
 using Bussiness.Model.Production;
 using Bussiness.Model.Sale;
 using Bussiness.Model.SRM;
+using Bussiness.Model.SystemData;
 using Bussiness.Model.Tech;
 using Microsoft.EntityFrameworkCore;
 using System;
@@ -195,6 +196,11 @@ namespace Business.EntityFrameworkCore
         public DbSet<srm_po_list> srm_po_list { get; set; }
 
         public DbSet<srm_po_occupy> srm_po_occupy { get; set; }
+
+        /// <summary>
+        /// ¹©Ó¦ÉÌ
+        /// </summary>
+        public DbSet<srm_supplier> srm_supplier { get; set; }
         #endregion
         //Code generation...
         public BusinessDbContext(DbContextOptions<BusinessDbContext> options)

+ 2 - 1
MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/BusinessDbContextModelCreatingExtensions.cs

@@ -97,7 +97,8 @@ namespace Business.EntityFrameworkCore
             builder.Entity<ic_item_stock>(b =>
             {
                 b.ToTable("ic_item_stock").HasComment("物料库存表");
-
+                //不映射到数据库中
+                b.Ignore(x => x.bang_id);
                 b.ConfigureByConvention();
             });
 

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

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

+ 0 - 5
MicroServices/Business/Bussiness.Model/MES/IC/ic_bom.cs

@@ -133,10 +133,5 @@ namespace Bussiness.Model.MES.IC
         [StringLength(20)]
         [Description("单位")]
         public string? unit { get; set; }
-        /// <summary>
-        /// 计算ID
-        /// </summary>
-        [Description("计算id")]
-        public long? bang_id { get; set; }
     }
 }

+ 3 - 1
MicroServices/Business/Bussiness.Model/SystemData/srm_supplier.cs

@@ -1,4 +1,5 @@
-using Business.Model;
+using Business.Core.Attributes;
+using Business.Model;
 using Microsoft.EntityFrameworkCore;
 using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
@@ -9,6 +10,7 @@ namespace Bussiness.Model.SystemData
     /// 供应商
     /// </summary>
     [Description("供应商")]
+    [CollectionName("dopbase", "srm_supplier")]
     public class srm_supplier: BaseEntity
     {
         ///// <summary>