59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
|
|
/**
|
|||
|
|
* 过期数据删除引擎
|
|||
|
|
**/
|
|||
|
|
|
|||
|
|
#ifndef DELETEEXPIREDFOLDERENGINE_H
|
|||
|
|
#define DELETEEXPIREDFOLDERENGINE_H
|
|||
|
|
|
|||
|
|
#include "AppCommon.h"
|
|||
|
|
#include "EngineBase.h"
|
|||
|
|
#include "EngineFactory.h"
|
|||
|
|
#include "MyYaml.h"
|
|||
|
|
#include "myutils.h"
|
|||
|
|
|
|||
|
|
// 定义日期结构体
|
|||
|
|
struct Date
|
|||
|
|
{
|
|||
|
|
int year;
|
|||
|
|
int month;
|
|||
|
|
int day;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
class DeleteExpiredFolderEngine : public ai_matrix::EngineBase
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
DeleteExpiredFolderEngine();
|
|||
|
|
~DeleteExpiredFolderEngine();
|
|||
|
|
|
|||
|
|
APP_ERROR Init() override;
|
|||
|
|
APP_ERROR DeInit() override;
|
|||
|
|
APP_ERROR Process() override;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
// 获取某月有多少天
|
|||
|
|
int DaysInMonth(int year, int month);
|
|||
|
|
// 解析字符串为日期结构体
|
|||
|
|
Date StrToDate(const std::string &date_str);
|
|||
|
|
// 减去指定天数
|
|||
|
|
void SubtractDays(Date &date, int n_days);
|
|||
|
|
// 格式化日期结构体为字符串
|
|||
|
|
std::string DateToStr(const Date &date);
|
|||
|
|
// 接收一个日期字符串和一个整数n,返回n天前的日期字符串
|
|||
|
|
std::string getDateBeforeNDays(const std::string &input_date, int n_days);
|
|||
|
|
void GetSubfolderNames(std::string &directory, std::vector<Date> &folder_names);
|
|||
|
|
void DeleteFolder(const std::string directory);
|
|||
|
|
// 删除向量中小于指定日期的所有元素
|
|||
|
|
void DeleteEarlierDatesFolder(std::string &path, std::vector<Date> &subfolders, const Date &reference_date);
|
|||
|
|
void DeletePreviousFolder(std::string path, const std::string &date, int n_days);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
std::string strResultPath_;
|
|||
|
|
std::string strLogBakPath_;
|
|||
|
|
|
|||
|
|
int iDaysNumber_;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
ENGINE_REGIST(DeleteExpiredFolderEngine)
|
|||
|
|
|
|||
|
|
#endif
|