2023-09-11 11:49:58 +08:00
|
|
|
|
/*
|
|
|
|
|
* @Author: Kane
|
|
|
|
|
* @Date: 2023-09-11 09:59:00
|
|
|
|
|
* @LastEditors: Kane
|
|
|
|
|
* @FilePath: /task_schedule/src/utils/reward.ts
|
2023-09-11 18:27:06 +08:00
|
|
|
|
* @Description: 奖励相关的API
|
2023-09-11 11:49:58 +08:00
|
|
|
|
*
|
|
|
|
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
|
|
|
*/
|
|
|
|
|
import { type AxiosResponse } from "axios";
|
|
|
|
|
import { service as instance } from "./api/request.js";
|
|
|
|
|
import { API_URL } from "./api/config.js";
|
|
|
|
|
|
|
|
|
|
interface RewardProject
|
|
|
|
|
{
|
|
|
|
|
rewardCode: number;
|
|
|
|
|
rewardName: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface RewardProjectResponse
|
|
|
|
|
{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
2023-09-11 18:27:06 +08:00
|
|
|
|
rewardList: RewardProject[] | null;
|
2023-09-11 11:49:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface RewardGainer
|
|
|
|
|
{
|
2023-09-13 18:01:07 +08:00
|
|
|
|
recID: number;
|
2023-09-11 11:49:58 +08:00
|
|
|
|
callerName: string;
|
|
|
|
|
callerCode: string;
|
|
|
|
|
rewardProjectCode: string;
|
|
|
|
|
rewardProjectName: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 18:27:06 +08:00
|
|
|
|
interface RewardGainerResponse
|
|
|
|
|
{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
2023-09-13 18:01:07 +08:00
|
|
|
|
gainerList: RewardGainer[] | null;
|
2023-09-11 18:27:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 11:49:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* 请求奖项清单
|
|
|
|
|
* @param handler 用于处理请求数据的回调函数;
|
|
|
|
|
*/
|
|
|
|
|
function requestRewardPorjectsList( handler: any ): void
|
|
|
|
|
{
|
|
|
|
|
if ( handler === undefined || handler === null )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 18:27:06 +08:00
|
|
|
|
const rewardResponse: RewardProjectResponse = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "",
|
|
|
|
|
rewardList: [],
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-11 11:49:58 +08:00
|
|
|
|
instance.request({
|
|
|
|
|
url: API_URL.URL_RWARD_PROJECTS,
|
|
|
|
|
method: "post",
|
|
|
|
|
})
|
|
|
|
|
// 请求成功,检查服务器返回结果
|
|
|
|
|
.then(( response: AxiosResponse<any, any> ): void =>
|
|
|
|
|
{
|
|
|
|
|
const data = response.data ?? {};
|
2023-09-11 18:27:06 +08:00
|
|
|
|
rewardResponse.success = data.success ?? false;
|
|
|
|
|
rewardResponse.message = data.message ?? "";
|
|
|
|
|
rewardResponse.rewardList = checkRewardProjects( data.rewardList ?? []);
|
|
|
|
|
|
|
|
|
|
handler( rewardResponse, null );
|
2023-09-11 11:49:58 +08:00
|
|
|
|
})
|
|
|
|
|
.catch(( error: any ): void =>
|
|
|
|
|
{
|
|
|
|
|
console.log( error );
|
|
|
|
|
|
2023-09-11 18:27:06 +08:00
|
|
|
|
rewardResponse.success = false;
|
|
|
|
|
|
|
|
|
|
handler( rewardResponse, error );
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param handler
|
|
|
|
|
*/
|
|
|
|
|
function requestRewardGainers( handler: any ): void
|
|
|
|
|
{
|
|
|
|
|
if ( handler === undefined || handler === null )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rewardResponse: RewardGainerResponse = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "",
|
|
|
|
|
gainerList: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
instance.request({
|
|
|
|
|
url: API_URL.URL_REWARD_GAINERS,
|
|
|
|
|
method: "post",
|
|
|
|
|
})
|
|
|
|
|
.then(( response: AxiosResponse<any, any> ): void =>
|
|
|
|
|
{
|
|
|
|
|
const data = response.data ?? {};
|
|
|
|
|
|
|
|
|
|
rewardResponse.success = data.success;
|
|
|
|
|
rewardResponse.message = data.message;
|
2023-09-13 18:01:07 +08:00
|
|
|
|
rewardResponse.gainerList = checkRewardGainers( data.gainerList );
|
2023-09-11 18:27:06 +08:00
|
|
|
|
|
|
|
|
|
handler( rewardResponse, null );
|
|
|
|
|
})
|
|
|
|
|
.catch(( error: any ): void =>
|
|
|
|
|
{
|
|
|
|
|
console.log( error );
|
|
|
|
|
|
|
|
|
|
rewardResponse.success = false;
|
|
|
|
|
|
|
|
|
|
handler( rewardResponse, error );
|
2023-09-11 11:49:58 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// **功能函数 **********************************/
|
|
|
|
|
function checkRewardProjects( data: any[]): RewardProject[] | null
|
|
|
|
|
{
|
|
|
|
|
const rewardList: RewardProject[] = [];
|
|
|
|
|
|
|
|
|
|
// 检查一下参数的类型,如果不是数组返回 null
|
|
|
|
|
if ( !( data instanceof Array ))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.forEach(( item: any ) =>
|
|
|
|
|
{
|
|
|
|
|
const reward = {
|
|
|
|
|
rewardCode: item.rewardCode ?? "",
|
|
|
|
|
rewardName: item.rewardName ?? "",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rewardList.push( reward );
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return rewardList;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 18:27:06 +08:00
|
|
|
|
function checkRewardGainers( gainers: any[]): RewardGainer[] | null
|
|
|
|
|
{
|
|
|
|
|
const gainerList: RewardGainer[] = [];
|
|
|
|
|
|
|
|
|
|
if ( !( gainers instanceof Array ))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gainers.forEach(( item: RewardGainer ): void =>
|
|
|
|
|
{
|
|
|
|
|
const gainer: RewardGainer = {
|
2023-09-13 18:01:07 +08:00
|
|
|
|
recID: item.recID ?? "",
|
2023-09-11 18:27:06 +08:00
|
|
|
|
callerName: item.callerName ?? "",
|
|
|
|
|
callerCode: item.callerCode ?? "",
|
|
|
|
|
rewardProjectCode: item.rewardProjectCode ?? "",
|
|
|
|
|
rewardProjectName: item.rewardProjectName ?? "",
|
|
|
|
|
};
|
2023-09-13 18:01:07 +08:00
|
|
|
|
|
|
|
|
|
gainerList.push( gainer );
|
2023-09-11 18:27:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return gainerList;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 11:49:58 +08:00
|
|
|
|
export {
|
|
|
|
|
type RewardProject,
|
|
|
|
|
type RewardGainer,
|
|
|
|
|
type RewardProjectResponse,
|
2023-09-11 18:27:06 +08:00
|
|
|
|
type RewardGainerResponse,
|
|
|
|
|
requestRewardPorjectsList,
|
|
|
|
|
requestRewardGainers
|
2023-09-11 11:49:58 +08:00
|
|
|
|
};
|