Example #1
0
        /// <summary>
        /// 消息发送:ExcelIE消息发送与较验
        /// </summary>
        /// <param name="ieDto"></param>
        /// <returns></returns>
        public async Task <string> PushExcelExportMsg(ExcelIEDto ieDto)
        {
            string error = string.Empty;

            if (string.IsNullOrEmpty(ieDto.TemplateCode))
            {
                error = "模板编码不能为空!";
            }
            else
            {
                // 切换数据库连接
                await _dbService.ChangeConnectionString(ieDto);

                var templateRedisKey = ExcelIEConsts.ExcelIERedisPre + ieDto.TemplateCode + ":" + ieDto.TenantId.ToString();
                var templateStr      = await _redis.StringGetAsync(templateRedisKey);

                if (string.IsNullOrEmpty(templateStr))
                {
                    var template = await _excelIEDomainService.GetFirstExcelModelAsync(o => o.TemplateCode == ieDto.TemplateCode);

                    if (template.Id == Guid.Empty)
                    {
                        return(error = "模板不存在!");
                    }
                    else
                    {
                        await _redis.StringSetAsync(templateRedisKey, JsonHelper.ToJsonString(template), TimeSpan.FromMinutes(50));

                        ieDto.Template = template;
                    }
                }
                else
                {
                    ieDto.Template = JsonHelper.ToJson <CoExcelExportSql>(templateStr);
                }
                //消息发送(导出)
                ieDto.TemplateLog.ExportParameters = JsonHelper.ToJsonString(ieDto);
                ieDto.TemplateLog.ParentId         = ieDto.Template.Id;
                ieDto.TemplateLog.TemplateSql      = ieDto.Template.ExecSql;
                ieDto.TemplateLog.CreateTime       = DateTime.Now;
                ieDto.TemplateLog.TenantId         = ieDto.TenantId;
                ieDto.TemplateLog.CreateUserId     = ieDto.UserId;
                ieDto.TemplateLog.CreateUser       = ieDto.UserName;
                ieDto.TemplateLog.Id = _excelIEDomainService.NewGuid();
                await _excelIEDomainService.AddAsyncExcelLogModel(ieDto.TemplateLog);

                await _capPublisher.PublishAsync(MqConst.ExcelIETopicName, ieDto);
            }
            return(error);
        }
Example #2
0
        /// <summary>
        /// 修改数据库连接字符串
        /// 只有saas版需要切换,非saas版读取本地连接
        /// </summary>
        /// <param name="name">方法/key名称</param>
        /// <returns></returns>
        public async Task ChangeConnectionString(ExcelIEDto ieDto)
        {
            if (ieDto.TenantId == Guid.Empty)
            {
                throw new Exception("输入的tntid错误");
            }
            var tntKey = ExcelIEConsts.ExcelIERedisPre + ieDto.TenantId.ToString();
            var tntStr = await _redis.StringGetAsync(tntKey);

            if (string.IsNullOrEmpty(tntStr))
            {
                var tnt = await _amUnit.GetRepository <AmTenant>().GetFirstOrDefaultAsync(m => m.Id == ieDto.TenantId);

                if (tnt == null)
                {
                    throw new Exception($"未找到对应的租户配置,请检查输入的tntid:{ieDto.TenantId}是否有误");
                }
                if (!string.IsNullOrEmpty(tnt.TntDbStr) && !string.IsNullOrEmpty(tnt.TntCode))
                {
                    tntStr = JsonHelper.ToJsonString(new
                    {
                        tnt.TntCode,
                        tnt.TntDbStr
                    });
                    ieDto.TenantCode  = tnt.TntCode;
                    ieDto.TenantDBStr = tnt.TntDbStr;
                    await _redis.StringSetAsync(tntKey, tntStr, TimeSpan.FromMinutes(30));

                    await _scmUnit.ChangeConnectionStringAsync(tnt.TntDbStr);
                }
            }
            else
            {
                var dbDto = JsonHelper.ToJson <dynamic>(tntStr);
                await _scmUnit.ChangeConnectionStringAsync(Convert.ToString(dbDto.TntDbStr));
            }
        }