1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package api_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 CheckAPI(ctx context.Context, req *v1.CheckAPIRequest) (reply *v1.CheckAPIReply, 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.CheckAPIReply{}
- db := database.DB()
- api := model.AdmAPIList{}
- err = db.Raw("SELECT api_no, `desc`, request, response,related_table_ids FROM t_adm_api_management where id = ?", req.ApiId).Find(&api).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- related := []model.AdmRelatedTableList{}
- str := "select table_name, `desc` from t_adm_data_management where id in (" + api.RelatedTableIds + ")"
- err = db.Raw(str).Find(&related).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- reply.ApiNo = api.ApiNo
- reply.Desc = api.Desc
- reply.Request = api.Request
- reply.Response = api.Response
- reply.List = make([]*v1.RelatedTables, 0, 0)
- return reply, nil
- }
- reply.ApiNo = api.ApiNo
- reply.Desc = api.Desc
- reply.Request = api.Request
- reply.Response = api.Response
- reply.List = make([]*v1.RelatedTables, 0, len(related))
- for _, v := range related {
- reply.List = append(reply.List, &v1.RelatedTables{
- TableName: v.TableName,
- Desc: v.Desc,
- })
- }
- return reply, nil
- }
|