Преглед на файлове

config: 修改牛只类型下来接口

Yi преди 5 месеца
родител
ревизия
a3e2537e8e
променени са 10 файла, в които са добавени 35 реда и са изтрити 24 реда
  1. 1 1
      .drone.yml
  2. 1 1
      go.mod
  3. 2 0
      go.sum
  4. 2 2
      http/handler/analysis/analysis.go
  5. 7 1
      http/handler/config/config.go
  6. 2 14
      module/backend/analysis.go
  7. 15 1
      module/backend/config_data.go
  8. 2 1
      module/backend/enum_map.go
  9. 2 2
      module/backend/enum_options.go
  10. 1 1
      module/backend/interface.go

+ 1 - 1
.drone.yml

@@ -1,6 +1,6 @@
 kind: pipeline
 type: docker
-name: kptTmrGroup
+name: kptPasture
 
 #clone:
 #  depth: 1

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241017071700-cf080afaeec6
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241018062323-e9d24b0e37b7
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241010101255-0c6bd229b939
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 2 - 0
go.sum

@@ -90,6 +90,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241017053229-f6f500c7072c h1:etsV1/NX
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241017053229-f6f500c7072c/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241017071700-cf080afaeec6 h1:ahpnQMqvJDQux/3MTFH2lVgJHyvQwdFVYko9oWc46vA=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241017071700-cf080afaeec6/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241018062323-e9d24b0e37b7 h1:ifjGzo+Kz+arWC0+MOuD7Cdd0Ph2cQ9Eg3eJyp8wEXY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241018062323-e9d24b0e37b7/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 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=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241008063555-121a776fd331 h1:qJcpJ3o+O7uxDqR0I9LijQmi607IKvhf4mGum/ZUPT0=

+ 2 - 2
http/handler/analysis/analysis.go

@@ -105,8 +105,8 @@ func AbortionRate(c *gin.Context) {
 	}
 
 	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.StartDayAt, valid.Required),
-		valid.Field(&req.EndDayAt, valid.Required),
+		valid.Field(&req.StartDayTime, valid.Required),
+		valid.Field(&req.EndDayTime, valid.Required),
 		valid.Field(&req.CowType, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)

+ 7 - 1
http/handler/config/config.go

@@ -89,7 +89,13 @@ func CowSourceOptions(c *gin.Context) {
 }
 
 func CowTypeOptions(c *gin.Context) {
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.CowTypeOptions(c)
+	optionName := c.Query("option_name")
+	if err := valid.Validate(optionName, valid.Required, valid.Length(1, 50)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.CowTypeOptions(c, optionName)
 	if err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return

+ 2 - 14
module/backend/analysis.go

@@ -315,20 +315,8 @@ func (s *StoreEntry) PenWeight(ctx context.Context, req *pasturePb.PenWeightRequ
 }
 
 func (s *StoreEntry) AbortionRate(ctx context.Context, req *pasturePb.AbortionRateRequest) (*pasturePb.AbortionRateResponse, error) {
-	if req.StartDayAt <= 0 || req.EndDayAt <= 0 || req.StartDayAt > req.EndDayAt || req.CowType <= 0 {
-		return nil, xerr.Customf("参数错误")
-	}
-
-	startDay, err := util.GetLastDayOfMonth(time.Unix(int64(req.StartDayAt), 0).Format(model.LayoutMonth))
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
-	endDay, err := util.GetLastDayOfMonth(time.Unix(int64(req.EndDayAt), 0).Format(model.LayoutMonth))
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
 
-	dayTimeList, err := util.GetMonthsInRange(startDay, endDay)
+	dayTimeList, err := util.GetMonthsInRange(req.StartDayTime, req.EndDayTime)
 	if err != nil {
 		return nil, xerr.WithStack(err)
 	}
@@ -346,7 +334,7 @@ func (s *StoreEntry) AbortionRate(ctx context.Context, req *pasturePb.AbortionRa
 			DATE_FORMAT(FROM_UNIXTIME(updated_at),'%Y-%m-%d') as month`,
 		).Where("status = ?", pasturePb.IsShow_Ok).
 		Where("cow_type = ?", req.CowType).
-		Where("DATE_FORMAT(FROM_UNIXTIME(`created_at`),'%Y-%m-%d') IN = ?", lastDayForMonth).
+		Where("DATE_FORMAT(FROM_UNIXTIME(`created_at`),'%Y-%m-%d') IN ?", lastDayForMonth).
 		Group("month").Find(&cowPregnantMonthList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}

+ 15 - 1
module/backend/config_data.go

@@ -138,8 +138,21 @@ func (s *StoreEntry) CowSourceEnumList() []*pasturePb.ConfigOptionsList {
 	})
 	return cowSourceList
 }
-func (s *StoreEntry) CowTypeEnumList() []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) CowTypeEnumList(optionName string) []*pasturePb.ConfigOptionsList {
 	cowTypeList := make([]*pasturePb.ConfigOptionsList, 0)
+	if optionName == "breed" {
+		cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowType_Reserve_Calf),
+			Label:    "后备牛",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.CowType_Breeding_Calf),
+			Label:    "经产牛",
+			Disabled: true,
+		})
+		return cowTypeList
+	}
+
 	cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CowType_Lactating_Calf),
 		Label:    "哺乳犊牛",
@@ -169,6 +182,7 @@ func (s *StoreEntry) CowTypeEnumList() []*pasturePb.ConfigOptionsList {
 		Label:    "种公牛",
 		Disabled: true,
 	})
+
 	return cowTypeList
 }
 

+ 2 - 1
module/backend/enum_map.go

@@ -60,7 +60,8 @@ func (s *StoreEntry) MonthMap() map[int32]string {
 
 func (s *StoreEntry) CowTypeMap() map[pasturePb.CowType_Kind]string {
 	res := make(map[pasturePb.CowType_Kind]string)
-	for _, v := range s.CowTypeEnumList() {
+	optionName := ""
+	for _, v := range s.CowTypeEnumList(optionName) {
 		res[pasturePb.CowType_Kind(v.Value)] = v.Label
 	}
 	return res

+ 2 - 2
module/backend/enum_options.go

@@ -105,11 +105,11 @@ func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOpt
 	}, nil
 }
 
-func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
+func (s *StoreEntry) CowTypeOptions(ctx context.Context, optionName string) (*pasturePb.ConfigOptionsListResponse, error) {
 	return &pasturePb.ConfigOptionsListResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
-		Data:    s.CowTypeEnumList(),
+		Data:    s.CowTypeEnumList(optionName),
 	}, nil
 }
 

+ 1 - 1
module/backend/interface.go

@@ -136,7 +136,7 @@ type ConfigDataService interface {
 	BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
-	CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
+	CowTypeOptions(ctx context.Context, optionName string) (*pasturePb.ConfigOptionsListResponse, error)
 	CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error)
 	BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error)