refactor event
This commit is contained in:
+64
-21
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { axios, type Page, type PageResult } from "timi-web";
|
||||
import type { RegistrationEvent } from "@/types/RegistrationEvent";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
|
||||
const BASE_URI = "/gao/registration-event";
|
||||
const BASE_URI = "/gao/event";
|
||||
|
||||
async function list(req: Page<RegistrationEvent>): Promise<PageResult<RegistrationEvent>> {
|
||||
async function list(req: Page<EventItem>): Promise<PageResult<EventItem>> {
|
||||
return await axios.post(`${BASE_URI}/list`, req);
|
||||
}
|
||||
|
||||
async function enabledList(): Promise<RegistrationEvent[]> {
|
||||
return await axios.post(`${BASE_URI}/enabled/list`);
|
||||
async function enabledList(): Promise<EventItem[]> {
|
||||
return await axios.post(`${BASE_URI}/list/valid`);
|
||||
}
|
||||
|
||||
async function detail(id: string): Promise<RegistrationEvent> {
|
||||
async function detail(id: string): Promise<EventItem> {
|
||||
return await axios.post(`${BASE_URI}/detail`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
async function create(req: RegistrationEvent): Promise<void> {
|
||||
async function create(req: EventItem): Promise<void> {
|
||||
return await axios.post(`${BASE_URI}/create`, req);
|
||||
}
|
||||
|
||||
async function update(req: RegistrationEvent): Promise<void> {
|
||||
async function update(req: EventItem): Promise<void> {
|
||||
return await axios.post(`${BASE_URI}/update`, req);
|
||||
}
|
||||
|
||||
@@ -44,3 +44,4 @@ export default {
|
||||
sort,
|
||||
remove
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { axios, type Page, type PageResult, type Role } from "timi-web";
|
||||
import type { GaoUser } from "@/types/GaoUser";
|
||||
import type { ManagedUser } from "@/types/ManagedUser";
|
||||
|
||||
const BASE_URI = "/gao/user";
|
||||
|
||||
async function list(req: Page<GaoUser>): Promise<PageResult<GaoUser>> {
|
||||
async function list(req: Page<ManagedUser>): Promise<PageResult<ManagedUser>> {
|
||||
return await axios.post(`${BASE_URI}/list`, req);
|
||||
}
|
||||
|
||||
async function detail(id: string): Promise<GaoUser> {
|
||||
async function detail(id: string): Promise<ManagedUser> {
|
||||
return await axios.post(`${BASE_URI}/detail`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
async function create(req: GaoUser): Promise<GaoUser> {
|
||||
async function create(req: ManagedUser): Promise<ManagedUser> {
|
||||
return await axios.post(`${BASE_URI}/create`, req);
|
||||
}
|
||||
|
||||
async function update(req: GaoUser): Promise<GaoUser> {
|
||||
async function update(req: ManagedUser): Promise<ManagedUser> {
|
||||
return await axios.post(`${BASE_URI}/update`, req);
|
||||
}
|
||||
|
||||
@@ -39,3 +39,4 @@ export default {
|
||||
remove,
|
||||
roleList
|
||||
};
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
import { axios, type Page, type PageResult } from "timi-web";
|
||||
import type {
|
||||
CustomerRegisterStatView,
|
||||
CustomerRegistrationRankView,
|
||||
RegistrationEventRecordCalendarView,
|
||||
RegistrationEventRecord,
|
||||
RegistrationEventRecordCreateReq,
|
||||
RegistrationEventRecordDailyStatView,
|
||||
RegistrationEventRecordListItemView,
|
||||
RegistrationEventRecordRangeReq,
|
||||
RegistrationEventRecordStatReq,
|
||||
RegistrationEventRecordTrendStatReq
|
||||
} from "@/types/RegistrationEventRecord";
|
||||
|
||||
const BASE_URI = "/gao/registration-event-record";
|
||||
|
||||
async function list(req: Page<RegistrationEventRecord>): Promise<PageResult<RegistrationEventRecord>> {
|
||||
return await axios.post(`${BASE_URI}/list`, req);
|
||||
}
|
||||
|
||||
async function detail(id: string): Promise<RegistrationEventRecord> {
|
||||
return await axios.post(`${BASE_URI}/detail`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
async function rangeList(req: RegistrationEventRecordRangeReq): Promise<RegistrationEventRecord[]> {
|
||||
return await axios.post(`${BASE_URI}/range/list`, req);
|
||||
}
|
||||
|
||||
async function calendarRangeList(req: RegistrationEventRecordRangeReq): Promise<RegistrationEventRecordCalendarView[]> {
|
||||
return await axios.post(`${BASE_URI}/range/calendar/list`, req);
|
||||
}
|
||||
|
||||
async function rangePage(req: Page<RegistrationEventRecordRangeReq>): Promise<PageResult<RegistrationEventRecordListItemView>> {
|
||||
return await axios.post(`${BASE_URI}/range/page`, req);
|
||||
}
|
||||
|
||||
async function rangeExport(req: RegistrationEventRecordRangeReq): Promise<Blob> {
|
||||
return await axios.post(`${BASE_URI}/range/export`, req, {
|
||||
responseType: "blob"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function create(req: RegistrationEventRecordCreateReq): Promise<RegistrationEventRecord[]> {
|
||||
return await axios.post(`${BASE_URI}/create`, req);
|
||||
}
|
||||
|
||||
async function update(req: RegistrationEventRecord): 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 customerRangeStat(req: RegistrationEventRecordStatReq): Promise<CustomerRegisterStatView[]> {
|
||||
return await axios.post(`${BASE_URI}/customer/range/stat`, req);
|
||||
}
|
||||
|
||||
async function allCustomerRangeStat(req: RegistrationEventRecordStatReq): Promise<CustomerRegisterStatView[]> {
|
||||
return await axios.post(`${BASE_URI}/all-customer/range/stat`, req);
|
||||
}
|
||||
|
||||
async function customerRegistrationRank(req?: Partial<RegistrationEventRecordRangeReq>): Promise<CustomerRegistrationRankView[]> {
|
||||
return await axios.post(`${BASE_URI}/customer/registration-rank`, req);
|
||||
}
|
||||
|
||||
async function customerRegistrationEventDailyStat(req: RegistrationEventRecordTrendStatReq): Promise<RegistrationEventRecordDailyStatView[]> {
|
||||
return await axios.post(`${BASE_URI}/customer/registration-event/daily/stat`, req);
|
||||
}
|
||||
|
||||
async function allCustomerRegistrationEventDailyStat(req: RegistrationEventRecordTrendStatReq): Promise<RegistrationEventRecordDailyStatView[]> {
|
||||
return await axios.post(`${BASE_URI}/all-customer/registration-event/daily/stat`, req);
|
||||
}
|
||||
|
||||
export default {
|
||||
list,
|
||||
detail,
|
||||
rangeList,
|
||||
calendarRangeList,
|
||||
rangePage,
|
||||
rangeExport,
|
||||
create,
|
||||
update,
|
||||
remove,
|
||||
customerRangeStat,
|
||||
allCustomerRangeStat,
|
||||
customerRegistrationRank,
|
||||
customerRegistrationEventDailyStat,
|
||||
allCustomerRegistrationEventDailyStat
|
||||
};
|
||||
Reference in New Issue
Block a user