From 2095b8832323fec9bf5abe737762d495a81bcd58 Mon Sep 17 00:00:00 2001 From: bairubing Date: Mon, 21 Oct 2024 13:31:15 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8Emanage=E6=96=B0=E5=A2=9E=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=A1=B9=E7=9B=AE=E3=80=81=E6=A3=80=E5=87=BA=E3=80=81?= =?UTF-8?q?=E6=A3=80=E5=85=A5=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/CheckDataInput.cs | 31 ++++ .../Dto/CreateProjectInput.cs | 28 ++++ .../Dto/CreateRecordInput.cs | 3 + .../SolidWorksManageService.cs | 136 ++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CheckDataInput.cs create mode 100644 admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateProjectInput.cs diff --git a/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CheckDataInput.cs b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CheckDataInput.cs new file mode 100644 index 0000000..075cb82 --- /dev/null +++ b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CheckDataInput.cs @@ -0,0 +1,31 @@ +// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 +// +// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 +// +// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Vistar.Application.SolidWorksManageService.Dto; +/// +/// 检入检出输入参数 +/// +public class CheckDataInput +{ + /// + /// 对象id + /// + public long object_id { get; set; } + /// + /// 记录RecordGuid + /// + public string record_guid { get; set; } + /// + /// BOM层次 + /// + public int bom_level { get; set; } +} diff --git a/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateProjectInput.cs b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateProjectInput.cs new file mode 100644 index 0000000..6be2e8e --- /dev/null +++ b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateProjectInput.cs @@ -0,0 +1,28 @@ +// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 +// +// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 +// +// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Vistar.Application.SolidWorksManageService.Dto; +/// +/// 创建项目输入参数 +/// +public class CreateProjectInput +{ + public long object_id { get; set; } + public long field_group_id { get; set; } + public List fields { get; set; } +} + +public class CreateProjectField +{ + public string key { get; set; } + public string value { get; set; } +} diff --git a/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateRecordInput.cs b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateRecordInput.cs index 0d37d77..74d0fed 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateRecordInput.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/Dto/CreateRecordInput.cs @@ -11,6 +11,9 @@ using System.Text; using System.Threading.Tasks; namespace Vistar.Application.SolidWorksManageService.Dto; +/// +/// 创建记录输入参数 +/// public class CreateRecordInput { public long object_id { get; set; } diff --git a/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/SolidWorksManageService.cs b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/SolidWorksManageService.cs index 6512a90..671af34 100644 --- a/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/SolidWorksManageService.cs +++ b/admin.net.pro/Admin.NET/Vistar.Application/SolidWorksManageService/SolidWorksManageService.cs @@ -119,4 +119,140 @@ public class SolidWorksManageService : IDynamicApiController, ITransient } } + /// + /// 创建项目 + /// + /// + /// Create Project(创建项目) + public async Task CreateProject(CreateProjectInput input) + { + // 获取 SolidWorksManage 地址 + string apiUrl = await _sysConfigService.GetConfigValueByCode(ConfigConst.SolidWorksManageApiUrl); + // 拼接接口地址 + string url = $"{apiUrl}/api/PropertyCard/CreateProject"; + //获取token + var token = await _sysConfigService.GetConfigValueByCode(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(responseBody); + return result; + } + else + { + string responseBody = await response.Content.ReadAsStringAsync(); + + var errorResponse = new ManageResponse() + { + Success = false, + Message = responseBody, + Data = "", + CustomAction = "", + CustomAttributes = "" + }; + return errorResponse; + } + } + /// + /// 检出 + /// + /// + /// + public async Task CheckOut(CheckDataInput input) + { + // 获取 SolidWorksManage 地址 + string apiUrl = await _sysConfigService.GetConfigValueByCode(ConfigConst.SolidWorksManageApiUrl); + // 拼接接口地址 + string url = $"{apiUrl}/api/PropertyCard/CheckOut"; + //获取token + var token = await _sysConfigService.GetConfigValueByCode(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(responseBody); + return result; + } + else + { + string responseBody = await response.Content.ReadAsStringAsync(); + + var errorResponse = new ManageResponse() + { + Success = false, + Message = responseBody, + Data = "", + CustomAction = "", + CustomAttributes = "" + }; + return errorResponse; + } + } + /// + /// 检入 + /// + /// + /// + public async Task CheckIn(CheckDataInput input) + { + // 获取 SolidWorksManage 地址 + string apiUrl = await _sysConfigService.GetConfigValueByCode(ConfigConst.SolidWorksManageApiUrl); + // 拼接接口地址 + string url = $"{apiUrl}/api/PropertyCard/CheckIn"; + //获取token + var token = await _sysConfigService.GetConfigValueByCode(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(responseBody); + return result; + } + else + { + string responseBody = await response.Content.ReadAsStringAsync(); + + var errorResponse = new ManageResponse() + { + Success = false, + Message = responseBody, + Data = "", + CustomAction = "", + CustomAttributes = "" + }; + return errorResponse; + } + } + }