Browse Source

event: add log

ping 5 days ago
parent
commit
1f37ae53c0

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250324091419-f7fa3ad96c0e
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250324120913-88e4f53314db
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 2 - 0
go.sum

@@ -80,6 +80,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250324084120-e6352deeb1c5 h1:lSms9Fs2
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250324084120-e6352deeb1c5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250324091419-f7fa3ad96c0e h1:Dv1OgQfYuzw6+O1FBaSg86CiAOiGPnUIWV2FeWoPYdM=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250324091419-f7fa3ad96c0e/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250324120913-88e4f53314db h1:QLLT24YPsIii/vCJYawzA2t5uwpoYb77y83WOqvlwtY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250324120913-88e4f53314db/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b h1:w05MxH7yqveRlaRbxHhbif5YjPrJFodRPfOjYhXn7Zk=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 1 - 1
http/route/event_api.go

@@ -75,6 +75,6 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		// 禁配
 		eventRoute.POST("/forbidden/mating/batch", event.ForbiddenMatingBatch)
 		eventRoute.POST("/forbidden/mating/list", event.ForbiddenMatingList)
-		eventRoute.POST("/un_forbidden/mating", event.UnForbiddenMating)
+		eventRoute.POST("/un_forbidden/mating/batch", event.UnForbiddenMating)
 	}
 }

+ 5 - 1
model/event_forbidden_mating.go

@@ -15,6 +15,8 @@ type EventForbiddenMating struct {
 	UnForbiddenMatingAt        int64                                 `json:"unForbiddenMatingAt"`
 	OperationId                int64                                 `json:"operationId"`
 	OperationName              string                                `json:"operationName"`
+	UnForbiddenOperationId     int64                                 `json:"unForbiddenOperationId"`
+	UnForbiddenOperationName   string                                `json:"unForbiddenOperationName"`
 	Remarks                    string                                `json:"remarks"`
 	IsShow                     pasturePb.IsShow_Kind                 `json:"isShow"`
 	MessageId                  int64                                 `json:"messageId"`
@@ -27,9 +29,11 @@ func (e *EventForbiddenMating) TableName() string {
 	return "event_forbidden_mating"
 }
 
-func (e *EventForbiddenMating) UnForbiddenMatingUpdate(unForbiddenMatingAt int64) {
+func (e *EventForbiddenMating) UnForbiddenMatingUpdate(unForbiddenMatingAt int64, currentUser *SystemUser) {
 	e.UnForbiddenMatingAt = unForbiddenMatingAt
 	e.IsShow = pasturePb.IsShow_No
+	e.UnForbiddenOperationId = currentUser.Id
+	e.UnForbiddenOperationName = currentUser.Name
 }
 
 func NewEventForbiddenMating(pastureId int64, cow *Cow, forbiddenMatingAt int64, forbiddenMatingReasonsKind pasturePb.ForbiddenMatingReasons_Kind,

+ 8 - 0
module/backend/config_data_other.go

@@ -532,6 +532,14 @@ func (s *StoreEntry) EventTypeEnumList(isAll string) []*pasturePb.ConfigOptionsL
 		Value:    int32(pasturePb.EventType_Disease),
 		Label:    "疾病",
 		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.EventType_ForbiddenMating),
+		Label:    "禁配",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.EventType_UnForbiddenMating),
+		Label:    "解禁",
+		Disabled: true,
 	})
 	return configOptions
 }

+ 5 - 1
module/backend/event_breed_more_two.go

@@ -262,7 +262,7 @@ func (s *StoreEntry) UnForbiddenMating(ctx context.Context, req *pasturePb.Event
 			}
 
 			// 事件更新
-			item.UnForbiddenMatingUpdate(nowTime)
+			item.UnForbiddenMatingUpdate(nowTime, userModel.SystemUser)
 			if err = tx.Model(new(model.EventForbiddenMating)).
 				Select("is_show", "un_forbidden_mating_at").
 				Where("id = ?", item.Id).
@@ -270,6 +270,10 @@ func (s *StoreEntry) UnForbiddenMating(ctx context.Context, req *pasturePb.Event
 				return xerr.WithStack(err)
 			}
 
+			cowLog := s.SubmitEventLog(ctx, userModel.AppPasture.Id, cowInfo, pasturePb.EventType_UnForbiddenMating, item)
+			if err = tx.Model(new(model.EventCowLog)).Create(cowLog).Error; err != nil {
+				return xerr.WithStack(err)
+			}
 		}
 		return nil
 	}); err != nil {

+ 7 - 0
module/backend/event_cow_log.go

@@ -7,6 +7,7 @@ import (
 	"kpt-pasture/util"
 	"strconv"
 	"strings"
+	"time"
 
 	"gitee.com/xuyiping_admin/pkg/xerr"
 
@@ -193,6 +194,12 @@ func (s *StoreEntry) SubmitEventLog(ctx context.Context, pastureId int64, cow *m
 		operationUser.Name = data.OperationUser.Name
 		remarks = data.Remarks
 		desc = fmt.Sprintf("禁配原因: %s", data.ForbiddenMatingReasonsName)
+	case pasturePb.EventType_UnForbiddenMating:
+		data := req.(*model.EventForbiddenMating)
+		eventAt = data.UnForbiddenMatingAt
+		operationUser.Id = data.UnForbiddenOperationId
+		operationUser.Name = data.UnForbiddenOperationName
+		desc = fmt.Sprintf("解禁时间: %s", time.Unix(eventAt, 0).Format(model.LayoutDate2))
 	}
 	newEventCowLogModel := &model.EventCowLogModel{
 		Cow:               cow,