sign_list.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package event
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "property-garden/errors"
  13. dbmodel "property-garden/model"
  14. pb_v1 "property-garden/pb/v1"
  15. "property-garden/utils"
  16. )
  17. //
  18. func EventSignList(ctx context.Context, req *pb_v1.EventSignListRequest) (reply *pb_v1.EventSignListReply, err error) {
  19. reply = &pb_v1.EventSignListReply{}
  20. // 捕获各个task中的异常并返回给调用者
  21. defer func() {
  22. if r := recover(); r != nil {
  23. err = fmt.Errorf("%+v", r)
  24. e := &status.Status{}
  25. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  26. logger.Error("err",
  27. zap.String("system_err", err.Error()),
  28. zap.Stack("stacktrace"))
  29. }
  30. }
  31. }()
  32. if req.GardenId < 1 || req.EventId < 1{
  33. return nil, errors.ParamsError
  34. }
  35. if req.Page == 0 {
  36. req.Page = 1
  37. }
  38. if req.PageSize == 0 {
  39. req.PageSize = 10
  40. }
  41. dbname := utils.GetGardenDbName(req.GardenId)
  42. p := dbmodel.NewEventSign(dbname)
  43. where := map[string]interface{}{
  44. "event_id":req.EventId,
  45. }
  46. reply.Total, err = p.Count(database.DB(), where, nil)
  47. if err != nil {
  48. return nil, errors.DataBaseError
  49. }
  50. reply.Page = req.Page
  51. if reply.Total == 0 {
  52. return reply, nil
  53. }
  54. list, err := p.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
  55. if err != nil {
  56. return nil, errors.DataBaseError
  57. }
  58. reply.List = make([]*pb_v1.EventSignItem, len(list))
  59. for i, v := range list {
  60. reply.List[i] = &pb_v1.EventSignItem{
  61. Id:v.ID,
  62. Name:v.Name,
  63. Phone:v.Phone,
  64. Comment:v.Comment,
  65. Count:v.SignCount,
  66. SignTime:v.CreatedAt.Format("2006-01-02 15:04:05"),
  67. }
  68. }
  69. return reply, nil
  70. }