Browse Source

immunization: 免疫计划

Yi 7 months ago
parent
commit
673700b0b4

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240812032539-162361f00f2c
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240812084330-1dca101fe7e7
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/getsentry/sentry-go v0.23.0

+ 16 - 0
go.sum

@@ -72,6 +72,22 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240812025440-f2a0dfae1d18 h1:0anw9cZt
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240812025440-f2a0dfae1d18/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240812032539-162361f00f2c h1:9EFUWB564/hTtPI8zqP67fq5PcATFAimhwNy/Z7X5fo=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240812032539-162361f00f2c/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812033729-b9cdd9e6e2b3 h1:vluA2TlwgBkO3liLRk3f3dY6MRImI9PvTf+OfghHO3E=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812033729-b9cdd9e6e2b3/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812060557-a935f6d45041 h1:yG4ASDo0Lim+dPHwqH9A7f2dlRQvjz/WE6SxPkqCHtk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812060557-a935f6d45041/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812060927-f75be24f076c h1:jDDknrfdu72nayB07jSsoxfHImpUksnCr/5Bbb+gRwk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812060927-f75be24f076c/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812071349-438319d61d6a h1:3FgT4eKOqeliXJnmNko5HtzmLsaj4C/DFGcdF0b1Y0w=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812071349-438319d61d6a/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812074836-d707a6bcdf94 h1:XXDukOFUskB+E5bqgURjS6f5RdahsUKTAXaU9H+FKLQ=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812074836-d707a6bcdf94/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812075404-16faad67e90e h1:I3ELBmo/zi9ASnrfEWRRMRDHqkYxd7VaaO0xMSXgLpY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812075404-16faad67e90e/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812080243-38f667fd91e7 h1:GfXdHwc4/5F+/kVAy5yAhxBrxXypmhf73adk6Q+VxCM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812080243-38f667fd91e7/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812084330-1dca101fe7e7 h1:S0anZ8cTjnVGPvGSx3vRjjazKNFnaIH3Sdt65sIV1Rk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240812084330-1dca101fe7e7/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=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

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

@@ -131,7 +131,7 @@ func BullListOptions(c *gin.Context) {
 
 func SystemBaseConfigOptions(c *gin.Context) {
 	optionName := c.Query("option_name")
-	if err := valid.Validate(optionName, valid.Required, valid.Length(1, 20)); err != nil {
+	if err := valid.Validate(optionName, valid.Required, valid.Length(1, 50)); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}

+ 71 - 0
http/handler/pasture/prescription.go

@@ -3,6 +3,7 @@ package pasture
 import (
 	"kpt-pasture/http/middleware"
 	"net/http"
+	"strconv"
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
@@ -154,3 +155,73 @@ func CreatedOrUpdatePrescription(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
+
+func SearchImmunizationList(c *gin.Context) {
+	var req pasturePb.ImmunizationRequest
+	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.ImmunizationList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}
+
+func CreatedOrUpdateImmunization(c *gin.Context) {
+	var req pasturePb.ImmunizationRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.Name, valid.Required),
+		valid.Field(&req.CowType, valid.Required),
+		valid.Field(&req.Conditions, valid.Required),
+		valid.Field(&req.Value, valid.Required),
+		valid.Field(&req.Value2, valid.Required),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.CreatedOrUpdateImmunization(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 ImmunizationIsShow(c *gin.Context) {
+	immunizationIdStr := c.Param("id")
+	immunizationId, _ := strconv.Atoi(immunizationIdStr)
+
+	if err := valid.Validate(immunizationId, valid.Required, valid.Min(1)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	if err := middleware.Dependency(c).StoreEventHub.OpsService.ImmunizationIsShow(c, int64(immunizationId)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 6 - 0
http/route/pasture_api.go

@@ -40,6 +40,12 @@ func PastureManageAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		pastureRoute.POST("/prescription/list", pasture.SearchPrescriptionList)
 		pastureRoute.POST("/prescription/createOrUpdate", pasture.CreatedOrUpdatePrescription)
 
+		// 免疫计划相关
+		pastureRoute.POST("/immunization/plan/list", pasture.SearchImmunizationList)
+		pastureRoute.POST("/immunization/plan/createOrUpdate", pasture.CreatedOrUpdateImmunization)
+		pastureRoute.PUT("/immunization/is_show/:id", pasture.ImmunizationIsShow)
+
+		// 同期相关
 		pastureRoute.POST("/seme/time/create", pasture.SemeTimeCreated)
 		pastureRoute.POST("/seme/time/list", pasture.SemeTimeList)
 		pastureRoute.GET("/seme/time/detail/:semeTimeId", pasture.SemeTimeDetail)

+ 76 - 0
model/immunization_plan.go

@@ -0,0 +1,76 @@
+package model
+
+import (
+	"fmt"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+type ImmunizationPlan struct {
+	Id            int64                                 `json:"id"`
+	Name          string                                `json:"name"`
+	CowType       pasturePb.ImmunizationCowType_Kind    `json:"cow_type"`
+	Conditions    pasturePb.ImmunizationConditions_Kind `json:"conditions"`
+	Value         int64                                 `json:"value"`
+	Value2        int64                                 `json:"value2"`
+	IsShow        pasturePb.IsShow_Kind                 `json:"is_show"`
+	OperationId   int64                                 `json:"operation_id"`
+	OperationName string                                `json:"operation_name"`
+	CreatedAt     int64                                 `json:"created_at"`
+	UpdatedAt     int64                                 `json:"updated_at"`
+}
+
+func (i *ImmunizationPlan) TableName() string {
+	return "immunization_plan"
+}
+
+func NewImmunizationPlan(systemUser *SystemUser, req *pasturePb.ImmunizationRequest) *ImmunizationPlan {
+	return &ImmunizationPlan{
+		Name:          req.Name,
+		CowType:       req.CowType,
+		Conditions:    req.Conditions,
+		Value:         int64(req.Value),
+		Value2:        int64(req.Value2),
+		IsShow:        req.IsShow,
+		OperationId:   systemUser.Id,
+		OperationName: systemUser.Name,
+	}
+}
+
+type ImmunizationPlanSlice []*ImmunizationPlan
+
+func (i ImmunizationPlanSlice) ToPB(cowTypeOptions []*pasturePb.ConfigOptionsList, conditionsOptions []*pasturePb.ConfigOptionsList) []*pasturePb.ImmunizationRequest {
+	res := make([]*pasturePb.ImmunizationRequest, len(i))
+	for d, v := range i {
+		cowTypeName, conditionsName := "", ""
+		for _, c := range cowTypeOptions {
+			if c.Value != int32(v.CowType) {
+				continue
+			}
+			cowTypeName = c.Label
+		}
+		for _, cd := range conditionsOptions {
+			if cd.Value != int32(v.Conditions) {
+				continue
+			}
+			conditionsName = cd.Label
+		}
+		res[d] = &pasturePb.ImmunizationRequest{
+			Id:             int32(v.Id),
+			Name:           v.Name,
+			CowType:        v.CowType,
+			CowTypeName:    cowTypeName,
+			Conditions:     v.Conditions,
+			ConditionsName: conditionsName,
+			Value:          int32(v.Value),
+			IsShow:         v.IsShow,
+			OperationId:    int32(v.OperationId),
+			OperationName:  v.OperationName,
+			CreatedAt:      int32(v.CreatedAt),
+			UpdatedAt:      int32(v.UpdatedAt),
+			Value2:         int32(v.Value2),
+			DaysRange:      fmt.Sprintf("%d ~ %d", v.Value, v.Value2),
+		}
+	}
+	return res
+}

+ 48 - 0
module/backend/config_data.go

@@ -252,6 +252,50 @@ func (s *StoreEntry) SemeTimeCowTypeEnumList() []*pasturePb.ConfigOptionsList {
 	return cowTypeList
 }
 
+func (s *StoreEntry) ImmunizationCowTypeEnumList() []*pasturePb.ConfigOptionsList {
+	cowTypeList := make([]*pasturePb.ConfigOptionsList, 0)
+	cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationCowType_Reserve_Cattle),
+		Label:    "后备牛",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationCowType_Adult_Cow),
+		Label:    "种母牛",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationCowType_Adult_bulls),
+		Label:    "种公牛",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationCowType_Calf),
+		Label:    "犊牛",
+		Disabled: true,
+	})
+	return cowTypeList
+}
+
+func (s *StoreEntry) ImmunizationConditionsEnumList() []*pasturePb.ConfigOptionsList {
+	cowTypeList := make([]*pasturePb.ConfigOptionsList, 0)
+	cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationConditions_Days_Age),
+		Label:    "日龄",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationConditions_Days_After_Delivery),
+		Label:    "产后天数",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationConditions_Days_Of_Pregnancy),
+		Label:    "怀孕天数",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.ImmunizationConditions_Month),
+		Label:    "每年月份",
+		Disabled: true,
+	})
+	return cowTypeList
+}
+
 func (s *StoreEntry) TransferPenEnumList() []*pasturePb.ConfigOptionsList {
 	transferPenList := make([]*pasturePb.ConfigOptionsList, 0)
 	transferPenList = append(transferPenList, &pasturePb.ConfigOptionsList{
@@ -825,6 +869,10 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName st
 		configOptions = s.WeekEnumList()
 	case "sameTimeCowType":
 		configOptions = s.SemeTimeCowTypeEnumList()
+	case "immunizationCowType":
+		configOptions = s.ImmunizationCowTypeEnumList()
+	case "immunizationConditions":
+		configOptions = s.ImmunizationConditionsEnumList()
 	}
 
 	return &pasturePb.ConfigOptionsListResponse{

+ 4 - 0
module/backend/interface.go

@@ -119,6 +119,10 @@ type PastureManageService interface {
 
 	SearchPrescriptionList(ctx context.Context, req *pasturePb.SearchPrescriptionRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchPrescriptionResponse, error)
 	CreateOrUpdatePrescription(ctx context.Context, req *pasturePb.PrescriptionRequest) error
+
+	ImmunizationList(ctx context.Context, req *pasturePb.ImmunizationRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchImmunizationResponse, error)
+	CreatedOrUpdateImmunization(ctx context.Context, req *pasturePb.ImmunizationRequest) error
+	ImmunizationIsShow(ctx context.Context, id int64) error
 }
 
 //go:generate mockgen -destination mock/ConfigDataService.go -package kptservicemock kpt-pasture/module/backend ConfigDataService

+ 0 - 93
module/backend/pasture.go

@@ -2,7 +2,6 @@ package backend
 
 import (
 	"context"
-	"encoding/json"
 	"errors"
 	"fmt"
 	"kpt-pasture/model"
@@ -409,95 +408,3 @@ func (s *StoreEntry) CreateOrUpdateCowSource(ctx context.Context, req *pasturePb
 	}
 	return nil
 }
-
-func (s *StoreEntry) CreateOrUpdateSemeTime(ctx context.Context, req *pasturePb.SemeTimeRequest) error {
-	currentUser, _ := s.GetCurrentSystemUser(ctx)
-	if err := s.DB.Transaction(func(tx *gorm.DB) error {
-		semeTime := model.NewEventSemeTime(currentUser, req)
-		semeTimeFlow := model.NewEventSemeTimeFlow(semeTime.Id, req)
-		if req.Form.Id > 0 {
-			if err := tx.Model(new(model.EventSemeTime)).Where("id = ?", req.Form.Id).Updates(semeTime).Error; err != nil {
-				return xerr.WithStack(err)
-			}
-			if err := tx.Model(new(model.EventSemeTimeFlow)).Where("seme_time_id = ?", req.Form.Id).Updates(semeTimeFlow).Error; err != nil {
-				return xerr.WithStack(err)
-			}
-		} else {
-			if err := tx.Create(&semeTime).Error; err != nil {
-				return xerr.WithStack(err)
-			}
-			if err := tx.Create(&semeTimeFlow).Error; err != nil {
-				return xerr.WithStack(err)
-			}
-		}
-
-		return nil
-	}); err != nil {
-		return xerr.WithStack(err)
-	}
-	return nil
-}
-
-func (s *StoreEntry) SearchSemeTimeList(ctx context.Context, req *pasturePb.SearchNameRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SemeTimeEventResponse, error) {
-	semeTimeList := make([]*model.EventSemeTime, 0)
-	var count int64 = 0
-	pref := s.DB.Model(new(model.EventSemeTime)).
-		Where("is_delete = ?", pasturePb.IsShow_Ok)
-	if req.Name != "" {
-		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
-	}
-
-	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
-		Find(&semeTimeList).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	weekMap := s.WeekMap()
-	cowTypeMap := s.CowTypeMap()
-	systemUser, _ := s.SystemUserList(ctx)
-	return &pasturePb.SemeTimeEventResponse{
-		Code:    http.StatusOK,
-		Message: "ok",
-		Data: &pasturePb.SearchSemeTimeData{
-			List:     model.EventSemeTimeSlice(semeTimeList).ToPB(weekMap, cowTypeMap, systemUser),
-			Total:    int32(count),
-			PageSize: pagination.PageSize,
-			Page:     pagination.Page,
-		},
-	}, nil
-}
-
-func (s *StoreEntry) SemeTimeDetail(ctx context.Context, semeTimeId int64) (*pasturePb.SemeTimeDetailResponse, error) {
-	semeTime := &model.EventSemeTime{Id: semeTimeId}
-	if err := s.DB.Model(new(model.EventSemeTime)).
-		Where("is_delete = ?", pasturePb.IsShow_Ok).First(semeTime).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	semeTimeFlow := &model.EventSemeTimeFlow{}
-	if err := s.DB.Model(new(model.EventSemeTimeFlow)).Where("seme_time_id = ?", semeTimeId).
-		First(&semeTimeFlow).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	graph := &pasturePb.SemeTimeGraphData{}
-	if err := json.Unmarshal([]byte(semeTimeFlow.OriginalFlowData), graph); err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	return &pasturePb.SemeTimeDetailResponse{
-		Code:    http.StatusOK,
-		Message: "ok",
-		Data: &pasturePb.SemeTimeRequest{
-			Form: &pasturePb.SemeTimeFormData{
-				Id:             int32(semeTime.Id),
-				Name:           semeTime.Name,
-				WeekType:       semeTime.WeekType,
-				PostpartumDays: semeTime.PostpartumDays,
-				CowType:        semeTime.CowType,
-				Remarks:        semeTime.Remarks,
-			},
-			Graph: graph,
-		},
-	}, nil
-}

+ 176 - 0
module/backend/prescription.go

@@ -14,6 +14,98 @@ import (
 	"gorm.io/gorm"
 )
 
+func (s *StoreEntry) CreateOrUpdateSemeTime(ctx context.Context, req *pasturePb.SemeTimeRequest) error {
+	currentUser, _ := s.GetCurrentSystemUser(ctx)
+	if err := s.DB.Transaction(func(tx *gorm.DB) error {
+		semeTime := model.NewEventSemeTime(currentUser, req)
+		semeTimeFlow := model.NewEventSemeTimeFlow(semeTime.Id, req)
+		if req.Form.Id > 0 {
+			if err := tx.Model(new(model.EventSemeTime)).Where("id = ?", req.Form.Id).Updates(semeTime).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+			if err := tx.Model(new(model.EventSemeTimeFlow)).Where("seme_time_id = ?", req.Form.Id).Updates(semeTimeFlow).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		} else {
+			if err := tx.Create(&semeTime).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+			if err := tx.Create(&semeTimeFlow).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+
+		return nil
+	}); err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}
+
+func (s *StoreEntry) SearchSemeTimeList(ctx context.Context, req *pasturePb.SearchNameRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SemeTimeEventResponse, error) {
+	semeTimeList := make([]*model.EventSemeTime, 0)
+	var count int64 = 0
+	pref := s.DB.Model(new(model.EventSemeTime)).
+		Where("is_delete = ?", pasturePb.IsShow_Ok)
+	if req.Name != "" {
+		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
+	}
+
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
+		Find(&semeTimeList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	weekMap := s.WeekMap()
+	cowTypeMap := s.CowTypeMap()
+	systemUser, _ := s.SystemUserList(ctx)
+	return &pasturePb.SemeTimeEventResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchSemeTimeData{
+			List:     model.EventSemeTimeSlice(semeTimeList).ToPB(weekMap, cowTypeMap, systemUser),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
+func (s *StoreEntry) SemeTimeDetail(ctx context.Context, semeTimeId int64) (*pasturePb.SemeTimeDetailResponse, error) {
+	semeTime := &model.EventSemeTime{Id: semeTimeId}
+	if err := s.DB.Model(new(model.EventSemeTime)).
+		Where("is_delete = ?", pasturePb.IsShow_Ok).First(semeTime).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	semeTimeFlow := &model.EventSemeTimeFlow{}
+	if err := s.DB.Model(new(model.EventSemeTimeFlow)).Where("seme_time_id = ?", semeTimeId).
+		First(&semeTimeFlow).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	graph := &pasturePb.SemeTimeGraphData{}
+	if err := json.Unmarshal([]byte(semeTimeFlow.OriginalFlowData), graph); err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.SemeTimeDetailResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SemeTimeRequest{
+			Form: &pasturePb.SemeTimeFormData{
+				Id:             int32(semeTime.Id),
+				Name:           semeTime.Name,
+				WeekType:       semeTime.WeekType,
+				PostpartumDays: semeTime.PostpartumDays,
+				CowType:        semeTime.CowType,
+				Remarks:        semeTime.Remarks,
+			},
+			Graph: graph,
+		},
+	}, nil
+}
+
 func (s *StoreEntry) SearchDiseaseList(ctx context.Context, req *pasturePb.SearchDiseaseRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchDiseaseResponse, error) {
 	diseaseList := make([]*model.Disease, 0)
 	var count int64 = 0
@@ -262,3 +354,87 @@ func (s *StoreEntry) CreateOrUpdatePrescription(ctx context.Context, req *pastur
 	}
 	return nil
 }
+
+func (s *StoreEntry) ImmunizationList(ctx context.Context, req *pasturePb.ImmunizationRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchImmunizationResponse, error) {
+	immunizationList := make([]*model.ImmunizationPlan, 0)
+	var count int64 = 0
+	pref := s.DB.Model(new(model.ImmunizationPlan))
+	if req.Name != "" {
+		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
+	}
+
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
+		Find(&immunizationList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	CowTypeOptions := s.ImmunizationCowTypeEnumList()
+	conditionsOptions := s.ImmunizationConditionsEnumList()
+	return &pasturePb.SearchImmunizationResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchImmunizationData{
+			List:     model.ImmunizationPlanSlice(immunizationList).ToPB(CowTypeOptions, conditionsOptions),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
+func (s *StoreEntry) CreatedOrUpdateImmunization(ctx context.Context, req *pasturePb.ImmunizationRequest) error {
+	var immunization *model.ImmunizationPlan
+	var err error
+	if req.Id > 0 {
+		immunization, err = s.ImmunizationById(ctx, int64(req.Id))
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+		immunization.Name = req.Name
+		immunization.CowType = req.CowType
+		immunization.Conditions = req.Conditions
+		immunization.Value = int64(req.Value)
+		immunization.Value2 = int64(req.Value2)
+		immunization.IsShow = req.IsShow
+	} else {
+		systemUser, _ := s.GetCurrentSystemUser(ctx)
+		immunization = model.NewImmunizationPlan(systemUser, req)
+	}
+	if err = s.DB.Model(&model.ImmunizationPlan{}).Where(map[string]interface{}{
+		"id": req.Id,
+	}).Assign(map[string]interface{}{
+		"name":           immunization.Name,
+		"cow_type":       immunization.CowType,
+		"conditions":     immunization.Conditions,
+		"value":          immunization.Value,
+		"value2":         immunization.Value2,
+		"is_show":        immunization.IsShow,
+		"operation_id":   immunization.OperationId,
+		"operation_name": immunization.OperationName,
+	}).FirstOrCreate(&model.ImmunizationPlan{}).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return nil
+}
+
+func (s *StoreEntry) ImmunizationIsShow(ctx context.Context, id int64) error {
+	immunizationPlan := &model.ImmunizationPlan{
+		Id: id,
+	}
+	if err := s.DB.First(immunizationPlan).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return xerr.Custom("该免疫计划不存在")
+		}
+		return xerr.WithStack(err)
+	}
+	isShow := pasturePb.IsShow_No
+	if immunizationPlan.IsShow == pasturePb.IsShow_No {
+		isShow = pasturePb.IsShow_Ok
+	}
+
+	if err := s.DB.Model(immunizationPlan).Update("is_show", isShow).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}

+ 11 - 0
module/backend/sql.go

@@ -138,3 +138,14 @@ func (s *StoreEntry) DiseaseListByIds(ctx context.Context, ids []int32) ([]*mode
 	}
 	return diseaseList, nil
 }
+
+func (s *StoreEntry) ImmunizationById(ctx context.Context, id int64) (*model.ImmunizationPlan, error) {
+	immunizationPlan := &model.ImmunizationPlan{Id: id}
+	if err := s.DB.First(immunizationPlan).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return nil, xerr.Customf("该免疫计划不存在: %d", id)
+		}
+		return nil, xerr.WithStack(err)
+	}
+	return immunizationPlan, nil
+}