PicProvider.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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.Pic;
  7. using ivf_tl_Entity.Response;
  8. using Newtonsoft.Json;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace ivf_tl_Service.HttpProvider
  15. {
  16. public class PicProvider
  17. {
  18. LogService LogService { get; set; }
  19. HttpServiceCall httpServiceCall1 { get; set; }
  20. public PicProvider(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, $"PicProvider.{name}", LogEnum.RunException);
  28. }
  29. private void ErrorLog(string message, LogEnum logType)
  30. {
  31. LogService.TLLog($"PicProvider.{message}", logType);
  32. }
  33. /// <summary>
  34. /// 设备数据接口 详情-图片查看(获取原图)
  35. /// </summary>
  36. /// <param name="embryoId"></param>
  37. /// <param name="houseSn"></param>
  38. /// <param name="pictureLayer"></param>
  39. /// <param name="tlSn"></param>
  40. /// <returns></returns>
  41. public List<PictureEntity> GetImageSourceApi(long embryoId, int houseSn, int pictureLayer, string tlSn)
  42. {
  43. string funcName = "GetImageSourceApi";
  44. try
  45. {
  46. string url = "/api/businessManage/pc/resource/getSourcePictures";
  47. string body = JsonConvert.SerializeObject(new
  48. {
  49. embryoId = embryoId,
  50. houseSn = houseSn,
  51. pictureLayer = pictureLayer,
  52. tlSn = tlSn,
  53. });
  54. string resultString = httpServiceCall1.callWebService(url, body);
  55. if (string.IsNullOrEmpty(resultString)) return new List<PictureEntity>();
  56. var rs = JsonConvert.DeserializeObject<ResultEntity<List<PictureEntity>>>(resultString);
  57. if (!rs.success)
  58. {
  59. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  60. return new List<PictureEntity>();
  61. }
  62. if (rs.data != null && rs.data.Any()) return rs.data;
  63. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  64. return new List<PictureEntity>();
  65. }
  66. catch (Exception ex)
  67. {
  68. ExLog(ex, funcName);
  69. return new List<PictureEntity>();
  70. }
  71. }
  72. /// <summary>
  73. /// 设备数据接口 详情-图片查看(获取原图)分页
  74. /// </summary>
  75. /// <param name="embryoId"></param>
  76. /// <param name="houseSn"></param>
  77. /// <param name="pictureLayer"></param>
  78. /// <param name="tlSn"></param>
  79. /// <returns></returns>
  80. public SourcePicPageResult GetImageSourcePageApi(long embryoId, int houseSn, int pictureLayer, string tlSn, int current, int size, List<PhotoBoxSetting1> photoBoxSetting1s)
  81. {
  82. string funcName = "GetImageSourcePageApi";
  83. try
  84. {
  85. string url = "/api/businessManage/pc/resource/getSourcePicturesByPage";
  86. string body = null;
  87. if (photoBoxSetting1s.Any())
  88. {
  89. body = JsonConvert.SerializeObject(new
  90. {
  91. embryoId = embryoId,
  92. houseSn = houseSn,
  93. pictureLayer = pictureLayer,
  94. tlSn = tlSn,
  95. current,
  96. size,
  97. searchButtons = photoBoxSetting1s,
  98. });
  99. }
  100. else
  101. {
  102. body = JsonConvert.SerializeObject(new
  103. {
  104. embryoId = embryoId,
  105. houseSn = houseSn,
  106. pictureLayer = pictureLayer,
  107. tlSn = tlSn,
  108. current,
  109. size
  110. });
  111. }
  112. string resultString = httpServiceCall1.callWebService(url, body);
  113. if (string.IsNullOrEmpty(resultString)) return new SourcePicPageResult();
  114. var rs = JsonConvert.DeserializeObject<ResultEntity<SourcePicPageResult>>(resultString);
  115. if (!rs.success)
  116. {
  117. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  118. return new SourcePicPageResult();
  119. }
  120. if (rs.data != null) return rs.data;
  121. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  122. return new SourcePicPageResult();
  123. }
  124. catch (Exception ex)
  125. {
  126. ExLog(ex, funcName);
  127. return new SourcePicPageResult();
  128. }
  129. }
  130. /// <summary>
  131. /// 设备数据接口 患者管理-详情-获取指定指定well的指定图层图片
  132. /// </summary>
  133. /// <param name="tlsn"></param>
  134. /// <param name="housesn"></param>
  135. /// <param name="dishId"></param>
  136. /// <param name="wellList"></param>
  137. /// <param name="layerList"></param>
  138. /// <returns></returns>
  139. public List<SwitchVideoPictureLayersData> SwitchVideoPictureLayersApi(string tlsn, int housesn, long dishId, List<int> wellList, List<int> layerList)
  140. {
  141. string funcName = "SwitchVideoPictureLayersApi";
  142. try
  143. {
  144. string url = "/api/businessManage/pc/resource/switchVideoPictureLayers";
  145. string body = JsonConvert.SerializeObject(new
  146. {
  147. tlSn = tlsn,
  148. houseSn = housesn,
  149. id = dishId,
  150. wellSnList = wellList,
  151. pictureLayer = layerList
  152. });
  153. string resultString = httpServiceCall1.callWebService(url, body);
  154. if (string.IsNullOrEmpty(resultString)) return new List<SwitchVideoPictureLayersData>();
  155. var rs = JsonConvert.DeserializeObject<ResultEntity<List<SwitchVideoPictureLayersData>>>(resultString);
  156. if (!rs.success)
  157. {
  158. ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
  159. return new List<SwitchVideoPictureLayersData>();
  160. }
  161. if (rs.data != null) return rs.data;
  162. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  163. return new List<SwitchVideoPictureLayersData>();
  164. }
  165. catch (Exception ex)
  166. {
  167. ExLog(ex, funcName);
  168. return new List<SwitchVideoPictureLayersData>();
  169. }
  170. }
  171. public bool DownloadSelectPicturesApi(string tlSn, int houseSn, List<long> ids, string fileName)
  172. {
  173. string funcName = "DownloadSelectPicturesApi";
  174. try
  175. {
  176. string url = "/api/businessManage/pc/resource/downloadSelectPictures";
  177. string body = JsonConvert.SerializeObject(new
  178. {
  179. tlSn = tlSn,
  180. houseSn = houseSn,
  181. ids = ids,
  182. });
  183. return httpServiceCall1.callWebService(url, body, fileName);
  184. }
  185. catch (Exception ex)
  186. {
  187. ExLog(ex, funcName);
  188. return false;
  189. }
  190. }
  191. /// <summary>
  192. /// 下载图片
  193. /// </summary>
  194. /// <param name="sourceFileUrl"></param>
  195. /// <param name="newFile"></param>
  196. /// <returns></returns>
  197. public bool DownloadFileApi(string tlSn, int houseSn, long id, string newFile)
  198. {
  199. string funcName = "DownloadFileApi";
  200. try
  201. {
  202. return httpServiceCall1.DownLoadFileAsync($"/api/businessManage/pc/resource/downloadPicture?tlSn={tlSn}&houseSn={houseSn}&ids={id}", newFile).GetAwaiter().GetResult() == 1;
  203. }
  204. catch (Exception ex)
  205. {
  206. ExLog(ex, funcName);
  207. return false;
  208. }
  209. }
  210. /// <summary>
  211. /// 下载指定well - 指定图层所有图片
  212. /// </summary>
  213. /// <returns></returns>
  214. public bool DownloadLayerPicApi(string body, string newFile,string ss)
  215. {
  216. string funcName = "DownloadLayerPicApi";
  217. try
  218. {
  219. string url = "/api/businessManage/pc/resource/downloadPictures";
  220. return httpServiceCall1.callWebService(url, body, newFile);
  221. }
  222. catch (Exception ex)
  223. {
  224. ExLog(ex, funcName);
  225. return false;
  226. }
  227. }
  228. /// <summary>
  229. /// 下载指定well - 指定图层所有图片
  230. /// </summary>
  231. /// <returns></returns>
  232. public async Task<bool> DownloadLayerPicApi(string tlsn,int housesn,int pic,List<long> ids, string newFile)
  233. {
  234. string funcName = "DownloadLayerPicApi";
  235. try
  236. {
  237. string url = $"/api/businessManage/pc/resource/downloadPictures?houseSn={housesn}&ids={string.Join(",",ids)}&pictureLayer={pic}&tlSn={tlsn}";
  238. url = url.Replace("+", "%2B");
  239. url = url.Replace(",", "%2C");
  240. //var a = await httpServiceCall1.DownLoadFile(url, newFile);
  241. return true;
  242. }
  243. catch (Exception ex)
  244. {
  245. ExLog(ex, funcName);
  246. return false;
  247. }
  248. }
  249. /// <summary>
  250. /// 下载指定well - 指定图层所有图片
  251. /// </summary>
  252. /// <returns></returns>
  253. public async Task<bool> DownloadApi(string url, string newFile)
  254. {
  255. string funcName = "DownloadLayerPicApi";
  256. try
  257. {
  258. url = url.Replace("+", "%2B");
  259. url = url.Replace(",", "%2C");
  260. //var a = await httpServiceCall1.DownLoadFile(url, newFile);
  261. return true;
  262. }
  263. catch (Exception ex)
  264. {
  265. ExLog(ex, funcName);
  266. return false;
  267. }
  268. }
  269. /// <summary>
  270. /// 下载指定well - 指定图层所有图片
  271. /// </summary>
  272. /// <returns></returns>
  273. public bool DownloadLayerVideoApi(string body, string newFile)
  274. {
  275. string funcName = "DownloadLayerVideoApi";
  276. try
  277. {
  278. string url = "/api/businessManage/pc/resource/downloadVideos";
  279. return httpServiceCall1.callWebService(url, body, newFile);
  280. }
  281. catch (Exception ex)
  282. {
  283. ExLog(ex, funcName);
  284. return false;
  285. }
  286. }
  287. public List<PictureView> GetPictureViewApi(string tlSn,int houseSn,long embryoId,int pictureLayer)
  288. {
  289. string funcName = "GetPictureViewApi";
  290. try
  291. {
  292. string url = "/api/businessManage/pc/resource/getPictures";
  293. string body = JsonConvert.SerializeObject(new { tlSn, houseSn, embryoId , pictureLayer });
  294. string resultString = httpServiceCall1.callWebService(url, body);
  295. if (string.IsNullOrEmpty(resultString)) return new List<PictureView>();
  296. var rs = JsonConvert.DeserializeObject<ResultEntity<List<PictureView>>>(resultString);
  297. if (!rs.success)
  298. {
  299. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  300. return new List<PictureView>();
  301. }
  302. if (rs.data != null && rs.data.Any()) return rs.data;
  303. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  304. return new List<PictureView>();
  305. }
  306. catch (Exception ex)
  307. {
  308. ExLog(ex, funcName);
  309. return new List<PictureView>();
  310. }
  311. }
  312. public int GetSourcePicturesTotalLayerApi(string tlSn, int houseSn, long embryoId)
  313. {
  314. string funcName = "GetSourcePicturesTotalLayerApi";
  315. try
  316. {
  317. string url = "/api/businessManage/pc/resource/getSourcePicturesTotalLayer";
  318. string body = JsonConvert.SerializeObject(new { tlSn, houseSn, embryoId });
  319. string resultString = httpServiceCall1.callWebService(url, body);
  320. if (string.IsNullOrEmpty(resultString)) return 0;
  321. var rs = JsonConvert.DeserializeObject<ResultEntity<string>>(resultString);
  322. if (!rs.success)
  323. {
  324. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  325. return 0;
  326. }
  327. if (string.IsNullOrEmpty(rs.data))
  328. {
  329. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  330. return 0;
  331. }
  332. if (int.TryParse(rs.data, out int newValue))
  333. {
  334. return newValue;
  335. }
  336. else
  337. {
  338. ErrorLog($"{funcName}接口返回成功但是结果转int类型失败 {resultString}", LogEnum.RunError);
  339. return 0;
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. ExLog(ex, funcName);
  345. return 0;
  346. }
  347. }
  348. public List<PositionEntity> GetPositionApi(string tlSn, int houseSn, List<int> wellSn)
  349. {
  350. string funcName = "GetPositionApi";
  351. try
  352. {
  353. string url = "/api/tl/control/setting/house/autofocus/position";
  354. string body = JsonConvert.SerializeObject(new { tlSn, houseSn, wellSn });
  355. string resultString = httpServiceCall1.callWebService(url, body);
  356. if (string.IsNullOrEmpty(resultString)) return new List<PositionEntity>();
  357. var rs = JsonConvert.DeserializeObject<ResultEntity<List<PositionEntity>>>(resultString);
  358. if (!rs.success)
  359. {
  360. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  361. return new List<PositionEntity>();
  362. }
  363. if (rs.data != null && rs.data.Any()) return rs.data;
  364. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  365. return new List<PositionEntity>();
  366. }
  367. catch (Exception ex)
  368. {
  369. ExLog(ex, funcName);
  370. return new List<PositionEntity>();
  371. }
  372. }
  373. public AutoFocusResult GetAutofocusPicturesApi(string tlSn, int houseSn, long embryoId)
  374. {
  375. string funcName = "GetAutofocusPicturesApi";
  376. try
  377. {
  378. string url = "/api/businessManage/pc/resource/getAutofocusPictures";
  379. string body = JsonConvert.SerializeObject(new { tlSn, houseSn, embryoId });
  380. string resultString = httpServiceCall1.callWebService(url, body);
  381. if (string.IsNullOrEmpty(resultString)) return new AutoFocusResult();
  382. var rs = JsonConvert.DeserializeObject<ResultEntity<AutoFocusResult>>(resultString);
  383. if (!rs.success)
  384. {
  385. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  386. return new AutoFocusResult();
  387. }
  388. if (rs.data != null) return rs.data;
  389. ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
  390. return new AutoFocusResult();
  391. }
  392. catch (Exception ex)
  393. {
  394. ExLog(ex, funcName);
  395. return new AutoFocusResult();
  396. }
  397. }
  398. public bool UpdateImmediatelyApi(string tlSn, int houseSn, List<FocusStartingPointResponse> wellFocusStartingPointList)
  399. {
  400. string funcName = "UpdateImmediatelyApi";
  401. try
  402. {
  403. string url = "/api/tl/control/setting/well/immediately";
  404. string body = JsonConvert.SerializeObject(new { tlSn, houseSn, wellFocusStartingPointList });
  405. string resultString = httpServiceCall1.callWebService(url, body);
  406. if (string.IsNullOrEmpty(resultString)) return false;
  407. var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
  408. if (!rs.success)
  409. {
  410. ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
  411. return false;
  412. }
  413. return true;
  414. }
  415. catch (Exception ex)
  416. {
  417. ExLog(ex, funcName);
  418. return false;
  419. }
  420. }
  421. }
  422. }