57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
|
|
package relation
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/pkg/ctxdata"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListRelationHistoryLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListRelationHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListRelationHistoryLogic {
|
||
|
|
return &ListRelationHistoryLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListRelationHistoryLogic) ListRelationHistory(req *types.CrmRelationHistoryReq) (*types.CrmRelationHistoryResp, error) {
|
||
|
|
tenantId := ctxdata.GetTenantId(l.ctx)
|
||
|
|
rows, total, err := l.svcCtx.CrmRepo.ListHistory(l.ctx, tenantId, req.Page, req.PageSize)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
list := make([]types.CrmRelationHistoryItem, 0, len(rows))
|
||
|
|
for _, row := range rows {
|
||
|
|
before := ""
|
||
|
|
if row.BeforeJSON.Valid {
|
||
|
|
before = row.BeforeJSON.String
|
||
|
|
}
|
||
|
|
after := ""
|
||
|
|
if row.AfterJSON.Valid {
|
||
|
|
after = row.AfterJSON.String
|
||
|
|
}
|
||
|
|
list = append(list, types.CrmRelationHistoryItem{
|
||
|
|
RelationshipId: row.RelationshipId,
|
||
|
|
ChangeType: row.ChangeType,
|
||
|
|
BeforeJson: before,
|
||
|
|
AfterJson: after,
|
||
|
|
ChangedBy: row.ChangedBy,
|
||
|
|
ChangedAt: row.ChangedAt.Format(timeLayout),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
return &types.CrmRelationHistoryResp{Total: total, List: list}, nil
|
||
|
|
}
|
||
|
|
|