REVIEW 定时日志

This commit is contained in:
YunaiV 2023-04-01 14:26:29 +08:00
parent 65663df3aa
commit 8810cb953e
9 changed files with 129 additions and 160 deletions

View File

@ -13,50 +13,38 @@ export interface JobVO {
createTime: Date createTime: Date
} }
export interface JobPageReqVO extends PageParam {
name?: string
status?: number
handlerName?: string
}
export interface JobExportReqVO {
name?: string
status?: number
handlerName?: string
}
// 任务列表 // 任务列表
export const getJobPageApi = (params: JobPageReqVO) => { export const getJobPage = (params: PageParam) => {
return request.get({ url: '/infra/job/page', params }) return request.get({ url: '/infra/job/page', params })
} }
// 任务详情 // 任务详情
export const getJobApi = (id: number) => { export const getJob = (id: number) => {
return request.get({ url: '/infra/job/get?id=' + id }) return request.get({ url: '/infra/job/get?id=' + id })
} }
// 新增任务 // 新增任务
export const createJobApi = (data: JobVO) => { export const createJob = (data: JobVO) => {
return request.post({ url: '/infra/job/create', data }) return request.post({ url: '/infra/job/create', data })
} }
// 修改定时任务调度 // 修改定时任务调度
export const updateJobApi = (data: JobVO) => { export const updateJob = (data: JobVO) => {
return request.put({ url: '/infra/job/update', data }) return request.put({ url: '/infra/job/update', data })
} }
// 删除定时任务调度 // 删除定时任务调度
export const deleteJobApi = (id: number) => { export const deleteJob = (id: number) => {
return request.delete({ url: '/infra/job/delete?id=' + id }) return request.delete({ url: '/infra/job/delete?id=' + id })
} }
// 导出定时任务调度 // 导出定时任务调度
export const exportJobApi = (params: JobExportReqVO) => { export const exportJob = (params) => {
return request.download({ url: '/infra/job/export-excel', params }) return request.download({ url: '/infra/job/export-excel', params })
} }
// 任务状态修改 // 任务状态修改
export const updateJobStatusApi = (id: number, status: number) => { export const updateJobStatus = (id: number, status: number) => {
const params = { const params = {
id, id,
status status
@ -70,6 +58,6 @@ export const runJobApi = (id: number) => {
} }
// 获得定时任务的下 n 次执行时间 // 获得定时任务的下 n 次执行时间
export const getJobNextTimesApi = (id: number) => { export const getJobNextTimes = (id: number) => {
return request.get({ url: '/infra/job/get_next_times?id=' + id }) return request.get({ url: '/infra/job/get_next_times?id=' + id })
} }

View File

@ -14,34 +14,18 @@ export interface JobLogVO {
createTime: string createTime: string
} }
export interface JobLogPageReqVO extends PageParam {
jobId?: number
handlerName?: string
beginTime?: string
endTime?: string
status?: number
}
export interface JobLogExportReqVO {
jobId?: number
handlerName?: string
beginTime?: string
endTime?: string
status?: number
}
// 任务日志列表 // 任务日志列表
export const getJobLogPageApi = (params: JobLogPageReqVO) => { export const getJobLogPage = (params: PageParam) => {
return request.get({ url: '/infra/job-log/page', params }) return request.get({ url: '/infra/job-log/page', params })
} }
// 任务日志详情 // 任务日志详情
export const getJobLogApi = (id: number) => { export const getJobLog = (id: number) => {
return request.get({ url: '/infra/job-log/get?id=' + id }) return request.get({ url: '/infra/job-log/get?id=' + id })
} }
// 导出定时任务日志 // 导出定时任务日志
export const exportJobLogApi = (params: JobLogExportReqVO) => { export const exportJobLog = (params) => {
return request.download({ return request.download({
url: '/infra/job-log/export-excel', url: '/infra/job-log/export-excel',
params params

View File

@ -162,7 +162,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
children: [ children: [
{ {
path: 'job-log', path: 'job-log',
component: () => import('@/views/infra/job/JobLog.vue'), component: () => import('@/views/infra/job/logger/index.vue'),
name: 'JobLog', name: 'JobLog',
meta: { meta: {
noCache: true, noCache: true,

View File

@ -59,9 +59,9 @@ const open = async (id: number) => {
if (id) { if (id) {
detailLoading.value = true detailLoading.value = true
try { try {
detailData.value = await JobApi.getJobApi(id) detailData.value = await JobApi.getJob(id)
// //
nextTimes.value = await JobApi.getJobNextTimesApi(id) nextTimes.value = await JobApi.getJobNextTimes(id)
} finally { } finally {
detailLoading.value = false detailLoading.value = false
} }

View File

@ -80,7 +80,7 @@ const open = async (type: string, id?: number) => {
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await JobApi.getJobApi(id) formData.value = await JobApi.getJob(id)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -100,10 +100,10 @@ const submitForm = async () => {
try { try {
const data = formData.value as unknown as JobApi.JobVO const data = formData.value as unknown as JobApi.JobVO
if (formType.value === 'create') { if (formType.value === 'create') {
await JobApi.createJobApi(data) await JobApi.createJob(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await JobApi.updateJobApi(data) await JobApi.updateJob(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
modelVisible.value = false modelVisible.value = false

View File

@ -1,74 +0,0 @@
<template>
<!-- 调度日志详细 -->
<Dialog title="调度日志详细" v-model="modelVisible" width="700px" append-to-body>
<el-form ref="form" :model="formData" label-width="120px" size="mini">
<el-row>
<el-col :span="12">
<el-form-item label="日志编号:">{{ formData.id }}</el-form-item>
<el-form-item label="任务编号:">{{ formData.jobId }}</el-form-item>
<el-form-item label="处理器的名字:">{{ formData.handlerName }}</el-form-item>
<el-form-item label="处理器的参数:">{{ formData.handlerParam }}</el-form-item>
<el-form-item label="第几次执行:">{{ formData.executeIndex }}</el-form-item>
<el-form-item label="执行时间:">{{
parseTime(formData.beginTime) + ' ~ ' + parseTime(formData.endTime)
}}</el-form-item>
<el-form-item label="执行时长:">{{ formData.duration + ' 毫秒' }}</el-form-item>
<el-form-item label="任务状态:">
<dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="formData.status" />
</el-form-item>
<el-form-item label="执行结果:">{{ formData.result }}</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="close"> </el-button>
</div>
</template>
</Dialog>
</template>
<script setup lang="ts" name="JobView">
import * as JobLogApi from '@/api/infra/jobLog'
import { DICT_TYPE } from '@/utils/dict'
import { parseTime } from './utils'
const emit = defineEmits(['success']) // success
const { t } = useI18n() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined,
jobId: undefined,
handlerParam: '',
handlerName: '',
executeIndex: '',
beginTime: undefined,
endTime: undefined,
duration: true,
result: '',
status: undefined
})
/** 打开弹窗 */
const openModal = async (id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.detail')
//
if (id) {
formLoading.value = true
try {
formData.value = await JobLogApi.getJobLogApi(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
const close = () => {
emit('success')
}
</script>

View File

@ -172,7 +172,7 @@ const exportLoading = ref(false) // 导出的加载中
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await JobApi.getJobPageApi(queryParams) const data = await JobApi.getJobPage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -199,7 +199,7 @@ const handleExport = async () => {
await message.exportConfirm() await message.exportConfirm()
// //
exportLoading.value = true exportLoading.value = true
const data = await JobApi.exportJobApi(queryParams) const data = await JobApi.exportJob(queryParams)
download.excel(data, '定时任务.xls') download.excel(data, '定时任务.xls')
} catch { } catch {
} finally { } finally {
@ -224,7 +224,7 @@ const handleChangeStatus = async (row: JobApi.JobVO) => {
) )
const status = const status =
row.status === InfraJobStatusEnum.STOP ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP row.status === InfraJobStatusEnum.STOP ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP
await JobApi.updateJobStatusApi(row.id, status) await JobApi.updateJobStatus(row.id, status)
message.success(text + '成功') message.success(text + '成功')
// //
await getList() await getList()
@ -241,7 +241,7 @@ const handleDelete = async (id: number) => {
// //
await message.delConfirm() await message.delConfirm()
// //
await JobApi.deleteJobApi(id) await JobApi.deleteJob(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()
@ -284,10 +284,10 @@ const openDetail = (id: number) => {
detailRef.value.open(id) detailRef.value.open(id)
} }
// /** 跳转执行日志 */
const handleJobLog = (rowId?: number) => { const handleJobLog = (id: number) => {
if (rowId) { if (id) {
push('/job/job-log?id=' + rowId) push('/job/job-log?id=' + id)
} else { } else {
push('/job/job-log') push('/job/job-log')
} }

View File

@ -0,0 +1,57 @@
<template>
<Dialog title="任务详细" v-model="modelVisible" width="700px">
<el-descriptions border :column="1">
<el-descriptions-item label="日志编号" min-width="60">
{{ detailData.id }}
</el-descriptions-item>
<el-descriptions-item label="任务编号">
{{ detailData.jobId }}
</el-descriptions-item>
<el-descriptions-item label="处理器的名字">
{{ detailData.handlerName }}
</el-descriptions-item>
<el-descriptions-item label="处理器的参数">
{{ detailData.handlerParam }}
</el-descriptions-item>
<el-descriptions-item label="第几次执行">
{{ detailData.executeIndex }}
</el-descriptions-item>
<el-descriptions-item label="执行时间">
{{ formatDate(detailData.beginTime) + ' ~ ' + formatDate(detailData.endTime) }}
</el-descriptions-item>
<el-descriptions-item label="执行时长">
{{ detailData.duration + ' 毫秒' }}
</el-descriptions-item>
<el-descriptions-item label="任务状态">
<dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="detailData.status" />
</el-descriptions-item>
<el-descriptions-item label="执行结果">
{{ detailData.duration + ' result' }}
</el-descriptions-item>
</el-descriptions>
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import * as JobLogApi from '@/api/infra/jobLog'
const modelVisible = ref(false) //
const detailLoading = ref(false) //
const detailData = ref({}) //
/** 打开弹窗 */
const open = async (id: number) => {
modelVisible.value = true
//
if (id) {
detailLoading.value = true
try {
detailData.value = await JobLogApi.getJobLog(id)
} finally {
detailLoading.value = false
}
}
}
defineExpose({ open }) // open
</script>

View File

@ -1,37 +1,52 @@
<template> <template>
<content-wrap> <content-wrap>
<!-- 搜索栏 --> <!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="120px"> <el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="120px"
>
<el-form-item label="处理器的名字" prop="handlerName"> <el-form-item label="处理器的名字" prop="handlerName">
<el-input <el-input
v-model="queryParams.handlerName" v-model="queryParams.handlerName"
placeholder="请输入处理器的名字" placeholder="请输入处理器的名字"
clearable clearable
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="开始执行时间" prop="beginTime"> <el-form-item label="开始执行时间" prop="beginTime">
<el-date-picker <el-date-picker
clearable
v-model="queryParams.beginTime" v-model="queryParams.beginTime"
type="date" type="date"
value-format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss"
placeholder="选择开始执行时间" placeholder="选择开始执行时间"
clearable
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="结束执行时间" prop="endTime"> <el-form-item label="结束执行时间" prop="endTime">
<el-date-picker <el-date-picker
clearable
v-model="queryParams.endTime" v-model="queryParams.endTime"
type="date" type="date"
value-format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss"
placeholder="选择结束执行时间" placeholder="选择结束执行时间"
clearable
:default-time="new Date('1 23:59:59')"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="任务状态" prop="status"> <el-form-item label="任务状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable> <el-select
v-model="queryParams.status"
placeholder="请选择任务状态"
clearable
class="!w-240px"
>
<el-option <el-option
v-for="dict in getDictOptions(DICT_TYPE.INFRA_JOB_LOG_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.INFRA_JOB_LOG_STATUS)"
:key="dict.value" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="dict.value" :value="dict.value"
@ -52,16 +67,19 @@
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</content-wrap>
<!-- 列表 -->
<content-wrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="日志编号" align="center" prop="id" /> <el-table-column label="日志编号" align="center" prop="id" />
<el-table-column label="任务编号" align="center" prop="jobId" /> <el-table-column label="任务编号" align="center" prop="jobId" />
<el-table-column label="处理器的名字" align="center" prop="handlerName" /> <el-table-column label="处理器的名字" align="center" prop="handlerName" />
<el-table-column label="处理器的参数" align="center" prop="handlerParam" /> <el-table-column label="处理器的参数" align="center" prop="handlerParam" />
<el-table-column label="第几次执行" align="center" prop="executeIndex" /> <el-table-column label="第几次执行" align="center" prop="executeIndex" />
<el-table-column label="执行时间" align="center" width="180"> <el-table-column label="执行时间" align="center" width="170s">
<template #default="scope"> <template #default="scope">
<span>{{ parseTime(scope.row.beginTime) + ' ~ ' + parseTime(scope.row.endTime) }}</span> <span>{{ formatDate(scope.row.beginTime) + ' ~ ' + formatDate(scope.row.endTime) }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="执行时长" align="center" prop="duration"> <el-table-column label="执行时长" align="center" prop="duration">
@ -74,40 +92,39 @@
<dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.INFRA_JOB_LOG_STATUS" :value="scope.row.status" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center">
<template #default="scope"> <template #default="scope">
<el-button <el-button
type="primary"
link link
icon="el-icon-view" @click="openDetail(scope.row.id)"
@click="handleView(scope.row.id)"
:loading="exportLoading"
v-hasPermi="['infra:job:query']" v-hasPermi="['infra:job:query']"
>详细 >
详细
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 分页组件 -->
<pagination <Pagination
v-show="total > 0"
:total="total" :total="total"
v-model:page="queryParams.pageNo" v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
@pagination="getList" @pagination="getList"
/> />
</content-wrap> </content-wrap>
<!-- 表单弹窗查看 --> <!-- 表单弹窗查看 -->
<log-view ref="viewModalRef" @success="getList" /> <JobLogDetail ref="detailRef" />
</template> </template>
<script setup lang="ts" name="JobLog"> <script setup lang="ts" name="JobLog">
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import LogView from './JobLogView.vue' import JobLogDetail from './JobLogDetail.vue'
import * as JobLogApi from '@/api/infra/jobLog' import * as JobLogApi from '@/api/infra/jobLog'
import { parseTime } from './utils'
const message = useMessage() // const message = useMessage() //
const { query } = useRoute() //
const loading = ref(true) // const loading = ref(true) //
const total = ref(0) // const total = ref(0) //
@ -115,6 +132,7 @@ const list = ref([]) // 列表的数据
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
jobId: query.id,
handlerName: undefined, handlerName: undefined,
beginTime: undefined, beginTime: undefined,
endTime: undefined, endTime: undefined,
@ -127,11 +145,7 @@ const exportLoading = ref(false) // 导出的加载中
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await JobLogApi.getJobLogPageApi({ const data = await JobLogApi.getJobLogPage(queryParams)
...queryParams,
beginTime: queryParams.beginTime ? queryParams.beginTime + ' 00:00:00' : undefined,
endTime: queryParams.endTime ? queryParams.endTime + ' 23:59:59' : undefined
})
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -152,9 +166,9 @@ const resetQuery = () => {
} }
/** 查看操作 */ /** 查看操作 */
const viewModalRef = ref() const detailRef = ref()
const handleView = (rowId?: number) => { const openDetail = (rowId?: number) => {
viewModalRef.value.openModal(rowId) detailRef.value.open(rowId)
} }
/** 导出按钮操作 */ /** 导出按钮操作 */
@ -164,7 +178,7 @@ const handleExport = async () => {
await message.exportConfirm() await message.exportConfirm()
// //
exportLoading.value = true exportLoading.value = true
const data = await JobLogApi.exportJobLogApi(queryParams) const data = await JobLogApi.exportJobLog(queryParams)
download.excel(data, '定时任务执行日志.xls') download.excel(data, '定时任务执行日志.xls')
} catch { } catch {
} finally { } finally {