del.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package garden
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/cache"
  9. "git.getensh.com/common/gopkgs/database"
  10. "git.getensh.com/common/gopkgs/logger"
  11. "go.uber.org/zap"
  12. "google.golang.org/grpc/status"
  13. "gorm.io/gorm"
  14. "property-system/errors"
  15. dbmodel "property-system/model"
  16. "property-system/pb"
  17. pb_v1 "property-system/pb/v1"
  18. )
  19. const (
  20. HouseholdApproveStatusWait = 1
  21. HouseholdApproveStatusSuccess = 2
  22. HouseholdApproveStatusFail = 3
  23. )
  24. func RefuseHouseApply(gardenId int64, buildingId int64, unitId int64, houseId int64) error {
  25. mreq := pb_v1.HouseholdRefuseRequest{
  26. GardenId:gardenId,
  27. HouseId:houseId,
  28. BuildingId:buildingId,
  29. UnitId:unitId,
  30. Feedback:"房屋变更,请重新申请",
  31. }
  32. _, err := pb.Household.HouseholdRefuse(context.Background(), &mreq)
  33. if err != nil {
  34. return err
  35. }
  36. return nil
  37. }
  38. //
  39. func GardenDel(ctx context.Context, req *pb_v1.GardenDelRequest) (reply *pb_v1.GardenDelReply, err error) {
  40. return nil, status.Error(10003, "小区不支持删除")
  41. reply = &pb_v1.GardenDelReply{}
  42. // 捕获各个task中的异常并返回给调用者
  43. defer func() {
  44. if r := recover(); r != nil {
  45. err = fmt.Errorf("%+v", r)
  46. e := &status.Status{}
  47. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  48. logger.Error("err",
  49. zap.String("system_err", err.Error()),
  50. zap.Stack("stacktrace"))
  51. }
  52. }
  53. }()
  54. if req.Id < 1 || req.Cid < 1{
  55. return nil, errors.ParamsError
  56. }
  57. mreq := pb_v1.GardenHouseIsInRequest{GardenId:req.Id}
  58. mreply, err := pb.Garden.GardenHouseIsIn(ctx, &mreq)
  59. if err != nil {
  60. return nil, err
  61. }
  62. if mreply.In {
  63. return nil, status.Error(10003, "已入住房屋, 不能删除小区")
  64. }
  65. old := &dbmodel.TGardenApproved{}
  66. p := &dbmodel.TGardenApproved{}
  67. where := map[string]interface{}{
  68. "id":req.Id,
  69. "cid":req.Cid,
  70. }
  71. values := map[string]interface{}{
  72. "in_use":nil,
  73. "pay_mode":1,
  74. "mch_id":2,
  75. }
  76. err = old.Find(database.DB(), where)
  77. if err != nil && err != gorm.ErrRecordNotFound {
  78. return nil, errors.DataBaseError
  79. }
  80. if old.ID == 0 {
  81. return nil, errors.ErrRecordNotFound
  82. }
  83. reply.Origin = &pb_v1.GardenUpdateRequest{
  84. Id:req.Id,
  85. GardenName:old.GardenName,
  86. GardenDesc:old.GardenDesc,
  87. StreetCode:old.StreetCode,
  88. CommitteeCode:old.CommitteeCode,
  89. ProvinceCode:old.ProvinceCode,
  90. CityCode:old.CityCode,
  91. AreaCode:old.AreaCode,
  92. Cid:old.Cid,
  93. PropertyPerson:old.PropertyPerson,
  94. PropertyPhone:old.PropertyPhone,
  95. GardenPic:old.GardenPic,
  96. GardenAddr:old.GardenAddr,
  97. }
  98. db := database.DB().Begin()
  99. err = p.Update(db, where, values)
  100. if err != nil {
  101. db.Rollback()
  102. return nil, errors.DataBaseError
  103. }
  104. _, err = cache.Redis().SAdd("garden_del", fmt.Sprintf("%d"), req.Id)
  105. if err != nil {
  106. db.Rollback()
  107. return nil, errors.RedisError
  108. }
  109. if err = RefuseHouseApply(req.Id, 0, 0, 0); err != nil {
  110. db.Rollback()
  111. return nil, err
  112. }
  113. db.Commit()
  114. return reply, nil
  115. }