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