| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.balance;
- using ivf_tl_Entity.Entity.Result;
- using ivf_tl_Manage.Converts;
- using ivf_tl_Manage.Views;
- using ivf_tl_Service.HttpProvider;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Input;
- namespace ivf_tl_Manage.ViewModels
- {
- /// <summary>
- /// 设备管理主界面数据源
- /// </summary>
- public partial class DevManageViewModel : BaseViewModel
- {
- private DishProvider _dishProvider = null;
- private TLInfoProvider _tLInfoProvider = null;
- public AppData Appdata { get; set; }
- public DevManageView View { get; set; } = null;
- public List<TLInfo> TlInfoList { get; set; } = new List<TLInfo>();
- public bool IsInit { get; set; } = false;
- public DevManageViewModel()
- {
- base.NavName = KeyToStringConvert.GetLanguageStringByKey("0001");
- base.ViewModelName = nameof(DevManageViewModel);
- Appdata = AppData.Instance;
- _dishProvider = new DishProvider(Appdata.HttpServiceCall, Appdata.LogService);
- _tLInfoProvider = Appdata.GetTLInfoProvider();
- }
- List<TLInfo> tLInfos = new List<TLInfo>();
- int zhixingNum = 0;
- public bool UpData()
- {
- bool isAdd = false;
- try
- {
- zhixingNum = 1;
- tLInfos.Clear();
- tLInfos = _dishProvider.GetTlInfoList();
- zhixingNum = 2;
- TLInfo currentTlInfo = null;
- GetHouseCultureListResult currentDishInfo = null;
- foreach (var item in tLInfos)
- {
- currentTlInfo = TlInfoList.FirstOrDefault(x => x.tlSn == item.tlSn);
- if (currentTlInfo == null)
- {
- isAdd = true;
- TlInfoList.Add(item);
- continue;
- }
- currentTlInfo.id = item.id;
- currentTlInfo.tlName = item.tlName;
- currentTlInfo.state = item.state;
- currentTlInfo.online = item.online;
- }
- zhixingNum = 3;
- foreach (var item in TlInfoList)
- {
- currentDishInfo = _tLInfoProvider.GetHouseCultureList(item.tlSn);
- if (currentDishInfo == null) continue;
- if (currentDishInfo.embryoCultureRecords == null) currentDishInfo.embryoCultureRecords = new List<Dish>();
- if (currentDishInfo.balances == null) currentDishInfo.balances = new List<Balance>();
- zhixingNum = 4;
- foreach (var houseItem in item.houses)
- {
- if (houseItem == null) continue;
- houseItem.embryoRecordVO = currentDishInfo.embryoCultureRecords.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
- if (houseItem.embryoRecordVO == null)
- houseItem.embryoRecordVO = new Dish();
- if (houseItem.embryoRecordVO.embryoList == null) houseItem.embryoRecordVO.embryoList = new List<Embryo>();
- houseItem.balanceVO = currentDishInfo.balances.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
- if (!houseItem.IsUpdate) continue;
- if (houseItem.embryoRecordVO != null && houseItem.embryoRecordVO.id > 0)
- {
- if (DateTime.TryParse(houseItem.embryoRecordVO.startTime, out DateTime sou))
- {
- var span = DateTime.Now.Subtract(sou);
- if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
- else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
- houseItem.StartTime = sou.ToString("MM-dd HH:mm");
- }
- else
- {
- houseItem.FaYuTime = "-------";
- houseItem.StartTime = "--- ---";
- }
- continue;
- }
- if (houseItem.balanceVO != null && houseItem.balanceVO.id > 0)
- {
- if (DateTime.TryParse(houseItem.balanceVO.startTime, out DateTime sou))
- {
- var span = DateTime.Now.Subtract(sou);
- if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
- else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
- houseItem.StartTime = sou.ToString("MM-dd HH:mm");
- }
- else
- {
- houseItem.FaYuTime = "-------";
- houseItem.StartTime = "--- ---";
- }
- continue;
- }
- houseItem.FaYuTime = "-------";
- houseItem.StartTime = "--- ---";
- }
- zhixingNum = 5;
- }
- tLInfos.Clear();
- return isAdd;
- }
- catch (Exception ex)
- {
- ExLog(ex, $"UpData:{zhixingNum}:{isAdd}");
- return false;
- }
- }
- public bool UpData1()
- {
- try
- {
- bool isAdd = false;
- TlInfoList.Clear();
- tLInfos.Clear();
- tLInfos = _dishProvider.GetTlInfoList();
- TLInfo currentTlInfo = null;
- GetHouseCultureListResult currentDishInfo = null;
- foreach (var item in tLInfos)
- {
- currentTlInfo = TlInfoList.FirstOrDefault(x => x.tlSn == item.tlSn);
- if (currentTlInfo == null)
- {
- isAdd = true;
- TlInfoList.Add(item);
- continue;
- }
- currentTlInfo.id = item.id;
- currentTlInfo.tlName = item.tlName;
- currentTlInfo.state = item.state;
- currentTlInfo.online = item.online;
- }
- foreach (var item in TlInfoList)
- {
- currentDishInfo = _tLInfoProvider.GetHouseCultureList(item.tlSn);
- if (currentDishInfo == null) continue;
- if (currentDishInfo.embryoCultureRecords == null) currentDishInfo.embryoCultureRecords = new List<Dish>();
- if (currentDishInfo.balances == null) currentDishInfo.balances = new List<Balance>();
- foreach (var houseItem in item.houses)
- {
- if (houseItem == null) continue;
- houseItem.embryoRecordVO = currentDishInfo.embryoCultureRecords.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
- if (houseItem.embryoRecordVO == null) houseItem.embryoRecordVO = new Dish();
- if (houseItem.embryoRecordVO.embryoList == null) houseItem.embryoRecordVO.embryoList = new List<Embryo>();
- houseItem.balanceVO = currentDishInfo.balances.FirstOrDefault(x => x.houseSn == houseItem.houseSn);
- if (!houseItem.IsUpdate) continue;
- if (houseItem.embryoRecordVO != null && houseItem.embryoRecordVO.id > 0)
- {
- if (DateTime.TryParse(houseItem.embryoRecordVO.startTime, out DateTime sou))
- {
- var span = DateTime.Now.Subtract(sou);
- if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
- else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
- houseItem.StartTime = sou.ToString("MM-dd HH:mm");
- }
- else
- {
- houseItem.FaYuTime = "-------";
- houseItem.StartTime = "--- ---";
- }
- continue;
- }
- if (houseItem.balanceVO != null && houseItem.balanceVO.id > 0)
- {
- if (DateTime.TryParse(houseItem.balanceVO.startTime, out DateTime sou))
- {
- var span = DateTime.Now.Subtract(sou);
- if (span.TotalHours > 168) houseItem.FaYuTime = $"168h+";
- else houseItem.FaYuTime = $"{(span.Days * 24) + span.Hours}h:{span.Minutes}m";
- houseItem.StartTime = sou.ToString("MM-dd HH:mm");
- }
- else
- {
- houseItem.FaYuTime = "-------";
- houseItem.StartTime = "--- ---";
- }
- continue;
- }
- houseItem.FaYuTime = "-------";
- houseItem.StartTime = "--- ---";
- }
- }
- tLInfos.Clear();
- return isAdd;
- }
- catch (Exception ex)
- {
- ExLog(ex, "UpData");
- return false;
- }
- }
- public bool DeleteTL(long id)
- {
- return _tLInfoProvider.DeleteTlByIdApi(id);
- }
- public bool HiddenTL(long id)
- {
- return _tLInfoProvider.HiddenTLByIdAPi(id);
- }
- }
- }
|