fix: cbc时间字段统一毫秒处理

This commit is contained in:
TsMask
2025-08-01 16:29:28 +08:00
parent e4f52c949e
commit de0b81ee01
8 changed files with 35 additions and 59 deletions

View File

@@ -93,8 +93,9 @@ func (m *CBCController) Insert(c *gin.Context) {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
msg.CreatedAt = time.Now().Local().UnixMicro()
msg.UpdatedAt = nil // 新增时更新时间为nil
now := time.Now().UnixMilli()
msg.CreatedAt = now
msg.UpdatedAt = now
// 使用 ShouldBindBodyWithJSON 读取请求体
var jsonData interface{}

View File

@@ -71,14 +71,14 @@ type CBCMessageQuery struct {
// @Description CBCMessage CB消息
type CBCMessage struct {
Id int64 `json:"id" gorm:"column:id"` // CB消息ID
NeType string `json:"neType" gorm:"column:ne_type"` // 网元类型
NeId string `json:"neId" gorm:"column:ne_id"` // 网元ID
MessageJson json.RawMessage `json:"messageJson" gorm:"column:message_json"` // 消息内容JSON
Status CBCEventStatus `json:"status" gorm:"column:status"` // 消息状态
Detail string `json:"detail" gorm:"column:detail"` // 详情
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"` // 创建时间
UpdatedAt *int64 `json:"updatedAt" gorm:"column:updated_at;autoUpdateTime:false"` // 更新时间
Id int64 `json:"id" gorm:"column:id"` // CB消息ID
NeType string `json:"neType" gorm:"column:ne_type"` // 网元类型
NeId string `json:"neId" gorm:"column:ne_id"` // 网元ID
MessageJson json.RawMessage `json:"messageJson" gorm:"column:message_json"` // 消息内容JSON
Status CBCEventStatus `json:"status" gorm:"column:status"` // 消息状态
Detail string `json:"detail" gorm:"column:detail"` // 详情
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"` // 创建时间
UpdatedAt int64 `json:"updatedAt" gorm:"column:updated_at"` // 更新时间
}
// TableName 表名称

View File

@@ -109,6 +109,7 @@ func (s *CBCMessage) SelectByPage(query model.CBCMessageQuery) ([]model.CBCMessa
// @example
// CBCMessage.InsertCBCMessage(msg)
func (s *CBCMessage) Insert(msg model.CBCMessage) error {
msg.CreatedAt = time.Now().UnixMilli()
// 这里可以使用ORM或其他方式将ticket插入到数据库中
if err := db.DB("").Table("cbc_message").Create(&msg).Error; err != nil {
return fmt.Errorf("failed to insert CBC message: %w", err)
@@ -157,10 +158,10 @@ func (s *CBCMessage) SelectByEventName(eventName string) (*model.CBCMessage, err
// @example
// mfCBCMessageService.UpdateCBCMessage(msg)
func (s *CBCMessage) Update(id int64, messageJson json.RawMessage) error {
now := time.Now().UnixMicro()
now := time.Now().UnixMilli()
if err := db.DB("").Table("cbc_message").
Where("id = ?", id).
Updates(map[string]interface{}{
Updates(map[string]any{
"message_json": messageJson,
"updated_at": now,
}).Error; err != nil {
@@ -177,7 +178,7 @@ func (s *CBCMessage) Update(id int64, messageJson json.RawMessage) error {
// @example
// UpdateCBCMessageDetail(msg)
func (s *CBCMessage) UpdateDetail(eventName, detail string) error {
now := time.Now().UnixMicro()
now := time.Now().UnixMilli()
if err := db.DB("").Table("cbc_message").
Where("JSON_EXTRACT(message_json, '$.eventName') = ?", eventName).
Updates(map[string]any{
@@ -212,7 +213,7 @@ func (s *CBCMessage) Delete(id int64) error {
// @return error 错误信息
func (s *CBCMessage) UpdateStatus(id int64, status model.CBCEventStatus) error {
// 更新数据库状态
now := time.Now().UnixMicro()
now := time.Now().UnixMilli()
if err := db.DB("").Table("cbc_message").
Where("id = ?", id).
Updates(map[string]interface{}{
@@ -250,5 +251,5 @@ func parseTimeToMicro(ts string) (int64, error) {
if err != nil {
return 0, err
}
return t.UnixMicro(), nil
return t.UnixMilli(), nil
}

View File

@@ -291,8 +291,8 @@ func (r CBCMessage) ExportXlsx(rows []model.CBCMessage, fileName, language strin
"C" + idx: row.MessageJson, // 这里假设 MessageJson 已经是字符串格式
"D" + idx: row.Status.Enum(),
"E" + idx: row.Detail,
"F" + idx: time.Unix(row.CreatedAt, 0).Format(time.RFC3339),
"G" + idx: time.Unix(*row.UpdatedAt, 0).Format(time.RFC3339),
"F" + idx: time.UnixMilli(row.CreatedAt).Format(time.RFC3339),
"G" + idx: time.UnixMilli(row.UpdatedAt).Format(time.RFC3339),
}
dataCells = append(dataCells, cells)