using MegaRobo.C00225155.Entities.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.ServiceModel;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace MegaRobo.C00225155.ControlDevices
{
public class AACWebApiService
{
public string _baseUrl { get; set; }
public string AuthToken { get; set; }
public HttpOperateHelper httpClient { get; set; }
public JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
};
#region Authentication
///
/// 登录系统并获取Token
///
/// 用户名
/// 密码
/// 包含Token的响应模型
public async Task> Login(string userName, string userPassword)
{
var requestUrl = $"{_baseUrl}/api/v1/Authentication?userName={userName}&userPassword={userPassword}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (HttpRequestException ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
#endregion
#region Instrument
///
/// 开启/关闭模块相关启用状态
///
/// 仪器Id
/// 仪器模块Id
/// 要设置的状态 0: Standby/off ,1: on
///
///
public async Task> State(int instrumentid, string moduleIdentity,int state)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/Module/State?cdsId={instrumentid}&moduleIdentity={moduleIdentity}&state={state}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (HttpRequestException ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 重置LC馏分收集器容器
///
///
///
///
///
public async Task> LCContainerReset(int instrumentid, string containerName)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/SubDevice/Drawer/Container/Volume/Reset?cdsId={instrumentid}&containerName={containerName}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (HttpRequestException ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 重置LC馏分收集器子设备
///
///
///
///
///
public async Task> LCSubDeviceReset(int instrumentid, string subDeviceName)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/SubDevice/Volume/Reset?cdsId={instrumentid}&subDeviceName={subDeviceName}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (HttpRequestException ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 重置进样器
///
///
///
///
public async Task> InjectorReset(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Injector/Reset?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (HttpRequestException ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// LC G7167全部复位
///
///
///
///
public async Task> HomeAll(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/G7167/HomeAll?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 重置LC馏分收集器子设备下单某个抽屉
///
///
///
/// 抽屉序号,从1开始,如果传小于等于0的值表示重置整个子设备.对于回收收集器只支持1
///
///
public async Task> LCSubDeviceDrawerReset(int instrumentid, string subDeviceName,int drawerIndex)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/SubDevice/Drawer/Volume/Reset?cdsId={instrumentid}&subDeviceName={subDeviceName}&drawerIndex={drawerIndex}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (Exception ex)
{
// 处理网络异常(如连接失败、超时等)
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC馏分收集器溶剂体积
///
///
///
///
///
public async Task> GetLCContainerVolume(int instrumentid, string subDeviceName)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/SubDevice/Volume?cdsId={instrumentid}&subDeviceName={subDeviceName}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 获取LC馏分收集器主设备的子模块列表
///
///
///
///
public async Task> GetLCFeature(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/SubDevices?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC馏分模块抽屉状态
///
///
///
///
///
///
///
public async Task> GetLCDrawerStatus(int instrumentid, string deviceType,string deviceSN,string moduleId)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/ModuleDrawerStatus?cdsId={instrumentid}&deviceType={deviceType}&deviceSN={deviceSN}&moduleId={moduleId}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 获取收集器模块的模块类型
///
///
///
public async Task>> GetModuleTypes()
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/ModuleTypes";
try
{
return await httpClient.GetAsync>(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
public async Task> GetLCG7167DrawerState(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/G7167/DrawerState?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取GC模块常用信息
///
///
///
///
public async Task> GetGCModuleInfo(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/GC/Module/Info?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
// 处理网络异常(如连接失败、超时等)
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC模块常用信息
///
///
///
///
public async Task> GetLCModuleInfo(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Module/Info?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
// 处理网络异常(如连接失败、超时等)
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 取消当前仪器运行的job
///
///
///
///
public async Task> CancelCurrentJob(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/Action/Cancel/CurrentJob?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 暂停仪器运行
///
///
///
///
public async Task> PauseCurrentJob(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/Action/Pause?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 恢复仪器重新运行
///
///
///
///
public async Task> ResumeCurrentJob(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/Action/Resume?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl, null);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
public async Task> ShutDownJob(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/Job/Shutdown?cdsId={instrumentid}";
try
{
return await httpClient.PostAsync(requestUrl, null);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC泵溶剂体积
///
///
///
///
public async Task> BottleVolume(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/BottleVolume?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 设置LC泵溶剂体积
///
///
///
///
///
public async Task> SetBottleVolume(int instrumentid, BottleVolumesResponse data)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/BottleVolume?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl, data);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC泵准备状态信息
///
///
///
///
public async Task> PreparationState(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/PreparationState?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 开始LC泵清洗
///
///
///
///
///
public async Task> PumpClean(int instrumentid, purgeCleaningParam data)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/Purge?cdsId={instrumentid}";
try
{
return await httpClient.PostAsync(requestUrl, data);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 关闭LC泵清洗
///
///
///
///
public async Task> StopPumpClean(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/Purge?cdsId={instrumentid}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 开始LC泵调节
///
///
///
///
///
public async Task> PumpCondition(int instrumentid,double conditionTime)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/Condition?cdsId={instrumentid}&conditionTime={conditionTime}";
try
{
return await httpClient.PostAsync(requestUrl, null);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 关闭LC泵调节
///
///
///
///
public async Task> StopPumpCondition(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/Condition?cdsId={instrumentid}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 开始LC泵注入
///
///
///
///
public async Task> PumpPrime(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/Prime?cdsId={instrumentid}";
try
{
return await httpClient.PostAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 关闭LC泵注入
///
///
///
///
public async Task> StopPumpPrime(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/Prime?cdsId={instrumentid}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC泵废液体积
///
///
///
///
public async Task> WasteBottleVolume(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Pump/WasteBottleVolume?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 读取LC进样器溶剂体积
///
///
///
///
public async Task>> PrepSampleBottleVolume(int instrumentid)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/PrepSampler/BottleVolume?cdsId={instrumentid}";
try
{
return await httpClient.GetAsync>(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 设置LC进样器溶剂体积
///
///
///
///
///
public async Task> SetPrepSampleBottleVolume(int instrumentid, List data)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/PrepSampler/BottleVolume?cdsId={instrumentid}";
try
{
return await httpClient.PutAsync(requestUrl,data);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 获取样品盘信息
///
///
///
///
///
public async Task> GetPlateExtraInfo(int instrumentid,string injectorPlateName)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Injector/Plate/ExtraInfo?cdsId={instrumentid}&injectorPlateName={injectorPlateName}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 替换进样器盘子
///
///
///
///
///
///
///
///
public async Task>> PutPlatePlacement(int instrumentid, string injectorPlateName, string openLabContainerDisplayName, bool keepAnalysisTargets, bool replaceFCFlag)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Injector/Plate/Replacement?cdsId={instrumentid}&injectorPlateName={injectorPlateName}&keepAnalysisTargets={keepAnalysisTargets}&replaceFCFlag={replaceFCFlag}";
try
{
return await httpClient.PutAsync>(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 替换馏分收集器盘子
///
///
///
///
///
///
public async Task>> PutLCPlatePlacement(int instrumentid, string fractionCollectorPlateName, string openLabContainerDisplayName)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/FractionCollector/Plate/Replacement?cdsId={instrumentid}&fractionCollectorPlateName={fractionCollectorPlateName}&openLabContainerDisplayName={openLabContainerDisplayName}";
try
{
return await httpClient.PutAsync>(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 开启/关闭模块相关启用状态
///
/// 仪器Id
/// 仪器模块Id
/// 要设置的状态 0: Standby/off ,1: on
///
///
public async Task> LCModuleState(int instrumentid, string moduleIdentity, int state)
{
var requestUrl = $"{_baseUrl}/api/v1/Instrument/LC/Module/State?cdsId={instrumentid}&moduleIdentity={moduleIdentity}&state={state}";
try
{
return await httpClient.PutAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
#endregion
#region Sample
///
/// 按批次设置Sample数据
///
///
///
///
public async Task> Sample(List data)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/batch";
try
{
return await httpClient.PostAsync(requestUrl,data);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 增加一个新样品
///
///
///
///
public async Task> AddOneSample(limsSamples sample)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample";
try
{
return await httpClient.PostAsync(requestUrl, sample);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 根据id删除大样品数据
///
///
///
///
public async Task> DeleteBigSample(string id)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample?id={id}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 根据id获取Sample数据
///
///
///
///
public async Task> GetSampleById(string id)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/id?id={id}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 根据id更新Sample数据
///
///
///
///
///
public async Task> RefreshSampleById(string id,limsSamples sample)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/id?id={id}";
try
{
return await httpClient.PutAsync(requestUrl, sample);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 根据barcode查询大样品数据
///
///
///
///
public async Task> ReserchSampleByBarcode(string barcode)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/barcode?barcode={barcode}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
public async Task> RefreshSampleByBarcode(string barcode)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/barcode?barcode={barcode}";
try
{
return await httpClient.PutAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
public async Task> DeleteSampleByBarcode(string barcode)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/barcode?barcode={barcode}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 根据BatchId获取Sample数据
///
///
///
///
public async Task> GetSampleByBatchId(string batchId)
{
var requestUrl = $"{_baseUrl}/api/v1/Sample/batchId?batchId={batchId}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
#endregion
#region SampleTestItem
public async Task> GetSampleItemByBarcode(string barcode)
{
var requestUrl = $"{_baseUrl}/api/v1/SampleTestItem/barcode?barcode={barcode}";
try
{
return await httpClient.GetAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
public async Task> RefreshSampleItemByBarcode(string barcode,SampleItem sampleItem)
{
var requestUrl = $"{_baseUrl}/api/v1/SampleTestItem/barcode?barcode={barcode}";
try
{
return await httpClient.PutAsync(requestUrl,sampleItem);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
public async Task> DeleteSampleItemByBarcode(string barcode)
{
var requestUrl = $"{_baseUrl}/api/v1/SampleTestItem/barcode?barcode={barcode}";
try
{
return await httpClient.DeleteAsync(requestUrl);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
///
/// 增加测试瓶数据
///
///
///
///
///
public async Task> AddSampleItemByBarcode(string sampleBarcode,SampleItem sampleItem)
{
var requestUrl = $"{_baseUrl}/api/v1/SampleTestItem?sampleBarcode={sampleBarcode}";
try
{
return await httpClient.PostAsync(requestUrl,sampleItem);
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}", ex);
}
}
#endregion
#region Store
#endregion
#region SystemInfo
#endregion
#region WorkPlan
#endregion
#region InstrumentAnalysisRun
#endregion
#region EventHandler
#endregion
}
}