group_pasture.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package model
  2. import (
  3. "kpt-tmr-group/pkg/tool"
  4. operationPb "kpt-tmr-group/proto/go/backend/operation"
  5. "time"
  6. )
  7. type GroupPasture struct {
  8. Id int64 `json:"id,omitempty"`
  9. Name string `json:"name,omitempty"`
  10. Account string `json:"account,omitempty"`
  11. Password string `json:"password"`
  12. ManagerUser string `json:"manager_user"`
  13. ManagerPhone string `json:"manager_phone"`
  14. IsShow operationPb.IsShow_Kind `json:"is_show,omitempty"`
  15. IsDelete operationPb.IsShow_Kind `json:"is_delete,omitempty"`
  16. Address string `json:"address"`
  17. CreatedAt int64 `json:"created_at,omitempty"`
  18. UpdatedAt int64 `json:"updated_at,omitempty"`
  19. }
  20. func (s *GroupPasture) TableName() string {
  21. return "group_pasture"
  22. }
  23. const InitManagerPassword = "123456"
  24. func NewGroupPasture(req *operationPb.AddPastureRequest) *GroupPasture {
  25. groupPasture := &GroupPasture{
  26. Name: req.Name,
  27. Account: req.Account,
  28. Password: tool.Md5String(InitManagerPassword),
  29. ManagerUser: req.ManagerUser,
  30. ManagerPhone: req.ManagerPhone,
  31. IsShow: operationPb.IsShow_OK,
  32. Address: req.Address,
  33. }
  34. return groupPasture
  35. }
  36. type GroupPastureSlice []*GroupPasture
  37. func (g GroupPastureSlice) ToPB() []*operationPb.AddPastureRequest {
  38. res := make([]*operationPb.AddPastureRequest, len(g))
  39. for i, v := range g {
  40. res[i] = &operationPb.AddPastureRequest{
  41. Id: v.Id,
  42. Name: v.Name,
  43. ManagerUser: v.ManagerUser,
  44. ManagerPhone: v.ManagerPhone,
  45. Address: v.Address,
  46. IsShow: v.IsShow,
  47. CreatedAt: v.CreatedAt,
  48. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  49. }
  50. }
  51. return res
  52. }
  53. func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest {
  54. return &operationPb.AddPastureRequest{
  55. Id: g.Id,
  56. Name: g.Name,
  57. ManagerUser: g.ManagerUser,
  58. ManagerPhone: g.ManagerPhone,
  59. Address: g.Address,
  60. IsShow: g.IsShow,
  61. CreatedAt: g.CreatedAt,
  62. }
  63. }
  64. type GroupPastureResponse struct {
  65. Page int32 `json:"page"`
  66. Total int32 `json:"total"`
  67. List []*operationPb.AddPastureRequest `json:"list"`
  68. }
  69. func (g *GroupPastureResponse) ToPB() *operationPb.SearchPastureResponse {
  70. return &operationPb.SearchPastureResponse{
  71. Page: g.Page,
  72. Total: g.Total,
  73. List: g.List,
  74. }
  75. }