package task_management import ( "adm-management/errors" "adm-management/model" v1 "adm-management/pb/v1" "context" "encoding/json" "fmt" "git.getensh.com/common/gopkgsv2/database" "git.getensh.com/common/gopkgsv2/logger" "go.uber.org/zap" "google.golang.org/grpc/status" "gorm.io/gorm" ) func Dependency(ctx context.Context, req *v1.DependencyRequest) (reply *v1.DependencyReply, err error) { 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.Type == 1 { reply = &v1.DependencyReply{} db := database.DB() dependencyInfo := []model.DependencyInfo{} err = db.Raw("SELECT * FROM t_adm_task_data_relation as t1 LEFT JOIN `t_adm_data_management` as t2 on t1.source_code=t2.source_code where t1.task_id= ?", req.TaskId).Find(&dependencyInfo).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, nil } return reply, errors.SystemError } for _, v := range dependencyInfo { reply.List = append(reply.List, &v1.Dependency{ TableName: v.TableName, Desc: v.Desc, }) } return reply, nil } // 依赖表 if req.Type == 2 { reply = &v1.DependencyReply{} db := database.DB() dependencyInfo := []model.DependencyInfo{} err = db.Raw("SELECT * FROM t_adm_task_dependency as t1 LEFT JOIN `t_adm_data_management` as t2 on t1.source_code=t2.source_code where t1.task_id= ?", req.TaskId).Find(&dependencyInfo).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, nil } return reply, errors.SystemError } for _, v := range dependencyInfo { reply.List = append(reply.List, &v1.Dependency{ TableName: v.TableName, Desc: v.Desc, }) } return reply, nil } return reply, nil }