using ivf_tl_Entity.Entity;
using ivf_tl_Entity.Entity.balance;
using ivf_tl_Entity.Entity.BinSetting;
using ivf_tl_Entity.Entity.Mark;
using ivf_tl_Entity.Entity.Result;
using ivf_tl_Entity.Enums;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ivf_tl_Service.HttpProvider
{
///
/// 下位机控制软件-TL设备信息接口
///
public class TLInfoProvider
{
LogService LogService { get; set; }
HttpServiceCall httpServiceCall1 { get; set; }
public TLInfoProvider(HttpServiceCall _httpServiceCall, LogService _logService)
{
httpServiceCall1 = _httpServiceCall;
LogService = _logService;
}
private void ExLog(Exception ex, string name)
{
LogService.ExceptionLog(ex, $"TLInfoProvider.{name}", LogEnum.RunException);
}
private void MessageLog(string mesage, LogEnum typeLog)
{
LogService.TLLog($"TLInfoProvider.{mesage}", typeLog);
}
///
/// 修改回显 - 通过id查询TlInfo信息
///
///
///
public TLSettingInfo GetTlInfoById(long id)
{
string name = "GetTlInfoById";
try
{
string url = "/api/tl/control/tlInfo/getTlInfoById";
Dictionary body = new Dictionary();
body.Add("id", id.ToString());
string json = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(json)) return new TLSettingInfo();
var result = JsonConvert.DeserializeObject>(json);
if (!result.success)
{
MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
return new TLSettingInfo();
}
if (result.data != null) return result.data;
MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
return new TLSettingInfo();
}
catch (Exception ex)
{
ExLog(ex, name);
return new TLSettingInfo();
}
}
///
/// 修改TL设备信息
///
///
///
///
///
///
///
///
public string TLInfoUpdate(string address, long addressId, long id, string installTime, string remark, string tlName, string collectSn, string collectName)
{
string name = "TLInfoUpdate";
try
{
string url = "/api/tl/control/tlInfo/update";
string body = JsonConvert.SerializeObject(new
{
address = address,
addressId = addressId,
installTime = installTime,
remark = remark,
tlName = tlName,
id = id,
collectSn,
collectName
});
string json = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(json)) return "服务器返回空";
var result = JsonConvert.DeserializeObject>(json);
if (!result.success)
{
MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
return result.message;
}
return null;
}
catch (Exception ex)
{
ExLog(ex, name);
return ex.Message;
}
}
///
/// 获取指定tl的培养中的信息
///
///
///
public EmbryoDataResult GetEmbryoData(string tlSn)
{
string name = "GetEmbryoData";
try
{
string url = "/api/businessManage/pc/embryo/embryo/data";
Dictionary body = new Dictionary();
body.Add("tlSn", tlSn);
string json = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(json)) return new EmbryoDataResult();
var result = JsonConvert.DeserializeObject>(json);
if (!result.success)
{
MessageLog($"{name}服务器返回失败{json}", LogEnum.RunError);
return new EmbryoDataResult();
}
if (result.data != null) return result.data;
MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
return new EmbryoDataResult();
}
catch (Exception ex)
{
ExLog(ex, name);
return new EmbryoDataResult();
}
}
///
/// 患者培养接口 患者管理 - 舱室列表
///
///
///
public GetHouseCultureListResult GetHouseCultureList(string tlSn)
{
string name = "GetHouseCultureList";
try
{
string url = "/api/businessManage/pc/embryoCultureRecord/getHouseCultureList";
Dictionary body = new Dictionary();
body.Add("tlSn", tlSn);
string json = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(json)) return null;
var result = JsonConvert.DeserializeObject>(json);
if (!result.success)
{
MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
return null;
}
if (result.data != null) return result.data;
MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
return null;
}
catch (Exception ex)
{
ExLog(ex, name);
return null;
}
}
public List GetBinSetting(string tlSn, string houseSn, string startTime, string endTime)
{
string name = "getHouseEnviroment";
try
{
string url = "/api/tl/control/houseCollect/getHouseEnviroment";
string body = JsonConvert.SerializeObject(new { tlSn, houseSn, startTime, endTime });
string json = httpServiceCall1.callWebService(url, body);
if (string.IsNullOrEmpty(json)) return null;
var result = JsonConvert.DeserializeObject>>(json);
if (!result.success)
{
MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
return null;
}
if (result.data != null) return result.data;
MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
return null;
}
catch (Exception ex)
{
ExLog(ex, name);
return null;
}
}
public HouseChartEntity GetHouseEnvironmentListApi(string tlSn, string houseSn, string startTime, string endTime)
{
string name = "GetHouseEnvironmentListApi";
try
{
string url = "/api/tl/control/houseCollect/getHouseEnvironmentList";
string resultString = httpServiceCall1.callWebService(url, JsonConvert.SerializeObject(new { tlSn, houseSn, startTime, endTime }));
if (string.IsNullOrEmpty(resultString)) return new HouseChartEntity();
var rs = JsonConvert.DeserializeObject>(resultString);
if (!rs.success)
{
MessageLog($"{name}服务器返回失败 {resultString}", LogEnum.RunError);
return null;
}
if (rs.data != null) return rs.data;
MessageLog($"{name}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
return new HouseChartEntity();
}
catch (Exception ex)
{
ExLog(ex, name);
return new HouseChartEntity();
}
}
public bool DeleteTlByIdApi(long id)
{
string name = "DeleteTlByIdApi";
try
{
string url = "/api/tl/control/tlInfo/deleteTlById";
string resultString = httpServiceCall1.callWebService(url, new Dictionary { { "id", id.ToString() } });
if (string.IsNullOrEmpty(resultString)) return false;
var rs = JsonConvert.DeserializeObject>(resultString);
if (!rs.success)
{
MessageLog($"{name}服务器返回失败{resultString}", LogEnum.RunError);
return false;
}
return true;
}
catch (Exception ex)
{
ExLog(ex, name);
return false;
}
}
public bool HiddenTLByIdAPi(long id)
{
string name = "HiddenTLByIdAPi";
try
{
string url = "/api/tl/control/tlInfo/removeTlById";
string resultString = httpServiceCall1.callWebService(url, new Dictionary { { "id", id.ToString() } });
if (string.IsNullOrEmpty(resultString)) return false;
var rs = JsonConvert.DeserializeObject(resultString);
if (!rs.success)
{
MessageLog($"{name}服务器返回失败{resultString}", LogEnum.RunError);
return false;
}
return true;
}
catch (Exception ex)
{
ExLog(ex, name);
return false;
}
}
}
}