package model import ( "kpt-tmr-group/pkg/tool" operationPb "kpt-tmr-group/proto/go/backend/operation" "time" ) type GroupPasture struct { Id int64 `json:"id,omitempty"` Name string `json:"name,omitempty"` Account string `json:"account,omitempty"` Password string `json:"password"` ManagerUser string `json:"manager_user"` ManagerPhone string `json:"manager_phone"` IsShow operationPb.IsShow_Kind `json:"is_show,omitempty"` IsDelete operationPb.IsShow_Kind `json:"is_delete,omitempty"` Address string `json:"address"` CreatedAt int64 `json:"created_at,omitempty"` UpdatedAt int64 `json:"updated_at,omitempty"` } func (s *GroupPasture) TableName() string { return "group_pasture" } const InitManagerPassword = "123456" func NewGroupPasture(req *operationPb.AddPastureRequest) *GroupPasture { groupPasture := &GroupPasture{ Name: req.Name, Account: req.Account, Password: tool.Md5String(InitManagerPassword), ManagerUser: req.ManagerUser, ManagerPhone: req.ManagerPhone, IsShow: operationPb.IsShow_OK, IsDelete: operationPb.IsShow_OK, Address: req.Address, } return groupPasture } type GroupPastureSlice []*GroupPasture func (g GroupPastureSlice) ToPB() []*operationPb.AddPastureRequest { res := make([]*operationPb.AddPastureRequest, len(g)) for i, v := range g { res[i] = &operationPb.AddPastureRequest{ Id: int32(v.Id), Name: v.Name, Account: v.Account, ManagerUser: v.ManagerUser, ManagerPhone: v.ManagerPhone, Address: v.Address, IsShow: v.IsShow, CreatedAt: int32(v.CreatedAt), CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime), } } return res } func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest { return &operationPb.AddPastureRequest{ Id: int32(g.Id), Name: g.Name, ManagerUser: g.ManagerUser, ManagerPhone: g.ManagerPhone, Address: g.Address, IsShow: g.IsShow, CreatedAt: int32(g.CreatedAt), } }