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. )
  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 InitPassword = "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(InitPassword),
  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. ManagerPassword: v.ManagerPassword,
  44. ManagerPhone: v.ManagerPhone,
  45. Address: v.ManagerPassword,
  46. IsShow: v.IsShow,
  47. CreatedAt: v.CreatedAt,
  48. }
  49. }
  50. return res
  51. }
  52. func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest {
  53. return &operationPb.AddPastureRequest{
  54. Id: g.Id,
  55. Name: g.Name,
  56. ManagerUser: g.ManagerUser,
  57. ManagerPassword: g.ManagerPassword,
  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. Data []*operationPb.AddPastureRequest `json:"data"`
  68. }
  69. func (g *GroupPastureResponse) ToPB() *operationPb.SearchPastureResponse {
  70. return &operationPb.SearchPastureResponse{
  71. Page: g.Page,
  72. Total: g.Total,
  73. Data: g.Data,
  74. }
  75. }