refactor event
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import { axios, type Page, type PageResult } from "timi-web";
|
||||
import type {
|
||||
CustomerEventRankResponse,
|
||||
CustomerEventRankView,
|
||||
EventRecord,
|
||||
EventRecordCalendarView,
|
||||
EventRecordCreateReq,
|
||||
EventRecordDailyStatView,
|
||||
EventRecordListItemView,
|
||||
EventRecordPage,
|
||||
EventRecordPageReq,
|
||||
EventRecordTrendStatReq
|
||||
} from "@/types/EventRecord";
|
||||
|
||||
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 detail(id: string): Promise<EventRecord> {
|
||||
return await axios.post(`${BASE_URI}/detail`, undefined, {
|
||||
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 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 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 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 remove(id: string): Promise<void> {
|
||||
await axios.post(`${BASE_URI}/delete`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
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 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
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
list,
|
||||
detail,
|
||||
rangeList,
|
||||
calendarRangeList,
|
||||
rangePage,
|
||||
rangeExport,
|
||||
create,
|
||||
update,
|
||||
remove,
|
||||
customerRegistrationRank,
|
||||
allCustomerEventDailyStat
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user