package backend import ( "context" "kpt-pasture/model" "net/http" "gitee.com/xuyiping_admin/pkg/logger/zaplog" "go.uber.org/zap" xxerr "gitee.com/xuyiping_admin/pkg/xerr" 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{ Value: int32(pasturePb.PenType_Lactating_Calves), Label: "哺乳犊牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Weaned_Calves), Label: "断奶犊牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Youth), Label: "育成牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Nurturing), Label: "育成牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Lactation), Label: "泌乳牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Peripartum), Label: "围产牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Dry_Milking), Label: "干奶牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Sick_Cow), Label: "病牛舍", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PenType_Eliminate), Label: "淘汰牛舍", Disabled: true, }) return barnTypeList } func (s *StoreEntry) BreedStatusEnumList() []*pasturePb.ConfigOptionsList { breedStatusList := make([]*pasturePb.ConfigOptionsList, 0) breedStatusList = append(breedStatusList, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_Unmarried), Label: "未配", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_InCheck_Unpregnant), Label: "初检无胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_InCheck_Pregnant), Label: "初检有胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_Recheck_Unpregnant), Label: "复检无胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_Recheck_Pregnant), Label: "复检有胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_Pause_Pregnant), Label: "停配", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.BreedStatus_No_Pregnant), Label: "禁配", Disabled: true, }) return breedStatusList } func (s *StoreEntry) CowKindEnumList() []*pasturePb.ConfigOptionsList { cowKindList := make([]*pasturePb.ConfigOptionsList, 0) cowKindList = append(cowKindList, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowKind_HST), Label: "荷斯坦", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowKind_JSN), Label: "娟姗牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowKind_SHN), Label: "三河牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowKind_XJHN), Label: "新疆褐牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowKind_MN), Label: "牦牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowKind_XMTEN), Label: "西门塔尔牛", Disabled: true, }) return cowKindList } func (s *StoreEntry) CowSourceEnumList() []*pasturePb.ConfigOptionsList { cowSourceList := make([]*pasturePb.ConfigOptionsList, 0) cowSourceList = append(cowSourceList, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowSource_Calving), Label: "产犊", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowSource_Transfer_In), Label: "调入", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowSource_Buy), Label: "购买", Disabled: true, }) return cowSourceList } func (s *StoreEntry) CowStatusEnumList() []*pasturePb.ConfigOptionsList { cowStatusList := make([]*pasturePb.ConfigOptionsList, 0) cowStatusList = append(cowStatusList, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_Calving), Label: "产犊", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_Empty), Label: "空怀", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_Breeding), Label: "配种", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_Pregnant), Label: "怀孕", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_Dry_Milk), Label: "干奶", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_Peripartum), Label: "围产", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowStatus_No_Pregnant), Label: "禁配", Disabled: true, }) return cowStatusList } func (s *StoreEntry) CowTypeEnumList() []*pasturePb.ConfigOptionsList { cowTypeList := make([]*pasturePb.ConfigOptionsList, 0) cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Lactating_Calf), Label: "哺乳犊牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Weaned_Calf), Label: "断奶犊牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Youth_Calf), Label: "青年牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Fattening_Calf), Label: "育肥牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Reserve_Calf), Label: "后备牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Breeding_Calf), Label: "种母牛", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CowType_Breeding_Bull), Label: "种公牛", Disabled: true, }) return cowTypeList } func (s *StoreEntry) SemeTimeCowTypeEnumList() []*pasturePb.ConfigOptionsList { cowTypeList := make([]*pasturePb.ConfigOptionsList, 0) 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 } 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{ Value: int32(pasturePb.TransferPenReason_Normal), Label: "正常转群", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.TransferPenReason_Feed), Label: "饲喂转群", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.TransferPenReason_Dry_Milk), Label: "干奶转群", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.TransferPenReason_Pregnant), Label: "怀孕转群", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.TransferPenReason_Overantibody), Label: "过抗转群", Disabled: true, }) return transferPenList } func (s *StoreEntry) ChildNumberEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ChildNumber_One), Label: "单胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ChildNumber_Two), Label: "双胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ChildNumber_Three), Label: "三胎", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ChildNumber_Four), Label: "四胎", Disabled: true, }) return configOptions } func (s *StoreEntry) CalvingLevelEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CalvingLevel_Natural_Childbirth), Label: "自然分娩", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery1), Label: "人工助产(1-2人)", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CalvingLevel_Artificial_Midwifery2), Label: "人工助产(3人以上)", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.CalvingLevel_Caesarean_Section), Label: "剖腹产", Disabled: true, }) return configOptions } func (s *StoreEntry) DystociaReasonEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.DystociaReason_Malposition), Label: "胎位不正", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.DystociaReason_Fetal_Overgrowth), Label: "胎儿过大", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.DystociaReason_Uterine_Atony), Label: "子宫收缩无力", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.DystociaReason_Pelvic_Stenosis), Label: "盆骨狭小", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.DystociaReason_Sub_Health), Label: "母牛亚健康状态", Disabled: true, }) return configOptions } func (s *StoreEntry) PregnantCheckResultEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckResult_InCheck_UnPregnant), Label: "初检未孕", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckResult_InCheck_Pregnant), Label: "初检已孕", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckResult_Recheck_UnPregnant), Label: "复检未孕", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckResult_Recheck_Pregnant), Label: "初检已孕", Disabled: true, }) return configOptions } func (s *StoreEntry) PregnantCheckMethodEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckMethod_B_Ultrasound), Label: "B超", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckMethod_Blood_Testing), Label: "血检", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.PregnantCheckMethod_Manual_Inspection), Label: "人工检查", Disabled: true, }) 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, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.DrugCategory_Immunity), 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, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Unit_ML), Label: "毫升", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Unit_L), Label: "升", Disabled: true, }) return configOptions } func (s *StoreEntry) ExposeEstrusTypeEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ExposeEstrusType_Neck_Ring), Label: "脖环揭发", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ExposeEstrusType_Foot_Ring), Label: "脚环/计步器揭发", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.ExposeEstrusType_Manual_Observation), Label: "人工观察", Disabled: true, }) return configOptions } func (s *StoreEntry) FrozenSemenTypeEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.FrozenSemenType_Ordinary), Label: "常规冻精", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.FrozenSemenType_Gender_Control), Label: "性控冻精", Disabled: true, }) return configOptions } func (s *StoreEntry) BullNumberEnumList() []*pasturePb.BullOptionsList { frozenSemenList := make([]*model.EventFrozenSemen, 0) bullNumberList := make([]*pasturePb.BullOptionsList, 0) if err := s.DB.Where("quantity > 0").Group("bull_id").Find(&frozenSemenList).Error; err != nil { zaplog.Error("BullNumberEnumList", zap.Any("Find", err)) } for _, v := range frozenSemenList { bullNumberList = append(bullNumberList, &pasturePb.BullOptionsList{ Value: v.BullId, Label: v.BullId, Disabled: true, }) } return bullNumberList } func (s *StoreEntry) WeekEnumList() []*pasturePb.ConfigOptionsList { configOptions := make([]*pasturePb.ConfigOptionsList, 0) configOptions = append(configOptions, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Monday), Label: "周一", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Tuesday), Label: "周二", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Wednesday), Label: "周三", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Thursday), Label: "周四", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Friday), Label: "周五", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Saturday), Label: "周六", Disabled: true, }, &pasturePb.ConfigOptionsList{ Value: int32(pasturePb.Week_Sunday), Label: "周日", Disabled: true, }) return configOptions } func (s *StoreEntry) DrugUsageMaps() map[pasturePb.DrugUsage_Kind]string { res := make(map[pasturePb.DrugUsage_Kind]string) for _, v := range s.DrugUsageEnumList() { res[pasturePb.DrugUsage_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) ExposeEstrusTypeMap() map[pasturePb.ExposeEstrusType_Kind]string { res := make(map[pasturePb.ExposeEstrusType_Kind]string) for _, v := range s.ExposeEstrusTypeEnumList() { res[pasturePb.ExposeEstrusType_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) FrozenSemenTypeMap() map[pasturePb.FrozenSemenType_Kind]string { res := make(map[pasturePb.FrozenSemenType_Kind]string) for _, v := range s.FrozenSemenTypeEnumList() { res[pasturePb.FrozenSemenType_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) UnitMap() map[pasturePb.Unit_Kind]string { res := make(map[pasturePb.Unit_Kind]string) for _, v := range s.UnitEnumList() { res[pasturePb.Unit_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) WeekMap() map[pasturePb.Week_Kind]string { res := make(map[pasturePb.Week_Kind]string) for _, v := range s.WeekEnumList() { res[pasturePb.Week_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) CowTypeMap() map[pasturePb.CowType_Kind]string { res := make(map[pasturePb.CowType_Kind]string) for _, v := range s.CowTypeEnumList() { res[pasturePb.CowType_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) CowStatusMap() map[pasturePb.CowStatus_Kind]string { res := make(map[pasturePb.CowStatus_Kind]string) for _, v := range s.CowStatusEnumList() { res[pasturePb.CowStatus_Kind(v.Value)] = v.Label } return res } func (s *StoreEntry) BarnTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.BarnTypeEnumList(), }, nil } func (s *StoreEntry) BarnListOptions(ctx context.Context, penType int) (*pasturePb.ConfigOptionsListResponse, error) { penList := make([]*model.Pen, 0) pref := s.DB.Table(new(model.Pen).TableName()). Where("is_delete = ?", pasturePb.IsShow_Ok) if penType != -1 { pref.Where("pen_type = ?", penType) } if err := pref.Find(&penList).Error; err != nil { return nil, err } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.PenSlice(penList).ToPB2(s.BarnTypeEnumList()), }, nil } func (s *StoreEntry) DiseaseTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { diseaseTypeList := make([]*model.ConfigDiseaseType, 0) pref := s.DB.Table(new(model.ConfigDiseaseType).TableName()). Where("is_show =? ", pasturePb.IsShow_Ok) if err := pref.Find(&diseaseTypeList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB2(), }, nil } func (s *StoreEntry) DiseaseOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { diseaseList := make([]*model.Disease, 0) pref := s.DB.Table(new(model.Disease).TableName()). Where("is_show =? ", pasturePb.IsShow_Ok) if err := pref.Find(&diseaseList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.DiseaseSlice(diseaseList).ToPB2(), }, nil } func (s *StoreEntry) BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.BreedStatusEnumList(), }, nil } func (s *StoreEntry) CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowKindEnumList(), }, nil } func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowSourceEnumList(), }, nil } func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowStatusEnumList(), }, nil } func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.CowTypeEnumList(), }, nil } func (s *StoreEntry) CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) { return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.TransferPenEnumList(), }, nil } func (s *StoreEntry) SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error) { systemUserList := make([]*model.SystemUser, 0) pref := s.DB.Table(new(model.SystemUser).TableName()). Where("is_delete = ?", pasturePb.IsShow_Ok). Where("is_show =? ", pasturePb.IsShow_Ok) if depId != -1 && depId > 0 { pref = pref.Where("dept_id = ?", depId) } if err := pref.Find(&systemUserList).Error; err != nil { return nil, xxerr.WithStack(err) } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: model.SystemUserSlice(systemUserList).ToPB2(), }, nil } func (s *StoreEntry) BullOptions(ctx context.Context) (*pasturePb.BullOptionsListResponse, error) { return &pasturePb.BullOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: s.BullNumberEnumList(), }, nil } func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName string) (*pasturePb.ConfigOptionsListResponse, error) { configOptions := make([]*pasturePb.ConfigOptionsList, 0) switch optionsName { case "childNumber": configOptions = s.ChildNumberEnumList() case "calvingLevel": configOptions = s.CalvingLevelEnumList() case "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() case "exposeEstrusType": configOptions = s.ExposeEstrusTypeEnumList() case "frozenSemenType": configOptions = s.FrozenSemenTypeEnumList() case "week": configOptions = s.WeekEnumList() case "sameTimeCowType": configOptions = s.SemeTimeCowTypeEnumList() case "immunizationCowType": configOptions = s.ImmunizationCowTypeEnumList() case "immunizationConditions": configOptions = s.ImmunizationConditionsEnumList() } return &pasturePb.ConfigOptionsListResponse{ Code: http.StatusOK, Message: "ok", Data: configOptions, }, nil }