Browse Source

event: 转群事件

Yi 10 months ago
parent
commit
d4128bf5ac

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240430082601-9300922bef83
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240508080006-64977b5c321d
 	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

+ 14 - 38
go.sum

@@ -36,44 +36,20 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
 cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
 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/go_proto v0.0.0-20240428015639-7a6e0cd54b97 h1:J7A5DbtzqOJ77FlRXMDsHfWYQtFpllNIfSMsKaSPKHs=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240428015639-7a6e0cd54b97/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240428053026-cef7ffa85f63 h1:IwGT4Tfgj67D+7M+vYluYug8nSQ9Gl505cJvxDBl9Fo=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240428053026-cef7ffa85f63/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240429093353-bbb01da08b4e h1:d2iUF//PtvMnqV40NR1Wfh4qqrxexSnmAlKV9QR2kho=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240429093353-bbb01da08b4e/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240429093656-ddd0948ba705 h1:FURTtdTQjJnDc9SOA2bFgwH7f+gMWovVVHFb6SF3E5k=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240429093656-ddd0948ba705/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240430072830-f136f793f6b1 h1:cR+0spDUIeSDjB9Mdm6ThAJsBmMFZN40EYP08nrK93I=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240430072830-f136f793f6b1/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240430082601-9300922bef83 h1:CgxdEzvMp/OlWUsuGUGcYJjNqYSBFk79xJFf3MipJ7c=
-gitee.com/xuyiping_admin/go_proto v0.0.0-20240430082601-9300922bef83/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240506084300-6d0267e74122 h1:vqc20q4RvQ3ommNWGRN1h+61phXEllZdSwQIyrz8Mzg=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240506084300-6d0267e74122/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240506090538-9d6beda359cb h1:XZr1IuVNq6q9/KaoN/RiYHuy66BtJJ8cbOpeH8YXV2E=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240506090538-9d6beda359cb/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508060326-e5f376dcfe85 h1:nuD30H9Y2R8oSteyeOLSs+PjMhKMM+CdEMuoS5liFC8=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508060326-e5f376dcfe85/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508062143-1087f5b5588f h1:NTSDl7nwFGWfZVuqSpH40IlLfkfboTTHvNhxhZ4ztfc=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508062143-1087f5b5588f/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508064026-1bdb0320dc5f h1:O5d+gv6uqCmSTsSPAX0EStWP1QdXTEVxQCXhphxJ0ik=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508064026-1bdb0320dc5f/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508070519-7040a3cce5cb h1:9pcF+F4SY9WwnyHW1MRcegJQ3Q63Z5D8idE1KVq/1Bc=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508070519-7040a3cce5cb/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508080006-64977b5c321d h1:4mvRqpIybdhodr8Idd/brpBl65U7EXBWPhFstH3nM2I=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240508080006-64977b5c321d/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

@@ -2,6 +2,9 @@ package config
 
 import (
 	"kpt-pasture/http/middleware"
+	"strconv"
+
+	"gitee.com/xuyiping_admin/pkg/valid"
 
 	"gitee.com/xuyiping_admin/pkg/apierr"
 	"gitee.com/xuyiping_admin/pkg/ginutil"
@@ -79,3 +82,18 @@ func CowTransferPenReasonOptions(c *gin.Context) {
 	}
 	ginutil.JSONResp(c, res)
 }
+
+func SystemUserOptions(c *gin.Context) {
+	depIdStr := c.Query("dept_id")
+	depId, _ := strconv.Atoi(depIdStr)
+	if err := valid.Validate(depId, valid.Required, valid.Min(-1)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.SystemUserOptions(c, depId)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}

+ 56 - 1
http/handler/event/event.go

@@ -14,7 +14,7 @@ import (
 )
 
 func EnterEventList(c *gin.Context) {
-	var req pasturePb.SearchEnterEventRequest
+	var req pasturePb.SearchEventRequest
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -66,3 +66,58 @@ func EnterEventCreate(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
+
+func GroupTransferEventList(c *gin.Context) {
+	var req pasturePb.SearchEventRequest
+	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.GroupTransferList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}
+
+func GroupTransferEventCreate(c *gin.Context) {
+	var req pasturePb.TransferGroupEventRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.Body, valid.Required, valid.Each(valid.By(func(value interface{}) error {
+			s := value.(pasturePb.TransferGroupEventData)
+			return valid.ValidateStruct(&s,
+				valid.Field(&s.CowId, valid.Required),
+				valid.Field(&s.TransferDate, valid.Required),
+				valid.Field(&s.TransferInPenId, valid.Required),
+				valid.Field(&s.TransferReasonId, valid.Required),
+				valid.Field(&s.StaffMemberId, valid.Required),
+			)
+		}))),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.CreateGroupTransfer(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 1 - 0
http/route/config_api.go

@@ -21,5 +21,6 @@ func ConfigAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		pastureRoute.GET("/cow/status/options", config.CowStatusOptions)
 		pastureRoute.GET("/cow/type/options", config.CowTypeOptions)
 		pastureRoute.GET("/cow/transfer/pen/reason/options", config.CowTransferPenReasonOptions)
+		pastureRoute.GET("/system/user/options", config.SystemUserOptions)
 	}
 }

+ 7 - 4
http/route/event_api.go

@@ -11,9 +11,12 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		for _, opt := range opts {
 			opt(s)
 		}
-		// pasture API 组  牧场管理
-		pastureRoute := authRouteGroup(s, "/api/v1/event/")
-		pastureRoute.POST("/enter/list", event.EnterEventList)
-		pastureRoute.POST("/enter/create", event.EnterEventCreate)
+		// eventRoute API 组  事件管理
+		eventRoute := authRouteGroup(s, "/api/v1/event/")
+		eventRoute.POST("/enter/list", event.EnterEventList)
+		eventRoute.POST("/enter/create", event.EnterEventCreate)
+
+		eventRoute.POST("/group/transfer/list", event.GroupTransferEventList)
+		eventRoute.POST("/group/transfer/create", event.GroupTransferEventCreate)
 	}
 }

+ 20 - 0
model/event_transfer_group.go

@@ -0,0 +1,20 @@
+package model
+
+type EventTransferGroup struct {
+	Id               int64  `json:"id"`
+	CowId            int64  `json:"cow_id"`
+	TransferInPenId  int64  `json:"transfer_in_pen_id"`
+	TransferOutPenId int64  `json:"transfer_out_pen_id"`
+	Lact             int32  `json:"lact"`
+	TransferDate     string `json:"transfer_date"`
+	TransferReasonId int64  `json:"transfer_reason_id"`
+	Remarks          string `json:"remarks"`
+	StaffMemberId    int64  `json:"staff_member_id"`
+	OperationId      int64  `json:"operation_id"`
+	CreatedAt        int64  `json:"created_at"`
+	UpdatedAt        int64  `json:"updated_at"`
+}
+
+func (e *EventTransferGroup) TableName() string {
+	return "event_transfer_group"
+}

+ 12 - 0
model/system_user.go

@@ -99,3 +99,15 @@ func (s *SystemUser) ToPb() *operationPb.AddSystemUser {
 		RoleIds:         []int32{},
 	}
 }
+
+func (c SystemUserSlice) ToPB2() []*pasturePb.ConfigOptionsList {
+	res := make([]*pasturePb.ConfigOptionsList, len(c))
+	for i, d := range c {
+		res[i] = &pasturePb.ConfigOptionsList{
+			Value:    int32(d.Id),
+			Label:    d.Name,
+			Disabled: true,
+		}
+	}
+	return res
+}

+ 16 - 0
module/backend/config_data.go

@@ -110,3 +110,19 @@ func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pastureP
 		Data:    model.ConfigTransferPenReasonSlice(configTransferPenReasonList).ToPB2(),
 	}, nil
 }
+
+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())
+	if depId != -1 && depId > 0 {
+		pref = pref.Where("dep_id = ?", depId)
+	}
+	if err := pref.Find(&systemUserList).Error; err != nil {
+		return nil, xxerr.WithStack(err)
+	}
+	return &pasturePb.ConfigOptionsListResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data:    model.SystemUserSlice(systemUserList).ToPB2(),
+	}, nil
+}

+ 105 - 4
module/backend/event.go

@@ -6,17 +6,19 @@ import (
 	"kpt-pasture/model"
 	"net/http"
 
-	"gorm.io/gorm"
-
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	"gitee.com/xuyiping_admin/pkg/xerr"
+	"gorm.io/gorm"
 )
 
-func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEnterEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error) {
+func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error) {
 	eventEnterList := make([]*pasturePb.SearchEnterData, 0)
 	var count int64 = 0
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventEnter).TableName())).
-		Select("a.id,a.birth_at,a.weaning_at,a.dry_milk_at,a.cow_source_id,a.remarks,a.mating_at,a.status,a.lact,a.breed_status_id,a.mother_id,a.cow_kind_id,a.cow_id,b.name as breed_status_name,c.name as cow_source_name,d.name as cow_type_name,e.name as cow_kind_name,f.name as pen_name,g.name as operation_name").
+		Select(`a.id,a.birth_at,a.weaning_at,a.dry_milk_at,a.cow_source_id,a.remarks,a.mating_at,a.status,
+			a.lact,a.breed_status_id,a.mother_id,a.cow_kind_id,a.cow_id,a.ear_number,a.sex,a.created_at,
+			a.weight / 100 as weight,a.price / 100 as price,b.name as breed_status_name,
+			c.name as cow_source_name,d.name as cow_type_name,e.name as cow_kind_name,f.name as pen_name,g.name as operation_name`).
 		Joins(fmt.Sprintf("JOIN %s AS b ON a.breed_status_id = b.id", new(model.ConfigBreedStatus).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS c on a.cow_source_id = c.id", new(model.ConfigCowSource).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS d on a.cow_type_id = d.id", new(model.ConfigCowType).TableName())).
@@ -64,3 +66,102 @@ func (s *StoreEntry) CreateEnter(ctx context.Context, req *pasturePb.SearchEnter
 	}
 	return nil
 }
+
+func (s *StoreEntry) GroupTransferList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchTransferGroupEventResponse, error) {
+	eventGroupTransferList := make([]*pasturePb.SearchTransferGroupData, 0)
+	var count int64 = 0
+	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventTransferGroup).TableName())).
+		Select(`a.id,a.cow_id,a.transfer_in_pen_id,a.transfer_out_pen_id,a.lact,a.remarks,a.transfer_reason_id,
+			a.transfer_date,a.created_at,a.staff_member_id,b.name as transfer_in_pen_name,c.name as transfer_out_pen_name,
+			d.name as transfer_reason_name,e.name as staff_member_name,f.lact,f.ear_number`).
+		Joins(fmt.Sprintf("JOIN %s AS b ON a.transfer_in_pen_id = b.id", new(model.Pen).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS c on a.transfer_out_pen_id = c.id", new(model.Pen).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS d on a.transfer_reason_id = d.id", new(model.ConfigTransferPenReason).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS e ON a.staff_member_id = e.id", new(model.SystemUser).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS f ON a.cow_id = b.id", new(model.Cow).TableName()))
+	if req.CowId > 0 {
+		pref.Where("a.cow_id = ?", req.CowId)
+	}
+
+	if err := pref.Order("a.id desc").Group("a.id").
+		Count(&count).Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Find(&eventGroupTransferList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.SearchTransferGroupEventResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchTransferGroupEventData{
+			List:     eventGroupTransferList,
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
+func (s *StoreEntry) CreateGroupTransfer(ctx context.Context, req *pasturePb.TransferGroupEventRequest) error {
+	system, _ := s.GetCurrentSystemUser(ctx)
+	res := make([]*model.EventTransferGroup, 0)
+	for _, v := range req.Body {
+		cow, err := s.GetCowInfo(ctx, int64(v.CowId))
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+		// 转去栏舍和当前栏舍相同,则不处理
+		if cow.PenId == int64(v.TransferInPenId) {
+			continue
+		}
+		pen, err := s.GetPenInfo(ctx, int64(v.TransferInPenId))
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+
+		transferReasonData, err := s.GetTransferReasonInfo(ctx, int64(v.TransferReasonId))
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+
+		staffMemberData, err := s.GetSystemUserInfo(ctx, int64(v.StaffMemberId))
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+
+		res = append(res, &model.EventTransferGroup{
+			CowId:            int64(v.CowId),
+			TransferInPenId:  int64(v.TransferInPenId),
+			TransferOutPenId: pen.Id,
+			Lact:             cow.Lact,
+			TransferDate:     v.TransferDate,
+			TransferReasonId: transferReasonData.Id,
+			Remarks:          v.Remarks,
+			StaffMemberId:    staffMemberData.Id,
+			OperationId:      system.Id,
+		})
+	}
+	if len(res) <= 0 {
+		return nil
+	}
+
+	if err := s.DB.Transaction(func(tx *gorm.DB) error {
+		if err := tx.Create(res).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		for _, v := range res {
+			cow, err := s.GetCowInfo(ctx, v.CowId)
+			if err != nil {
+				return xerr.WithStack(err)
+			}
+			if err = s.DB.Model(cow).Update("pen_id", v.TransferInPenId).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return nil
+}

+ 5 - 2
module/backend/interface.go

@@ -8,7 +8,6 @@ import (
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	"gitee.com/xuyiping_admin/pkg/di"
-
 	"go.uber.org/dig"
 )
 
@@ -116,10 +115,14 @@ type ConfigDataService interface {
 	CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
+	SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error)
 }
 
 //go:generate mockgen -destination mock/EventService.go -package kptservicemock kpt-pasture/module/backend EventService
 type EventService interface {
-	EnterList(ctx context.Context, req *pasturePb.SearchEnterEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error)
+	EnterList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error)
 	CreateEnter(ctx context.Context, req *pasturePb.SearchEnterData) error
+
+	GroupTransferList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchTransferGroupEventResponse, error)
+	CreateGroupTransfer(ctx context.Context, req *pasturePb.TransferGroupEventRequest) error
 }

+ 94 - 0
module/backend/sql.go

@@ -0,0 +1,94 @@
+package backend
+
+import (
+	"context"
+	"errors"
+	"kpt-pasture/model"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"gorm.io/gorm"
+)
+
+// GetCurrentUserName 获取当前用户名
+func (s *StoreEntry) GetCurrentUserName(ctx context.Context) (string, error) {
+	userNameInter := ctx.Value(CurrentUserName)
+	if userNameInter == nil {
+		return "", xerr.Customf("cannot userName")
+	}
+
+	if userName, ok := userNameInter.(string); ok {
+		return userName, nil
+	} else {
+		return "", xerr.Customf("waring userName")
+	}
+}
+
+func (s *StoreEntry) GetCurrentSystemUser(ctx context.Context) (*model.SystemUser, error) {
+	// 解析token
+	userName, err := s.GetCurrentUserName(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	// 根据用户token获取用户数据
+	systemUser := &model.SystemUser{Name: userName}
+	if err = s.DB.Where("name = ?", userName).
+		Where("is_show = ? and is_delete = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
+		First(systemUser).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return nil, xerr.Custom("该用户数据不存在")
+		}
+		return nil, xerr.WithStack(err)
+	}
+	return systemUser, nil
+}
+
+func (s *StoreEntry) GetSystemUserInfo(ctx context.Context, userId int64) (*model.SystemUser, 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 systemUser, nil
+}
+
+func (s *StoreEntry) GetPenInfo(ctx context.Context, penId int64) (*model.Pen, error) {
+	penData := &model.Pen{
+		Id: penId,
+	}
+	if err := s.DB.First(penData).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return nil, xerr.Custom("该数据不存在")
+		}
+		return nil, xerr.WithStack(err)
+	}
+	return penData, nil
+}
+
+func (s *StoreEntry) GetCowInfo(ctx context.Context, cowId int64) (*model.Cow, error) {
+	cowData := &model.Cow{Id: cowId}
+	if err := s.DB.First(cowData).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return nil, xerr.Custom("该数据不存在")
+		}
+		return nil, xerr.WithStack(err)
+	}
+	return cowData, nil
+}
+
+func (s *StoreEntry) GetTransferReasonInfo(ctx context.Context, reasonId int64) (*model.ConfigTransferPenReason, error) {
+	configTransferPenReasonData := &model.ConfigTransferPenReason{
+		Id: reasonId,
+	}
+	if err := s.DB.First(configTransferPenReasonData).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return nil, xerr.Custom("该数据不存在")
+		}
+		return nil, xerr.WithStack(err)
+	}
+	return configTransferPenReasonData, nil
+}

+ 0 - 46
module/backend/system_service.go

@@ -69,19 +69,6 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
 	}, nil
 }
 
-func (s *StoreEntry) GetSystemUserInfo(ctx context.Context, userId int64) (*model.SystemUser, 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 systemUser, nil
-}
-
 // SearchSystemUserList 查询系统用户
 func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchUserResponse, error) {
 	systemUserList := make([]*model.SystemUser, 0)
@@ -264,39 +251,6 @@ func (s *StoreEntry) SystemUserRoleSave(ctx context.Context, req *pasturePb.Syst
 	return nil
 }
 
-// GetCurrentUserName 获取当前用户名
-func (s *StoreEntry) GetCurrentUserName(ctx context.Context) (string, error) {
-	userNameInter := ctx.Value(CurrentUserName)
-	if userNameInter == nil {
-		return "", xerr.Customf("cannot userName")
-	}
-
-	if userName, ok := userNameInter.(string); ok {
-		return userName, nil
-	} else {
-		return "", xerr.Customf("waring userName")
-	}
-}
-
-func (s *StoreEntry) GetCurrentSystemUser(ctx context.Context) (*model.SystemUser, error) {
-	// 解析token
-	userName, err := s.GetCurrentUserName(ctx)
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
-	// 根据用户token获取用户数据
-	systemUser := &model.SystemUser{Name: userName}
-	if err = s.DB.Where("name = ?", userName).
-		Where("is_show = ? and is_delete = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
-		First(systemUser).Error; err != nil {
-		if errors.Is(err, gorm.ErrRecordNotFound) {
-			return nil, xerr.Custom("该用户数据不存在")
-		}
-		return nil, xerr.WithStack(err)
-	}
-	return systemUser, nil
-}
-
 // GetSystemUserMenu 返回系统用户相关菜单权限
 func (s *StoreEntry) GetSystemUserMenu(ctx context.Context) (*pasturePb.SystemUserMenuTreeResponse, error) {
 	// 解析token