garden_name.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. )
  16. func checkHouseholdGardenNameChangeParam(req *pb_v1.HouseholdGardenNameChangeRequest) error {
  17. switch {
  18. case req.GardenId < 1:
  19. return status.Error(10003, "小区id不能为空")
  20. case req.GardenName == "":
  21. return status.Error(10003, "小区名称不能为空")
  22. }
  23. return nil
  24. }
  25. // 废弃不用
  26. func HouseholdGardenNameChange(ctx context.Context, req *pb_v1.HouseholdGardenNameChangeRequest) (reply *pb_v1.HouseholdGardenNameChangeReply, err error) {
  27. reply = &pb_v1.HouseholdGardenNameChangeReply{}
  28. // 捕获各个task中的异常并返回给调用者
  29. defer func() {
  30. if r := recover(); r != nil {
  31. err = fmt.Errorf("%+v", r)
  32. e := &status.Status{}
  33. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  34. logger.Error("err",
  35. zap.String("system_err", err.Error()),
  36. zap.Stack("stacktrace"))
  37. }
  38. }
  39. }()
  40. err = checkHouseholdGardenNameChangeParam(req)
  41. if err != nil {
  42. return nil, err
  43. }
  44. p := dbmodel.THouse{}
  45. where := map[string]interface{}{
  46. "garden_id": req.GardenId,
  47. }
  48. values := map[string]interface{}{
  49. "garden_name":req.GardenName,
  50. }
  51. err = p.Update(database.DB(), where, values)
  52. if err != nil {
  53. return nil, errors.DataBaseError
  54. }
  55. return reply, nil
  56. }