TLInfoProvider.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using ivf_tl_Entity.Entity;
  2. using ivf_tl_Entity.Entity.balance;
  3. using ivf_tl_Entity.Entity.BinSetting;
  4. using ivf_tl_Entity.Entity.Mark;
  5. using ivf_tl_Entity.Entity.Result;
  6. using ivf_tl_Entity.Enums;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Xml.Linq;
  15. namespace ivf_tl_Service.HttpProvider
  16. {
  17. /// <summary>
  18. /// 下位机控制软件-TL设备信息接口
  19. /// </summary>
  20. public class TLInfoProvider
  21. {
  22. LogService LogService { get; set; }
  23. HttpServiceCall httpServiceCall1 { get; set; }
  24. public TLInfoProvider(HttpServiceCall _httpServiceCall, LogService _logService)
  25. {
  26. httpServiceCall1 = _httpServiceCall;
  27. LogService = _logService;
  28. }
  29. private void ExLog(Exception ex, string name)
  30. {
  31. LogService.ExceptionLog(ex, $"TLInfoProvider.{name}", LogEnum.RunException);
  32. }
  33. private void MessageLog(string mesage, LogEnum typeLog)
  34. {
  35. LogService.TLLog($"TLInfoProvider.{mesage}", typeLog);
  36. }
  37. /// <summary>
  38. /// 修改回显 - 通过id查询TlInfo信息
  39. /// </summary>
  40. /// <param name="id"></param>
  41. /// <returns></returns>
  42. public TLSettingInfo GetTlInfoById(long id)
  43. {
  44. string name = "GetTlInfoById";
  45. try
  46. {
  47. string url = "/api/tl/control/tlInfo/getTlInfoById";
  48. Dictionary<string, string> body = new Dictionary<string, string>();
  49. body.Add("id", id.ToString());
  50. string json = httpServiceCall1.callWebService(url, body);
  51. if (string.IsNullOrEmpty(json)) return new TLSettingInfo();
  52. var result = JsonConvert.DeserializeObject<ResultEntity<TLSettingInfo>>(json);
  53. if (!result.success)
  54. {
  55. MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  56. return new TLSettingInfo();
  57. }
  58. if (result.data != null) return result.data;
  59. MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
  60. return new TLSettingInfo();
  61. }
  62. catch (Exception ex)
  63. {
  64. ExLog(ex, name);
  65. return new TLSettingInfo();
  66. }
  67. }
  68. /// <summary>
  69. /// 修改TL设备信息
  70. /// </summary>
  71. /// <param name="address"></param>
  72. /// <param name="addressId"></param>
  73. /// <param name="id"></param>
  74. /// <param name="installTime"></param>
  75. /// <param name="remark"></param>
  76. /// <param name="tlName"></param>
  77. /// <returns></returns>
  78. public string TLInfoUpdate(string address, long addressId, long id, string installTime, string remark, string tlName, string collectSn, string collectName)
  79. {
  80. string name = "TLInfoUpdate";
  81. try
  82. {
  83. string url = "/api/tl/control/tlInfo/update";
  84. string body = JsonConvert.SerializeObject(new
  85. {
  86. address = address,
  87. addressId = addressId,
  88. installTime = installTime,
  89. remark = remark,
  90. tlName = tlName,
  91. id = id,
  92. collectSn,
  93. collectName
  94. });
  95. string json = httpServiceCall1.callWebService(url, body);
  96. if (string.IsNullOrEmpty(json)) return "服务器返回空";
  97. var result = JsonConvert.DeserializeObject<ResultEntity<TLSettingInfo>>(json);
  98. if (!result.success)
  99. {
  100. MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  101. return result.message;
  102. }
  103. return null;
  104. }
  105. catch (Exception ex)
  106. {
  107. ExLog(ex, name);
  108. return ex.Message;
  109. }
  110. }
  111. /// <summary>
  112. /// 获取指定tl的培养中的信息
  113. /// </summary>
  114. /// <param name="tlSn"></param>
  115. /// <returns></returns>
  116. public EmbryoDataResult GetEmbryoData(string tlSn)
  117. {
  118. string name = "GetEmbryoData";
  119. try
  120. {
  121. string url = "/api/businessManage/pc/embryo/embryo/data";
  122. Dictionary<string, string> body = new Dictionary<string, string>();
  123. body.Add("tlSn", tlSn);
  124. string json = httpServiceCall1.callWebService(url, body);
  125. if (string.IsNullOrEmpty(json)) return new EmbryoDataResult();
  126. var result = JsonConvert.DeserializeObject<ResultEntity<EmbryoDataResult>>(json);
  127. if (!result.success)
  128. {
  129. MessageLog($"{name}服务器返回失败{json}", LogEnum.RunError);
  130. return new EmbryoDataResult();
  131. }
  132. if (result.data != null) return result.data;
  133. MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
  134. return new EmbryoDataResult();
  135. }
  136. catch (Exception ex)
  137. {
  138. ExLog(ex, name);
  139. return new EmbryoDataResult();
  140. }
  141. }
  142. /// <summary>
  143. /// 患者培养接口 患者管理 - 舱室列表
  144. /// </summary>
  145. /// <param name="tlSn"></param>
  146. /// <returns></returns>
  147. public GetHouseCultureListResult GetHouseCultureList(string tlSn)
  148. {
  149. string name = "GetHouseCultureList";
  150. try
  151. {
  152. string url = "/api/businessManage/pc/embryoCultureRecord/getHouseCultureList";
  153. Dictionary<string, string> body = new Dictionary<string, string>();
  154. body.Add("tlSn", tlSn);
  155. string json = httpServiceCall1.callWebService(url, body);
  156. if (string.IsNullOrEmpty(json)) return null;
  157. var result = JsonConvert.DeserializeObject<ResultEntity<GetHouseCultureListResult>>(json);
  158. if (!result.success)
  159. {
  160. MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  161. return null;
  162. }
  163. if (result.data != null) return result.data;
  164. MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
  165. return null;
  166. }
  167. catch (Exception ex)
  168. {
  169. ExLog(ex, name);
  170. return null;
  171. }
  172. }
  173. public List<SettingEntity> GetBinSetting(string tlSn, string houseSn, string startTime, string endTime)
  174. {
  175. string name = "getHouseEnviroment";
  176. try
  177. {
  178. string url = "/api/tl/control/houseCollect/getHouseEnviroment";
  179. string body = JsonConvert.SerializeObject(new { tlSn, houseSn, startTime, endTime });
  180. string json = httpServiceCall1.callWebService(url, body);
  181. if (string.IsNullOrEmpty(json)) return null;
  182. var result = JsonConvert.DeserializeObject<ResultEntity<List<SettingEntity>>>(json);
  183. if (!result.success)
  184. {
  185. MessageLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  186. return null;
  187. }
  188. if (result.data != null) return result.data;
  189. MessageLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
  190. return null;
  191. }
  192. catch (Exception ex)
  193. {
  194. ExLog(ex, name);
  195. return null;
  196. }
  197. }
  198. public HouseChartEntity GetHouseEnvironmentListApi(string tlSn, string houseSn, string startTime, string endTime)
  199. {
  200. string name = "GetHouseEnvironmentListApi";
  201. try
  202. {
  203. string url = "/api/tl/control/houseCollect/getHouseEnvironmentList";
  204. string resultString = httpServiceCall1.callWebService(url, JsonConvert.SerializeObject(new { tlSn, houseSn, startTime, endTime }));
  205. if (string.IsNullOrEmpty(resultString)) return new HouseChartEntity();
  206. var rs = JsonConvert.DeserializeObject<ResultEntity<HouseChartEntity>>(resultString);
  207. if (!rs.success)
  208. {
  209. MessageLog($"{name}服务器返回失败 {resultString}", LogEnum.RunError);
  210. return null;
  211. }
  212. if (rs.data != null) return rs.data;
  213. MessageLog($"{name}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  214. return new HouseChartEntity();
  215. }
  216. catch (Exception ex)
  217. {
  218. ExLog(ex, name);
  219. return new HouseChartEntity();
  220. }
  221. }
  222. public bool DeleteTlByIdApi(long id)
  223. {
  224. string name = "DeleteTlByIdApi";
  225. try
  226. {
  227. string url = "/api/tl/control/tlInfo/deleteTlById";
  228. string resultString = httpServiceCall1.callWebService(url, new Dictionary<string, string> { { "id", id.ToString() } });
  229. if (string.IsNullOrEmpty(resultString)) return false;
  230. var rs = JsonConvert.DeserializeObject<ResultEntity<HouseChartEntity>>(resultString);
  231. if (!rs.success)
  232. {
  233. MessageLog($"{name}服务器返回失败{resultString}", LogEnum.RunError);
  234. return false;
  235. }
  236. return true;
  237. }
  238. catch (Exception ex)
  239. {
  240. ExLog(ex, name);
  241. return false;
  242. }
  243. }
  244. public bool HiddenTLByIdAPi(long id)
  245. {
  246. string name = "HiddenTLByIdAPi";
  247. try
  248. {
  249. string url = "/api/tl/control/tlInfo/removeTlById";
  250. string resultString = httpServiceCall1.callWebService(url, new Dictionary<string, string> { { "id", id.ToString() } });
  251. if (string.IsNullOrEmpty(resultString)) return false;
  252. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  253. if (!rs.success)
  254. {
  255. MessageLog($"{name}服务器返回失败{resultString}", LogEnum.RunError);
  256. return false;
  257. }
  258. return true;
  259. }
  260. catch (Exception ex)
  261. {
  262. ExLog(ex, name);
  263. return false;
  264. }
  265. }
  266. }
  267. }