12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package project
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- "smart-site-management/errors"
- dbmodel "smart-site-management/model"
- pb_v1 "smart-site-management/pb/v1"
- "time"
- )
- func ProjectUpdate(ctx context.Context, req *pb_v1.ProjectUpdateRequest)(reply *pb_v1.ProjectUpdateReply, err error) {
- p := &dbmodel.TProject{}
- where := map[string]interface{}{
- "id": req.ProjectId,
- }
- // 状态判断
- err = p.Find(database.DB(), where)
- if err != nil {
- logger.Error("ProjectUpdate",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return nil, errors.NoRecordError
- }
- reply = &pb_v1.ProjectUpdateReply{}
- values := map[string]interface{}{}
- values["updated_at"] = time.Now()
- // 0平面图 1效果图
- if req.Name != "" {
- values["name"] = req.Name
- }
- if req.ShortName != ""{
- values["short_name"] = req.ShortName
- }
- if req.Location != "" {
- values["location"] = req.Location
- }
- err = p.Update(database.DB(), where, values)
- if err != nil {
- logger.Error("ProjectUpdate",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- return reply, nil
- }
|