feat: 回滚

This commit is contained in:
骑着蜗牛追导弹 2024-11-11 21:15:21 +08:00
parent cb9c8d8ef3
commit 45154e01db
3 changed files with 44 additions and 15 deletions

View File

@ -260,24 +260,24 @@ func InitRestFunc(r *gin.Engine) {
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("校验失败, %v", err)}) c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("校验失败, %v", err)})
return return
} }
versions := dao.FindResolveRecordByVersion(jsonObj.Version, true) resolveVersion := dao.FindResolveVersionByVersion(jsonObj.Version)
if len(versions) == 0 { if resolveVersion == nil {
c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("版本号 %d 不存在, 回滚失败", jsonObj.Version)}) c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("版本号 %d 不存在, 回滚失败", jsonObj.Version)})
return return
} }
//executeResult, err := dao.ModifyResolveVersion(jsonObj.Version) err = dao.ModifyResolveVersion(jsonObj.Version)
//if !executeResult { if err != nil {
// c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("回滚失败, %v", err)}) c.JSON(http.StatusBadRequest, gin.H{"message": fmt.Sprintf("回滚失败, %v", err)})
// return return
//} }
//cache.ReloadCache() cache.ReloadCache()
//body := make(map[string]interface{}) body := make(map[string]interface{})
//body["currentVersion"] = jsonObj.Version body["currentVersion"] = jsonObj.Version
//c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
// "code": 0, "code": 0,
// "message": "回滚成功", "message": "回滚成功",
// "data": body, "data": body,
//}) })
return return
}) })
} }

View File

@ -38,6 +38,21 @@ func GetResolveVersion() int {
return records[0].Version 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) { func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) {
// 全表更新为未发布 // 全表更新为未发布
_, _ = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{}) _, _ = Engine.Table("resolve_version").Update(ResolveVersion{IsRelease: 2}, ResolveVersion{})
@ -52,6 +67,20 @@ func SaveResolveVersion(wrapper *ResolveVersion) (bool, error) {
return true, nil 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 { func FindResolveVersionPage(pageNo int, pageSize int) []*ResolveVersion {
// 每页显示5条记录 // 每页显示5条记录
if pageSize <= 5 { if pageSize <= 5 {

Binary file not shown.