using CsharpHttpHelper; using DeviceRepairAndOptimization.Models; using DeviceRepairAndOptimization.Models.Common; using DeviceRepairAndOptimization.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DeviceRepairAndOptimization.Business { public class FileManager { /// /// 下载附件 /// /// /// public APIResponseData GetFileSingle(AttachmentQueryModel filter) { APIResponseData apiResponseData = new APIResponseData { Code = -1, Data = "" }; try { if (filter == null) return apiResponseData; switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": //filePath = ApiHelper.Instance.DownLoadFile(new HttpItem() //{ // URL = "api/MaintenanceForm/DownloadFile?AutoID=" + AutoID, // Method = "get", // ContentType = "application/vnd.ms-excel" //}); ////创建Httphelper对象 //HttpHelper http = new HttpHelper(); ////创建Httphelper参数对象 //HttpItem item = new HttpItem() //{ // URL = "api/MaintenanceForm/DownloadFile?AutoID=" + AutoID, // Method = "get", // ContentType = "application/vnd.ms-excel", // ResultType = ResultType.Byte //}; //HttpResult result = http.GetHtml(item); //WebHeaderCollection header = result.Header; //if (header != null) //{ // string fileName = header["FileName"]; // if (!string.IsNullOrWhiteSpace(fileName)) // { // string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; // if (!Directory.Exists(Path.Combine(CurrentDirectory, "Cache"))) // Directory.CreateDirectory(Path.Combine(CurrentDirectory, "Cache")); // File.WriteAllBytes(Path.Combine(CurrentDirectory, fileName), result.ResultByte); // filePath = Path.Combine(CurrentDirectory, fileName); // } //} break; case "sql": //entity = MaintenanceFormVersionAccess.Instance().GetSingle(AutoID); break; default: break; } } catch (Exception ex) { apiResponseData.Code = -1; apiResponseData.Message = ex.Message; } return apiResponseData; } } }