group_pasture.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }