progress_list.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ProjectProgress(ctx context.Context, req *v1.ProjectProgressRequest) (reply *v1.ProjectProgressReply, err error) {
  15. reply = &v1.ProjectProgressReply{}
  16. if req.ProjectId == 0 {
  17. return nil, errors.ParamsError
  18. }
  19. project := model.TProject{}
  20. where := map[string]interface{}{
  21. "id":req.ProjectId,
  22. }
  23. err = project.Find(database.DB(), where)
  24. if err != nil {
  25. return nil, errors.DataBaseError
  26. }
  27. p := model.TProjectSchedule{}
  28. where = map[string]interface{}{
  29. "project_id":req.ProjectId,
  30. }
  31. list, err := p.ListNoPage(database.DB(), where)
  32. if err != nil {
  33. logger.Error("ProjectProgress",
  34. zap.String("err", err.Error()))
  35. return nil, errors.DataBaseError
  36. }
  37. reply.List = make([]*v1.ProjectProgress, len(list))
  38. now := time.Now()
  39. nowDate := time.Date(now.Year(), now.Month(), now.Day(), 0,0,0,0, time.Local)
  40. for i, v := range list {
  41. item := &v1.ProjectProgress{
  42. Id:v.ID,
  43. Name:v.Name,
  44. Image:v.Image,
  45. ExpectEndTime:v.ExpectEndTime.Format("2006-01-02"),
  46. ExpectStartTime: v.ExpectStartTime.Format("2006-01-02"),
  47. RealityEndTime:v.RealityEndTime.Format("2006-01-02"),
  48. RealityStartTime:v.RealityStartTime.Format("2006-01-02"),
  49. Status:int32(v.Status),
  50. }
  51. if item.Status == model.ProjectProgressUnfinish {
  52. item.RealityEndTime = ""
  53. item.RealityStartTime = ""
  54. }
  55. if item.Status == model.ProjectProgressWorking {
  56. item.RealityEndTime = ""
  57. }
  58. reply.List[i] = item
  59. }
  60. if nowDate.Unix() > project.StartDay.Unix() {
  61. reply.StartDays = (nowDate.Unix() - project.StartDay.Unix())/(3600*24) + 1
  62. }
  63. reply.TotalDays = (project.EndDay.Unix() - project.StartDay.Unix())/(3600*24) + 1
  64. reply.StartDay = project.StartDay.Format("2006-01-02")
  65. reply.EndDay = project.EndDay.Format("2006-01-02")
  66. return reply, nil
  67. }