PayrollManagementSystem/frontend/src/api/params.ts

229 lines
5.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import service, { request } from './request'
import type { PageData } from './types'
/** 参数目录项(含各维度截至查询时点的生效值) */
export interface ParamDimensionValue {
dimension_value: string
value_text: string
effective_date: string | null
}
export interface ParamCatalogItem {
param_code: string
param_name: string
param_group: string
value_type: string
unit: string | null
dimension_type: string
options: string[]
default_value: string | null
value_min: string | null
value_max: string | null
description: string | null
values: ParamDimensionValue[]
}
/**
* 枚举参数值 → 中文(展示层翻译;库与接口仍存英文码,审计口径不变)。
*
* 业界惯例(RuoYi 字典标签同款):映射单一出处,避免页内复制漂移;
* 未知码原样回显 —— 后端新增枚举项而前端未跟上时不会显示成空。
*/
export const PARAM_ENUM_LABELS: Record<string, string> = {
FULL: '当月全额',
BALANCE: '余额',
INCLUDE: '含基本工资',
DEDUCT: '扣除基本工资',
EXCLUDE: '不计基本工资',
'0': '关',
'1': '开',
}
export function paramEnumLabel(code: string): string {
return PARAM_ENUM_LABELS[code] ?? code
}
/** 参数目录(asOf 缺省为今日) */
export function getCatalog(asOf?: string): Promise<ParamCatalogItem[]> {
return request({ url: '/v1/system/params', method: 'get', params: asOf ? { as_of: asOf } : {} })
}
/** 变更条目:参数 + 维度 + 新值 */
export interface ParamChangeItem {
param_code: string
dimension_value: string
value: string
}
export interface ParamChangePayload {
/** 生效方式:1立即生效 2指定日期生效 */
change_type: number
effective_date?: string
remark?: string
items: ParamChangeItem[]
}
export interface ParamChangeBatch {
id: number
version_no: string
effective_date: string
change_type: number
remark: string | null
operator_name: string
item_count: number
create_time: string
}
/** 提交变更批次 */
export function submitChanges(data: ParamChangePayload): Promise<ParamChangeBatch> {
return request({ url: '/v1/system/params/changes', method: 'post', data })
}
export interface ParamBatchItem {
param_code: string
param_name: string
dimension_value: string
old_value_text: string | null
value_text: string
effective_date: string
}
export interface ParamBatchDetail {
id: number
version_no: string
effective_date: string
change_type: number
remark: string | null
operator_name: string
item_count: number
create_time: string
items: ParamBatchItem[]
}
/** 批次明细(旧值 → 新值) */
export function getBatchDetail(batchId: number): Promise<ParamBatchDetail> {
return request({ url: `/v1/system/params/changes/${batchId}`, method: 'get' })
}
export interface ParamBatch {
id: number
version_no: string
effective_date: string
change_type: number
remark: string | null
operator_name: string
item_count: number
create_time: string
}
/** 变更记录分页 */
export function listBatches(params: {
pageNum?: number
pageSize?: number
start_date?: string
end_date?: string
}): Promise<PageData<ParamBatch>> {
return request({ url: '/v1/system/params/changes', method: 'get', params })
}
/** 撤回未生效批次 */
export function withdrawBatch(batchId: number): Promise<null> {
return request({ url: `/v1/system/params/changes/${batchId}`, method: 'delete' })
}
export interface ParamDiff {
param_code: string
param_name: string
param_group: string
dimension_value: string
old_value: string | null
new_value: string | null
changed: boolean
}
/** 两日期快照对比 */
export function compareParams(fromDate: string, toDate: string): Promise<ParamDiff[]> {
return request({
url: '/v1/system/params/compare',
method: 'get',
params: { from_date: fromDate, to_date: toDate },
})
}
export interface ParamHistory {
version_no: string
dimension_value: string
old_value_text: string | null
value_text: string
effective_date: string
operator_name: string
create_time: string
}
/** 单参数版本历史 */
export function getParamHistory(
paramCode: string,
params: { pageNum?: number; pageSize?: number; dimension_value?: string },
): Promise<PageData<ParamHistory>> {
return request({ url: `/v1/system/params/${paramCode}/history`, method: 'get', params })
}
/**
* 导出变更记录(文件流)。
*
* 走 axios 实例(带令牌)而非 request 封装:响应是 xlsx 文件流,
* 不是统一信封,拦截器已对 responseType=blob 直通。
*/
export async function exportChanges(params: {
start_date?: string
end_date?: string
}): Promise<Blob> {
const response = await service.get('/v1/system/params/export', {
params,
responseType: 'blob',
})
return response.data as Blob
}
/** 计算预览入参(金额为字符串,Decimal 承载) */
export interface ParamPreviewPayload {
business_role?: string
customer_type?: string
product_category?: string
ship_date: string
receipt_date: string
revenue: string
profit: string
received_amount: string
barter: boolean
probation: boolean
}
export interface ParamUsed {
param_code: string
value_text: string
effective_date: string | null
}
export interface ParamPreviewResult {
payment_days: number
rate: string
rate_text: string
profit_rate: string
converted_profit: string
performance_amount: string
barter_applied: boolean
performance_after_barter: string | null
start_payment_ok: boolean
payment_weight_r: number
payment_weight: string
payable_amount: string
probation_note: string | null
params_used: ParamUsed[]
}
/** 计算预览 */
export function previewCalc(data: ParamPreviewPayload): Promise<ParamPreviewResult> {
return request({ url: '/v1/system/params/preview', method: 'post', data })
}