Kaynağa Gözat

event: 药品管理和孕检事件

ping 10 ay önce
ebeveyn
işleme
6afb9633bd

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240524004006-fa7e55b57e1a
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240526140108-73f4ee04f1c5
 	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

+ 10 - 0
go.sum

@@ -72,6 +72,16 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240523234532-3f892302e1b1 h1:Qo70vVtX
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240523234532-3f892302e1b1/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240524004006-fa7e55b57e1a h1:j8eLmI8VXAc6HHCN4AhyP4ibtEzrvYn43dJe3H/DtpY=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240524004006-fa7e55b57e1a/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240524064014-5e4b51cf5659 h1:L0ncdDSb8RAEOpXvnCDkbOadMVep8y48KmbQc+kNPOA=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240524064014-5e4b51cf5659/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526012105-32abd34abd7f h1:ip0zJlF9+JZMco3dAr6nY8VnkAHGosP/MAmgUKUA5g8=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526012105-32abd34abd7f/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526022458-2ea5543f4ce5 h1:buvZSZwiqJnJg0AxSeFBoLj40iFfgK81+bnAK2THRRk=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526022458-2ea5543f4ce5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526024805-eac3258223e5 h1:2iGgtLkYUrO4KCFU9IxGew+2iLAovSvjjBXnshSnBC4=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526024805-eac3258223e5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526140108-73f4ee04f1c5 h1:ni/CWwJhAilmh95iOIFJOup5eWCsSkYOVHq18sO+AFY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240526140108-73f4ee04f1c5/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=

+ 30 - 0
http/handler/event/event.go

@@ -252,3 +252,33 @@ func PregnantCheckEventList(c *gin.Context) {
 	}
 	ginutil.JSONResp(c, res)
 }
+
+func PregnantCheckEventCreate(c *gin.Context) {
+	var req pasturePb.PregnantCheckEventRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.CowId, valid.Required),
+		valid.Field(&req.PregnantCheckAt, valid.Required),
+		valid.Field(&req.PregnantCheckResult, valid.Required),
+		valid.Field(&req.PregnantCheckAt, valid.Required),
+		valid.Field(&req.StaffMemberId, valid.Required),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.PregnantCheckCreate(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 68 - 0
http/handler/goods/drugs.go

@@ -0,0 +1,68 @@
+package goods
+
+import (
+	"kpt-pasture/http/middleware"
+	"net/http"
+
+	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
+	"gitee.com/xuyiping_admin/pkg/valid"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"github.com/gin-gonic/gin"
+)
+
+func DrugsList(c *gin.Context) {
+	var req pasturePb.SearchDrugsRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusOK, 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.DrugsList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}
+
+func DrugsCreateOrUpdate(c *gin.Context) {
+	var req pasturePb.SearchDrugsList
+	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.CategoryId, valid.Required),
+		valid.Field(&req.Producer, valid.Required),
+		valid.Field(&req.Usage, valid.Required),
+		valid.Field(&req.Unit, valid.Required),
+		valid.Field(&req.Specs, valid.Required),
+		valid.Field(&req.Inventory, valid.Required),
+		valid.Field(&req.ExpirationAt, valid.Required),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	if err := middleware.BackendOperation(c).OpsService.DrugsCreate(c, &req); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 1 - 0
http/route/event_api.go

@@ -26,5 +26,6 @@ func EventAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		eventRoute.POST("/calving/create", event.CalvingEventCreate)
 
 		eventRoute.POST("/pregnant/check/list", event.PregnantCheckEventList)
+		eventRoute.POST("/pregnant/check/create", event.PregnantCheckEventCreate)
 	}
 }

+ 19 - 0
http/route/goods.go

@@ -0,0 +1,19 @@
+package route
+
+import (
+	"kpt-pasture/http/handler/goods"
+
+	"github.com/gin-gonic/gin"
+)
+
+func GoodsManageAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+		// goods API 组  物品管理
+		goodsRoute := authRouteGroup(s, "/api/v1/goods/")
+		goodsRoute.POST("/drugs/list", goods.DrugsList)
+		goodsRoute.POST("/drugs/createOrUpdate", goods.DrugsCreateOrUpdate)
+	}
+}

+ 1 - 0
http/route/route.go

@@ -11,6 +11,7 @@ func HTTPServerRoute(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		ConfigAPI(opts...),
 		EventAPI(opts...),
 		CowAPI(opts...),
+		GoodsManageAPI(opts...),
 	}
 
 	return func(s *gin.Engine) {

+ 84 - 0
model/drugs.go

@@ -0,0 +1,84 @@
+package model
+
+import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+
+type Drugs struct {
+	Id           int64                       `json:"id"`
+	Name         string                      `json:"name"`
+	CategoryId   pasturePb.DrugCategory_Kind `json:"category_id"`
+	Producer     string                      `json:"producer"`
+	BatchNumber  string                      `json:"batch_number"`
+	ProductionAt int64                       `json:"production_at"`
+	ExpirationAt int64                       `json:"expiration_at"`
+	Unit         pasturePb.Unit_Kind         `json:"unit"`
+	Specs        string                      `json:"specs"`
+	Inventory    int32                       `json:"inventory"`
+	UsageMethod  pasturePb.DrugUsage_Kind    `json:"usage_method"`
+	Price        int32                       `json:"price"`
+	Remarks      string                      `json:"remarks"`
+	OperationId  int32                       `json:"operation_id"`
+	CreatedAt    int64                       `json:"created_at"`
+	UpdatedAt    int64                       `json:"updated_at"`
+}
+
+func (d *Drugs) TableName() string {
+	return "drugs"
+}
+
+func NewDrugs(req *pasturePb.SearchDrugsList, currentUser *SystemUser) *Drugs {
+	return &Drugs{
+		Name:         req.Name,
+		CategoryId:   req.CategoryId,
+		Producer:     req.Producer,
+		BatchNumber:  req.BatchNumber,
+		ProductionAt: int64(req.ProductionAt),
+		ExpirationAt: int64(req.ExpirationAt),
+		Unit:         req.Unit,
+		Specs:        req.Specs,
+		Inventory:    req.Inventory,
+		UsageMethod:  req.Usage,
+		Price:        int32(req.Price * 100),
+		Remarks:      req.Remarks,
+		OperationId:  int32(currentUser.Id),
+	}
+}
+
+type DrugsSlice []*Drugs
+
+func (d DrugsSlice) ToPB(systemUserList []*SystemUser, drugsCategoryMap map[pasturePb.DrugCategory_Kind]string,
+	unitMap map[pasturePb.Unit_Kind]string, drugUsageMap map[pasturePb.DrugUsage_Kind]string) []*pasturePb.SearchDrugsList {
+	res := make([]*pasturePb.SearchDrugsList, len(d))
+	for i, v := range d {
+		operationName := ""
+		for _, u := range systemUserList {
+			if int64(v.OperationId) != u.Id {
+				continue
+			}
+			operationName = u.Name
+		}
+
+		res[i] = &pasturePb.SearchDrugsList{
+			Id:            int32(v.Id),
+			Name:          v.Name,
+			CategoryId:    v.CategoryId,
+			CategoryName:  drugsCategoryMap[v.CategoryId],
+			Producer:      v.Producer,
+			BatchNumber:   v.BatchNumber,
+			ProductionAt:  int32(v.ProductionAt),
+			ExpirationAt:  int32(v.ExpirationAt),
+			Unit:          v.Unit,
+			UnitName:      unitMap[v.Unit],
+			Specs:         v.Specs,
+			Inventory:     v.Inventory,
+			Usage:         v.UsageMethod,
+			UsageName:     drugUsageMap[v.UsageMethod],
+			Price:         float32(v.Price) / 100,
+			Remarks:       v.Remarks,
+			OperationId:   v.OperationId,
+			OperationName: operationName,
+			CreatedAt:     int32(v.CreatedAt),
+			UpdatedAt:     int32(v.UpdatedAt),
+		}
+	}
+	return res
+}

+ 15 - 1
model/event_pregnant_check.go

@@ -21,6 +21,20 @@ func (e *EventPregnantCheck) TableName() string {
 	return "event_pregnant_check"
 }
 
+func NewEventPregnantCheck(cow *Cow, systemUser *SystemUser, req *pasturePb.PregnantCheckEventRequest) *EventPregnantCheck {
+	return &EventPregnantCheck{
+		CowId:               cow.Id,
+		DayAge:              cow.GetDayAge(),
+		Lact:                int8(cow.Lact),
+		PregnantCheckAt:     int64(req.PregnantCheckAt),
+		PregnantCheckResult: req.PregnantCheckResult,
+		PregnantCheckMethod: req.PregnantCheckMethod,
+		StaffMemberId:       int64(req.StaffMemberId),
+		OperationId:         systemUser.Id,
+		Remarks:             req.Remarks,
+	}
+}
+
 type EventPregnantCheckSlice []*EventPregnantCheck
 
 func (e EventPregnantCheckSlice) ToPB(systemUserList []*SystemUser, pregnantCheckResult, pregnantCheckMethod []*pasturePb.ConfigOptionsList) []*pasturePb.SearchPregnantCheckList {
@@ -28,7 +42,7 @@ func (e EventPregnantCheckSlice) ToPB(systemUserList []*SystemUser, pregnantChec
 	for i, v := range e {
 		var pregnantCheckResultName, pregnantCheckMethodName, staffMemberName, operationName = "", "", "", ""
 		for _, u := range systemUserList {
-			if v.StaffMemberId != u.Id {
+			if v.StaffMemberId == u.Id {
 				staffMemberName = u.Name
 			}
 			if v.OperationId == u.Id {

+ 184 - 6
module/backend/config_data.go

@@ -10,6 +10,39 @@ import (
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
+var DrugCategoryMap = map[pasturePb.DrugCategory_Kind]string{
+	pasturePb.DrugCategory_Antibiotics:    "抗生素类",
+	pasturePb.DrugCategory_Antivirals:     "抗病毒类",
+	pasturePb.DrugCategory_Antifungals:    "抗真菌类",
+	pasturePb.DrugCategory_Antiparasitics: "抗寄生虫类",
+	pasturePb.DrugCategory_Analgesics:     "镇痛类",
+	pasturePb.DrugCategory_Antipyretic:    "退烧类",
+	pasturePb.DrugCategory_Vitamin:        "维生素类",
+	pasturePb.DrugCategory_Brine:          "盐水",
+	pasturePb.DrugCategory_Glucose:        "葡萄糖",
+	pasturePb.DrugCategory_Hormone:        "激素类",
+	pasturePb.DrugCategory_Anti_Stress:    "抗应激类",
+	pasturePb.DrugCategory_Disinfect:      "消毒类",
+	pasturePb.DrugCategory_Chinese_Herbal: "中药合剂",
+	pasturePb.DrugCategory_Tocolytic:      "保胎类",
+}
+var UnitMap = map[pasturePb.Unit_Kind]string{
+	pasturePb.Unit_Pieces:  "个",
+	pasturePb.Unit_Package: "包/袋",
+	pasturePb.Unit_Bottle:  "瓶",
+	pasturePb.Unit_Box:     "盒",
+	pasturePb.Unit_Boxful:  "箱",
+	pasturePb.Unit_Branch:  "支",
+	pasturePb.Unit_Barrel:  "桶",
+	pasturePb.Unit_Pot:     "罐",
+}
+var DrugUsageMap = map[pasturePb.DrugUsage_Kind]string{
+	pasturePb.DrugUsage_Oral_Medications:       "口服",
+	pasturePb.DrugUsage_Injectable_Medications: "肌注",
+	pasturePb.DrugUsage_Topical_Medications:    "外用",
+	pasturePb.DrugUsage_Drink_Medications:      "饮水",
+}
+
 func (s *StoreEntry) BarnTypeEnumList() []*pasturePb.ConfigOptionsList {
 	barnTypeList := make([]*pasturePb.ConfigOptionsList, 0)
 	barnTypeList = append(barnTypeList, &pasturePb.ConfigOptionsList{
@@ -84,7 +117,6 @@ func (s *StoreEntry) BreedStatusEnumList() []*pasturePb.ConfigOptionsList {
 	})
 	return breedStatusList
 }
-
 func (s *StoreEntry) CowKindEnumList() []*pasturePb.ConfigOptionsList {
 	cowKindList := make([]*pasturePb.ConfigOptionsList, 0)
 	cowKindList = append(cowKindList, &pasturePb.ConfigOptionsList{
@@ -269,7 +301,7 @@ func (s *StoreEntry) CalvingLevelEnumList() []*pasturePb.ConfigOptionsList {
 	return configOptions
 }
 
-func (s *StoreEntry) DystociaReason() []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) DystociaReasonEnumList() []*pasturePb.ConfigOptionsList {
 	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
 	configOptions = append(configOptions,
 		&pasturePb.ConfigOptionsList{
@@ -296,7 +328,7 @@ func (s *StoreEntry) DystociaReason() []*pasturePb.ConfigOptionsList {
 	return configOptions
 }
 
-func (s *StoreEntry) PregnantCheckResult() []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) PregnantCheckResultEnumList() []*pasturePb.ConfigOptionsList {
 	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
 	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.PregnantCheckResult_InCheck_UnPregnant),
@@ -318,7 +350,7 @@ func (s *StoreEntry) PregnantCheckResult() []*pasturePb.ConfigOptionsList {
 	return configOptions
 }
 
-func (s *StoreEntry) PregnantCheckMethod() []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) PregnantCheckMethodEnumList() []*pasturePb.ConfigOptionsList {
 	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
 	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.PregnantCheckMethod_B_Ultrasound),
@@ -335,6 +367,142 @@ func (s *StoreEntry) PregnantCheckMethod() []*pasturePb.ConfigOptionsList {
 	})
 	return configOptions
 }
+
+func (s *StoreEntry) DrugCategoryEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Antibiotics),
+		Label:    "抗生素类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Antivirals),
+		Label:    "抗病毒类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Antifungals),
+		Label:    "抗真菌类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Antiparasitics),
+		Label:    "抗寄生虫类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Analgesics),
+		Label:    "镇痛类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Antipyretic),
+		Label:    "退烧类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Vitamin),
+		Label:    "维生素类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Brine),
+		Label:    "盐水",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Glucose),
+		Label:    "葡萄糖",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Hormone),
+		Label:    "激素类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Anti_Stress),
+		Label:    "抗应激类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Disinfect),
+		Label:    "消毒类",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Chinese_Herbal),
+		Label:    "中药合剂",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.DrugCategory_Tocolytic),
+		Label:    "保胎类",
+		Disabled: true,
+	})
+	return configOptions
+}
+
+func (s *StoreEntry) DrugUsageEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions,
+		&pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.DrugUsage_Oral_Medications),
+			Label:    "口服",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.DrugUsage_Injectable_Medications),
+			Label:    "肌注",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.DrugUsage_Topical_Medications),
+			Label:    "外用",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.DrugUsage_Drink_Medications),
+			Label:    "饮水",
+			Disabled: true,
+		})
+	return configOptions
+}
+
+func (s *StoreEntry) UnitEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions,
+		&pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Pieces),
+			Label:    "个",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Package),
+			Label:    "包/袋",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Bottle),
+			Label:    "瓶",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Box),
+			Label:    "盒",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Boxful),
+			Label:    "箱",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Branch),
+			Label:    "支",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Barrel),
+			Label:    "桶",
+			Disabled: true,
+		}, &pasturePb.ConfigOptionsList{
+			Value:    int32(pasturePb.Unit_Pot),
+			Label:    "罐",
+			Disabled: true,
+		})
+	return configOptions
+}
+
+func (s *StoreEntry) DrugUsageMaps(key pasturePb.DrugUsage_Kind) string {
+	res := ""
+	for _, v := range s.DrugUsageEnumList() {
+		if v.Value != int32(key) {
+			continue
+		}
+		res = v.Label
+	}
+	return res
+}
+
 func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
 	return &pasturePb.ConfigOptionsListResponse{
 		Code:    http.StatusOK,
@@ -412,7 +580,7 @@ func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasture
 		Where("is_delete = ?", pasturePb.IsShow_Ok).
 		Where("is_show =? ", pasturePb.IsShow_Ok)
 	if depId != -1 && depId > 0 {
-		pref = pref.Where("dep_id = ?", depId)
+		pref = pref.Where("dept_id = ?", depId)
 	}
 	if err := pref.Find(&systemUserList).Error; err != nil {
 		return nil, xxerr.WithStack(err)
@@ -432,7 +600,17 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName st
 	case "calvingLevel":
 		configOptions = s.CalvingLevelEnumList()
 	case "dystociaReason":
-		configOptions = s.DystociaReason()
+		configOptions = s.DystociaReasonEnumList()
+	case "drugCategory":
+		configOptions = s.DrugCategoryEnumList()
+	case "drugUsage":
+		configOptions = s.DrugUsageEnumList()
+	case "unit":
+		configOptions = s.UnitEnumList()
+	case "pregnantCheckResult":
+		configOptions = s.PregnantCheckResultEnumList()
+	case "pregnantCheckMethod":
+		configOptions = s.PregnantCheckMethodEnumList()
 	}
 	return &pasturePb.ConfigOptionsListResponse{
 		Code:    http.StatusOK,

+ 24 - 2
module/backend/event.go

@@ -332,8 +332,8 @@ func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.Searc
 	}
 
 	systemUserList, _ := s.SystemUserList(ctx)
-	pregnantCheckResult := s.PregnantCheckResult()
-	pregnantCheckMethod := s.PregnantCheckMethod()
+	pregnantCheckResult := s.PregnantCheckResultEnumList()
+	pregnantCheckMethod := s.PregnantCheckMethodEnumList()
 
 	return &pasturePb.PregnantCheckEventResponse{
 		Code:    http.StatusOK,
@@ -346,3 +346,25 @@ func (s *StoreEntry) PregnantCheckList(ctx context.Context, req *pasturePb.Searc
 		},
 	}, nil
 }
+
+func (s *StoreEntry) PregnantCheckCreate(ctx context.Context, req *pasturePb.PregnantCheckEventRequest) error {
+	if len(req.CowId) <= 0 {
+		return xerr.Custom("请选择相关牛只")
+	}
+	cowList := strings.Split(req.CowId, ",")
+	eventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
+	currentUser, _ := s.GetCurrentSystemUser(ctx)
+	for _, v := range cowList {
+		cowId, _ := strconv.ParseInt(v, 10, 64)
+		cow, err := s.GetCowInfo(ctx, cowId)
+		if err != nil {
+			return xerr.WithStack(err)
+		}
+		eventPregnantCheckList = append(eventPregnantCheckList, model.NewEventPregnantCheck(cow, currentUser, req))
+	}
+
+	if err := s.DB.Create(eventPregnantCheckList).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}

+ 67 - 0
module/backend/goods.go

@@ -0,0 +1,67 @@
+package backend
+
+import (
+	"context"
+	"fmt"
+	"kpt-pasture/model"
+	"net/http"
+
+	"gitee.com/xuyiping_admin/pkg/xerr"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+func (s *StoreEntry) DrugsList(ctx context.Context, req *pasturePb.SearchDrugsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchDrugsResponse, error) {
+	drugsList := make([]*model.Drugs, 0)
+	var count int64 = 0
+
+	pref := s.DB.Model(new(model.Drugs))
+	if req.Name != "" {
+		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
+	}
+
+	if req.Usage > 0 {
+		pref.Where("usage_method = ?", req.Usage)
+	}
+
+	if req.CategoryId > 0 {
+		pref.Where("category_id = ?", req.CategoryId)
+	}
+
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
+		Find(&drugsList).Debug().Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	drugsCategoryMap := DrugCategoryMap
+	systemUserList, _ := s.SystemUserList(ctx)
+	unitMap := UnitMap
+	drugUsageMap := DrugUsageMap
+
+	return &pasturePb.SearchDrugsResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchDrugsData{
+			List:     model.DrugsSlice(drugsList).ToPB(systemUserList, drugsCategoryMap, unitMap, drugUsageMap),
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}
+
+func (s *StoreEntry) DrugsCreate(ctx context.Context, req *pasturePb.SearchDrugsList) error {
+	currentUser, _ := s.GetCurrentSystemUser(ctx)
+	newDrugs := model.NewDrugs(req, currentUser)
+	if req.Id <= 0 {
+		if err := s.DB.Create(newDrugs).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+	} else {
+		if err := s.DB.Where("id = ?", req.Id).Updates(newDrugs).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+	}
+
+	return nil
+}

+ 8 - 1
module/backend/interface.go

@@ -44,7 +44,8 @@ type KptService interface {
 	PastureManageService // 牧场管理相关
 	ConfigDataService    // 配置数据相关
 	EventService         // 事件相关
-	CowService           // 牛相关
+	CowService           // 牛只相关
+	GoodsService         // 牧场物品相关
 }
 
 //go:generate mockgen -destination mock/SystemService.go -package kptservicemock kpt-pasture/module/backend SystemService
@@ -131,9 +132,15 @@ type EventService interface {
 	CalvingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchLavingEventResponse, error)
 	CalvingCreate(ctx context.Context, req *pasturePb.CalvingEventRequest) error
 	PregnantCheckList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnantCheckEventResponse, error)
+	PregnantCheckCreate(ctx context.Context, req *pasturePb.PregnantCheckEventRequest) error
 }
 
 //go:generate mockgen -destination mock/CowService.go -package kptservicemock kpt-pasture/module/backend CowService
 type CowService interface {
 	CowList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchCowListResponse, error)
 }
+
+type GoodsService interface {
+	DrugsList(ctx context.Context, req *pasturePb.SearchDrugsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchDrugsResponse, error)
+	DrugsCreate(ctx context.Context, req *pasturePb.SearchDrugsList) error
+}

+ 0 - 0
module/backend/pasture_manage.go → module/backend/pasture.go


+ 5 - 3
module/backend/system_service.go

@@ -25,8 +25,6 @@ const CurrentUserName = "userName"
 func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SystemUserResponse, error) {
 	systemUser := &model.SystemUser{}
 	if err := s.DB.Where("name = ?", req.Name).
-		Where("is_delete = ?", pasturePb.IsShow_Ok).
-		Where("is_show = ?", pasturePb.IsShow_Ok).
 		Find(systemUser).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
@@ -39,6 +37,10 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
 		return nil, xerr.Customf("该账号已被禁用,请联系管理员")
 	}
 
+	if systemUser.IsDelete == pasturePb.IsShow_No {
+		return nil, xerr.Customf("该账号已被删除,请联系管理员")
+	}
+
 	systemRole := &model.SystemRole{Id: systemUser.RoleId}
 	if err := s.DB.Where("is_show = ? and is_delete = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
 		First(systemRole).Error; err != nil {
@@ -91,7 +93,7 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.Se
 		pref.Where("is_show = ?", req.IsShow)
 	}
 
-	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
+	if err := pref.Order("is_show asc,id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
 		Find(&systemUserList).Debug().Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}