#pragma once //stl #include #include #include //local #include "../xml/xml_context.hpp" /** * @brief 用于定义一个以 _Table 为模板参数的空结构体。 * @tparam _Table 要用于结构体的类型。 */ template struct _update_ {}; /** * @brief 更新指定的 web_after_config_info 实例:先根据 id 删除已有项,再追加新的值并提交更改。 */ template<> struct _update_ { /** * @brief 更新或添加 web_after_config_info 配置信息到 XML 上下文中。 * @param value 要更新或添加的 web_after_config_info 对象。 */ static void invoke(web_after_config_info const&value) { xml_context::from(). remove([value](auto it) {return it->id == value.id; }). submit(); xml_context::from(). append(value). submit(); } }; /** * @brief 更新或添加 web_general_config_info 配置信息到 XML 上下文中。 */ template<> struct _update_ { /** * @brief 检查是否存在指定的 key,如果不存在则添加新的配置项,否则更新现有配置项。 * @param value 要更新或添加的 web_general_config_info 对象。 */ static void invoke(web_general_config_info const& value) { if (xml_context::from().where([value](auto it) {return it->key == value.key; }).empty()) { web_general_config_info info{ .id = 0, .modify_time = v3::datetime::current_time_stamp(), .key = value.key, .value = value.value, .enable = value.enable, .remarks = value.remarks }; xml_context::from(). max(info.id, [](auto it) {return it->id; }). inc(info.id). append(info). submit(); } else { xml_context::from(). where([value](auto it) { return it->key == value.key; }). update([value](auto it) { it->modify_time = v3::datetime::current_time_stamp(); it->key = value.key; it->value = value.value; it->enable = value.enable; it->remarks = value.remarks; return true; }). submit(); } } }; /** * @brief 用于更新指定表或表项的数据。 */ class xml_config { public: /** * @brief 更新指定表的数据。 * @tparam _Table 要更新的数据表类型。 * @param value 要更新的数据表对象的常量引用。 */ template static void update(_Table const& value) { _update_<_Table>::invoke(value); } /** * @brief 使用给定的值集合更新表项。 * @tparam _Table 表示表项类型的模板参数。 * @param values 包含要更新的表项的常量引用向量。 */ template static void update(std::vector<_Table> const& values) { for (auto const& value : values) { _update_<_Table>::invoke(value); } } };