feed_template.go 4.4 KB

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