123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- package model
- import (
- "fmt"
- "strconv"
- "strings"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type SystemUser struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
- NickName string `json:"nickName"`
- Gender pasturePb.Genders_Kind `json:"gender"`
- Mobile string `json:"mobile"`
- Password string `json:"password"`
- Avatar string `json:"avatar"`
- RoleIds string `json:"roleIds"`
- DeptIds string `json:"deptIds"`
- IndicatorsKinds string `json:"indicatorsKinds"`
- 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) UserUpdate(req *pasturePb.SearchUserRequest, deptIds, pastureIds string) {
- s.Name = req.Name
- s.NickName = req.NickName
- s.Mobile = req.Mobile
- s.Gender = req.Gender
- s.DeptIds = deptIds
- s.Remarks = req.Remarks
- s.IsShow = req.IsShow
- s.PastureIds = pastureIds
- }
- func NewSystemUser(req *pasturePb.SearchUserRequest, deptIds, pastureIds string) *SystemUser {
- return &SystemUser{
- Name: req.Name,
- NickName: req.NickName,
- Gender: req.Gender,
- Mobile: req.Mobile,
- Password: req.Password,
- Avatar: "",
- RoleIds: "",
- DeptIds: deptIds,
- IndicatorsKinds: fmt.Sprintf("%s,%s,%s,%s,%s,%s", AllCow, OutNumber, InputNumber, SalesVolume, FattenCattleNumber, AdultCow),
- PastureIds: pastureIds,
- IsShow: pasturePb.IsShow_Ok,
- IsDelete: pasturePb.IsShow_Ok,
- Remarks: req.Remarks,
- }
- }
- func (s *SystemUser) GetPastureIds() []int64 {
- res := make([]int64, 0)
- if s.PastureIds != "" {
- pastureIds := strings.Split(s.PastureIds, ",")
- for _, idStr := range pastureIds {
- id, _ := strconv.Atoi(idStr)
- res = append(res, int64(id))
- }
- }
- return res
- }
- func (s *SystemUser) GetRoleIds() []int32 {
- res := make([]int32, 0)
- if s.RoleIds != "" {
- roleIds := strings.Split(s.RoleIds, ",")
- for _, idStr := range roleIds {
- id, _ := strconv.Atoi(idStr)
- res = append(res, int32(id))
- }
- }
- return res
- }
- func (s *SystemUser) GetDepthIds() []int64 {
- res := make([]int64, 0)
- if s.DeptIds != "" {
- depthIds := strings.Split(s.DeptIds, ",")
- for _, idStr := range depthIds {
- id, _ := strconv.Atoi(idStr)
- res = append(res, int64(id))
- }
- }
- return res
- }
- 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,
- //PastureDepthList: 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 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
- }
|