del.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 system_msg
  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 isParkBindCharge(id int64, dbname string) (bool, error) {
  19. p := dbmodel.NewChargeSpace(dbname)
  20. where := map[string]interface{}{
  21. "park_id":id,
  22. }
  23. count, err := p.Count(database.DB(), where, nil)
  24. if err != nil {
  25. return false, errors.DataBaseError
  26. }
  27. if count > 0 {
  28. return true, nil
  29. }
  30. return false, nil
  31. }
  32. */
  33. //
  34. func SystemMsgReaded(ctx context.Context, req *pb_v1.SystemMsgReadedRequest) (reply *pb_v1.SystemMsgReadedReply, err error) {
  35. reply = &pb_v1.SystemMsgReadedReply{}
  36. // 捕获各个task中的异常并返回给调用者
  37. defer func() {
  38. if r := recover(); r != nil {
  39. err = fmt.Errorf("%+v", r)
  40. e := &status.Status{}
  41. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  42. logger.Error("err",
  43. zap.String("system_err", err.Error()),
  44. zap.Stack("stacktrace"))
  45. }
  46. }
  47. }()
  48. // 参数检查
  49. if len(req.Id) < 1 || req.GardenId < 1 {
  50. return nil, errors.ParamsError
  51. }
  52. dbname := utils.GetGardenDbName(req.GardenId)
  53. p := dbmodel.NewMsg(dbname)
  54. where := map[string]interface{}{
  55. "id in": req.Id,
  56. }
  57. err = p.Delete(database.DB(), where)
  58. if err != nil {
  59. return nil, errors.DataBaseError
  60. }
  61. return reply, nil
  62. }