2025-09-12 12:03:20 +08:00

346 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SWS.Commons;
using SWS.Model;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SWS.Service
{
public class IOModuleService : HttpService
{
public IOModuleService() : base()
{
}
/// <summary>
/// 获取所有的信号
/// </summary>
/// <param name="projId"></param>
/// <param name="Assigned"></param>
/// <returns></returns>
public async Task<List<Model.TreeModel>> GetPanelTree()
{
var res = await this.GetAsync<List<Model.TreeModel>>($"IOModuleApi/GetPanelTree?projectId={GlobalObject.curProject?.ProjectId}");
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// 在IO分配界面从左侧目录树中选择一个“端子排”后进行查询
/// </summary>
/// <param name="StripID"></param>
/// <param name="projId"></param>
/// <param name="OnlySelf">false时带上下面的通道和端子。true时就是返回端子排自己</param>
/// <returns></returns>
public async Task<ec_PanelStrip> GetPanelStrip(string StripID, bool OnlySelf = false, bool HaveChannel = true)
{
var res = await this.GetAsync<ec_PanelStrip>($"IOModuleApi/GetPanelStrip?StripID={StripID}&projId={GlobalObject.curProject?.ProjectId}&OnlySelf={OnlySelf}&HaveChannel={HaveChannel}");
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// 保存端子排 通道 端子的信息(不管信号和接线关系)。
/// 迁移通道也是这里。
/// </summary>
/// <param name="entity"></param>
/// <param name="projId"></param>
public async Task<object> SavePanelStrip(ec_PanelStrip entity)
{
var res = await this.PostBodyAsync<ec_PanelStrip, ec_PanelStrip>($"IOModuleApi/SavePanelStrip?projId={GlobalObject.curProject?.ProjectId}", entity);
if (res.code == 200)
{
//return res.info;
return null;
}
else
{
return res.info; // 返回错误信息
}
}
/// <summary>
/// 创建、修改 端子排和端子(一般是为非监测设备的端子排)
/// </summary>
/// <param name="entity"></param>
/// <param name="projId"></param>
public async Task<object> SavePanelStripNoChannel(ec_PanelStrip entity)
{
var res = await this.PostBodyAsync<ec_PanelStrip, ec_PanelStrip>($"IOModuleApi/SavePanelStripNoChannel?projId={GlobalObject.curProject?.ProjectId}", entity);
if (res.code == 200)
{
//return res.info;
return res.data;
}
else
{
return null; // 返回错误信息
}
}
/// <summary>
/// 查询所有的电缆
/// </summary>
/// <param name="projId"></param>
/// <param name="homerun">true或false</param>
/// <returns></returns>
public async Task<List<ec_Cable>> GetCables(bool homerun = true)
{
var res = await this.GetAsync<List<ec_Cable>>($"IOModuleApi/GetCables?projId={GlobalObject.curProject?.ProjectId}&homerun={homerun}");
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// 根据ID拿。只查询ec panel表本身
/// </summary>
/// <param name="PanelID"></param>
/// <param name="projId"></param>
/// <returns></returns>
public async Task<ec_Panel> GetPanel(string PanelID)
{
var res = await this.GetAsync<ec_Panel>($"IOModuleApi/GetPanel?PanelID={PanelID}&projId={GlobalObject.curProject?.ProjectId}");
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// 通过预设模式,批量创建端子排 通道 端子
/// </summary>
/// <param name="entity"></param>
/// <param name="projId"></param>
public async Task<object> CreatePanelStripByProfile(ec_PanelStrip entity)
{
var res = await this.PostBodyAsync<ec_PanelStrip, ec_PanelStrip>($"IOModuleApi/CreatePanelStripByProfile?projId={GlobalObject.curProject?.ProjectId}", entity);
//if (res.code == 200)
//{
// //return res.info;
// return null;
//}
//else
//{
// return res.info; // 返回错误信息
//}
return res;
}
public async Task<string> DeletePanel(string PanelID)
{
var res = await this.PostBodyAsync<object,string>($"IOModuleApi/DeletePanel?PanelID={PanelID}&ProjectId={GlobalObject.curProject?.ProjectId}", null);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
public async Task<string> DeletePanelStrip(string StripID)
{
var res = await this.PostBodyAsync<object, string>($"IOModuleApi/DeletePanelStrip?StripID={StripID}&ProjectId={GlobalObject.curProject?.ProjectId}", null);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
/// <summary>
/// 根据通道id来删除
/// </summary>
/// <param name="keyValue"></param>
/// <param name="ProjectId"></param>
public async Task<string> DeletePanelChannel(string ChannelID)
{
var res = await this.PostBodyAsync<object, string>($"IOModuleApi/DeletePanelChannel?ProjectId={GlobalObject.curProject?.ProjectId}&ChannelID={ChannelID}", null);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
/// <summary>
/// 根据电缆id来删除
/// </summary>
/// <param name="keyValue"></param>
/// <param name="ProjectId"></param>
public async Task<string> DeleteCableProfile(string CableID)
{
var res = await this.PostBodyAsync<object, string>($"IOModuleApi/DeleteCableProfile?CableID={CableID}&ProjectId={GlobalObject.curProject?.ProjectId}", null);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
/// <summary>
/// 根据EngineerDataID拿。包括set wire以及from to信息
/// </summary>
/// <param name="EngineerDataID"></param>
/// <param name="projId"></param>
/// <param name="OnlySelf"></param>
/// <param name="PreAssign"></param>
/// <returns></returns>
public async Task<ec_Cable> GetCableByEngID(string EngineerDataID,bool OnlySelf = false, bool PreAssign = false)
{
var res = await this.GetAsync<ec_Cable>($"IOModuleApi/GetCableByEngID?EngineerDataID={EngineerDataID}&projId={GlobalObject.curProject?.ProjectId}&OnlySelf{OnlySelf}&PreAssign{PreAssign}");
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// 新增或者修改。
/// 新建相当于强行因为正常流程是和engineerdata一起新建出来的。
/// 改的话只是改location和端子排数量这些。常规属性依旧通过objectTypeAPI去做
/// </summary>
/// <param name="entity"></param>
/// <param name="projId"></param>
/// <returns></returns>
public async Task<string> SavePanel(ec_Panel entity)
{
var res = await this.PostBodyAsync<object, ec_Panel>($"IOModuleApi/SavePanel?projId={GlobalObject.curProject?.ProjectId}", entity);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
/// <summary>
/// 查询所有需要预分配的电缆
/// </summary>
/// <param name="projId"></param>
/// <returns></returns>
public async Task<List<ec_Cable>> GetCablePreAssignPreview()
{
var res = await this.GetAsync<List<ec_Cable>>($"IOModuleApi/GetCablePreAssignPreview?projId={GlobalObject.curProject?.ProjectId}");
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// GetCableByEngID先去判断这个cable是否已经有了IO Module这边的记录
/// 电缆-端子连接,从图面上选择一个电缆对象
/// </summary>
/// <param name="projId"></param>
public async Task<string> CreateCableByProfile(ec_Cable entity)
{
var res = await this.PostBodyAsync<ec_Cable, ec_Cable>($"IOModuleApi/CreateCableByProfile?projId={GlobalObject.curProject?.ProjectId}", entity);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
public async Task<string> SaveCable(ec_Cable entity)
{
var res = await this.PostBodyAsync<ec_Cable, ec_Cable>($"IOModuleApi/SaveCable?projId={GlobalObject.curProject?.ProjectId}", entity);
if (res.code == 200)
{
return null;
}
else
{
}
return res.info;
}
/// <summary>
/// 处理 接线关系同时对cableset和wire的个别属性进行修改
/// </summary>
/// <param name="projId"></param>
/// <returns></returns>
public async Task<List<ec_WireTerminal>> SaveConnections(Connections entity)
{
var res = await this.PostBodyAsync<List<ec_WireTerminal>, Connections>($"IOModuleApi/SaveConnections?projId={GlobalObject.curProject?.ProjectId}", entity);
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
public async Task<List<ec_Cable>> SaveCables(List<ec_Cable> entitys)
{
var res = await this.PostBodyAsync<List<ec_Cable>, List<ec_Cable>>($"IOModuleApi/SaveCables?projId={GlobalObject.curProject?.ProjectId}", entitys);
if (res.code == 200)
{
return res.data;
}
else
{
}
return null;
}
/// <summary>
/// SaveConnections 专用
/// </summary>
public class Connections
{
public string ID { get; set; }
public List<ec_WireTerminal> Conns { get; set; }
}
}
}