project_update.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 githup.com. All rights reserved.
  2. // Use of this source code is governed by githup.com.
  3. package project
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "github.com/jaryhe/gopkgs/logger"
  8. "go.uber.org/zap"
  9. "smart-site-management/errors"
  10. dbmodel "smart-site-management/model"
  11. pb_v1 "smart-site-management/pb/v1"
  12. "time"
  13. )
  14. func ProjectUpdate(ctx context.Context, req *pb_v1.ProjectUpdateRequest)(reply *pb_v1.ProjectUpdateReply, err error) {
  15. p := &dbmodel.TProject{}
  16. where := map[string]interface{}{
  17. "id": req.ProjectId,
  18. }
  19. // 状态判断
  20. err = p.Find(database.DB(), where)
  21. if err != nil {
  22. logger.Error("ProjectUpdate",
  23. zap.String("err", err.Error()))
  24. return nil, errors.DataBaseError
  25. }
  26. if p.Id == 0 {
  27. return nil, errors.NoRecordError
  28. }
  29. reply = &pb_v1.ProjectUpdateReply{}
  30. values := map[string]interface{}{}
  31. values["updated_at"] = time.Now()
  32. // 0平面图 1效果图
  33. if req.Name != "" {
  34. values["name"] = req.Name
  35. }
  36. if req.ShortName != ""{
  37. values["short_name"] = req.ShortName
  38. }
  39. if req.Location != "" {
  40. values["location"] = req.Location
  41. }
  42. err = p.Update(database.DB(), where, values)
  43. if err != nil {
  44. logger.Error("ProjectUpdate",
  45. zap.String("err", err.Error()))
  46. return nil, errors.DataBaseError
  47. }
  48. return reply, nil
  49. }