123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package manual_task
- import (
- "context"
- "encoding/json"
- "fmt"
- "adm-management/errors"
- "adm-management/model"
- v1 "adm-management/pb/v1"
- "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 Source(ctx context.Context, req *v1.SourceRequest) (reply *v1.SourceReply, err error) {
- reply = &v1.SourceReply{}
- // 捕获各个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.SourceName == "" {
- // 源表搜索
- // 构造分页类
- pagination := model.NewPagination(0, 100000, 0).GetLimitOffset()
- list, err := model.NewDataList().List(database.DB().Where("table_name is NOT null"), pagination)
- if err != nil && err != gorm.ErrRecordNotFound {
- return reply, errors.SystemError
- }
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- reply.List = make([]*v1.Source, 0, len(list))
- for _, v := range list {
- reply.List = append(reply.List, &v1.Source{
- TableName: v.TableName,
- Desc: v.Desc,
- })
- }
- }
- return reply, nil
- }
- func Task(ctx context.Context, req *v1.TaskRequest) (reply *v1.TaskReply, err error) {
- reply = &v1.TaskReply{}
- // 捕获各个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.Task == "" {
- // 任务搜索
- // 构造分页类
- pagination := model.NewPagination(0, 100000, 0).GetLimitOffset()
- list, err := model.NewTaskList().List(database.DB().Where("task_name is NOT null"), pagination)
- if err != nil && err != gorm.ErrRecordNotFound {
- return reply, errors.SystemError
- }
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- reply.List = make([]*v1.Task, 0, len(list))
- for _, v := range list {
- reply.List = append(reply.List, &v1.Task{
- TaskName: v.TaskName,
- Desc: v.Desc,
- })
- }
- }
- if req.Task != "" {
- db := database.DB()
- relationInfo := []model.TaskInfo{}
- err = db.Raw("SELECT DISTINCT t1.task_id, t3.task_name, t3.`desc` FROM t_adm_task_data_relation as t1 LEFT JOIN `t_adm_data_management` as t2 on t1.source_code=t2.source_code LEFT JOIN `t_adm_tasks_management` as t3 on t1.task_id = t3.task_id where t2.table_name= ?", req.Task).Find(&relationInfo).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- reply.List = make([]*v1.Task, 0, len(relationInfo))
- for _, v := range relationInfo {
- reply.List = append(reply.List, &v1.Task{
- TaskName: v.TaskName,
- Desc: v.Desc,
- })
- }
- }
- return reply, nil
- }
|