cattle_category.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package model
  2. import (
  3. operationPb "kpt-tmr-group/proto/go/backend/operation"
  4. "time"
  5. )
  6. type CattleCategory struct {
  7. Id int64 `json:"id"`
  8. ParentId operationPb.CattleCategoryParent_Kind `json:"parent_id"`
  9. ParentName string `json:"parent_name"`
  10. Name string `json:"name"`
  11. Number string `json:"number"`
  12. IsShow operationPb.IsShow_Kind `json:"is_show"`
  13. IsDelete operationPb.IsShow_Kind `json:"is_delete"`
  14. CreatedAt int64 `json:"created_at"`
  15. UpdatedAt int64 `json:"updated_at"`
  16. }
  17. func (s *CattleCategory) TableName() string {
  18. return "cattle_category"
  19. }
  20. func NewCattleCategory(req *operationPb.AddCattleCategoryRequest) *CattleCategory {
  21. return &CattleCategory{
  22. ParentId: req.ParentId,
  23. ParentName: req.ParentName,
  24. Name: req.Name,
  25. Number: req.Number,
  26. IsShow: operationPb.IsShow_OK,
  27. IsDelete: operationPb.IsShow_OK,
  28. }
  29. }
  30. type CattleCategorySlice []*CattleCategory
  31. func (c CattleCategorySlice) ToPB() []*operationPb.AddCattleCategoryRequest {
  32. res := make([]*operationPb.AddCattleCategoryRequest, len(c))
  33. for i, v := range c {
  34. res[i] = &operationPb.AddCattleCategoryRequest{
  35. Id: v.Id,
  36. Name: v.Name,
  37. ParentId: v.ParentId,
  38. ParentName: v.ParentName,
  39. Number: v.Number,
  40. IsShow: v.IsShow,
  41. CreatedAt: v.CreatedAt,
  42. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  43. }
  44. }
  45. return res
  46. }
  47. func (c *CattleCategory) ToPb() *operationPb.AddCattleCategoryRequest {
  48. return &operationPb.AddCattleCategoryRequest{
  49. Id: c.Id,
  50. Name: c.Name,
  51. Number: c.Number,
  52. ParentId: c.ParentId,
  53. ParentName: c.ParentName,
  54. IsShow: c.IsShow,
  55. CreatedAt: c.CreatedAt,
  56. }
  57. }
  58. type CattleCategoryResponse struct {
  59. Page int32 `json:"page"`
  60. Total int32 `json:"total"`
  61. List []*operationPb.AddCattleCategoryRequest `json:"list"`
  62. }
  63. func (c *CattleCategoryResponse) ToPB() *operationPb.SearchCattleCategoryResponse {
  64. return &operationPb.SearchCattleCategoryResponse{
  65. Page: c.Page,
  66. Total: c.Total,
  67. List: c.List,
  68. }
  69. }