123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package project
- import (
- "context"
- "encoding/json"
- "fmt"
- "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"
- )
- func makeProjectInfoContent(data []byte)([]*v1.ProjectInfoItem) {
- m := map[string]interface{}{}
- if len(data) == 0 {
- return nil
- }
- json.Unmarshal(data, &m)
- ret := make([]*v1.ProjectInfoItem, 0)
- for k, v := range m {
- if _, ok := projectFieldMap[k]; !ok {
- continue
- }
- item := &v1.ProjectInfoItem{
- Name:k,
- Chinese:projectFieldMap[k],
- Value:fmt.Sprintf("%v", v),
- }
- ret = append(ret, item)
- }
- return ret
- }
- func ProjectInfoForChange(ctx context.Context, req *v1.ProjectInfoForChangeRequest) (reply *v1.ProjectInfoForChangeReply, err error) {
- project := model.TProject{}
- err = project.Find(database.DB(), map[string]interface{}{"id":req.Id})
- if err != nil {
- logger.Error("DeviceList",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if project.Id == 0 {
- return nil, errors.NoRecordError
- }
- bytes, _ := json.Marshal(project)
- list := makeProjectInfoContent(bytes)
- reply = &v1.ProjectInfoForChangeReply{
- List:list,
- }
- return reply, nil
- }
|