dsh-workbench-tasks 0.0.0-stage → 5.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -2
- package/cordis.patch.yml +7 -0
- package/lib/client.js +11963 -0
- package/lib/db/db-core.js +432 -0
- package/lib/db/db-legacy.js +473 -0
- package/lib/db/db.js +97 -0
- package/lib/db/ownership-path.js +33 -0
- package/lib/db/timeline-schema.js +7 -0
- package/lib/db/workspace-schema.js +15 -0
- package/lib/index.js +232 -0
- package/lib/infra/backup.js +289 -0
- package/lib/infra/config.js +462 -0
- package/lib/infra/data.js +368 -0
- package/lib/infra/sync.js +189 -0
- package/lib/publisher/brief.js +76 -0
- package/lib/publisher/catalog.js +99 -0
- package/lib/publisher/command.js +81 -0
- package/lib/stats/activity-calendar.js +74 -0
- package/lib/stats/difficulty-bins.js +49 -0
- package/lib/stats/events.js +40 -0
- package/lib/stats/overview.js +99 -0
- package/lib/stats/stats-today.js +26 -0
- package/lib/stats/stats.js +589 -0
- package/lib/stats/timeline-stats.js +174 -0
- package/lib/tagging/source.js +89 -0
- package/lib/tagging/tag-options.js +99 -0
- package/lib/tagging/tagging.js +371 -0
- package/lib/task/model/task-difficulty.js +15 -0
- package/lib/task/model/task-model.js +256 -0
- package/lib/task/model/task-ownership-path.js +22 -0
- package/lib/task/model/task-priority.js +33 -0
- package/lib/task/read/task-discovery.js +123 -0
- package/lib/task/read/task-publish-filter.js +31 -0
- package/lib/task/read/task-query.js +351 -0
- package/lib/task/read/task-search-schema.js +34 -0
- package/lib/task/read/task-view.js +146 -0
- package/lib/task/write/task-bulk.js +247 -0
- package/lib/task/write/task-claim.js +229 -0
- package/lib/task/write/task-create-schema.js +34 -0
- package/lib/task/write/task-create.js +178 -0
- package/lib/task/write/task-operations.js +207 -0
- package/lib/task/write/task-target.js +56 -0
- package/lib/task/write/task-transaction.js +18 -0
- package/lib/task/write/task-update.js +104 -0
- package/lib/tasks.js +456 -0
- package/lib/timeline/task-timelines.js +110 -0
- package/lib/timeline/timeline-actions.js +69 -0
- package/lib/timeline/timeline-migration.js +70 -0
- package/lib/timeline/timeline-store.js +57 -0
- package/lib/timeline/timeline-sync.js +46 -0
- package/lib/tree/task-node-write.js +26 -0
- package/lib/tree/tree.js +517 -0
- package/lib/workspace/workspace-actions.js +217 -0
- package/lib/workspace/workspace-store.js +196 -0
- package/package.json +144 -4
- package/shared/tree/limits.cjs +3 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function clampPriority(value, fallback) {
|
|
2
|
+
if (value === undefined || value === null || value === "") return fallback;
|
|
3
|
+
const n = Number(value);
|
|
4
|
+
if (!Number.isFinite(n)) throw new Error("priority 必须是数字");
|
|
5
|
+
const v = Math.round(n);
|
|
6
|
+
if (v < 0 || v > 10) throw new Error("priority 必须在 0..10");
|
|
7
|
+
return v;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 优先级状态机(唯一入口):
|
|
12
|
+
* - 已开启(status=0):P1..P10,显式传 0 是错误(0 只表示「没有优先级」);
|
|
13
|
+
* - 已关闭/已完成/已重启:一律 P0,写入什么都被忽略;
|
|
14
|
+
* - 已接取(4):仍持有 P1..P10,与已开启同规;
|
|
15
|
+
* - 开启但历史值为 0(旧数据)且本次没有显式传值:回落到 P1。
|
|
16
|
+
*/
|
|
17
|
+
export function priorityForStatus(status, requested, fallback) {
|
|
18
|
+
// 已接取(4)仍持有优先级,按「开启类」处理。
|
|
19
|
+
if (status !== "0" && status !== "4") return 0;
|
|
20
|
+
if (requested !== undefined && requested !== null && requested !== "" && Number(requested) === 0) {
|
|
21
|
+
throw new Error("已开启任务的优先级必须在 1..10(0 仅用于已完成/已关闭)");
|
|
22
|
+
}
|
|
23
|
+
const p = clampPriority(requested, fallback);
|
|
24
|
+
return p > 0 ? p : 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 重启创建的默认值固定 P1;调用方可显式传入原任务有效优先级。 */
|
|
28
|
+
export function priorityForCreate(status, requested, source) {
|
|
29
|
+
if (source === "2" && requested !== undefined && requested !== null && requested !== "" && Number(requested) === 0) {
|
|
30
|
+
throw new Error("重启任务的优先级必须是 1–10;已完成/已关闭任务才用 0");
|
|
31
|
+
}
|
|
32
|
+
return priorityForStatus(status, requested, 1);
|
|
33
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { DIFFICULTY_GUIDANCE } from "../model/task-difficulty.js";
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { nodeMap } from '../../db/db.js';
|
|
4
|
+
import { tagsAvailable } from '../../tagging/tagging.js';
|
|
5
|
+
import { ownershipError, pathFromMap } from '../model/task-ownership-path.js';
|
|
6
|
+
|
|
7
|
+
export const GUIDANCE = [
|
|
8
|
+
DIFFICULTY_GUIDANCE,
|
|
9
|
+
'已有具体开发、修复、设计任务:先核对职责、完整路径与描述,显式 domain→tableId 映射优先,选择后带 tableId 创建。',
|
|
10
|
+
'已确认的新子模块:先核对组/表形态,无合适表且获授权才用 tablePath + createMissing:true + pathDescriptions;不要每条任务新建表。',
|
|
11
|
+
'一次性问答、临时查询不建任务;物品登记走 storage.create,开发 storage 功能才走 tasks。',
|
|
12
|
+
'目标不确定或多候选:展示路径与描述请用户选;唯一候选也仅建议核对,不按第一项、热度或分数自动写入。',
|
|
13
|
+
'结论要标注来源:运行时 action 返回用于判断当前能力,源码只说明实现,历史任务只说明意图;三者冲突时先做只读核对再下结论。',
|
|
14
|
+
];
|
|
15
|
+
export const NO_MATCH_STEPS = [
|
|
16
|
+
'taskNodes.overview({}):读取完整节点树(名称、类型、完整路径、职责描述、子树任务数),确认是否已有合适任务表',
|
|
17
|
+
'tasks.capabilities({limit:200}):分页浏览全部任务表;truncated=true 时按 nextCursor 继续,不能把一页当作全部',
|
|
18
|
+
'核对确属新路径且已获授权:tasks.create 传 tablePath + createMissing:true + pathDescriptions;不要每条任务新建表',
|
|
19
|
+
];
|
|
20
|
+
export const EVIDENCE_NOTE = '本次结果来自当前实例运行时数据;未配置 domain→tableId 映射、关键词未命中、任务表不存在是三件不同的事,不能互相推断。';
|
|
21
|
+
export function tableCatalog(db, api) {
|
|
22
|
+
const map = nodeMap(db), tables = [], diagnostics = [];
|
|
23
|
+
const tagDomainAvailable = tagsAvailable(db, api);
|
|
24
|
+
for (const row of map.values()) {
|
|
25
|
+
if (row.deleted_at != null || String(row.type) !== '1') continue;
|
|
26
|
+
let path;
|
|
27
|
+
try { path = pathFromMap(row.id, map); }
|
|
28
|
+
catch (error) { diagnostics.push({ id: String(row.id), code: error.code, message: error.message }); continue; }
|
|
29
|
+
const counts = db.prepare("SELECT COUNT(*) AS total, SUM(CASE WHEN status='0' THEN 1 ELSE 0 END) AS active, MAX(updated_at) AS used FROM task WHERE table_id=? AND deleted_at IS NULL").get(String(row.id));
|
|
30
|
+
const commonTags = tagDomainAvailable ? db.prepare("SELECT g.id,g.name,COUNT(DISTINCT t.id) AS count FROM task t JOIN tag_mapping m ON m.item_type='task' AND m.item_id=t.id AND m.deleted_at IS NULL JOIN tag g ON g.id=m.tag_id AND g.deleted_at IS NULL WHERE t.table_id=? AND t.deleted_at IS NULL GROUP BY g.id,g.name ORDER BY count DESC,g.id ASC LIMIT 5").all(String(row.id)).map(g => ({ id: String(g.id), name: g.name, count: Number(g.count) })) : [];
|
|
31
|
+
tables.push({ id: String(row.id), name: row.name, ...path, description: String(row.description || ''), taskCount: Number(counts.total), activeTaskCount: Number(counts.active || 0), lastUsedAt: counts.used == null ? null : Number(counts.used), lastUsedBasis: 'MAX(updated_at) of non-deleted tasks; not reading/access time', commonTags, commonTagsStatus: tagDomainAvailable ? 'available' : 'unavailable' });
|
|
32
|
+
}
|
|
33
|
+
tables.sort((candidateA,candidateB) => candidateA.id < candidateB.id ? -1 : candidateA.id > candidateB.id ? 1 : 0);
|
|
34
|
+
return { tables, diagnostics, tagDomainAvailable };
|
|
35
|
+
}
|
|
36
|
+
// 规则 v1:有限停用短语与显式同义词,不声称自然语言语义理解。
|
|
37
|
+
export const MATCH_RULE_VERSION = 'terms-v1';
|
|
38
|
+
const SYNONYMS = [['存储', 'storage'], ['任务', 'tasks'], ['标签', 'tags'], ['站点', 'sites']];
|
|
39
|
+
function termsOf(query) {
|
|
40
|
+
const cleaned = query.toLowerCase().replace(/相关的|相关|的待办|待办|请帮我|帮我|我要|一个|任务$/g, ' ').trim();
|
|
41
|
+
const terms = cleaned.split(/[\s,,。;;]+/).filter(Boolean);
|
|
42
|
+
for (const pair of SYNONYMS) if (pair.some(s => cleaned.includes(s))) for (const s of pair) if (!terms.includes(s)) terms.push(s);
|
|
43
|
+
return terms;
|
|
44
|
+
}
|
|
45
|
+
export function resolveTable(db, args, api) {
|
|
46
|
+
if (typeof args.query !== 'string' || !args.query.trim()) throw ownershipError('INVALID_QUERY', 'query 必须是非空字符串');
|
|
47
|
+
const query = args.query.trim(), terms = termsOf(query);
|
|
48
|
+
const limit = limitArg(args.limit, 5, 20);
|
|
49
|
+
const catalog = tableCatalog(db, api);
|
|
50
|
+
const candidates = [];
|
|
51
|
+
for (const table of catalog.tables) {
|
|
52
|
+
const matchedOn = [], reasons = [];
|
|
53
|
+
let score = 0;
|
|
54
|
+
if (table.name.toLowerCase() === query.toLowerCase()) { score = 1000; matchedOn.push('nameExact'); reasons.push('表名精确匹配'); }
|
|
55
|
+
for (const [field, text, weight] of [['name', table.name, 100], ['path', table.path, 30], ['description', table.description, 10], ['commonTags', table.commonTags.map(g => g.name).join(' '), 3]]) {
|
|
56
|
+
const hits = terms.filter(term => String(text).toLowerCase().includes(term));
|
|
57
|
+
if (hits.length) { score += weight; matchedOn.push(field); reasons.push(field + ' 词项匹配:' + hits.join('、')); }
|
|
58
|
+
}
|
|
59
|
+
if (score) candidates.push({ ...table, score, matchedOn, reasons });
|
|
60
|
+
}
|
|
61
|
+
candidates.sort((candidateA,candidateB) => candidateB.score-candidateA.score || (candidateB.lastUsedAt || 0)-(candidateA.lastUsedAt || 0) || (candidateA.id < candidateB.id ? -1 : candidateA.id > candidateB.id ? 1 : 0));
|
|
62
|
+
const noMatch = candidates.length === 0;
|
|
63
|
+
const notice = noMatch
|
|
64
|
+
? '本次关键词未命中,不代表不存在任务表:当前实例共有 ' + catalog.tables.length + ' 张存活任务表可浏览,请按 nextActions 只读核对后再决定是否新建。'
|
|
65
|
+
: '候选按确定性词项打分,仅供核对;不存在自动选择或自动写入。';
|
|
66
|
+
return {
|
|
67
|
+
candidates: candidates.slice(0,limit), total: candidates.length, truncated: candidates.length > limit,
|
|
68
|
+
needsSelection: true, noMatch: noMatch, catalogSize: catalog.tables.length,
|
|
69
|
+
terms: terms, matchMethod: 'deterministic-terms', matchRuleVersion: MATCH_RULE_VERSION,
|
|
70
|
+
notice: notice, evidence: EVIDENCE_NOTE,
|
|
71
|
+
nextActions: noMatch ? NO_MATCH_STEPS : ['展示 pathSegments 与 description 给用户确认', '确认后用 tasks.capabilities({tableId}) 复核完整祖先链,再带 tableId 创建'],
|
|
72
|
+
diagnostics: catalog.diagnostics, guidance: GUIDANCE,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function limitArg(value, fallback, max) {
|
|
76
|
+
if (value === undefined) return fallback;
|
|
77
|
+
if (!Number.isInteger(value) || value < 1) throw ownershipError('INVALID_LIMIT', 'limit 必须是正整数');
|
|
78
|
+
return Math.min(max, value);
|
|
79
|
+
}
|
|
80
|
+
export function taskCapabilities(db, args, api) {
|
|
81
|
+
const { tables, diagnostics, tagDomainAvailable } = tableCatalog(db, api);
|
|
82
|
+
const limit = limitArg(args.limit, 50, 200);
|
|
83
|
+
if (args.tableId !== undefined) {
|
|
84
|
+
if (args.cursor !== undefined) throw ownershipError('INVALID_TARGET_OPTIONS', 'tableId 与 cursor 互斥');
|
|
85
|
+
const row = db.prepare('SELECT * FROM task_node WHERE id=? AND deleted_at IS NULL').get(String(args.tableId));
|
|
86
|
+
if (!row) throw ownershipError('TABLE_NOT_FOUND', '任务表不存在:' + args.tableId);
|
|
87
|
+
if (String(row.type) !== '1') throw ownershipError('TARGET_NOT_TABLE', '目标不是任务表:' + args.tableId);
|
|
88
|
+
pathFromMap(row.id, nodeMap(db));
|
|
89
|
+
return { guidance: GUIDANCE, tables: tables.filter(t => t.id === String(args.tableId)), total: 1, nextCursor: null, truncated: false, tagDomainAvailable, diagnostics };
|
|
90
|
+
}
|
|
91
|
+
const fingerprint = createHash('sha256').update(JSON.stringify(tables)).digest('hex');
|
|
92
|
+
let offset = 0;
|
|
93
|
+
if (args.cursor !== undefined) {
|
|
94
|
+
try {
|
|
95
|
+
const cursor = JSON.parse(Buffer.from(args.cursor, 'base64url').toString());
|
|
96
|
+
if (cursor.fingerprint !== fingerprint || !Number.isInteger(cursor.offset) || cursor.offset < 1 || cursor.offset >= tables.length) throw new Error('stale');
|
|
97
|
+
offset = cursor.offset;
|
|
98
|
+
} catch { throw ownershipError('INVALID_CURSOR', '游标已失效,请不带 cursor 重新查询 tasks.capabilities'); }
|
|
99
|
+
}
|
|
100
|
+
const end = Math.min(offset + limit, tables.length);
|
|
101
|
+
const empty = tables.length === 0;
|
|
102
|
+
return {
|
|
103
|
+
guidance: GUIDANCE, tables: tables.slice(offset,end), total: tables.length,
|
|
104
|
+
nextCursor: end < tables.length ? Buffer.from(JSON.stringify({ fingerprint, offset: end })).toString('base64url') : null,
|
|
105
|
+
truncated: end < tables.length, tagDomainAvailable, diagnostics,
|
|
106
|
+
notice: empty
|
|
107
|
+
? '当前没有任何存活任务表(节点树里 type=table 的节点为 0),这与「未配置 domain→tableId 映射」不同。先 taskNodes.overview 查看节点树;确需新表时用 tasks.create 的 tablePath + createMissing:true + pathDescriptions(先获授权)。'
|
|
108
|
+
: (end < tables.length ? '已分页:还有 ' + (tables.length - end) + ' 张表未返回,用 nextCursor 继续,不能把本页当作全部。' : '已返回全部 ' + tables.length + ' 张任务表。'),
|
|
109
|
+
evidence: EVIDENCE_NOTE,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export function registerDiscoveryActions(api) {
|
|
113
|
+
api.action('tasks.capabilities', {
|
|
114
|
+
description: '只读任务归属发现:先核对职责、路径再创建。未配置 domain→tableId 映射不阻断在核对现有表职责后创建任务,也不是「没有任务表」。分页不能当作全部表,truncated 时用 nextCursor;tableId 精确查询与 cursor 互斥。' + GUIDANCE.join(' '),
|
|
115
|
+
input: { type: 'object', properties: { limit: { type: 'integer', minimum: 1, description: '默认50,最大200' }, cursor: { type: 'string', description: '上一页 nextCursor;失效时重新查询' }, tableId: { type: ['string','number'], description: '精确验证存活任务表与完整祖先链;与cursor互斥' } } },
|
|
116
|
+
execute: args => taskCapabilities(api.db, args || {}, api), render: result => JSON.stringify(result),
|
|
117
|
+
});
|
|
118
|
+
api.action('tasks.resolveTable', {
|
|
119
|
+
description: '只读候选检索,确定性词项匹配(非语义推断),只返回合法任务表;即使唯一候选也需核对,不自动创建。候选为空时返回 noMatch、catalogSize、notice 与 nextActions:关键词未命中不代表没有任务表,先按下一步只读核对。' + GUIDANCE.join(' '),
|
|
120
|
+
input: { type: 'object', required: ['query'], properties: { query: { type: 'string', minLength: 1, description: '任务主题,SQL通配符按文字匹配' }, limit: { type: 'integer', minimum: 1, description: '默认5,最大20' } } },
|
|
121
|
+
execute: args => resolveTable(api.db, args || {}, api), render: result => JSON.stringify(result),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** 四组事件日期范围共用真实日期校验;只比较存储值的日期部分。 */
|
|
2
|
+
function rangeDay(value, field) {
|
|
3
|
+
if (value === undefined || value === null || value === "") return null;
|
|
4
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
5
|
+
throw new Error(field + " 必须是合法的 YYYY-MM-DD 日期");
|
|
6
|
+
}
|
|
7
|
+
const [year, month, day] = value.split("-").map(Number);
|
|
8
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
9
|
+
if (year < 1 || month < 1 || month > 12 || day < 1 ||
|
|
10
|
+
day > [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]) {
|
|
11
|
+
throw new Error(field + " 必须是合法的 YYYY-MM-DD 日期");
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function dateRangeFilter(from, to, kind) {
|
|
17
|
+
const fromKey = kind + "From", toKey = kind + "To";
|
|
18
|
+
let start = rangeDay(from, fromKey), end = rangeDay(to, toKey);
|
|
19
|
+
const notices = [];
|
|
20
|
+
if (start && end && start > end) {
|
|
21
|
+
[start, end] = [end, start];
|
|
22
|
+
const label = { publish: "发布", done: "完成", shutdown: "关闭", claimed: "接取" }[kind];
|
|
23
|
+
notices.push({ code: kind + "_range_swapped", field: fromKey + "/" + toKey,
|
|
24
|
+
message: label + "日期起始晚于终止,已交换", [fromKey]: start, [toKey]: end });
|
|
25
|
+
}
|
|
26
|
+
return { [fromKey]: start, [toKey]: end, notices };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function publishFilter(from, to) {
|
|
30
|
+
return dateRangeFilter(from, to, "publish");
|
|
31
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/** 列表查询。与 tasks.js 的循环依赖只在函数调用期读取,顶层不求值。 */
|
|
2
|
+
import { idOf, addDays, todayStr, nodeMap, taskOut } from "../../db/db.js";
|
|
3
|
+
import { asCode, STATUS_NAMES, STATUSES, requireTable, dateArg, withNotices, tagMissingNotices } from "../../tasks.js";
|
|
4
|
+
import { dateRangeFilter } from "./task-publish-filter.js";
|
|
5
|
+
import { activityFilter } from "../../stats/activity-calendar.js";
|
|
6
|
+
import { clampPriority } from "../model/task-priority.js";
|
|
7
|
+
import { clampDifficulty } from "../model/task-model.js";
|
|
8
|
+
import { attachWorkspaces } from "../../workspace/workspace-store.js";
|
|
9
|
+
import { LEGACY_TYPE_TAGS, tagsAvailable, normalizeTagIds, normalizeTagNames, tagIdsByNames, attachTags, migrateLegacyTypes } from "../../tagging/tagging.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 旧页签参数已移除:tab 与 filterRestarted 不再有实现,传入时明确抛错并给出
|
|
13
|
+
* 迁移映射,避免调用方以为「传了还在生效」。
|
|
14
|
+
*/
|
|
15
|
+
const LEGACY_TAB_HINT = {
|
|
16
|
+
0: "statuses:[0] 且 priorityMin=8、priorityMax=10(新口径的紧急任务只含优先级 8..10)",
|
|
17
|
+
1: "tags:['工作'](旧类型页签已迁成同名标签)",
|
|
18
|
+
2: "tags:['生活']",
|
|
19
|
+
3: "tags:['学习']",
|
|
20
|
+
4: "tags:['开发']",
|
|
21
|
+
5: "statuses:[1](要看已重启传 statuses:[3])",
|
|
22
|
+
6: "statuses:[0]",
|
|
23
|
+
7: "statuses:[2]",
|
|
24
|
+
8: "statuses:[](全部状态,含已重启)",
|
|
25
|
+
9: "statuses:[4]",
|
|
26
|
+
};
|
|
27
|
+
function rejectLegacyArgs(args) {
|
|
28
|
+
if (args.tab !== undefined && args.tab !== null && String(args.tab).trim() !== "") {
|
|
29
|
+
const key = Number(args.tab);
|
|
30
|
+
const hint = LEGACY_TAB_HINT[key] || "statuses(0..4 整数数组,空数组=全部状态)";
|
|
31
|
+
throw new Error("tab 参数已移除:状态筛选统一走 statuses。tab=" + args.tab + " 的等价写法是 " + hint);
|
|
32
|
+
}
|
|
33
|
+
if (args.filterRestarted !== undefined && args.filterRestarted !== null) {
|
|
34
|
+
throw new Error("filterRestarted 参数已移除:状态筛选统一走 statuses;需要含已重启请传 statuses:[0,1,2,3,4] 或空数组(全部状态)");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function listTasks(db, args, api) {
|
|
39
|
+
const activity = activityFilter(args.activityDate, args.activityType);
|
|
40
|
+
const ranges = [
|
|
41
|
+
dateRangeFilter(args.publishFrom, args.publishTo, "publish"),
|
|
42
|
+
dateRangeFilter(args.doneFrom, args.doneTo, "done"),
|
|
43
|
+
dateRangeFilter(args.shutdownFrom, args.shutdownTo, "shutdown"),
|
|
44
|
+
dateRangeFilter(args.claimedFrom, args.claimedTo, "claimed"),
|
|
45
|
+
];
|
|
46
|
+
rejectLegacyArgs(args);
|
|
47
|
+
const multiStatus = args.statuses !== undefined || args.urgent !== undefined;
|
|
48
|
+
if (args.statuses !== undefined && (!Array.isArray(args.statuses) ||
|
|
49
|
+
args.statuses.some(s => !Number.isInteger(s) || s < 0 || s > 4))) {
|
|
50
|
+
throw new Error("statuses 必须是 0/1/2/3/4 整数数组");
|
|
51
|
+
}
|
|
52
|
+
if (args.urgent !== undefined && typeof args.urgent !== "boolean") throw new Error("urgent 必须是布尔值");
|
|
53
|
+
const statuses = [...new Set(args.statuses || [])];
|
|
54
|
+
const urgent = args.urgent === true;
|
|
55
|
+
// 第一次打开列表时把旧「类型」补成标签;幂等,失败不阻断列表。
|
|
56
|
+
try {
|
|
57
|
+
migrateLegacyTypes(db, api, "migrate");
|
|
58
|
+
} catch (e) {
|
|
59
|
+
/* ignore */
|
|
60
|
+
}
|
|
61
|
+
const where = ["t.deleted_at IS NULL"];
|
|
62
|
+
const params = [];
|
|
63
|
+
const listNotices = ranges.flatMap(range => range.notices);
|
|
64
|
+
// 四组事件日期共用闭区间;claimed 没有独立列(终态清空接取列),按 COALESCE(claimed_at 本地日, 发布日) 兜底。
|
|
65
|
+
const DATE_FIELDS = {
|
|
66
|
+
publish: { column: "substr(t.publish_date,1,10)", status: null },
|
|
67
|
+
done: { column: "substr(t.done_date,1,10)", status: "t.status='2'" },
|
|
68
|
+
shutdown: { column: "substr(t.shutdown_date,1,10)", status: "t.status='1'" },
|
|
69
|
+
claimed: {
|
|
70
|
+
column: "COALESCE(strftime('%Y-%m-%d', t.claimed_at/1000, 'unixepoch', 'localtime'), substr(t.publish_date,1,10))",
|
|
71
|
+
status: "t.status IN ('2','4')",
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
for (const [index, kind] of ["publish", "done", "shutdown", "claimed"].entries()) {
|
|
75
|
+
const from = ranges[index][kind + "From"], to = ranges[index][kind + "To"];
|
|
76
|
+
const spec = DATE_FIELDS[kind];
|
|
77
|
+
if ((from || to) && spec.status) where.push(spec.status);
|
|
78
|
+
if (from) { where.push(spec.column + ">=?"); params.push(from); }
|
|
79
|
+
if (to) { where.push(spec.column + "<=?"); params.push(to); }
|
|
80
|
+
}
|
|
81
|
+
if (activity) { where.push(activity.sql); params.push(...activity.params); }
|
|
82
|
+
|
|
83
|
+
const titleKey = args.titleKey === undefined || args.titleKey === null ? "" : String(args.titleKey).trim();
|
|
84
|
+
if (titleKey) {
|
|
85
|
+
const key = titleKey.replace(/[\\%_]/g, "\\$&");
|
|
86
|
+
where.push("(t.title LIKE ? ESCAPE '\\' OR t.description LIKE ? ESCAPE '\\' OR t.review LIKE ? ESCAPE '\\' OR t.id LIKE ? ESCAPE '\\')");
|
|
87
|
+
params.push("%" + key + "%", "%" + key + "%", "%" + key + "%", "%" + key + "%");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const tableId = idOf(args.tableId);
|
|
91
|
+
const groupId = idOf(args.groupId);
|
|
92
|
+
if (tableId && tableId !== "0") {
|
|
93
|
+
requireTable(db, tableId);
|
|
94
|
+
where.push("t.table_id=?");
|
|
95
|
+
params.push(tableId);
|
|
96
|
+
} else if (groupId && groupId !== "0") {
|
|
97
|
+
const group = db.prepare("SELECT * FROM task_node WHERE id=? AND deleted_at IS NULL").get(groupId);
|
|
98
|
+
if (!group) throw new Error("任务组不存在:" + groupId);
|
|
99
|
+
const prefix = String(group.path || "") + "%";
|
|
100
|
+
const tables = db.prepare("SELECT id FROM task_node WHERE type='1' AND deleted_at IS NULL AND path LIKE ?").all(prefix);
|
|
101
|
+
if (!tables.length) {
|
|
102
|
+
where.push("1=0");
|
|
103
|
+
} else {
|
|
104
|
+
where.push("t.table_id IN (" + tables.map(function () { return "?"; }).join(",") + ")");
|
|
105
|
+
for (const t of tables) params.push(String(t.id));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const tableKey = args.tableKey === undefined || args.tableKey === null ? "" : String(args.tableKey).trim();
|
|
110
|
+
if (tableKey) {
|
|
111
|
+
const key = tableKey.replace(/[\\%_]/g, "\\$&");
|
|
112
|
+
where.push(
|
|
113
|
+
"EXISTS (SELECT 1 FROM task_node n WHERE n.id=t.table_id AND n.deleted_at IS NULL AND (n.name LIKE ? ESCAPE '\\' OR n.description LIKE ? ESCAPE '\\'))",
|
|
114
|
+
);
|
|
115
|
+
params.push("%" + key + "%", "%" + key + "%");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const workspaceIds = Array.isArray(args.workspaceIds)
|
|
119
|
+
? [...new Set(args.workspaceIds.map(function (v) { return String(v).trim(); }).filter(Boolean))]
|
|
120
|
+
: [];
|
|
121
|
+
const noWorkspace = args.noWorkspace === true;
|
|
122
|
+
if (workspaceIds.length && noWorkspace) {
|
|
123
|
+
throw new Error("workspaceIds 与 noWorkspace 互斥:要么按工作区筛,要么只看未关联工作区的任务");
|
|
124
|
+
}
|
|
125
|
+
if (workspaceIds.length) {
|
|
126
|
+
where.push(
|
|
127
|
+
"EXISTS (SELECT 1 FROM task_workspace_link wl JOIN task_workspace w ON w.id=wl.workspace_id " +
|
|
128
|
+
"WHERE wl.task_id=t.id AND wl.deleted_at IS NULL AND w.deleted_at IS NULL AND wl.workspace_id IN (" +
|
|
129
|
+
workspaceIds.map(function () { return "?"; }).join(",") + "))",
|
|
130
|
+
);
|
|
131
|
+
for (const id of workspaceIds) params.push(id);
|
|
132
|
+
} else if (noWorkspace) {
|
|
133
|
+
where.push(
|
|
134
|
+
"NOT EXISTS (SELECT 1 FROM task_workspace_link wl JOIN task_workspace w ON w.id=wl.workspace_id " +
|
|
135
|
+
"WHERE wl.task_id=t.id AND wl.deleted_at IS NULL AND w.deleted_at IS NULL)",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 旧前端的 checkedTypes(0..3)仍接受,按旧类型名映射成标签过滤。
|
|
140
|
+
const checkedTypes = Array.isArray(args.checkedTypes) ? args.checkedTypes.map(String) : [];
|
|
141
|
+
for (const c of checkedTypes) {
|
|
142
|
+
if (!(c in LEGACY_TYPE_TAGS)) throw new Error("checkedTypes 取值非法:" + c);
|
|
143
|
+
}
|
|
144
|
+
const tagAvailable = tagsAvailable(db, api);
|
|
145
|
+
let filterTagIds = normalizeTagIds(args.tagIds);
|
|
146
|
+
const filterTagNames = normalizeTagNames(args.tags);
|
|
147
|
+
for (const c of checkedTypes) {
|
|
148
|
+
const name = LEGACY_TYPE_TAGS[c];
|
|
149
|
+
if (filterTagNames.indexOf(name) < 0) filterTagNames.push(name);
|
|
150
|
+
}
|
|
151
|
+
if (filterTagNames.length) {
|
|
152
|
+
if (!tagAvailable) {
|
|
153
|
+
// 可选能力缺失:不报错,按「筛不到任何任务」处理,并在回执里说明原因。
|
|
154
|
+
listNotices.push(tagMissingNotices({ tags: [] }, false)[0]);
|
|
155
|
+
where.push("1=0");
|
|
156
|
+
}
|
|
157
|
+
const resolved = tagAvailable ? tagIdsByNames(db, filterTagNames) : { ids: [] };
|
|
158
|
+
for (const id of resolved.ids) if (filterTagIds.indexOf(id) < 0) filterTagIds.push(id);
|
|
159
|
+
if (!resolved.ids.length) where.push("1=0");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 区间端点校验:复用优先级/难度各自的 clamp,但把错误归到具体字段名上。
|
|
164
|
+
* agent 只看到 schema,报错里没有字段名就无法判断是 min 还是 max 传错。
|
|
165
|
+
*/
|
|
166
|
+
function rangeArg(clamp, value, label, span) {
|
|
167
|
+
try {
|
|
168
|
+
return clamp(value, null);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
throw new Error(label + " 必须是 " + span + " 内的数字");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 额外过滤:与 tab/tableId/groupId 条件是 AND 关系。
|
|
175
|
+
if (args.status !== undefined && args.status !== null && args.status !== "") {
|
|
176
|
+
where.push("t.status=?");
|
|
177
|
+
params.push(asCode(args.status, STATUS_NAMES, STATUSES, "status"));
|
|
178
|
+
}
|
|
179
|
+
const difficultyMissing = args.difficultyMissing === true;
|
|
180
|
+
if (difficultyMissing) where.push("(t.difficulty IS NULL OR t.difficulty=0)");
|
|
181
|
+
const priorityMin = rangeArg(clampPriority, args.priorityMin, "priorityMin", "0..10");
|
|
182
|
+
const priorityMax = rangeArg(clampPriority, args.priorityMax, "priorityMax", "0..10");
|
|
183
|
+
if (priorityMin !== null) {
|
|
184
|
+
where.push("t.priority>=?");
|
|
185
|
+
params.push(priorityMin);
|
|
186
|
+
}
|
|
187
|
+
if (priorityMax !== null) {
|
|
188
|
+
where.push("t.priority<=?");
|
|
189
|
+
params.push(priorityMax);
|
|
190
|
+
}
|
|
191
|
+
// 难度区间:NULL 视作未设置(0),所以凡是下界为 0 的区间都要显式把 NULL 算进来,
|
|
192
|
+
// 否则「难度 ≤3」会把未填难度的任务整批漏掉。0 是合法端点,1..5 才是可选档位。
|
|
193
|
+
const difficultyMin = rangeArg(clampDifficulty, args.difficultyMin, "difficultyMin", "0..5");
|
|
194
|
+
const difficultyMax = rangeArg(clampDifficulty, args.difficultyMax, "difficultyMax", "0..5");
|
|
195
|
+
if (difficultyMin !== null && difficultyMax !== null) {
|
|
196
|
+
if (difficultyMin <= 0) {
|
|
197
|
+
where.push("(t.difficulty IS NULL OR t.difficulty BETWEEN ? AND ?)");
|
|
198
|
+
params.push(difficultyMin, difficultyMax);
|
|
199
|
+
} else {
|
|
200
|
+
where.push("t.difficulty BETWEEN ? AND ?");
|
|
201
|
+
params.push(difficultyMin, difficultyMax);
|
|
202
|
+
}
|
|
203
|
+
} else if (difficultyMin !== null) {
|
|
204
|
+
if (difficultyMin <= 0) where.push("(t.difficulty IS NULL OR t.difficulty>=?)");
|
|
205
|
+
else where.push("t.difficulty>=?");
|
|
206
|
+
params.push(difficultyMin);
|
|
207
|
+
} else if (difficultyMax !== null) {
|
|
208
|
+
where.push("(t.difficulty IS NULL OR t.difficulty<=?)");
|
|
209
|
+
params.push(difficultyMax);
|
|
210
|
+
}
|
|
211
|
+
const targetFrom = dateArg(args.targetFrom, "targetFrom");
|
|
212
|
+
if (targetFrom) {
|
|
213
|
+
where.push("t.target_date>=?");
|
|
214
|
+
params.push(targetFrom);
|
|
215
|
+
}
|
|
216
|
+
const targetTo = dateArg(args.targetTo, "targetTo");
|
|
217
|
+
if (targetTo) {
|
|
218
|
+
where.push("t.target_date<=?");
|
|
219
|
+
params.push(targetTo);
|
|
220
|
+
}
|
|
221
|
+
if (filterTagIds.length && !tagAvailable) {
|
|
222
|
+
if (!listNotices.some(n => n.code === "tag_domain_missing")) listNotices.push(tagMissingNotices({ tags: [] }, false)[0]);
|
|
223
|
+
where.push("1=0");
|
|
224
|
+
} else if (filterTagIds.length) {
|
|
225
|
+
where.push("EXISTS (SELECT 1 FROM tag_mapping tm WHERE tm.item_type='task' AND tm.item_id=t.id AND tm.deleted_at IS NULL AND tm.tag_id IN (" + filterTagIds.map(function () { return "?"; }).join(",") + "))");
|
|
226
|
+
for (const id of filterTagIds) params.push(id);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (multiStatus) {
|
|
230
|
+
const alternatives = [];
|
|
231
|
+
if (statuses.length) {
|
|
232
|
+
alternatives.push("t.status IN (" + statuses.map(() => "?").join(",") + ")");
|
|
233
|
+
params.push(...statuses.map(String));
|
|
234
|
+
}
|
|
235
|
+
if (urgent) {
|
|
236
|
+
alternatives.push("(t.status='0' AND (t.priority>=6 OR t.target_date<=?))");
|
|
237
|
+
params.push(addDays(todayStr(), 2));
|
|
238
|
+
}
|
|
239
|
+
if (alternatives.length) where.push("(" + alternatives.join(" OR ") + ")");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 分页语义(2026-11-08 明确化):
|
|
243
|
+
// - pageSize 夹在 1..200,请求值超出时按上限截断并在 filter.pageSize 回显实际值;
|
|
244
|
+
// - total 永远是筛选后的真实总数(不受 LIMIT 影响),returned 是本页实际返回条数;
|
|
245
|
+
// - 未分页时最多返回 MAX_UNPAGED 条,被截断时 truncated=true。
|
|
246
|
+
const MAX_PAGE_SIZE = 200;
|
|
247
|
+
const MAX_UNPAGED = 500;
|
|
248
|
+
const wantPaging = args.pageNumber !== undefined || args.pageSize !== undefined;
|
|
249
|
+
const pageable = wantPaging;
|
|
250
|
+
let pageNumber = 1;
|
|
251
|
+
let pageSize = 0;
|
|
252
|
+
let limitSql = "";
|
|
253
|
+
let pageSizeRequested = null;
|
|
254
|
+
if (pageable) {
|
|
255
|
+
pageNumber = Math.max(1, Math.floor(Number(args.pageNumber) || 1));
|
|
256
|
+
const rawSize = Number(args.pageSize);
|
|
257
|
+
pageSizeRequested = Number.isFinite(rawSize) && rawSize > 0 ? Math.floor(rawSize) : null;
|
|
258
|
+
pageSize = Math.max(1, Math.min(MAX_PAGE_SIZE, pageSizeRequested || 12));
|
|
259
|
+
limitSql = " LIMIT ? OFFSET ?";
|
|
260
|
+
} else {
|
|
261
|
+
limitSql = " LIMIT " + MAX_UNPAGED;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const SORTS = {
|
|
265
|
+
priority: "t.priority", target: "t.target_date", publish: "t.publish_date",
|
|
266
|
+
updated: "t.updated_at", created: "t.created_at",
|
|
267
|
+
};
|
|
268
|
+
let order = "";
|
|
269
|
+
if (args.sort !== undefined && args.sort !== null && String(args.sort).trim() !== "") {
|
|
270
|
+
let key = String(args.sort).trim();
|
|
271
|
+
let dir = "ASC";
|
|
272
|
+
if (key.charAt(0) === "-") {
|
|
273
|
+
dir = "DESC";
|
|
274
|
+
key = key.slice(1);
|
|
275
|
+
}
|
|
276
|
+
const col = SORTS[key];
|
|
277
|
+
if (!col) throw new Error("sort 取值非法:" + args.sort + "(可用 priority / target / publish / updated / created,前缀 - 表示降序)");
|
|
278
|
+
if (args.order !== undefined && String(args.order).trim() !== "") {
|
|
279
|
+
const o = String(args.order).trim().toUpperCase();
|
|
280
|
+
if (o !== "ASC" && o !== "DESC") throw new Error("order 只能是 asc 或 desc");
|
|
281
|
+
dir = o;
|
|
282
|
+
}
|
|
283
|
+
order = " ORDER BY " + col + " " + dir + ", t.id " + dir;
|
|
284
|
+
} else {
|
|
285
|
+
order = pageable
|
|
286
|
+
? " ORDER BY t.publish_date DESC, t.id DESC"
|
|
287
|
+
: " ORDER BY t.priority DESC, t.target_date ASC, t.publish_date DESC, t.id ASC";
|
|
288
|
+
}
|
|
289
|
+
const base = " FROM task t WHERE " + where.join(" AND ");
|
|
290
|
+
const total = db.prepare("SELECT COUNT(*) AS n" + base).get(...params).n;
|
|
291
|
+
const queryParams = params.slice();
|
|
292
|
+
if (pageable) {
|
|
293
|
+
queryParams.push(pageSize, (pageNumber - 1) * pageSize);
|
|
294
|
+
}
|
|
295
|
+
const rows = db.prepare("SELECT t.*" + base + order + limitSql).all(...queryParams);
|
|
296
|
+
const map = nodeMap(db);
|
|
297
|
+
const records = rows.map(function (r) {
|
|
298
|
+
return taskOut(r, map);
|
|
299
|
+
});
|
|
300
|
+
attachTags(db, api, records);
|
|
301
|
+
attachWorkspaces(db, records);
|
|
302
|
+
const returned = records.length;
|
|
303
|
+
const truncated = returned < total;
|
|
304
|
+
const filter = {
|
|
305
|
+
pageNumber: pageable ? pageNumber : 1,
|
|
306
|
+
pageSize: pageable ? pageSize : null,
|
|
307
|
+
pageable: pageable,
|
|
308
|
+
totalPages: pageable && pageSize ? Math.max(1, Math.ceil(total / pageSize)) : 1,
|
|
309
|
+
total: total,
|
|
310
|
+
returned: returned,
|
|
311
|
+
truncated: truncated,
|
|
312
|
+
};
|
|
313
|
+
// 请求的 pageSize 超过上限时明确回显被截断,别让调用方以为按 500 取了 500 条。
|
|
314
|
+
if (pageable && pageSizeRequested !== null && pageSizeRequested > pageSize) {
|
|
315
|
+
filter.pageSizeRequested = pageSizeRequested;
|
|
316
|
+
filter.pageSizeCapped = true;
|
|
317
|
+
}
|
|
318
|
+
if (activity) { filter.activityDate = activity.date; filter.activityType = activity.type; }
|
|
319
|
+
if (titleKey) filter.titleKey = titleKey;
|
|
320
|
+
if (tableId && tableId !== "0") filter.tableId = tableId;
|
|
321
|
+
if (tableKey) filter.tableKey = tableKey;
|
|
322
|
+
if (groupId && groupId !== "0") filter.groupId = groupId;
|
|
323
|
+
if (args.status !== undefined && args.status !== null && args.status !== "") filter.status = String(args.status);
|
|
324
|
+
if (filterTagIds.length) filter.tagIds = filterTagIds.slice();
|
|
325
|
+
if (filterTagNames.length) filter.tags = filterTagNames.slice();
|
|
326
|
+
if (workspaceIds.length) filter.workspaceIds = workspaceIds.slice();
|
|
327
|
+
if (noWorkspace) filter.noWorkspace = true;
|
|
328
|
+
if (difficultyMissing) filter.difficultyMissing = true;
|
|
329
|
+
if (priorityMin !== null) filter.priorityMin = priorityMin;
|
|
330
|
+
if (priorityMax !== null) filter.priorityMax = priorityMax;
|
|
331
|
+
if (difficultyMin !== null) filter.difficultyMin = difficultyMin;
|
|
332
|
+
if (difficultyMax !== null) filter.difficultyMax = difficultyMax;
|
|
333
|
+
for (const range of ranges) for (const [key, value] of Object.entries(range)) {
|
|
334
|
+
if (key !== "notices" && value) filter[key] = value;
|
|
335
|
+
}
|
|
336
|
+
if (multiStatus) { filter.statuses = statuses; filter.urgent = urgent; }
|
|
337
|
+
if (targetFrom) filter.targetFrom = targetFrom;
|
|
338
|
+
if (targetTo) filter.targetTo = targetTo;
|
|
339
|
+
if (args.sort) filter.sort = String(args.sort) + (args.order ? " " + String(args.order) : "");
|
|
340
|
+
return withNotices({
|
|
341
|
+
records,
|
|
342
|
+
current: pageable ? pageNumber : 1,
|
|
343
|
+
size: pageable ? pageSize : returned,
|
|
344
|
+
total: total,
|
|
345
|
+
returned: returned,
|
|
346
|
+
truncated: truncated,
|
|
347
|
+
pageable,
|
|
348
|
+
pageSize: pageable ? pageSize : null,
|
|
349
|
+
filter,
|
|
350
|
+
}, listNotices);
|
|
351
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Shared list/export filtering contract; paging remains list-only. */
|
|
2
|
+
export const TASK_FILTER_SCHEMA = {
|
|
3
|
+
statuses: { type: "array", items: { type: "integer", enum: [0, 1, 2, 3, 4] }, description: "多选状态:0 已开启、1 已关闭、2 已完成、3 已重启、4 已接取;去重后 OR,再与其它筛选 AND。不传 statuses 且不传 urgent 时不过滤状态,返回全部状态(含 3 已重启);空数组且 urgent=false 同样表示不按状态筛。过滤面板固定发送本字段(可能是空数组),因此优先级/难度区间筛选不会回落到任何隐含状态条件。filter 回显去重后的 statuses 与 urgent。" },
|
|
4
|
+
urgent: { type: "boolean", description: "旧紧急谓词(仅兼容保留):status=0 且(priority>=6 或 target_date<=本地今天+2天),与 statuses 各状态 OR;不是独立状态。过滤面板已不再发送它,改为前端快捷组合 priorityMin=6、priorityMax=10(口径因此不再包含「优先级低但 2 天内到期」的任务)。传 false 仍会启用新状态模式;缺省 false。" },
|
|
5
|
+
doneFrom: { type: ["string", "null"], description: "完成日起始(含),严格真实 YYYY-MM-DD(0001..9999 年),独立端点,空串/null 未传;按 substr(done_date,1,10) 比较且强制当前 status=2。与发布/关闭范围及其它条件 AND;同时有完成、关闭范围时结果为空。反序交换并在 filter 回显,notices 返回 {code:'done_range_swapped',field:'doneFrom/doneTo',message:'完成日期起始晚于终止,已交换',doneFrom,doneTo}。非 ids 导出共用。" },
|
|
6
|
+
doneTo: { type: ["string", "null"], description: "完成日终止(含);校验、独立端点、空值、status=2、AND、反序和 filter/notices 契约同 doneFrom。" },
|
|
7
|
+
shutdownFrom: { type: ["string", "null"], description: "关闭日起始(含),严格真实 YYYY-MM-DD(0001..9999 年),独立端点,空串/null 未传;按 substr(shutdown_date,1,10) 比较且强制当前 status=1。与发布/完成范围及其它条件 AND;同时有完成、关闭范围时结果为空。反序交换并在 filter 回显,notices 返回 {code:'shutdown_range_swapped',field:'shutdownFrom/shutdownTo',message:'关闭日期起始晚于终止,已交换',shutdownFrom,shutdownTo}。非 ids 导出共用。" },
|
|
8
|
+
shutdownTo: { type: ["string", "null"], description: "关闭日终止(含);校验、独立端点、空值、status=1、AND、反序和 filter/notices 契约同 shutdownFrom。" },
|
|
9
|
+
claimedFrom: { type: ["string", "null"], description: "接取日起始(含),严格真实 YYYY-MM-DD(0001..9999 年),独立端点,空串/null 未传;按 COALESCE(claimed_at 转本地日期, substr(publish_date,1,10)) 比较且强制当前 status IN (2,4)。终端清空接取列,已完成任务不回填,历史任务的接取日按发布日近似。与其它筛选 AND;反序交换并在 filter 回显,notices 返回 {code:'claimed_range_swapped',field:'claimedFrom/claimedTo',message:'接取日期起始晚于终止,已交换',claimedFrom,claimedTo}。非 ids 导出共用。" },
|
|
10
|
+
claimedTo: { type: ["string", "null"], description: "接取日终止(含);校验、独立端点、空值、status IN (2,4)、AND、反序和 filter/notices 契约同 claimedFrom。" },
|
|
11
|
+
publishFrom: { type: ["string", "null"], description: "发布日起始(含),严格真实 YYYY-MM-DD(0001..9999 年);可独立传,空串/null 等同未传。按 substr(publish_date,1,10) 比较,与 target/activity 及其他筛选 AND。起始晚于终止时交换,filter 回显归一后值,notices 返回 {code:'publish_range_swapped',field:'publishFrom/publishTo',message:'发布日期起始晚于终止,已交换',publishFrom,publishTo}。非 ids 导出同口径并透传 filter/notices。" },
|
|
12
|
+
publishTo: { type: ["string", "null"], description: "发布日终止(含),严格真实 YYYY-MM-DD(0001..9999 年);可独立传,空串/null 等同未传。与 publishFrom 构成闭区间,反序自动交换;filter/notices 契约同 publishFrom。" },
|
|
13
|
+
activityDate: { type: "string", pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$", description: "活动日(合法 YYYY-MM-DD,1900..9999 年),与 tasks.activityCalendar 同口径;选定单一事件类型,与现有筛选 AND。全状态请传 statuses=[]。非 ids 导出与列表共用。" },
|
|
14
|
+
activityType: { type: "string", enum: ["publish", "done", "shutdown", "claimed"], description: "需同时传 activityDate,缺省 done;publish=publish_date,done=status2 且 done_date,shutdown=status1 且 shutdown_date,claimed=status IN (2,4) 且按 COALESCE(claimed_at 本地日期, publish_date) 计。" },
|
|
15
|
+
titleKey: { type: "string", description: "关键词字面包含匹配,同时搜索标题、描述、感受、任务 ID(OR);任务 ID 支持完整值、前 8 位或中段片段;整体 ASCII 大小写不敏感,%/_/反斜杠按普通字符、不当作通配符" },
|
|
16
|
+
tableId: { type: ["string", "number", "null"], description: "只看某个任务表" },
|
|
17
|
+
groupId: { type: ["string", "number", "null"], description: "只看某个任务组下的所有任务表" },
|
|
18
|
+
tableKey: { type: "string", description: "按任务表关键词过滤:同时匹配表名与表描述" },
|
|
19
|
+
checkedTypes: { type: "array", items: { type: "string" }, description: "旧参数:任务类型 0..3,按同名标签过滤(新代码请用 tags)" },
|
|
20
|
+
tags: { type: "array", items: { type: "string" }, description: "按标签名过滤,命中任一即可" },
|
|
21
|
+
status: { type: ["string", "number"], description: "直接按状态过滤(与 statuses/urgent 条件 AND)" },
|
|
22
|
+
difficultyMissing: { type: "boolean", description: "true 只看未填难度(NULL 或 0);false/缺省不筛难度,与其他条件 AND,可配合 tasks.bulkUpdate 补齐" },
|
|
23
|
+
priorityMin: { type: "number", description: "最低优先级(含),0..10 整数;与 priorityMax AND。0 只表示没有优先级,UI 区间端点从 1 起。与 statuses 等其它条件 AND。" },
|
|
24
|
+
priorityMax: { type: "number", description: "最高优先级(含),0..10 整数;与 priorityMin AND,min>max 时结果为空(不自动交换)。" },
|
|
25
|
+
difficultyMin: { type: "number", description: "最低难度(含),0..5,兼容 0.5 档;NULL 视作 0。与 difficultyMax AND;下界为 0 时把 NULL 一并算入,下界>0 时排除未填难度的任务。非法或越界抛错,不静默截断。" },
|
|
26
|
+
difficultyMax: { type: "number", description: "最高难度(含),0..5,兼容 0.5 档;NULL 视作 0(因此上限条件包含未填难度)。与 difficultyMin AND。" },
|
|
27
|
+
targetFrom: { type: "string", description: "targetDate >= 该日期" },
|
|
28
|
+
targetTo: { type: "string", description: "targetDate <= 该日期" },
|
|
29
|
+
tagIds: { type: "array", items: { type: "string" }, description: "任一标签命中(AND 到其他条件)" },
|
|
30
|
+
workspaceIds: { type: "array", items: { type: "string" }, description: "按工作区筛选,命中任一即可(OR,再与其他条件 AND);与 noWorkspace 互斥;已删除的工作区与关联不参与匹配" },
|
|
31
|
+
noWorkspace: { type: "boolean", description: "true 只看未关联任何工作区的任务;与 workspaceIds 互斥" },
|
|
32
|
+
sort: { type: "string", description: "priority / target / publish / updated / created;前缀 - 表示降序" },
|
|
33
|
+
order: { type: "string", enum: ["asc", "desc"], description: "配合 sort 指定方向" },
|
|
34
|
+
};
|