progress_set.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.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. "smart-site-management/model"
  11. "smart-site-management/pb/v1"
  12. "time"
  13. )
  14. func ProjectProgressSet(ctx context.Context, req *v1.ProjectProgressSetRequest) (reply *v1.ProjectProgressSetReply, err error) {
  15. reply = &v1.ProjectProgressSetReply{}
  16. if req.Id == 0 {
  17. return nil, errors.ParamsError
  18. }
  19. p := model.TProjectSchedule{}
  20. where := map[string]interface{}{
  21. "id":req.Id,
  22. }
  23. err = p.Find(database.DB(), where, nil)
  24. if err != nil {
  25. logger.Error("ProjectProgressSet",
  26. zap.String("err", err.Error()))
  27. return nil, errors.DataBaseError
  28. }
  29. if p.ID == 0 {
  30. return nil, errors.NoRecordError
  31. }
  32. now := time.Now()
  33. value := map[string]interface{}{
  34. "image":req.Image,
  35. "updated_at":now,
  36. }
  37. if req.End > 0 {
  38. value["reality_end_time"] = time.Unix(req.End, 0)
  39. value["status"] = model.ProjectProgressFinish
  40. }
  41. if req.Start > 0 {
  42. value["reality_start_time"] = time.Unix(req.Start, 0)
  43. value["status"] = model.ProjectProgressWorking
  44. }
  45. err = p.Update(database.DB(), where, value)
  46. if err != nil {
  47. logger.Error("ProjectProgressFinish",
  48. zap.String("err", err.Error()))
  49. return nil, errors.DataBaseError
  50. }
  51. return reply, nil
  52. }