1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package dao
- import (
- "go-common/app/admin/ep/merlin/model"
- pkgerr "github.com/pkg/errors"
- )
- func (d *Dao) FindDeleteMachineTasks() (tasks []*model.Task, err error) {
- tasks = []*model.Task{}
- err = pkgerr.WithStack(d.db.Where("status=? AND type=? AND DATEDIFF(NOW(),execute_time)=0 AND execute_time < NOW()", model.TaskInit, model.DeleteMachine).Find(&tasks).Error)
- return
- }
- func (d *Dao) UpdateTaskStatusByMachines(machineIDs []int64, status int) (err error) {
- return pkgerr.WithStack(d.db.Model(&model.Task{}).Where("machine_id IN (?)", machineIDs).Update("status", status).Error)
- }
- func (d *Dao) UpdateTaskStatusByTaskID(taskID int64, status int) (err error) {
- return pkgerr.WithStack(d.db.Model(&model.Task{}).Where("id IN (?)", taskID).Update("status", status).Error)
- }
- func (d *Dao) InsertDeleteMachinesTasks(ms []*model.Machine) (err error) {
- for _, machine := range ms {
- mrTask := &model.Task{
- TYPE: model.DeleteMachine,
- ExecuteTime: machine.EndTime,
- MachineID: machine.ID,
- Status: model.TaskInit,
- }
- if tempErr := d.db.Create(mrTask).Error; tempErr != nil {
- err = pkgerr.WithStack(tempErr)
- }
- }
- return
- }
|