DevManageViewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using ivf_tl_Entity.Entity;
  2. using ivf_tl_Entity.Entity.balance;
  3. using ivf_tl_Entity.Entity.Result;
  4. using ivf_tl_Manage.Converts;
  5. using ivf_tl_Manage.Views;
  6. using ivf_tl_Service.HttpProvider;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. namespace ivf_tl_Manage.ViewModels
  16. {
  17. /// <summary>
  18. /// 设备管理主界面数据源
  19. /// </summary>
  20. public partial class DevManageViewModel : BaseViewModel
  21. {
  22. private DishProvider _dishProvider = null;
  23. private TLInfoProvider _tLInfoProvider = null;
  24. public AppData Appdata { get; set; }
  25. public DevManageView View { get; set; } = null;
  26. public List<TLInfo> TlInfoList { get; set; } = new List<TLInfo>();
  27. public bool IsInit { get; set; } = false;
  28. public DevManageViewModel()
  29. {
  30. base.NavName = KeyToStringConvert.GetLanguageStringByKey("0001");
  31. base.ViewModelName = nameof(DevManageViewModel);
  32. Appdata = AppData.Instance;
  33. _dishProvider = new DishProvider(Appdata.HttpServiceCall, Appdata.LogService);
  34. _tLInfoProvider = Appdata.GetTLInfoProvider();
  35. }
  36. List<TLInfo> tLInfos = new List<TLInfo>();
  37. int zhixingNum = 0;
  38. public bool UpData()
  39. {
  40. bool isAdd = false;
  41. try
  42. {
  43. zhixingNum = 1;
  44. tLInfos.Clear();
  45. tLInfos = _dishProvider.GetTlInfoList();
  46. zhixingNum = 2;
  47. TLInfo currentTlInfo = null;
  48. GetHouseCultureListResult currentDishInfo = null;
  49. foreach (var item in tLInfos)
  50. {
  51. currentTlInfo = TlInfoList.FirstOrDefault(x => x.tlSn == item.tlSn);
  52. if (currentTlInfo == null)
  53. {
  54. isAdd = true;
  55. TlInfoList.Add(item);
  56. continue;
  57. }
  58. currentTlInfo.id = item.id;
  59. currentTlInfo.tlName = item.tlName;
  60. currentTlInfo.state = item.state;
  61. currentTlInfo.online = item.online;
  62. }
  63. zhixingNum = 3;
  64. foreach (var item in TlInfoList)
  65. {
  66. currentDishInfo = _tLInfoProvider.GetHouseCultureList(item.tlSn);
  67. if (currentDishInfo == null) continue;
  68. if (currentDishInfo.embryoCultureRecords == null) currentDishInfo.embryoCultureRecords = new List<Dish>();
  69. if (currentDishInfo.balances == null) currentDishInfo.balances = new List<Balance>();
  70. zhixingNum = 4;
  71. foreach (var houseItem in item.houses)
  72. {
  73. if (houseItem == null) continue;
  74. houseItem.embryoRecordVO = currentDishInfo.embryoCultureRecords.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
  75. if (houseItem.embryoRecordVO == null)
  76. houseItem.embryoRecordVO = new Dish();
  77. if (houseItem.embryoRecordVO.embryoList == null) houseItem.embryoRecordVO.embryoList = new List<Embryo>();
  78. houseItem.balanceVO = currentDishInfo.balances.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
  79. if (!houseItem.IsUpdate) continue;
  80. if (houseItem.embryoRecordVO != null && houseItem.embryoRecordVO.id > 0)
  81. {
  82. if (DateTime.TryParse(houseItem.embryoRecordVO.startTime, out DateTime sou))
  83. {
  84. var span = DateTime.Now.Subtract(sou);
  85. if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
  86. else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
  87. houseItem.StartTime = sou.ToString("MM-dd HH:mm");
  88. }
  89. else
  90. {
  91. houseItem.FaYuTime = "-------";
  92. houseItem.StartTime = "--- ---";
  93. }
  94. continue;
  95. }
  96. if (houseItem.balanceVO != null && houseItem.balanceVO.id > 0)
  97. {
  98. if (DateTime.TryParse(houseItem.balanceVO.startTime, out DateTime sou))
  99. {
  100. var span = DateTime.Now.Subtract(sou);
  101. if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
  102. else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
  103. houseItem.StartTime = sou.ToString("MM-dd HH:mm");
  104. }
  105. else
  106. {
  107. houseItem.FaYuTime = "-------";
  108. houseItem.StartTime = "--- ---";
  109. }
  110. continue;
  111. }
  112. houseItem.FaYuTime = "-------";
  113. houseItem.StartTime = "--- ---";
  114. }
  115. zhixingNum = 5;
  116. }
  117. tLInfos.Clear();
  118. return isAdd;
  119. }
  120. catch (Exception ex)
  121. {
  122. ExLog(ex, $"UpData:{zhixingNum}:{isAdd}");
  123. return false;
  124. }
  125. }
  126. public bool UpData1()
  127. {
  128. try
  129. {
  130. bool isAdd = false;
  131. TlInfoList.Clear();
  132. tLInfos.Clear();
  133. tLInfos = _dishProvider.GetTlInfoList();
  134. TLInfo currentTlInfo = null;
  135. GetHouseCultureListResult currentDishInfo = null;
  136. foreach (var item in tLInfos)
  137. {
  138. currentTlInfo = TlInfoList.FirstOrDefault(x => x.tlSn == item.tlSn);
  139. if (currentTlInfo == null)
  140. {
  141. isAdd = true;
  142. TlInfoList.Add(item);
  143. continue;
  144. }
  145. currentTlInfo.id = item.id;
  146. currentTlInfo.tlName = item.tlName;
  147. currentTlInfo.state = item.state;
  148. currentTlInfo.online = item.online;
  149. }
  150. foreach (var item in TlInfoList)
  151. {
  152. currentDishInfo = _tLInfoProvider.GetHouseCultureList(item.tlSn);
  153. if (currentDishInfo == null) continue;
  154. if (currentDishInfo.embryoCultureRecords == null) currentDishInfo.embryoCultureRecords = new List<Dish>();
  155. if (currentDishInfo.balances == null) currentDishInfo.balances = new List<Balance>();
  156. foreach (var houseItem in item.houses)
  157. {
  158. if (houseItem == null) continue;
  159. houseItem.embryoRecordVO = currentDishInfo.embryoCultureRecords.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
  160. if (houseItem.embryoRecordVO == null) houseItem.embryoRecordVO = new Dish();
  161. if (houseItem.embryoRecordVO.embryoList == null) houseItem.embryoRecordVO.embryoList = new List<Embryo>();
  162. houseItem.balanceVO = currentDishInfo.balances.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
  163. if (!houseItem.IsUpdate) continue;
  164. if (houseItem.embryoRecordVO != null && houseItem.embryoRecordVO.id > 0)
  165. {
  166. if (DateTime.TryParse(houseItem.embryoRecordVO.startTime, out DateTime sou))
  167. {
  168. var span = DateTime.Now.Subtract(sou);
  169. if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
  170. else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
  171. houseItem.StartTime = sou.ToString("MM-dd HH:mm");
  172. }
  173. else
  174. {
  175. houseItem.FaYuTime = "-------";
  176. houseItem.StartTime = "--- ---";
  177. }
  178. continue;
  179. }
  180. if (houseItem.balanceVO != null && houseItem.balanceVO.id > 0)
  181. {
  182. if (DateTime.TryParse(houseItem.balanceVO.startTime, out DateTime sou))
  183. {
  184. var span = DateTime.Now.Subtract(sou);
  185. if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
  186. else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
  187. houseItem.StartTime = sou.ToString("MM-dd HH:mm");
  188. }
  189. else
  190. {
  191. houseItem.FaYuTime = "-------";
  192. houseItem.StartTime = "--- ---";
  193. }
  194. continue;
  195. }
  196. houseItem.FaYuTime = "-------";
  197. houseItem.StartTime = "--- ---";
  198. }
  199. }
  200. tLInfos.Clear();
  201. return isAdd;
  202. }
  203. catch (Exception ex)
  204. {
  205. ExLog(ex, "UpData");
  206. return false;
  207. }
  208. }
  209. public bool DeleteTL(long id)
  210. {
  211. return _tLInfoProvider.DeleteTlByIdApi(id);
  212. }
  213. public bool HiddenTL(long id)
  214. {
  215. return _tLInfoProvider.HiddenTLByIdAPi(id);
  216. }
  217. }
  218. }