This commit is contained in:
parent
7f89b8c0b3
commit
540d7de478
|
|
@ -1,6 +1,7 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"intent-system/pkg/config"
|
||||
"intent-system/pkg/dal/dao"
|
||||
|
|
@ -145,7 +146,16 @@ func (m *BizCore) NewsEdit(ctx *itypes.Context, req *proto.NewsEditReq) (resp *p
|
|||
if err != nil {
|
||||
return nil, itypes.NewBizCodeDatabaseError(err.Error())
|
||||
}
|
||||
news.ExtraData.Logs = models.MakeChangeLog(news.ExtraData.Logs, ctx.UserName(), models.OperType_Edit)
|
||||
// news.ExtraData.Logs = models.MakeChangeLog(news.ExtraData.Logs, ctx.UserName(), models.OperType_Edit)
|
||||
var prevLogs []*models.ChangeLog
|
||||
if raw, ok := news.ExtraData["logs"]; ok {
|
||||
if arr, ok := raw.([]interface{}); ok {
|
||||
// 先 marshal 回去再 unmarshal 成 []*ChangeLog(通用做法)
|
||||
bytes, _ := json.Marshal(arr)
|
||||
_ = json.Unmarshal(bytes, &prevLogs)
|
||||
}
|
||||
}
|
||||
news.ExtraData["logs"] = models.MakeChangeLog(prevLogs, ctx.UserName(), models.OperType_Edit)
|
||||
_, err = m.newsDAO.Update(&models.NewsDO{
|
||||
Id: news.Id,
|
||||
ExtraData: news.ExtraData,
|
||||
|
|
@ -171,7 +181,16 @@ func (m *BizCore) NewsDelete(ctx *itypes.Context, req *proto.NewsDeleteReq) (res
|
|||
return nil, itypes.NewBizCode(itypes.CODE_INVALID_PARAMS, err.Error())
|
||||
}
|
||||
|
||||
news.ExtraData.Logs = models.MakeChangeLog(news.ExtraData.Logs, ctx.UserName(), models.OperType_Delete)
|
||||
// news.ExtraData.Logs = models.MakeChangeLog(news.ExtraData.Logs, ctx.UserName(), models.OperType_Delete)
|
||||
var prevLogs []*models.ChangeLog
|
||||
if raw, ok := news.ExtraData["logs"]; ok {
|
||||
if arr, ok := raw.([]interface{}); ok {
|
||||
// 尝试转成 []*ChangeLog
|
||||
bytes, _ := json.Marshal(arr)
|
||||
_ = json.Unmarshal(bytes, &prevLogs)
|
||||
}
|
||||
}
|
||||
news.ExtraData["logs"] = models.MakeChangeLog(prevLogs, ctx.UserName(), models.OperType_Delete)
|
||||
|
||||
_, err = m.newsDAO.Update(&models.NewsDO{
|
||||
Id: id,
|
||||
|
|
@ -282,7 +301,8 @@ func (m *BizCore) NewsDraftPublish(ctx *itypes.Context, req *proto.NewsDraftPubl
|
|||
ImageUrl: draft.ImageUrl,
|
||||
Content: draft.Content,
|
||||
Language: draft.Language,
|
||||
ExtraData: models.CommonExtraData{},
|
||||
// ExtraData: models.CommonExtraData{},
|
||||
ExtraData: map[string]interface{}{}, // ✅ 替代旧结构体
|
||||
})
|
||||
if err != nil {
|
||||
return nil, itypes.NewBizCodeDatabaseError(err.Error())
|
||||
|
|
@ -751,7 +771,19 @@ func (m *BizCore) SubEditNews(ctx *itypes.Context, req *proto.SubEditNewsReq) (r
|
|||
news.Tags = req.Tags
|
||||
news.ImageUrl = req.ImageUrl
|
||||
news.Content = req.Content
|
||||
news.ExtraData.Logs = models.MakeChangeLog(news.ExtraData.Logs, ctx.UserName(), models.OperType_Edit)
|
||||
// news.ExtraData.Logs = models.MakeChangeLog(news.ExtraData.Logs, ctx.UserName(), models.OperType_Edit)
|
||||
|
||||
var prevLogs []*models.ChangeLog
|
||||
if raw, ok := news.ExtraData["logs"]; ok {
|
||||
if arr, ok := raw.([]interface{}); ok {
|
||||
// 安全解析为 []*ChangeLog
|
||||
if bytes, err := json.Marshal(arr); err == nil {
|
||||
_ = json.Unmarshal(bytes, &prevLogs)
|
||||
}
|
||||
}
|
||||
}
|
||||
news.ExtraData["logs"] = models.MakeChangeLog(prevLogs, ctx.UserName(), models.OperType_Edit)
|
||||
|
||||
_, err = m.newsDAO.Update(news,
|
||||
models.NEWS_COLUMN_CATEGORY,
|
||||
models.NEWS_COLUMN_MAIN_TITLE,
|
||||
|
|
|
|||
Loading…
Reference in New Issue