Browse Source

items: 新增产犊清单

Yi 4 months ago
parent
commit
5b8c977411

+ 1 - 1
config/app.develop.yaml

@@ -41,4 +41,4 @@ cron:
   same_time_plan: "0 15 1 * * ?"
   update_same_time: "0 20 1 * * ?"
   system_basic_crontab: "0 25 1 * * ?"
-  cow_pregnant: "0 00 15 * * ?"
+  cow_pregnant: "0 00 15 * * ?"

+ 3 - 3
dep/di_crontab.go

@@ -47,10 +47,10 @@ func EntryCrontab(dependency CrontabDependency) *cron.Crontab {
 		panic(err)
 	}
 
-	err = newCrontab.Bind("GenerateWorkOrder", cs.GenerateWorkOrder, dependency.CrontabHub.GenerateAsynqWorkOrder)
+	/*err = newCrontab.Bind("GenerateWorkOrder", cs.GenerateWorkOrder, dependency.CrontabHub.GenerateAsynqWorkOrder)
 	if err != nil {
 		panic(err)
-	}
+	}*/
 
 	err = newCrontab.Bind("ImmunizationPlan", cs.ImmunizationPlan, dependency.CrontabHub.ImmunizationPlan)
 	if err != nil {
@@ -72,7 +72,7 @@ func EntryCrontab(dependency CrontabDependency) *cron.Crontab {
 		panic(err)
 	}
 
-	err = newCrontab.Bind("CowPregnant", cs.CowPregnant, dependency.CrontabHub.SystemBasicCrontab)
+	err = newCrontab.Bind("CowPregnant", cs.CowPregnant, dependency.CrontabHub.CowPregnant)
 	if err != nil {
 		panic(err)
 	}

+ 13 - 13
docker-compose.yml

@@ -29,16 +29,16 @@ services:
       - APP_ENVIRONMENT=production
       - PASTURE_WORK_DIR=/app/kpt-pasture
     command: [ "/app/kpt-pasture/kptPasture","http" ]
-  kpt-pasture-consumer:
-    privileged: true
-    container_name: xdmy001_kpt_pasture_consumer
-    restart: always
-    image: registry.cn-hangzhou.aliyuncs.com/kpt-event/kpt-pasture:test
-    volumes:
-      - /var/logger/kpt-pasture/:/app/kpt-pasture/logger
-      - /etc/localtime:/etc/localtime
-      - /data/docker-compose/kpt-pasture/config:/app/kpt-pasture/config
-    environment:
-      - APP_ENVIRONMENT=production
-      - PASTURE_WORK_DIR=/app/kpt-pasture
-    command: [ "/app/kpt-pasture/kptPasture","consumer" ]
+  #kpt-pasture-consumer:
+    #privileged: true
+    #container_name: xdmy001_kpt_pasture_consumer
+    #restart: always
+    #image: registry.cn-hangzhou.aliyuncs.com/kpt-event/kpt-pasture:test
+      #volumes:
+      #- /var/logger/kpt-pasture/:/app/kpt-pasture/logger
+      #- /etc/localtime:/etc/localtime
+      #- /data/docker-compose/kpt-pasture/config:/app/kpt-pasture/config
+      #environment:
+      #- APP_ENVIRONMENT=production
+      #- PASTURE_WORK_DIR=/app/kpt-pasture
+    #command: [ "/app/kpt-pasture/kptPasture","consumer" ]

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241113022812-b52528a61377
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241113101816-de37e79ac6d7
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 4 - 0
go.sum

@@ -60,6 +60,10 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241112090416-295c2aa69dab h1:72cBosC+
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241112090416-295c2aa69dab/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241113022812-b52528a61377 h1:Z6WoiWxa3mqk6Dxfv0jK/DDlcdqBI7wewp4w/ELEieo=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241113022812-b52528a61377/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241113084609-d7d3c9619f26 h1:VLwdNyG94ee7H8c4fQ7831vzP5DmU1Uuf0DYDTDGjYA=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241113084609-d7d3c9619f26/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241113101816-de37e79ac6d7 h1:BgZfIUaX6pdvF72FpX7dFb9KczzjzlD+DW69aYVc6F8=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241113101816-de37e79ac6d7/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=

+ 20 - 0
http/handler/work/calendar.go

@@ -182,3 +182,23 @@ func MatingCowList(c *gin.Context) {
 	}
 	ginutil.JSONResp(c, res)
 }
+
+func CalvingList(c *gin.Context) {
+	var req pasturePb.ItemsRequest
+	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.CalvingCowList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}

+ 1 - 0
http/route/work_order.go

@@ -28,5 +28,6 @@ func WorkOrderAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		workRoute.POST("/pregnancy/check/items", work.PregnancyCheckCowList)
 		workRoute.POST("/weaning/items", work.WeaningCowList)
 		workRoute.POST("/mating/items", work.MatingCowList)
+		workRoute.POST("/calving/items", work.CalvingList)
 	}
 }

+ 2 - 1
model/event_calving.go

@@ -18,6 +18,7 @@ type EventCalving struct {
 	PlanDay        int64                         `json:"planDay"`
 	RealityDay     int64                         `json:"realityDay"`
 	EndDay         int64                         `json:"endDay"`
+	Status         pasturePb.IsShow_Kind         `json:"status"`
 	PenId          int32                         `json:"penId"`
 	ChildNumber    int8                          `json:"childNumber"`
 	BullNumber     string                        `json:"bullNumber"`
@@ -41,9 +42,9 @@ func NewEventCalving(cow *Cow) *EventCalving {
 		CowKind:    cow.CowKind,
 		CowType:    cow.CowType,
 		EarNumber:  cow.EarNumber,
-		Lact:       cow.Lact,
 		PenId:      cow.PenId,
 		BullNumber: cow.LastBullNumber,
+		Status:     pasturePb.IsShow_No,
 		PlanDay:    util.TimeParseLocalUnix(time.Now().Format(LayoutTime)),
 		EndDay:     util.TimeParseLocalEndUnix(time.Now().Format(LayoutTime)),
 	}

+ 66 - 1
module/backend/calendar.go

@@ -134,6 +134,8 @@ func (s *StoreEntry) getCalendarCowList(
 		return s.TreatmentCowList(ctx, req, pagination)
 	case pasturePb.CalendarType_Mating: // 配种
 		return s.MatingCowList(ctx, req, pagination)
+	case pasturePb.CalendarType_Calving: // 产犊
+		return s.CalvingCowList(ctx, req, pagination)
 	default:
 		return nil, xerr.New("不支持的日历类型")
 	}
@@ -382,7 +384,8 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
 		pref.Where("a.status = ?", req.Status)
 	}
 
-	if err := pref.Order("a.id desc").Count(&count).
+	if err := pref.Order("a.id desc").
+		Count(&count).
 		Limit(int(pagination.PageSize)).
 		Offset(int(pagination.PageOffset)).
 		Find(&matingItems).Error; err != nil {
@@ -413,10 +416,72 @@ func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequ
 	}, nil
 }
 
+func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error) {
+	calvingItems := make([]*pasturePb.CalvingItems, 0)
+	count := int64(0)
+	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCalving).TableName())).
+		Select(`a.id,a.cow_id,a.status,b.breed_status,b.pen_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,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("b.admission_status = ?", pasturePb.AdmissionStatus_Admission)
+
+	if req.EndDay != "" {
+		dateTime := util.TimeParseLocalEndUnix(req.EndDay)
+		pref.Where("a.plan_day <= ?", dateTime)
+	}
+
+	if req.Status > 0 {
+		pref.Where("a.status = ?", req.Status)
+	}
+
+	if err := pref.Order("a.id desc").
+		Count(&count).
+		Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Find(&calvingItems).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	breedStatusMap := s.CowBreedStatusMap()
+	for _, v := range calvingItems {
+		breedStatusName := ""
+		if breedStatus, ok := breedStatusMap[v.BreedStatus]; ok {
+			breedStatusName = breedStatus
+		}
+		v.BreedStatusName = breedStatusName
+	}
+
+	return &pasturePb.CalvingItemsResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.CalvingItemsData{
+			Total:    int32(count),
+			Page:     pagination.Page,
+			PageSize: pagination.PageSize,
+			Header: map[string]string{
+				"id":              "编号",
+				"cowId":           "牛号",
+				"breedStatusName": "繁殖状态",
+				"penName":         "栏舍",
+				"lact":            "胎次",
+				"matingAge":       "配后天数",
+				"dayAge":          "日龄",
+				"status":          "是否完成",
+				"bullId":          "配种公牛号",
+				"planDay":         "预产时间",
+			},
+			List: calvingItems,
+		},
+	}, nil
+
+}
+
+// WorkOrderCowList 暂时不处理工单业务
 func (s *StoreEntry) WorkOrderCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (interface{}, error) {
 	return nil, nil
 }
 
+// TreatmentCowList 治疗清单
 func (s *StoreEntry) TreatmentCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (interface{}, error) {
 	return nil, nil
 }

+ 4 - 0
module/backend/cow.go

@@ -49,3 +49,7 @@ func (s *StoreEntry) CowList(ctx context.Context, req *pasturePb.SearchEventRequ
 	}, nil
 
 }
+
+func (s *StoreEntry) CowDetail(ctx context.Context, req *pasturePb.SearchEventRequest) {
+
+}

+ 1 - 0
module/backend/interface.go

@@ -250,4 +250,5 @@ type WorkService interface {
 	PregnancyCheckCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyCheckItemsResponse, error)
 	WeaningCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.WeaningItemsResponse, error)
 	MatingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingItemsResponse, error)
+	CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error)
 }