From 5d3c06c12c418e03729d5db7289e54a18466f578 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B2=A9=E4=BB=9488?= <>
Date: Thu, 2 Apr 2026 00:59:55 +0800
Subject: [PATCH] bug
---
opencode.json | 133 ++++++++++++
.../MyHosListener/common/Tools.cs | 191 +++++++-----------
2 files changed, 206 insertions(+), 118 deletions(-)
create mode 100644 opencode.json
diff --git a/opencode.json b/opencode.json
new file mode 100644
index 0000000..c82c31c
--- /dev/null
+++ b/opencode.json
@@ -0,0 +1,133 @@
+{
+ "$schema": "https://opencode.ai/config.json",
+ "provider":{
+ "bailian-coding-plan": {
+ "npm": "@ai-sdk/anthropic",
+ "name": "Model Studio Coding Plan",
+ "options": {
+ "baseURL": "https://coding.dashscope.aliyuncs.com/apps/anthropic/v1",
+ "apiKey": "sk-sp-08990303176d4bfeb36f8eef6a46484f"
+ },
+ "models": {
+ "qwen3.5-plus": {
+ "name": "Qwen3.5 Plus",
+ "modalities": {
+ "input": ["text", "image"],
+ "output": ["text"]
+ },
+ "options": {
+ "thinking": {
+ "type": "enabled",
+ "budgetTokens": 8192
+ }
+ },
+ "limit": {
+ "context": 1000000,
+ "output": 65536
+ }
+ },
+ "qwen3-max-2026-01-23": {
+ "name": "Qwen3 Max 2026-01-23",
+ "modalities": {
+ "input": ["text"],
+ "output": ["text"]
+ },
+ "limit": {
+ "context": 262144,
+ "output": 32768
+ }
+ },
+ "qwen3-coder-next": {
+ "name": "Qwen3 Coder Next",
+ "modalities": {
+ "input": ["text"],
+ "output": ["text"]
+ },
+ "limit": {
+ "context": 262144,
+ "output": 65536
+ }
+ },
+ "qwen3-coder-plus": {
+ "name": "Qwen3 Coder Plus",
+ "modalities": {
+ "input": ["text"],
+ "output": ["text"]
+ },
+ "limit": {
+ "context": 1000000,
+ "output": 65536
+ }
+ },
+ "MiniMax-M2.5": {
+ "name": "MiniMax M2.5",
+ "modalities": {
+ "input": ["text"],
+ "output": ["text"]
+ },
+ "options": {
+ "thinking": {
+ "type": "enabled",
+ "budgetTokens": 8192
+ }
+ },
+ "limit": {
+ "context": 204800,
+ "output": 131072
+ }
+ },
+ "glm-5": {
+ "name": "GLM-5",
+ "modalities": {
+ "input": ["text"],
+ "output": ["text"]
+ },
+ "options": {
+ "thinking": {
+ "type": "enabled",
+ "budgetTokens": 8192
+ }
+ },
+ "limit": {
+ "context": 202752,
+ "output": 16384
+ }
+ },
+ "glm-4.7": {
+ "name": "GLM-4.7",
+ "modalities": {
+ "input": ["text"],
+ "output": ["text"]
+ },
+ "options": {
+ "thinking": {
+ "type": "enabled",
+ "budgetTokens": 8192
+ }
+ },
+ "limit": {
+ "context": 202752,
+ "output": 16384
+ }
+ },
+ "kimi-k2.5": {
+ "name": "Kimi K2.5",
+ "modalities": {
+ "input": ["text", "image"],
+ "output": ["text"]
+ },
+ "options": {
+ "thinking": {
+ "type": "enabled",
+ "budgetTokens": 8192
+ }
+ },
+ "limit": {
+ "context": 262144,
+ "output": 32768
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/秦皇岛中医院监听mq/MyHosListener/common/Tools.cs b/秦皇岛中医院监听mq/MyHosListener/common/Tools.cs
index f278c53..56103d8 100644
--- a/秦皇岛中医院监听mq/MyHosListener/common/Tools.cs
+++ b/秦皇岛中医院监听mq/MyHosListener/common/Tools.cs
@@ -1,162 +1,84 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
+using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
-using System.Timers;
-using Newtonsoft.Json; // 用于生成 JSON 数据
+using Newtonsoft.Json;
namespace MyHosListener.common
{
public class Tools
{
- private static Timer _timerNoPay;
- private static Timer _timerNightly;
-
- // 保持 HttpClient 单例,复用连接
- static readonly HttpClient client = new HttpClient();
+ private static System.Timers.Timer _timerNoPay;
+ private static readonly HttpClient client = new HttpClient();
///
- /// 原有的委托变更通知 (GET) - 未修改
+ /// 通知医技取消
///
public static async Task NoticeEntrustChange(string orderNo)
{
try
{
string url = $"http://192.168.80.76/api/PacsCancelApplyInfo?orderNo={orderNo}";
- HttpResponseMessage response = await client.GetAsync(url);
+ var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
MyLog.Info(responseBody);
}
- catch (HttpRequestException e)
+ catch (Exception e)
{
MyLog.Info($"请求错误 (NoticeEntrustChange): {e.Message}");
- Console.WriteLine($"请求错误: {e.Message}");
- }
- }
-
- ///
- /// 原有的未支付取消任务 (GET) - 未修改
- ///
- public static async void NoPayCancel(object sender, ElapsedEventArgs e)
- {
- try
- {
- string url = $"http://192.168.80.76/api/admin/NoPayCancel";
- HttpResponseMessage response = await client.GetAsync(url);
- response.EnsureSuccessStatusCode();
-
- string responseBody = await response.Content.ReadAsStringAsync();
- MyLog.Info(responseBody);
- }
- catch (HttpRequestException es)
- {
- MyLog.Info($"请求错误 (NoPayCancel): {es.Message}");
}
}
///
- /// 新增:每天晚上10点执行的任务 (POST)
- /// 逻辑:计算当前日期+15天,构建JSON,发送POST请求
+ /// 未支付自动取消(每5分钟)
///
- public static async void NightlyTaskHandler(object sender, ElapsedEventArgs e)
+ private static async void NoPayCancel(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
- MyLog.Info(">>> 开始执行每日夜间定时任务 (POST)...");
-
- // 1. 计算日期:当前日期 + 15天
- DateTime targetDate = DateTime.Now.AddDays(15);
- string dateStr = targetDate.ToString("yyyy-MM-dd");
-
- // 2. 构建符合要求的对象
- var postData = new
- {
- dateRange = new[] { dateStr, dateStr }, // ["2026-XX-XX", "2026-XX-XX"]
- HolidayEnable = 1
- };
+ string url = "http://192.168.80.76/api/admin/NoPayCancel";
- // 3. 序列化为 JSON 字符串
- string jsonContent = JsonConvert.SerializeObject(postData);
-
- // 4. 准备 HTTP 内容 (UTF8 编码,application/json 类型)
- var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
-
- // TODO: 【重要】请在此处替换为你真实的夜间任务接口地址
- string url = "http://192.168.80.76/api/YourNightlyApi";
-
- MyLog.Info($"准备发送 POST 请求到: {url}");
- MyLog.Info($"请求体数据: {jsonContent}");
-
- // 5. 发送 POST 请求
- HttpResponseMessage response = await client.PostAsync(url, content);
-
- // 检查状态码,如果不是 2xx 会抛出异常
+ var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
- MyLog.Info($"<<< 夜间任务执行成功,响应内容: {responseBody}");
+ MyLog.Info("[NoPayCancel] " + responseBody);
}
catch (Exception ex)
{
- MyLog.Info($"!!! 夜间任务执行失败: {ex.Message}");
- if (ex.InnerException != null)
- {
- MyLog.Info($"内部错误详情: {ex.InnerException.Message}");
- }
- }
- finally
- {
- // 关键步骤:无论成功或失败,都要重新计算下一次运行时间并重启定时器
- // 这样能保证即使某次报错,明天的任务依然会准时运行
- ScheduleNextNightlyRun();
+ MyLog.Info($"请求错误 (NoPayCancel): {ex.Message}");
}
}
///
- /// 计算距离下一个晚上 22:00 的时间间隔,并配置定时器
+ /// 夜间任务核心逻辑(每天22点执行)
///
- private static void ScheduleNextNightlyRun()
+ private static async Task NightlyTaskCore()
{
- DateTime now = DateTime.Now;
- DateTime nextRun = now.Date.AddHours(22); // 设定为今天的 22:00
+ MyLog.Info(">>> 夜间任务执行:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- // 如果现在已超过今天 22:00,则设为明天 22:00
- if (nextRun <= now)
+ DateTime targetDate = DateTime.Now.AddDays(15);
+ string dateStr = targetDate.ToString("yyyy-MM-dd");
+
+ var postData = new
{
- nextRun = nextRun.AddDays(1);
- }
+ dateRange = new[] { dateStr, dateStr },
+ HolidayEnable = 1
+ };
- // 计算毫秒差
- double intervalMs = (nextRun - now).TotalMilliseconds;
+ string jsonContent = JsonConvert.SerializeObject(postData);
+ var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
- // 安全保护:防止负数
- if (intervalMs < 0) intervalMs = 60000;
+ string url = "http://192.168.80.76/api/YourNightlyApi";
- if (_timerNightly == null)
- {
- _timerNightly = new Timer(intervalMs);
- _timerNightly.Elapsed += NightlyTaskHandler;
- _timerNightly.AutoReset = false; // 设置为只触发一次,由我们在回调中手动重置
- }
- else
- {
- _timerNightly.Interval = intervalMs;
- _timerNightly.Stop();
- _timerNightly.Start();
- }
+ var response = await client.PostAsync(url, content);
+ response.EnsureSuccessStatusCode();
- // 确保启用
- if (!_timerNightly.Enabled)
- {
- _timerNightly.Enabled = true;
- }
+ string responseBody = await response.Content.ReadAsStringAsync();
- double minutesToWait = intervalMs / 1000 / 60;
- MyLog.Info($"[调度器] 夜间任务已设定,将于 {nextRun:yyyy-MM-dd HH:mm:ss} 执行 (约 {minutesToWait:F1} 分钟后)");
+ MyLog.Info("<<< 夜间任务成功:" + responseBody);
}
///
@@ -166,22 +88,55 @@ namespace MyHosListener.common
{
MyLog.Info("正在初始化定时任务模块...");
- // 1. 启动原有的每 5 分钟任务 (GET)
+ // ===== 5分钟任务 =====
if (_timerNoPay == null)
{
- _timerNoPay = new Timer(300000); // 300000ms = 5分钟
+ _timerNoPay = new System.Timers.Timer(300000); // 5分钟
_timerNoPay.Elapsed += NoPayCancel;
- _timerNoPay.AutoReset = true; // 自动重复
- _timerNoPay.Enabled = true;
- MyLog.Info("[OK] 定时任务 [NoPayCancel] 已启动 (每 5 分钟/GET)");
+ _timerNoPay.AutoReset = true;
+ _timerNoPay.Start();
+
+ MyLog.Info("[OK] 定时任务 [NoPayCancel] 已启动 (每5分钟)");
}
- else
+
+ // ===== 每天22点任务 =====
+ Task.Run(async () =>
{
- MyLog.Info("[提示] 任务 [NoPayCancel] 已在运行中");
- }
+ MyLog.Info("[Nightly] 每日22点任务已启动");
+
+ while (true)
+ {
+ try
+ {
+ DateTime now = DateTime.Now;
+
+ // 今天22点
+ DateTime today22 = new DateTime(
+ now.Year, now.Month, now.Day, 22, 0, 0
+ );
+
+ // 如果已经过了22点,就安排到明天
+ DateTime nextRun = now > today22 ? today22.AddDays(1) : today22;
- // 2. 启动新的每天 22:00 任务 (POST)
- ScheduleNextNightlyRun();
+ TimeSpan delay = nextRun - now;
+
+ MyLog.Info($"[Nightly] 下次执行时间: {nextRun:yyyy-MM-dd HH:mm:ss}");
+
+ // 等待到指定时间
+ await Task.Delay(delay);
+
+ // 执行任务
+ await NightlyTaskCore();
+ }
+ catch (Exception ex)
+ {
+ MyLog.Info("夜间任务异常:" + ex.Message);
+
+ // 出错后延迟1分钟再重试
+ await Task.Delay(TimeSpan.FromMinutes(1));
+ }
+ }
+ });
MyLog.Info("所有定时任务初始化完成。");
}