info.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package msg_package
  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. "gorm.io/gorm"
  13. "property-common/errors"
  14. dbmodel "property-common/model"
  15. pb_v1 "property-common/pb/v1"
  16. )
  17. func checkMsgPackageInfoParam(req *pb_v1.MsgPackageInfoRequest) error {
  18. if req.Id == 0 {
  19. return status.Error(10003, "id 不能为空")
  20. }
  21. return nil
  22. }
  23. //
  24. func MsgPackageInfo(ctx context.Context, req *pb_v1.MsgPackageInfoRequest) (reply *pb_v1.MsgPackageInfoReply, err error) {
  25. reply = &pb_v1.MsgPackageInfoReply{}
  26. // 捕获各个task中的异常并返回给调用者
  27. defer func() {
  28. if r := recover(); r != nil {
  29. err = fmt.Errorf("%+v", r)
  30. e := &status.Status{}
  31. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  32. logger.Error("err",
  33. zap.String("system_err", err.Error()),
  34. zap.Stack("stacktrace"))
  35. }
  36. }
  37. }()
  38. // 参数检查
  39. err = checkMsgPackageInfoParam(req)
  40. if err != nil {
  41. return nil, err
  42. }
  43. p := &dbmodel.TMsgPackage{}
  44. where := map[string]interface{}{
  45. "id": req.Id,
  46. }
  47. err = p.Find(database.DB(), where)
  48. if err != nil && err != gorm.ErrRecordNotFound {
  49. return nil, errors.DataBaseError
  50. }
  51. if p.ID == 0 {
  52. return nil, errors.ErrRecordNotFound
  53. }
  54. // 获取套餐的应用id
  55. reply.MsgCount = p.MsgCount
  56. reply.Id = p.ID
  57. reply.Name = p.Name
  58. reply.Comment = p.Comment
  59. reply.Price = p.Price
  60. return reply, nil
  61. }