Browse Source

system: 系统设置调整

ping 10 months ago
parent
commit
5f0285e570
5 changed files with 41 additions and 22 deletions
  1. 1 1
      go.mod
  2. 4 0
      go.sum
  3. 21 14
      model/system_dept.go
  4. 9 5
      module/backend/config_data.go
  5. 6 2
      module/backend/system_service.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240523134220-ba93682bd389
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240524004006-fa7e55b57e1a
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/getsentry/sentry-go v0.23.0

+ 4 - 0
go.sum

@@ -68,6 +68,10 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240523080657-02e978da15c4 h1:aetycKzx
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240523080657-02e978da15c4/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240523134220-ba93682bd389 h1:43IRgppwRjNuTkYiRfDnKsdjBKzVXVngfhKT2F0xHEs=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240523134220-ba93682bd389/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240523234532-3f892302e1b1 h1:Qo70vVtXVdmqZY4qg7v5GIF7Q29PJZbQ6nosgM+zE5w=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240523234532-3f892302e1b1/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240524004006-fa7e55b57e1a h1:j8eLmI8VXAc6HHCN4AhyP4ibtEzrvYn43dJe3H/DtpY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240524004006-fa7e55b57e1a/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015 h1:dfb5dRd57L2HKjdwLT93UFmPYFPOmEl56gtZmqcNnaE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015/go.mod h1:Fk4GYI/v0IK3XFrm1Gn+VkgCz5Y7mfswD5hsTJYOG6A=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 21 - 14
model/system_dept.go

@@ -1,8 +1,6 @@
 package model
 
 import (
-	"time"
-
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
@@ -26,21 +24,30 @@ func (s *SystemDept) TableName() string {
 
 type SystemDeptSlice []*SystemDept
 
-func (s SystemDeptSlice) ToPB() []*pasturePb.SearchDeptRequest {
+func (s SystemDeptSlice) ToPB(systemUserList []*SystemUser) []*pasturePb.SearchDeptRequest {
 	res := make([]*pasturePb.SearchDeptRequest, len(s))
 	for i, d := range s {
+		leaderName := ""
+		for _, v := range systemUserList {
+			if d.LeaderId != v.Id {
+				continue
+			}
+			leaderName = v.Name
+		}
+
 		res[i] = &pasturePb.SearchDeptRequest{
-			Id:              int32(d.Id),
-			Name:            d.Name,
-			Remarks:         d.Remarks,
-			ParentId:        int32(d.ParentId),
-			DepthType:       d.DeptType,
-			LeaderId:        int32(d.LeaderId),
-			Sort:            d.Sort,
-			IsShow:          d.IsShow,
-			IsDelete:        d.IsDelete,
-			CreatedAtFormat: time.Unix(d.CreatedAt, 0).Format(LayoutTime),
-			UpdatedAtFormat: time.Unix(d.UpdatedAt, 0).Format(LayoutTime),
+			Id:         int32(d.Id),
+			Name:       d.Name,
+			Remarks:    d.Remarks,
+			ParentId:   int32(d.ParentId),
+			DepthType:  d.DeptType,
+			LeaderId:   int32(d.LeaderId),
+			LeaderName: leaderName,
+			Sort:       d.Sort,
+			IsShow:     d.IsShow,
+			IsDelete:   d.IsDelete,
+			CreatedAt:  int32(d.CreatedAt),
+			UpdatedAt:  int32(d.UpdatedAt),
 		}
 	}
 	return res

+ 9 - 5
module/backend/config_data.go

@@ -344,10 +344,12 @@ func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOpti
 }
 func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) {
 	penList := make([]*model.Pen, 0)
-	if err := s.DB.Table(new(model.Pen).TableName()).
-		Where("is_delete = ?", pasturePb.IsShow_Ok).
-		Where("pen_type = ?", penType).
-		Find(&penList).Error; err != nil {
+	pref := s.DB.Table(new(model.Pen).TableName()).
+		Where("is_delete = ?", pasturePb.IsShow_Ok)
+	if penType != -1 {
+		pref.Where("pen_type = ?", penType)
+	}
+	if err := pref.Find(&penList).Error; err != nil {
 		return nil, err
 	}
 
@@ -406,7 +408,9 @@ func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pastureP
 
 func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) {
 	systemUserList := make([]*model.SystemUser, 0)
-	pref := s.DB.Table(new(model.SystemUser).TableName())
+	pref := s.DB.Table(new(model.SystemUser).TableName()).
+		Where("is_delete = ?", pasturePb.IsShow_Ok).
+		Where("is_show =? ", pasturePb.IsShow_Ok)
 	if depId != -1 && depId > 0 {
 		pref = pref.Where("dep_id = ?", depId)
 	}

+ 6 - 2
module/backend/system_service.go

@@ -120,7 +120,9 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 
 func (s *StoreEntry) SystemUserList(ctx context.Context) ([]*model.SystemUser, error) {
 	systemUserList := make([]*model.SystemUser, 0)
-	if err := s.DB.Where("is_delete = ?", pasturePb.IsShow_Ok).Find(&systemUserList).Error; err != nil {
+	if err := s.DB.Where("is_delete = ?", pasturePb.IsShow_Ok).
+		Where("is_show = ? ", pasturePb.IsShow_Ok).
+		Find(&systemUserList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 	return systemUserList, nil
@@ -598,10 +600,12 @@ func (s *StoreEntry) SearchSystemDeptList(ctx context.Context, req *pasturePb.Se
 		return nil, xerr.WithStack(err)
 	}
 
+	systemUserList, _ := s.SystemUserList(ctx)
+
 	return &pasturePb.SearchDeptResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
-		Data:    model.SystemDeptSlice(deptList).ToPB(),
+		Data:    model.SystemDeptSlice(deptList).ToPB(systemUserList),
 	}, nil
 }