Procházet zdrojové kódy

pasture: 牧场管理-栏舍管理模块

Yi před 11 měsíci
rodič
revize
6dee0d6c45

+ 2 - 2
config/app.develop.yaml

@@ -8,8 +8,8 @@ jwt_expire_time: 172800
 store:
   show_sql: true
   driver_name: mysql
-  kpt_rw: "root:123456@tcp(47.92.95.119:3306)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
-  kpt_migr: "root:123456@tcp(47.92.95.119:3306)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
+  kpt_rw: "kpt_pasture:4~H@InK6jK@tcp(47.92.95.119:3326)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
+  kpt_migr: "kpt_pasture:4~H@InK6jK@tcp(47.92.95.119:3326)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
 
 redis_setting:
   sso_cache:

+ 2 - 2
config/app.test.yaml

@@ -8,8 +8,8 @@ jwt_expire_time: 172800
 store:
   show_sql: true
   driver_name: mysql
-  kpt_rw: "root:123456@tcp(47.92.95.119:3306)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
-  kpt_migr: "root:123456@tcp(47.92.95.119:3306)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
+  kpt_rw: "kpt_pasture:4~H@InK6jK@tcp(47.92.95.119:3326)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
+  kpt_migr: "kpt_pasture:4~H@InK6jK@tcp(47.92.95.119:3326)/kpt_pasture?charset=utf8mb4&parseTime=true&loc=Local&allowNativePasswords=true&timeout=300s&readTimeout=300s&writeTimeout=300s"
 
 redis_setting:
   sso_cache:

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240410062335-c8e3d2cdf42e
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240426071708-b9b3ad7038bd
 	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

+ 24 - 0
go.sum

@@ -38,6 +38,30 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240410062335-c8e3d2cdf42e h1:9ULDek9hY5Wwq2kowvlkP4cs0EHyit61Y5UXMm30qNQ=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240410062335-c8e3d2cdf42e/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423060400-7aab96199f28 h1:EE/krB13w6d+CM2QnJpiUIZvYupk1GRb0ibBwjtS87U=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423060400-7aab96199f28/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423064437-ed6e968b60b0 h1:UhgBHbYI3ZqPZsozo9syLfUA4MfDUpuR6/GfqChT7pE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423064437-ed6e968b60b0/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423074707-38168d47d746 h1:aMUKy/NQwcHjVylqLiJmRkBCMzWxU6I2Vigamcs859Y=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423074707-38168d47d746/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423085407-1b1485d9ef23 h1:D9l7UJOaW9iEHysy1m0qWJKYucYkXkGfHszHouIzdPY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423085407-1b1485d9ef23/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423091123-4c66ec606d44 h1:ZE8O4adX0eIntRVXwdYnSB0pGUcI/XVvAIKsO0rWwDY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240423091123-4c66ec606d44/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240425052959-85ae9a2fe5bb h1:6IBpGt6kf7d7c+qLKOfvVxZ7Q46+qjcQbu5zzFqINf0=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240425052959-85ae9a2fe5bb/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240425055608-2c760fefec9e h1:YPxPCEeSxg+m47V4rk9Dl/idzLCnSME6E3rNzopSgyA=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240425055608-2c760fefec9e/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240425060737-5be481b3c899 h1:+Um88uwlW68BR+PL2KVXcZxTBimnMAPG9gNBm96WFs8=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240425060737-5be481b3c899/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426031212-ce26e36229f2 h1:+susVuhAgqoXhoQognNfDOug6/rUVBSj6Q+3JsBeUcM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426031212-ce26e36229f2/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426032250-3453d0d3127c h1:0Klrgv7ofDqfmNscKdtWj+M8G7Seok5JcDowLMG1eSI=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426032250-3453d0d3127c/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426060603-a68c0321fda3 h1:CpeOukiJE82k2PCJM5qRyOrX01mesj3r19UVnYoxuWc=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426060603-a68c0321fda3/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426071708-b9b3ad7038bd h1:t/CNbQqjhxWVw53ZQz/4GV1e0eLw7eEmQhGCsIT1p9k=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240426071708-b9b3ad7038bd/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 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=

+ 18 - 0
http/handler/config/config.go

@@ -0,0 +1,18 @@
+package config
+
+import (
+	"kpt-pasture/http/middleware"
+
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"github.com/gin-gonic/gin"
+)
+
+func BarnTypeList(c *gin.Context) {
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.BarnTypeList(c)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}

+ 65 - 0
http/handler/pasture/barn.go

@@ -0,0 +1,65 @@
+package pasture
+
+import (
+	"kpt-pasture/http/middleware"
+	"net/http"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
+
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"gitee.com/xuyiping_admin/pkg/valid"
+	"github.com/gin-gonic/gin"
+)
+
+func SearchBarnList(c *gin.Context) {
+	var req pasturePb.SearchBarnRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	pagination := &pasturePb.PaginationModel{
+		Page:       int32(c.GetInt(middleware.Page)),
+		PageSize:   int32(c.GetInt(middleware.PageSize)),
+		PageOffset: int32(c.GetInt(middleware.PageOffset)),
+	}
+
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchBarnList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}
+
+// CreatedOrUpdateBarn 添加或者更新栏舍
+func CreatedOrUpdateBarn(c *gin.Context) {
+	var req pasturePb.SearchBarnList
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.Name, valid.Required),
+		valid.Field(&req.Lengths, valid.Required, valid.Min(1)),
+		valid.Field(&req.Widths, valid.Required, valid.Min(1)),
+		valid.Field(&req.DoctrinalCapacity, valid.Required, valid.Min(1)),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateBarn(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 2 - 2
http/handler/system/dept.go

@@ -22,13 +22,13 @@ func DeptList(c *gin.Context) {
 		return
 	}
 
-	req.Pagination = &pasturePb.PaginationModel{
+	pagination := &pasturePb.PaginationModel{
 		Page:       int32(c.GetInt(middleware.Page)),
 		PageSize:   int32(c.GetInt(middleware.PageSize)),
 		PageOffset: int32(c.GetInt(middleware.PageOffset)),
 	}
 
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemDeptList(c, &req)
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemDeptList(c, &req, pagination)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 2 - 2
http/handler/system/menu.go

@@ -52,13 +52,13 @@ func SearchSystemMenuList(c *gin.Context) {
 		return
 	}
 
-	req.Pagination = &pasturePb.PaginationModel{
+	pagination := &pasturePb.PaginationModel{
 		Page:       int32(c.GetInt(middleware.Page)),
 		PageSize:   int32(c.GetInt(middleware.PageSize)),
 		PageOffset: int32(c.GetInt(middleware.PageOffset)),
 	}
 
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemMenuList(c, &req)
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemMenuList(c, &req, pagination)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 2 - 2
http/handler/system/role.go

@@ -110,13 +110,13 @@ func SearchSystemRoleList(c *gin.Context) {
 		return
 	}
 
-	req.Pagination = &pasturePb.PaginationModel{
+	pagination := &pasturePb.PaginationModel{
 		Page:       int32(c.GetInt(middleware.Page)),
 		PageSize:   int32(c.GetInt(middleware.PageSize)),
 		PageOffset: int32(c.GetInt(middleware.PageOffset)),
 	}
 
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemRoleList(c, &req)
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemRoleList(c, &req, pagination)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 2 - 2
http/handler/system/user.go

@@ -81,13 +81,13 @@ func SearchSystemUserList(c *gin.Context) {
 		return
 	}
 
-	req.Pagination = &pasturePb.PaginationModel{
+	pagination := &pasturePb.PaginationModel{
 		Page:       int32(c.GetInt(middleware.Page)),
 		PageSize:   int32(c.GetInt(middleware.PageSize)),
 		PageOffset: int32(c.GetInt(middleware.PageOffset)),
 	}
 
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemUserList(c, &req)
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemUserList(c, &req, pagination)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 0 - 37
http/handler/user.go

@@ -3,50 +3,13 @@ package handler
 import (
 	"kpt-pasture/http/middleware"
 	"net/http"
-	"strconv"
 
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 	"gitee.com/xuyiping_admin/pkg/apierr"
 	"gitee.com/xuyiping_admin/pkg/ginutil"
-	"gitee.com/xuyiping_admin/pkg/valid"
 	"github.com/gin-gonic/gin"
 )
 
-// GetUserInfo 获取用户信息
-func GetUserInfo(c *gin.Context) {
-	token := middleware.GetToken(c)
-	if err := valid.Validate(token, valid.Required); err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-
-	res, err := middleware.BackendOperation(c).OpsService.GetUserInfo(c, token)
-	if err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-	ginutil.JSONResp(c, res)
-}
-
-// Details 系统用户详情
-func Details(c *gin.Context) {
-	userIdStr := c.Param("user_id")
-	userId, _ := strconv.Atoi(userIdStr)
-
-	if err := valid.Validate(userId, valid.Required, valid.Min(1)); err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-
-	res, err := middleware.BackendOperation(c).OpsService.DetailsSystemUser(c, int64(userId))
-	if err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-
-	ginutil.JSONResp(c, res)
-}
-
 // GetUserMenu 获取系统用户菜单权限
 func GetUserMenu(c *gin.Context) {
 	res, err := middleware.BackendOperation(c).OpsService.GetSystemUserMenu(c)

+ 18 - 0
http/route/config_api.go

@@ -0,0 +1,18 @@
+package route
+
+import (
+	"kpt-pasture/http/handler/config"
+
+	"github.com/gin-gonic/gin"
+)
+
+func ConfigAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+		// pasture API 组  牧场管理
+		pastureRoute := authRouteGroup(s, "/api/v1/config/")
+		pastureRoute.GET("/barn/type/list", config.BarnTypeList)
+	}
+}

+ 19 - 0
http/route/pasture_api.go

@@ -0,0 +1,19 @@
+package route
+
+import (
+	"kpt-pasture/http/handler/pasture"
+
+	"github.com/gin-gonic/gin"
+)
+
+func PastureManageAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+		// pasture API 组  牧场管理
+		pastureRoute := authRouteGroup(s, "/api/v1/pasture/")
+		pastureRoute.POST("/barn/list", pasture.SearchBarnList)
+		pastureRoute.POST("/barn/createOrUpdate", pasture.CreatedOrUpdateBarn)
+	}
+}

+ 2 - 0
http/route/route.go

@@ -7,6 +7,8 @@ func HTTPServerRoute(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 	routes := []func(s *gin.Engine){
 		Root(opts...),
 		SystemAPI(opts...),
+		PastureManageAPI(opts...),
+		ConfigAPI(opts...),
 	}
 
 	return func(s *gin.Engine) {

+ 0 - 3
http/route/system_api.go

@@ -51,9 +51,6 @@ func SystemAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 
 		// 登录用户的相关接口
 		systemRoute.GET("/user/menu", handler.GetUserMenu)
-
-		systemRoute.POST("/user_info", handler.GetUserInfo)
-		systemRoute.GET("/user/details/:user_id", handler.Details)
 		systemRoute.POST("/user/logout", handler.Logout)
 	}
 }

+ 59 - 0
model/barn.go

@@ -0,0 +1,59 @@
+package model
+
+import (
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+type Bran struct {
+	Id                int64                 `json:"id"`
+	Name              string                `json:"name"`
+	Remarks           string                `json:"remarks"`
+	BarnType          int32                 `json:"barn_type"`
+	Lengths           int32                 `json:"lengths"`
+	Widths            int32                 `json:"widths"`
+	DoctrinalCapacity int32                 `json:"doctrinal_capacity"`
+	ActualCapacity    int32                 `json:"actual_capacity"`
+	BedNumber         int32                 `json:"bed_number"`
+	NeckNumber        int32                 `json:"neck_number"`
+	IsShow            pasturePb.IsShow_Kind `json:"is_show"`
+	IsDelete          pasturePb.IsShow_Kind `json:"is_delete"`
+	CreatedAt         int64                 `json:"created_at"`
+	UpdatedAt         int64                 `json:"updated_at"`
+}
+
+func (b *Bran) TableName() string {
+	return "barn"
+}
+
+type BarnSlice []*Bran
+
+func (b BarnSlice) ToPB(configBarnTypes []*ConfigBarnType) []*pasturePb.SearchBarnList {
+	res := make([]*pasturePb.SearchBarnList, len(b))
+	for i, v := range b {
+		barnTypeName := ""
+		for _, c := range configBarnTypes {
+			if c.Id == int64(v.BarnType) {
+				barnTypeName = c.Name
+				break
+			}
+		}
+
+		res[i] = &pasturePb.SearchBarnList{
+			Id:                v.Id,
+			Name:              v.Name,
+			IsShow:            v.IsShow,
+			Remarks:           v.Remarks,
+			BarnTypeId:        int32(v.BarnType),
+			BarnTypeName:      barnTypeName,
+			Lengths:           v.Lengths,
+			Widths:            v.Widths,
+			DoctrinalCapacity: v.DoctrinalCapacity,
+			ActualCapacity:    v.ActualCapacity,
+			NeckNumber:        v.NeckNumber,
+			BedNumber:         v.BedNumber,
+			CreatedAt:         int32(v.CreatedAt),
+			UpdatedAt:         int32(v.UpdatedAt),
+		}
+	}
+	return res
+}

+ 32 - 0
model/config_barn_type.go

@@ -0,0 +1,32 @@
+package model
+
+import (
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+type ConfigBarnType struct {
+	Id        int64                 `json:"id"`
+	Name      string                `json:"name"`
+	Remarks   string                `json:"remarks"`
+	IsShow    pasturePb.IsShow_Kind `json:"is_show"`
+	CreatedAt int64                 `json:"created_at"`
+	UpdatedAt int64                 `json:"updated_at"`
+}
+
+func (c *ConfigBarnType) TableName() string {
+	return "config_barn_type"
+}
+
+type ConfigBarnTypeSlice []*ConfigBarnType
+
+func (c ConfigBarnTypeSlice) ToPB() []*pasturePb.BarnTypeList {
+	res := make([]*pasturePb.BarnTypeList, len(c))
+	for i, d := range c {
+		res[i] = &pasturePb.BarnTypeList{
+			Value:    int32(d.Id),
+			Label:    d.Name,
+			Disabled: true,
+		}
+	}
+	return res
+}

+ 6 - 8
model/system_menu.go

@@ -4,9 +4,6 @@ import (
 	"sort"
 	"time"
 
-	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
-	"go.uber.org/zap"
-
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
@@ -123,10 +120,13 @@ func (s SystemMenuSlice) ToTree() []*pasturePb.MenuTree {
 			Id:       int32(v.Id),
 			Path:     v.Path,
 			ParentId: int32(v.ParentId),
+			Name:     v.Name,
 			Meta: &pasturePb.MenuMeta{
-				Icon:  v.Icon,
-				Title: v.Title,
-				Rank:  v.Rank,
+				Icon:     v.Icon,
+				Title:    v.Title,
+				Rank:     v.Rank,
+				Roles:    []string{"admin"},
+				ShowLink: v.ShowLink == pasturePb.IsShow_Ok,
 			},
 			Children: make([]*pasturePb.MenuTree, 0),
 		}
@@ -147,8 +147,6 @@ func buildTree(menuTreeList []*pasturePb.MenuTree) []*pasturePb.MenuTree {
 			}
 		}
 	}
-
-	zaplog.Info("tree", zap.Any("tree", tree))
 	return tree
 }
 

+ 0 - 10
model/system_role.go

@@ -4,7 +4,6 @@ import (
 	"time"
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
-	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 )
 
 type SystemRole struct {
@@ -26,15 +25,6 @@ const (
 	LayoutDate = "20060102"
 )
 
-func NewSystemRole(req *operationPb.AddRoleRequest) *SystemRole {
-	systemRole := &SystemRole{
-		Name:    req.Name,
-		Remarks: req.Remarks,
-		IsShow:  pasturePb.IsShow_Ok,
-	}
-	return systemRole
-}
-
 type SystemRoleSlice []*SystemRole
 
 func (s SystemRoleSlice) ToPB() []*pasturePb.SearchRoleRequest {

+ 0 - 1
model/system_user.go

@@ -91,7 +91,6 @@ func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole) []
 }
 
 func (s *SystemUser) ToPb() *operationPb.AddSystemUser {
-
 	return &operationPb.AddSystemUser{
 		Id:              int32(s.Id),
 		Name:            s.Name,

+ 23 - 0
module/backend/config_data.go

@@ -0,0 +1,23 @@
+package backend
+
+import (
+	"context"
+	"kpt-pasture/model"
+	"net/http"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+func (s *StoreEntry) BarnTypeList(ctx context.Context) (*pasturePb.BarnTypeListResponse, error) {
+	configBarnTypeList := make([]*model.ConfigBarnType, 0)
+
+	if err := s.DB.Table(new(model.ConfigBarnType).TableName()).Find(&configBarnTypeList).Error; err != nil {
+		return nil, err
+	}
+
+	return &pasturePb.BarnTypeListResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data:    model.ConfigBarnTypeSlice(configBarnTypeList).ToPB(),
+	}, nil
+}

+ 18 - 8
module/backend/interface.go

@@ -7,7 +7,6 @@ import (
 	"kpt-pasture/store/kptstore"
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
-	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 	"gitee.com/xuyiping_admin/pkg/di"
 
 	"go.uber.org/dig"
@@ -42,14 +41,16 @@ func NewStoreEntry(cfg *config.AppConfig, Db *kptstore.DB) *StoreEntry {
 
 //go:generate mockgen -destination mock/kptservice.go -package kptservicemock kpt-pasture/module/backend KptService
 type KptService interface {
-	SystemService // 系统相关操作
+	SystemService        // 系统相关操作
+	PastureManageService // 牧场管理相关
+	ConfigDataService    // 配置数据相关
 }
 
 //go:generate mockgen -destination mock/SystemService.go -package kptservicemock kpt-pasture/module/backend SystemService
 type SystemService interface {
 	// Login 系统用户相关
 	Login(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SystemUserResponse, error)
-	SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SearchUserResponse, error)
+	SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchUserResponse, error)
 	IsShowSystemUser(ctx context.Context, userId int64) error
 	DeleteSystemUser(ctx context.Context, userId int64) error
 	SystemUserCreateOrUpdate(ctx context.Context, req *pasturePb.SearchUserRequest) error
@@ -61,11 +62,9 @@ type SystemService interface {
 	GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUserMenuTreeResponse, error)
 
 	GetCurrentUserName(ctx context.Context) (string, error)
-	GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error)
-	DetailsSystemUser(ctx context.Context, userId int64) (*operationPb.UserDetails, error)
 
 	// SearchSystemRoleList 系统角色相关
-	SearchSystemRoleList(ctx context.Context, req *pasturePb.SearchRoleRequest) (*pasturePb.SearchRoleResponse, error)
+	SearchSystemRoleList(ctx context.Context, req *pasturePb.SearchRoleRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchRoleResponse, error)
 	DeleteSystemRole(ctx context.Context, roleId int64) error
 	IsShowSystemRole(ctx context.Context, roleId int64) error
 	SystemRoleCreateOrUpdate(ctx context.Context, req *pasturePb.SearchRoleRequest) error
@@ -74,13 +73,24 @@ type SystemService interface {
 	SystemRoleList(ctx context.Context) (*pasturePb.GetRoleListResponse, error)
 
 	// SearchSystemMenuList 系统菜单权限
-	SearchSystemMenuList(ctx context.Context, req *pasturePb.SearchMenuRequest) (*pasturePb.SearchMenuResponse, error)
+	SearchSystemMenuList(ctx context.Context, req *pasturePb.SearchMenuRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchMenuResponse, error)
 	DeleteSystemMenu(ctx context.Context, menuId int64) error
 	CreateOrUpdateSystemMenu(ctx context.Context, req *pasturePb.SearchMenuRequest) error
 	SystemMenuTree(ctx context.Context) (*pasturePb.SystemMenuTreeResponse, error)
 
 	// SearchSystemDeptList 部门列表
-	SearchSystemDeptList(ctx context.Context, req *pasturePb.SearchDeptRequest) (*pasturePb.SearchDeptResponse, error)
+	SearchSystemDeptList(ctx context.Context, req *pasturePb.SearchDeptRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchDeptResponse, error)
 	SystemDepDelete(ctx context.Context, id int64) error
 	SystemDeptCreateOrUpdate(ctx context.Context, req *pasturePb.SearchDeptRequest) error
 }
+
+//go:generate mockgen -destination mock/PastureManageService.go -package kptservicemock kpt-pasture/module/backend PastureManageService
+type PastureManageService interface {
+	SearchBarnList(ctx context.Context, req *pasturePb.SearchBarnRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchBarnResponse, error)
+	CreateOrUpdateBarn(ctx context.Context, req *pasturePb.SearchBarnList) error
+}
+
+//go:generate mockgen -destination mock/ConfigDataService.go -package kptservicemock kpt-pasture/module/backend ConfigDataService
+type ConfigDataService interface {
+	BarnTypeList(ctx context.Context) (*pasturePb.BarnTypeListResponse, error)
+}

+ 74 - 0
module/backend/pasture_manage.go

@@ -0,0 +1,74 @@
+package backend
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"kpt-pasture/model"
+	"net/http"
+
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"gorm.io/gorm"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+func (s *StoreEntry) SearchBarnList(ctx context.Context, req *pasturePb.SearchBarnRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchBarnResponse, error) {
+	barnList := make([]*model.Bran, 0)
+	var count int64 = 0
+
+	pref := s.DB.Model(new(model.Bran)).Where("is_delete = ?", pasturePb.IsShow_Ok)
+	if req.Name != "" {
+		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
+	}
+
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
+		Find(&barnList).Debug().Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	configBarnTypeList := make([]*model.ConfigBarnType, 0)
+	if err := s.DB.Model(new(model.ConfigBarnType)).Find(&configBarnTypeList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.SearchBarnResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchBarnData{
+			List:     model.BarnSlice(barnList).ToPB(configBarnTypeList),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
+func (s *StoreEntry) CreateOrUpdateBarn(ctx context.Context, req *pasturePb.SearchBarnList) error {
+	if req.Id > 0 {
+		barn := &model.Bran{Id: req.Id}
+		if err := s.DB.Model(&model.Bran{}).First(barn).Error; err != nil {
+			if !errors.Is(err, gorm.ErrRecordNotFound) {
+				return xerr.WithStack(err)
+			}
+		}
+	}
+
+	if err := s.DB.Model(&model.Bran{}).Where(map[string]interface{}{
+		"id": req.Id,
+	}).Assign(map[string]interface{}{
+		"name":               req.Name,
+		"remarks":            req.Remarks,
+		"barn_type":          req.BarnTypeId,
+		"lengths":            req.Lengths,
+		"widths":             req.Widths,
+		"doctrinal_capacity": req.DoctrinalCapacity,
+		"bed_number":         req.BedNumber,
+		"neck_number":        req.NeckNumber,
+		"is_delete":          pasturePb.IsShow_Ok,
+		"is_show":            pasturePb.IsShow_Ok,
+	}).FirstOrCreate(&model.Bran{}).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}

+ 24 - 51
module/backend/system_service.go

@@ -70,7 +70,7 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
 }
 
 // SearchSystemUserList 查询系统用户
-func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SearchUserResponse, error) {
+func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchUserResponse, error) {
 	systemUserList := make([]*model.SystemUser, 0)
 	var count int64 = 0
 
@@ -91,7 +91,7 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 		pref.Where("is_show = ?", req.IsShow)
 	}
 
-	if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
 		Find(&systemUserList).Debug().Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
@@ -112,8 +112,8 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 		Data: &pasturePb.SearchUserData{
 			List:     model.SystemUserSlice(systemUserList).ToPB(deptList, roleList),
 			Total:    int32(count),
-			PageSize: req.Pagination.PageSize,
-			Page:     req.Pagination.Page,
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
 		},
 	}, nil
 }
@@ -265,41 +265,6 @@ func (s *StoreEntry) GetCurrentUserName(ctx context.Context) (string, error) {
 	}
 }
 
-// GetUserInfo 获取用户信息
-func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error) {
-	systemUser := &model.SystemUser{}
-	userName, err := s.GetCurrentUserName(ctx)
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	if err = s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	systemRole := make([]*model.SystemRole, 0)
-	return systemUser.SystemUserFormat(systemRole, nil), nil
-}
-
-// DetailsSystemUser 系统用户详情
-func (s *StoreEntry) DetailsSystemUser(ctx context.Context, userId int64) (*operationPb.UserDetails, error) {
-	systemUser := &model.SystemUser{
-		Id: userId,
-	}
-	if err := s.DB.First(systemUser).Error; err != nil {
-		if errors.Is(err, gorm.ErrRecordNotFound) {
-			return nil, xerr.Custom("该用户不存在")
-		}
-		return nil, xerr.WithStack(err)
-	}
-
-	return &operationPb.UserDetails{
-		Code: http.StatusOK,
-		Msg:  "ok",
-		Data: systemUser.ToPb(),
-	}, nil
-}
-
 // GetSystemUserMenu 返回系统用户相关菜单权限
 func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUserMenuTreeResponse, error) {
 	// 解析token
@@ -407,7 +372,7 @@ func (s *StoreEntry) IsShowSystemRole(ctx context.Context, roleId int64) error {
 }
 
 // SearchSystemRoleList 查询系统角色
-func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.SearchRoleRequest) (*pasturePb.SearchRoleResponse, error) {
+func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.SearchRoleRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchRoleResponse, error) {
 	systemRoleList := make([]*model.SystemRole, 0)
 	var count int64 = 0
 
@@ -420,8 +385,8 @@ func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.Se
 		pref.Where("is_show = ?", req.IsShow)
 	}
 
-	if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).
-		Offset(int(req.Pagination.PageOffset)).Find(&systemRoleList).Error; err != nil {
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).Find(&systemRoleList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
@@ -429,9 +394,9 @@ func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *pasturePb.Se
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SearchRoleData{
-			Page:     req.Pagination.Page,
+			Page:     pagination.Page,
 			Total:    int32(count),
-			PageSize: req.Pagination.PageSize,
+			PageSize: pagination.PageSize,
 			List:     model.SystemRoleSlice(systemRoleList).ToPB(),
 		},
 	}, nil
@@ -530,7 +495,12 @@ func (s *StoreEntry) SystemRoleList(ctx context.Context) (*pasturePb.GetRoleList
 // CreateOrUpdateSystemMenu 添加或者更新系统菜单权限
 func (s *StoreEntry) CreateOrUpdateSystemMenu(ctx context.Context, req *pasturePb.SearchMenuRequest) error {
 	if req.Id > 0 {
-
+		systemMenu := &model.SystemMenu{Id: int64(req.Id)}
+		if err := s.DB.Model(&model.SystemMenu{}).First(systemMenu).Error; err != nil {
+			if !errors.Is(err, gorm.ErrRecordNotFound) {
+				return xerr.WithStack(err)
+			}
+		}
 	}
 
 	if err := s.DB.Model(&model.SystemMenu{}).Where(map[string]interface{}{
@@ -578,11 +548,14 @@ func (s *StoreEntry) SystemMenuTree(ctx context.Context) (*pasturePb.SystemMenuT
 }
 
 // SearchSystemMenuList 菜单列表查询
-func (s *StoreEntry) SearchSystemMenuList(ctx context.Context, req *pasturePb.SearchMenuRequest) (*pasturePb.SearchMenuResponse, error) {
+func (s *StoreEntry) SearchSystemMenuList(ctx context.Context, req *pasturePb.SearchMenuRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchMenuResponse, error) {
 	systemMenuList := make([]*model.SystemMenu, 0)
 	var count int64 = 0
 
-	if err := s.DB.Model(new(model.SystemMenu)).Where("is_delete = ? ", operationPb.IsShow_OK).Order("parent_id").Count(&count).Find(&systemMenuList).Error; err != nil {
+	if err := s.DB.Model(new(model.SystemMenu)).
+		Where("is_delete = ? ", operationPb.IsShow_OK).
+		Order("parent_id").Count(&count).
+		Find(&systemMenuList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
@@ -590,9 +563,9 @@ func (s *StoreEntry) SearchSystemMenuList(ctx context.Context, req *pasturePb.Se
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SearchMenuData{
-			Page:     req.Pagination.Page,
+			Page:     pagination.Page,
 			Total:    int32(count),
-			PageSize: req.Pagination.PageSize,
+			PageSize: pagination.PageSize,
 			List:     model.SystemMenuSlice(systemMenuList).ToPB(),
 		},
 	}, nil
@@ -614,7 +587,7 @@ func (s *StoreEntry) DeleteSystemMenu(ctx context.Context, menuId int64) error {
 	return nil
 }
 
-func (s *StoreEntry) SearchSystemDeptList(ctx context.Context, req *pasturePb.SearchDeptRequest) (*pasturePb.SearchDeptResponse, error) {
+func (s *StoreEntry) SearchSystemDeptList(ctx context.Context, req *pasturePb.SearchDeptRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchDeptResponse, error) {
 	deptList := make([]*model.SystemDept, 0)
 	var count int64 = 0
 	pref := s.DB.Model(new(model.SystemDept)).Where("is_delete = ?", operationPb.IsShow_OK)
@@ -626,7 +599,7 @@ func (s *StoreEntry) SearchSystemDeptList(ctx context.Context, req *pasturePb.Se
 		pref.Where("is_show = ?", req.IsShow)
 	}
 
-	if err := pref.Order("sort desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
+	if err := pref.Order("sort desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
 		Find(&deptList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}