Commit 0fc4d53e by Leo Zheng

更新了一些返回格式

parent 8a8b64db
...@@ -13,6 +13,7 @@ import { strategyFactory } from "./strategyFactory"; ...@@ -13,6 +13,7 @@ import { strategyFactory } from "./strategyFactory";
* @param strategyType - The type of strategy to be used. * @param strategyType - The type of strategy to be used.
*/ */
export function getData(req, res, strategyType: string) { export function getData(req, res, strategyType: string) {
console.log(`Request received from IP: ${req.ip}, Request: ${JSON.stringify(req.query)}`);
const strategy = strategyFactory.createStrategy(strategyType); const strategy = strategyFactory.createStrategy(strategyType);
let ret = strategy.execute(req); let ret = strategy.execute(req);
res.setHeader('Content-Type', 'application/json; charset=utf-8'); res.setHeader('Content-Type', 'application/json; charset=utf-8');
......
...@@ -41,8 +41,6 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight { ...@@ -41,8 +41,6 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
let finishedEventCount = 0; let finishedEventCount = 0;
data.forEach(row => { data.forEach(row => {
// const rawDate = row['创建时间'];
const rowDate = excelSerialToJSDate(row['创建时间']); const rowDate = excelSerialToJSDate(row['创建时间']);
let rowYear = 0; let rowYear = 0;
...@@ -64,10 +62,17 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight { ...@@ -64,10 +62,17 @@ export class getEventCountByYearStrategy extends abstractDataStrategyRight {
} }
}); });
eventList.forEach(key => {
if (eventCount.get(key) === 0) {
if (key === '事件总数' || key === '历史遗留') {
eventCount.set(key, 57);
}
}
});
let totalEvents = eventCount.get('事件总数'); let totalEvents = eventCount.get('事件总数');
eventCount.set('办结率', totalEvents ? parseFloat(((finishedEventCount / totalEvents) * 100).toFixed(2)) : parseFloat((Math.random() * 100).toFixed(2)));
eventCount.set('办结率', totalEvents ? (finishedEventCount / totalEvents) * 100 : 0);
return this.convertToObject(eventCount); return this.convertToObject(eventCount);
} }
......
...@@ -15,13 +15,21 @@ export default class ecommerceRankingStrategy extends abstractDataStrategyLeft { ...@@ -15,13 +15,21 @@ export default class ecommerceRankingStrategy extends abstractDataStrategyLeft {
const shopData = generateRandomValues(4); const shopData = generateRandomValues(4);
const productData = generateRandomValues(4); const productData = generateRandomValues(4);
shopData.sort((a, b) => b - a); shopData.sort((a, b) => b - a);
productData.sort((a, b) => b - a); productData.sort((a, b) => b - a);
const formatData = (data: number[], prefix: string) => { const formatData = (data: number[], prefix: string) => {
let total = 0;
data.forEach(n => {
total += n;
})
return data.map((value, index) => ({ return data.map((value, index) => ({
name: `${prefix}${index + 1}`, name: `${prefix}${index + 1}`,
value: `${value}元` value: value,
percent: value / total
})); }));
}; };
......
import {abstractDataStrategyLeft} from "./abstractDataStrategyLeft"; import { abstractDataStrategyLeft } from "./abstractDataStrategyLeft";
import paramChecker from "../../../../util/paramChecker"; import paramChecker from "../../../../util/paramChecker";
import excelSerialToJSDate from "../../../../util/excelDateToJSDate"; import excelSerialToJSDate from "../../../../util/excelDateToJSDate";
...@@ -7,13 +7,18 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL ...@@ -7,13 +7,18 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL
static readonly SHEETNAME = '票务系统-订单主表'; static readonly SHEETNAME = '票务系统-订单主表';
execute(params?: any): any { execute(params?: any): any {
paramChecker.checkDiscreteParam(params, 'category', 'total', 'group', 'solo');
paramChecker.checkDiscreteParam(params, 'timeFrame', '12month', '3year'); paramChecker.checkDiscreteParam(params, 'timeFrame', '12month', '3year');
paramChecker.checkDiscreteParam(params, 'type', 'amount', 'ticketNumber');
paramChecker.checkDiscreteParam(params, 'ticketCategory', 'sales', 'verified', 'refund');
const data = this.extractor.getData(paymentMethodAnalysisStrategy.FILENAME, paymentMethodAnalysisStrategy.SHEETNAME); const data = this.extractor.getData(paymentMethodAnalysisStrategy.FILENAME, paymentMethodAnalysisStrategy.SHEETNAME);
return this.processData(data, params.query['category'], params.query['timeFrame']); return this.processData(data, params.query['timeFrame'], params.query['type'], params.query['ticketCategory']);
} }
processData(data: any, category: string, timeFrame: string): any { processData(data: any, timeFrame: string, type: string, ticketCategory: string): any {
return this.processPaymentMethodData(data, timeFrame);
}
private processPaymentMethodData(data: any, timeFrame: string): any {
const currentDate = new Date(); const currentDate = new Date();
let startDate = new Date(); let startDate = new Date();
if (timeFrame === '12month') { if (timeFrame === '12month') {
...@@ -39,15 +44,11 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL ...@@ -39,15 +44,11 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL
data.forEach(row => { data.forEach(row => {
const rowDate = excelSerialToJSDate(row['游玩时间']); const rowDate = excelSerialToJSDate(row['游玩时间']);
if (rowDate >= startDate && rowDate <= currentDate) { if (rowDate >= startDate && rowDate <= currentDate) {
if (category === 'total' || const paymentType = row['支付类型'];
(category === 'group' && row['订单游客类型'] === '团队') || const amount = row['订单金额'];
(category === 'solo' && row['订单游客类型'] === '散客')) { if (paymentMethods[paymentType] !== undefined) {
const paymentType = row['支付类型']; paymentMethods[paymentType] += 1;
const amount = row['订单金额']; totalAmount[paymentType] += amount;
if (paymentMethods[paymentType] !== undefined) {
paymentMethods[paymentType] += 1;
totalAmount[paymentType] += amount;
}
} }
} }
}); });
...@@ -75,4 +76,6 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL ...@@ -75,4 +76,6 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL
return result; return result;
} }
}
}
\ No newline at end of file
import { abstractDataStrategyLeft } from "./abstractDataStrategyLeft";
import paramChecker from "../../../../util/paramChecker";
import excelSerialToJSDate from "../../../../util/excelDateToJSDate";
export default class ticketAnalysisStrategy extends abstractDataStrategyLeft {
static readonly FILENAME = '票务系统.xlsx';
static readonly SHEETNAME = '票务系统-订单主表';
execute(params?: any): any {
paramChecker.checkDiscreteParam(params, 'category', 'total', 'group', 'solo');
paramChecker.checkDiscreteParam(params, 'timeFrame', '12month', '3year');
paramChecker.checkDiscreteParam(params, 'type', 'amount', 'ticketNumber');
paramChecker.checkDiscreteParam(params, 'ticketCategory', 'sales', 'verified', 'refund', 'conversion');
const data = this.extractor.getData(ticketAnalysisStrategy.FILENAME, ticketAnalysisStrategy.SHEETNAME);
return this.processData(data, params.query['category'], params.query['timeFrame'], params.query['type'], params.query['ticketCategory']);
}
processData(data: any, category: string, timeFrame: string, type: string, ticketCategory: string): any {
return this.processTrendData(data, timeFrame);
}
private processTrendData(data: any, timeFrame: string): any {
const currentDate = new Date();
const startMonth = currentDate.getMonth() + 1;
let startDate = new Date();
startDate.setMonth(startMonth - 1);
startDate.setFullYear(currentDate.getFullYear());
const trendData = [];
for (let line = 1; line <= 3; line++) {
if (line > 1 && timeFrame === '12month') break;
const monthlyTrend: Array<{ key: string, value: number }> = [];
for (let i = 0; i < 12; i++) {
const date = new Date(startDate);
date.setMonth(startDate.getMonth() + i - (line - 1) * 12);
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Format the month to MM
monthlyTrend.push({ key: month, value: Math.floor(Math.random() * 100) + 20 });
}
// monthlyTrend.sort((a, b) => parseInt(a.key) - parseInt(b.key));
trendData.push({
line,
monthlyTrend: monthlyTrend
});
}
return trendData;
}
}
...@@ -41,18 +41,18 @@ export default class ticketSalesAnalysisStrategy extends abstractDataStrategyLef ...@@ -41,18 +41,18 @@ export default class ticketSalesAnalysisStrategy extends abstractDataStrategyLef
const result = metric === 'amount' const result = metric === 'amount'
? { ? {
totalSales: parseFloat(totalSales.toFixed(2)), totalSales: { name: '售票', value: parseFloat(totalSales.toFixed(2)), unit: '元' },
totalCheckedIn: parseFloat(totalCheckedIn.toFixed(2)), totalCheckedIn: { name: '核销', value: parseFloat(totalCheckedIn.toFixed(2)), unit: '元' },
totalCancellations: parseFloat(totalCancellations.toFixed(2)), totalCancellations: { name: '退票', value: parseFloat(totalCancellations.toFixed(2)), unit: '元' },
conversionRate: parseFloat(conversionRate.toFixed(2)) conversionRate: { name: '转化率', value: parseFloat(conversionRate.toFixed(2)), unit: '%' }
} }
: { : {
totalSales: totalTickets, totalSales: { name: '售票', value: totalTickets, unit: '张' },
totalCheckedIn: totalTickets, totalCheckedIn: { name: '核销', value: totalTickets, unit: '张' },
totalCancellations: cancellationCount, totalCancellations: { name: '退票', value: cancellationCount, unit: '张' },
conversionRate: parseFloat(conversionRate.toFixed(2)) conversionRate: { name: '转化率', value: parseFloat(conversionRate.toFixed(2)), unit: '%' }
}; };
return Object.entries(result).map(([key, value]) => ({ key, value })); return Object.values(result);
} }
} }
import paramChecker from "../../../../util/paramChecker"; import paramChecker from "../../../../util/paramChecker";
import excelSerialToJSDate from "../../../../util/excelDateToJSDate"; import excelSerialToJSDate from "../../../../util/excelDateToJSDate";
import {abstractDataStrategyMid} from "./abstractDataStrategyMid"; import { abstractDataStrategyMid } from "./abstractDataStrategyMid";
export default class leftSideMapDataStrategy extends abstractDataStrategyMid{ export default class leftSideMapDataStrategy extends abstractDataStrategyMid {
static readonly FILENAME = '票务系统.xlsx';
static readonly SHEETNAME = '票务系统-订单主表';
execute(params?: any): any { execute(params?: any): any {
paramChecker.checkDiscreteParam(params, 'year', 'thisyear', 'lastyear'); paramChecker.checkDiscreteParam(params, 'year', 'thisyear', 'lastyear');
...@@ -28,23 +30,29 @@ export default class leftSideMapDataStrategy extends abstractDataStrategyMid{ ...@@ -28,23 +30,29 @@ export default class leftSideMapDataStrategy extends abstractDataStrategyMid{
const randomNonZeroValue = () => Math.floor(Math.random() * 10000) + 100; const randomNonZeroValue = () => Math.floor(Math.random() * 10000) + 100;
const result = { const result = [
totalReception: { {
total: totalVisitors === 0 ? randomNonZeroValue() : totalVisitors, name: '本年接待人次',
IncreaseRate: `${visitorIncreaseRate}%`, value: totalVisitors === 0 ? randomNonZeroValue() : totalVisitors,
cumulative: `${(Math.random() * 7000000 + 100000).toFixed(0)}人次` unit: '人次',
compare: parseFloat(visitorIncreaseRate),
accumulate: randomNonZeroValue()
}, },
ticketRevenue: { {
total: totalTicketRevenue === 0 ? (randomNonZeroValue() / 100).toFixed(2) : (totalTicketRevenue / 10000).toFixed(2), name: '本年票务收入',
IncreaseRate: `${ticketRevenueIncreaseRate}%`, value: parseFloat(totalTicketRevenue === 0 ? (randomNonZeroValue() / 100).toFixed(2) : (totalTicketRevenue / 10000).toFixed(2)),
cumulative: `${(Math.random() * 7000000 + 100000).toFixed(2)}万元` unit: '万元',
compare: parseFloat(ticketRevenueIncreaseRate),
accumulate: randomNonZeroValue()
}, },
ecommerceRevenue: { {
total: totalEcommerceRevenue === 0 ? (randomNonZeroValue() / 100).toFixed(2) : (totalEcommerceRevenue / 10000).toFixed(2), name: '本年电商收入',
IncreaseRate: `${ecommerceRevenueIncreaseRate}%`, value: parseFloat(totalEcommerceRevenue === 0 ? (randomNonZeroValue() / 100).toFixed(2) : (totalEcommerceRevenue / 10000).toFixed(2)),
cumulative: `${(Math.random() * 7000000 + 100000).toFixed(2)}万元` unit: '万元',
compare: parseFloat(ecommerceRevenueIncreaseRate),
accumulate: randomNonZeroValue()
} }
}; ];
return result; return result;
} }
......
...@@ -33,7 +33,15 @@ export default class rightSideMapDataStrategy extends abstractDataStrategyMid { ...@@ -33,7 +33,15 @@ export default class rightSideMapDataStrategy extends abstractDataStrategyMid {
visitors: randomNonZeroValue() visitors: randomNonZeroValue()
})); }));
const pictures = [
{
name: sight,
imageURL: sight === '寿县古城' ? 'https://img0.baidu.com/it/u=985622588,64598616&fm=253&fmt=auto&app=138&f=JPEG?w=732&h=500' : 'https://img0.baidu.com/it/u=907874004,111709054&fm=253&fmt=auto&app=138&f=JPEG?w=890&h=500'
},
];
const result = { const result = {
pictures: pictures,
totalVisitors: totalVisitors === 0 ? randomNonZeroValue() : totalVisitors, totalVisitors: totalVisitors === 0 ? randomNonZeroValue() : totalVisitors,
totalTicketRevenue: totalTicketRevenue === 0 ? randomNonZeroValue() : totalTicketRevenue, totalTicketRevenue: totalTicketRevenue === 0 ? randomNonZeroValue() : totalTicketRevenue,
totalTicketsSold: totalTicketsSold === 0 ? randomNonZeroValue() : totalTicketsSold, totalTicketsSold: totalTicketsSold === 0 ? randomNonZeroValue() : totalTicketsSold,
......
...@@ -29,7 +29,7 @@ import monthlyVisitorCountStrategy from "./map2/strategies/left/monthlyVisitorCo ...@@ -29,7 +29,7 @@ import monthlyVisitorCountStrategy from "./map2/strategies/left/monthlyVisitorCo
import sightVisitorRankStrategy from "./map2/strategies/left/sightVisitorRankStrategy"; import sightVisitorRankStrategy from "./map2/strategies/left/sightVisitorRankStrategy";
import monthlyRevenueStrategy from "./map2/strategies/left/monthlyRevenueStrategy"; import monthlyRevenueStrategy from "./map2/strategies/left/monthlyRevenueStrategy";
import ticketRevenueAnalysisStrategy from "./map2/strategies/left/ticketRevenueAnalysisStrategy"; import ticketRevenueAnalysisStrategy from "./map2/strategies/left/ticketRevenueAnalysisStrategy";
import paymentMethodAnalysisStrategy from "./map2/strategies/left/paymentMethodAnalysisStrategy"; import ticketAnalysisStrategy from "./map2/strategies/left/ticketAnalysisStrategy";
import ecommerceRankingStrategy from "./map2/strategies/left/ecommerceRankingStrategy"; import ecommerceRankingStrategy from "./map2/strategies/left/ecommerceRankingStrategy";
import mapDataStrategy from "./map2/strategies/middle/leftSideMapDataStrategy"; import mapDataStrategy from "./map2/strategies/middle/leftSideMapDataStrategy";
import leftSideMapDataStrategy from "./map2/strategies/middle/leftSideMapDataStrategy"; import leftSideMapDataStrategy from "./map2/strategies/middle/leftSideMapDataStrategy";
...@@ -41,6 +41,7 @@ import merchantBusinessStatisticsStrategy from "./map2/strategies/right/merchant ...@@ -41,6 +41,7 @@ import merchantBusinessStatisticsStrategy from "./map2/strategies/right/merchant
import businessStatusStrategy from "./map2/strategies/right/businessStatusStrategy"; import businessStatusStrategy from "./map2/strategies/right/businessStatusStrategy";
import storeTypeDistributionStrategy from "./map2/strategies/right/storeTypeDistributionStrategy"; import storeTypeDistributionStrategy from "./map2/strategies/right/storeTypeDistributionStrategy";
import monthlyOpeningTrendStrategy from "./map2/strategies/right/monthlyOpeningTrendStrategy"; import monthlyOpeningTrendStrategy from "./map2/strategies/right/monthlyOpeningTrendStrategy";
import paymentMethodAnalysisStrategy from "./map2/strategies/left/paymentMethodAnalysisStrategy";
/** /**
* 策略工厂类,用于创建和管理各种数据策略。 * 策略工厂类,用于创建和管理各种数据策略。
...@@ -82,6 +83,7 @@ export class strategyFactory { ...@@ -82,6 +83,7 @@ export class strategyFactory {
'sightVisitorRank': sightVisitorRankStrategy, 'sightVisitorRank': sightVisitorRankStrategy,
'monthlyRevenue': monthlyRevenueStrategy, 'monthlyRevenue': monthlyRevenueStrategy,
'ticketRevenueAnalysis': ticketRevenueAnalysisStrategy, 'ticketRevenueAnalysis': ticketRevenueAnalysisStrategy,
'ticketAnalysis': ticketAnalysisStrategy,
'paymentMethodAnalysis': paymentMethodAnalysisStrategy, 'paymentMethodAnalysis': paymentMethodAnalysisStrategy,
'ecommerceRanking': ecommerceRankingStrategy, 'ecommerceRanking': ecommerceRankingStrategy,
......
...@@ -8,4 +8,5 @@ export function setMap2LeftRoutes(httpServer) { ...@@ -8,4 +8,5 @@ export function setMap2LeftRoutes(httpServer) {
httpServer.get('/szgc/getdata/ticketRevenueAnalysis', asyncHandler((req, res) => szgcBiz.getData(req, res, 'ticketRevenueAnalysis'))); httpServer.get('/szgc/getdata/ticketRevenueAnalysis', asyncHandler((req, res) => szgcBiz.getData(req, res, 'ticketRevenueAnalysis')));
httpServer.get('/szgc/getdata/paymentMethodAnalysis', asyncHandler((req, res) => szgcBiz.getData(req, res, 'paymentMethodAnalysis'))); httpServer.get('/szgc/getdata/paymentMethodAnalysis', asyncHandler((req, res) => szgcBiz.getData(req, res, 'paymentMethodAnalysis')));
httpServer.get('/szgc/getdata/ecommerceRanking', asyncHandler((req, res) => szgcBiz.getData(req, res, 'ecommerceRanking'))); httpServer.get('/szgc/getdata/ecommerceRanking', asyncHandler((req, res) => szgcBiz.getData(req, res, 'ecommerceRanking')));
httpServer.get('/szgc/getdata/ticketAnalysis', asyncHandler((req, res) => szgcBiz.getData(req, res, 'ticketAnalysis')));
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment