del_apply.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-household/errors"
  13. dbmodel "property-household/model"
  14. pb_v1 "property-household/pb/v1"
  15. "time"
  16. )
  17. func checkHouseholdDelApplyParam(req *pb_v1.HouseholdDelApplyRequest) error {
  18. switch {
  19. case req.Id > 0:
  20. return nil
  21. case req.HouseId > 0:
  22. return nil
  23. case req.GardenId > 0 :
  24. return nil
  25. case req.BuildingId > 0:
  26. return nil
  27. case req.UnitId > 0:
  28. return nil
  29. }
  30. return errors.ParamsError
  31. }
  32. //
  33. func HouseholdDelApply(ctx context.Context, req *pb_v1.HouseholdDelApplyRequest) (reply *pb_v1.HouseholdDelApplyReply, err error) {
  34. reply = &pb_v1.HouseholdDelApplyReply{}
  35. // 捕获各个task中的异常并返回给调用者
  36. defer func() {
  37. if r := recover(); r != nil {
  38. err = fmt.Errorf("%+v", r)
  39. e := &status.Status{}
  40. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  41. logger.Error("err",
  42. zap.String("system_err", err.Error()),
  43. zap.Stack("stacktrace"))
  44. }
  45. }
  46. }()
  47. if err = checkHouseholdDelApplyParam(req); err != nil {
  48. return nil, err
  49. }
  50. p := &dbmodel.THouse{}
  51. where := map[string]interface{}{
  52. "approve_status":HouseholdApproveStatusWait,
  53. }
  54. if req.HouseId > 0 {
  55. where["house_id"] = req.HouseId
  56. }
  57. if req.Id > 0 {
  58. where["id"] = req.Id
  59. }
  60. if req.BuildingId > 0 {
  61. where["building_id"] = req.BuildingId
  62. }
  63. if req.UnitId > 0 {
  64. where["unit_id"] = req.UnitId
  65. }
  66. if req.GardenId > 0 {
  67. where["garden_id"] = req.GardenId
  68. }
  69. now := time.Now()
  70. values := map[string]interface{}{
  71. "approve_status":HouseholdApproveStatusFail,
  72. "feedback":"房屋变更,请重新申请",
  73. "approved_at":now,
  74. "updated_at":now,
  75. }
  76. err = p.Update(database.DB(), where, values)
  77. if err != nil {
  78. return nil, errors.DataBaseError
  79. }
  80. return reply, nil
  81. }