broker.ts
4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { AnyObject, QueryForPaginationParams, QueryForParams, ServiceResponse } from '@/types/global';
import { User } from '@/utils/model';
import axios, { AxiosRequestConfig } from 'axios';
import FileSaver from 'file-saver';
export default class useBrokerApi {}
export interface BrokerUserConfigItem {
user_id: number;
user?: User;
identifier: '';
singer_count: 0;
status: 0 | 1;
}
export interface BrokerUserConfig {
id: number;
title: string;
begin_at: string;
end_at: string;
push_type: number;
push_at: string;
user_id: number;
user?: User;
items?: BrokerUserConfigItem[];
}
export class useUserConfigApi {
static get(params?: QueryForParams | QueryForPaginationParams): Promise<ServiceResponse<BrokerUserConfig[]>> {
return axios.get('system/broker/user-configs', { params });
}
static async create(data: AnyObject): Promise<BrokerUserConfig> {
return axios.post('system/broker/user-configs', data).then((res) => Promise.resolve(res.data));
}
static async createLevel(id: number, data: AnyObject) {
return axios.post(`system/broker/user-configs/${id}/level`, data).then((res) => Promise.resolve(res.data));
}
static async show(id: number): Promise<BrokerUserConfig> {
return axios.get(`system/broker/user-configs/${id}`).then((res) => Promise.resolve(res.data));
}
static async update(id: number, data: AnyObject): Promise<BrokerUserConfig> {
return axios.put(`system/broker/user-configs/${id}`, data).then((res) => Promise.resolve(res.data));
}
static async destroy(id: number) {
return axios.delete(`system/broker/user-configs/${id}`).then((res) => Promise.resolve(res.data));
}
}
export interface BrokerPushConfig {
id: number;
identifier: string;
title: string;
intro: string;
match_title: string;
match_intro: string;
user_id: number;
user?: User;
}
export class usePushConfigApi {
static get(params?: QueryForParams | QueryForPaginationParams): Promise<ServiceResponse<BrokerPushConfig[]>> {
return axios.get('system/broker/push-configs', { params });
}
static async create(data: AnyObject): Promise<BrokerPushConfig> {
return axios.post('system/broker/push-configs', data).then((res) => Promise.resolve(res.data));
}
static async update(id: number, data: AnyObject): Promise<BrokerPushConfig> {
return axios.put(`system/broker/push-configs/${id}`, data).then((res) => Promise.resolve(res.data));
}
static async destroy(id: number) {
return axios.delete(`system/broker/push-configs/${id}`).then((res) => Promise.resolve(res.data));
}
}
export class usePushMatchRecordApi {
static get(params?: QueryForParams | QueryForPaginationParams): Promise<ServiceResponse> {
return axios.get('system/broker/push-match-records', { params });
}
static async getExport(fileName: string, params?: QueryForParams) {
const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
return axios.get('system/broker/push-match-records', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
}
static async rollback(recordId: number) {
return axios.post(`system/broker/push-match-records/${recordId}/rollback`);
}
static async send(recordId: number) {
return axios.post(`system/broker/push-match-records/${recordId}/send`);
}
}
export interface BrokerPushLevel {
id: number;
user_id: number;
title: string;
is_alert: 1 | 0;
begin_at: string;
end_at: string;
publish_at: string;
status: number;
}
export class usePushLevelRecordApi {
static statusOption = [
{ value: 0, label: '待发送' },
{ value: 1, label: '处理中' },
{ value: 2, label: '已发送' },
{ value: 3, label: '已撤销' },
{ value: -1, label: '发送失败' },
];
static async get(params?: QueryForParams | QueryForPaginationParams): Promise<ServiceResponse<BrokerPushLevel[]>> {
return axios.get('system/broker/push-level-records', { params });
}
static async update(id: number, data: AnyObject): Promise<BrokerPushLevel> {
return axios.put(`system/broker/push-level-records/${id}`, data).then((res) => Promise.resolve(res.data));
}
static async send(id: number) {
return axios.post(`system/broker/push-level-records/${id}/send`).then((res) => Promise.resolve(res.data));
}
static async rollback(id: number) {
return axios.post(`system/broker/push-level-records/${id}/rollback`).then((res) => Promise.resolve(res.data));
}
static async destroy(id: number) {
return axios.delete(`system/broker/push-level-records/${id}`).then((res) => Promise.resolve(res.data));
}
static getChildren(id: number, params?: QueryForParams | QueryForPaginationParams) {
return axios.get(`system/broker/push-level-records/${id}/children`, { params });
}
}