#6 v1.0

Хаасан
xuyiping 12-ийг xuyiping/develop-оос xuyiping/master руу нэгтгэхийг хүсэлт

+ 1 - 1
.drone.yml

@@ -9,7 +9,7 @@ steps:
   - name: clone
     image: alpine/git
     commands:
-      - git clone -b feature/event http://192.168.1.8:3000/xuyiping/kpt-pasture.git
+      - git clone -b ${DRONE_COMMIT_BRANCH} http://192.168.1.8:3000/xuyiping/kpt-pasture.git
       - cp -R kpt-pasture/* ./
   - name: build
     image: plugins/docker:20.14.2

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250731013344-bd687f491881
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250813060227-ac0a14292eb8
 	gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 6 - 0
go.sum

@@ -1329,6 +1329,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250730095437-35f6be63af97 h1:hOXg1Ot2
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250730095437-35f6be63af97/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250731013344-bd687f491881 h1:JCa0Y3NyPxe339VC3AnGu+eFyr2aXduuIypy8RXgwRw=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250731013344-bd687f491881/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250806065630-af563d4b2726 h1:Nw5SlOLC+TXc2oGVQRTTVsxpXe4XlHF16zl2E2LxLzk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250806065630-af563d4b2726/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250812064516-17d87a02cad2 h1:vnNX8F32UB9Tsx/aMFxf1QLeaA3Dtf4HOXWJEQ63OPo=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250812064516-17d87a02cad2/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250813060227-ac0a14292eb8 h1:MFeaHtBnwmLb9ljU90N1JpnHZPgXiHhlHGU3M3+5W7E=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250813060227-ac0a14292eb8/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0 h1:ZCOqEAnGm6+DTAhACigzWKbwMKtleb8/7OzP2xfHG7g=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 3 - 0
model/cow.go

@@ -157,6 +157,9 @@ func (c *Cow) EventHealthStatusUpdate(healthStatus pasturePb.HealthStatus_Kind)
 func (c *Cow) EventPenUpdate(pen *Pen) {
 	c.PenId = pen.Id
 	c.PenName = pen.Name
+	if pen.PenType == pasturePb.PenType_Reserve {
+		c.CowType = pasturePb.CowType_Reserve_Calf
+	}
 }
 
 // EventEarNumberUpdate 更新耳标号

+ 2 - 2
model/event_transfer_group.go

@@ -14,7 +14,7 @@ type EventTransferGroup struct {
 	PenOutId           int32  `json:"penOutId"`
 	DayAge             int32  `json:"dayAge"`
 	Lact               int32  `json:"lact"`
-	TransferDate       string `json:"transferDate"`
+	TransferDate       int64  `json:"transferDate"`
 	TransferReasonId   int64  `json:"transferReasonId"`
 	TransferReasonName string `json:"TransferReasonName"`
 	Remarks            string `json:"remarks"`
@@ -38,7 +38,7 @@ func NewEventTransferGroup(pastureId int64, cow *Cow, req *pasturePb.TransferGro
 		PenOutId:           cow.PenId,
 		Lact:               cow.Lact,
 		DayAge:             cow.GetEventDayAge(eventAt),
-		TransferDate:       req.TransferDate,
+		TransferDate:       eventAt,
 		TransferReasonId:   int64(req.TransferReasonId),
 		TransferReasonName: transferPenMap[req.TransferReasonId],
 		Remarks:            req.Remarks,

+ 1 - 1
module/backend/calendar_more.go

@@ -23,7 +23,7 @@ func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsReq
 	count := int64(0)
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCalving).TableName())).
 		Select(`a.id,a.cow_id,a.ear_number,a.status,b.breed_status,b.pen_id,ROUND(b.current_weight/1000,2) as current_weight,
-		DATE_FORMAT(FROM_UNIXTIME(last_mating_at), '%Y-%m-%d') AS mating_at_format,b.day_age,b.last_bull_number as bull_id,
+		DATE_FORMAT(FROM_UNIXTIME(last_mating_at), '%Y-%m-%d') AS mating_at_format,b.day_age,b.last_bull_number as bull_id,b.lact,
 		b.pen_name,DATEDIFF(NOW(),FROM_UNIXTIME(last_mating_at)) AS mating_age,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day`).
 		Joins("left join cow as b on a.cow_id = b.id").
 		Where("a.status = ?", pasturePb.IsShow_No).

+ 35 - 25
module/backend/config_data.go

@@ -64,31 +64,41 @@ func (s *StoreEntry) BreedStatusEnumList() []*pasturePb.ConfigOptionsList {
 
 func (s *StoreEntry) CowKindEnumList() []*pasturePb.ConfigOptionsList {
 	cowKindList := make([]*pasturePb.ConfigOptionsList, 0)
-	cowKindList = append(cowKindList, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowKind_XMTEN),
-		Label:    "西门塔尔牛",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowKind_AGSN),
-		Label:    "安格斯牛",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowKind_XNLN),
-		Label:    "夏洛莱牛",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowKind_LMZN),
-		Label:    "利木赞牛",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowKind_HFTN),
-		Label:    "海福特牛",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowKind_HN),
-		Label:    "和牛",
-		Disabled: true,
-	})
+	cowKindList = append(cowKindList,
+		&pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_JSN),
+			Label:    "娟姗牛",
+			Disabled: true,
+		},
+		&pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_XMTEN),
+			Label:    "西门塔尔牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_AGSN),
+			Label:    "安格斯牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_XNLN),
+			Label:    "夏洛莱牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_LMZN),
+			Label:    "利木赞牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_HFTN),
+			Label:    "海福特牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_HN),
+			Label:    "和牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowKind_HX),
+			Label:    "华西牛",
+			Disabled: true,
+		})
 	return cowKindList
 }
 

+ 1 - 1
module/backend/dashboard_more.go

@@ -198,7 +198,7 @@ func (s *StoreEntry) FocusIndicatorsList(ctx context.Context, dimension string)
 		if currValue > 0 && oldValue > 0 {
 			b := float64(0)
 			if oldValue > 0 {
-				b = (oldValue - currValue) / oldValue * 100
+				b = (currValue - oldValue) / oldValue * 100
 			}
 			omv := util.RoundToTwoDecimals(b)
 			if omv < 0 {

+ 14 - 6
module/backend/event_base.go

@@ -10,6 +10,9 @@ import (
 	"strings"
 	"time"
 
+	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
+	"go.uber.org/zap"
+
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	"gitee.com/xuyiping_admin/pkg/xerr"
 	"gorm.io/gorm"
@@ -264,12 +267,17 @@ func (s *StoreEntry) CreateGroupTransfer(ctx context.Context, req *pasturePb.Tra
 				return xerr.WithStack(err)
 			}
 
-			if err = s.DB.Model(cow).
-				Updates(map[string]interface{}{
-					"pen_id":   v.TransferInPenId,
-					"pen_name": penMap[v.TransferReasonId].Name,
-				}).Error; err != nil {
-				return xerr.WithStack(err)
+			penInfo, ok := penMap[v.TransferInPenId]
+			if !ok {
+				return xerr.Custom("转栏的栏舍不存在")
+			}
+
+			cow.EventPenUpdate(penInfo)
+			if err = s.DB.Model(new(model.Cow)).
+				Select("pen_id", "pen_name", "cow_type").
+				Where("id = ?", cow.Id).
+				Updates(cow).Error; err != nil {
+				zaplog.Error("CowDiseaseCreate", zap.Any("EventPenUpdate", err))
 			}
 
 			// 事件日志

+ 1 - 3
module/backend/event_cow_log.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"kpt-pasture/model"
-	"kpt-pasture/util"
 	"strconv"
 	"strings"
 	"time"
@@ -45,8 +44,7 @@ func (s *StoreEntry) SubmitEventLog(ctx context.Context, pastureId int64, cow *m
 			strconv.FormatFloat(float64(data.Price), 'f', 2, 64), sourceMap[cow.SourceKind])
 	case pasturePb.EventType_Transfer_Ben:
 		data := req.(*model.EventTransferGroup)
-		transferAt, _ := util.TimeParseLocal(model.LayoutTime, data.TransferDate)
-		eventAt = transferAt.Unix()
+		eventAt = data.TransferDate
 		remarks = data.Remarks
 		operationUser.Id = data.OperationId
 		operationUser.Name = data.OperationName

+ 1 - 1
module/backend/event_health.go

@@ -265,7 +265,7 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
 			if penData, ok := penMap[req.PenId]; ok {
 				cow.EventPenUpdate(penData)
 				if err = s.DB.Model(new(model.Cow)).
-					Select("pen_id", "pen_name").
+					Select("pen_id", "pen_name", "cow_type").
 					Where("id = ?", cow.Id).
 					Updates(cow).Error; err != nil {
 					zaplog.Error("CowDiseaseCreate", zap.Any("EventPenUpdate", err))

+ 1 - 0
module/crontab/neck_ring_health.go

@@ -107,6 +107,7 @@ func calculateNewScore(data *model.NeckRingHealth) int32 {
 	if data.IsImmunization == pasturePb.IsShow_Ok {
 		otherScore += 12
 	}
+
 	return data.Score + otherScore
 }