zhangqian
2023-12-08 a9fdd955d57f6940d170a2f4c36a9bb8f0fcf871
json输出字符串
3个文件已修改
47 ■■■■■ 已修改文件
crontask/cron_task.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/model.go 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
crontask/cron_task.go
@@ -81,9 +81,9 @@
    if isMaster {
        s.Every(20).Seconds().Do(SyncProductionProgress) //同步生产数据
        //s.Every(30).Seconds().Do(SyncTaskStatus)         //同步任务状态
        s.Every(10).Seconds().Do(CheckNsqConn) //查询nsq连接
        s.Every(30).Seconds().Do(ReportData)   //上报数据
        s.Every(30).Seconds().Do(SyncTaskStatus)         //同步任务状态
        s.Every(10).Seconds().Do(CheckNsqConn)           //查询nsq连接
        s.Every(30).Seconds().Do(ReportData)             //上报数据
    }
    s.Every(20).Seconds().Do(QueryClusterStatus) //查询集群节点数量
main.go
@@ -38,7 +38,6 @@
    var syncTables = []string{
        "procedures",
        "process_model",
        "production_progress",
        "work_order",
        "task_status_sync",
        "device",
model/model.go
@@ -1,50 +1,12 @@
package model
import (
    "apsClient/pkg/snowflake"
    "encoding/json"
    "github.com/jinzhu/gorm"
    "strconv"
    "time"
)
type BigID uint
type CommonModel struct {
    ID        uint  `gorm:"primary_key" json:"-"`
    Id        BigID `json:"ID"`
    ID        uint `gorm:"primary_key" json:"ID,string"`
    CreatedAt time.Time
    UpdatedAt time.Time
    DeletedAt *time.Time `sql:"index"`
}
func (c *CommonModel) BeforeCreate(db *gorm.DB) {
    if c.ID == 0 {
        id := snowflake.GenerateID()
        if id < 0 {
            // 处理 ID 为负数的情况(可选)
            id = snowflake.GenerateID()
        }
        c.ID = uint(id)
    }
}
func (id *BigID) UnmarshalJSON(b []byte) error {
    var idString string
    if err := json.Unmarshal(b, &idString); err != nil {
        return err
    }
    idValue, err := strconv.ParseUint(idString, 10, 64)
    if err != nil {
        return err
    }
    *id = BigID(idValue)
    return nil
}
func (id *BigID) MarshalJSON() ([]byte, error) {
    idString := strconv.FormatUint(uint64(*id), 10)
    return []byte(idString), nil
}