|
@@ -1,6 +1,7 @@
|
|
package model
|
|
package model
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
@@ -24,6 +25,7 @@ type SystemUser struct {
|
|
IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
|
|
IsDelete pasturePb.IsShow_Kind `json:"isDelete"`
|
|
Remarks string `json:"remarks"`
|
|
Remarks string `json:"remarks"`
|
|
|
|
+ Spare string `json:"spare"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
UpdatedAt int64 `json:"updated_at"`
|
|
UpdatedAt int64 `json:"updated_at"`
|
|
}
|
|
}
|
|
@@ -43,14 +45,19 @@ func (s *SystemUser) UserUpdate(req *pasturePb.SearchUserRequest, deptIds, pastu
|
|
s.PastureIds = pastureIds
|
|
s.PastureIds = pastureIds
|
|
}
|
|
}
|
|
|
|
|
|
-func NewSystemUser(req *pasturePb.SearchUserRequest, deptIds, pastureIds string) *SystemUser {
|
|
|
|
|
|
+func NewSystemUser(req *pasturePb.SearchUserRequest, deptIds, pastureIds string, pastureDepthList []*pasturePb.PastureDepthDetail) *SystemUser {
|
|
|
|
+ spare := ""
|
|
|
|
+ if len(pastureDepthList) > 0 {
|
|
|
|
+ bt, _ := json.Marshal(pastureDepthList)
|
|
|
|
+ spare = string(bt)
|
|
|
|
+ }
|
|
return &SystemUser{
|
|
return &SystemUser{
|
|
Name: req.Name,
|
|
Name: req.Name,
|
|
NickName: req.NickName,
|
|
NickName: req.NickName,
|
|
Gender: req.Gender,
|
|
Gender: req.Gender,
|
|
Mobile: req.Mobile,
|
|
Mobile: req.Mobile,
|
|
Password: req.Password,
|
|
Password: req.Password,
|
|
- Avatar: "",
|
|
|
|
|
|
+ Avatar: "https://avatars.githubusercontent.com/u/9510375",
|
|
RoleIds: "",
|
|
RoleIds: "",
|
|
DeptIds: deptIds,
|
|
DeptIds: deptIds,
|
|
IndicatorsKinds: fmt.Sprintf("%s,%s,%s,%s,%s,%s", AllCow, OutNumber, InputNumber, SalesVolume, FattenCattleNumber, AdultCow),
|
|
IndicatorsKinds: fmt.Sprintf("%s,%s,%s,%s,%s,%s", AllCow, OutNumber, InputNumber, SalesVolume, FattenCattleNumber, AdultCow),
|
|
@@ -58,16 +65,17 @@ func NewSystemUser(req *pasturePb.SearchUserRequest, deptIds, pastureIds string)
|
|
IsShow: pasturePb.IsShow_Ok,
|
|
IsShow: pasturePb.IsShow_Ok,
|
|
IsDelete: pasturePb.IsShow_Ok,
|
|
IsDelete: pasturePb.IsShow_Ok,
|
|
Remarks: req.Remarks,
|
|
Remarks: req.Remarks,
|
|
|
|
+ Spare: spare,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *SystemUser) GetPastureIds() []int64 {
|
|
|
|
- res := make([]int64, 0)
|
|
|
|
|
|
+func (s *SystemUser) GetPastureIds() []int32 {
|
|
|
|
+ res := make([]int32, 0)
|
|
if s.PastureIds != "" {
|
|
if s.PastureIds != "" {
|
|
pastureIds := strings.Split(s.PastureIds, ",")
|
|
pastureIds := strings.Split(s.PastureIds, ",")
|
|
for _, idStr := range pastureIds {
|
|
for _, idStr := range pastureIds {
|
|
id, _ := strconv.Atoi(idStr)
|
|
id, _ := strconv.Atoi(idStr)
|
|
- res = append(res, int64(id))
|
|
|
|
|
|
+ res = append(res, int32(id))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return res
|
|
return res
|
|
@@ -85,13 +93,13 @@ func (s *SystemUser) GetRoleIds() []int32 {
|
|
return res
|
|
return res
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *SystemUser) GetDepthIds() []int64 {
|
|
|
|
- res := make([]int64, 0)
|
|
|
|
|
|
+func (s *SystemUser) GetDepthIds() []int32 {
|
|
|
|
+ res := make([]int32, 0)
|
|
if s.DeptIds != "" {
|
|
if s.DeptIds != "" {
|
|
depthIds := strings.Split(s.DeptIds, ",")
|
|
depthIds := strings.Split(s.DeptIds, ",")
|
|
for _, idStr := range depthIds {
|
|
for _, idStr := range depthIds {
|
|
id, _ := strconv.Atoi(idStr)
|
|
id, _ := strconv.Atoi(idStr)
|
|
- res = append(res, int64(id))
|
|
|
|
|
|
+ res = append(res, int32(id))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return res
|
|
return res
|
|
@@ -104,58 +112,71 @@ type UserModel struct {
|
|
|
|
|
|
type SystemUserSlice []*SystemUser
|
|
type SystemUserSlice []*SystemUser
|
|
|
|
|
|
-func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole) []*pasturePb.SearchUserRequest {
|
|
|
|
- deptMap := make(map[string]*SystemDept)
|
|
|
|
|
|
+func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole, appPastureList []*AppPastureList) []*pasturePb.SearchUserRequest {
|
|
|
|
+ deptMap := make(map[int32]*SystemDept)
|
|
for _, v := range deptList {
|
|
for _, v := range deptList {
|
|
- deptMap[fmt.Sprintf("%d", v.Id)] = v
|
|
|
|
|
|
+ deptMap[int32(v.Id)] = v
|
|
}
|
|
}
|
|
- roleMap := make(map[string]*SystemRole)
|
|
|
|
|
|
+ roleMap := make(map[int32]*SystemRole)
|
|
for _, v := range roleList {
|
|
for _, v := range roleList {
|
|
- roleMap[fmt.Sprintf("%d", v.Id)] = v
|
|
|
|
|
|
+ roleMap[int32(v.Id)] = v
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ appPastureMap := make(map[int32]*AppPastureList)
|
|
|
|
+ for _, v := range appPastureList {
|
|
|
|
+ appPastureMap[int32(v.Id)] = v
|
|
}
|
|
}
|
|
|
|
|
|
res := make([]*pasturePb.SearchUserRequest, len(s))
|
|
res := make([]*pasturePb.SearchUserRequest, len(s))
|
|
for i, v := range 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,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ userDepthName := make([]string, 0)
|
|
|
|
+ deptIds := v.GetDepthIds()
|
|
|
|
+ for _, d := range deptIds {
|
|
|
|
+ if de, ok := deptMap[d]; ok {
|
|
|
|
+ userDepthName = append(userDepthName, de.Name)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ userRoleName := make([]string, 0)
|
|
|
|
+ roleIds := v.GetRoleIds()
|
|
|
|
+ for _, r := range roleIds {
|
|
|
|
+ if ro, ok := roleMap[r]; ok {
|
|
|
|
+ userRoleName = append(userRoleName, ro.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,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ pastureName := make([]string, 0)
|
|
|
|
+ for _, p := range v.GetPastureIds() {
|
|
|
|
+ if pa, ok := appPastureMap[p]; ok {
|
|
|
|
+ pastureName = append(pastureName, pa.Name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ pastureDepthList := make([]*pasturePb.PastureDepthDetail, 0)
|
|
|
|
+ if len(v.Spare) > 0 {
|
|
|
|
+ json.Unmarshal([]byte(v.Spare), &pastureDepthList)
|
|
|
|
+ }
|
|
|
|
+
|
|
res[i] = &pasturePb.SearchUserRequest{
|
|
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),
|
|
|
|
|
|
+ Id: int32(v.Id),
|
|
|
|
+ Name: v.Name,
|
|
|
|
+ NickName: v.NickName,
|
|
|
|
+ Mobile: v.Mobile,
|
|
|
|
+ Avatar: v.Avatar,
|
|
|
|
+ Gender: v.Gender,
|
|
|
|
+ IsShow: v.IsShow,
|
|
|
|
+ IsDelete: v.IsDelete,
|
|
|
|
+ Remarks: v.Remarks,
|
|
|
|
+ PastureDepthList: pastureDepthList,
|
|
|
|
+ DepthId: deptIds,
|
|
|
|
+ DeptName: userDepthName,
|
|
|
|
+ RoleList: nil,
|
|
|
|
+ RoleId: v.GetRoleIds(),
|
|
|
|
+ RoleName: userRoleName,
|
|
|
|
+ PastureId: v.GetPastureIds(),
|
|
|
|
+ PastureName: pastureName,
|
|
|
|
+ CreatedAtFormat: time.Unix(v.CreatedAt, 0).Local().Format(LayoutTime),
|
|
|
|
+ UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Local().Format(LayoutTime),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return res
|
|
return res
|