milk_afimilk.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package backend
  2. import (
  3. "context"
  4. "encoding/json"
  5. "kpt-pasture/model"
  6. "gitee.com/xuyiping_admin/pkg/xerr"
  7. )
  8. // AFIMILK 阿菲金品牌实现
  9. type AFIMILK struct {
  10. store *StoreEntry
  11. body *model.MilkHallBody
  12. }
  13. func (a *AFIMILK) SaveData(ctx context.Context) error {
  14. contentList := a.body.Content
  15. if len(contentList) <= 0 {
  16. return nil
  17. }
  18. pastureData := &model.AppPastureList{}
  19. if err := a.store.DB.Model(pastureData).
  20. Where("farm_id = ?", a.body.FarmId).
  21. First(pastureData).Error; err != nil {
  22. return xerr.WithStack(err)
  23. }
  24. milkOriginalList := make([]*model.MilkOriginal, 0)
  25. for _, content := range contentList {
  26. afiMilkOriginalData := &model.AFIMilkHallOriginal{}
  27. if err := json.Unmarshal([]byte(content.(string)), afiMilkOriginalData); err != nil {
  28. return xerr.WithStack(err)
  29. }
  30. milkOriginalList = append(milkOriginalList, model.NewAFIMilkOriginal(pastureData.Id, a.body.MilkHallNumber, afiMilkOriginalData))
  31. }
  32. if len(milkOriginalList) > 0 {
  33. if err := a.store.DB.Model(new(model.MilkOriginal)).
  34. Create(milkOriginalList).Error; err != nil {
  35. return xerr.WithStack(err)
  36. }
  37. }
  38. return nil
  39. }
  40. type AFI struct {
  41. store *StoreEntry
  42. body *model.MilkHallBody
  43. }
  44. func (a *AFI) SaveData(ctx context.Context) error {
  45. return nil
  46. }