// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package task import ( "adm-task/errors" "context" "fmt" "gorm.io/gorm" "git.getensh.com/common/gopkgsv2/database" pb_v1 "adm-task/pb/v1" ) func GetTaskBySourceCode(ctx context.Context, req *pb_v1.GetTaskBySourceCodeRequest) (reply *pb_v1.GetTaskBySourceCodeReply, err error) { reply = &pb_v1.GetTaskBySourceCodeReply{} if req.SourceCode == "" { fmt.Println("参数错误,source code 为空") return reply, nil } reply = &pb_v1.GetTaskBySourceCodeReply{} err = database.DB().Raw("select task_id from t_adm_task_data_relation where is_on=1 and source_code=?", req.SourceCode).Find(&reply.TaskList).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, nil } return reply, errors.ServiceError } return reply, nil }