fix: 添加调试日志排查版本更新不生效问题

This commit is contained in:
2026-05-08 21:34:22 +08:00
parent 3b4b0ac1e3
commit 426290e299
2 changed files with 27 additions and 28 deletions
+20 -24
View File
@@ -323,10 +323,13 @@ func handleUpdateVersionGlobal(c *gin.Context) {
var req UpdateVersionRequest
if err := c.ShouldBindJSON(&req); err != nil {
log.Printf("[ERROR] ShouldBindJSON failed: %v\n", err)
response.Error(c, 400, "参数错误")
return
}
log.Printf("[DEBUG] UpdateVersionRequest parsed: %+v\n", req)
var userApps []model.Application
if err := database.DB.Where("user_id = ?", userID).Find(&userApps).Error; err != nil {
response.Error(c, 500, "获取应用列表失败")
@@ -350,30 +353,10 @@ func handleUpdateVersionGlobal(c *gin.Context) {
response.Error(c, 400, "该版本号已存在")
return
}
version.Version = req.Version
}
if req.Version != "" {
version.Version = req.Version
}
if req.UpdateStrategy != "" {
version.UpdateStrategy = req.UpdateStrategy
}
if req.UpdateMethod != "" {
version.UpdateMethod = req.UpdateMethod
}
if req.MinVersion != "" {
version.MinVersion = req.MinVersion
}
if req.Description != "" {
version.Description = req.Description
}
if req.Changelog != "" {
version.Changelog = req.Changelog
}
if req.Status != "" {
version.Status = req.Status
}
log.Printf("[DEBUG] handleUpdateVersionGlobal versionID=%s, req: version=%s, update_strategy=%s, update_method=%s, description=%s\n",
versionID, req.Version, req.UpdateStrategy, req.UpdateMethod, req.Description)
updates := map[string]interface{}{}
if req.Version != "" {
@@ -398,11 +381,24 @@ func handleUpdateVersionGlobal(c *gin.Context) {
updates["status"] = req.Status
}
if len(updates) > 0 {
if err := database.DB.Model(&version).Updates(updates).Error; err != nil {
log.Printf("[DEBUG] Updates map: %+v\n", updates)
if len(updates) == 0 {
response.Success(c, nil)
return
}
result := database.DB.Model(&model.Version{}).Where("id = ?", versionID).Updates(updates)
if result.Error != nil {
log.Printf("[ERROR] Updates failed: %v\n", result.Error)
response.Error(c, 500, "更新版本失败")
return
}
log.Printf("[DEBUG] Updates rows affected: %d\n", result.RowsAffected)
if result.RowsAffected == 0 {
response.Error(c, 500, "更新未生效,请重试")
return
}
userIDPtr := &userID
+4 -1
View File
@@ -180,13 +180,16 @@ async function handleSubmit() {
entry_file: formData.value.entry_file,
}
console.log('[DEBUG] handleSubmit payload:', JSON.stringify(payload))
if (uploadedData.value) {
payload.file_path = uploadedData.value.file_path
payload.file_size = uploadedData.value.file_size
payload.file_hash = uploadedData.value.file_hash
}
await api.put(`/dev/versions/${versionId.value}`, payload)
const response = await api.put(`/dev/versions/${versionId.value}`, payload)
console.log('[DEBUG] handleSubmit response:', response)
toast.success(t('admin.versions.createForm.updateSuccess'))
router.push('/admin/versions')
}