feat: 回滚
This commit is contained in:
parent
cb9c8d8ef3
commit
45154e01db
|
@ -260,24 +260,24 @@ func InitRestFunc(r *gin.Engine) {
|
|||
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("校验失败, %v", err)})
|
||||
return
|
||||
}
|
||||
versions := dao.FindResolveRecordByVersion(jsonObj.Version, true)
|
||||
if len(versions) == 0 {
|
||||
resolveVersion := dao.FindResolveVersionByVersion(jsonObj.Version)
|
||||
if resolveVersion == nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("版本号 %d 不存在, 回滚失败", jsonObj.Version)})
|
||||
return
|
||||
}
|
||||
//executeResult, err := dao.ModifyResolveVersion(jsonObj.Version)
|
||||
//if !executeResult {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("回滚失败, %v", err)})
|
||||
// return
|
||||
//}
|
||||
//cache.ReloadCache()
|
||||
//body := make(map[string]interface{})
|
||||
//body["currentVersion"] = jsonObj.Version
|
||||
//c.JSON(http.StatusOK, gin.H{
|
||||
// "code": 0,
|
||||
// "message": "回滚成功",
|
||||
// "data": body,
|
||||
//})
|
||||
err = dao.ModifyResolveVersion(jsonObj.Version)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("回滚失败, %v", err)})
|
||||
return
|
||||
}
|
||||
cache.ReloadCache()
|
||||
body := make(map[string]interface{})
|
||||
body["currentVersion"] = jsonObj.Version
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "回滚成功",
|
||||
"data": body,
|
||||
})
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
|
@ -38,6 +38,21 @@ func GetResolveVersion() int {
|
|||
return records[0].Version
|
||||
}
|
||||
|
||||
func FindResolveVersionByVersion(version int) *ResolveVersion {
|
||||
var record ResolveVersion
|
||||
session := Engine.Table("resolve_version")
|
||||
session.And("version = ?", version)
|
||||
result, err := session.Get(&record)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil
|
||||
}
|
||||
if result {
|
||||
return &record
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) {
|
||||
// 全表更新为未发布
|
||||
_, _ = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{})
|
||||
|
@ -52,6 +67,20 @@ func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func ModifyResolveVersion(version int) error {
|
||||
// 全表更新为未发布
|
||||
_, err := Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 更新具体的版本为已发布
|
||||
_, err = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 1}, ResolveVersion{Version: version})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindResolveVersionPage(pageNo int, pageSize int) []*ResolveVersion {
|
||||
// 每页显示5条记录
|
||||
if pageSize <= 5 {
|
||||
|
|
BIN
dns.sqlite3
BIN
dns.sqlite3
Binary file not shown.
Loading…
Reference in New Issue