|
@@ -46,7 +46,7 @@ func (s *StoreEntry) SearchBarnList(ctx context.Context, req *pasturePb.SearchNa
|
|
|
|
|
|
func (s *StoreEntry) CreateOrUpdateBarn(ctx context.Context, req *pasturePb.SearchBarnList) error {
|
|
|
if req.Id > 0 {
|
|
|
- barn := &model.Bran{Id: req.Id}
|
|
|
+ barn := &model.Bran{Id: int64(req.Id)}
|
|
|
if err := s.DB.Model(&model.Bran{}).First(barn).Error; err != nil {
|
|
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
return xerr.WithStack(err)
|
|
@@ -101,7 +101,7 @@ func (s *StoreEntry) SearchBarnTypeList(ctx context.Context, req *pasturePb.Sear
|
|
|
|
|
|
func (s *StoreEntry) CreateOrUpdateBarnType(ctx context.Context, req *pasturePb.SearchBaseConfigList) error {
|
|
|
if req.Id > 0 {
|
|
|
- barn := &model.ConfigBarnType{Id: req.Id}
|
|
|
+ barn := &model.ConfigBarnType{Id: int64(req.Id)}
|
|
|
if err := s.DB.Model(&model.ConfigBarnType{}).First(barn).Error; err != nil {
|
|
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
return xerr.WithStack(err)
|
|
@@ -120,3 +120,51 @@ func (s *StoreEntry) CreateOrUpdateBarnType(ctx context.Context, req *pasturePb.
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *StoreEntry) SearchBreedStatusList(ctx context.Context, req *pasturePb.SearchNameRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchBaseConfigResponse, error) {
|
|
|
+ breedStatusList := make([]*model.ConfigBreedStatus, 0)
|
|
|
+ var count int64 = 0
|
|
|
+
|
|
|
+ pref := s.DB.Model(new(model.ConfigBreedStatus))
|
|
|
+ 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(&breedStatusList).Debug().Error; err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return &pasturePb.SearchBaseConfigResponse{
|
|
|
+ Code: http.StatusOK,
|
|
|
+ Message: "ok",
|
|
|
+ Data: &pasturePb.SearchBaseConfigData{
|
|
|
+ List: model.ConfigBreedStatusSlice(breedStatusList).ToPB2(),
|
|
|
+ Total: int32(count),
|
|
|
+ PageSize: pagination.PageSize,
|
|
|
+ Page: pagination.Page,
|
|
|
+ },
|
|
|
+ }, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *StoreEntry) CreateOrUpdateBreedStatus(ctx context.Context, req *pasturePb.SearchBaseConfigList) error {
|
|
|
+ if req.Id > 0 {
|
|
|
+ barn := &model.ConfigBreedStatus{Id: int64(req.Id)}
|
|
|
+ if err := s.DB.Model(&model.ConfigBreedStatus{}).First(barn).Error; err != nil {
|
|
|
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := s.DB.Model(&model.ConfigBreedStatus{}).Where(map[string]interface{}{
|
|
|
+ "id": req.Id,
|
|
|
+ }).Assign(map[string]interface{}{
|
|
|
+ "name": req.Name,
|
|
|
+ "remarks": req.Remarks,
|
|
|
+ "is_show": pasturePb.IsShow_Ok,
|
|
|
+ }).FirstOrCreate(&model.ConfigBreedStatus{}).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|