HouseProvider.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using ivf_tl_Entity.Entity.HouseSetting;
  2. using ivf_tl_Entity.Entity.Result;
  3. using ivf_tl_Entity.Enums;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ivf_tl_Service.HttpProvider
  11. {
  12. public class HouseProvider
  13. {
  14. LogService LogService { get; set; }
  15. HttpServiceCall httpServiceCall1 { get; set; }
  16. public HouseProvider(HttpServiceCall _httpServiceCall, LogService _logService)
  17. {
  18. httpServiceCall1 = _httpServiceCall;
  19. LogService = _logService;
  20. }
  21. private void ExLog(Exception ex, string name)
  22. {
  23. LogService.ExceptionLog(ex, $"HouseProvider.{name}", LogEnum.RunException);
  24. }
  25. private void ErrorLog(string message, LogEnum logType)
  26. {
  27. LogService.TLLog($"HouseProvider.{message}", logType);
  28. }
  29. /// <summary>
  30. /// 获取对焦参数设置
  31. /// </summary>
  32. /// <param name="tlsn"></param>
  33. public List<AutoFocusHouseInfo> GetFocusSettingApi(string tlsn)
  34. {
  35. string funcName = "GetFocusSettingApi";
  36. try
  37. {
  38. string url = "/api/tl/control/setting/house/focus/setting";
  39. Dictionary<string, string> body = new Dictionary<string, string>();
  40. body.Add("tlSn", tlsn);
  41. string resultString = httpServiceCall1.callWebService(url, body);
  42. if (string.IsNullOrEmpty(resultString)) return new List<AutoFocusHouseInfo>();
  43. ResultEntity<List<AutoFocusHouseInfo>> rs = JsonConvert.DeserializeObject<ResultEntity<List<AutoFocusHouseInfo>>>(resultString);
  44. if (!rs.success)
  45. {
  46. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  47. return new List<AutoFocusHouseInfo>();
  48. }
  49. if (rs.data != null) return rs.data;
  50. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  51. return new List<AutoFocusHouseInfo>();
  52. }
  53. catch (Exception ex)
  54. {
  55. ExLog(ex, funcName);
  56. return new List<AutoFocusHouseInfo>();
  57. }
  58. }
  59. /// <summary>
  60. /// 获取指定tlSn的tl通用设置
  61. /// </summary>
  62. /// <param name="tlsn"></param>
  63. public TLSettingCommon GetSettingCommonApi(string tlsn)
  64. {
  65. string funcName = "GetSettingCommonApi";
  66. try
  67. {
  68. string url = "/api/tl/control/setting/common";
  69. Dictionary<string, string> body = new Dictionary<string, string>();
  70. body.Add("tlSn", tlsn);
  71. string resultString = httpServiceCall1.callWebService(url, body);
  72. if (string.IsNullOrEmpty(resultString)) return new TLSettingCommon();
  73. ResultEntity<TLSettingCommon> rs = JsonConvert.DeserializeObject<ResultEntity<TLSettingCommon>>(resultString);
  74. if (!rs.success)
  75. {
  76. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  77. return new TLSettingCommon();
  78. }
  79. if (rs.data != null) return rs.data;
  80. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  81. return new TLSettingCommon();
  82. }
  83. catch (Exception ex)
  84. {
  85. ExLog(ex, funcName);
  86. return new TLSettingCommon();
  87. }
  88. }
  89. /// <summary>
  90. /// 更新指定tlSn通用设置
  91. /// </summary>
  92. /// <param name="body"></param>
  93. /// <returns></returns>
  94. public bool UpdateSettingCommonApi(string body)
  95. {
  96. string funcName = "UpdateSettingCommonApi";
  97. try
  98. {
  99. string url = "/api/tl/control/setting/common/update";
  100. string resultString = httpServiceCall1.callWebService(url, body);
  101. if (string.IsNullOrEmpty(resultString)) return false;
  102. ResultEntity rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  103. if (!rs.success)
  104. {
  105. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  106. return false;
  107. }
  108. return true;
  109. }
  110. catch (Exception ex)
  111. {
  112. ExLog(ex, funcName);
  113. return false;
  114. }
  115. }
  116. /// <summary>
  117. /// 获取指定tlSn的系统设置
  118. /// </summary>
  119. /// <param name="tlsn"></param>
  120. /// <returns></returns>
  121. public TLSettingModel GetSettingSystemApi(string tlsn)
  122. {
  123. string funcName = "GetSettingSystemApi";
  124. try
  125. {
  126. string url = "/api/tl/control/setting/system";
  127. Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
  128. keyValuePairs.Add("tlSn", tlsn);
  129. string resultString = httpServiceCall1.callWebService(url, keyValuePairs);
  130. if (string.IsNullOrEmpty(resultString)) return new TLSettingModel();
  131. ResultEntity<TLSettingModel> rs = JsonConvert.DeserializeObject<ResultEntity<TLSettingModel>>(resultString);
  132. if (!rs.success)
  133. {
  134. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  135. return new TLSettingModel();
  136. }
  137. if (rs.data != null) return rs.data;
  138. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  139. return new TLSettingModel();
  140. }
  141. catch (Exception ex)
  142. {
  143. ExLog(ex, funcName);
  144. return new TLSettingModel();
  145. }
  146. }
  147. /// <summary>
  148. /// 更新tlSn的系统设置
  149. /// </summary>
  150. /// <param name="body"></param>
  151. /// <returns></returns>
  152. public bool UpdateSettingSystemApi(string body)
  153. {
  154. string funcName = "UpdateSettingSystemApi";
  155. try
  156. {
  157. string url = "/api/tl/control/setting/system/update";
  158. string resultString = httpServiceCall1.callWebService(url, body);
  159. if (string.IsNullOrEmpty(resultString)) return false;
  160. ResultEntity rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  161. if (!rs.success)
  162. {
  163. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  164. return false;
  165. }
  166. return true;
  167. }
  168. catch (Exception ex)
  169. {
  170. ExLog(ex, funcName);
  171. return false;
  172. }
  173. }
  174. /// <summary>
  175. /// 获取指定tlSn的舱室配置
  176. /// </summary>
  177. /// <param name="tlSn"></param>
  178. /// <returns></returns>
  179. public List<HouseInfo> GetSettingHouseApi(string tlSn)
  180. {
  181. string funcName = "GetSettingHouseApi";
  182. try
  183. {
  184. string url = "/api/tl/control/setting/house";
  185. string body = JsonConvert.SerializeObject(new { tlSn = tlSn, size = 100, current = 1 });
  186. string resultString = httpServiceCall1.callWebService(url, body);
  187. if (string.IsNullOrEmpty(resultString)) return new List<HouseInfo>();
  188. ResultEntity<SettingHouseData> rs = JsonConvert.DeserializeObject<ResultEntity<SettingHouseData>>(resultString);
  189. if (!rs.success)
  190. {
  191. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  192. return new List<HouseInfo>();
  193. }
  194. if (rs.data != null && rs.data.records != null) return rs.data.records;
  195. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  196. return new List<HouseInfo>();
  197. }
  198. catch (Exception ex)
  199. {
  200. ExLog(ex, funcName);
  201. return new List<HouseInfo>();
  202. }
  203. }
  204. public bool UploadLogoApi(byte[] logoBtye, string fileName, string tlsn)
  205. {
  206. string funcName = "UploadLogoApi";
  207. try
  208. {
  209. string url = "/api/tl/control/setting/common/updateLogoFile";
  210. Dictionary<string, string> body = new Dictionary<string, string> { { "tlSn", tlsn } };
  211. string resultString = httpServiceCall1.callWebServiceUpLoad(url, body, logoBtye, fileName);
  212. if (string.IsNullOrEmpty(resultString)) return false;
  213. ResultEntity rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  214. if (!rs.success)
  215. {
  216. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  217. return false;
  218. }
  219. return true;
  220. }
  221. catch (Exception ex)
  222. {
  223. ExLog(ex, funcName);
  224. return false;
  225. }
  226. }
  227. public bool ClearLogoApi(string tlsn)
  228. {
  229. string funcName = "ClearLogoApi";
  230. try
  231. {
  232. string url = "/api/tl/control/setting/common/deleteLogoFile";
  233. string resultString = httpServiceCall1.callWebService(url, new Dictionary<string, string> { { "tlSn",tlsn} });
  234. if (string.IsNullOrEmpty(resultString)) return false;
  235. ResultEntity rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  236. if (!rs.success)
  237. {
  238. ErrorLog($"{funcName}接口返回失败:{resultString}", LogEnum.RunError);
  239. return false;
  240. }
  241. return true;
  242. }
  243. catch (Exception ex)
  244. {
  245. ExLog(ex, funcName);
  246. return false;
  247. }
  248. }
  249. }
  250. }