-
Notifications
You must be signed in to change notification settings - Fork 2
/
language.go
62 lines (53 loc) · 1.65 KB
/
language.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package models
import (
"database/sql/driver"
"encoding/json"
"strings"
"github.com/google/uuid"
"github.com/mss-boot-io/mss-boot/pkg/enum"
)
/*
* @Author: lwnmengjing<lwnmengjing@qq.com>
* @Date: 2023/12/12 11:38:05
* @Last Modified by: lwnmengjing<lwnmengjing@qq.com>
* @Last Modified time: 2023/12/12 11:38:05
*/
type LanguageDefine struct {
// ID 主键
ID string `json:"id"`
// Group 分组
Group string `json:"group" gorm:"column:group;comment:分组;type:varchar(20);not null" binding:"required"`
// Key 键
Key string `json:"key" gorm:"column:key;comment:键;type:varchar(20);not null" binding:"required"`
// Value 值
Value string `json:"value" gorm:"column:value;comment:值;type:varchar(100);not null" binding:"required"`
}
type Language struct {
ModelGormTenant
// Name 名称
Name string `json:"name" gorm:"column:name;comment:名称;type:varchar(255);not null" binding:"required"`
// Remark 备注
Remark string `json:"remark" gorm:"column:remark;comment:备注;type:varchar(255);not null"`
// Statue 状态
Status enum.Status `json:"status" gorm:"column:status;comment:状态;size:10"`
// Defines
Defines *LanguageDefines `json:"defines,omitempty" gorm:"column:defines;comment:定义;type:json"`
}
func (*Language) TableName() string {
return "mss_boot_languages"
}
type LanguageDefines []*LanguageDefine
func (l *LanguageDefines) Scan(val any) error {
return json.Unmarshal(val.([]uint8), l)
}
func (l *LanguageDefines) Value() (driver.Value, error) {
if l == nil {
return nil, nil
}
for i := range *l {
if (*l)[i].ID == "" {
(*l)[i].ID = strings.ReplaceAll(uuid.New().String(), "-", "")
}
}
return json.Marshal(*l)
}