mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-27 22:56:07 +08:00
增加去重功能
This commit is contained in:
parent
0792f7c5f6
commit
34b04bccc1
|
@ -191,6 +191,24 @@ export default (app: Router) => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
route.delete(
|
||||||
|
'/crons/remove-duplicate',
|
||||||
|
celebrate({
|
||||||
|
body: Joi.array().items(Joi.string().required()),
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
|
try {
|
||||||
|
const cronService = Container.get(CronService);
|
||||||
|
const data = await cronService.removeDuplicate(req.body);
|
||||||
|
return res.send({ code: 200, data });
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
route.get(
|
route.get(
|
||||||
'/crons/import',
|
'/crons/import',
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
|
|
@ -107,6 +107,26 @@ export default class CronService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async removeDuplicate(ids: string[]) {
|
||||||
|
return new Promise((resolve: any) => {
|
||||||
|
{
|
||||||
|
this.cronDb.find({ _id: { $in: ids } }).exec((err, docs: Crontab[]) => {
|
||||||
|
const nameSet = new Set<string>();
|
||||||
|
const removeIdsSet = new Set<string>();
|
||||||
|
docs.forEach((item) => {
|
||||||
|
if (nameSet.has(item.name)) {
|
||||||
|
removeIdsSet.add(item._id);
|
||||||
|
} else {
|
||||||
|
nameSet.add(item.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const removeIds: string[] = Array.from(removeIdsSet);
|
||||||
|
this.remove(removeIds).then(resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async crontabs(searchText?: string): Promise<Crontab[]> {
|
public async crontabs(searchText?: string): Promise<Crontab[]> {
|
||||||
let query = {};
|
let query = {};
|
||||||
if (searchText) {
|
if (searchText) {
|
||||||
|
|
|
@ -492,6 +492,31 @@ const Crontab = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeDuplicate = () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '确认去重',
|
||||||
|
content: <>确认删除选中的重复定时任务吗</>,
|
||||||
|
onOk() {
|
||||||
|
request
|
||||||
|
.delete(`${config.apiPrefix}crons/remove-duplicate`, {
|
||||||
|
data: selectedRowIds,
|
||||||
|
})
|
||||||
|
.then((data: any) => {
|
||||||
|
if (data.code === 200) {
|
||||||
|
message.success('批量删除成功');
|
||||||
|
setSelectedRowIds([]);
|
||||||
|
getCrons();
|
||||||
|
} else {
|
||||||
|
message.error(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onCancel() {
|
||||||
|
console.log('Cancel');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const operateCrons = (operationStatus: number) => {
|
const operateCrons = (operationStatus: number) => {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: `确认${OperationName[operationStatus]}`,
|
title: `确认${OperationName[operationStatus]}`,
|
||||||
|
@ -579,6 +604,13 @@ const Crontab = () => {
|
||||||
<Button type="primary" style={{ marginBottom: 5 }} onClick={delCrons}>
|
<Button type="primary" style={{ marginBottom: 5 }} onClick={delCrons}>
|
||||||
批量删除
|
批量删除
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
style={{ marginLeft: 8, marginBottom: 5 }}
|
||||||
|
onClick={removeDuplicate}
|
||||||
|
>
|
||||||
|
批量去重
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => operateCrons(0)}
|
onClick={() => operateCrons(0)}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user