// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package project import ( "context" "github.com/jaryhe/gopkgs/database" "github.com/jaryhe/gopkgs/logger" "go.uber.org/zap" "smart-site-management/errors" "smart-site-management/model" "smart-site-management/pb/v1" "time" ) func ProjectProgress(ctx context.Context, req *v1.ProjectProgressRequest) (reply *v1.ProjectProgressReply, err error) { reply = &v1.ProjectProgressReply{} if req.ProjectId == 0 { return nil, errors.ParamsError } project := model.TProject{} where := map[string]interface{}{ "id":req.ProjectId, } err = project.Find(database.DB(), where) if err != nil { return nil, errors.DataBaseError } p := model.TProjectSchedule{} where = map[string]interface{}{ "project_id":req.ProjectId, } list, err := p.ListNoPage(database.DB(), where) if err != nil { logger.Error("ProjectProgress", zap.String("err", err.Error())) return nil, errors.DataBaseError } reply.List = make([]*v1.ProjectProgress, len(list)) now := time.Now() nowDate := time.Date(now.Year(), now.Month(), now.Day(), 0,0,0,0, time.Local) for i, v := range list { item := &v1.ProjectProgress{ Id:v.ID, Name:v.Name, Image:v.Image, ExpectEndTime:v.ExpectEndTime.Format("2006-01-02"), ExpectStartTime: v.ExpectStartTime.Format("2006-01-02"), RealityEndTime:v.RealityEndTime.Format("2006-01-02"), RealityStartTime:v.RealityStartTime.Format("2006-01-02"), Status:int32(v.Status), } if item.Status == model.ProjectProgressUnfinish { item.RealityEndTime = "" item.RealityStartTime = "" } if item.Status == model.ProjectProgressWorking { item.RealityEndTime = "" } reply.List[i] = item } if nowDate.Unix() > project.StartDay.Unix() { reply.StartDays = (nowDate.Unix() - project.StartDay.Unix())/(3600*24) + 1 } reply.TotalDays = (project.EndDay.Unix() - project.StartDay.Unix())/(3600*24) + 1 reply.StartDay = project.StartDay.Format("2006-01-02") reply.EndDay = project.EndDay.Format("2006-01-02") return reply, nil }