Skip to content

Let's use AI to Earn!

feat: 自动任务列表和任务记录列表

牛文政0253617f6bda
diff --git a/electron/db/models/autoRunRecord.ts b/electron/db/models/autoRunRecord.ts
index 3a3f8f54..ba657c0d 100644
--- a/electron/db/models/autoRunRecord.ts
+++ b/electron/db/models/autoRunRecord.ts
@@ -21,6 +21,9 @@ export class AutoRunRecordModel extends TempModel {
@PrimaryGeneratedColumn({ type: 'int', comment: 'id' })
id!: number;
+ @Column({ type: 'int', nullable: false, comment: ' 自动任务id' })
+ autoRunId!: number;
+
@Column({ type: 'varchar', nullable: false, comment: '用户id' })
userId!: string;
diff --git a/electron/db/models/pubRecord.ts b/electron/db/models/pubRecord.ts
index 930af1b3..fa01a6b5 100644
--- a/electron/db/models/pubRecord.ts
+++ b/electron/db/models/pubRecord.ts
@@ -48,7 +48,11 @@ export class PubRecordModel extends TempModel {
timingTime?: Date;
// 封面路径
- @Column({ type: 'varchar', nullable: false, comment: '封面路径,展示给前台用' })
+ @Column({
+ type: 'varchar',
+ nullable: false,
+ comment: '封面路径,展示给前台用',
+ })
coverPath!: string;
// 通用封面路径
diff --git a/electron/main/autoRun/controller.ts b/electron/main/autoRun/controller.ts
index e7afa7a7..fa16865c 100644
--- a/electron/main/autoRun/controller.ts
+++ b/electron/main/autoRun/controller.ts
@@ -7,10 +7,11 @@
*/
import { Controller, Icp, Inject, Scheduled } from '../core/decorators';
import { AutoRunService } from './service';
-import { AutoRunType } from '../../db/models/autoRun';
+import { AutoRunStatus, AutoRunType } from '../../db/models/autoRun';
import { getUserInfo } from '../user/comment';
import { EtEvent } from '../../global/event';
import { autoRunTypeEtTag, hasTriggered } from './comment';
+import { AutoRunRecordStatus } from '../../db/models/autoRunRecord';
@Controller()
export class AutoRunController {
@@ -44,8 +45,21 @@ export class AutoRunController {
* 进程列表
*/
@Icp('ICP_AUTO_RUN_LIST')
- async getAutoRunList(event: Electron.IpcMainInvokeEvent) {
- const list = await this.autoRunService.findAutoRunList({});
+ async getAutoRunList(
+ event: Electron.IpcMainInvokeEvent,
+ pageInfo: {
+ page: number;
+ pageSize: number;
+ },
+ query: {
+ type?: AutoRunType;
+ status?: AutoRunStatus;
+ cycleType?: string;
+ accountId?: number;
+ dataId?: string;
+ },
+ ) {
+ const list = await this.autoRunService.findAutoRunList(pageInfo, query);
return list;
}
@@ -100,8 +114,23 @@ export class AutoRunController {
* 获取进程记录列表
*/
@Icp('ICP_AUTO_RUN_RECORD_LIST')
- async getCommentList(event: Electron.IpcMainInvokeEvent): Promise<any> {
- const list = await this.autoRunService.findAutoRunRecordList({});
+ async getCommentList(
+ event: Electron.IpcMainInvokeEvent,
+ pageInfo: {
+ page: number;
+ pageSize: number;
+ },
+ query: {
+ autoRunId: number;
+ type?: AutoRunType;
+ status?: AutoRunRecordStatus;
+ cycleType?: string;
+ },
+ ): Promise<any> {
+ const list = await this.autoRunService.findAutoRunRecordList(
+ pageInfo,
+ query,
+ );
return list;
}
diff --git a/electron/main/autoRun/service.ts b/electron/main/autoRun/service.ts
index 7cfa7223..d5591176 100644
--- a/electron/main/autoRun/service.ts
+++ b/electron/main/autoRun/service.ts
@@ -5,12 +5,16 @@
* @Description: autoRun AutoRun
*/
import { Injectable } from '../core/decorators';
-import { AutoRunModel, AutoRunStatus } from '../../db/models/autoRun';
+import {
+ AutoRunModel,
+ AutoRunStatus,
+ AutoRunType,
+} from '../../db/models/autoRun';
import {
AutoRunRecordModel,
AutoRunRecordStatus,
} from '../../db/models/autoRunRecord';
-import { Repository } from 'typeorm';
+import { FindOptionsWhere, Repository } from 'typeorm';
import { AppDataSource } from '../../db';
import windowOperate from '../../util/windowOperate';
import { SendChannelEnum } from '../../../commont/UtilsEnum';
@@ -57,10 +61,45 @@ export class AutoRunService {
}
// 查询进程列表
- async findAutoRunList(data: Partial<AutoRunModel>) {
- return await this.autoRunRepository.find({
- where: data,
+ async findAutoRunList(
+ pageInfo: {
+ page: number;
+ pageSize: number;
+ },
+ query: {
+ type?: AutoRunType;
+ status?: AutoRunStatus;
+ cycleType?: string;
+ accountId?: number;
+ dataId?: string;
+ },
+ ): Promise<{
+ list: AutoRunModel[];
+ total: number;
+ }> {
+ const { page, pageSize } = pageInfo;
+ const whereClause: FindOptionsWhere<AutoRunModel> = {
+ ...(query.type !== undefined && { type: query.type }),
+ ...(query.status !== undefined && { status: query.status }),
+ ...(query.cycleType !== undefined && { cycleType: query.cycleType }),
+ ...(query.accountId !== undefined && { accountId: query.accountId }),
+ ...(query.dataId !== undefined && { dataId: query.dataId }),
+ };
+
+ const list = await this.autoRunRepository.find({
+ where: whereClause,
+ skip: (page - 1) * pageSize,
+ take: pageSize,
});
+
+ const total = await this.autoRunRepository.count({
+ where: whereClause,
+ });
+
+ return {
+ list,
+ total,
+ };
}
// 查询需要运行的进程列表
@@ -92,10 +131,40 @@ export class AutoRunService {
}
// 查询进程记录列表
- async findAutoRunRecordList(data: Partial<AutoRunRecordModel>) {
- return await this.autoRunRecordRepository.find({
- where: data,
+ async findAutoRunRecordList(
+ pageInfo: {
+ page: number;
+ pageSize: number;
+ },
+ query: {
+ autoRunId: number;
+ type?: AutoRunType;
+ status?: AutoRunRecordStatus;
+ cycleType?: string;
+ },
+ ) {
+ const { page, pageSize } = pageInfo;
+ const whereClause: FindOptionsWhere<AutoRunRecordModel> = {
+ ...(query.autoRunId !== undefined && { autoRunId: query.autoRunId }),
+ ...(query.type !== undefined && { type: query.type }),
+ ...(query.status !== undefined && { status: query.status }),
+ ...(query.cycleType !== undefined && { cycleType: query.cycleType }),
+ };
+
+ const list = await this.autoRunRecordRepository.find({
+ where: whereClause,
+ skip: (page - 1) * pageSize,
+ take: pageSize,
});
+
+ const total = await this.autoRunRecordRepository.count({
+ where: whereClause,
+ });
+
+ return {
+ list,
+ total,
+ };
}
// 更新进程记录状态
diff --git a/src/icp/autoRun.ts b/src/icp/autoRun.ts
index 521037af..4f0f0373 100644
--- a/src/icp/autoRun.ts
+++ b/src/icp/autoRun.ts
@@ -64,20 +64,49 @@ export async function ipcCreateAutoRun(data: {
/**
* 获取进程列表
- * @param data
+ * @param query
*/
-export async function ipcGetAutoRunList() {
- const res: AutoRun[] = await window.ipcRenderer.invoke('ICP_AUTO_RUN_LIST');
+export async function ipcGetAutoRunList(
+ pageInfo: {
+ page: number;
+ pageSize: number;
+ },
+ query: {
+ type?: AutoRunType;
+ status?: AutoRunStatus;
+ cycleType?: string;
+ accountId?: number;
+ dataId?: string;
+ },
+) {
+ const res: AutoRun[] = await window.ipcRenderer.invoke(
+ 'ICP_AUTO_RUN_LIST',
+ pageInfo,
+ query,
+ );
return res;
}
/**
- * 获取进程列表
+ * 获取进运行记录列表
* @param data
*/
-export async function ipcGetAutoRunRecordList() {
+export async function ipcGetAutoRunRecordList(
+ pageInfo: {
+ page: number;
+ pageSize: number;
+ },
+ query: {
+ autoRunId: number;
+ type?: AutoRunType;
+ status?: AutoRunRecordStatus;
+ cycleType?: string;
+ },
+) {
const res: AutoRunRecord[] = await window.ipcRenderer.invoke(
'ICP_AUTO_RUN_RECORD_LIST',
+ pageInfo,
+ query,
);
return res;
}
diff --git a/src/views/reply/autoRun.tsx b/src/views/reply/autoRun.tsx
new file mode 100644
index 00000000..841ebcf9
--- /dev/null
+++ b/src/views/reply/autoRun.tsx
@@ -0,0 +1,74 @@
+import { Space, Table, Tag } from 'antd';
+import React from 'react';
+
+const { Column } = Table;
+
+interface DataType {
+ key: React.Key;
+ firstName: string;
+ lastName: string;
+ age: number;
+ address: string;
+ tags: string[];
+}
+
+const data: DataType[] = [
+ {
+ key: '1',
+ firstName: 'John',
+ lastName: 'Brown',
+ age: 32,
+ address: 'New York No. 1 Lake Park',
+ tags: ['nice', 'developer'],
+ },
+ {
+ key: '2',
+ firstName: 'Jim',
+ lastName: 'Green',
+ age: 42,
+ address: 'London No. 1 Lake Park',
+ tags: ['loser'],
+ },
+ {
+ key: '3',
+ firstName: 'Joe',
+ lastName: 'Black',
+ age: 32,
+ address: 'Sydney No. 1 Lake Park',
+ tags: ['cool', 'teacher'],
+ },
+];
+
+const Page: React.FC = () => (
+ <Table dataSource={data}>
+ <Column title="Age" dataIndex="age" key="age" />
+ <Column title="Age" dataIndex="age" key="age" />
+ <Column title="Address" dataIndex="address" key="address" />
+ <Column
+ title="Tags"
+ dataIndex="tags"
+ key="tags"
+ render={(tags: string[]) => (
+ <>
+ {tags.map((tag) => (
+ <Tag color="blue" key={tag}>
+ {tag}
+ </Tag>
+ ))}
+ </>
+ )}
+ />
+ <Column
+ title="Action"
+ key="action"
+ render={(_: any, record: DataType) => (
+ <Space size="middle">
+ <a>Invite {record.lastName}</a>
+ <a>Delete</a>
+ </Space>
+ )}
+ />
+ </Table>
+);
+
+export default Page;
diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsx
index 9d55affd..c3d17d84 100644
--- a/src/views/reply/index.tsx
+++ b/src/views/reply/index.tsx
@@ -6,7 +6,7 @@
* @Description: 评论页面 reply
*/
import { icpCreatorList, WorkData, icpCreateCommentList } from '@/icp/reply';
-import { Button, Col, message, Row, Tooltip } from 'antd';
+import { Button, Col, message, Row, Tabs, Tooltip } from 'antd';
import { useCallback, useRef, useState } from 'react';
import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';
import ReplyWorks, { ReplyWorksRef } from './components/replyWorks';
@@ -20,6 +20,7 @@ import {
MenuUnfoldOutlined,
} from '@ant-design/icons';
import styles from './reply.module.scss';
+import AutoRun from './autoRun';
export default function Page() {
const [wordList, setWordList] = useState<WorkData[]>([]);
@@ -97,77 +98,90 @@ export default function Page() {
<AccountSidebar
activeAccountId={activeAccountId}
onAccountChange={useCallback((info) => {
+ setWordList([]);
setActiveAccountId(info.id);
getCreatorList(info.id);
}, [])}
/>
- <div className="grid grid-cols-5 p-4 account-con">
- {wordList.map((item) => (
- <div
- className="bg-white w-[200px] h-[200px] border border-gray-300 p-4 rounded-lg hover:shadow-lg transition-shadow duration-300 m-4"
- key={item.dataId}
- >
- <Row>
- <Col span={12}>
- <div className="w-[100px] h-[200px]">
- <img
- alt="example"
- src={item.coverUrl}
- className="object-cover w-full h-full rounded"
- />
- </div>
- </Col>
- <Col span={12}>
- <div className="flex flex-col h-full">
- <p className="mb-2">{item.title || '无标题'}</p>
- <div className="w-full mt-auto">
- <Row justify="space-evenly">
- <Col span={8}>
- <Tooltip title="评论列表">
- <MenuUnfoldOutlined
- onClick={() => openCommentList(item)}
- />
- </Tooltip>
- </Col>
- <Col span={8}>
- <Tooltip title="评论作品">
- <CommentOutlined
- onClick={() => openReplyWorks(item)}
- />
- </Tooltip>
- </Col>
- </Row>
+ <div className="m-4 ">
+ <Tabs defaultActiveKey="1">
+ <Tabs.TabPane tab="作品列表" key="1">
+ <div className="grid grid-cols-5 p-4 account-con bg-slate-300">
+ {wordList.map((item) => (
+ <div
+ className="bg-white w-[200px] h-[200px] border border-gray-300 p-4 rounded-lg hover:shadow-lg transition-shadow duration-300 m-4"
+ key={item.dataId}
+ >
+ <Row>
+ <Col span={12}>
+ <div className="w-[100px] h-[200px]">
+ <img
+ alt="example"
+ src={item.coverUrl}
+ className="object-cover w-full h-full rounded"
+ />
+ </div>
+ </Col>
+ <Col span={12}>
+ <div className="flex flex-col h-full">
+ <p className="mb-2">{item.title || '无标题'}</p>
+ <div className="w-full mt-auto">
+ <Row justify="space-evenly">
+ <Col span={8}>
+ <Tooltip title="评论列表">
+ <MenuUnfoldOutlined
+ onClick={() => openCommentList(item)}
+ />
+ </Tooltip>
+ </Col>
+ <Col span={8}>
+ <Tooltip title="评论作品">
+ <CommentOutlined
+ onClick={() => openReplyWorks(item)}
+ />
+ </Tooltip>
+ </Col>
+ </Row>
- <Row justify="space-evenly">
- <Col span={8}>
- <Tooltip title="一键评论">
- <AliwangwangOutlined
- onClick={() => createCommentList(item)}
- />
- </Tooltip>
- </Col>
- <Col span={8}>
- <Tooltip title="自动评论">
- <FieldTimeOutlined
- onClick={() => openAddAutoRun(item)}
- />
- </Tooltip>
- </Col>
- </Row>
- </div>
+ <Row justify="space-evenly">
+ <Col span={8}>
+ <Tooltip title="一键评论">
+ <AliwangwangOutlined
+ onClick={() => createCommentList(item)}
+ />
+ </Tooltip>
+ </Col>
+ <Col span={8}>
+ <Tooltip title="自动评论">
+ <FieldTimeOutlined
+ onClick={() => openAddAutoRun(item)}
+ />
+ </Tooltip>
+ </Col>
+ </Row>
+ </div>
+ </div>
+ </Col>
+ </Row>
</div>
- </Col>
- </Row>
- </div>
- ))}
- {wordList.length > 0 && (
- <p>
- <Button type="link" onClick={() => getCreatorList(activeAccountId)}>
- 加载更多
- </Button>
- </p>
- )}
+ ))}
+ {wordList.length > 0 && (
+ <p>
+ <Button
+ type="link"
+ onClick={() => getCreatorList(activeAccountId)}
+ >
+ 加载更多
+ </Button>
+ </p>
+ )}
+ </div>
+ </Tabs.TabPane>
+ <Tabs.TabPane tab="自动任务" key="2">
+ <AutoRun />
+ </Tabs.TabPane>
+ </Tabs>
</div>
<ReplyWorks ref={Ref_ReplyWorks} />