You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BloodpressResolver.cs 23KB

1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
1 vuosi sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. 
  2. using HealthMonitor.Common;
  3. using HealthMonitor.Common.helper;
  4. using HealthMonitor.Service.Biz.db;
  5. using HealthMonitor.Service.Cache;
  6. using HealthMonitor.Service.Etcd;
  7. using HealthMonitor.Service.Resolver.Interface;
  8. using HealthMonitor.Service.Sub;
  9. using HealthMonitor.Service.Sub.Topic.Model;
  10. using Microsoft.EntityFrameworkCore.Metadata;
  11. using Microsoft.Extensions.Logging;
  12. using Newtonsoft.Json;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Data.Common;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Text.Json.Serialization;
  19. using System.Threading.Tasks;
  20. using TDengineTMQ;
  21. using TelpoDataService.Util.Entities.GpsCard;
  22. using TelpoDataService.Util;
  23. using TelpoDataService.Util.Entities.GpsLocationHistory;
  24. using HealthMonitor.Service.Biz;
  25. using HealthMonitor.Model.Service;
  26. namespace HealthMonitor.Service.Resolver
  27. {
  28. public class BloodpressResolver: IResolver
  29. {
  30. private readonly ILogger<BloodpressResolver> _logger;
  31. private readonly PersonCacheManager _personCacheMgr;
  32. private readonly TDengineService _serviceTDengine;
  33. private readonly BloodPressReferenceValueCacheManager _bpRefValCacheManager;
  34. private readonly HttpHelper _httpHelper = default!;
  35. private readonly GpsCardAccessorClient<GpsPerson> _gpsPersonApiClient;
  36. private readonly IotWebApiService _serviceIotWebApi;
  37. private readonly AsyncLocal<string> _messageId = new();
  38. private readonly AsyncLocal<HisGpsBloodPress> _msgData = new();
  39. private readonly EtcdService _serviceEtcd;
  40. public BloodpressResolver(
  41. TDengineService serviceDengine,
  42. BloodPressReferenceValueCacheManager bpRefValCacheManager,
  43. PersonCacheManager personCacheMgr, HttpHelper httpHelper,
  44. GpsCardAccessorClient<GpsPerson> gpsPersonApiClient,
  45. IotWebApiService iotWebApiService,
  46. EtcdService serviceEtcd,
  47. ILogger<BloodpressResolver> logger)
  48. {
  49. _httpHelper = httpHelper;
  50. _serviceTDengine = serviceDengine;
  51. _bpRefValCacheManager = bpRefValCacheManager;
  52. _gpsPersonApiClient = gpsPersonApiClient;
  53. _serviceIotWebApi = iotWebApiService;
  54. _logger = logger;
  55. _personCacheMgr = personCacheMgr;
  56. _serviceEtcd = serviceEtcd;
  57. }
  58. public void SetResolveInfo(PackageMsgModel msg)
  59. {
  60. var topicHmBloodPress = JsonConvert.DeserializeObject<TopicHmBloodPress>(msg.DetailData.ToString()!);
  61. _messageId.Value = msg.MessageId;
  62. _msgData.Value = new HisGpsBloodPress()
  63. {
  64. BloodPressId = topicHmBloodPress!.BloodPressId,
  65. MessageId = topicHmBloodPress!.MessageId,
  66. Serialno= topicHmBloodPress!.Serialno,
  67. SystolicValue = topicHmBloodPress!.SystolicValue,
  68. DiastolicValue= topicHmBloodPress!.DiastolicValue,
  69. LastUpdate= DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(SafeType.SafeInt64(topicHmBloodPress.LastUpdate) / 1000000),
  70. CreateTime= DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(SafeType.SafeInt64(topicHmBloodPress.CreateTime) / 1000000),
  71. Method= topicHmBloodPress!.Method,
  72. IsDisplay=topicHmBloodPress!.IsDisplay ? 1 : 0
  73. };
  74. }
  75. public override string ToString()
  76. {
  77. return $"{nameof(BloodpressResolver)}[{_messageId.Value}]";
  78. }
  79. public async Task ExecuteMessageAsync()
  80. {
  81. var messageId = _messageId.Value;
  82. var bp = _msgData.Value!;
  83. #region 获取个人信息
  84. var person = await _personCacheMgr.GetDeviceGpsPersonCacheBySerialNoAsync(bp.MessageId, bp.Serialno).ConfigureAwait(false);
  85. //验证这个信息是否存在
  86. if (person == null || person?.Person.BornDate == null)
  87. {
  88. _logger.LogWarning("验证个人信息,找不到个人信息,跳过此消息");
  89. return;
  90. }
  91. // 验证年龄是否在范围 (2 - 120)
  92. var age = SafeType.SafeInt(DateTime.Today.Year - person?.Person.BornDate!.Value.Year!);
  93. if (age < 1 || age > 120)
  94. {
  95. _logger.LogWarning("验证年龄,不在范围 (2 - 120)岁,跳过此消息");
  96. return;
  97. }
  98. #endregion
  99. var gender = person?.Person.Gender == true ? 1 : 2;
  100. var isHypertension = SafeType.SafeBool(person?.Person.Ishypertension!);
  101. var height = SafeType.SafeDouble(person?.Person.Height!);
  102. var weight = SafeType.SafeDouble(person?.Person.Weight!);
  103. #region 计算增量值
  104. var bpRef = await _bpRefValCacheManager.GetBloodPressReferenceValueAsync(age, gender, isHypertension);
  105. var lastPush = await _serviceTDengine.GetLastAsync("stb_hm_bp_push_ref_inc_value", $"serialno='{bp.Serialno}' order by ts desc");
  106. //var ts = last?[0];
  107. var systolicRefValue = bpRef?.Systolic;//?
  108. var diastolicRefValue = bpRef?.Diastolic;//?
  109. long duration = 7 * 24 * 3600 * 1000;
  110. int systolicInc;
  111. int diastolicInc;
  112. string sql = string.Empty;
  113. var remarkFlag = false;
  114. // 曾经有下发记录
  115. if (lastPush?.Count!=0)
  116. {
  117. // 重置设备,取正常值标定值
  118. if (
  119. (int)lastPush![2] == 0
  120. && (int)lastPush![3] == 0
  121. && (int)lastPush![4] == 0
  122. && (int)lastPush![5] == 0
  123. )
  124. {
  125. systolicRefValue = bpRef?.Systolic;//?
  126. diastolicRefValue = bpRef?.Diastolic;//?
  127. }
  128. // 取最后一条下推的标定值
  129. else
  130. {
  131. systolicRefValue = (int)lastPush?[2]!;
  132. diastolicRefValue = (int)lastPush?[3]!;
  133. }
  134. if (DateTime.TryParse(lastPush?[0]!.ToString(), out DateTime newTs))
  135. {
  136. duration = SafeType.SafeInt64(((DateTime)bp.LastUpdate! - newTs).TotalMilliseconds);
  137. }
  138. }
  139. TimeSpan ts= TimeSpan.FromMilliseconds(duration);
  140. // 获取历史数据
  141. ////DateTime now = DateTime.Now;
  142. //DateTime now = (DateTime)bp.LastUpdate!; //测试
  143. //DateTime startTime = now.AddDays(-duration);
  144. //DateTime endTime = now;
  145. DateTime endTime = (DateTime)bp.LastUpdate!; //测试
  146. DateTime startTime = endTime-ts;
  147. // 如果hm_bp_config_manual_calibration存在数据,使用最新数据
  148. //
  149. var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
  150. var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
  151. //var systolicAggregate = _serviceTDengine.GetAggregateValue("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
  152. //var diastolicAggregate = _serviceTDengine.GetAggregateValue("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
  153. // 最大值
  154. var systolicMax = systolicAggregate.Max;
  155. var diastolicMax = diastolicAggregate.Max;
  156. // 最小值
  157. var systolicMin = systolicAggregate.Min;
  158. var diastolicMin = diastolicAggregate.Min;
  159. // 偏移参数
  160. var avgOffset = 0.25M;
  161. var systolicAvgOffset = avgOffset;
  162. var diastolicAvgOffset = avgOffset;
  163. // 计算去除最大值和最小值和异常值的平均值
  164. var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} ");
  165. var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and diastolic_value < {diastolicRefValue}");
  166. if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
  167. {
  168. _logger.LogWarning("平均值为0不保存");
  169. systolicAvg = bp.SystolicValue;
  170. diastolicAvg = bp.DiastolicValue;
  171. systolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! > 0? (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!:0;
  172. diastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! >0? (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!:0;
  173. // 初始化 remark
  174. remarkFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(bp.Serialno, (int)systolicRefValue!, (int)diastolicRefValue!, systolicInc, diastolicInc).ConfigureAwait(false);
  175. if (remarkFlag)
  176. {
  177. // 下推
  178. BloodPressCalibrationConfigModel bpIncData = new()
  179. {
  180. Imei = bp.Serialno,
  181. SystolicRefValue = (int)systolicRefValue!, //收缩压标定值,值为0 表示不生效
  182. DiastolicRefValue = (int)diastolicRefValue!, //舒张压标定值,值为0表示不生效
  183. SystolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效
  184. DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效
  185. };
  186. // 下发 IOT 增量值
  187. var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false);
  188. if (flagIot)
  189. {
  190. #region 保存下推记录 stb_hm_bp_push_ref_inc_value
  191. sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " +
  192. $"USING health_monitor.stb_hm_bp_push_ref_inc_value " +
  193. $"TAGS ('{bp.Serialno.Substring(bp.Serialno.Length - 2)}') " +
  194. $"VALUES(" +
  195. $"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," +
  196. $"'{bp.Serialno}'," +
  197. $"{systolicRefValue}," +
  198. $"{diastolicRefValue}," +
  199. $"{systolicInc}," +
  200. $"{diastolicInc}," +
  201. $"{true})";
  202. _serviceTDengine.ExecuteInsertSQL(sql);
  203. #endregion
  204. }
  205. }
  206. return;
  207. }
  208. //var systolicAvg = _serviceTDengine.GetAvgExceptMaxMinValue("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} ");
  209. //var diastolicAvg = _serviceTDengine.GetAvgExceptMaxMinValue("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and diastolic_value < {diastolicRefValue}");
  210. // 增量值=(标定值-平均值)* 0.25
  211. systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
  212. diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;
  213. #endregion
  214. #region 插入BP增量值 hm_bloodpress_stats_inc
  215. // 自动建表
  216. sql = $"INSERT INTO health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " +
  217. $"USING health_monitor.stb_hm_bloodpress_stats_inc " +
  218. $"TAGS ('{bp.Serialno.Substring(bp.Serialno.Length - 2)}') " +
  219. $"VALUES(" +
  220. $"'{bp.LastUpdate:yyyy-MM-dd HH:mm:ss.fff}'," +
  221. $"'{bp.BloodPressId}'," +
  222. $"'{bp.MessageId}'," +
  223. $"'{bp.Serialno}'," +
  224. $"{bp.SystolicValue}," +
  225. $"{systolicRefValue}," +
  226. $"{systolicAvg}," +
  227. $"{systolicMax}," +
  228. $"{systolicMin}," +
  229. $"{systolicAvgOffset}," +
  230. $"{systolicInc}," +
  231. $"{bp.DiastolicValue}," +
  232. $"{diastolicRefValue}," +
  233. $"{diastolicAvg}," +
  234. $"{diastolicMax}," +
  235. $"{diastolicMin}," +
  236. $"{diastolicAvgOffset}," +
  237. $"{diastolicInc}," +
  238. $"{gender}," +
  239. $"{age}," +
  240. $"{height}," +
  241. $"{weight}," +
  242. $"'{bp.LastUpdate:yyyy-MM-dd HH:mm:ss.fff}'," +
  243. $"{duration}," +
  244. $"'{startTime:yyyy-MM-dd HH:mm:ss.fff}'," +
  245. $"'{endTime:yyyy-MM-dd HH:mm:ss.fff}'," +
  246. $"'{string.Empty}'," +
  247. $"{isHypertension})";
  248. _serviceTDengine.ExecuteInsertSQL(sql);
  249. // 发送到 设置设备血压标定参数
  250. #endregion
  251. // 初始化 remark
  252. remarkFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(bp.Serialno, (int)systolicRefValue!, (int)diastolicRefValue!, systolicInc, diastolicInc).ConfigureAwait(false);
  253. if (remarkFlag)
  254. {
  255. // 下推
  256. BloodPressCalibrationConfigModel bpIncData = new()
  257. {
  258. Imei = bp.Serialno,
  259. SystolicRefValue = (int)systolicRefValue!, //收缩压标定值,值为0 表示不生效
  260. DiastolicRefValue = (int)diastolicRefValue!, //舒张压标定值,值为0表示不生效
  261. SystolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效
  262. DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效
  263. };
  264. // 下发 IOT 增量值
  265. var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false);
  266. if (flagIot)
  267. {
  268. #region 保存下推记录 stb_hm_bp_push_ref_inc_value
  269. sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " +
  270. $"USING health_monitor.stb_hm_bp_push_ref_inc_value " +
  271. $"TAGS ('{bp.Serialno.Substring(bp.Serialno.Length - 2)}') " +
  272. $"VALUES(" +
  273. $"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," +
  274. $"'{bp.Serialno}'," +
  275. $"{systolicRefValue}," +
  276. $"{diastolicRefValue}," +
  277. $"{systolicInc}," +
  278. $"{diastolicInc}," +
  279. $"{true})";
  280. _serviceTDengine.ExecuteInsertSQL(sql);
  281. #endregion
  282. }
  283. }
  284. // 注册定时下发事件
  285. // 获取当前时间
  286. //DateTime sNow = DateTime.Now;
  287. //// 计算距离明天12点的时间间隔
  288. //TimeSpan timeUntil = new DateTime(sNow.Year, sNow.Month, sNow.Day, 12, 0, 0) - sNow;
  289. //// 如果当前时间已经超过了12点,将等待到明天
  290. //if (timeUntil < TimeSpan.Zero)
  291. //{
  292. // timeUntil = timeUntil.Add(TimeSpan.FromHours(24));
  293. //}
  294. //var data = new
  295. //{
  296. // imei = bp.Serialno,
  297. // systolicCalibrationValue = systolicRefValue, //收缩压标定值,值为0 表示不生效
  298. // diastolicCalibrationValue = diastolicRefValue, //舒张压标定值,值为0表示不生效
  299. // systolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效
  300. // diastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效
  301. //};
  302. //var url = $"http://id.ssjlai.com/webapi/api/Command/SetBloodPressCalibrationConfig";
  303. //List<KeyValuePair<string, string>> headers = new()
  304. //{
  305. // new KeyValuePair<string, string>("AuthKey", "key1")
  306. //};
  307. //var data = new
  308. //{
  309. // imei = bp.Serialno,
  310. // systolicCalibrationValue = systolicRefValue, //收缩压标定值,值为0 表示不生效
  311. // diastolicCalibrationValue = diastolicRefValue, //舒张压标定值,值为0表示不生效
  312. // systolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效
  313. // diastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效
  314. //};
  315. //var result = JsonConvert.SerializeObject(data);
  316. //var result = bp.Serialno;
  317. var key = $"health_moniter/schedule_push/imei/{bp.Serialno}";
  318. var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false);
  319. if (string.IsNullOrWhiteSpace(schedule_push))
  320. {
  321. // 注册首次下推
  322. #if DEBUG
  323. // await _serviceEtcd.PutValAsync(key, result, 60*1, false).ConfigureAwait(false);
  324. var interval = 0;
  325. // 获取当前时间
  326. DateTime now = DateTime.Now;
  327. // 计算距离下一个$interval天后的8点的时间间隔
  328. DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute+1, 58).AddDays(interval);
  329. TimeSpan timeUntilNextRun = nextRunTime - now;
  330. // 如果当前时间已经超过了8点,将等待到明天后的8点
  331. if (timeUntilNextRun < TimeSpan.Zero)
  332. {
  333. timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1));
  334. nextRunTime += timeUntilNextRun;
  335. }
  336. var ttl = (long)timeUntilNextRun.TotalSeconds;
  337. var data = new
  338. {
  339. imei = bp.Serialno,
  340. create_time = now.ToString("yyyy-MM-dd HH:mm:ss"),
  341. ttl,
  342. next_run_time= nextRunTime.ToString("yyyy-MM-dd HH:mm:ss")
  343. };
  344. var result=JsonConvert.SerializeObject(data);
  345. await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false);
  346. #else
  347. //DateTime sNow = DateTime.Now;
  348. //// 计算距离19:59:55点的时间间隔
  349. //TimeSpan timeUntil = new DateTime(sNow.Year, sNow.Month, sNow.Day, 19, 59, 55) - sNow;
  350. //// 如果当前时间已经超过了12点,将等待到明天
  351. //if (timeUntil < TimeSpan.Zero)
  352. //{
  353. // timeUntil = timeUntil.Add(TimeSpan.FromHours(24));
  354. //}
  355. //var ttl = (long)timeUntil.TotalSeconds;
  356. var interval = 0;
  357. // 获取当前时间
  358. DateTime now = DateTime.Now;
  359. // 计算距离下一个$interval天后的8点的时间间隔
  360. DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, 19, 59, 58).AddDays(interval);
  361. TimeSpan timeUntilNextRun = nextRunTime - now;
  362. // 如果当前时间已经超过了8点,将等待到明天后的8点
  363. if (timeUntilNextRun < TimeSpan.Zero)
  364. {
  365. timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1));
  366. nextRunTime += timeUntilNextRun;
  367. }
  368. var ttl =(long)timeUntilNextRun.TotalSeconds;
  369. var data = new
  370. {
  371. imei = bp.Serialno,
  372. create_time = now.ToString("yyyy-MM-dd HH:mm:ss"),
  373. ttl,
  374. next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss")
  375. };
  376. var result = JsonConvert.SerializeObject(data);
  377. await _serviceEtcd.PutValAsync(key, result,ttl, false).ConfigureAwait(false);
  378. #endif
  379. }
  380. //// 生效
  381. //if (DateTime.Now.Hour == 1)
  382. //{
  383. // var data = new
  384. // {
  385. // imei = bp.Serialno,
  386. // systolicCalibrationValue = systolicRefValue, //收缩压标定值,值为0 表示不生效
  387. // diastolicCalibrationValue = diastolicRefValue, //舒张压标定值,值为0表示不生效
  388. // systolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效
  389. // diastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效
  390. // };
  391. // var result = await _httpHelper.HttpToPostAsync(url, data, headers).ConfigureAwait(false);
  392. // _logger.LogInformation($"将 {JsonConvert.SerializeObject(data)}发送到 {url} 并且返回 {JsonConvert.SerializeObject(result)}");
  393. //}
  394. //// 不生效
  395. //else if (DateTime.Now.Hour == 3)
  396. //{
  397. // var data = new
  398. // {
  399. // imei = bp.Serialno,
  400. // systolicCalibrationValue = 0, //收缩压标定值,值为0 表示不生效
  401. // diastolicCalibrationValue = 0, //舒张压标定值,值为0表示不生效
  402. // systolicIncValue = 0, //收缩压显示增量,值为0 表示不生效
  403. // diastolicIncValue = 0 //舒张压显示增量,值为0 表示不生效
  404. // };
  405. // var result = await _httpHelper.HttpToPostAsync(url, data, headers).ConfigureAwait(false);
  406. // _logger.LogInformation($"将 {JsonConvert.SerializeObject(data)}发送到 {url} 并且返回 {JsonConvert.SerializeObject(result)}");
  407. //}
  408. }
  409. }
  410. }