Browse Source

定时任务

chenc 4 years ago
parent
commit
6167b9cef5

+ 3 - 1
src/app/routes/system/system.module.ts

@@ -34,6 +34,7 @@ import { SystemTimedTaskComponent } from './timed-task/timed-task.component';
 import { SystemTimedTaskAddComponent } from './timed-task/add/add.component';
 import { SystemTimedTaskAddComponent } from './timed-task/add/add.component';
 import { SystemDepartDetailsComponent } from './depart/details/details.component';
 import { SystemDepartDetailsComponent } from './depart/details/details.component';
 import { SystemRoleViewUserComponent } from './role/view-user/view-user.component';
 import { SystemRoleViewUserComponent } from './role/view-user/view-user.component';
+import { SystemTimedTaskUpdateModelComponent } from './timed-task/update-model/update-model.component';
 const COMPONENTS = [SystemDictComponent,
 const COMPONENTS = [SystemDictComponent,
   SystemUserComponent,
   SystemUserComponent,
   SystemDepartComponent,
   SystemDepartComponent,
@@ -64,7 +65,8 @@ const COMPONENTS_NOROUNT = [SystemMenuEditComponent,
   SystemMenuDataRolesDataRolesEditComponent,
   SystemMenuDataRolesDataRolesEditComponent,
   SystemRoleAuthAuthDataRulesComponent,
   SystemRoleAuthAuthDataRulesComponent,
   SystemTimedTaskAddComponent,
   SystemTimedTaskAddComponent,
-  SystemRoleViewUserComponent];
+  SystemRoleViewUserComponent,
+  SystemTimedTaskUpdateModelComponent];
 
 
 @NgModule({
 @NgModule({
   imports: [
   imports: [

+ 0 - 1
src/app/routes/system/timed-task/add/add.component.ts

@@ -110,7 +110,6 @@ export class SystemTimedTaskAddComponent implements OnInit {
       cronExpression2=cronExpression2.substring(0,cronExpression2.length-1);
       cronExpression2=cronExpression2.substring(0,cronExpression2.length-1);
     }
     }
     this.timedTask.cronExpression = "0 "+cronExpression1+" "+cronExpression2+"  * * ?";
     this.timedTask.cronExpression = "0 "+cronExpression1+" "+cronExpression2+"  * * ?";
-
     if (this.timedTask.id === "" || this.timedTask.id === null) {
     if (this.timedTask.id === "" || this.timedTask.id === null) {
       //添加
       //添加
       this.timedTaskService.add(this.timedTask).then((response) => {
       this.timedTaskService.add(this.timedTask).then((response) => {

+ 3 - 1
src/app/routes/system/timed-task/timed-task.component.html

@@ -56,7 +56,7 @@
           <nz-tag *ngIf="data.status==-1" [nzColor]="'orange'">{{'TimedTask.Status.suspend'|translate}}</nz-tag>
           <nz-tag *ngIf="data.status==-1" [nzColor]="'orange'">{{'TimedTask.Status.suspend'|translate}}</nz-tag>
           <!-- 正常 -->
           <!-- 正常 -->
           <nz-tag *ngIf="data.status==0" [nzColor]="'green'">{{'TimedTask.Status.normal'|translate}}</nz-tag>
           <nz-tag *ngIf="data.status==0" [nzColor]="'green'">{{'TimedTask.Status.normal'|translate}}</nz-tag>
-          <!-- 停止 -->
+          <!-- 停止 this.timedTask.cronExpression="0 0/1 * * * ?";-->
           <nz-tag *ngIf="data.status==1" [nzColor]="'red'">{{'TimedTask.Status.stoped'|translate}}</nz-tag>
           <nz-tag *ngIf="data.status==1" [nzColor]="'red'">{{'TimedTask.Status.stoped'|translate}}</nz-tag>
         </td>
         </td>
         <td>
         <td>
@@ -69,6 +69,8 @@
             (nzOnConfirm)="delete(data.id)"
             (nzOnConfirm)="delete(data.id)"
             (nzOnCancel)="cancelDel()"
             (nzOnCancel)="cancelDel()"
             >{{'table.delete'|translate}}</a>
             >{{'table.delete'|translate}}</a>
+            <nz-divider nzType="vertical"></nz-divider>
+            <a href="javascript:void(0);" (click)="editDirect(data)">直接修改定时规则</a>
         </td>
         </td>
       </tr>
       </tr>
     </tbody>
     </tbody>

+ 72 - 37
src/app/routes/system/timed-task/timed-task.component.ts

@@ -3,11 +3,12 @@ import { Component, OnInit, ViewChild } from '@angular/core';
 import { _HttpClient, ModalHelper } from '@delon/theme';
 import { _HttpClient, ModalHelper } from '@delon/theme';
 import { STColumn, STComponent } from '@delon/abc';
 import { STColumn, STComponent } from '@delon/abc';
 import { SFSchema } from '@delon/form';
 import { SFSchema } from '@delon/form';
-import { NzDrawerService, NzNotificationService } from 'ng-zorro-antd';
+import { NzDrawerService, NzNotificationService, NzModalService } from 'ng-zorro-antd';
 import { TimedTaskService } from 'app/services/timed-task.service';
 import { TimedTaskService } from 'app/services/timed-task.service';
 import { TimedTask } from 'app/entity/timed-task';
 import { TimedTask } from 'app/entity/timed-task';
 import { SystemTimedTaskAddComponent } from './add/add.component';
 import { SystemTimedTaskAddComponent } from './add/add.component';
 import { EventManager } from '@angular/platform-browser';
 import { EventManager } from '@angular/platform-browser';
+import { SystemTimedTaskUpdateModelComponent } from './update-model/update-model.component';
 
 
 @Component({
 @Component({
   selector: 'app-system-timed-task',
   selector: 'app-system-timed-task',
@@ -21,15 +22,13 @@ import { EventManager } from '@angular/platform-browser';
  * Copyright 2019 上海翠颠信息科技有限公司. All Rights Reserved.
  * Copyright 2019 上海翠颠信息科技有限公司. All Rights Reserved.
  */
  */
 export class SystemTimedTaskComponent implements OnInit {
 export class SystemTimedTaskComponent implements OnInit {
-
-  listOfData = [];//任务列表
+  listOfData = []; //任务列表
   page = {
   page = {
     total: 0,
     total: 0,
-    current: 0
+    current: 0,
   };
   };
 
 
-
-  timedTask: TimedTask;//查询条件
+  timedTask: TimedTask; //查询条件
   isSpinning = false;
   isSpinning = false;
 
 
   constructor(
   constructor(
@@ -37,34 +36,33 @@ export class SystemTimedTaskComponent implements OnInit {
     private drawerService: NzDrawerService,
     private drawerService: NzDrawerService,
     private notification: NzNotificationService,
     private notification: NzNotificationService,
     private i18NService: I18NService,
     private i18NService: I18NService,
-    private eventManager: EventManager
-  ) { }
+    private eventManager: EventManager,
+    private modalService: NzModalService,
+  ) {}
 
 
   ngOnInit() {
   ngOnInit() {
-    this.timedTask = {//初始化查询条件
-      jobClassName: "",
-      cronExpression: "",
-      parameter: "",
-      description: "",
-      pageNo: 0
-    }
+    this.timedTask = {
+      //初始化查询条件
+      jobClassName: '',
+      cronExpression: '',
+      parameter: '',
+      description: '',
+      pageNo: 0,
+    };
     this.list(1);
     this.list(1);
   }
   }
 
 
-
-
   // 获取分页编号模式列表
   // 获取分页编号模式列表
   list(pageNo) {
   list(pageNo) {
     this.isSpinning = true;
     this.isSpinning = true;
-    this.timedTask.pageNo = pageNo;//当前页码
-    this.timedTaskService.list(this.timedTask).then((response) => {
+    this.timedTask.pageNo = pageNo; //当前页码
+    this.timedTaskService.list(this.timedTask).then(response => {
       this.listOfData = response.result.records;
       this.listOfData = response.result.records;
       this.page = response.result;
       this.page = response.result;
       this.isSpinning = false;
       this.isSpinning = false;
-    })
+    });
   }
   }
 
 
-
   // 翻页事件
   // 翻页事件
   pageIndexChange(event) {
   pageIndexChange(event) {
     this.list(event);
     this.list(event);
@@ -74,8 +72,8 @@ export class SystemTimedTaskComponent implements OnInit {
   add() {
   add() {
     const drawerRef = this.drawerService.create<SystemTimedTaskAddComponent, { value: string }, string>({
     const drawerRef = this.drawerService.create<SystemTimedTaskAddComponent, { value: string }, string>({
       nzTitle: this.i18NService.fanyi('TimedTask.Pages.Add.title'),
       nzTitle: this.i18NService.fanyi('TimedTask.Pages.Add.title'),
-      nzWidth: "600px",
-      nzContent: SystemTimedTaskAddComponent
+      nzWidth: '600px',
+      nzContent: SystemTimedTaskAddComponent,
     });
     });
     //关闭的回调函数
     //关闭的回调函数
     drawerRef.afterClose.subscribe(() => {
     drawerRef.afterClose.subscribe(() => {
@@ -85,21 +83,22 @@ export class SystemTimedTaskComponent implements OnInit {
 
 
   //修改
   //修改
   edit(id) {
   edit(id) {
-    this.timedTaskService.queryById(id).then((respon) => {
-      if (respon.success) {//判断是否返回数据
+    this.timedTaskService.queryById(id).then(respon => {
+      if (respon.success) {
+        //判断是否返回数据
         console.log(respon);
         console.log(respon);
         const drawerRef = this.drawerService.create<SystemTimedTaskAddComponent, { timedTask: TimedTask }, string>({
         const drawerRef = this.drawerService.create<SystemTimedTaskAddComponent, { timedTask: TimedTask }, string>({
           nzTitle: this.i18NService.fanyi('TimedTask.Pages.Edit.title'),
           nzTitle: this.i18NService.fanyi('TimedTask.Pages.Edit.title'),
-          nzWidth: "600px",
+          nzWidth: '600px',
           nzContent: SystemTimedTaskAddComponent,
           nzContent: SystemTimedTaskAddComponent,
           nzContentParams: {
           nzContentParams: {
             //params
             //params
-            timedTask: respon.result
-          }
+            timedTask: respon.result,
+          },
         });
         });
 
 
         //关闭的回调函数
         //关闭的回调函数
-        drawerRef.afterClose.subscribe((isload) => {
+        drawerRef.afterClose.subscribe(isload => {
           if (isload) {
           if (isload) {
             //刷新表中的数据
             //刷新表中的数据
             this.list(this.page.current);
             this.list(this.page.current);
@@ -111,18 +110,54 @@ export class SystemTimedTaskComponent implements OnInit {
 
 
   //删除
   //删除
   delete(id) {
   delete(id) {
-    this.timedTaskService.delete(id).then((response) => {
+    this.timedTaskService.delete(id).then(response => {
       if (response.success) {
       if (response.success) {
-        this.notification.success(this.i18NService.fanyi("successful.deletion"), "");
+        this.notification.success(this.i18NService.fanyi('successful.deletion'), '');
         this.list(this.page.current);
         this.list(this.page.current);
       } else {
       } else {
-        this.notification.success(this.i18NService.fanyi("delete.failed"), response.message);
+        this.notification.success(this.i18NService.fanyi('delete.failed'), response.message);
       }
       }
-    })
-
+    });
   }
   }
-  cancelDel() {
-
+  cancelDel() {}
+
+  /**
+   * 直接修改定时规则
+   */
+  editDirect(data) {
+    const modalRef = this.modalService.create({
+      nzTitle: '修改定时规则',
+      nzContent: SystemTimedTaskUpdateModelComponent,
+      nzWidth: 900,
+      nzFooter: [
+        {
+          label: this.i18NService.fanyi('button.cancel'),
+          type: 'default',
+          onClick: addModel => {
+            addModel.close();
+          },
+        },
+        {
+          label: this.i18NService.fanyi('determine'),
+          type: 'primary',
+          onClick: addModel => {
+            
+            addModel.submitForm().then(() => {
+              data.cronExpression = addModel.cronExpression; //获取定时规则
+              //修改
+              this.timedTaskService.edit(data).then(response => {
+                if (response.success === true) {
+                  addModel.close();
+                  alert(this.i18NService.fanyi('successful.revision'));
+                  this.list(this.page.current)
+                } else {
+                  alert(this.i18NService.fanyi('modification.failed'));
+                }
+              });
+            });
+          },
+        },
+      ],
+    });
   }
   }
-
 }
 }

+ 15 - 0
src/app/routes/system/timed-task/update-model/update-model.component.html

@@ -0,0 +1,15 @@
+<form nz-form>
+  <!-- 查询条件 -->
+  <div nz-row [nzGutter]="{xs:12,sm:15,md:29,lg: 36, xl: 40}">
+    <div nz-col nzXs="24" nzSm="4" nzLg="8">
+      <nz-form-item class="nz-form-item">
+        <nz-form-label [nzSpan]="8" >定时规则:</nz-form-label>
+        <nz-form-control [nzSpan]="16">
+          <input nz-input name="cronExpression" [(ngModel)]="cronExpression"
+            nzPlaceHolder="请选择" />
+         
+        </nz-form-control>
+      </nz-form-item>
+    </div>
+  </div>
+</form>

+ 24 - 0
src/app/routes/system/timed-task/update-model/update-model.component.spec.ts

@@ -0,0 +1,24 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { SystemTimedTaskUpdateModelComponent } from './update-model.component';
+
+describe('SystemTimedTaskUpdateModelComponent', () => {
+  let component: SystemTimedTaskUpdateModelComponent;
+  let fixture: ComponentFixture<SystemTimedTaskUpdateModelComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ SystemTimedTaskUpdateModelComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(SystemTimedTaskUpdateModelComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 32 - 0
src/app/routes/system/timed-task/update-model/update-model.component.ts

@@ -0,0 +1,32 @@
+import { Component, OnInit } from '@angular/core';
+import { NzModalRef, NzMessageService } from 'ng-zorro-antd';
+import { _HttpClient } from '@delon/theme';
+
+@Component({
+  selector: 'app-system-timed-task-update-model',
+  templateUrl: './update-model.component.html',
+})
+export class SystemTimedTaskUpdateModelComponent implements OnInit {
+  
+
+  constructor(
+    private modal: NzModalRef
+  ) { }
+
+  ngOnInit(): void {
+    
+  }
+  cronExpression="";
+
+  submitForm(){
+    return new Promise((resolve)=>{
+      
+      resolve()
+    })
+    
+  }
+
+  close() {
+    this.modal.destroy();
+  }
+}