65 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			65 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 
								 | 
							
								using APT.BaseData.Domain.Entities.FM;
							 | 
						|||
| 
								 | 
							
								using APT.BaseData.Domain.Entities.OP;
							 | 
						|||
| 
								 | 
							
								using APT.BaseData.Domain.Enums.OP;
							 | 
						|||
| 
								 | 
							
								using APT.BaseData.Domain.IServices.OP;
							 | 
						|||
| 
								 | 
							
								using APT.Infrastructure.Api;
							 | 
						|||
| 
								 | 
							
								using APT.Infrastructure.Core;
							 | 
						|||
| 
								 | 
							
								using APT.Migrations;
							 | 
						|||
| 
								 | 
							
								using Newtonsoft.Json;
							 | 
						|||
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Linq.Expressions;
							 | 
						|||
| 
								 | 
							
								using System.Net;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace APT.BaseData.Services.Services.OP
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class OPTenantDBConnService : CommonService, IOPTenantDBConnService
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        public OPTenantDBConnService(IRepository repository) : base(repository)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 获取 除 ORG_IDBeside 之外对应的数据库链接字典  ORG_ID  DB_CONN
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="ORG_IDBeside"></param>
							 | 
						|||
| 
								 | 
							
								        /// <returns></returns>
							 | 
						|||
| 
								 | 
							
								        public Dictionary<Guid, string> GetConnDictionary(Guid? ORG_IDBeside)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Dictionary<Guid, string> dicORGCONN = new Dictionary<Guid, string>();
							 | 
						|||
| 
								 | 
							
								            string conn = string.Empty;
							 | 
						|||
| 
								 | 
							
								            IEnumerable<T_OP_TENANT> listTent = null;
							 | 
						|||
| 
								 | 
							
								            using (var context = new MigrationContext())
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Expression<Func<T_OP_TENANT, bool>> expression = e => e.DB_CONN_ID.HasValue;
							 | 
						|||
| 
								 | 
							
								                if (ORG_IDBeside.HasValue)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    expression = expression.And(e => e.ID != ORG_IDBeside);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                listTent = context.GetEntities(expression, null, null);
							 | 
						|||
| 
								 | 
							
								                List<Guid> listConnID = listTent.Select(e => e.DB_CONN_ID.Value).ToList();
							 | 
						|||
| 
								 | 
							
								                var listDbConn = context.GetEntities<T_OP_TENANT_DB_CONN>(e => listConnID.Contains(e.ID), null, null);
							 | 
						|||
| 
								 | 
							
								                if (listDbConn != null && listDbConn.Count() > 0)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    var env = ConfigurationManager.AppSettings["Env"];
							 | 
						|||
| 
								 | 
							
								                    foreach (var item in listDbConn)
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        conn = item.DB_CONN;
							 | 
						|||
| 
								 | 
							
								                        if (env == ((int)EnvType.外网).ToString())
							 | 
						|||
| 
								 | 
							
								                        {
							 | 
						|||
| 
								 | 
							
								                            conn = item.DB_CONN_WAN;
							 | 
						|||
| 
								 | 
							
								                        }
							 | 
						|||
| 
								 | 
							
								                        if (!dicORGCONN.ContainsKey(item.ID))
							 | 
						|||
| 
								 | 
							
								                        {
							 | 
						|||
| 
								 | 
							
								                            dicORGCONN.Add(listTent.First(e => e.DB_CONN_ID == item.ID).ID, conn);
							 | 
						|||
| 
								 | 
							
								                        }
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            return dicORGCONN;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |