feed_template.go 4.3 KB

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