[REV] optimize event update method

This commit is contained in:
bay1ts 2017-11-22 19:16:20 +08:00
parent 9844ae172a
commit 6d5532adb6

View File

@ -26,6 +26,8 @@ import (
"fmt"
"time"
"github.com/Sirupsen/logrus"
"encoding/json"
)
@ -53,6 +55,8 @@ func (c *EventDaoImpl) UpdateModel(mo model.Interface) error {
var oldResult model.ServiceEvent
if ok := c.DB.Where("event_id=?", result.EventID).Find(&oldResult).RecordNotFound(); !ok {
finalUpdateEvent(result,&oldResult)
oldB,_:=json.Marshal(oldResult)
logrus.Infof("update event to %s",string(oldB))
if err := c.DB.Save(oldResult).Error; err != nil {
return err
}
@ -62,22 +66,21 @@ func (c *EventDaoImpl) UpdateModel(mo model.Interface) error {
func finalUpdateEvent(target *model.ServiceEvent, old *model.ServiceEvent) {
if target.CodeVersion!="" {
old.CodeVersion=target.CodeVersion
}else{
if target.Status!="" {
old.Status=target.Status
}
if target.Message!="" {
old.Message=target.Message
}
old.FinalStatus = "complete"
if target.FinalStatus!="" {
old.FinalStatus=target.FinalStatus
}
}
if target.Status!="" {
old.Status=target.Status
}
if target.Message!="" {
old.Message=target.Message
}
old.FinalStatus = "complete"
if target.FinalStatus!="" {
old.FinalStatus=target.FinalStatus
}
old.EndTime = time.Now().String()
if old.Status == "failure" && old.OptType == "callback"{
old.DeployVersion = old.OldDeployVersion
}
old.EndTime = time.Now().String()
if old.Status == "failure" && old.OptType == "callback"{
old.DeployVersion = old.OldDeployVersion
}
}
//EventLogMessageDaoImpl EventLogMessageDaoImpl