2021-06-27 21:00:24 +08:00
import { MysqlUtil } from '../util/MysqlHelper' ;
import Plan from '../entity/Plan' ;
import { OkPacket } from 'mysql2' ;
export default class PlanDao {
/ * *
* 新 增 一 个 备 份 计 划
* @param plan plan
* /
static async addOne ( plan : Plan ) : Promise < number > {
let res = await MysqlUtil . pool . execute ( "insert into plan(createdDate,updatedDate,planName,description,sourcePath,targetPath,nextLaunchTime,launchInterval,latestHistoryId,ignoreList,holdHistory) values(?,?,?,?,?,?,?,?,?,?,?)"
, [ Date . now ( ) , Date . now ( ) , plan . planName , plan . description , plan . sourcePath , plan . targetPath , plan . nextLaunchTime , plan . lanuchInterval , plan . latestHistoryId , JSON . stringify ( plan . ignoreList ) , plan . holdHistory ] ) ;
return ( res [ 0 ] as unknown as OkPacket ) . insertId ;
}
/ * *
* 获 取 所 有 待 执 行 的 plan
* /
static async getNeedActionPlan ( ) : Promise < Array < Plan > > {
let sql = ` select * from plan where nextLaunchTime < ${ Date . now ( ) } order by nextLaunchTime ` ;
return ( await MysqlUtil . pool . query ( sql ) ) [ 0 ] as unknown as Array < Plan > ;
}
/ * *
* 更 新 某 个 计 划 的 下 次 执 行 时 间
* @param id planId
* /
static async updateNextlaunchTimeAndLatestHistoryId ( planId : number , historyId : number ) {
await MysqlUtil . pool . execute ( ` update plan set nextLaunchTime = nextLaunchTime+launchInterval,latestHistoryId=? where planId=? `
, [ historyId , planId ] ) ;
}
static async deleteByPlanId ( planId : number ) {
await MysqlUtil . pool . execute ( ` delete from plan where planid=? ` , [ planId ] ) ;
}
static async getAll ( ) : Promise < Array < Plan > > {
return ( await MysqlUtil . pool . query ( "select * from plan" ) ) [ 0 ] as unknown as Array < Plan > ;
}
2021-06-21 16:32:10 +08:00
}