2024-10-16 13:33:54 +08:00
|
|
|
|
using Admin.NET.Core;
|
|
|
|
|
using Admin.NET.Core.Service;
|
2024-12-20 16:53:03 +08:00
|
|
|
|
using COSXML.Network;
|
2024-10-16 13:33:54 +08:00
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
2024-12-20 16:53:03 +08:00
|
|
|
|
using ICSharpCode.SharpZipLib.Zip;
|
2024-10-16 17:39:12 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-11-13 17:32:09 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-10-16 13:33:54 +08:00
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
|
using Newtonsoft.Json;
|
2024-12-20 16:53:03 +08:00
|
|
|
|
using Org.BouncyCastle.Asn1.Cms;
|
2024-10-16 13:33:54 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-11-13 17:32:09 +08:00
|
|
|
|
using System.ComponentModel;
|
2024-12-20 16:53:03 +08:00
|
|
|
|
using System.IO.Compression;
|
2024-10-16 13:33:54 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Vistar.Application.SolidWorksManageService.Dto;
|
|
|
|
|
|
|
|
|
|
namespace Vistar.Application.SolidWorksManageService;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// SolidWorksManage服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SolidWorksManageService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
2024-12-20 16:53:03 +08:00
|
|
|
|
private static readonly System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
|
2024-10-16 13:33:54 +08:00
|
|
|
|
private readonly SysConfigService _sysConfigService;
|
|
|
|
|
public SolidWorksManageService(SysConfigService sysConfigService)
|
|
|
|
|
{
|
|
|
|
|
_sysConfigService = sysConfigService;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取 token
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>授权响应对象</returns>
|
2024-11-13 17:32:09 +08:00
|
|
|
|
[ApiDescriptionSettings(Name = "Authenticate", Description = "获取 token", Order = 1000), HttpGet]
|
|
|
|
|
[DisplayName("获取 token")]
|
2024-10-16 17:39:12 +08:00
|
|
|
|
[AllowAnonymous]
|
2024-10-16 13:33:54 +08:00
|
|
|
|
public async Task<AuthorizationResponse> Authenticate()
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/Authentication/Authenticate";
|
|
|
|
|
|
2024-10-30 17:25:26 +08:00
|
|
|
|
var SolidWorksManageUserName = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageUserName);
|
|
|
|
|
var SolidWorksManagePassword = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManagePassword);
|
|
|
|
|
var SolidWorksManageLicenseId = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageLicenseId);
|
|
|
|
|
var SolidWorksManageApiKey = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiKey);
|
2024-10-16 13:33:54 +08:00
|
|
|
|
// 构建请求参数字典
|
|
|
|
|
var parameter = new Dictionary<string, string>
|
|
|
|
|
{
|
2024-10-30 17:25:26 +08:00
|
|
|
|
["username"] = SolidWorksManageUserName,
|
|
|
|
|
["password"] = SolidWorksManagePassword,
|
|
|
|
|
["licenseId"] = SolidWorksManageLicenseId,
|
|
|
|
|
["apikey"] = SolidWorksManageApiKey
|
2024-10-16 13:33:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 将请求参数格式化为 URL 格式的字符串
|
|
|
|
|
var formattingParameter = string.Join("&", parameter.Select(kvp => $"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}"));
|
|
|
|
|
// 构建完整的请求 URL
|
|
|
|
|
var requestUrl = $"{url}?{formattingParameter}";
|
|
|
|
|
|
|
|
|
|
// 使用 using 语句确保 HttpResponseMessage 资源被正确释放
|
|
|
|
|
using (var response = await client.PostAsync(requestUrl, null))
|
|
|
|
|
{
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
// 读取响应内容并反序列化为授权响应对象
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
2024-10-16 17:39:12 +08:00
|
|
|
|
AuthorizationResponse jsondata = JsonConvert.DeserializeObject<AuthorizationResponse>(responseBody);
|
|
|
|
|
string value = jsondata.access_token;
|
|
|
|
|
await _sysConfigService.UpdateConfigValue(ConfigConst.SolidWorksManageAuthorization, value);
|
2024-10-16 13:33:54 +08:00
|
|
|
|
return JsonConvert.DeserializeObject<AuthorizationResponse>(responseBody);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 读取响应内容并反序列化为授权响应对象(通常表示请求失败,但这里也尝试反序列化以便进一步处理错误)
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
return JsonConvert.DeserializeObject<AuthorizationResponse>(responseBody);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ManageResponse> CreateRecord(CreateRecordInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/PropertyCard/CreateRecord";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
2024-10-30 17:25:26 +08:00
|
|
|
|
|
2024-10-16 13:33:54 +08:00
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
2024-10-30 17:25:26 +08:00
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
2024-10-16 13:33:54 +08:00
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 13:31:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建项目
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>Create Project(创建项目)
|
|
|
|
|
public async Task<ManageResponse> CreateProject(CreateProjectInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/PropertyCard/CreateProject";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检出
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ManageResponse> CheckOut(CheckDataInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/PropertyCard/CheckOut";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检入
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ManageResponse> CheckIn(CheckDataInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/PropertyCard/CheckIn";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-05 09:35:12 +08:00
|
|
|
|
|
2024-10-30 15:59:19 +08:00
|
|
|
|
/// <summary>
|
2024-11-05 09:35:12 +08:00
|
|
|
|
/// 创建流程
|
2024-10-30 15:59:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-11-05 09:35:12 +08:00
|
|
|
|
public async Task<ManageResponse> CreateProcess(CreateProjectInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/PropertyCard/CreateProcess";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 17:32:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导出相关文件(全部)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-12-20 16:53:03 +08:00
|
|
|
|
public async Task<ExportRelatedFilesOutput> ExportRelatedFiles(ExportRelatedFilesInput input)
|
2024-10-30 15:59:19 +08:00
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
2024-12-20 16:53:03 +08:00
|
|
|
|
string url = $"{apiUrl}/api/File/ExportRelatedFiles?object_id=" + input.object_id + "&record_id=" + input.record_id;
|
2024-10-30 15:59:19 +08:00
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
//// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
//string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
//// 设置请求内容
|
|
|
|
|
//var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.GetAsync(url);
|
2024-12-20 16:53:03 +08:00
|
|
|
|
|
|
|
|
|
var output = new ExportRelatedFilesOutput();
|
2024-10-30 15:59:19 +08:00
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
2024-12-20 16:53:03 +08:00
|
|
|
|
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
|
|
|
|
|
string fileName;
|
|
|
|
|
string fileContentBase64;
|
|
|
|
|
|
|
|
|
|
// 将字节数据加载到内存流
|
|
|
|
|
using (var memoryStream = new MemoryStream(bytes))
|
|
|
|
|
using (var zipInputStream = new ZipInputStream(memoryStream))
|
|
|
|
|
{
|
|
|
|
|
ZipEntry entry;
|
|
|
|
|
while ((entry = zipInputStream.GetNextEntry()) != null)
|
|
|
|
|
{
|
|
|
|
|
fileName = entry.Name;
|
|
|
|
|
output.FileName = fileName;
|
|
|
|
|
// 读取解压后的文件内容
|
|
|
|
|
using (var decompressedStream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
zipInputStream.CopyTo(decompressedStream);
|
|
|
|
|
byte[] fileData = decompressedStream.ToArray();
|
|
|
|
|
|
|
|
|
|
// 将解压后的文件内容转为 Base64
|
|
|
|
|
fileContentBase64 = Convert.ToBase64String(fileData);
|
|
|
|
|
output.FileBate = fileContentBase64;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
output.State = "成功";
|
2024-10-30 15:59:19 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-12-20 16:53:03 +08:00
|
|
|
|
output.State = "失败";
|
2024-10-30 15:59:19 +08:00
|
|
|
|
}
|
2024-12-20 16:53:03 +08:00
|
|
|
|
return output;
|
2024-10-30 15:59:19 +08:00
|
|
|
|
}
|
2024-12-20 16:53:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-13 17:32:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加相关文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ManageResponse> AddRelatedFiles(AddRelatedFilesInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/File/AddRelatedFileToFolder";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
2024-11-29 09:47:10 +08:00
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存物料清单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ManageResponse> AddItemsInBom(AddItemsInBomInput input)
|
|
|
|
|
{
|
|
|
|
|
// 获取 SolidWorksManage 地址
|
|
|
|
|
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
|
|
|
|
// 拼接接口地址
|
|
|
|
|
string url = $"{apiUrl}/api/BOM/AddItemsInBom";
|
|
|
|
|
//获取token
|
|
|
|
|
var token = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageAuthorization);
|
|
|
|
|
// 将参数对象序列化为 JSON 字符串
|
|
|
|
|
string jsonParameters = JsonConvert.SerializeObject(input);
|
|
|
|
|
// 设置请求内容
|
|
|
|
|
var content = new StringContent(jsonParameters, Encoding.UTF8, "application/json");
|
2024-11-13 17:32:09 +08:00
|
|
|
|
client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
|
|
// 添加 Authorization 到请求头
|
|
|
|
|
client.DefaultRequestHeaders.Add("Authorization", token);
|
|
|
|
|
// 发送 POST 请求
|
|
|
|
|
HttpResponseMessage response = await client.PostAsync(url, content);
|
|
|
|
|
// 处理响应
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
// 解析 JSON 数据
|
|
|
|
|
var result = JsonConvert.DeserializeObject<ManageResponse>(responseBody);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
2024-10-30 15:59:19 +08:00
|
|
|
|
|
2024-11-13 17:32:09 +08:00
|
|
|
|
var errorResponse = new ManageResponse()
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = responseBody,
|
|
|
|
|
Data = "",
|
|
|
|
|
CustomAction = "",
|
|
|
|
|
CustomAttributes = ""
|
|
|
|
|
};
|
|
|
|
|
return errorResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-16 13:33:54 +08:00
|
|
|
|
}
|