package model import ( "kpt-tmr-group/pkg/tool" operationPb "kpt-tmr-group/proto/go/backend/operation" ) type GroupPasture struct { Id int64 `json:"id,omitempty"` Name string `json:"name,omitempty"` ManagerUser string `json:"manager_user"` ManagerPassword string `json:"manager_password"` ManagerPhone string `json:"manager_phone"` IsShow operationPb.IsShow_Kind `json:"is_show,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 NewGroupPastureList(reqs []*operationPb.AddPastureRequest) []*GroupPasture { groupPastureList := make([]*GroupPasture, len(reqs)) for k, pasture := range reqs { groupPastureList[k] = &GroupPasture{ Name: pasture.Name, ManagerUser: pasture.ManagerUser, ManagerPassword: tool.Md5String(InitManagerPassword), ManagerPhone: pasture.ManagerPhone, IsShow: operationPb.IsShow_OK, Address: pasture.Address, } } return groupPastureList } 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: v.Id, Name: v.Name, ManagerUser: v.ManagerUser, ManagerPhone: v.ManagerPhone, Address: v.Address, IsShow: v.IsShow, CreatedAt: v.CreatedAt, } } return res } func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest { return &operationPb.AddPastureRequest{ Id: g.Id, Name: g.Name, ManagerUser: g.ManagerUser, ManagerPhone: g.ManagerPhone, Address: g.Address, IsShow: g.IsShow, CreatedAt: g.CreatedAt, } } type GroupPastureResponse struct { Page int32 `json:"page"` Total int32 `json:"total"` List []*operationPb.AddPastureRequest `json:"list"` } func (g *GroupPastureResponse) ToPB() *operationPb.SearchPastureResponse { return &operationPb.SearchPastureResponse{ Page: g.Page, Total: g.Total, List: g.List, } }