148 lines
4.3 KiB
C++
148 lines
4.3 KiB
C++
#ifndef ETMS_TASK_TEMPLATE_MANAGER_HPP
|
||
#define ETMS_TASK_TEMPLATE_MANAGER_HPP
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <cstdint>
|
||
|
||
/**
|
||
* @brief 任务模板数据结构
|
||
*
|
||
* 对应分析文档中 t_task_template 表的核心字段。
|
||
* 完整模板文件存储于 MinIO 对象存储,本地仅维护元数据。
|
||
*/
|
||
struct TaskTemplate {
|
||
std::string templateId; ///< 模板唯一标识
|
||
std::string name; ///< 模板名称
|
||
std::string version; ///< 版本号
|
||
std::string contentPath; ///< MinIO 对象存储路径
|
||
std::string metadata; ///< 元数据(JSON 字符串)
|
||
int64_t createTime; ///< 创建时间戳 (毫秒)
|
||
uint64_t usageCount; ///< 使用频率计数
|
||
};
|
||
|
||
/**
|
||
* @brief 知识库版本数据结构
|
||
*
|
||
* 对应分析文档中 t_kb_version 表的字段。
|
||
*/
|
||
struct KbVersion {
|
||
std::string versionId; ///< 版本标识
|
||
int64_t releaseDate; ///< 发布日期 (毫秒时间戳)
|
||
std::string description; ///< 版本描述
|
||
bool isActive; ///< 是否为当前活跃版本
|
||
};
|
||
|
||
/**
|
||
* @brief 任务模板管理器
|
||
*
|
||
* 负责任务模板的增删改查、版本管理、排序展示。
|
||
* 支持增量更新和按名称/使用频率排序。
|
||
*/
|
||
class TaskTemplateManager {
|
||
public:
|
||
/// @brief 默认构造函数
|
||
TaskTemplateManager();
|
||
|
||
/// @brief 虚析构函数
|
||
virtual ~TaskTemplateManager();
|
||
|
||
/// @brief 禁止拷贝
|
||
TaskTemplateManager(const TaskTemplateManager&) = delete;
|
||
TaskTemplateManager& operator=(const TaskTemplateManager&) = delete;
|
||
|
||
/// @brief 允许移动
|
||
TaskTemplateManager(TaskTemplateManager&&) noexcept;
|
||
TaskTemplateManager& operator=(TaskTemplateManager&&) noexcept;
|
||
|
||
/**
|
||
* @brief 添加或更新一个任务模板(增量更新)
|
||
*
|
||
* 如果 templateId 已存在则更新,否则新增。
|
||
*
|
||
* @param tmpl 模板对象
|
||
* @return true 操作成功
|
||
*/
|
||
bool upsertTemplate(const TaskTemplate& tmpl);
|
||
|
||
/**
|
||
* @brief 按模板 ID 删除模板
|
||
* @param templateId 模板唯一标识
|
||
* @return true 删除成功,false 未找到
|
||
*/
|
||
bool removeTemplate(const std::string& templateId);
|
||
|
||
/**
|
||
* @brief 根据模板 ID 查找模板
|
||
* @param templateId 模板唯一标识
|
||
* @return const TaskTemplate* 找到返回指针,否则返回 nullptr
|
||
*/
|
||
const TaskTemplate* findTemplate(const std::string& templateId) const;
|
||
|
||
/**
|
||
* @brief 获取所有模板列表
|
||
* @return const std::vector<TaskTemplate>&
|
||
*/
|
||
const std::vector<TaskTemplate>& getAllTemplates() const;
|
||
|
||
/**
|
||
* @brief 按名称排序获取模板列表
|
||
* @param ascending true: 升序, false: 降序
|
||
* @return std::vector<TaskTemplate> 排序后的副本
|
||
*/
|
||
std::vector<TaskTemplate> getTemplatesSortedByName(bool ascending = true) const;
|
||
|
||
/**
|
||
* @brief 按使用频率排序获取模板列表
|
||
* @param ascending true: 升序, false: 降序
|
||
* @return std::vector<TaskTemplate> 排序后的副本
|
||
*/
|
||
std::vector<TaskTemplate> getTemplatesSortedByUsage(bool ascending = false) const;
|
||
|
||
// ---- 知识库版本管理 ----
|
||
|
||
/**
|
||
* @brief 添加知识库版本
|
||
* @param version 版本对象
|
||
* @return true 添加成功
|
||
*/
|
||
bool addKbVersion(const KbVersion& version);
|
||
|
||
/**
|
||
* @brief 获取所有知识库版本列表
|
||
* @return const std::vector<KbVersion>&
|
||
*/
|
||
const std::vector<KbVersion>& getAllKbVersions() const;
|
||
|
||
/**
|
||
* @brief 设置指定版本为活跃版本
|
||
* @param versionId 版本标识
|
||
* @return true 设置成功,false 未找到该版本
|
||
*/
|
||
bool activateKbVersion(const std::string& versionId);
|
||
|
||
/**
|
||
* @brief 获取当前活跃的知识库版本
|
||
* @return const KbVersion* 找到返回指针,否则返回 nullptr
|
||
*/
|
||
const KbVersion* getActiveKbVersion() const;
|
||
|
||
/**
|
||
* @brief 获取模板总数
|
||
* @return size_t
|
||
*/
|
||
size_t totalTemplates() const;
|
||
|
||
private:
|
||
std::vector<TaskTemplate> m_templates; ///< 模板存储容器(模拟 t_task_template 表)
|
||
std::vector<KbVersion> m_kbVersions; ///< 知识库版本存储(模拟 t_kb_version 表)
|
||
|
||
/**
|
||
* @brief 获取当前毫秒时间戳
|
||
* @return int64_t
|
||
*/
|
||
static int64_t nowMs() noexcept;
|
||
};
|
||
|
||
#endif // ETMS_TASK_TEMPLATE_MANAGER_HPP
|