123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package style_map_management
- import (
- "adm-management/errors"
- "adm-management/model"
- "fmt"
- "git.getensh.com/common/gopkgsv2/database"
- v1 "adm-management/pb/v1"
- "context"
- "encoding/json"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- )
- func AllSource(ctx context.Context, req *v1.AllSourceRequest) (reply *v1.AllSourceReply, err error) {
- reply = &v1.AllSourceReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- if req.AllSource == "" {
- db := database.DB()
- sourceInfo := []model.SourceInfo{}
- err = db.Raw("SELECT DISTINCT source FROM db_adm_dws.t_adm_dws13 ").Find(&sourceInfo).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- reply.List = make([]string, 0, len(sourceInfo))
- for _, v := range sourceInfo {
- reply.List = append(reply.List, v.Source)
- }
- }
- return reply, nil
- }
|