DishProvider.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. using ivf_tl_Entity.Entity;
  2. using ivf_tl_Entity.Entity.balance;
  3. using ivf_tl_Entity.Entity.Mark;
  4. using ivf_tl_Entity.Entity.Result;
  5. using ivf_tl_Entity.Enums;
  6. using ivf_tl_Entity.Response;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Security.Policy;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace ivf_tl_Service.HttpProvider
  15. {
  16. public class DishProvider
  17. {
  18. LogService LogService { get; set; }
  19. HttpServiceCall httpServiceCall1 { get; set; }
  20. public DishProvider(HttpServiceCall _httpServiceCall, LogService _logService)
  21. {
  22. httpServiceCall1 = _httpServiceCall;
  23. LogService = _logService;
  24. }
  25. private void ExLog(Exception ex, string name)
  26. {
  27. LogService.ExceptionLog(ex, $"DishProvider.{name}", LogEnum.RunException);
  28. }
  29. private void ErrorLog(string message, LogEnum logType)
  30. {
  31. LogService.TLLog($"DishProvider.{message}", logType);
  32. }
  33. /// <summary>
  34. /// 设备管理 - 设备列表
  35. /// </summary>
  36. /// <returns></returns>
  37. public List<TLInfo> GetTlInfoList()
  38. {
  39. string funcName = "GetTlInfoList";
  40. string resultString = string.Empty;
  41. try
  42. {
  43. string url = "/api/businessManage/pc/embryoCultureRecord/getTlInfoList";
  44. resultString = httpServiceCall1.callWebService(url);
  45. if (string.IsNullOrEmpty(resultString)) return new List<TLInfo>();
  46. var result = JsonConvert.DeserializeObject<ResultEntity<List<TLInfo>>>(resultString);
  47. if (!result.success)
  48. {
  49. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  50. return new List<TLInfo>();
  51. }
  52. if (result.data != null) return result.data;
  53. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  54. return new List<TLInfo>();
  55. }
  56. catch (Exception ex)
  57. {
  58. ExLog(ex, $"{funcName}:[resultString:{resultString}]");
  59. return new List<TLInfo>();
  60. }
  61. }
  62. /// <summary>
  63. /// 患者培养接口 开始培养-添加患者信息
  64. /// </summary>
  65. /// <param name="dish"></param>
  66. /// <returns></returns>
  67. public string StartDish(Dish dish)
  68. {
  69. string name = "StartDish";
  70. try
  71. {
  72. string url = "/api/businessManage/pc/embryoCultureRecord/addCultureRecord";
  73. string body = JsonConvert.SerializeObject(dish);
  74. string json = httpServiceCall1.callWebService(url, body);
  75. if (string.IsNullOrEmpty(json)) return "服务器返回空";
  76. var result = JsonConvert.DeserializeObject<ResultEntity>(json);
  77. if (!result.success)
  78. {
  79. ErrorLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  80. return result.message;
  81. }
  82. return null;
  83. }
  84. catch (Exception ex)
  85. {
  86. ExLog(ex, name);
  87. return ex.Message;
  88. }
  89. }
  90. /// <summary>
  91. /// 患者培养接口 编辑患者信息
  92. /// </summary>
  93. /// <param name="body"></param>
  94. /// <returns></returns>
  95. public string UpDataDish(string body)
  96. {
  97. string name = "UpDataDish";
  98. try
  99. {
  100. string url = "/api/businessManage/pc/embryoCultureRecord/updateCultureRecord";
  101. string json = httpServiceCall1.callWebService(url, body);
  102. if (string.IsNullOrEmpty(json)) return "服务器返回空";
  103. var result = JsonConvert.DeserializeObject<ResultEntity>(json);
  104. if (!result.success)
  105. {
  106. ErrorLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  107. return result.message;
  108. }
  109. return null;
  110. }
  111. catch (Exception ex)
  112. {
  113. ExLog(ex, name);
  114. return ex.Message;
  115. }
  116. }
  117. /// <summary>
  118. /// 舱室平衡接口 舱室列表-开始平衡
  119. /// </summary>
  120. /// <param name="dish"></param>
  121. /// <returns></returns>
  122. public string StartBalance(string tlSn, int houseSn)
  123. {
  124. string name = "StartBalance";
  125. try
  126. {
  127. string url = "/api/businessManage/pc/balance/startBalance";
  128. string body = JsonConvert.SerializeObject(new { tlSn = tlSn, houseSn = houseSn });
  129. string json = httpServiceCall1.callWebService(url, body);
  130. if (string.IsNullOrEmpty(json)) return "服务器返回空";
  131. var result = JsonConvert.DeserializeObject<ResultEntity>(json);
  132. if (!result.success)
  133. {
  134. ErrorLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  135. return result.message;
  136. }
  137. return null;
  138. }
  139. catch (Exception ex)
  140. {
  141. ExLog(ex, name);
  142. return ex.Message;
  143. }
  144. }
  145. /// <summary>
  146. /// 舱室平衡接口 舱室列表-结束平衡
  147. /// </summary>
  148. /// <param name="dish"></param>
  149. /// <returns></returns>
  150. public string StopBalance(long id)
  151. {
  152. string name = "StopBalance";
  153. try
  154. {
  155. string url = "/api/businessManage/pc/balance/stopBalance";
  156. string body = JsonConvert.SerializeObject(new { id = id });
  157. string json = httpServiceCall1.callWebService(url, body);
  158. if (string.IsNullOrEmpty(json)) return "服务器返回空";
  159. var result = JsonConvert.DeserializeObject<ResultEntity>(json);
  160. if (!result.success)
  161. {
  162. ErrorLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  163. return result.message;
  164. }
  165. return null;
  166. }
  167. catch (Exception ex)
  168. {
  169. ExLog(ex, name);
  170. return ex.Message;
  171. }
  172. }
  173. public List<PictureEntity> GetNewPicApi(string tlsn, int housesn, List<long> wellList)
  174. {
  175. string name = "GetNewPicApi";
  176. try
  177. {
  178. string url = "/api/businessManage/pc/resource/getEmbryosLastPictures";
  179. string body = JsonConvert.SerializeObject(new
  180. {
  181. tlSn = tlsn,
  182. houseSn = housesn,
  183. embryoIds = wellList,
  184. });
  185. string json = httpServiceCall1.callWebService(url, body);
  186. if (string.IsNullOrEmpty(json)) return new List<PictureEntity>();
  187. var result = JsonConvert.DeserializeObject<ResultEntity<List<PictureEntity>>>(json);
  188. if (!result.success)
  189. {
  190. ErrorLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  191. return new List<PictureEntity>();
  192. }
  193. if (result.data != null && result.data.Any()) return result.data;
  194. ErrorLog($"{name}接口返回成功但是无数据 {json}", LogEnum.RunError);
  195. return new List<PictureEntity>();
  196. }
  197. catch (Exception ex)
  198. {
  199. ExLog(ex, name);
  200. return new List<PictureEntity>();
  201. }
  202. }
  203. /// <summary>
  204. /// 患者培养接口 培养记录 - 分页查询
  205. /// </summary>
  206. /// <returns></returns>
  207. public DishRecordResult SearchDishRecordApi(SearchDishRecordResponse searchDishRecord)
  208. {
  209. string funcName = "SearchDishRecordApi";
  210. try
  211. {
  212. string url = "/api/businessManage/pc/embryoCultureRecord/getEmbryoCultureRecord";
  213. string body = JsonConvert.SerializeObject(searchDishRecord, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
  214. string resultString = httpServiceCall1.callWebService(url, body);
  215. if (string.IsNullOrEmpty(resultString)) return new DishRecordResult() { IsSuccess = false };
  216. var rs = JsonConvert.DeserializeObject<ResultEntity<DishRecordResult>>(resultString);
  217. if (!rs.success)
  218. {
  219. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  220. return new DishRecordResult() { IsSuccess = false };
  221. }
  222. if (rs.data != null) return rs.data;
  223. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  224. return new DishRecordResult();
  225. }
  226. catch (Exception ex)
  227. {
  228. ExLog(ex, funcName);
  229. return new DishRecordResult() { IsSuccess = false };
  230. }
  231. }
  232. /// <summary>
  233. /// 患者培养接口 培养记录 - 查询数量
  234. /// </summary>
  235. /// <returns></returns>
  236. public AlarmHistoryNumResult SearchDishRecordNumApi(SearchDishRecordResponse searchDishRecord)
  237. {
  238. string funcName = "SearchDishRecordNumApi";
  239. try
  240. {
  241. string url = "/api/businessManage/pc/embryoCultureRecord/getEmbryoCultureRecordNum";
  242. string body = JsonConvert.SerializeObject(searchDishRecord, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
  243. string resultString = httpServiceCall1.callWebService(url, body);
  244. if (string.IsNullOrEmpty(resultString)) return new AlarmHistoryNumResult();
  245. var rs = JsonConvert.DeserializeObject<ResultEntity<AlarmHistoryNumResult>>(resultString);
  246. if (!rs.success)
  247. {
  248. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  249. return new AlarmHistoryNumResult();
  250. }
  251. if (rs.data != null) return rs.data;
  252. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  253. return new AlarmHistoryNumResult();
  254. }
  255. catch (Exception ex)
  256. {
  257. ExLog(ex, funcName);
  258. return new AlarmHistoryNumResult();
  259. }
  260. }
  261. /// <summary>
  262. /// 患者培养接口 患者管理 - 详情
  263. /// </summary>
  264. /// <returns></returns>
  265. public Dish GetDishByIdApi(long id)
  266. {
  267. string funcName = "GetDishByIdApi";
  268. try
  269. {
  270. string url = "/api/businessManage/pc/embryoCultureRecord/getCultureRecordById";
  271. Dictionary<string, string> body = new Dictionary<string, string> { { "id", id.ToString() } };
  272. string resultString = httpServiceCall1.callWebService(url, body);
  273. if (string.IsNullOrEmpty(resultString)) return new Dish();
  274. var rs = JsonConvert.DeserializeObject<ResultEntity<Dish>>(resultString);
  275. if (!rs.success)
  276. {
  277. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  278. return new Dish();
  279. }
  280. if (rs.data != null) return rs.data;
  281. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  282. return new Dish();
  283. }
  284. catch (Exception ex)
  285. {
  286. ExLog(ex, funcName);
  287. return new Dish();
  288. }
  289. }
  290. public string DeleteDishRecordApi(long id)
  291. {
  292. string name = "DeleteDishRecordApi";
  293. try
  294. {
  295. string url = "/api/businessManage/pc/embryoCultureRecord/deleteEmbryoCultureRecord";
  296. Dictionary<string, string> body = new Dictionary<string, string>() { { "id", id.ToString() } };
  297. string json = httpServiceCall1.callWebService(url, body);
  298. if (string.IsNullOrEmpty(json)) return "服务器返回空";
  299. var result = JsonConvert.DeserializeObject<ResultEntity>(json);
  300. if (!result.success)
  301. {
  302. ErrorLog($"{name}服务器返回失败 {json}", LogEnum.RunError);
  303. return result.message;
  304. }
  305. return null;
  306. }
  307. catch (Exception ex)
  308. {
  309. ExLog(ex, name);
  310. return ex.Message;
  311. }
  312. }
  313. public byte[] GetImageByte(string imageUrl)
  314. {
  315. string funcName = "GetImageByte";
  316. try
  317. {
  318. return httpServiceCall1.GetImageByteApi(imageUrl);
  319. }
  320. catch (Exception ex)
  321. {
  322. ExLog(ex, funcName);
  323. return null;
  324. }
  325. }
  326. public ReportMarkData GetCultureRecordDetailByIdApi(long id)
  327. {
  328. string funcName = "GetCultureRecordDetailByIdApi";
  329. try
  330. {
  331. string url = "/api/businessManage/pc/embryoCultureRecord/getCultureRecordDetailById";
  332. Dictionary<string, string> body = new Dictionary<string, string>();
  333. body.Add("id", id.ToString());
  334. string resultString = httpServiceCall1.callWebService(url, body);
  335. if (string.IsNullOrEmpty(resultString)) return null;
  336. ResultEntity<ReportMarkData> rs = JsonConvert.DeserializeObject<ResultEntity<ReportMarkData>>(resultString);
  337. if (!rs.success)
  338. {
  339. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  340. return null;
  341. }
  342. if (rs.data != null) return rs.data;
  343. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  344. return null;
  345. }
  346. catch (Exception ex)
  347. {
  348. ExLog(ex, funcName);
  349. return null;
  350. }
  351. }
  352. }
  353. }