group_pasture.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 GroupPastureSlice) ToPermissionsPB() []*operationPb.AddPastureRequest {
  49. res := make([]*operationPb.AddPastureRequest, len(g))
  50. for i, v := range g {
  51. res[i] = &operationPb.AddPastureRequest{
  52. Id: v.Id,
  53. Name: v.Name,
  54. }
  55. }
  56. return res
  57. }
  58. func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest {
  59. return &operationPb.AddPastureRequest{
  60. Id: g.Id,
  61. Name: g.Name,
  62. ManagerUser: g.ManagerUser,
  63. ManagerPhone: g.ManagerPhone,
  64. Address: g.Address,
  65. IsShow: g.IsShow,
  66. CreatedAt: g.CreatedAt,
  67. }
  68. }
  69. type GroupPastureResponse struct {
  70. Page int32 `json:"page"`
  71. Total int32 `json:"total"`
  72. List []*operationPb.AddPastureRequest `json:"list"`
  73. }
  74. func (g *GroupPastureResponse) ToPB() *operationPb.SearchPastureResponse {
  75. return &operationPb.SearchPastureResponse{
  76. Page: g.Page,
  77. Total: g.Total,
  78. List: g.List,
  79. }
  80. }