manager_del.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package house_rent
  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. func checkHouseRentDelManagerParam(req *pb_v1.HouseRentDelManagerRequest) error {
  18. switch {
  19. case req.GardenId < 1:
  20. return status.Error(10003, "小区不能为空")
  21. case req.Id < 1:
  22. return status.Error(10003, "绑定id不能为空")
  23. }
  24. return nil
  25. }
  26. //
  27. func HouseRentDelManager(ctx context.Context, req *pb_v1.HouseRentDelManagerRequest) (reply *pb_v1.HouseRentDelManagerReply, err error) {
  28. reply = &pb_v1.HouseRentDelManagerReply{}
  29. // 捕获各个task中的异常并返回给调用者
  30. defer func() {
  31. if r := recover(); r != nil {
  32. err = fmt.Errorf("%+v", r)
  33. e := &status.Status{}
  34. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  35. logger.Error("err",
  36. zap.String("system_err", err.Error()),
  37. zap.Stack("stacktrace"))
  38. }
  39. }
  40. }()
  41. // 参数检查
  42. err = checkHouseRentDelManagerParam(req)
  43. if err != nil {
  44. return nil, err
  45. }
  46. dbname := utils.GetGardenDbName(req.GardenId)
  47. p := dbmodel.NewHouseRentManager(dbname)
  48. where := map[string]interface{}{
  49. "id":req.Id,
  50. }
  51. err = p.Delete(database.DB(), where)
  52. if err != nil {
  53. return nil, errors.DataBaseError
  54. }
  55. return reply, nil
  56. }