123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package backend
- import (
- "kpt-pasture/model"
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
- "go.uber.org/zap"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- func (s *StoreEntry) DeathReasonEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigDeathReason, 0)
- pref := s.DB.Model(new(model.ConfigDeathReason)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.DeathReason_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.DeathReason_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("DeathReasonEnumList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigDeathReasonSlice(dataList).ToPB(userModel)
- }
- func (s *StoreEntry) MatingResultEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigMatingResult, 0)
- pref := s.DB.Model(new(model.ConfigMatingResult)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.MatingResult_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.MatingResult_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("MatingResultEnumList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigMatingResultSlice(dataList).ToPB(userModel)
- }
- func (s *StoreEntry) EventCategoryEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigEventCategory, 0)
- pref := s.DB.Model(new(model.ConfigEventCategory)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.EventCategory_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.EventCategory_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("EventCategoryEnumList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigEventCategorySlice(dataList).ToPB(userModel)
- }
- func (s *StoreEntry) IndicatorsCategoryEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigIndicatorsCategory, 0)
- pref := s.DB.Model(new(model.ConfigIndicatorsCategory)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.IndicatorType_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.IndicatorType_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("IndicatorsCategoryEnumList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigIndicatorsCategorySlice(dataList).ToPB(userModel)
- }
- func (s *StoreEntry) IndicatorsDetailsList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- indicatorsDetailsList, _ := s.FindIndicatorsDetailsList()
- if len(indicatorsDetailsList) <= 0 {
- return configOptions
- }
- for _, v := range indicatorsDetailsList {
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Label: v.Name,
- Disabled: true,
- Props: v.Kind,
- })
- }
- return configOptions
- }
- func (s *StoreEntry) CowPurposeList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigCowPurpose, 0)
- pref := s.DB.Model(new(model.ConfigCowPurpose)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.Purpose_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.Purpose_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("CowPurposeList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigCowPurposeSlice(dataList).ToPB(userModel)
- }
- func (s *StoreEntry) CowOutReasonEnumList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigCowOutReason, 0)
- pref := s.DB.Model(new(model.ConfigCowOutReason)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.OutReasons_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.OutReasons_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("CowOutReasonList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigCowOutReasonSlice(dataList).ToPB(userModel)
- }
- func (s *StoreEntry) CowDeathDestinationList(userModel *model.UserModel, isAll string) []*pasturePb.ConfigOptionsList {
- dataList := make([]*model.ConfigCowDeathDestination, 0)
- pref := s.DB.Model(new(model.ConfigCowDeathDestination)).
- Where("is_show =? ", pasturePb.IsShow_Ok).
- Where("pasture_id =? ", userModel.AppPasture.Id)
- if isAll == model.IsAllYes {
- pref = pref.Where("kind >= ?", pasturePb.DeathDestination_Invalid)
- } else {
- pref = pref.Where("kind > ?", pasturePb.DeathDestination_Invalid)
- }
- if err := pref.Order("kind ASC").
- Find(&dataList).Error; err != nil {
- zaplog.Error("CowDeathDestinationList", zap.Any("err", err))
- return make([]*pasturePb.ConfigOptionsList, 0)
- }
- return model.ConfigCowDeathDestinationSlice(dataList).ToPB(userModel)
- }
|