import CheckCache from "../StreamCache/CheckCache"; import TimeCache from "../StreamCache/TimeCache"; import UGCPublish from "../index"; import {CryptUploadDispatcher} from "../CryptUploadTack/CryptUploadDispatcher"; /** * @breif 时间比较函数 * @return false 不存在大小不超过七天的 * @return true 存在大小超过七天的 * */ function timeContrast(nowTime: number, sqlMinTimeObject: number): boolean { let timeBool = false; /** * 转换为时间戳进行比较 * 过期的时间+7天 对比 现在的时间 若大于则超过 * */ timeBool = nowTime > (sqlMinTimeObject + 60 * 7 * 24);//7 * 24 * 60 * 60 * 60); /** * 判断一下大小是否超过七天 * */ if(timeBool){ //console.log("存在超过七天到"); return true }else{ //console.log("不存在超过七天的"); return false; } } /** * @brief 时间检测循环 * */ export class CacheTimeInspectCycle { private _checkCachedb; private cycle: any; constructor() { this._checkCachedb = CryptUploadDispatcher._cacheManager.getTimeCache(); } /** * 注意他是以协程的方式执行的 * @breif 获取不到时间以及数据库数据的情况下他什么都不会做 * */ public async timeCycle() { var today = new Date() let time_name = "delect_cache_time"; /** * 获取网络的上海时间 * */ let time_str: number = today.getTime()/(1000 * 60); // 获取分钟数 /** * @breif 若获取时间和删除函数执行成功则插入修改时间 否则什么都不做 * */ if (time_str != undefined && time_str != 0) { let min_time_checkpoint = await this._checkCachedb.querymin(); /** * @breif 保证只有我们在获取到值到情况下执行 * */ if (min_time_checkpoint != undefined) { let out_timed: number = parseInt(min_time_checkpoint["min(storage_time)"]); let out_time_bool: boolean = timeContrast(time_str.valueOf(), out_timed.valueOf()); if (out_time_bool) { /** * @breif 开始执行时间轴所有过期函数 * */ await this._checkCachedb.deletes(Number(time_str - (60 * 7 * 24))); //设置过期时间为20分钟 /** * @brief 执行结束插入一下修改时间 * */ let time_data = await this._checkCachedb.query(time_name); if (time_data){ await this._checkCachedb.update({ time_name: time_name, time_value: time_str }); }else{ await this._checkCachedb.insert({ time_name: time_name, time_value: time_str }); } } } } } /** * @breif 设置时间检测允许 * */ public async setTimeInspectRun() { this.timeCycle(); this.cycle = setInterval(this.timeCycle, 1000 * 60 * 60); //1分钟X 60分钟执行一次 } }