package group import ( "context" "net/http" "tmr-watch/models" "tmr-watch/module" feedPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/pasture" ) func SearchFeedTemplateList(ctx context.Context, req *feedPb.SearchFeedTemplateRequest) (*feedPb.SearchFeedTemplateResponse, error) { feedTemplateList, total, err := module.NewSearchFeedTemplateList(ctx, req) if err != nil { return nil, err } feedDetailVersionLogList, err := module.FeedDetailVersionLogList(ctx) if err != nil { return nil, err } res := &feedPb.SearchFeedTemplateResponse{ Code: http.StatusOK, Msg: "ok", Data: &feedPb.FeedTemplateData{ Page: req.Pagination.Page, PageSize: req.Pagination.PageSize, Total: int32(total), List: models.FeedTemplateSlice(feedTemplateList).ToPB(feedDetailVersionLogList), }, } return res, nil } func GetFeetTemplateVersion(ctx context.Context, pastureId, feedTemplateId int) (*feedPb.GetFeetTemplateVersionResponse, error) { feedTemplateData, err := module.SearchFeedTemplateById(ctx, int64(pastureId), int64(feedTemplateId)) if err != nil { return nil, err } historyFeedTemplateDetailList, err := module.SearchFeedTemplateDetailListByFeedTemplateId(ctx, int64(pastureId), int64(feedTemplateId)) if err != nil { return nil, err } newFeedTemplateDetailVersion, err := module.GetFeedDetailVersionByDesc(ctx, int64(pastureId), feedTemplateData.GroupDataId) if err != nil { return nil, err } newFeedTemplateDetailVersionLogList, err := module.SearchFeedDetailVersionLogById(ctx, int64(pastureId), feedTemplateData.GroupDataId, newFeedTemplateDetailVersion.Id) if err != nil { return nil, err } res := &feedPb.GetFeetTemplateVersionResponse{ Code: http.StatusOK, Msg: "ok", Data: &feedPb.FeetTemplateVersionData{ Version: int32(newFeedTemplateDetailVersion.Id), List: make([]*feedPb.FeetTemplateVersionList, 0), }, } // 比例两个配方饲料的不同 for _, n := range newFeedTemplateDetailVersionLogList { // 更新 for _, v := range historyFeedTemplateDetailList { if v.FName == n.ForageName { res.Data.List = append(res.Data.List, &feedPb.FeetTemplateVersionList{ ForageName: v.FName, ForageGroupNameOld: n.ForageName, ForageGroupName: v.FeedGroup, ForageNameOld: n.ForageGroupName, Weight: float32(v.LWeight), WeightOld: float32(n.Weight), StirDelay: v.AutoSecond, StirDelayOld: n.StirDelay, AllowError: v.Deviation, AllowErrorOld: n.AllowError, Sort: v.Sort, SortOld: n.Sort, IsLockCowCountRatio: v.IsLockCount, IsLockCowCountRatioOld: int32(n.IsLockCowCountRatio), IsModify: v.IsModify, Status: feedPb.VersionStatus_UPDATE, }) } } // 新增 var insertInfo bool for _, v := range historyFeedTemplateDetailList { if v.FName == n.ForageName { insertInfo = true } } if !insertInfo { res.Data.List = append(res.Data.List, &feedPb.FeetTemplateVersionList{ ForageName: n.ForageName, ForageGroupName: n.ForageGroupName, Weight: float32(n.Weight), StirDelay: n.StirDelay, AllowError: n.AllowError, Sort: n.Sort, IsLockCowCountRatio: int32(n.IsLockCowCountRatio), Status: feedPb.VersionStatus_ADD, }) } } // 删除 for _, v := range historyFeedTemplateDetailList { var deleteInfo bool for _, n := range newFeedTemplateDetailVersionLogList { if v.FName == n.ForageName { deleteInfo = true break } } if !deleteInfo { res.Data.List = append(res.Data.List, &feedPb.FeetTemplateVersionList{ ForageName: v.FName, ForageGroupName: v.FeedGroup, Weight: float32(v.LWeight), StirDelay: v.AutoSecond, AllowError: v.Deviation, Sort: v.Sort, IsLockCowCountRatio: int32(v.IsLockCount), Status: feedPb.VersionStatus_DELETE, }) } } return res, nil } func FeetTemplateUpgradeNewVersion(ctx context.Context, pastureId, feedTemplateId int) error { if err := module.FeetTemplateUpgradeNewVersion(ctx, int64(pastureId), int64(feedTemplateId)); err != nil { return err } else { return nil } }