123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // 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 ProjectProgressSet(ctx context.Context, req *v1.ProjectProgressSetRequest) (reply *v1.ProjectProgressSetReply, err error) {
- reply = &v1.ProjectProgressSetReply{}
- if req.Id == 0 {
- return nil, errors.ParamsError
- }
- p := model.TProjectSchedule{}
- where := map[string]interface{}{
- "id":req.Id,
- }
- err = p.Find(database.DB(), where, nil)
- if err != nil {
- logger.Error("ProjectProgressSet",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.ID == 0 {
- return nil, errors.NoRecordError
- }
- now := time.Now()
- value := map[string]interface{}{
- "image":req.Image,
- "updated_at":now,
- }
- if req.End > 0 {
- value["reality_end_time"] = time.Unix(req.End, 0)
- value["status"] = model.ProjectProgressFinish
- }
- if req.Start > 0 {
- value["reality_start_time"] = time.Unix(req.Start, 0)
- value["status"] = model.ProjectProgressWorking
- }
- err = p.Update(database.DB(), where, value)
- if err != nil {
- logger.Error("ProjectProgressFinish",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- return reply, nil
- }
|