Prechádzať zdrojové kódy

sameTime: 同期批量处理

Yi 3 mesiacov pred
rodič
commit
87de5bd66b

+ 1 - 1
Dockerfile

@@ -6,7 +6,7 @@ COPY . .
 RUN mkdir -p ./bin
 
 RUN go env -w GO111MODULE=on && \
-    go env -w GOPROXY=https://goproxy.cn,direct && \
+    go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct && \
     go env -w CGO_ENABLED=0 && \
     go env -w GOARCH=amd64 && \
     go env -w GOOS=linux && \

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241122093434-2c4af4bddc59
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241127090200-9343aa730c3f
 	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

+ 6 - 0
go.sum

@@ -46,6 +46,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241122090558-77fd1cd65cb5 h1:XCxiDeGz
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241122090558-77fd1cd65cb5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241122093434-2c4af4bddc59 h1:TxIsS8RgDS3hjM5YjdAvbwzYjD4Wr8nYDuUtj72aVYs=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241122093434-2c4af4bddc59/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241127070814-25f6418ad0c6 h1:ZNPcgtm3q+chmuxmW5XQVPl5yD2E3D8ZzyZWgL7W8RQ=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241127070814-25f6418ad0c6/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241127084727-32ff0826e19a h1:JDS3rqbwK46fLevp0/lnU6iJxMLaeOs1GfZhV9HSxmI=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241127084727-32ff0826e19a/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241127090200-9343aa730c3f h1:iRYyVkDAbWJG56FUqvbuNkMgDU7v+fkCI2iuepaNxEw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241127090200-9343aa730c3f/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=

+ 37 - 2
http/handler/event/event_breed.go

@@ -235,8 +235,9 @@ func SameTimeCreate(c *gin.Context) {
 	}
 
 	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.SameTimeId, valid.Required),
-		valid.Field(&req.SameTimeType, valid.Required),
+		valid.Field(&req.Id, valid.Required),
+		valid.Field(&req.DrugsId, valid.Required),
+		valid.Field(&req.OperationId, valid.Required),
 		valid.Field(&req.SameTimeAt, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
@@ -255,6 +256,40 @@ func SameTimeCreate(c *gin.Context) {
 	})
 }
 
+func SameTimeBatch(c *gin.Context) {
+	var req pasturePb.EventSameTimeBatch
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.OperationId, valid.Required),
+		valid.Field(&req.DrugsId, valid.Required),
+		valid.Field(&req.SameTimeAt, valid.Required),
+		valid.Field(&req.Item, valid.Required, valid.Each(valid.By(func(value interface{}) error {
+			item := value.(pasturePb.EventSameTimeItem)
+			return valid.ValidateStruct(&item,
+				valid.Field(&item.CowId, valid.Required),
+			)
+		}))),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.SameTimeBatch(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}
+
 func SameTimeList(c *gin.Context) {
 	var req pasturePb.SearchEventRequest
 	if err := ginutil.BindProto(c, &req); err != nil {

+ 1 - 0
http/route/event_api.go

@@ -43,6 +43,7 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		// 同期
 		eventRoute.POST("/same/time/list", event.SameTimeList)
 		eventRoute.POST("/same/time/create", event.SameTimeCreate)
+		eventRoute.POST("/same/time/batch", event.SameTimeBatch)
 
 		// 流产
 		eventRoute.POST("/abortion/list", event.AbortionList)

+ 0 - 0
http/route/work_order.go → http/route/work.go


+ 57 - 33
model/event_cow_same_time.go

@@ -1,6 +1,8 @@
 package model
 
 import (
+	"time"
+
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
@@ -12,6 +14,7 @@ type EventCowSameTime struct {
 	PenName       string                      `json:"penName"`
 	Lact          int32                       `json:"lact"`
 	SameTimeId    int64                       `json:"sameTimeId"`
+	SameTimeName  string                      `json:"sameTimeName"`
 	SameTimeType  pasturePb.SameTimeType_Kind `json:"sameTimeType"`
 	PlanDay       int64                       `json:"planDay"`
 	EndDay        int64                       `json:"endDay"`
@@ -30,13 +33,14 @@ func (s *EventCowSameTime) TableName() string {
 	return "event_cow_same_time"
 }
 
-func NewEventCowSameTime(cow *Cow, planTime int64, sameTimeId int64, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {
+func NewEventCowSameTime(cow *Cow, planTime int64, sameTime *SameTime, sameTimeType pasturePb.SameTimeType_Kind) *EventCowSameTime {
 	return &EventCowSameTime{
 		CowId:        cow.Id,
 		Lact:         cow.Lact,
 		CowType:      cow.CowType,
 		PenId:        cow.PenId,
-		SameTimeId:   sameTimeId,
+		SameTimeId:   sameTime.Id,
+		SameTimeName: sameTime.Name,
 		SameTimeType: sameTimeType,
 		Status:       pasturePb.IsShow_No,
 		PlanDay:      planTime,
@@ -44,54 +48,74 @@ func NewEventCowSameTime(cow *Cow, planTime int64, sameTimeId int64, sameTimeTyp
 	}
 }
 
-func NewEventCowSameTimeList(cowList []*Cow, sameTimeId int64, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {
+func NewEventCowSameTimeList(cowList []*Cow, sameTime *SameTime, planTime int64, sameTimeType pasturePb.SameTimeType_Kind) []*EventCowSameTime {
 	res := make([]*EventCowSameTime, len(cowList))
 	for i, cow := range cowList {
-		res[i] = NewEventCowSameTime(cow, planTime, sameTimeId, sameTimeType)
+		res[i] = NewEventCowSameTime(cow, planTime, sameTime, sameTimeType)
 	}
 	return res
 }
 
-type SameTimeBody struct {
-	Id              int64                      `json:"id"`
-	CowId           int64                      `json:"cowId"`
-	BreedStatus     pasturePb.BreedStatus_Kind `json:"breedStatus"`
-	BreedStatusName string                     `json:"breedStatusName"`
-	CowType         pasturePb.CowType_Kind     `json:"cowType"`
-	CowTypeName     string                     `json:"cowTypeName"`
-	PenId           int32                      `json:"penId"`
-	PenName         string                     `json:"penName"`
-	Lact            int32                      `json:"lact"`
-	CalvingAge      int32                      `json:"calvingAge"`
-	AbortionAge     int32                      `json:"abortionAge"`
-	DayAge          int32                      `json:"dayAge"`
-	Status          pasturePb.IsShow_Kind      `json:"status"`
+type SameTimeItemBody struct {
+	Id              int64                       `json:"id"`
+	CowId           int64                       `json:"cowId"`
+	BreedStatus     pasturePb.BreedStatus_Kind  `json:"breedStatus"`
+	BreedStatusName string                      `json:"breedStatusName"`
+	CowType         pasturePb.CowType_Kind      `json:"cowType"`
+	CowTypeName     string                      `json:"cowTypeName"`
+	PenId           int32                       `json:"penId"`
+	PenName         string                      `json:"penName"`
+	Lact            int32                       `json:"lact"`
+	CalvingAge      int32                       `json:"calvingAge"`
+	AbortionAge     int32                       `json:"abortionAge"`
+	DayAge          int32                       `json:"dayAge"`
+	Status          pasturePb.IsShow_Kind       `json:"status"`
+	SameTimeType    pasturePb.SameTimeType_Kind `json:"sameTimeType"`
+	LastCalvingAt   int64                       `json:"lastCalvingAt"`
+	LastAbortionAt  int64                       `json:"lastAbortionAt"`
+	MatingTimes     int32                       `json:"matingTimes"`
+	SameTimeName    string                      `json:"sameTimeName"`
 }
 
-type SameTimeBodySlice []*SameTimeBody
+type SameTimeBodySlice []*SameTimeItemBody
 
 func (s SameTimeBodySlice) ToPB(
 	breedStatusMap map[pasturePb.BreedStatus_Kind]string,
 	penMap map[int32]*Pen,
+	sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string,
 ) []*pasturePb.SameTimeItems {
 	res := make([]*pasturePb.SameTimeItems, len(s))
 	for i, v := range s {
-		penName := ""
+		penName, calvingAtFormat, abortionAtFormat := "", "", ""
 		if pen, ok := penMap[v.PenId]; ok {
 			penName = pen.Name
 		}
+
+		if v.LastCalvingAt > 0 {
+			calvingAtFormat = time.Unix(v.LastCalvingAt, 0).Format(LayoutDate2)
+		}
+
+		if v.LastAbortionAt > 0 {
+			abortionAtFormat = time.Unix(v.LastAbortionAt, 0).Format(LayoutDate2)
+		}
+
 		res[i] = &pasturePb.SameTimeItems{
-			Id:              int32(v.Id),
-			CowId:           int32(v.CowId),
-			BreedStatus:     v.BreedStatus,
-			BreedStatusName: breedStatusMap[v.BreedStatus],
-			PenName:         penName,
-			PenId:           v.PenId,
-			Lact:            v.Lact,
-			CalvingAge:      v.CalvingAge,
-			AbortionAge:     v.AbortionAge,
-			DayAge:          v.DayAge,
-			Status:          v.Status,
+			Id:               int32(v.Id),
+			CowId:            int32(v.CowId),
+			BreedStatus:      v.BreedStatus,
+			BreedStatusName:  breedStatusMap[v.BreedStatus],
+			PenName:          penName,
+			PenId:            v.PenId,
+			Lact:             v.Lact,
+			CalvingAge:       v.CalvingAge,
+			AbortionAge:      v.AbortionAge,
+			DayAge:           v.DayAge,
+			Status:           v.Status,
+			SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
+			CalvingAtFormat:  calvingAtFormat,
+			AbortionAtFormat: abortionAtFormat,
+			MatingTimes:      v.MatingTimes,
+			SameTimeName:     v.SameTimeName,
 		}
 	}
 	return res
@@ -99,7 +123,7 @@ func (s SameTimeBodySlice) ToPB(
 
 type EventCowSameTimeSlice []*EventCowSameTime
 
-func (s EventCowSameTimeSlice) ToPB() []*pasturePb.EventSameTime {
+func (s EventCowSameTimeSlice) ToPB(sameTimeTypeMap map[pasturePb.SameTimeType_Kind]string) []*pasturePb.EventSameTime {
 	res := make([]*pasturePb.EventSameTime, len(s))
 	for i, v := range s {
 		res[i] = &pasturePb.EventSameTime{
@@ -110,7 +134,7 @@ func (s EventCowSameTimeSlice) ToPB() []*pasturePb.EventSameTime {
 			Lact:             v.Lact,
 			SameTimeId:       int32(v.SameTimeId),
 			SameTimeType:     v.SameTimeType,
-			SameTimeTypeName: "",
+			SameTimeTypeName: sameTimeTypeMap[v.SameTimeType],
 		}
 	}
 	return res

+ 19 - 13
module/backend/calendar.go

@@ -208,10 +208,10 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.Ite
 }
 
 func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SameTimeItemResponse, error) {
-	sameTimeBodyList := make([]*model.SameTimeBody, 0)
+	sameTimeBodyList := make([]*model.SameTimeItemBody, 0)
 	count := int64(0)
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCowSameTime).TableName())).
-		Select("a.id,a.cow_id,a.pen_name,a.status,b.breed_status,b.cow_type,b.day_age,b.calving_age,b.abortion_age").
+		Select("a.id,a.cow_id,a.pen_name,a.status,a.same_time_type,b.breed_status,a.same_time_name,b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at").
 		Joins("left join cow as b on a.cow_id = b.id").
 		Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
 		Where("a.status = ?", pasturePb.IsShow_No)
@@ -242,6 +242,7 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
 	}
 	breedStatusMap := s.CowBreedStatusMap()
 	penMap := s.PenMap(ctx)
+	sameTimeTypeMap := s.SameTimeTypeMap()
 	return &pasturePb.SameTimeItemResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
@@ -250,18 +251,23 @@ func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRe
 			Page:     pagination.Page,
 			PageSize: pagination.PageSize,
 			Header: map[string]string{
-				"id":              "编号",
-				"cowId":           "牛号",
-				"breedStatusName": "繁殖状态",
-				"cowTypeName":     "牛只类型",
-				"penName":         "栏舍",
-				"lact":            "胎次",
-				"calvingAge":      "产后天数",
-				"abortionAge":     "流产天数",
-				"dayAge":          "日龄",
-				"status":          "状态",
+				"id":               "编号",
+				"cowId":            "牛号",
+				"breedStatusName":  "繁殖状态",
+				"cowTypeName":      "牛只类型",
+				"penName":          "栏舍",
+				"lact":             "胎次",
+				"calvingAge":       "产后天数",
+				"abortionAge":      "流产天数",
+				"dayAge":           "日龄",
+				"status":           "状态",
+				"sameTimeTypeName": "处理方式",
+				"matingTimes":      "本胎次配次",
+				"calvingAtFormat":  "产犊日期",
+				"abortionAtFormat": "流产日期",
+				"sameTimeName":     "同情名称",
 			},
-			List: model.SameTimeBodySlice(sameTimeBodyList).ToPB(breedStatusMap, penMap),
+			List: model.SameTimeBodySlice(sameTimeBodyList).ToPB(breedStatusMap, penMap, sameTimeTypeMap),
 		},
 	}, nil
 }

+ 8 - 0
module/backend/enum_map.go

@@ -222,3 +222,11 @@ func (s *StoreEntry) AdmissionStatusMap() map[pasturePb.AdmissionStatus_Kind]str
 	}
 	return res
 }
+
+func (s *StoreEntry) SameTimeTypeMap() map[pasturePb.SameTimeType_Kind]string {
+	res := make(map[pasturePb.SameTimeType_Kind]string)
+	for _, v := range s.SameTimeTypeEnumList("") {
+		res[pasturePb.SameTimeType_Kind(v.Value)] = v.Label
+	}
+	return res
+}

+ 80 - 9
module/backend/event_breed.go

@@ -188,12 +188,20 @@ func (s *StoreEntry) EstrusCreate(ctx context.Context, req *pasturePb.EventEstru
 }
 
 func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) error {
-	if _, err := s.GetSameTimeById(ctx, int64(req.SameTimeId)); err != nil {
+	eventCowSameTime, err := s.GetEventCowSameTimeById(ctx, int64(req.Id))
+	if err != nil {
 		return xerr.WithStack(err)
 	}
 
+	if eventCowSameTime.Status == pasturePb.IsShow_Ok {
+		return xerr.Custom("该事件已处理")
+	}
+
+	if eventCowSameTime.CowId != int64(req.CowId) {
+		return xerr.Custom("牛只Id 不匹配")
+	}
+
 	drugs := &model.Drugs{}
-	var err error
 	if req.DrugsId > 0 {
 		if drugs, err = s.GetDrugsById(ctx, int64(req.DrugsId)); err != nil {
 			return xerr.WithStack(err)
@@ -206,16 +214,17 @@ func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSam
 
 	if err = s.DB.Transaction(func(tx *gorm.DB) error {
 		if err = tx.Model(new(model.CowSameTime)).
-			Where("cow_id = ?", req.CowId).
-			Where("same_time_id = ?", req.SameTimeId).
+			Where("cow_id = ?", eventCowSameTime.CowId).
+			Where("same_time_id = ?", eventCowSameTime.Id).
+			Where("same_time_status = ?", pasturePb.SameTimeStatus_No_Start).
 			Update("same_time_status", pasturePb.SameTimeStatus_In_Progress).Error; err != nil {
-			return xerr.WithStack(err)
+			zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
 		}
 
 		if err = tx.Model(new(model.EventCowSameTime)).
-			Where("cow_id = ?", req.CowId).
-			Where("same_time_id = ?", req.SameTimeId).
-			Where("same_time_type = ?", req.SameTimeType).
+			Where("id = ?", eventCowSameTime.Id).
+			Where("cow_id = ?", eventCowSameTime.CowId).
+			Where("status = ?", pasturePb.IsShow_No).
 			Updates(map[string]interface{}{
 				"status":         pasturePb.IsShow_Ok,
 				"drug_id":        drugs.Id,
@@ -227,7 +236,68 @@ func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSam
 			}).Error; err != nil {
 			return xerr.WithStack(err)
 		}
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}
+
+func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSameTimeBatch) error {
+	drugs := &model.Drugs{}
+	var err error
+	if req.DrugsId > 0 {
+		if drugs, err = s.GetDrugsById(ctx, int64(req.DrugsId)); err != nil {
+			return xerr.WithStack(err)
+		}
+	}
+	operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
+	if err != nil {
+		return xerr.WithStack(err)
+	}
+	eventCowSameTimeList := make([]*model.EventCowSameTime, 0)
+	for _, v := range req.Item {
+		eventCowSameTime, err := s.GetEventCowSameTimeById(ctx, int64(v.Id))
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+
+		if eventCowSameTime.Status == pasturePb.IsShow_Ok {
+			return xerr.Custom("该事件已处理")
+		}
 
+		if eventCowSameTime.CowId != int64(v.CowId) {
+			return xerr.Custom(" 牛只Id 不匹配")
+		}
+		eventCowSameTimeList = append(eventCowSameTimeList, eventCowSameTime)
+	}
+
+	if err = s.DB.Transaction(func(tx *gorm.DB) error {
+		for _, v := range eventCowSameTimeList {
+			if err = tx.Model(new(model.CowSameTime)).
+				Where("cow_id = ?", v.CowId).
+				Where("same_time_id = ?", v.Id).
+				Where("same_time_status = ?", pasturePb.SameTimeStatus_No_Start).
+				Update("same_time_status", pasturePb.SameTimeStatus_In_Progress).Error; err != nil {
+				zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
+			}
+
+			if err = tx.Model(new(model.EventCowSameTime)).
+				Where("id = ?", v.Id).
+				Where("cow_id = ?", v.CowId).
+				Where("status = ?", pasturePb.IsShow_No).
+				Updates(map[string]interface{}{
+					"status":         pasturePb.IsShow_Ok,
+					"drug_id":        drugs.Id,
+					"unit":           drugs.Unit,
+					"usage":          req.Usage,
+					"remarks":        req.Remarks,
+					"operation_id":   operationUser.Id,
+					"operation_name": operationUser.Name,
+				}).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
 		return nil
 	}); err != nil {
 		return xerr.WithStack(err)
@@ -255,11 +325,12 @@ func (s *StoreEntry) SameTimeList(
 		return nil, xerr.WithStack(err)
 	}
 
+	sameTimeTypeMap := s.SameTimeTypeMap()
 	return &pasturePb.SearchSameTimeResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SameTimeData{
-			List:     model.EventCowSameTimeSlice(cowSameTimeList).ToPB(),
+			List:     model.EventCowSameTimeSlice(cowSameTimeList).ToPB(sameTimeTypeMap),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,

+ 1 - 0
module/backend/interface.go

@@ -177,6 +177,7 @@ type EventService interface {
 	WeaningBatch(ctx context.Context, req *pasturePb.EventWeaningBatchRequest) error
 	// SameTimeCreate 同期
 	SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) error
+	SameTimeBatch(ctx context.Context, req *pasturePb.EventSameTimeBatch) error
 	SameTimeList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchSameTimeResponse, error)
 	// WeightList 称重
 	WeightList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchWeightEventResponse, error)

+ 5 - 4
module/backend/sql.go

@@ -230,12 +230,13 @@ func (s *StoreEntry) GetWorkOrderSubByWorkOrderId(ctx context.Context, workOrder
 	return workOrderSubList, nil
 }
 
-func (s *StoreEntry) GetSameTimeById(ctx context.Context, id int64) (*model.SameTime, error) {
-	sameTime := &model.SameTime{Id: id}
-	if err := s.DB.Model(new(model.SameTime)).Where("is_show = ?", pasturePb.IsShow_Ok).First(sameTime).Error; err != nil {
+func (s *StoreEntry) GetEventCowSameTimeById(ctx context.Context, id int64) (*model.EventCowSameTime, error) {
+	eventCowSameTime := &model.EventCowSameTime{Id: id}
+	if err := s.DB.Model(new(model.EventCowSameTime)).
+		First(eventCowSameTime).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
-	return sameTime, nil
+	return eventCowSameTime, nil
 }
 
 func (s *StoreEntry) SearchSystemDeptListByIds(ctx context.Context, ids []int64) ([]*model.SystemDept, error) {

+ 1 - 1
module/crontab/work_cron.go

@@ -62,7 +62,7 @@ func (e *Entry) GenerateCalendarBySameTimePlan(cowList []*model.Cow, sameTime *m
 				calendarType = pasturePb.CalendarType_RnGH
 			}
 			histCount = e.GetTowardSameTimeCowSum(sameTime.Id, collateNode.SameTimeType)
-			newEventCowSameTimeList := model.NewEventCowSameTimeList(newCowList, sameTime.Id, showDay.Unix(), collateNode.SameTimeType)
+			newEventCowSameTimeList := model.NewEventCowSameTimeList(newCowList, sameTime, showDay.Unix(), collateNode.SameTimeType)
 			newSameTimeCowDetailList = append(newSameTimeCowDetailList, newEventCowSameTimeList...)
 			newEventItemList = append(newEventItemList, model.NewEventItemList(newCowList, calendarType)...)
 		}