package model import ( operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation" "time" ) type SystemRole struct { Id int64 `json:"id,omitempty"` Name string `json:"name,omitempty"` Remarks string `json:"remarks,omitempty"` IsShow operationPb.IsShow_Kind `json:"is_show,omitempty"` CreateUser string `json:"create_user,omitempty"` CreatedAt int64 `json:"created_at,omitempty"` UpdatedAt int64 `json:"updated_at,omitempty"` } func (s *SystemRole) TableName() string { return "system_role" } const ( LayoutTime = "2006-01-02 15:04:05" LayoutDate = "20060102" ) func NewSystemRole(req *operationPb.AddRoleRequest) *SystemRole { systemRole := &SystemRole{ Name: req.Name, Remarks: req.Remarks, IsShow: operationPb.IsShow_OK, CreateUser: req.CreateUser, } return systemRole } type SystemRoleSlice []*SystemRole func (s SystemRoleSlice) ToPB(groupPastureList map[int64][]*GroupPasture, systemMenuList map[int64][]*SystemMenu) []*operationPb.AddRoleRequest { res := make([]*operationPb.AddRoleRequest, len(s)) for i, v := range s { res[i] = &operationPb.AddRoleRequest{ Id: uint32(v.Id), Name: v.Name, Remarks: v.Remarks, CreateUser: v.CreateUser, IsShow: v.IsShow, CreatedAt: uint32(v.CreatedAt), CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime), } groupPasture, ok := groupPastureList[v.Id] if ok { for _, g := range groupPasture { res[i].PastureList = append(res[i].PastureList, g.Name) res[i].PastureId = append(res[i].PastureId, uint32(g.Id)) } } systemMenu, ok := systemMenuList[v.Id] if ok { for _, m := range systemMenu { res[i].MenuList = append(res[i].MenuList, m.Name) res[i].MenuId = append(res[i].MenuId, uint32(m.Id)) } } } return res } func (s *SystemRole) ToPb() *operationPb.AddRoleRequest { return &operationPb.AddRoleRequest{ Id: uint32(s.Id), Name: s.Name, CreateUser: s.CreateUser, IsShow: s.IsShow, CreatedAt: uint32(s.CreatedAt), CreatedAtFormat: time.Unix(s.CreatedAt, 0).Format(LayoutTime), } }