岩仔88 1 month ago
parent a2ff92145a
commit 5d3c06c12c

@ -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
}
}
}
}
}
}

@ -1,162 +1,84 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using Newtonsoft.Json;
using Newtonsoft.Json; // 用于生成 JSON 数据
namespace MyHosListener.common namespace MyHosListener.common
{ {
public class Tools public class Tools
{ {
private static Timer _timerNoPay; private static System.Timers.Timer _timerNoPay;
private static Timer _timerNightly; private static readonly HttpClient client = new HttpClient();
// 保持 HttpClient 单例,复用连接
static readonly HttpClient client = new HttpClient();
/// <summary> /// <summary>
/// 原有的委托变更通知 (GET) - 未修改 /// 通知医技取消
/// </summary> /// </summary>
public static async Task NoticeEntrustChange(string orderNo) public static async Task NoticeEntrustChange(string orderNo)
{ {
try try
{ {
string url = $"http://192.168.80.76/api/PacsCancelApplyInfo?orderNo={orderNo}"; 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(); response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync(); string responseBody = await response.Content.ReadAsStringAsync();
MyLog.Info(responseBody); MyLog.Info(responseBody);
} }
catch (HttpRequestException e) catch (Exception e)
{ {
MyLog.Info($"请求错误 (NoticeEntrustChange): {e.Message}"); MyLog.Info($"请求错误 (NoticeEntrustChange): {e.Message}");
Console.WriteLine($"请求错误: {e.Message}");
}
}
/// <summary>
/// 原有的未支付取消任务 (GET) - 未修改
/// </summary>
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}");
} }
} }
/// <summary> /// <summary>
/// 新增每天晚上10点执行的任务 (POST) /// 未支付自动取消每5分钟
/// 逻辑:计算当前日期+15天构建JSON发送POST请求
/// </summary> /// </summary>
public static async void NightlyTaskHandler(object sender, ElapsedEventArgs e) private static async void NoPayCancel(object sender, System.Timers.ElapsedEventArgs e)
{ {
try try
{ {
MyLog.Info(">>> 开始执行每日夜间定时任务 (POST)..."); string url = "http://192.168.80.76/api/admin/NoPayCancel";
// 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
};
// 3. 序列化为 JSON 字符串 var response = await client.GetAsync(url);
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 会抛出异常
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync(); string responseBody = await response.Content.ReadAsStringAsync();
MyLog.Info($"<<< 夜间任务执行成功,响应内容: {responseBody}"); MyLog.Info("[NoPayCancel] " + responseBody);
} }
catch (Exception ex) catch (Exception ex)
{ {
MyLog.Info($"!!! 夜间任务执行失败: {ex.Message}"); MyLog.Info($"请求错误 (NoPayCancel): {ex.Message}");
if (ex.InnerException != null)
{
MyLog.Info($"内部错误详情: {ex.InnerException.Message}");
}
}
finally
{
// 关键步骤:无论成功或失败,都要重新计算下一次运行时间并重启定时器
// 这样能保证即使某次报错,明天的任务依然会准时运行
ScheduleNextNightlyRun();
} }
} }
/// <summary> /// <summary>
/// 计算距离下一个晚上 22:00 的时间间隔,并配置定时器 /// 夜间任务核心逻辑每天22点执行
/// </summary> /// </summary>
private static void ScheduleNextNightlyRun() private static async Task NightlyTaskCore()
{ {
DateTime now = DateTime.Now; MyLog.Info(">>> 夜间任务执行:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
DateTime nextRun = now.Date.AddHours(22); // 设定为今天的 22:00
// 如果现在已超过今天 22:00则设为明天 22:00 DateTime targetDate = DateTime.Now.AddDays(15);
if (nextRun <= now) string dateStr = targetDate.ToString("yyyy-MM-dd");
var postData = new
{ {
nextRun = nextRun.AddDays(1); dateRange = new[] { dateStr, dateStr },
} HolidayEnable = 1
};
// 计算毫秒差 string jsonContent = JsonConvert.SerializeObject(postData);
double intervalMs = (nextRun - now).TotalMilliseconds; var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
// 安全保护:防止负数 string url = "http://192.168.80.76/api/YourNightlyApi";
if (intervalMs < 0) intervalMs = 60000;
if (_timerNightly == null) var response = await client.PostAsync(url, content);
{ response.EnsureSuccessStatusCode();
_timerNightly = new Timer(intervalMs);
_timerNightly.Elapsed += NightlyTaskHandler;
_timerNightly.AutoReset = false; // 设置为只触发一次,由我们在回调中手动重置
}
else
{
_timerNightly.Interval = intervalMs;
_timerNightly.Stop();
_timerNightly.Start();
}
// 确保启用 string responseBody = await response.Content.ReadAsStringAsync();
if (!_timerNightly.Enabled)
{
_timerNightly.Enabled = true;
}
double minutesToWait = intervalMs / 1000 / 60; MyLog.Info("<<< 夜间任务成功:" + responseBody);
MyLog.Info($"[调度器] 夜间任务已设定,将于 {nextRun:yyyy-MM-dd HH:mm:ss} 执行 (约 {minutesToWait:F1} 分钟后)");
} }
/// <summary> /// <summary>
@ -166,22 +88,55 @@ namespace MyHosListener.common
{ {
MyLog.Info("正在初始化定时任务模块..."); MyLog.Info("正在初始化定时任务模块...");
// 1. 启动原有的每 5 分钟任务 (GET) // ===== 5分钟任务 =====
if (_timerNoPay == null) if (_timerNoPay == null)
{ {
_timerNoPay = new Timer(300000); // 300000ms = 5分钟 _timerNoPay = new System.Timers.Timer(300000); // 5分钟
_timerNoPay.Elapsed += NoPayCancel; _timerNoPay.Elapsed += NoPayCancel;
_timerNoPay.AutoReset = true; // 自动重复 _timerNoPay.AutoReset = true;
_timerNoPay.Enabled = true; _timerNoPay.Start();
MyLog.Info("[OK] 定时任务 [NoPayCancel] 已启动 (每 5 分钟/GET)");
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) TimeSpan delay = nextRun - now;
ScheduleNextNightlyRun();
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("所有定时任务初始化完成。"); MyLog.Info("所有定时任务初始化完成。");
} }

Loading…
Cancel
Save