using DataSharing.FwDataExchange;
using DataSharing.RawData;
using DataSharing.Share.Dtos;
using DataSharing.Share.Dtos.Common;
using DataSharing.Share.Dtos.HotlineSetting;
using DataSharing.Share.Dtos.HotlineWeb;
using DataSharing.Share.Enums;
using DotNetCore.CAP;
using Hotline.Share.Dtos.DataSharing.PusherHotlineDto;
using Hotline.Share.Dtos.File;
using MapsterMapper;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using XF.Domain.Filters;
using XF.Domain.Repository;
namespace DataSharing.Host.Controllers
{
    /// <summary>
    /// 通用API
    /// </summary>
    public class CommonApiController : BaseController
    {
        #region 注入
        private readonly IMapper _mapper;
        private readonly IMediator _mediator;
        private readonly ICapPublisher _capPublisher;
        private readonly IChannelConfigurationManager _channelConfigurationManager;
        private readonly IRepository<DsOrder> _dataOrderRepository;
        private readonly IRepository<DsOrderWorkFlow> _dataOrderWorkFlowRepository;
        private readonly IRepository<DsCommonReceiveData> _dsReceiveMediaDataRepository;
        private readonly IRepository<DsBulletin> _bulletinRepository;
        private readonly IRepository<DsUserTokenInfo> _dsUserTokenInfoRepository;
        private readonly FwClient _fwClient;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="mediator"></param>
        /// <param name="capPublisher"></param>
        /// <param name="channelConfigurationManager"></param>
        /// <param name="dataOrderRepository"></param>
        /// <param name="dataOrderWorkFlowRepository"></param>
        /// <param name="dsReceiveMediaDataRepository"></param>
        /// <param name="bulletinRepository"></param>
        /// <param name="dsUserTokenInfoRepository"></param>
        /// <param name="fwClient"></param>
        public CommonApiController(IMapper mapper, IMediator mediator,
            ICapPublisher capPublisher,
            IChannelConfigurationManager channelConfigurationManager,
            IRepository<DsOrder> dataOrderRepository,
            IRepository<DsOrderWorkFlow> dataOrderWorkFlowRepository,
            IRepository<DsCommonReceiveData> dsReceiveMediaDataRepository,
            IRepository<DsBulletin> bulletinRepository,
            IRepository<DsUserTokenInfo> dsUserTokenInfoRepository,
            FwClient fwClient)
        {
            _mapper = mapper;
            _mediator = mediator;
            _capPublisher = capPublisher;
            _channelConfigurationManager = channelConfigurationManager;
            _dataOrderRepository = dataOrderRepository;
            _dataOrderWorkFlowRepository = dataOrderWorkFlowRepository;
            _dsReceiveMediaDataRepository = dsReceiveMediaDataRepository;
            _bulletinRepository = bulletinRepository;
            _dsUserTokenInfoRepository = dsUserTokenInfoRepository;
            _fwClient = fwClient;
        }
        #endregion

        /// <summary>
        /// 2.1写信 
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("writeorder")]
        [AllowAnonymous]
        public async Task<OpenResponse> WriteOrder([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<OrderDataReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            //验证数据
            string strResult = dto.Validate();
            if (!string.IsNullOrEmpty(strResult))
                return OpenResponse.Ok(GetDataBaseReponse<CommWriteOrderResponseDto>.Failed(description: strResult));

            //写入原始数据
            DsCommonReceiveData dsReceiveMediaData = new()
            {
                ServiceInterface = "WriteOrder",
                PlatformSource = accountDto.PlatformSource,
                ReceiveData = System.Text.Json.JsonSerializer.Serialize(dto)
            };
            dsReceiveMediaData.Id = await _dsReceiveMediaDataRepository.AddAsync(dsReceiveMediaData, HttpContext.RequestAborted);
            Hotline.Share.Dtos.Order.AddOrderDto data = new()
            {
                Title = parasData.Title,
                FromName = parasData.FromName,
                Contact = parasData.Contact,
                Address = parasData.Address,
                Content = parasData.Content,
                IsSecret = parasData.Secrecy == "0" ? false : true,
                Source = (Hotline.Share.Enums.Order.ESource)Enum.Parse(typeof(Hotline.Share.Enums.Order.ESource), accountDto.PlatformSource),
                FromGender = parasData.Gender switch
                {
                    "1" => Hotline.Share.Enums.Order.EGender.Male,
                    "2" => Hotline.Share.Enums.Order.EGender.Female,
                    _ => Hotline.Share.Enums.Order.EGender.Unknown,
                },
                AcceptType = parasData.AcceptType,
                AcceptTypeCode = parasData.AcceptTypeCode,
                AreaCode = parasData.AreaCode,
                County = parasData.AreaName,
                IdentityType = Hotline.Share.Enums.Order.EIdentityType.Citizen,
                Transpond = false,
                IsEnforcementOrder = false
            };

            //调用工单创建接口
            //var result = await _hotlineClient.ReceiveOrderAsync(data, HttpContext.RequestAborted);
            var result = await _fwClient.RequestNoTokenAsync<HotlineClientResponse>("api/v1/Order/add-anonymous", "Post", System.Text.Json.JsonSerializer.Serialize(data));

            if (result != null && result.code == 0)
            {
                dsReceiveMediaData.OrderId = result.result.id;
                await _dsReceiveMediaDataRepository.UpdateAsync(dsReceiveMediaData, HttpContext.RequestAborted);
                CommWriteOrderResponseDto orderResponseDto = new()
                {
                    AcceptCode = result.result.no,
                    AcceptPwd = result.result.password
                };
                return OpenResponse.Ok(GetDataBaseReponse<CommWriteOrderResponseDto>.Success(orderResponseDto, "您已成功提交数据！"));
            }
            else
                return OpenResponse.Ok(GetDataBaseReponse<CommWriteOrderResponseDto>.Failed(description: "接口调用失败！"));
        }

        /// <summary>
        /// 2.2工单列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("getorderbylist")]
        [AllowAnonymous]
        public async Task<OpenResponse> GetOrderByList([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOrderReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            //数据查询
            RefAsync<int> total = 0;
            var items = await _dataOrderRepository
            .Queryable()
            .Where(p => p.Source == accountDto.PlatformSource)
            .WhereIF(!string.IsNullOrEmpty(parasData.AcceptCode), p => p.OrderNo.Contains(parasData.AcceptCode))
            .WhereIF(!string.IsNullOrEmpty(parasData.Title), p => p.Title.Contains(parasData.Title))
            .WhereIF(!string.IsNullOrEmpty(parasData.Contact), p => p.Contact.Contains(parasData.Contact))
            .WhereIF(!string.IsNullOrEmpty(parasData.AcceptTypeCode), p => p.CaseTypeCode == parasData.AcceptTypeCode)
            .WhereIF(!string.IsNullOrEmpty(parasData.StartDate), p => p.CaseDate >= Convert.ToDateTime(parasData.StartDate))
            .WhereIF(!string.IsNullOrEmpty(parasData.EndDate), p => p.CaseDate < Convert.ToDateTime(parasData.EndDate).AddDays(1))
            .Select(it => new
            {
                RowID = SqlFunc.RowNumber($"{it.CaseDate} desc "),
                it.Id,
                it.OrderNo,
                it.Title,
                it.CaseDate,
                it.CaseSource,
                it.CaseType,
                it.HandleState
            })
              .ToPageListAsync(parasData.PageIndex, parasData.PageSize, total);

            //计算总页数
            int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / parasData.PageSize));

            //处理返回
            GetOrderListDataDto dataDto = new()
            {
                pageCount = nPageCount,
                items = _mapper.Map<IReadOnlyList<GetOrderDataListDto>>(items)
            };

            return OpenResponse.Ok(GetDataBaseReponse<GetOrderListDataDto>.Success(dataDto, "成功"));

        }

        /// <summary>
        /// 2.3 工单查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("getorderdetail")]
        [AllowAnonymous]
        public async Task<OpenResponse> GetOrderDetail([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOrderDetailReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            var data = await _dataOrderRepository.GetAsync(p => p.OrderId == parasData.Id && p.Source == accountDto.PlatformSource, HttpContext.RequestAborted);
            if (data != null)
            {
                GetOrderDetailDataDto dataDto = new()
                {
                    Id = data.Id,
                    OrderNo = data.OrderNo,
                    Title = data.Title,
                    CaseSource = data.CaseSource,
                    CaseType = data.CaseType,
                    HotspotName = data.HotspotName,
                    CaseDate = data.CaseDate,
                    FromName = data.FromName,
                    ActualHandleOrgName = data.ActualHandleOrgName,
                    HandleState = data.HandleState,
                    Content = data.Content,
                    ActualOpinion = data.ActualOpinion,
                };
                return OpenResponse.Ok(GetDataBaseReponse<GetOrderDetailDataDto>.Success(dataDto, "成功"));
            }
            return OpenResponse.Ok(GetDataBaseReponse<GetOrderDetailDataDto>.Failed("数据查询失败"));

        }

        /// <summary>
        ///  2.4 今日受理分类统计
        /// </summary>
        /// <returns></returns>
        [HttpPost("getpurtypereport")]
        [AllowAnonymous]
        public async Task<OpenResponse> GetPurTypeReport([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            //数据查询
            var list = await _dataOrderRepository.Queryable()
                .Where(p => p.CaseDate >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")))
                .Where(p => p.CaseDate <= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")))
                .Select(it => new
                {
                    it.CaseType,
                    it.CaseTypeCode
                })
                .MergeTable()//将查询出来的结果合并成一个新表
                 .GroupBy(it => new { it.CaseType, it.CaseTypeCode })//对新表进行分组
                 .Select(it => new
                 {
                     Name = it.CaseType,
                     Num = SqlFunc.AggregateCount(it.CaseTypeCode)
                 })
                 .ToListAsync();

            var listData = _mapper.Map<List<GetNumReportDataDto>>(list);
            return OpenResponse.Ok(GetDataBaseReponse<List<GetNumReportDataDto>>.Success(listData, "成功"));
        }

        /// <summary>
        /// 2.5 答复公开
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("getorderbylistopen")]
        [AllowAnonymous]
        public async Task<OpenResponse> GetOrderByListOpen([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOrderReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            //查询数据
            RefAsync<int> total = 0;
            var items = await _dataOrderRepository
            .Queryable()
            .Where(p => p.IsPublish == EDsPublishState.Open)
            .WhereIF(!string.IsNullOrEmpty(parasData.Title), p => p.Title.Contains(parasData.Title))
            .WhereIF(!string.IsNullOrEmpty(parasData.AcceptTypeCode), p => p.CaseTypeCode == parasData.AcceptTypeCode)
            .WhereIF(!string.IsNullOrEmpty(parasData.StartDate), p => p.CaseDate >= Convert.ToDateTime(parasData.StartDate))
            .WhereIF(!string.IsNullOrEmpty(parasData.EndDate), p => p.CaseDate < Convert.ToDateTime(parasData.EndDate).AddDays(1))
           .Select(it => new
           {
               RowID = SqlFunc.RowNumber($"{it.CaseDate} desc "),
               it.Id,
               it.OrderNo,
               it.Title,
               it.CaseDate,
               it.CaseSource,
               it.CaseType,
               it.HandleState
           })
              .ToPageListAsync(parasData.PageIndex, parasData.PageSize, total);

            //计算总页数
            int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / parasData.PageSize));

            //处理返回
            GetOrderListDataDto dataDto = new()
            {
                pageCount = nPageCount,
                items = _mapper.Map<IReadOnlyList<GetOrderDataListDto>>(items)
            };

            return OpenResponse.Ok(GetDataBaseReponse<GetOrderListDataDto>.Success(dataDto, "成功"));

        }

        /// <summary>
        /// 2.6 办理明细
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("getorderbyrun")]
        [AllowAnonymous]
        public async Task<OpenResponse> GetOrderByRun([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOrderDetailReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            //验证信件是否存在
            var data = await _dataOrderRepository.GetAsync(p => p.OrderId == parasData.Id && p.Source == accountDto.PlatformSource, HttpContext.RequestAborted);
            if (data != null)
            {
                //数据查询
                var list = await _dataOrderWorkFlowRepository.Queryable()
                      .Where(p => p.OrderId == data.OrderId)
                      .Where(p => p.WorkflowId == data.WorkflowId)
                      .Select(it => new
                      {
                          it.HandlerOrgName,
                          it.StepExpiredTime,
                          it.HandleTime,
                          it.Opinion,
                          it.HandlerName
                      })
                      .ToListAsync();
                var dataDto = _mapper.Map<IReadOnlyList<GetOrderByRunDataListDto>>(list);
                return OpenResponse.Ok(GetDataBaseReponse<IReadOnlyList<GetOrderByRunDataListDto>>.Success(dataDto, "成功"));
            }
            return OpenResponse.Ok(GetDataBaseReponse<IReadOnlyList<GetOrderByRunDataListDto>>.Failed("数据获取失败"));
        }

        /// <summary>
        /// 2.1.3 上传附件
        /// </summary>
        /// <param name="params"></param>
        /// <param name="files"></param>
        /// <returns></returns>
        [HttpPost("writefiles")]
        [AllowAnonymous]
        public async Task<OpenResponse> WriteFiles([FromForm] string @params, List<IFormFile> files)
        {
            var tokenInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ParasDataDto>(@params);
            var accountDto = await CheckAccountAsync(tokenInfo.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            // 上传文件为必须
            if (files is null || files.Count <= 0)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed("上传文件为必须"));


            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOrderDetailReceiveDto>(tokenInfo.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            var dataRaw = await _dsReceiveMediaDataRepository.GetAsync(p => p.OrderId == parasData.Id && p.PlatformSource == accountDto.PlatformSource, HttpContext.RequestAborted);
            if (dataRaw == null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed("工单不存在"));

            List<FileDto> fileDtos = new();

            foreach (var item in files)
            {
                //这里需要上文件服务器上传
                var businessFileDto = await SendFileData(item);

                string strFileName = item.FileName;
                string strSuffix = strFileName.LastIndexOf(".") > 0 ? strFileName.Substring(strFileName.LastIndexOf(".")) : "";
                fileDtos.Add(new FileDto()
                {
                    Name = item.FileName,
                    Type = strSuffix,
                    Classify = "受理上传",
                    Additions = businessFileDto.id,
                    Path = businessFileDto.path
                });
            }

            //组装工单数据
            OrderUpdataFiles data = new()
            {
                Files = fileDtos,
                OrderId = dataRaw.OrderId
            };
            //推送数据
            await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.SharingOrderUpdataFiles, data, cancellationToken: HttpContext.RequestAborted);
            return OpenResponse.Ok(GetDataBaseReponse<string>.Success("", "上传成功"));
        }

        /// <summary>
        /// 2.7 新闻列表 
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("getnoticelistbypage")]
        [AllowAnonymous]
        public async Task<OpenResponse> GetNoticeListByPage([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetNoticeListReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));

            RefAsync<int> total = 0;
            var items = await _bulletinRepository
            .Queryable()
            .Where(p => p.LoseEfficacyTime >= DateTime.Now)
            .Where(p => p.BulletinTypeId == parasData.TypeId)
            .OrderByDescending(p => p.BulletinTime)
            .Select(it => new
            {
                Page = SqlFunc.RowNumber($"{it.BulletinTime} desc "),
                NoticeID = it.Id,
                NoticeTypeName = it.BulletinTypeName,
                NoticeTitle = it.Title,
                NoticeBMName = it.SourceOrgName,
                NoticeCreateDate = it.BulletinTime
            })
            .ToPageListAsync(parasData.PageIndex, parasData.PageSize, total);

            //计算总页数
            int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / parasData.PageSize));

            //处理返回
            GetNoticeReceiveDataListDto dataDto = new()
            {
                pageCount = nPageCount,
                items = _mapper.Map<IReadOnlyList<GetNoticeReceiveDataDto>>(items)
            };

            return OpenResponse.Ok(GetDataBaseReponse<GetNoticeReceiveDataListDto>.Success(dataDto, "成功"));
        }

        /// <summary>
        ///2.8 获取详情，修改阅读次数
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost("noticedetail")]
        public async Task<OpenResponse> GetArticleDetails([FromBody] ParasDataDto dto)
        {
            var accountDto = await CheckAccountAsync(dto.TokenInfo);
            if (accountDto is null || accountDto.IsCheckAccount == false)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: accountDto.Message));

            var parasData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetOrderDetailReceiveDto>(dto.ParasData);
            if (parasData is null)
                return OpenResponse.Ok(GetDataBaseReponse<string>.Failed(description: "参数解析失败"));


            var data = await _bulletinRepository.GetAsync(p => p.Id == parasData.Id, HttpContext.RequestAborted);
            GetArticleDetailsDto detailsDto = new();
            if (data != null)
            {
                data.ReadedNum = data.ReadedNum++;
                await _bulletinRepository.UpdateAsync(data, HttpContext.RequestAborted);

                detailsDto.Id = data.Id;
                detailsDto.TypeName = data.BulletinTypeName;
                detailsDto.Title = data.Title;
                detailsDto.SourceOrgName = data.SourceOrgName;
                detailsDto.CreateDate = data.BulletinTime;
                detailsDto.ReadedNum = data.ReadedNum;
                detailsDto.Content = data.Content;
            }

            return OpenResponse.Ok(WebPortalDeResponse<GetArticleDetailsDto>.Success(detailsDto, "成功"));
        }

        #region 私有方法-将文件转化为文件流

        /// <summary>
        /// 校验授权账号
        /// </summary>
        /// <param name="tokenInfo"></param>
        /// <returns></returns>
        private async Task<CheckAccountDto> CheckAccountAsync(string tokenInfo)
        {
            CheckAccountDto accountDto = new() { IsCheckAccount = false };
            var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DataSharing.Share.Dtos.Common.TokenInfo>(tokenInfo);
            if (dataInfo is null)
            {
                accountDto.Message = "授权信息解析失败";
                return accountDto;
            }

            if (string.IsNullOrEmpty(dataInfo.ClientId))
            {
                accountDto.Message = "授权账号不为空";
                return accountDto;
            }
            if (string.IsNullOrEmpty(dataInfo.ClientSecret))
            {
                accountDto.Message = "授权密码不为空";
                return accountDto;
            }

            var data = await _dsUserTokenInfoRepository.GetAsync(p => p.AccountId == dataInfo.ClientId && p.AccountSecret == dataInfo.ClientSecret && p.State == "1", HttpContext.RequestAborted);

            if (data is not null)
            {
                accountDto.PlatformSource = data.PlatformSource;
                accountDto.IsCheckAccount = true;
                return accountDto;
            }

            accountDto.Message = "授权账号或密码验证不通过";
            return accountDto;

        }

        /// <summary>
        /// 将文件流上传到附件服务器    
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private async Task<BusinessFileDto> SendFileData(IFormFile file)
        {
            var businessFile = _channelConfigurationManager.GetConfigurationBusinessFile();
            // 文件名称
            string fileName = file.FileName;

            // 文件内容字节数据
            using var memoryStream = new MemoryStream();
            await file.CopyToAsync(memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);
            byte[] fileContentBytes = memoryStream.ToArray();

            // 构造字典文件数据
            // 接口参数名称为files
            CFormUpload.FileParameter fileParameter = new CFormUpload.FileParameter("fileData", fileContentBytes, fileName, "multipart/form-data");

            Dictionary<string, object> dicParam = new()
            {
                { fileName, fileParameter }
            };
            string url = string.Format("{0}{1}?source={2}", businessFile.BaseUrl, businessFile.UploadUrlAddress, businessFile.Source);
            var result = CFormUpload.MultipartFormDataPost(url, null, dicParam, "");
            if (!string.IsNullOrEmpty(result))
            {
                var resultData = Newtonsoft.Json.JsonConvert.DeserializeObject<BusinessFileResponse>(result);
                if (resultData != null && resultData.code == 0)
                {
                    return resultData.result;
                }
            }
            return new BusinessFileDto();

        }


        #endregion
    }
}
