123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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
- }
- }
|