98 行
3.1 KiB
TypeScript
98 行
3.1 KiB
TypeScript
import { Body, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
|
|
import { CoolController, BaseController } from '@cool-midway/core';
|
|
import { CrmTrackEntity } from '../../entity/track';
|
|
import { CrmRadarService } from '../../service/radar';
|
|
|
|
/**
|
|
* 管理后台-访客雷达足迹
|
|
* 路由前缀: /admin/crm/radar
|
|
* 足迹由公开埋点写入,后台不提供手工 add
|
|
*/
|
|
@Provide()
|
|
@CoolController({
|
|
api: ['info', 'list', 'page', 'delete'],
|
|
entity: CrmTrackEntity,
|
|
service: CrmRadarService,
|
|
pageQueryOp: {
|
|
keyWordLikeFields: ['a.country', 'a.city', 'a.visitorId', 'a.ip'],
|
|
fieldEq: ['a.cardId', 'a.touchType', 'a.country'],
|
|
addOrderBy: { id: 'desc' },
|
|
},
|
|
serviceApis: [
|
|
{ method: 'getRecentTracks', summary: '最近足迹' },
|
|
{ method: 'distribution', summary: '国家分布' },
|
|
{ method: 'analytics', summary: '大屏综合指标' },
|
|
{ method: 'getWorkplaceOverview', summary: '商务概览工作台' },
|
|
],
|
|
})
|
|
export class AdminCrmRadarController extends BaseController {
|
|
@Inject()
|
|
crmRadarService: CrmRadarService;
|
|
|
|
/**
|
|
* 全球访客国家分布统计接口
|
|
* 路由: GET/POST /admin/crm/radar/distribution
|
|
*/
|
|
@Get('/distribution', { summary: '全球访客国家分布' })
|
|
@Post('/distribution', { summary: '全球访客国家分布' })
|
|
async distribution(
|
|
@Body() body?: { cardId?: number },
|
|
@Query('cardId') queryCardId?: number
|
|
) {
|
|
const cardId = body?.cardId ?? queryCardId;
|
|
const data = await this.crmRadarService.getCountryDistribution(
|
|
cardId !== undefined && cardId !== null && !isNaN(Number(cardId))
|
|
? Number(cardId)
|
|
: undefined
|
|
);
|
|
return this.ok(data);
|
|
}
|
|
|
|
/**
|
|
* 全球访客雷达大屏综合指标接口
|
|
* 路由: GET/POST /admin/crm/radar/analytics
|
|
*/
|
|
@Get('/analytics', { summary: '雷达大屏综合指标' })
|
|
@Post('/analytics', { summary: '雷达大屏综合指标' })
|
|
async analytics(
|
|
@Body() body?: { cardId?: number; days?: number },
|
|
@Query('cardId') queryCardId?: number,
|
|
@Query('days') queryDays?: number
|
|
) {
|
|
const cardId = body?.cardId ?? queryCardId;
|
|
const days = body?.days ?? queryDays;
|
|
const data = await this.crmRadarService.getAnalytics({
|
|
cardId:
|
|
cardId !== undefined && cardId !== null && !isNaN(Number(cardId))
|
|
? Number(cardId)
|
|
: undefined,
|
|
days:
|
|
days !== undefined && days !== null && !isNaN(Number(days))
|
|
? Number(days)
|
|
: undefined,
|
|
});
|
|
return this.ok(data);
|
|
}
|
|
|
|
/**
|
|
* 商务概览工作台
|
|
* 路由: GET/POST /admin/crm/radar/workplace
|
|
*/
|
|
@Get('/workplace', { summary: '商务概览工作台' })
|
|
@Post('/workplace', { summary: '商务概览工作台' })
|
|
async workplace(
|
|
@Body() body?: { feedLimit?: number },
|
|
@Query('feedLimit') queryFeedLimit?: number
|
|
) {
|
|
const feedLimit = body?.feedLimit ?? queryFeedLimit;
|
|
const data = await this.crmRadarService.getWorkplaceOverview({
|
|
feedLimit:
|
|
feedLimit !== undefined && feedLimit !== null && !isNaN(Number(feedLimit))
|
|
? Number(feedLimit)
|
|
: undefined,
|
|
});
|
|
return this.ok(data);
|
|
}
|
|
}
|
|
|