group_pasture.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. IsDelete: operationPb.IsShow_OK,
  33. Address: req.Address,
  34. }
  35. return groupPasture
  36. }
  37. type GroupPastureSlice []*GroupPasture
  38. func (g GroupPastureSlice) ToPB() []*operationPb.AddPastureRequest {
  39. res := make([]*operationPb.AddPastureRequest, len(g))
  40. for i, v := range g {
  41. res[i] = &operationPb.AddPastureRequest{
  42. Id: int32(v.Id),
  43. Name: v.Name,
  44. Account: v.Account,
  45. ManagerUser: v.ManagerUser,
  46. ManagerPhone: v.ManagerPhone,
  47. Address: v.Address,
  48. IsShow: v.IsShow,
  49. CreatedAt: int32(v.CreatedAt),
  50. CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
  51. }
  52. }
  53. return res
  54. }
  55. func (g *GroupPasture) ToPb() *operationPb.AddPastureRequest {
  56. return &operationPb.AddPastureRequest{
  57. Id: int32(g.Id),
  58. Name: g.Name,
  59. ManagerUser: g.ManagerUser,
  60. ManagerPhone: g.ManagerPhone,
  61. Address: g.Address,
  62. IsShow: g.IsShow,
  63. CreatedAt: int32(g.CreatedAt),
  64. }
  65. }