feed_template.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package models
  2. import (
  3. "fmt"
  4. "time"
  5. "tmr-watch/pkg/logger/zaplog"
  6. "go.uber.org/zap"
  7. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  8. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/pasture"
  9. )
  10. type FeedTemplate struct {
  11. Id int64 `xorm:"id" json:"id"`
  12. PastureId int64 `xorm:"pastureid" json:"pasture_id"`
  13. TCode string `xorm:"tcode" json:"t_code"`
  14. TName string `xorm:"tname" json:"t_name"`
  15. TColor string `xorm:"tcolor" json:"t_color"`
  16. CCid int64 `xorm:"ccid" json:"c_cid"`
  17. CCName string `xorm:"ccname" json:"cc_name"`
  18. FTType string `xorm:"fttype" json:"ft_type"`
  19. FTTypeId int32 `xorm:"fttypeid" json:"ft_type_id"`
  20. Source string `xorm:"source" json:"source"`
  21. Remark string `xorm:"remark" json:"remark"`
  22. Enable int32 `xorm:"enable" json:"enable"`
  23. Sort int64 `xorm:"sort" json:"sort"`
  24. Owner string `xorm:"owner" json:"owner"`
  25. Weight float64 `xorm:"weight" json:"weight"`
  26. DryWeight float64 `xorm:"dryweight" json:"dry_weight"`
  27. IsDelete int32 `xorm:"isdelete" json:"is_delete"`
  28. Version int64 `xorm:"version" json:"version"`
  29. SaveTime string `xorm:"savetime" json:"save_time"`
  30. IsIssue int32 `xorm:"isissue" json:"is_issue"`
  31. IssueVersion int32 `xorm:"issueversion" json:"issue_version"`
  32. IssueId int64 `xorm:"issueid" json:"issue_id"`
  33. Backup1 string `xorm:"backup1" json:"backup1"`
  34. Backup2 string `xorm:"backup2" json:"backup2"`
  35. IsModify int32 `xorm:"is_modify" json:"is_modify"`
  36. GroupDataId int64 `xorm:"group_data_id" json:"group_data_id"`
  37. GroupVersion int64 `xorm:"group_version" json:"group_version"`
  38. FeedFormulaDetail []*FeedTemplateDetail `xorm:"-" json:"feed_formula_detail"`
  39. }
  40. func (f *FeedTemplate) TableName() string {
  41. return "feedtemplet"
  42. }
  43. func NewFeedTemplateByGroup(req *operationPb.DistributeFeedRequest) *FeedTemplate {
  44. zaplog.Info("NewFeedTemplateByGroup",
  45. zap.Any("PastureId-int64", int64(req.PastureDataId)),
  46. zap.Any("PastureId", req.PastureDataId),
  47. zap.Any("req", req),
  48. )
  49. res := &FeedTemplate{
  50. PastureId: int64(req.PastureId),
  51. TCode: req.EncodeNumber,
  52. TName: req.Name,
  53. TColor: req.Colour,
  54. CCid: int64(req.CattleCategoryId),
  55. CCName: req.CattleCategoryName,
  56. FTType: req.FormulaTypeName,
  57. FTTypeId: int32(req.FormulaTypeId),
  58. Source: "集团下发",
  59. Remark: req.Remarks,
  60. Enable: 1,
  61. Version: int64(req.Version),
  62. SaveTime: time.Now().Format("2006-01-02 15:04:05"),
  63. IsIssue: 0,
  64. IssueVersion: 0,
  65. IssueId: 0,
  66. IsModify: int32(req.IsModify),
  67. GroupDataId: int64(req.Id),
  68. GroupVersion: int64(req.Version),
  69. }
  70. res.FeedFormulaDetail = make([]*FeedTemplateDetail, 0)
  71. for _, v := range req.FeedFormulaDetail {
  72. res.FeedFormulaDetail = append(res.FeedFormulaDetail, &FeedTemplateDetail{
  73. PastureId: int64(req.PastureId),
  74. FId: int64(v.ForageId),
  75. FName: v.ForageName,
  76. FWeight: float64(v.Weight / 100),
  77. IsLockCount: v.IsLockCowCountRatio,
  78. Sort: v.Sort,
  79. FeedGroup: v.ForageGroupName,
  80. PreFtId: int64(v.PreFit),
  81. AutoSecond: v.StirDelay,
  82. AutoSecondName: "",
  83. SplitFtPreId: 0,
  84. Deviation: v.AllowError,
  85. IsModify: int32(v.IsModify),
  86. })
  87. }
  88. return res
  89. }
  90. type FeedTemplateSlice []*FeedTemplate
  91. func (f FeedTemplateSlice) ToPB(feedDetailVersionLogs []*FeedDetailVersion) []*pasturePb.FeedTemplateDataList {
  92. res := make([]*pasturePb.FeedTemplateDataList, len(f))
  93. for i, v := range f {
  94. var isUpdate int32 = 2
  95. if v.GroupDataId > 0 {
  96. for _, l := range feedDetailVersionLogs {
  97. if l.Belong == 2 && v.GroupDataId == l.FeedTemplateId && int32(v.GroupVersion) < l.GroupVersion {
  98. isUpdate = 1
  99. }
  100. }
  101. } else {
  102. for _, l := range feedDetailVersionLogs {
  103. if l.Belong == 1 && v.Id == l.FeedTemplateId && int32(v.GroupVersion) < l.GroupVersion {
  104. isUpdate = 1
  105. }
  106. }
  107. }
  108. res[i] = &pasturePb.FeedTemplateDataList{
  109. Id: fmt.Sprintf("%d", v.Id),
  110. Name: v.TName,
  111. Code: v.TCode,
  112. Color: v.TColor,
  113. CattleCategoryId: int32(v.CCid),
  114. CattleCategoryName: v.CCName,
  115. FormulaTypeId: v.FTTypeId,
  116. FormulaTypeName: v.FTType,
  117. Source: v.Source,
  118. Remark: v.Remark,
  119. Version: int32(v.Version),
  120. Enable: v.Enable,
  121. IsModify: v.IsModify,
  122. IsUpdate: isUpdate,
  123. }
  124. }
  125. return res
  126. }