123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package project
- import (
- "context"
- "encoding/json"
- "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 ProjectSetPic(ctx context.Context, req *pb_v1.ProjectSetPicRequest)(reply *pb_v1.ProjectSetPicReply, err error) {
- p := &dbmodel.TProject{}
- where := map[string]interface{}{
- "id": req.ProjectId,
- }
- // 状态判断
- err = p.Find(database.DB(), where)
- if err != nil {
- logger.Error("ProjectSetPic",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return nil, errors.NoRecordError
- }
- reply = &pb_v1.ProjectSetPicReply{}
- values := map[string]interface{}{}
- // 0平面图 1效果图
- if req.PicType == 0 {
- bytes, _ := json.Marshal(req.PicUrl)
- values["project_plan"] = string(bytes)
- values["updated_at"] = time.Now()
- } else {
- bytes, _ := json.Marshal(req.PicUrl)
- values["project_effect_pic"] = string(bytes)
- values["updated_at"] = time.Now()
- }
- err = p.Update(database.DB(), where, values)
- if err != nil {
- logger.Error("ProjectSetPic",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- return reply, nil
- }
|