Explorar o código

fix: 任务调度

fanfan %!s(int64=2) %!d(string=hai) anos
pai
achega
b5fb83e850

+ 106 - 0
src/api/monitor/monitorJobApi.ts

@@ -0,0 +1,106 @@
+import { defHttp } from '/@/utils/http/axios';
+import { setParams } from '/@/utils/index';
+
+enum Api {
+  monitorJobQueryPage = '/quartz/job/query/page',
+  monitorJobDetail = '/quartz/job/detail',
+  monitorJobAdd = '/quartz/job/add',
+  monitorJobEdit = '/quartz/job/edit',
+  monitorJobRemove = '/quartz/job/removeByIds',
+}
+
+/**
+ *
+ * @author lf
+ * @date  2023/05/05 17:12
+ * @description: 根据条件查询定时任务调度表列表,权限 - quartz:job:query
+ * @method: POST
+ * @param:
+ * @return:
+ *       {String}  jobName  任务名称
+ *       {String}  jobGroup  任务组名
+ *       {String}  invokeTarget  调用目标字符串
+ *       {String}  cronExpression  cron执行表达式
+ *       {String}  misfirePolicy  计划执行错误策略(1立即执行 2执行一次 3放弃执行)
+ *       {Boolean}  concurrent  是否并发执行(0允许 1禁止)
+ *       {Boolean}  disable  状态(0正常 1暂停)
+ *       {String}  remark  备注信息
+ */
+
+export const monitorJobQueryPage = (params?: object) => {
+  return defHttp.post({ url: Api.monitorJobQueryPage, params: setParams(params) });
+};
+/**
+ *
+ * @author lf
+ * @date  2023/05/05 17:12
+ * @description: 根据id查询定时任务调度表详细信息,权限 - quartz:job:query
+ * @method: GET
+ * @param:  id 定时任务调度表主键id
+ * @return:
+ *       {String}  jobName  任务名称
+ *       {String}  jobGroup  任务组名
+ *       {String}  invokeTarget  调用目标字符串
+ *       {String}  cronExpression  cron执行表达式
+ *       {String}  misfirePolicy  计划执行错误策略(1立即执行 2执行一次 3放弃执行)
+ *       {Boolean}  concurrent  是否并发执行(0允许 1禁止)
+ *       {Boolean}  disable  状态(0正常 1暂停)
+ *       {String}  remark  备注信息
+ */
+export const monitorJobDetail = (id: string) => {
+  return defHttp.get({ url: Api.monitorJobDetail + '/' + id });
+};
+
+/**
+ *
+ * @author lf
+ * @date  2023/05/05 17:12
+ * @description: 添加定时任务调度表,权限 - quartz:job:add
+ * @method: POST
+ * @param:
+ *       {String}  jobName  任务名称
+ *       {String}  jobGroup  任务组名
+ *       {String}  invokeTarget  调用目标字符串
+ *       {String}  cronExpression  cron执行表达式
+ *       {String}  misfirePolicy  计划执行错误策略(1立即执行 2执行一次 3放弃执行)
+ *       {Boolean}  concurrent  是否并发执行(0允许 1禁止)
+ *       {Boolean}  disable  状态(0正常 1暂停)
+ *       {String}  remark  备注信息
+ * @return:
+ *       0 添加失败
+ *       1 添加成功
+ */
+export const monitorJobAdd = (params?: object) => {
+  return defHttp.post({ url: Api.monitorJobAdd, params: params });
+};
+
+/**
+ *
+ * @author lf
+ * @date  2023/05/05 17:12
+ * @description: 通过主键id编辑定时任务调度表,权限 - quartz:job:edit
+ * @method: POST
+ * @param:
+ *       {String}  jobName  任务名称
+ *       {String}  jobGroup  任务组名
+ *       {String}  invokeTarget  调用目标字符串
+ *       {String}  cronExpression  cron执行表达式
+ *       {String}  misfirePolicy  计划执行错误策略(1立即执行 2执行一次 3放弃执行)
+ *       {Boolean}  concurrent  是否并发执行(0允许 1禁止)
+ *       {Boolean}  disable  状态(0正常 1暂停)
+ *       {String}  remark  备注信息
+ * @return:
+ *       0 编辑失败
+ *       1 编辑成功
+ */
+export const monitorJobEdit = (params?: object) => {
+  return defHttp.post({ url: Api.monitorJobEdit, params: params });
+};
+
+/**
+ * @description: 删除,权限 - quartz:job:remove
+ * @method: POST
+ */
+export const monitorJobRemove = (params: Array<string | number>) => {
+  return defHttp.post({ url: Api.monitorJobRemove, params: params });
+};

+ 162 - 0
src/views/monitor/job/data.ts

@@ -0,0 +1,162 @@
+import { DescItem } from '/@/components/Description';
+import { BasicColumn, FormSchema } from '/@/components/Table';
+
+export const columns: BasicColumn[] = [
+  {
+    title: '任务名称',
+    dataIndex: 'jobName',
+  },
+  {
+    title: '任务组名',
+    dataIndex: 'jobGroup',
+  },
+  {
+    title: '调用目标字符串',
+    dataIndex: 'invokeTarget',
+  },
+  {
+    title: 'cron执行表达式',
+    dataIndex: 'cronExpression',
+  },
+  {
+    title: '计划执行错误策略(1立即执行 2执行一次 3放弃执行)',
+    dataIndex: 'misfirePolicy',
+  },
+  {
+    title: '是否并发执行(0允许 1禁止)',
+    dataIndex: 'concurrent',
+  },
+  {
+    title: '状态(0正常 1暂停)',
+    dataIndex: 'disable',
+  },
+  {
+    title: '备注信息',
+    dataIndex: 'remark',
+  },
+];
+
+// 表单列定义
+export const searchFormSchema: FormSchema[] = [];
+// 表单新增编辑
+export const dataFormSchema: FormSchema[] = [
+  {
+    label: '任务名称',
+    field: 'jobName',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入任务名称',
+    },
+  },
+  {
+    label: '任务组名',
+    field: 'jobGroup',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入任务组名',
+    },
+  },
+  {
+    label: '调用目标字符串',
+    field: 'invokeTarget',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入调用目标字符串',
+    },
+  },
+  {
+    label: 'cron执行表达式',
+    field: 'cronExpression',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入cron执行表达式',
+    },
+  },
+  {
+    label: '计划执行错误策略(1立即执行 2执行一次 3放弃执行)',
+    field: 'misfirePolicy',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入计划执行错误策略(1立即执行 2执行一次 3放弃执行)',
+    },
+  },
+  {
+    label: '是否并发执行(0允许 1禁止)',
+    field: 'concurrent',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入是否并发执行(0允许 1禁止)',
+    },
+  },
+  {
+    label: '状态(0正常 1暂停)',
+    field: 'disable',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入状态(0正常 1暂停)',
+    },
+  },
+  {
+    label: '备注信息',
+    field: 'remark',
+    required: true,
+    component: 'Input',
+    componentProps: {
+      placeholder: '请输入备注信息',
+    },
+  },
+];
+// 表单详情查看
+export const viewSchema: DescItem[] = [
+  {
+    label: '任务ID',
+    field: 'jobId',
+  },
+  {
+    label: '任务名称',
+    field: 'jobName',
+  },
+  {
+    label: '任务组名',
+    field: 'jobGroup',
+  },
+  {
+    label: '调用目标字符串',
+    field: 'invokeTarget',
+  },
+  {
+    label: 'cron执行表达式',
+    field: 'cronExpression',
+  },
+  {
+    label: '计划执行错误策略(1立即执行 2执行一次 3放弃执行)',
+    field: 'misfirePolicy',
+  },
+  {
+    label: '是否并发执行(0允许 1禁止)',
+    field: 'concurrent',
+  },
+  {
+    label: '状态(0正常 1暂停)',
+    field: 'disable',
+  },
+  {
+    label: '创建时间',
+    field: 'createTime',
+  },
+  {
+    label: '更新时间',
+    field: 'updateTime',
+  },
+  {
+    label: '备注信息',
+    field: 'remark',
+  },
+];

+ 71 - 0
src/views/monitor/job/formDrawer.vue

@@ -0,0 +1,71 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    destroyOnClose
+    @register="registerDrawer"
+    :title="getTitle"
+    :width="width"
+    @ok="handleSubmit"
+    :showFooter="true"
+  >
+    <BasicForm @register="registerForm" layout="vertical" />
+  </BasicDrawer>
+</template>
+<script lang="ts" setup>
+  import { ref, computed, unref } from 'vue';
+  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
+  import { BasicForm, useForm } from '/@/components/Form';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { dataFormSchema } from './data';
+
+  import { monitorJobAdd, monitorJobEdit, monitorJobDetail } from '/@/api/monitor/monitorJobApi';
+
+  const emit = defineEmits(['success', 'register']);
+
+  const getTitle = computed(() => (!unref(isUpdate) ? '新增定时任务调度表' : '编辑定时任务调度表'));
+  const width = '45%';
+  const isUpdate = ref(false);
+  const rowId = ref();
+
+  const { createMessage } = useMessage();
+  const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
+    labelWidth: 100,
+    schemas: dataFormSchema,
+    showActionButtonGroup: false,
+    actionColOptions: {
+      span: 23,
+    },
+  });
+  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async data => {
+    await resetFields();
+    setDrawerProps({ confirmLoading: false });
+    isUpdate.value = !!data?.isUpdate;
+
+    if (unref(isUpdate)) {
+      const resData = await monitorJobDetail(data.record.id);
+      rowId.value = resData.id;
+      await setFieldsValue({
+        ...resData,
+      });
+    }
+  });
+
+  // 提交按钮事件
+  async function handleSubmit() {
+    try {
+      const values = await validate();
+      setDrawerProps({ confirmLoading: true });
+      !unref(isUpdate)
+        ? await monitorJobAdd({ ...values })
+        : await monitorJobEdit({ ...values, id: rowId.value });
+      !unref(isUpdate) ? createMessage.success('新增成功!') : createMessage.success('编辑成功!');
+      closeDrawer();
+      emit('success', {
+        isUpdate: unref(isUpdate),
+        values: { ...values, id: rowId.value },
+      });
+    } finally {
+      setDrawerProps({ confirmLoading: false });
+    }
+  }
+</script>

+ 185 - 3
src/views/monitor/job/index.vue

@@ -1,7 +1,189 @@
 <template>
-  <div> 代码生成 </div>
+  <div>
+    <BasicTable @register="registerTable">
+      <template #bodyCell="{ column, record }">
+        <template v-if="column.key === 'action'">
+          <TableAction
+            :actions="[
+              {
+                auth: 'quartz:job:query',
+                icon: 'icon-eye|iconfont',
+                tooltip: '查看',
+                label: '查看',
+                onClick: handleView.bind(null, record),
+              },
+              {
+                auth: 'quartz:job:edit',
+                icon: 'icon-edit|iconfont',
+                tooltip: '编辑',
+                label: '编辑',
+                onClick: handleEdit.bind(null, record),
+              },
+              {
+                auth: 'quartz:job:remove',
+                icon: 'icon-delete|iconfont',
+                tooltip: '删除',
+                label: '删除',
+                color: 'error',
+                popConfirm: {
+                  title: '是否确认删除',
+                  placement: 'left',
+                  confirm: handleDelete.bind(null, record),
+                },
+              },
+            ]"
+          />
+        </template>
+      </template>
+      <template #toolbar>
+        <Button
+          v-auth="['quartz:job:add']"
+          type="primary"
+          @click="handleCreate"
+          preIcon="icon-plus|iconfont"
+        >
+          新增
+        </Button>
+        <Button
+          v-auth="['quartz:job:remove']"
+          type="primary"
+          danger
+          @click="handleDelete(null)"
+          preIcon="icon-delete|iconfont"
+        >
+          批量删除
+        </Button>
+      </template>
+    </BasicTable>
+    <FormDrawer @register="registerDrawer" @success="handleSuccess" />
+    <ViewDrawer @register="registerDrawerView" @success="handleSuccess" />
+  </div>
 </template>
+<script lang="ts" setup>
+  import { onBeforeMount, ref } from 'vue';
+  //   import { Tag } from 'ant-design-vue';
+  import { Button } from '/@/components/Button';
 
-<script setup lang="ts"></script>
+  import { BasicTable, useTable, TableAction } from '/@/components/Table';
 
-<style lang="less" scoped></style>
+  // import { useModal } from '/@/components/Modal';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import FormDrawer from './formDrawer.vue';
+  import ViewDrawer from './viewDrawer.vue';
+  import { columns, searchFormSchema } from './data';
+
+  import { monitorJobQueryPage, monitorJobRemove } from '/@/api/monitor/monitorJobApi';
+  //   import { listDictModel } from '/@/api/common';
+  //   import { formatDictColor, formatDictValue, commonDict } from '/@/utils';
+  import { useDrawer } from '/@/components/Drawer';
+
+  onBeforeMount(async () => {});
+
+  const { createConfirm, createMessage } = useMessage();
+  // const [registerModal, { openModal }] = useModal();
+  const [registerDrawer, { openDrawer }] = useDrawer();
+  const [registerDrawerView, { openDrawer: openDrawerView }] = useDrawer();
+
+  const tableSort = ref([
+    {
+      field: 'create_time',
+      direction: 'DESC',
+    },
+  ]) as any;
+
+  const [registerTable, { reload, getSelectRowKeys }] = useTable({
+    title: '定时任务 ',
+    api: monitorJobQueryPage,
+    rowKey: 'jobId',
+    columns,
+    showIndexColumn: true,
+    rowSelection: { type: 'checkbox' },
+    formConfig: {
+      labelWidth: 120,
+      schemas: searchFormSchema,
+      autoSubmitOnEnter: true,
+      baseColProps: { xs: 24, sm: 12, md: 12, lg: 8 },
+      resetButtonOptions: {
+        preIcon: 'icon-delete|iconfont',
+      },
+      submitButtonOptions: {
+        preIcon: 'icon-search|iconfont',
+      },
+    },
+    useSearchForm: true,
+    bordered: true,
+    actionColumn: {
+      width: 200,
+      title: '操作',
+      dataIndex: 'action',
+    },
+    beforeFetch: handleBeforeFetch,
+    sortFn: handleSortFn,
+  });
+  // 详情按钮事件
+  function handleView(record: Recordable) {
+    console.log(record);
+    openDrawerView(true, {
+      record,
+    });
+  }
+
+  // 新增按钮事件
+  function handleCreate() {
+    openDrawer(true, {
+      isUpdate: false,
+    });
+  }
+
+  // 编辑按钮事件
+  function handleEdit(record: Recordable) {
+    openDrawer(true, {
+      record,
+      isUpdate: true,
+    });
+  }
+
+  // 删除按钮事件
+  async function handleDelete(record: Recordable) {
+    if (record) {
+      await monitorJobRemove([record.jobId]);
+      createMessage.success('删除成功!');
+      await reload();
+    } else {
+      createConfirm({
+        content: '你确定要删除?',
+        iconType: 'warning',
+        onOk: async () => {
+          const keys = getSelectRowKeys();
+          await monitorJobRemove(keys);
+          createMessage.success('删除成功!');
+          await reload();
+        },
+      });
+    }
+  }
+  // 表格点击字段排序
+  function handleSortFn(sortInfo) {
+    if (sortInfo?.order && sortInfo?.columnKey) {
+      // 默认单列排序
+      tableSort.value = [
+        {
+          field: sortInfo.columnKey,
+          direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
+        },
+      ];
+    }
+  }
+
+  // 表格请求之前,对参数进行处理, 添加默认 排序
+  function handleBeforeFetch(params) {
+    return { ...params, orders: tableSort.value };
+  }
+
+  // 弹窗回调事件
+  async function handleSuccess({ isUpdate, values }) {
+    console.log(isUpdate);
+    console.log(values);
+    await reload();
+  }
+</script>

+ 42 - 0
src/views/monitor/job/viewDrawer.vue

@@ -0,0 +1,42 @@
+<template>
+  <BasicDrawer
+    v-bind="$attrs"
+    destroyOnClose
+    @register="registerDrawer"
+    :title="getTitle"
+    :width="width"
+  >
+    <Description @register="registerDesc" :data="descData" />
+  </BasicDrawer>
+</template>
+<script lang="ts" setup>
+  import { onBeforeMount, ref } from 'vue'; // onBeforeMount,
+  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
+  import { Description, useDescription } from '/@/components/Description';
+  import { viewSchema } from './data';
+
+  import { monitorJobDetail } from '/@/api/monitor/monitorJobApi';
+  //   import { listDictModel } from '/@/api/common';
+  //   import { formatDictValue } from '/@/utils';
+
+  const descData = ref({});
+  const getTitle = '查看定时任务调度表';
+  const width = '45%';
+
+  onBeforeMount(async () => {});
+  const [registerDrawer] = useDrawerInner(async data => {
+    console.log('::::::::::', data.record);
+    const resData = await monitorJobDetail(data.record.id);
+    descData.value = {
+      ...resData,
+    };
+  });
+  const [registerDesc] = useDescription({
+    schema: viewSchema,
+    column: 2,
+    size: 'middle',
+    labelStyle: {
+      width: '120px',
+    },
+  });
+</script>