group_pasture.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 NewGroupPastureList(reqs []*operationPb.AddPastureRequest) []*GroupPasture {
  22. groupPastureList := make([]*GroupPasture, len(reqs))
  23. for k, pasture := range reqs {
  24. groupPastureList[k] = &GroupPasture{
  25. Name: pasture.Name,
  26. ManagerUser: pasture.ManagerUser,
  27. ManagerPassword: tool.Md5String(InitManagerPassword),
  28. ManagerPhone: pasture.ManagerPhone,
  29. IsShow: operationPb.IsShow_OK,
  30. Address: pasture.Address,
  31. }
  32. }
  33. return groupPastureList
  34. }
  35. type GroupPastureSlice []*GroupPasture
  36. func (g GroupPastureSlice) ToPB() []*operationPb.AddPastureRequest {
  37. res := make([]*operationPb.AddPastureRequest, len(g))
  38. for i, v := range g {
  39. res[i] = &operationPb.AddPastureRequest{
  40. Id: v.Id,
  41. Name: v.Name,
  42. ManagerUser: v.ManagerUser,
  43. ManagerPhone: v.ManagerPhone,
  44. Address: v.Address,
  45. IsShow: v.IsShow,
  46. CreatedAt: v.CreatedAt,
  47. }
  48. }
  49. return res
  50. }
  51. func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest {
  52. return &operationPb.AddPastureRequest{
  53. Id: g.Id,
  54. Name: g.Name,
  55. ManagerUser: g.ManagerUser,
  56. ManagerPhone: g.ManagerPhone,
  57. Address: g.Address,
  58. IsShow: g.IsShow,
  59. CreatedAt: g.CreatedAt,
  60. }
  61. }
  62. type GroupPastureResponse struct {
  63. Page int32 `json:"page"`
  64. Total int32 `json:"total"`
  65. List []*operationPb.AddPastureRequest `json:"list"`
  66. }
  67. func (g *GroupPastureResponse) ToPB() *operationPb.SearchPastureResponse {
  68. return &operationPb.SearchPastureResponse{
  69. Page: g.Page,
  70. Total: g.Total,
  71. List: g.List,
  72. }
  73. }