2023-03-17 18:53:13 +08:00
|
|
|
|
/*
|
|
|
|
|
* @Author: Kane
|
|
|
|
|
* @Date: 2023-03-17 15:17:44
|
|
|
|
|
* @LastEditors: Kane
|
|
|
|
|
* @FilePath: /task_schedule/src/utils/archievement.ts
|
2023-08-28 17:41:07 +08:00
|
|
|
|
* @Description: 请求业绩数据相关的方法。
|
2023-03-17 18:53:13 +08:00
|
|
|
|
*
|
|
|
|
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
|
|
|
*/
|
|
|
|
|
import { service as instance } from "./api/request.js";
|
|
|
|
|
import { API_URL } from "./api/config.js";
|
2023-08-28 17:41:07 +08:00
|
|
|
|
import { type Department } from "../types/cpicxim/Department.js";
|
|
|
|
|
import { type TelSaler } from "../types/cpicxim/TelSaler.js";
|
|
|
|
|
import { type AxiosResponse } from "axios";
|
2023-03-17 18:53:13 +08:00
|
|
|
|
|
2023-08-28 17:41:07 +08:00
|
|
|
|
interface DepartmentArchievement // 定义业绩对象的结构
|
2023-03-17 18:53:13 +08:00
|
|
|
|
{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
total_archievement: number;
|
2023-03-21 18:01:05 +08:00
|
|
|
|
mensual_archievement_list: number[];
|
2023-03-17 18:53:13 +08:00
|
|
|
|
insurance_renewal_rate: string;
|
2023-12-18 16:03:19 +08:00
|
|
|
|
insurance_renewal_rate_target: string;
|
2023-03-17 18:53:13 +08:00
|
|
|
|
attaching_rate: string;
|
2023-12-18 16:03:19 +08:00
|
|
|
|
attaching_rate_target: string;
|
2023-03-17 18:53:13 +08:00
|
|
|
|
leading_reward_gainers: string[];
|
|
|
|
|
advance_reward_gainers: string[];
|
|
|
|
|
backward_list: string[];
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 10:55:30 +08:00
|
|
|
|
interface CallerArchievement // 坐席业绩对象
|
2023-08-28 17:41:07 +08:00
|
|
|
|
{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
total_archievement: number;
|
2023-10-26 18:46:32 +08:00
|
|
|
|
moto_premium_present_month: number;
|
2023-08-28 17:41:07 +08:00
|
|
|
|
mensual_archievement_list: number[];
|
|
|
|
|
insurance_renewal_rate: string;
|
|
|
|
|
attaching_rate: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 10:55:30 +08:00
|
|
|
|
interface MenusalArchievementItem // 每月业绩清单的项目
|
2023-08-28 17:41:07 +08:00
|
|
|
|
{
|
2023-08-29 10:55:30 +08:00
|
|
|
|
month: number;
|
|
|
|
|
premium: string;
|
2023-08-28 17:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 16:02:32 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取部门业绩数据,并调用回调函数进行渲染。
|
2023-08-29 10:55:30 +08:00
|
|
|
|
* @param departmentInfo 作为请求参数的部门参数对象
|
|
|
|
|
* @param render 用于给组件更新数据的回调函数,用DepartmentArchievement对象调用;
|
2023-03-20 16:02:32 +08:00
|
|
|
|
*/
|
2023-05-09 22:42:20 +08:00
|
|
|
|
function queryDepartmentArchievement( departmentInfo: Department, render: any ): void
|
2023-03-17 18:53:13 +08:00
|
|
|
|
{
|
2023-08-29 18:57:27 +08:00
|
|
|
|
// 默认的部门业绩对象
|
|
|
|
|
const archievement: DepartmentArchievement = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "",
|
|
|
|
|
total_archievement: 0,
|
|
|
|
|
mensual_archievement_list: [],
|
|
|
|
|
insurance_renewal_rate: "",
|
2023-12-18 16:03:19 +08:00
|
|
|
|
insurance_renewal_rate_target: "",
|
2023-08-29 18:57:27 +08:00
|
|
|
|
attaching_rate: "",
|
2023-12-18 16:03:19 +08:00
|
|
|
|
attaching_rate_target: "",
|
2023-08-29 18:57:27 +08:00
|
|
|
|
leading_reward_gainers: [],
|
|
|
|
|
advance_reward_gainers: [],
|
|
|
|
|
backward_list: [],
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-24 15:11:47 +08:00
|
|
|
|
instance.request({
|
2023-03-17 18:53:13 +08:00
|
|
|
|
method: "post",
|
|
|
|
|
url: API_URL.URL_DEPARTMENT_ARCHIEVEMENT,
|
2023-05-09 23:45:53 +08:00
|
|
|
|
data: departmentInfo,
|
2023-03-24 15:11:47 +08:00
|
|
|
|
})
|
2023-08-29 18:57:27 +08:00
|
|
|
|
// 请求结束,将请求的结果写入业绩对象,然后调用功能渲染函数。
|
2023-03-24 15:11:47 +08:00
|
|
|
|
.then(( response ) =>
|
2023-03-17 18:53:13 +08:00
|
|
|
|
{
|
|
|
|
|
const data = response.data ?? {};
|
|
|
|
|
|
|
|
|
|
archievement.success = data.success ?? false;
|
2023-08-29 18:57:27 +08:00
|
|
|
|
archievement.message = data.message ?? "服务器没有返回调用结果消息,请检查日志!";
|
2023-07-31 20:14:49 +08:00
|
|
|
|
archievement.total_archievement = data.total_archievement;
|
|
|
|
|
archievement.mensual_archievement_list = [];
|
2023-03-17 18:53:13 +08:00
|
|
|
|
archievement.insurance_renewal_rate = data.insurance_renewal_rate ?? "0.0";
|
2023-12-18 16:03:19 +08:00
|
|
|
|
archievement.insurance_renewal_rate_target = data.insurance_renewal_rate_target ?? "0.0";
|
2023-03-17 18:53:13 +08:00
|
|
|
|
archievement.attaching_rate = data.attaching_rate ?? "0.0";
|
2023-12-18 16:03:19 +08:00
|
|
|
|
archievement.attaching_rate_target = data.attaching_rate_target ?? "0.0";
|
2023-03-17 18:53:13 +08:00
|
|
|
|
archievement.leading_reward_gainers = data.leading_reward_gainers ?? [];
|
|
|
|
|
archievement.advance_reward_gainers = data.advance_reward_gainers ?? [];
|
|
|
|
|
archievement.backward_list = data.backward_list ?? [];
|
2023-08-25 20:47:36 +08:00
|
|
|
|
|
2023-07-31 20:14:49 +08:00
|
|
|
|
// 转换每月业绩数据,用month排序以后,保留premium。
|
2023-08-25 20:47:36 +08:00
|
|
|
|
data.mensual_archievement_list.sort(( a: any, b: any ) => a.month - b.month );
|
|
|
|
|
data.mensual_archievement_list.forEach(( item: any ) =>
|
2023-07-31 20:14:49 +08:00
|
|
|
|
{
|
|
|
|
|
archievement.mensual_archievement_list.push( item.premium );
|
|
|
|
|
});
|
2023-03-17 18:53:13 +08:00
|
|
|
|
|
2023-07-31 20:14:49 +08:00
|
|
|
|
console.log( "每月业绩", archievement );
|
|
|
|
|
|
2023-08-29 18:57:27 +08:00
|
|
|
|
// 调用渲染函数
|
|
|
|
|
if ( render !== undefined )
|
|
|
|
|
{
|
|
|
|
|
render( archievement );
|
|
|
|
|
}
|
2023-03-24 15:11:47 +08:00
|
|
|
|
})
|
2023-08-29 18:57:27 +08:00
|
|
|
|
// 请求失败,将失败原因写入业绩对象,调用渲染函数
|
2023-03-24 15:11:47 +08:00
|
|
|
|
.catch(( error ) =>
|
2023-03-17 18:53:13 +08:00
|
|
|
|
{
|
2023-08-29 18:57:27 +08:00
|
|
|
|
archievement.success = false;
|
|
|
|
|
archievement.message = String( error );
|
|
|
|
|
|
|
|
|
|
// 调用渲染函数
|
|
|
|
|
if ( render !== undefined )
|
|
|
|
|
{
|
|
|
|
|
render( archievement );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log( `queryDepartmentArchievement:查询部门${departmentInfo.departmentCode}业绩失败,原因${error}` );
|
2023-03-24 15:11:47 +08:00
|
|
|
|
});
|
2023-03-17 18:53:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 10:55:30 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查询坐席的业绩,并调用渲染函数.
|
|
|
|
|
* 1、请求坐席业绩的数据
|
|
|
|
|
* 2、对每月业绩清单进行检查,如果有缺少则用0代替,检查的结果是12个月的清单,让调用者自己截断;
|
2023-08-29 18:57:27 +08:00
|
|
|
|
* 3、将检查后的清单,写入到业绩对象中,只写金额;
|
|
|
|
|
* 4、即使请求失败,也将失败的message写入业绩对象,调用渲染函数;
|
2023-08-29 10:55:30 +08:00
|
|
|
|
* @param callerInfo 坐席的信息参数,用于请求业绩;
|
|
|
|
|
* @param render 渲染函数,用业绩对象CallerArchievement作为参数;
|
|
|
|
|
*/
|
2023-08-28 17:41:07 +08:00
|
|
|
|
function queryCallerArchievement( callerInfo: TelSaler, render: any ): void
|
|
|
|
|
{
|
|
|
|
|
const caller = {
|
|
|
|
|
callerCode: callerInfo.telSalerCode,
|
|
|
|
|
callName: callerInfo.telSalerName,
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-29 18:57:27 +08:00
|
|
|
|
// 默认的业绩对象
|
|
|
|
|
const callArchievement: CallerArchievement = {
|
|
|
|
|
success: false,
|
|
|
|
|
message: "",
|
|
|
|
|
total_archievement: 0,
|
2023-10-26 18:46:32 +08:00
|
|
|
|
moto_premium_present_month: 0,
|
2023-08-29 18:57:27 +08:00
|
|
|
|
mensual_archievement_list: [],
|
|
|
|
|
insurance_renewal_rate: "0.0",
|
|
|
|
|
attaching_rate: "0.0",
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-29 10:55:30 +08:00
|
|
|
|
// 发送请求
|
2023-08-28 17:41:07 +08:00
|
|
|
|
instance.request({
|
|
|
|
|
method: "post",
|
|
|
|
|
url: API_URL.URL_CALLER_ARCHIEVEMENT,
|
|
|
|
|
data: caller,
|
|
|
|
|
})
|
|
|
|
|
// 请求完成时
|
|
|
|
|
.then(( response: AxiosResponse<any, any> ) =>
|
|
|
|
|
{
|
|
|
|
|
const data = response.data ?? {};
|
|
|
|
|
|
2023-10-26 18:46:32 +08:00
|
|
|
|
console.log( "个人业绩数据", data );
|
|
|
|
|
|
2023-08-29 18:57:27 +08:00
|
|
|
|
callArchievement.success = data.success ?? false;
|
|
|
|
|
callArchievement.message = data.message ?? "服务器没有返回调用结果消息,请检查日志!";
|
|
|
|
|
callArchievement.total_archievement = data.total_archievement ?? 0;
|
2023-10-26 18:46:32 +08:00
|
|
|
|
callArchievement.moto_premium_present_month = data.motoPremiumPresentMonth ?? 0;
|
2023-08-29 18:57:27 +08:00
|
|
|
|
callArchievement.mensual_archievement_list = [];
|
|
|
|
|
callArchievement.insurance_renewal_rate = data.insurance_renewal_rate ?? "0.0";
|
|
|
|
|
callArchievement.attaching_rate = data.attaching_rate ?? "0.0";
|
2023-08-28 17:41:07 +08:00
|
|
|
|
|
2023-08-29 10:55:30 +08:00
|
|
|
|
// 检查业绩清单有没有缺漏,缺漏的用0补上
|
2023-08-28 17:41:07 +08:00
|
|
|
|
const checkedList = checkMensualArchievement( data.mensual_archievement_list );
|
|
|
|
|
|
2023-08-29 10:55:30 +08:00
|
|
|
|
// 排序一下
|
|
|
|
|
checkedList.sort(( a: MenusalArchievementItem, b: MenusalArchievementItem ): number =>
|
|
|
|
|
{
|
|
|
|
|
return a.month - b.month;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 将排序后的每月业绩写到业绩对象中
|
|
|
|
|
checkedList.forEach(( item: MenusalArchievementItem ): void =>
|
|
|
|
|
{
|
|
|
|
|
const premium = Number( item.premium );
|
|
|
|
|
|
|
|
|
|
callArchievement.mensual_archievement_list.push( premium );
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 调用渲染函数
|
|
|
|
|
if ( render !== undefined )
|
|
|
|
|
{
|
|
|
|
|
render( callArchievement );
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 17:41:07 +08:00
|
|
|
|
console.log( `queryCallerArchievement查询结果${data}` );
|
|
|
|
|
})
|
2023-08-29 18:57:27 +08:00
|
|
|
|
// 请求失败,将失败的原因保存到message属性,调用渲染函数
|
2023-08-28 17:41:07 +08:00
|
|
|
|
.catch(( error: any ) =>
|
|
|
|
|
{
|
2023-08-29 18:57:27 +08:00
|
|
|
|
callArchievement.success = false;
|
|
|
|
|
callArchievement.message = String( error );
|
|
|
|
|
|
|
|
|
|
// 调用渲染函数
|
|
|
|
|
if ( render !== undefined )
|
|
|
|
|
{
|
|
|
|
|
render( callArchievement );
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 17:41:07 +08:00
|
|
|
|
console.log( `queryCallerArchievement:查询坐席${callerInfo.telSalerCode}业绩失败,原因${error}` );
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查服务器返回的每月业绩数组,检查是否有缺漏,缺少的月份业绩用0代替。
|
2023-08-29 10:55:30 +08:00
|
|
|
|
* 检查的结果是12个月的清单,由调用者自己进行截断。
|
|
|
|
|
* @param mensualArchievementList MenusalArchievementItem类型的数组,为业绩清单
|
|
|
|
|
* @returns 返回MenusalArchievementItem数组,为检查过的清单
|
2023-08-28 17:41:07 +08:00
|
|
|
|
*/
|
|
|
|
|
function checkMensualArchievement( mensualArchievementList: MenusalArchievementItem[]): MenusalArchievementItem[]
|
|
|
|
|
{
|
|
|
|
|
const checkedList: MenusalArchievementItem[] = [];
|
|
|
|
|
const itemMap = new Map();
|
|
|
|
|
|
|
|
|
|
itemMap.set( 1, "0" );
|
|
|
|
|
itemMap.set( 2, "0" );
|
|
|
|
|
itemMap.set( 3, "0" );
|
|
|
|
|
itemMap.set( 4, "0" );
|
|
|
|
|
itemMap.set( 5, "0" );
|
|
|
|
|
itemMap.set( 6, "0" );
|
|
|
|
|
itemMap.set( 7, "0" );
|
|
|
|
|
itemMap.set( 8, "0" );
|
|
|
|
|
itemMap.set( 9, "0" );
|
|
|
|
|
itemMap.set( 10, "0" );
|
|
|
|
|
itemMap.set( 11, "0" );
|
|
|
|
|
itemMap.set( 12, "0" );
|
|
|
|
|
|
|
|
|
|
mensualArchievementList.forEach(( item: MenusalArchievementItem ): void =>
|
|
|
|
|
{
|
|
|
|
|
itemMap.set( item.month, item.premium );
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
itemMap.forEach(( value, key, map ) =>
|
|
|
|
|
{
|
|
|
|
|
const item: MenusalArchievementItem = {
|
|
|
|
|
month: key,
|
|
|
|
|
premium: value,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
checkedList.push( item );
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return checkedList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
queryDepartmentArchievement,
|
|
|
|
|
queryCallerArchievement,
|
|
|
|
|
type DepartmentArchievement,
|
|
|
|
|
type CallerArchievement
|
|
|
|
|
};
|