appointment_del.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-household/errors"
  13. dbmodel "property-household/model"
  14. pb_v1 "property-household/pb/v1"
  15. )
  16. //
  17. func HouseRentAppointmentDel(ctx context.Context, req *pb_v1.HouseRentAppointmentDelRequest) (reply *pb_v1.HouseRentAppointmentDelReply, err error) {
  18. reply = &pb_v1.HouseRentAppointmentDelReply{}
  19. // 捕获各个task中的异常并返回给调用者
  20. defer func() {
  21. if r := recover(); r != nil {
  22. err = fmt.Errorf("%+v", r)
  23. e := &status.Status{}
  24. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  25. logger.Error("err",
  26. zap.String("system_err", err.Error()),
  27. zap.Stack("stacktrace"))
  28. }
  29. }
  30. }()
  31. // 参数检查
  32. if req.Id < 1 && len(req.RentIds) == 0 {
  33. return nil, errors.ParamsError
  34. }
  35. p := dbmodel.THouseRentAppointment{}
  36. where := map[string]interface{}{}
  37. if req.Id > 0 {
  38. where["id"] = req.Id
  39. }
  40. if len(req.RentIds) > 0 {
  41. where["rent_id in"] = req.RentIds
  42. }
  43. err = p.Delete(database.DB(), where)
  44. if err != nil {
  45. return nil, errors.DataBaseError
  46. }
  47. return reply, nil
  48. }