mysql_hubimage_logs.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dao
  2. import (
  3. "strconv"
  4. "go-common/app/admin/ep/merlin/model"
  5. "go-common/library/ecode"
  6. pkgerr "github.com/pkg/errors"
  7. )
  8. // InsertHubImageLog Insert Hub Image Log.
  9. func (d *Dao) InsertHubImageLog(hubImageLog *model.HubImageLog) (err error) {
  10. return pkgerr.WithStack(d.db.Create(hubImageLog).Error)
  11. }
  12. // UpdateHubImageLog Update Hub Image Log.
  13. func (d *Dao) UpdateHubImageLog(hubImageLog *model.HubImageLog) (err error) {
  14. return pkgerr.WithStack(d.db.Model(&model.HubImageLog{}).Where("id=?", hubImageLog.ID).Updates(hubImageLog).Error)
  15. }
  16. // UpdateHubImageLogStatus Update Hub Image Log Status.
  17. func (d *Dao) UpdateHubImageLogStatus(logID int64, status int) (err error) {
  18. return pkgerr.WithStack(d.db.Model(&model.HubImageLog{}).Where("id=?", logID).Updates(map[string]interface{}{"status": status}).Error)
  19. }
  20. // FindHubImageLogByImageTag Find Hub Image Log By Image Tag.
  21. func (d *Dao) FindHubImageLogByImageTag(imageTag string) (hubImageLog *model.HubImageLog, err error) {
  22. hubImageLog = &model.HubImageLog{}
  23. if err = d.db.Where("imagetag = ?", imageTag).First(hubImageLog).Error; err == ecode.NothingFound {
  24. err = nil
  25. }
  26. return
  27. }
  28. // FindHubImageLogByMachineID Find Hub Image Log By MachineID .
  29. func (d *Dao) FindHubImageLogByMachineID(machineID int64) (hubImageLogs []*model.HubImageLog, err error) {
  30. if err = d.db.Where("machine_id = ? ", machineID).Order("id DESC").Find(&hubImageLogs).Error; err == ecode.NothingFound {
  31. err = nil
  32. }
  33. return
  34. }
  35. // FindHubMachine2ImageLog Find Hub Machine to Image Log .
  36. func (d *Dao) FindHubMachine2ImageLog(queryRequest *model.QueryMachine2ImageLogRequest) (total int64, hubImageLogs []*model.HubImageLog, err error) {
  37. cdb := d.db.Model(&model.HubImageLog{}).Where("machine_id=? and operate_type = ?", queryRequest.MachineID, strconv.Itoa(model.ImageMachine2Image)).Order("ID desc").Offset((queryRequest.PageNum - 1) * queryRequest.PageSize).Limit(queryRequest.PageSize)
  38. if err = pkgerr.WithStack(cdb.Find(&hubImageLogs).Error); err != nil {
  39. return
  40. }
  41. if err = pkgerr.WithStack(d.db.Model(&model.HubImageLog{}).Where("machine_id=? and operate_type = ?", queryRequest.MachineID, strconv.Itoa(model.ImageMachine2Image)).Count(&total).Error); err != nil {
  42. return
  43. }
  44. return
  45. }
  46. // UpdateHubImageLogStatusInDoingStatus Update Hub Image Log Status in doing status.
  47. func (d *Dao) UpdateHubImageLogStatusInDoingStatus(machineID int64, status int) (err error) {
  48. return pkgerr.WithStack(d.db.Model(&model.HubImageLog{}).Where("machine_id=? and status=? and operate_type = ?", machineID, model.ImageInit, model.ImageMachine2Image).Updates(map[string]interface{}{"status": status}).Error)
  49. }