project_set_pic.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. "encoding/json"
  7. "github.com/jaryhe/gopkgs/database"
  8. "github.com/jaryhe/gopkgs/logger"
  9. "go.uber.org/zap"
  10. "smart-site-management/errors"
  11. dbmodel "smart-site-management/model"
  12. pb_v1 "smart-site-management/pb/v1"
  13. "time"
  14. )
  15. func ProjectSetPic(ctx context.Context, req *pb_v1.ProjectSetPicRequest)(reply *pb_v1.ProjectSetPicReply, err error) {
  16. p := &dbmodel.TProject{}
  17. where := map[string]interface{}{
  18. "id": req.ProjectId,
  19. }
  20. // 状态判断
  21. err = p.Find(database.DB(), where)
  22. if err != nil {
  23. logger.Error("ProjectSetPic",
  24. zap.String("err", err.Error()))
  25. return nil, errors.DataBaseError
  26. }
  27. if p.Id == 0 {
  28. return nil, errors.NoRecordError
  29. }
  30. reply = &pb_v1.ProjectSetPicReply{}
  31. values := map[string]interface{}{}
  32. // 0平面图 1效果图
  33. if req.PicType == 0 {
  34. bytes, _ := json.Marshal(req.PicUrl)
  35. values["project_plan"] = string(bytes)
  36. values["updated_at"] = time.Now()
  37. } else {
  38. bytes, _ := json.Marshal(req.PicUrl)
  39. values["project_effect_pic"] = string(bytes)
  40. values["updated_at"] = time.Now()
  41. }
  42. err = p.Update(database.DB(), where, values)
  43. if err != nil {
  44. logger.Error("ProjectSetPic",
  45. zap.String("err", err.Error()))
  46. return nil, errors.DataBaseError
  47. }
  48. return reply, nil
  49. }