123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package model
- import (
- "fmt"
- "net/http"
- "strings"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- )
- type SystemUser struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
- NickName string `json:"nickName"`
- Mobile string `json:"mobile"`
- Password string `json:"password"`
- Avatar string `json:"avatar"`
- RoleIds string `json:"roleIds"`
- DeptIds string `json:"deptIds"`
- IndicatorsKinds string `json:"indicatorsKinds"`
- Gender pasturePb.Genders_Kind `json:"gender"`
- PastureIds string `json:"pastureIds"`
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
- IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
- Remarks string `json:"remarks"`
- CreatedAt int64 `json:"created_at"`
- UpdatedAt int64 `json:"updated_at"`
- }
- func (s *SystemUser) TableName() string {
- return "system_user"
- }
- func (s *SystemUser) SystemUserFormat(userRoles []*SystemRole, pastures []*operationPb.UserPasture) *operationPb.UserAuth {
- roles := make([]*operationPb.UserRole, len(userRoles))
- for k, v := range userRoles {
- roles[k] = &operationPb.UserRole{
- Id: int32(v.Id),
- Name: v.Name,
- }
- }
- return &operationPb.UserAuth{
- Code: http.StatusOK,
- Msg: "ok",
- Data: &operationPb.UserAuthData{
- UserName: s.Name,
- Roles: roles,
- Pastures: pastures,
- },
- }
- }
- type UserModel struct {
- SystemUser *SystemUser
- AppPasture *AppPastureList
- }
- type SystemUserSlice []*SystemUser
- func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole) []*pasturePb.SearchUserRequest {
- deptMap := make(map[string]*SystemDept)
- for _, v := range deptList {
- deptMap[fmt.Sprintf("%d", v.Id)] = v
- }
- roleMap := make(map[string]*SystemRole)
- for _, v := range roleList {
- roleMap[fmt.Sprintf("%d", v.Id)] = v
- }
- res := make([]*pasturePb.SearchUserRequest, len(s))
- for i, v := range s {
- userDeptList := make([]*pasturePb.IdName, 0)
- if v.DeptIds != "" {
- deptIds := strings.Split(v.DeptIds, ",")
- for _, d := range deptIds {
- if de, ok := deptMap[d]; ok {
- userDeptList = append(userDeptList, &pasturePb.IdName{
- Id: int32(de.Id),
- Name: de.Name,
- })
- }
- }
- }
- userRoleList := make([]*pasturePb.IdName, 0)
- if v.RoleIds != "" {
- roleIds := strings.Split(v.RoleIds, ",")
- for _, r := range roleIds {
- if ro, ok := roleMap[r]; ok {
- userRoleList = append(userRoleList, &pasturePb.IdName{
- Id: int32(ro.Id),
- Name: ro.Name,
- })
- }
- }
- }
- res[i] = &pasturePb.SearchUserRequest{
- Id: int32(v.Id),
- Name: v.Name,
- Mobile: v.Mobile,
- NickName: v.NickName,
- Avatar: v.Avatar,
- Gender: v.Gender,
- IsShow: v.IsShow,
- IsDelete: v.IsDelete,
- Remarks: v.Remarks,
- DepthList: userDeptList,
- RoleList: userRoleList,
- CreatedAtFormat: time.Unix(v.CreatedAt, 0).Local().Format(LayoutTime),
- UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Local().Format(LayoutTime),
- }
- }
- return res
- }
- func (s *SystemUser) ToPb() *operationPb.AddSystemUser {
- return &operationPb.AddSystemUser{
- Id: int32(s.Id),
- Name: s.Name,
- CreatedAt: int32(s.CreatedAt),
- CreatedAtFormat: time.Unix(s.CreatedAt, 0).Local().Format(LayoutTime),
- RoleIds: []int32{},
- }
- }
- func (s SystemUserSlice) ToPB2() []*pasturePb.ConfigOptionsList {
- res := make([]*pasturePb.ConfigOptionsList, len(s))
- for i, d := range s {
- res[i] = &pasturePb.ConfigOptionsList{
- Value: int32(d.Id),
- Label: d.Name,
- Disabled: true,
- }
- }
- return res
- }
|