refactor event

This commit is contained in:
Timi
2026-08-05 22:50:22 +08:00
parent 22ff13b1fe
commit 1243068fc3
46 changed files with 961 additions and 789 deletions
+64 -21
View File
@@ -1,6 +1,6 @@
import { axios, type Page, type PageResult } from "timi-web";
import type { Customer, CustomerDailyStatView, CustomerGenderStatView, CustomerInviteUpdateReq, CustomerSearchReq, CustomerTrendStatReq, QuickRegisterReq } from "@/types/Customer";
import type { RegistrationEventRecord } from "@/types/RegistrationEventRecord";
import type { EventRecord } from "@/types/EventRecord";
const BASE_URI = "/gao/customer";
@@ -9,15 +9,26 @@ async function list(req: Page<Customer>): Promise<PageResult<Customer>> {
}
async function search(req: CustomerSearchReq): Promise<Customer[]> {
return await axios.post(`${BASE_URI}/search`, req);
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}/search/page`, req);
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`, req, {
return await axios.post(`${BASE_URI}/export`, {
index: 0,
size: 100000,
equalsExample: buildCustomerListExample(req)
}, {
responseType: "blob"
});
}
@@ -28,15 +39,15 @@ async function detail(id: string): Promise<Customer> {
});
}
async function detailByCode(code: string): Promise<Customer> {
return await axios.post(`${BASE_URI}/detail/code`, undefined, {
async function nullableDetailByCode(code: string): Promise<Customer | null> {
return await axios.post(`${BASE_URI}/find/code`, undefined, {
params: { code }
});
}
async function nullableDetailByCode(code: string): Promise<Customer | null> {
return await axios.post(`${BASE_URI}/detail/code/nullable`, undefined, {
params: { code }
async function nullableDetailByName(name: string): Promise<Customer | null> {
return await axios.post(`${BASE_URI}/find/name`, undefined, {
params: { name }
});
}
@@ -47,11 +58,29 @@ async function invitedList(introducerCustomerId: string): Promise<Customer[]> {
}
async function create(req: Customer): Promise<Customer> {
return await axios.post(`${BASE_URI}/create`, req);
const id = await axios.post(`${BASE_URI}/create`, req) as unknown as string;
return {
...req,
id
};
}
async function quickRegister(req: QuickRegisterReq): Promise<RegistrationEventRecord> {
return await axios.post(`${BASE_URI}/quick/register`, req);
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> {
@@ -64,12 +93,17 @@ async function remove(id: string): Promise<void> {
});
}
async function createInvite(req: CustomerInviteUpdateReq): Promise<void> {
return await axios.post(`${BASE_URI}/invite/create`, req);
}
async function updateInvite(req: CustomerInviteUpdateReq): Promise<void> {
return await axios.post(`${BASE_URI}/invite/update`, req);
if (!req.introducerCustomerId) {
await deleteInvite(req.customerId);
return;
}
return await axios.post(`${BASE_URI}/invite/save`, undefined, {
params: {
customerId: req.customerId,
introducerCustomerId: req.introducerCustomerId
}
});
}
async function deleteInvite(customerId: string): Promise<void> {
@@ -79,11 +113,20 @@ async function deleteInvite(customerId: string): Promise<void> {
}
async function dailyStat(req: CustomerTrendStatReq): Promise<CustomerDailyStatView[]> {
return await axios.post(`${BASE_URI}/stat/daily`, req);
return await axios.post(`${BASE_URI}/state/daily`, req);
}
async function genderStat(): Promise<CustomerGenderStatView[]> {
return await axios.post(`${BASE_URI}/stat/gender`);
return await axios.post(`${BASE_URI}/state/gender`);
}
function buildCustomerListExample(req?: CustomerSearchReq): Partial<Customer> {
if (!req?.introducerCustomerId) {
return {};
}
return {
introducerCustomerId: req.introducerCustomerId
};
}
export default {
@@ -92,16 +135,16 @@ export default {
searchPage,
exportExcel,
detail,
detailByCode,
nullableDetailByCode,
nullableDetailByName,
invitedList,
create,
quickRegister,
update,
remove,
createInvite,
updateInvite,
deleteInvite,
dailyStat,
genderStat
};