1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package model
- import (
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- const DefaultUserId = 0
- type DataWarning struct {
- Id int64 `json:"id"`
- UserId int64 `json:"userId"`
- Kind string `json:"kind"`
- Name string `json:"name"`
- Description string `json:"description"`
- DataValue string `json:"dataValue"`
- DataUpdateAt int64 `json:"dataUpdateAt"`
- ConditionUpdateAt int64 `json:"conditionUpdateAt"`
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (d *DataWarning) TableName() string {
- return "data_warning"
- }
- func NewDataWarningList(userId int64, req []*pasturePb.WarningDataSet, warningMap map[string]*DataWarning) []*DataWarning {
- res := make([]*DataWarning, 0)
- isAdd := make(map[string]bool)
- for _, v := range req {
- if _, ok := isAdd[v.Kind]; ok {
- continue
- }
- isAdd[v.Kind] = true
- defaultDataWarning := warningMap[v.Kind]
- res = append(res, NewDataWarning(userId, v.Kind, v.IsShow, defaultDataWarning))
- }
- return res
- }
- func NewDataWarning(userId int64, Kind string, isShow pasturePb.IsShow_Kind, defaultDataWarning *DataWarning) *DataWarning {
- return &DataWarning{
- UserId: userId,
- Kind: Kind,
- Name: defaultDataWarning.Name,
- Description: defaultDataWarning.Description,
- IsShow: isShow,
- }
- }
- type DataWarningSlice []*DataWarning
- func (d DataWarningSlice) ToPB() []*pasturePb.WarningDataShow {
- res := make([]*pasturePb.WarningDataShow, 0)
- for _, warningData := range d {
- if warningData.IsShow != pasturePb.IsShow_Ok {
- continue
- }
- dataUpdateTimeFormat := ""
- if warningData.DataUpdateAt > 0 {
- dataUpdateTimeFormat = time.Unix(warningData.DataUpdateAt, 0).Format(LayoutTime)
- }
- res = append(res, &pasturePb.WarningDataShow{
- Name: warningData.Name,
- Number: warningData.DataValue,
- Describe: warningData.Description,
- DataUpdateTimeFormat: dataUpdateTimeFormat,
- Kind: warningData.Kind,
- })
- }
- return res
- }
|