Files
cz-web/src/api/project.ts
2026-10-09 11:41:50 +08:00

178 lines
7.5 KiB
TypeScript

import type {
AfterSalesAttachment,
AfterSalesPayload,
AfterSalesUploadVo,
ProjectListResult,
ProjectQuery,
ProjectStatistics,
RdProjectVo,
RequirementDetailBundle,
} from '@/types/business/project'
import { request, serializeQuery } from '@/utils/request'
import { formatDate } from '@/utils/format'
// ─────────────────────────────────────────────────────────────────────────────
// GET /web/requirementPool/list → 控制器 ProjectRequirementUserController#list
// → 服务层 ProjectRequirementServiceImpl#queryUserPageList
// 返回 { total, rows: RdProjectVo[] }
// key → 模糊匹配 projectName / projectNo / requirementDesc
// pageNum/pageSize → 分页参数 PageQuery
// ─────────────────────────────────────────────────────────────────────────────
// ─────────────────────────────────────────────────────────────────────────────
// GET /web/requirementPool/getFilterConditions
// → 控制器 ProjectRequirementUserController#getFilterConditions
// → 服务层 ProjectRequirementServiceImpl#getFilterConditions
// 业务类型统计 businessTypeCounts: [{ businessTypeId, businessTypeLabel, count }]
// ─────────────────────────────────────────────────────────────────────────────
function pad(value: number): string {
return String(value).padStart(2, '0')
}
function toDateTime(date: Date, endOfDay: boolean): string {
const ymd = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
return `${ymd} ${endOfDay ? '23:59:59' : '00:00:00'}`
}
function toTimeRange(query: ProjectQuery): { beginTime?: string; endTime?: string } {
if (query.startDate || query.endDate) {
return {
beginTime: query.startDate ? `${query.startDate} 00:00:00` : undefined,
endTime: query.endDate ? `${query.endDate} 23:59:59` : undefined,
}
}
if (query.timeShortcut === 'all') return {}
const start = new Date()
if (query.timeShortcut === '3m') start.setMonth(start.getMonth() - 3)
else if (query.timeShortcut === '6m') start.setMonth(start.getMonth() - 6)
else start.setFullYear(start.getFullYear() - 1)
return { beginTime: toDateTime(start, false), endTime: toDateTime(new Date(), true) }
}
export function getProjectList(query: ProjectQuery): Promise<ProjectListResult> {
return request<ProjectListResult>({
url: '/web/requirementPool/list',
method: 'get',
paramsSerializer: { serialize: serializeQuery },
params: {
pageNum: query.pageNum,
pageSize: query.pageSize,
key: query.keyword || undefined,
businessTypes: query.businessTypes.length > 0 ? [...query.businessTypes] : undefined,
status: query.status || undefined,
...toTimeRange(query),
},
})
}
export function getProjectFilterConditions(): Promise<ProjectStatistics> {
return request<ProjectStatistics>({
url: '/web/requirementPool/getFilterConditions',
method: 'get',
})
}
export function getCompletedProjects(): Promise<RdProjectVo[]> {
return request<ProjectListResult>({
url: '/web/requirementPool/list',
method: 'get',
params: {
pageNum: 1,
pageSize: 200,
status: 'COMPLETED',
},
}).then((result) => result?.rows ?? [])
}
// ─────────────────────────────────────────────────────────────────────────────
// GET /web/requirementPool/get/progress/{id} → 进度详情 ProjectRequirementProgressVo
// GET /web/requirementPool/get/files/{id} → 文件资料 ProjectRequirementFilesVo
// GET /web/requirementPool/get/finance/{id} → 财务信息 ProjectRequirementFinanceVo
// GET /web/requirementPool/get/afterSales/{id} → 售后信息 ProjectRequirementAfterSalesVo
// → 控制器 ProjectRequirementUserController#getProgress / #getFiles / #getFinance / #getAfterSales
// → 服务层 ProjectRequirementServiceImpl#queryProgress / queryFiles / queryFinance / queryAfterSales
//
// ─────────────────────────────────────────────────────────────────────────────
export type ProjectDetailTab = 'progress' | 'files' | 'finance' | 'afterSales'
const DETAIL_TAB_URL: Record<ProjectDetailTab, string> = {
progress: '/web/requirementPool/get/progress',
files: '/web/requirementPool/get/files',
finance: '/web/requirementPool/get/finance',
afterSales: '/web/requirementPool/get/afterSales',
}
export function getProjectDetailTab<T extends ProjectDetailTab>(
id: string,
tab: T,
): Promise<RequirementDetailBundle[T] | null> {
return request<RequirementDetailBundle[T] | null>({
url: `${DETAIL_TAB_URL[tab]}/${id}`,
method: 'get',
})
}
export function getProjectDetailBundle(id: string): Promise<RequirementDetailBundle | null> {
return Promise.all([
getProjectDetailTab(id, 'progress'),
getProjectDetailTab(id, 'files'),
getProjectDetailTab(id, 'finance'),
getProjectDetailTab(id, 'afterSales'),
]).then(([progress, files, finance, afterSales]) => {
if (!progress || !files || !finance || !afterSales) return null
return { progress, files, finance, afterSales }
})
}
// ─────────────────────────────────────────────────────────────────────────────
// → ProjectRequirementUserController#requestAfterSale / #withdrawAfterSale
// → ProjectRequirementServiceImpl#requestAfterSale / #withdrawAfterSale
//
//
// ─────────────────────────────────────────────────────────────────────────────
export function uploadAfterSalesFile(file: File): Promise<AfterSalesAttachment> {
const data = new FormData()
data.append('file', file)
return request<AfterSalesUploadVo>({
url: '/web/workOrderDraft/upload',
method: 'post',
data,
headers: { 'Content-Type': 'multipart/form-data' },
}).then((vo) => ({
ossId: vo.ossId,
name: vo.originalName || file.name,
size: file.size,
url: vo.url,
uploadTime: formatDate(new Date()),
}))
}
export function submitAfterSales(
id: string,
payload: AfterSalesPayload,
): Promise<void> {
return request<void>({
url: '/web/requirementPool/afterSales/request',
method: 'post',
data: {
id,
type: payload.type,
reason: payload.reason,
note: payload.note,
attachmentOssIds: payload.attachmentOssIds,
},
})
}
export function cancelAfterSales(id: string, reason = ''): Promise<void> {
return request<void>({
url: '/web/requirementPool/afterSales/withdraw',
method: 'post',
data: { id, reason },
})
}