group_pasture.go 2.3 KB

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