😎新增SOLIDWORKS Manage 获取 token、创建记录服务、新增SAP创建、修改客户档案接口
This commit is contained in:
parent
7c05e6c59f
commit
4747009617
274
admin.net.pro/Admin.NET/Vistar.Application/Entity/Obj132.cs
Normal file
274
admin.net.pro/Admin.NET/Vistar.Application/Entity/Obj132.cs
Normal file
@ -0,0 +1,274 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using Admin.NET.Core;
|
||||
using SqlSugar;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
namespace Vistar.Application.Entity;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarTable("OBJ132","")]
|
||||
[Tenant("启威星 1.94.4.74")]
|
||||
public class Obj132
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Required]
|
||||
[SugarColumn(ColumnName = "idRecord", IsIdentity = true, ColumnDescription = "", IsPrimaryKey = true)]
|
||||
public long idRecord { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "CheckedStatus", ColumnDescription = "")]
|
||||
public bool? CheckedStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "VersionIndex", ColumnDescription = "")]
|
||||
public int? VersionIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "IsLatestVersion", ColumnDescription = "")]
|
||||
public bool? IsLatestVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "CreatedDate", ColumnDescription = "")]
|
||||
public DateTime? CreatedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "VersionCreatedDate", ColumnDescription = "")]
|
||||
public DateTime? VersionCreatedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "dateModified", ColumnDescription = "")]
|
||||
public DateTime? dateModified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "UserCreatedId", ColumnDescription = "")]
|
||||
public long? UserCreatedId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "VersionUserCreatedId", ColumnDescription = "")]
|
||||
public long? VersionUserCreatedId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "UserModifiedId", ColumnDescription = "")]
|
||||
public long? UserModifiedId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "RecordGuid", ColumnDescription = "", Length = 40)]
|
||||
public string? RecordGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "isVisibilityNormal", ColumnDescription = "")]
|
||||
public bool? isVisibilityNormal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "deleted", ColumnDescription = "")]
|
||||
public bool? deleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "SubObjectGuid", ColumnDescription = "", Length = 40)]
|
||||
public string? SubObjectGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "PreviousStatus", ColumnDescription = "")]
|
||||
public bool? PreviousStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "revision", ColumnDescription = "", Length = 10)]
|
||||
public string? revision { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "Record_image160_160", ColumnDescription = "")]
|
||||
public byte[]? Record_image160_160 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "Record_Image320_240", ColumnDescription = "")]
|
||||
public byte[]? Record_Image320_240 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "Record_ImageMax", ColumnDescription = "")]
|
||||
public byte[]? Record_ImageMax { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_objNBS", ColumnDescription = "", Length = 100)]
|
||||
public string? _System_objNBS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_ObjDescription", ColumnDescription = "", Length = 200)]
|
||||
public string? _System_ObjDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_Effectivity_Begin", ColumnDescription = "")]
|
||||
public DateTime? _System_Effectivity_Begin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_Effectivity_End", ColumnDescription = "")]
|
||||
public DateTime? _System_Effectivity_End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "CheckedOutPc", ColumnDescription = "", Length = 255)]
|
||||
public string? CheckedOutPc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "GroupObjId", ColumnDescription = "")]
|
||||
public long? GroupObjId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_CheckOutInProgress", ColumnDescription = "")]
|
||||
public bool? _CheckOutInProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "EnableNotifications", ColumnDescription = "")]
|
||||
public bool? EnableNotifications { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_system_objConfigurationName", ColumnDescription = "", Length = 255)]
|
||||
public string? _system_objConfigurationName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_system_objConfigurationType", ColumnDescription = "")]
|
||||
public bool? _system_objConfigurationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_system_objConfigurationGuid", ColumnDescription = "", Length = 40)]
|
||||
public string? _system_objConfigurationGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Required]
|
||||
[SugarColumn(ColumnName = "ShowBomFromConfiguration", ColumnDescription = "", Length = 250)]
|
||||
public string ShowBomFromConfiguration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Required]
|
||||
[SugarColumn(ColumnName = "_System_ObjNbsAuto", ColumnDescription = "", Length = 50)]
|
||||
public string _System_ObjNbsAuto { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_DerivedFrom", ColumnDescription = "", Length = 50)]
|
||||
public string? _System_DerivedFrom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_DerivedFrom_RecordGuid", ColumnDescription = "", Length = 50)]
|
||||
public string? _System_DerivedFrom_RecordGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_system_objLinkedCompare", ColumnDescription = "")]
|
||||
public bool? _system_objLinkedCompare { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "isReleasedVersion", ColumnDescription = "")]
|
||||
public bool? isReleasedVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "_System_WebLink", ColumnDescription = "", Length = 500)]
|
||||
public string? _System_WebLink { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "LinkDrw", ColumnDescription = "")]
|
||||
public bool? LinkDrw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "ParentRecordGuid", ColumnDescription = "", Length = 40)]
|
||||
public string? ParentRecordGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "fld004807", ColumnDescription = "", Length = -1)]
|
||||
public string? fld004807 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "fld004808", ColumnDescription = "", Length = -1)]
|
||||
public string? fld004808 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "fld004950", ColumnDescription = "", Length = -1)]
|
||||
public string? fld004950 { get; set; }
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
// 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.Service.SapOpenInterface.Dto;
|
||||
public class CreateClientRecordInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 标识 新增或修改
|
||||
/// </summary>
|
||||
public string actionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户编码
|
||||
/// </summary>
|
||||
public string _System_objNBS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户名称
|
||||
/// </summary>
|
||||
public string _System_objDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户简介
|
||||
/// </summary>
|
||||
public string fld004808 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注册地址
|
||||
/// </summary>
|
||||
public string fld004950 { get; set; }
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using Admin.NET.Core;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Vistar.Application.Const;
|
||||
using Vistar.Application.Entity;
|
||||
using Vistar.Application.Service.SapOpenInterface.Dto;
|
||||
using Vistar.Application.SolidWorksManageService.Dto;
|
||||
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionResponse.Types;
|
||||
|
||||
namespace Vistar.Application.Service.SapOpenInterface;
|
||||
/// <summary>
|
||||
/// 开放接口给Sap
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "SapOpenInterface", Order = 100)]
|
||||
public class SapOpenInterfaceService : IDynamicApiController, ITransient
|
||||
{
|
||||
public SqlSugarRepository<Obj132> _obj132Rep;
|
||||
public SolidWorksManageService.SolidWorksManageService _solidWorksManageService;
|
||||
public SapOpenInterfaceService(SqlSugarRepository<Obj132> obj132Rep, SolidWorksManageService.SolidWorksManageService solidWorksManageService)
|
||||
{
|
||||
_obj132Rep = obj132Rep;
|
||||
_solidWorksManageService = solidWorksManageService;
|
||||
}
|
||||
/// <summary>
|
||||
/// SAP创建、修改客户档案
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(AuthenticationSchemes = SignatureAuthenticationDefaults.AuthenticationScheme)]
|
||||
[ApiDescriptionSettings(Name = "CreateClientRecord"), HttpPost]
|
||||
[DisplayName("SAP创建、修改客户档案")]
|
||||
public async Task<ManageResponse> CreateClientRecord(CreateClientRecordInput input)
|
||||
{
|
||||
var response = new ManageResponse();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input._System_objNBS) || string.IsNullOrWhiteSpace(input._System_objDescription) || string.IsNullOrWhiteSpace(input.actionType))
|
||||
{
|
||||
response.Success = true;
|
||||
response.Message = "请输入必填字段";
|
||||
return response;
|
||||
}
|
||||
|
||||
if (input.actionType == "新增")
|
||||
{
|
||||
var fieldList = new List<Field>();
|
||||
|
||||
fieldList.Add(new Field { key = "_System_objNBS", value = input._System_objNBS });
|
||||
fieldList.Add(new Field { key = "_System_objDescription", value = input._System_objDescription });
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(input.fld004808))
|
||||
{
|
||||
fieldList.Add(new Field { key = "fld004808", value = input.fld004808 });
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(input.fld004950))
|
||||
{
|
||||
fieldList.Add(new Field { key = "fld004950", value = input.fld004950 });
|
||||
}
|
||||
|
||||
var data = new CreateRecordInput
|
||||
{
|
||||
object_id = 132,
|
||||
field_group_id = 422,
|
||||
fields = fieldList
|
||||
};
|
||||
response= await _solidWorksManageService.CreateRecord(data);
|
||||
return response;
|
||||
}
|
||||
else if (input.actionType == "修改")
|
||||
{
|
||||
var updateable = await _obj132Rep.AsUpdateable()
|
||||
.SetColumns(it => new Obj132
|
||||
{
|
||||
_System_ObjDescription = input._System_objDescription,
|
||||
fld004808 = input.fld004808,
|
||||
fld004950 = input.fld004950
|
||||
})
|
||||
.Where(x => x._System_objNBS == input._System_objNBS)
|
||||
.ExecuteCommandHasChangeAsync();
|
||||
|
||||
response.Success = true;
|
||||
response.Message = updateable ? "修改成功" : "修改失败";
|
||||
return response;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// 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 AuthorizationResponse
|
||||
{
|
||||
public string access_token { get; set; }
|
||||
public DateTime expires_in { get; set; }
|
||||
public string token_type { get; set; }
|
||||
public string raw_claim { get; set; }
|
||||
public bool success { get; set; }
|
||||
public string message { get; set; }
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// 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 CreateRecordInput
|
||||
{
|
||||
public long object_id { get; set; }
|
||||
public long field_group_id { get; set; }
|
||||
public List<Field> fields { get; set; }
|
||||
}
|
||||
|
||||
public class Field
|
||||
{
|
||||
public string key { get; set; }
|
||||
public string value { get; set; }
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// 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 ManageResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; }
|
||||
public object Data { get; set; }
|
||||
public object CustomAction { get; set; }
|
||||
public object CustomAttributes { get; set; }
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using Admin.NET.Core;
|
||||
using Admin.NET.Core.Service;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
private static readonly HttpClient client = new HttpClient();
|
||||
private readonly SysConfigService _sysConfigService;
|
||||
public SolidWorksManageService(SysConfigService sysConfigService)
|
||||
{
|
||||
_sysConfigService = sysConfigService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取 token
|
||||
/// </summary>
|
||||
/// <returns>授权响应对象</returns>
|
||||
public async Task<AuthorizationResponse> Authenticate()
|
||||
{
|
||||
// 获取 SolidWorksManage 地址
|
||||
string apiUrl = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiUrl);
|
||||
// 拼接接口地址
|
||||
string url = $"{apiUrl}/api/Authentication/Authenticate";
|
||||
|
||||
// 构建请求参数字典
|
||||
var parameter = new Dictionary<string, string>
|
||||
{
|
||||
["username"] = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageUserName),
|
||||
["password"] = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManagePassword),
|
||||
["licenseId"] = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageLicenseId),
|
||||
["apikey"] = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SolidWorksManageApiKey)
|
||||
};
|
||||
|
||||
// 将请求参数格式化为 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();
|
||||
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();
|
||||
|
||||
var errorResponse = new ManageResponse()
|
||||
{
|
||||
Success = false,
|
||||
Message = responseBody,
|
||||
Data="",
|
||||
CustomAction="",
|
||||
CustomAttributes=""
|
||||
};
|
||||
return errorResponse;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user