manager_del.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package house
  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 checkBuildingDelManagerParam(req *pb_v1.BuildingDelManagerRequest) 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 BuildingDelManager(ctx context.Context, req *pb_v1.BuildingDelManagerRequest) (reply *pb_v1.BuildingDelManagerReply, err error) {
  28. reply = &pb_v1.BuildingDelManagerReply{}
  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 = checkBuildingDelManagerParam(req)
  43. if err != nil {
  44. return nil, err
  45. }
  46. dbname := utils.GetGardenDbName(req.GardenId)
  47. p := dbmodel.NewBuildingManager(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. }