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
+46 -97
View File
@@ -1,36 +1,10 @@
import { axios, type Page, type PageResult } from "timi-web";
import type { Customer, CustomerDailyStatView, CustomerGenderStatView, CustomerInviteUpdateReq, CustomerSearchReq, CustomerTrendStatReq, QuickRegisterReq } from "@/types/Customer";
import type { EventRecord } from "@/types/EventRecord";
import type { Customer, CustomerDailyStatView, CustomerGenderStatView, CustomerTrendStatReq } from "@/types/Customer";
const BASE_URI = "/gao/customer";
async function list(req: Page<Customer>): Promise<PageResult<Customer>> {
return await axios.post(`${BASE_URI}/list`, req);
}
async function search(req: CustomerSearchReq): Promise<Customer[]> {
const [codeMatched, nameMatched] = await Promise.all([
req.keyword ? nullableDetailByCode(req.keyword) : undefined,
req.keyword ? nullableDetailByName(req.keyword) : undefined
]);
return [codeMatched, nameMatched].filter((item, index, list): item is Customer => !!item && index === list.findIndex(current => current?.id === item.id));
}
async function searchPage(req: Page<CustomerSearchReq>): Promise<PageResult<Customer>> {
return await axios.post(`${BASE_URI}/list`, {
...req,
equalsExample: buildCustomerListExample(req.equalsExample)
});
}
async function exportExcel(req: CustomerSearchReq): Promise<Blob> {
return await axios.post(`${BASE_URI}/export`, {
index: 0,
size: 100000,
equalsExample: buildCustomerListExample(req)
}, {
responseType: "blob"
});
async function list(page: Page<Customer>): Promise<PageResult<Customer>> {
return await axios.post(`${BASE_URI}/list`, page);
}
async function detail(id: string): Promise<Customer> {
@@ -39,52 +13,12 @@ async function detail(id: string): Promise<Customer> {
});
}
async function nullableDetailByCode(code: string): Promise<Customer | null> {
return await axios.post(`${BASE_URI}/find/code`, undefined, {
params: { code }
});
async function create(customer: Customer): Promise<string> {
return await axios.post(`${BASE_URI}/create`, customer);
}
async function nullableDetailByName(name: string): Promise<Customer | null> {
return await axios.post(`${BASE_URI}/find/name`, undefined, {
params: { name }
});
}
async function invitedList(introducerCustomerId: string): Promise<Customer[]> {
return await axios.post(`${BASE_URI}/invited/list`, undefined, {
params: { introducerCustomerId }
});
}
async function create(req: Customer): Promise<Customer> {
const id = await axios.post(`${BASE_URI}/create`, req) as unknown as string;
return {
...req,
id
};
}
async function quickRegister(req: QuickRegisterReq): Promise<EventRecord> {
const customer = await nullableDetailByCode(req.customerCode);
if (!customer?.id) {
throw new Error("客户不存在,无法登记");
}
const record: EventRecord = {
customerId: customer.id,
eventId: req.eventId,
remark: req.remark,
attachmentIdList: req.attachmentIdList
};
await axios.post("/gao/event/record/create", {
...record,
eventId: req.eventId
});
return record;
}
async function update(req: Customer): Promise<void> {
return await axios.post(`${BASE_URI}/update`, req);
async function update(page: Customer): Promise<void> {
return await axios.post(`${BASE_URI}/update`, page);
}
async function remove(id: string): Promise<void> {
@@ -93,15 +27,41 @@ async function remove(id: string): Promise<void> {
});
}
async function updateInvite(req: CustomerInviteUpdateReq): Promise<void> {
if (!req.introducerCustomerId) {
await deleteInvite(req.customerId);
return;
}
async function findById(id: string): Promise<Customer | undefined> {
return await axios.post(`${BASE_URI}/find/id`, null, {
params: { id }
});
}
async function findByCode(code: string): Promise<Customer | undefined> {
return await axios.post(`${BASE_URI}/find/code`, null, {
params: { code }
});
}
async function findByName(name: string): Promise<Customer | undefined> {
return await axios.post(`${BASE_URI}/find/name`, null, {
params: { name }
})
}
async function exportXSSF(page: Page<Customer>): Promise<Blob> {
return await axios.post(`${BASE_URI}/export`, page, {
responseType: "blob"
});
}
async function listInvited(introducerCustomerId: string): Promise<Customer[]> {
return await axios.post(`${BASE_URI}/invited/list`, undefined, {
params: { introducerCustomerId }
});
}
async function saveInvite(introducerCustomerId: string, customerId: string): Promise<void> {
return await axios.post(`${BASE_URI}/invite/save`, undefined, {
params: {
customerId: req.customerId,
introducerCustomerId: req.introducerCustomerId
introducerCustomerId,
customerId
}
});
}
@@ -120,29 +80,18 @@ async function genderStat(): Promise<CustomerGenderStatView[]> {
return await axios.post(`${BASE_URI}/state/gender`);
}
function buildCustomerListExample(req?: CustomerSearchReq): Partial<Customer> {
if (!req?.introducerCustomerId) {
return {};
}
return {
introducerCustomerId: req.introducerCustomerId
};
}
export default {
list,
search,
searchPage,
exportExcel,
detail,
nullableDetailByCode,
nullableDetailByName,
invitedList,
create,
quickRegister,
update,
remove,
updateInvite,
findById,
findByCode,
findByName,
exportXSSF,
listInvited,
saveInvite,
deleteInvite,
dailyStat,
genderStat
+6 -7
View File
@@ -7,7 +7,7 @@ async function list(req: Page<EventItem>): Promise<PageResult<EventItem>> {
return await axios.post(`${BASE_URI}/list`, req);
}
async function enabledList(): Promise<EventItem[]> {
async function listValid(): Promise<EventItem[]> {
return await axios.post(`${BASE_URI}/list/valid`);
}
@@ -17,12 +17,12 @@ async function detail(id: string): Promise<EventItem> {
});
}
async function create(req: EventItem): Promise<void> {
return await axios.post(`${BASE_URI}/create`, req);
async function create(event: EventItem): Promise<void> {
return await axios.post(`${BASE_URI}/create`, event);
}
async function update(req: EventItem): Promise<void> {
return await axios.post(`${BASE_URI}/update`, req);
async function update(event: EventItem): Promise<void> {
return await axios.post(`${BASE_URI}/update`, event);
}
async function sort(idList: string[]): Promise<void> {
@@ -37,11 +37,10 @@ async function remove(id: string): Promise<void> {
export default {
list,
enabledList,
listValid,
detail,
create,
update,
sort,
remove
};
+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
};
+6 -7
View File
@@ -3,8 +3,8 @@ import type { ManagedUser } from "@/types/ManagedUser";
const BASE_URI = "/gao/user";
async function list(req: Page<ManagedUser>): Promise<PageResult<ManagedUser>> {
return await axios.post(`${BASE_URI}/list`, req);
async function list(page: Page<ManagedUser>): Promise<PageResult<ManagedUser>> {
return await axios.post(`${BASE_URI}/list`, page);
}
async function detail(id: string): Promise<ManagedUser> {
@@ -13,12 +13,12 @@ async function detail(id: string): Promise<ManagedUser> {
});
}
async function create(req: ManagedUser): Promise<ManagedUser> {
return await axios.post(`${BASE_URI}/create`, req);
async function create(user: ManagedUser): Promise<ManagedUser> {
return await axios.post(`${BASE_URI}/create`, user);
}
async function update(req: ManagedUser): Promise<ManagedUser> {
return await axios.post(`${BASE_URI}/update`, req);
async function update(user: ManagedUser): Promise<ManagedUser> {
return await axios.post(`${BASE_URI}/update`, user);
}
async function remove(id: string): Promise<void> {
@@ -39,4 +39,3 @@ export default {
remove,
roleList
};