| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.balance;
- using ivf_tl_Entity.Entity.Mark;
- using ivf_tl_Entity.Entity.Result;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Entity.Pic;
- using ivf_tl_Entity.Response;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ivf_tl_Service.HttpProvider
- {
- public class PicProvider
- {
- LogService LogService { get; set; }
- HttpServiceCall httpServiceCall1 { get; set; }
- public PicProvider(HttpServiceCall _httpServiceCall, LogService _logService)
- {
- httpServiceCall1 = _httpServiceCall;
- LogService = _logService;
- }
- private void ExLog(Exception ex, string name)
- {
- LogService.ExceptionLog(ex, $"PicProvider.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string message, LogEnum logType)
- {
- LogService.TLLog($"PicProvider.{message}", logType);
- }
- /// <summary>
- /// 设备数据接口 详情-图片查看(获取原图)
- /// </summary>
- /// <param name="embryoId"></param>
- /// <param name="houseSn"></param>
- /// <param name="pictureLayer"></param>
- /// <param name="tlSn"></param>
- /// <returns></returns>
- public List<PictureEntity> GetImageSourceApi(long embryoId, int houseSn, int pictureLayer, string tlSn)
- {
- string funcName = "GetImageSourceApi";
- try
- {
- string url = "/api/businessManage/pc/resource/getSourcePictures";
- string body = JsonConvert.SerializeObject(new
- {
- embryoId = embryoId,
- houseSn = houseSn,
- pictureLayer = pictureLayer,
- tlSn = tlSn,
- });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return new List<PictureEntity>();
- var rs = JsonConvert.DeserializeObject<ResultEntity<List<PictureEntity>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return new List<PictureEntity>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<PictureEntity>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<PictureEntity>();
- }
- }
- /// <summary>
- /// 设备数据接口 详情-图片查看(获取原图)分页
- /// </summary>
- /// <param name="embryoId"></param>
- /// <param name="houseSn"></param>
- /// <param name="pictureLayer"></param>
- /// <param name="tlSn"></param>
- /// <returns></returns>
- public SourcePicPageResult GetImageSourcePageApi(long embryoId, int houseSn, int pictureLayer, string tlSn, int current, int size, List<PhotoBoxSetting1> photoBoxSetting1s)
- {
- string funcName = "GetImageSourcePageApi";
- try
- {
- string url = "/api/businessManage/pc/resource/getSourcePicturesByPage";
- string body = null;
- if (photoBoxSetting1s.Any())
- {
- body = JsonConvert.SerializeObject(new
- {
- embryoId = embryoId,
- houseSn = houseSn,
- pictureLayer = pictureLayer,
- tlSn = tlSn,
- current,
- size,
- searchButtons = photoBoxSetting1s,
- });
- }
- else
- {
- body = JsonConvert.SerializeObject(new
- {
- embryoId = embryoId,
- houseSn = houseSn,
- pictureLayer = pictureLayer,
- tlSn = tlSn,
- current,
- size
- });
- }
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return new SourcePicPageResult();
- var rs = JsonConvert.DeserializeObject<ResultEntity<SourcePicPageResult>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return new SourcePicPageResult();
- }
- if (rs.data != null) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new SourcePicPageResult();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new SourcePicPageResult();
- }
- }
- /// <summary>
- /// 设备数据接口 患者管理-详情-获取指定指定well的指定图层图片
- /// </summary>
- /// <param name="tlsn"></param>
- /// <param name="housesn"></param>
- /// <param name="dishId"></param>
- /// <param name="wellList"></param>
- /// <param name="layerList"></param>
- /// <returns></returns>
- public List<SwitchVideoPictureLayersData> SwitchVideoPictureLayersApi(string tlsn, int housesn, long dishId, List<int> wellList, List<int> layerList)
- {
- string funcName = "SwitchVideoPictureLayersApi";
- try
- {
- string url = "/api/businessManage/pc/resource/switchVideoPictureLayers";
- string body = JsonConvert.SerializeObject(new
- {
- tlSn = tlsn,
- houseSn = housesn,
- id = dishId,
- wellSnList = wellList,
- pictureLayer = layerList
- });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return new List<SwitchVideoPictureLayersData>();
- var rs = JsonConvert.DeserializeObject<ResultEntity<List<SwitchVideoPictureLayersData>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}接口返回失败 {resultString}", LogEnum.RunError);
- return new List<SwitchVideoPictureLayersData>();
- }
- if (rs.data != null) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<SwitchVideoPictureLayersData>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<SwitchVideoPictureLayersData>();
- }
- }
- public bool DownloadSelectPicturesApi(string tlSn, int houseSn, List<long> ids, string fileName)
- {
- string funcName = "DownloadSelectPicturesApi";
- try
- {
- string url = "/api/businessManage/pc/resource/downloadSelectPictures";
- string body = JsonConvert.SerializeObject(new
- {
- tlSn = tlSn,
- houseSn = houseSn,
- ids = ids,
- });
- return httpServiceCall1.callWebService(url, body, fileName);
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- /// <summary>
- /// 下载图片
- /// </summary>
- /// <param name="sourceFileUrl"></param>
- /// <param name="newFile"></param>
- /// <returns></returns>
- public bool DownloadFileApi(string tlSn, int houseSn, long id, string newFile)
- {
- string funcName = "DownloadFileApi";
- try
- {
- return httpServiceCall1.DownLoadFileAsync($"/api/businessManage/pc/resource/downloadPicture?tlSn={tlSn}&houseSn={houseSn}&ids={id}", newFile).GetAwaiter().GetResult() == 1;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- /// <summary>
- /// 下载指定well - 指定图层所有图片
- /// </summary>
- /// <returns></returns>
- public bool DownloadLayerPicApi(string body, string newFile,string ss)
- {
- string funcName = "DownloadLayerPicApi";
- try
- {
- string url = "/api/businessManage/pc/resource/downloadPictures";
- return httpServiceCall1.callWebService(url, body, newFile);
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- /// <summary>
- /// 下载指定well - 指定图层所有图片
- /// </summary>
- /// <returns></returns>
- public async Task<bool> DownloadLayerPicApi(string tlsn,int housesn,int pic,List<long> ids, string newFile)
- {
- string funcName = "DownloadLayerPicApi";
- try
- {
- string url = $"/api/businessManage/pc/resource/downloadPictures?houseSn={housesn}&ids={string.Join(",",ids)}&pictureLayer={pic}&tlSn={tlsn}";
- url = url.Replace("+", "%2B");
- url = url.Replace(",", "%2C");
- //var a = await httpServiceCall1.DownLoadFile(url, newFile);
- return true;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- /// <summary>
- /// 下载指定well - 指定图层所有图片
- /// </summary>
- /// <returns></returns>
- public async Task<bool> DownloadApi(string url, string newFile)
- {
- string funcName = "DownloadLayerPicApi";
- try
- {
- url = url.Replace("+", "%2B");
- url = url.Replace(",", "%2C");
- //var a = await httpServiceCall1.DownLoadFile(url, newFile);
- return true;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- /// <summary>
- /// 下载指定well - 指定图层所有图片
- /// </summary>
- /// <returns></returns>
- public bool DownloadLayerVideoApi(string body, string newFile)
- {
- string funcName = "DownloadLayerVideoApi";
- try
- {
- string url = "/api/businessManage/pc/resource/downloadVideos";
- return httpServiceCall1.callWebService(url, body, newFile);
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- public List<PictureView> GetPictureViewApi(string tlSn,int houseSn,long embryoId,int pictureLayer)
- {
- string funcName = "GetPictureViewApi";
- try
- {
- string url = "/api/businessManage/pc/resource/getPictures";
- string body = JsonConvert.SerializeObject(new { tlSn, houseSn, embryoId , pictureLayer });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return new List<PictureView>();
- var rs = JsonConvert.DeserializeObject<ResultEntity<List<PictureView>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return new List<PictureView>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<PictureView>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<PictureView>();
- }
- }
- public int GetSourcePicturesTotalLayerApi(string tlSn, int houseSn, long embryoId)
- {
- string funcName = "GetSourcePicturesTotalLayerApi";
- try
- {
- string url = "/api/businessManage/pc/resource/getSourcePicturesTotalLayer";
- string body = JsonConvert.SerializeObject(new { tlSn, houseSn, embryoId });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return 0;
- var rs = JsonConvert.DeserializeObject<ResultEntity<string>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return 0;
- }
- if (string.IsNullOrEmpty(rs.data))
- {
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return 0;
- }
- if (int.TryParse(rs.data, out int newValue))
- {
- return newValue;
- }
- else
- {
- ErrorLog($"{funcName}接口返回成功但是结果转int类型失败 {resultString}", LogEnum.RunError);
- return 0;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return 0;
- }
- }
- public List<PositionEntity> GetPositionApi(string tlSn, int houseSn, List<int> wellSn)
- {
- string funcName = "GetPositionApi";
- try
- {
- string url = "/api/tl/control/setting/house/autofocus/position";
- string body = JsonConvert.SerializeObject(new { tlSn, houseSn, wellSn });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return new List<PositionEntity>();
- var rs = JsonConvert.DeserializeObject<ResultEntity<List<PositionEntity>>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return new List<PositionEntity>();
- }
- if (rs.data != null && rs.data.Any()) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new List<PositionEntity>();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new List<PositionEntity>();
- }
- }
- public AutoFocusResult GetAutofocusPicturesApi(string tlSn, int houseSn, long embryoId)
- {
- string funcName = "GetAutofocusPicturesApi";
- try
- {
- string url = "/api/businessManage/pc/resource/getAutofocusPictures";
- string body = JsonConvert.SerializeObject(new { tlSn, houseSn, embryoId });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return new AutoFocusResult();
- var rs = JsonConvert.DeserializeObject<ResultEntity<AutoFocusResult>>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return new AutoFocusResult();
- }
- if (rs.data != null) return rs.data;
- ErrorLog($"{funcName}接口返回成功但是无数据 {resultString}", LogEnum.RunError);
- return new AutoFocusResult();
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return new AutoFocusResult();
- }
- }
- public bool UpdateImmediatelyApi(string tlSn, int houseSn, List<FocusStartingPointResponse> wellFocusStartingPointList)
- {
- string funcName = "UpdateImmediatelyApi";
- try
- {
- string url = "/api/tl/control/setting/well/immediately";
- string body = JsonConvert.SerializeObject(new { tlSn, houseSn, wellFocusStartingPointList });
- string resultString = httpServiceCall1.callWebService(url, body);
- if (string.IsNullOrEmpty(resultString)) return false;
- var rs = JsonConvert.DeserializeObject<ResultEntity>(resultString);
- if (!rs.success)
- {
- ErrorLog($"{funcName}服务器返回失败 {resultString}", LogEnum.RunError);
- return false;
- }
- return true;
- }
- catch (Exception ex)
- {
- ExLog(ex, funcName);
- return false;
- }
- }
- }
- }
|