refactor event

This commit is contained in:
Timi
2026-08-06 20:53:22 +08:00
parent 1243068fc3
commit 9df6dfaf59
37 changed files with 1584 additions and 2316 deletions
+24 -114
View File
@@ -1,92 +1,33 @@
import { axios, type Page, type PageResult } from "timi-web";
import type {
CustomerEventRankResponse,
CustomerEventRankView,
EventRecord,
EventRecordCalendarView,
EventRecordCreateReq,
EventRecordDailyStatView,
EventRecordListItemView,
EventRecordPage,
EventRecordPageReq,
EventRecordTrendStatReq
} from "@/types/EventRecord";
import { axios, type PageResult } from "timi-web";
import type { CustomerEventRankView, EventRecord, EventRecordPage, EventRecordRankPage } from "@/types/EventRecord";
import type { Customer } from "@/types/Customer.ts";
const BASE_URI = "/gao/event/record";
async function list(req: Page<EventRecord>): Promise<PageResult<EventRecord>> {
return await axios.post(`${BASE_URI}/list`, buildRecordPage(req));
async function list(page: EventRecordPage): Promise<PageResult<EventRecord>> {
return await axios.post(`${BASE_URI}/list`, page);
}
async function detail(id: string): Promise<EventRecord> {
return await axios.post(`${BASE_URI}/detail`, undefined, {
return await axios.post(`${BASE_URI}/detail`, null, {
params: { id }
});
}
async function rangeList(req: EventRecordPage): Promise<EventRecord[]> {
const result: PageResult<EventRecord> = await axios.post(`${BASE_URI}/list`, buildRecordPage({
index: 0,
size: 1000,
equalsExample: req
}));
return result.list;
async function create(record: EventRecord): Promise<void> {
await axios.post(`${BASE_URI}/create`, record);
}
async function calendarRangeList(req: EventRecordPage): Promise<EventRecordCalendarView[]> {
const result = await rangeList(req);
return result.map(item => ({
id: item.id,
customerId: item.customerId,
customerCode: item.customer?.code || "",
customerName: item.customer?.name || "",
eventId: item.eventId,
registeredAt: item.registeredAt
}));
async function createBatch(recordList: EventRecord[]): Promise<void> {
await axios.post(`${BASE_URI}/create/batch`, recordList);
}
async function rangePage(req: Page<EventRecordPage>): Promise<PageResult<EventRecordListItemView>> {
const result: PageResult<EventRecord> = await axios.post(`${BASE_URI}/list`, buildRecordPage(req));
return {
total: result.total,
list: result.list.map(item => ({
id: item.id,
customerId: item.customerId,
customerName: item.customer?.name || "",
customerPhotoAttachmentId: item.customer?.attachmentList?.[0]?.id,
eventId: item.eventId,
eventName: item.event?.name || "",
registeredAt: item.registeredAt
}))
};
async function createWithCustomer(customer: Customer): Promise<void> {
await axios.post(`${BASE_URI}/create/customer`, customer);
}
async function rangeExport(req: EventRecordPage): Promise<Blob> {
return await axios.post(`${BASE_URI}/export`, buildRecordPage({
index: 0,
size: 100000,
equalsExample: req
}), {
responseType: "blob"
});
}
async function create(req: EventRecordCreateReq): Promise<EventRecord[]> {
const recordList = req.customerIdList.map(customerId => ({
customerId,
eventId: req.eventId,
remark: req.remark,
registeredAt: req.registeredAt,
attachmentIdList: req.attachmentIdList
}));
for (const record of recordList) {
await axios.post(`${BASE_URI}/create`, record);
}
return recordList;
}
async function update(req: EventRecord): Promise<void> {
await axios.post(`${BASE_URI}/update`, req);
async function update(record: EventRecord): Promise<void> {
await axios.post(`${BASE_URI}/update`, record);
}
async function remove(id: string): Promise<void> {
@@ -95,56 +36,25 @@ async function remove(id: string): Promise<void> {
});
}
async function customerRegistrationRank(req?: Partial<EventRecordPage>): Promise<CustomerEventRankView[]> {
const result: PageResult<CustomerEventRankResponse> = await axios.post(`${BASE_URI}/rank`, buildRecordPage({
index: 0,
size: 100,
equalsExample: req
}));
return result.list.map(item => ({
rank: item.rank,
customerId: item.customerId,
customerCode: item.customer?.code || "",
customerName: item.customer?.name || "",
customerPhotoAttachmentId: item.customer?.attachmentList?.[0]?.id,
totalEventDays: item.totalEventDays,
totalEventCount: item.totalEventCount,
recentContinuousEventDays: item.recentContinuousEventDays,
latestRegisteredAt: item.latestRegisteredAt
}));
async function eventRank(page: EventRecordRankPage): Promise<CustomerEventRankView> {
return await axios.post(`${BASE_URI}/rank`, page);
}
async function allCustomerEventDailyStat(req: EventRecordTrendStatReq): Promise<EventRecordDailyStatView[]> {
void req;
return [];
}
function buildRecordPage(req: Page<EventRecord | EventRecordPage> | Page<Partial<EventRecordPage>>): EventRecordPageReq {
const equalsExample = req.equalsExample || {};
const eventIdList = "eventIdList" in equalsExample ? equalsExample.eventIdList : undefined;
const singleEventId = "eventId" in equalsExample ? equalsExample.eventId : undefined;
return {
index: req.index,
size: req.size,
customerId: equalsExample.customerId,
eventIdList: eventIdList || (singleEventId ? [singleEventId] : undefined),
keyword: "keyword" in equalsExample ? equalsExample.keyword : undefined,
beginAt: "beginAt" in equalsExample ? equalsExample.beginAt : undefined,
endAt: "endAt" in equalsExample ? equalsExample.endAt : undefined
};
async function exportXSSF(page: EventRecordPage): Promise<Blob> {
return await axios.post(`${BASE_URI}/export`, page, {
responseType: "blob"
});
}
export default {
list,
detail,
rangeList,
calendarRangeList,
rangePage,
rangeExport,
exportXSSF,
create,
createBatch,
createWithCustomer,
update,
remove,
customerRegistrationRank,
allCustomerEventDailyStat
eventRank
};