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 24KB

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