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 { /// /// 资源检查 /// public class ScheduleTaskAppService : ApplicationService, IScheduleTaskAppService { #region 服务 /// /// 物料bom /// private readonly IMongoDB _ic_bom; private IRepository _mysql_ic_bom; /// /// 物料bom子表 /// private readonly IMongoDB _ic_bom_child; private IRepository _mysql_ic_bom_child; /// /// 物料 /// private readonly IMongoDB _ic_item; private IRepository _mysql_ic_item; /// /// 替代群组 /// private readonly IMongoDB _ic_substitute; private IRepository _mysql_ic_substitute; /// /// 物料替代多群组 /// private readonly IMongoDB _ic_substitute_all; private IRepository _mysql_ic_substitute_all; /// /// 物料替代多群组明细 /// private readonly IMongoDB _ic_substitute_all_dtl; private IRepository _mysql_ic_substitute_all_dtl; /// /// 供应商 /// private readonly IMongoDB _srm_supplier; private IRepository _mysql_srm_supplier; /// /// 工艺路径 /// private readonly IMongoDB _mes_technique; private IRepository _mysql_mes_technique; /// /// 工序 /// private readonly IMongoDB _mes_process; private IRepository _mysql_mes_process; /// /// 工艺路径关联工序 /// private readonly IMongoDB _mes_tech_process; private IRepository _mysql_mes_tech_process; #endregion /// /// 构造函数 /// public ScheduleTaskAppService( IMongoDB ic_bom, IMongoDB ic_bom_child, IMongoDB ic_item, IMongoDB ic_substitute, IMongoDB ic_substitute_all, IMongoDB ic_substitute_all_dtl, IMongoDB srm_supplier, IMongoDB mes_technique, IMongoDB mes_process, IMongoDB mes_tech_process, IRepository mysql_ic_bom, IRepository mysql_ic_bom_child, IRepository mysql_ic_item, IRepository mysql_ic_substitute, IRepository mysql_ic_substitute_all, IRepository mysql_ic_substitute_all_dtl, IRepository mysql_srm_supplier, IRepository mysql_mes_technique, IRepository mysql_mes_process, IRepository 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; } /// /// 同步基础数据到mongodb /// /// /// public async Task 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; } } } }