1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package backend
- import (
- "context"
- "encoding/json"
- "kpt-pasture/model"
- "gitee.com/xuyiping_admin/pkg/xerr"
- )
- // AFIMILK 阿菲金品牌实现
- type AFIMILK struct {
- store *StoreEntry
- body *model.MilkHallBody
- }
- func (a *AFIMILK) SaveData(ctx context.Context) error {
- contentList := a.body.Content
- if len(contentList) <= 0 {
- return nil
- }
- pastureData := &model.AppPastureList{}
- if err := a.store.DB.Model(pastureData).
- Where("farm_id = ?", a.body.FarmId).
- First(pastureData).Error; err != nil {
- return xerr.WithStack(err)
- }
- milkOriginalList := make([]*model.MilkOriginal, 0)
- for _, content := range contentList {
- afiMilkOriginalData := &model.AFIMilkHallOriginal{}
- if err := json.Unmarshal([]byte(content.(string)), afiMilkOriginalData); err != nil {
- return xerr.WithStack(err)
- }
- milkOriginalList = append(milkOriginalList, model.NewAFIMilkOriginal(pastureData.Id, a.body.MilkHallNumber, afiMilkOriginalData))
- }
- if len(milkOriginalList) > 0 {
- if err := a.store.DB.Model(new(model.MilkOriginal)).
- Create(milkOriginalList).Error; err != nil {
- return xerr.WithStack(err)
- }
- }
- return nil
- }
- type AFI struct {
- store *StoreEntry
- body *model.MilkHallBody
- }
- func (a *AFI) SaveData(ctx context.Context) error {
- return nil
- }
|