zhaowei
2 天以前 57fdca64e4e6d2573f116917b87c4c9155053c23
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
 
<template>
  <a-modal :title="title" width="100%" :visible="visible" :maskClosable="false" @ok="handleOk" @cancel="handleCancel"
           cancelText="关闭">
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
 
            <a-col :md="6" :sm="6">
              <a-form-item label="任务名称">
                <a-input placeholder="请输入任务名称" v-model="queryParam.jobName"></a-input>
              </a-form-item>
            </a-col>
 
            <a-col :md="6" :sm="6">
              <a-form-item label="时间">
                <a-range-picker show-time @change="dateParamChange" :disabledDate="disabledDate" format="YYYY-MM-DD HH:mm:ss" v-model="dates"/>
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="4">
              <a-space>
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload">重置</a-button>
                <a-button type="primary" icon="download" @click="handleExportXls('执行日志导出')">导出</a-button>
              </a-space>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 操作按钮区域 -->
      <div class="table-operator">
 
        <!--<a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
      </div>
      <!-- table区域-begin -->
      <div>
        <a-table ref="table" size="middle" bordered rowKey="index" :scroll="{  y: 400 }" :columns="columns"
                 :dataSource="dataSource" :pagination="ipagination" :loading="loading"
                 @change="handleTableChange">
          <!-- 状态渲染模板 -->
          <template slot="customRenderStatus" slot-scope="isSuccess">
            <a-tag v-if="isSuccess==0" color="green">成功</a-tag>
            <a-tag v-if="isSuccess==-1" color="red">失败</a-tag>
          </template>
          <span slot="action" slot-scope="text, record">
             <a @click="executeImmediately(record)">查看详情</a>
        </span>
        </a-table>
      </div>
      <!-- table区域-end -->
      <quartz-job-details ref="modalForm"></quartz-job-details>
 
    </a-card>
  </a-modal>
</template>
 
<script>
  import { filterObj } from '@/utils/util';
  import {
    ajaxGetSelectItems
  } from '@/api/api'
  import JDictSelectTag from '@/components/dict/JDictSelectTag'
  import {
    deleteAction,
    requestPut,
    getAction,
    downFile,
    postAction
  } from '@/api/manage'
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import JInput from '@/components/jeecg/JInput'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import Tooltip from 'ant-design-vue/es/tooltip'
  import JDate from '@/components/jeecg/JDate'
  import moment from 'moment'
  import QuartzJobDetails from './QuartzJobDetails'
  export default {
    name: 'QuartzJobListModal',
    // mixins: [JeecgListMixin],
    components: {
      JDictSelectTag,
      JEllipsis,
      JInput,
      Tooltip,
      JDate,
      QuartzJobDetails
    },
    props: {
      status: {
        type: Number,
        default: 1
      }
    },
    data() {
      return {
        title:'',
        visible:false,
        /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
        queryParam: {},
        /* 数据源 */
        dataSource:[],
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        /* 排序参数 */
        isorter:{
          column: 'createTime',
          order: 'desc',
        },
        /* 筛选参数 */
        filters: {},
        /* table加载状态 */
        loading:false,
        /* table选中keys*/
        selectedRowKeys: [],
        /* table选中records*/
        selectionRows: [],
        /* 查询折叠 */
        toggleSearchStatus:false,
        /* 高级查询条件生效状态 */
        superQueryFlag:false,
        /* 高级查询条件 */
        superQueryParams: '',
        /** 高级查询拼接方式 */
        superQueryMatchType: 'and',
 
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          // {
          //   title: '任务名称',
          //   align: 'center',
          //   dataIndex: 'jobClassName',
          // },
          // {
          //   title: 'cron表达式',
          //   align: 'center',
          //   dataIndex: 'cronExpression',
          // },
          {
            title: '任务名称',
            align: 'center',
            dataIndex: 'jobName'
          },
          {
            title: '参数',
            align: 'center',
            dataIndex: 'parameter'
          },
 
          {
            title: '日志信息',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          },
          {
            title: '成功标志',
            align: 'center',
            dataIndex: 'isSuccess',
            scopedSlots: { customRender: 'customRenderStatus' },
            filterMultiple: false,
            filters: [
              { text: '成功', value: '0' },
              { text: '失败', value: '-1' },
            ]
          },
          {
            title: '执行时间(毫秒)',
            align: 'center',
            dataIndex: 'executionTime',
            customRender:(t,r,index) =>{
              var milliseconds = parseInt(t)
                let hours = Math.floor(milliseconds / 3600000);
                milliseconds = milliseconds % 3600000;
                let minutes = Math.floor(milliseconds / 60000);
                milliseconds = milliseconds % 60000;
                let seconds = Math.floor(milliseconds / 1000);
                milliseconds = milliseconds % 1000;
                if(hours == 0){
                  if(minutes == 0){
                    if(seconds == 0) {
                      return `${milliseconds}毫秒`
                    }else{
                      return `${seconds}秒 ${milliseconds}毫秒`
                    }
                  }else{
                    return `${minutes}分钟 ${seconds}秒 ${milliseconds}毫秒`;
                  }
                }else{
                  return `${hours}小时 ${minutes}分钟 ${seconds}秒 ${milliseconds}毫秒`;
                }
 
            }
 
          },
          {
            title: '任务执行时间',
            align: 'center',
            dataIndex: 'createTime'
          },
        ],
        sectionPData: [],
        sectionData: [],
        url: {
          list: '/sys/quartzLog/list',
          exportXlsUrl:'/sys/quartzLog/exportXls'
        },
        value:undefined,
        valueProduct:undefined,
        dates: [],
      }
    },
    created() {
 
    },
    watch: {
 
    },
    methods: {
      searchReset() {
        let id =  this.queryParam.jobId
        this.queryParam = {}
        this.dates = []
        this.queryParam.jobId = id
        this.loadData(1);
      },
      executeImmediately:function (record) {
        this.$refs.modalForm.showDetails(record);
        this.$refs.modalForm.title = "日志信息";
        this.$refs.modalForm.disableSubmit = false;
      },
      handleExportXls(fileName){
        if(!fileName || typeof fileName != "string"){
          fileName = "导出文件"
        }
        let param = this.getQueryParams();
        if(this.selectedRowKeys && this.selectedRowKeys.length>0){
          param['selections'] = this.selectedRowKeys.join(",")
        }
        console.log("导出参数",param)
        downFile(this.url.exportXlsUrl,param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xls')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      disabledDate(current) {
        return current && current > moment().subtract('days', 1);
      },
      dateParamChange(v1, v2) {
        this.queryParam.startTime = v2[0]
        this.queryParam.endTime = v2[1]
      },
      handleTableChange(pagination, filters, sorter) {
        // this.onClearSelected()
        //分页、排序、筛选变化时触发
        //TODO 筛选
        console.log(pagination)
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        this.ipagination = pagination;
        this.loadData();
      },
      openPage(record) {
        // console.log(record)
        this.visible = true
        this.dataSource = [];
        this.queryParam = {
          jobId: record.id
        };
 
        this.loadData();
      },
      getQueryParams() {
        //获取查询条件
        let sqp = {}
        if(this.superQueryParams){
          sqp['superQueryParams']=encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        param.jobId = this.queryParam.jobId;
        param.startTime = this.queryParam.startTime;
        param.endTime =  this.queryParam.endTime;
        //获取用户定制的参数属性
        // if (this.getCustomQueryParams) {
        //   param = this.getCustomQueryParams(param);
        //   if(!param){
        //     return false;
        //   }
        // }
 
        return filterObj(param);
      },
      getQueryField() {
        //TODO 字段权限控制
        var str = "id,";
        this.columns.forEach(function (value) {
          str += "," + value.dataIndex;
        });
        return str;
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
 
        if(!params){
          return false;
        }
 
        this.loading = true;
        // params.id = this.queryParam.id
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            // console.log(res)
            //update-begin---author:zhangyafei    Date:20201118  for:适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for:适配不分页的数据列表------------
          }else{
            // this.$message.warning(res.message)
            this.$notification.warning({
              message:'消息',
              description:res.message
            });
          }
        }).finally(() => {
          this.loading = false
        })
      },
      modalFormOk(val) {
        // 新增/修改 成功时,重载列表
        this.loadData();
 
        this.selectedRowKeys = [val.id];
      },
      searchQuery() {
        this.loadData();
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleCancel() {
        this.close()
      },
      handleOk() {
        this.close()
      },
    },
  }
</script>
<style>
  @import '~@assets/less/common.less';
 
  .frozenRowClass {
    color: #c9c9c9;
  }
 
  .success {
    color: green;
  }
 
  .error {
    color: red;
  }
</style>