117 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-06-06 18:51:11 +08:00
/*
* @Author: Kane
* @Date: 2023-06-06 17:40:31
* @LastEditors: Kane
* @FilePath: /task_schedule/src/utils/ranking.ts
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
import { service as instance } from "./api/request.js";
import { API_URL } from "./api/config.js";
import { type RankingListItem } from "../types/cpicxim/RankingListItem.js";
/**
*
*/
interface RankingListRequest
{
departmentCode: string;
year: string;
month: string;
2023-07-25 19:11:27 +08:00
}
2023-06-06 18:51:11 +08:00
interface RankingListResponse
{
success: boolean;
message: string;
departmentCode: string;
year: string;
month: string;
2023-06-09 16:37:50 +08:00
attachingRateRankingList: RankingListItem[];
renewalRateRankingList: RankingListItem[];
2023-07-25 19:11:27 +08:00
}
2023-06-06 18:51:11 +08:00
2023-08-29 18:57:27 +08:00
// 判断用的正则表达式
const regexMonth = "(0[1-9])|(1[0-2])";
2023-06-07 17:19:47 +08:00
/**
*
* @param reqParam
* @param rander
* @returns RankingListResponse对象
*/
function requestRankingList( reqParam: RankingListRequest, rander: any ): void // eslint-disable-line
{
// let attachingRankingList: RankingListItem[];
// let renewalRankintList: RankingListItem[];
const rankingListResponse: RankingListResponse = {
success: false,
message: "",
departmentCode: reqParam.departmentCode,
year: reqParam.year,
month: reqParam.month,
2023-06-09 16:37:50 +08:00
attachingRateRankingList: [],
renewalRateRankingList: [],
2023-06-07 17:19:47 +08:00
};
2023-08-29 18:57:27 +08:00
// 检查请求参数
// TODO: 这里要加一个对month的正则表达式验证。
2023-06-07 17:19:47 +08:00
instance.request(
{
method: "post",
url: API_URL.URL_RANKINGLIST,
data: reqParam,
})
.then(( response ) =>
{
const data: RankingListResponse = response.data as RankingListResponse;
rankingListResponse.success = data.success ?? false;
rankingListResponse.message = data.message ?? "";
rankingListResponse.departmentCode = data.departmentCode ?? "";
rankingListResponse.year = data.year ?? "";
rankingListResponse.month = data.month ?? "";
// 遍历排行榜元素
2023-06-09 16:37:50 +08:00
for ( const item of ( data.attachingRateRankingList ?? [] )) // eslint-disable-line
2023-06-07 17:19:47 +08:00
{
const index: number = item.index ?? -1;
if ( index === -1 )
{
continue;
}
2023-06-09 16:37:50 +08:00
rankingListResponse.attachingRateRankingList.push( item );
2023-06-07 17:19:47 +08:00
}
2023-06-09 16:37:50 +08:00
for ( const item of ( data.renewalRateRankingList ?? [] )) // eslint-disable-line
2023-06-07 17:19:47 +08:00
{
const index: number = item.index ?? -1;
if ( index === -1 )
{
continue;
}
2023-06-09 16:37:50 +08:00
rankingListResponse.renewalRateRankingList.push( item );
2023-06-07 17:19:47 +08:00
}
// 调用回调函数保存数据
rander( rankingListResponse );
})
.catch(( error ) =>
{
console.log( error );
});
}
export {
type RankingListRequest,
type RankingListResponse,
requestRankingList
};