123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package data_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 Relation(ctx context.Context, req *v1.RelationRequest) (reply *v1.RelationReply, 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"))
- }
- }
- }()
- reply = &v1.RelationReply{}
- db := database.DB()
- dataTaskInfo := []model.DataTaskInfo{}
- err = db.Raw("SELECT * FROM t_adm_task_data_relation as t1 LEFT JOIN `t_adm_tasks_management` as t2 on t1.task_id=t2.task_id where t1.source_code= ?", req.SourceCode).Find(&dataTaskInfo).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- var desc string
- for _, v := range dataTaskInfo {
- err = db.Raw("SELECT `desc` FROM t_adm_tasks_management where task_id= ?", v.TaskId).Find(&desc).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- reply.List = append(reply.List, &v1.Relation{
- Id: v.Id,
- TaskId: v.TaskId,
- TaskName: v.TaskName,
- IsOn: v.IsOn,
- Desc: desc,
- })
- }
- return reply, nil
- }
|