59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
|
|
package relation
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/pkg/ctxdata"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListDownstreamLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListDownstreamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDownstreamLogic {
|
||
|
|
return &ListDownstreamLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListDownstreamLogic) ListDownstream(req *types.CrmListRelationsReq) (*types.CrmListRelationsResp, error) {
|
||
|
|
if req.Depth != 1 {
|
||
|
|
return nil, errors.New("only depth=1 is allowed")
|
||
|
|
}
|
||
|
|
|
||
|
|
tenantId := ctxdata.GetTenantId(l.ctx)
|
||
|
|
rows, err := l.svcCtx.CrmRepo.ListDownstream(l.ctx, tenantId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
list := make([]types.CrmRelationInfo, 0, len(rows))
|
||
|
|
for _, row := range rows {
|
||
|
|
item := types.CrmRelationInfo{
|
||
|
|
RelationshipId: row.RelationshipId,
|
||
|
|
FromTenantId: row.FromTenantId,
|
||
|
|
FromTenantName: row.FromTenantName,
|
||
|
|
ToTenantId: row.ToTenantId,
|
||
|
|
ToTenantName: row.ToTenantName,
|
||
|
|
RelationType: row.RelationType,
|
||
|
|
Status: row.Status,
|
||
|
|
ValidFrom: row.ValidFrom.Format(timeLayout),
|
||
|
|
}
|
||
|
|
if row.ValidTo.Valid {
|
||
|
|
item.ValidTo = row.ValidTo.Time.Format(timeLayout)
|
||
|
|
}
|
||
|
|
list = append(list, item)
|
||
|
|
}
|
||
|
|
return &types.CrmListRelationsResp{Total: int64(len(list)), List: list}, nil
|
||
|
|
}
|
||
|
|
|