446f7fcfaf6b715934a2066f95dd0ca9aae8b7a0
[usecase-ui.git] /
1 import {Component, OnInit} from '@angular/core';
2 import {BUSINESS_STATUS} from "../../../../../constants/constants";
3 import {SlicingTaskServices} from '.././../../../core/services/slicingTaskServices';
4 import { NzModalService, NzMessageService } from 'ng-zorro-antd';
5 import *as moment from 'moment';
6 @Component({
7     selector: 'app-csmf-slicing-business-management',
8     templateUrl: './csmf-slicing-business-management.component.html',
9     styleUrls: ['./csmf-slicing-business-management.component.less']
10 })
11 export class CsmfSlicingBusinessManagementComponent implements OnInit {
12
13     constructor(
14         private myhttp: SlicingTaskServices,
15         private modalService: NzModalService,
16         private message: NzMessageService
17     ) {
18     }
19
20     ngOnInit() {
21         this.getCSMFBusinessList()
22     }
23     ngOnDestroy() {
24         this.progressingTimer.forEach((item) => {
25             clearInterval(item.timer);
26         });
27         this.progressingTimer = [];
28     }
29
30     selectedValue: string = BUSINESS_STATUS[0];
31     listOfData: any[] = [];
32     pageIndex: number = 1;
33     pageSize: number = 10;
34     total: number = 0;
35     loading = false;
36     statusOptions: any[] = BUSINESS_STATUS;
37     // isSelect: boolean = false;
38     progressingTimer: any[] = [];
39     terminateStart:  any[] = [];
40     businessOrderShow: boolean = false;
41     getCSMFBusinessList() {
42         this.loading = true;
43         // this.isSelect = false;
44         this.listOfData = [];
45         let paramsObj = {
46             status: this.selectedValue.toLocaleLowerCase(),
47             pageNo: this.pageIndex,
48             pageSize: this.pageSize
49         };
50         // if (this.selectedValue !== BUSINESS_STATUS[0]) {
51         //     paramsObj["businessStatus"] = this.selectedValue;
52         //     this.isSelect = true;
53         // }
54         this.myhttp.getCSMFSlicingBusinessList(paramsObj).subscribe(res => {
55             const {result_header: {result_code}, result_body: {slicing_order_list, record_number}} = res;
56             this.loading = false;
57             if (+result_code === 200) {
58                 this.total = record_number;
59                 if (slicing_order_list !== null && slicing_order_list.length > 0) {
60                     this.listOfData = slicing_order_list.map((item, index) => {
61                         item.order_creation_time =  moment(Number(item.order_creation_time)).format('YYYY-MM-DD hh:mm:ss');
62                         if (item.last_operation_progress && item.last_operation_type && Number(item.last_operation_progress) < 100) {
63                             let updata = (prodata: { operation_progress: string }) => {
64                                 item.last_operation_progress = prodata.operation_progress || item.last_operation_progress;
65                             };
66                             let obj = {
67                                 serviceId: item.order_id
68                             };
69                             if (item.last_operation_type === 'DELETE') this.terminateStart[index] = true
70                             else this.terminateStart[index] = false;
71                             this.queryProgress(obj, index, updata).then((res) => {
72                                 item.last_operation_progress = '100';
73                                 this.getCSMFBusinessList();
74                             })
75                         }
76                         return item
77                     });
78                 }
79             }
80         })
81     }
82
83     getListOfProcessingStatus() {
84         this.pageIndex = 1;
85         this.pageSize = 10;
86         this.progressingTimer.forEach((item) => {
87             clearInterval(item.timer);
88         });
89         this.progressingTimer = [];
90         this.getCSMFBusinessList();
91     }
92
93     searchData(reset: boolean = false) {
94         this.progressingTimer.forEach((item) => {
95             clearInterval(item.timer);
96         });
97         this.progressingTimer = [];
98         this.getCSMFBusinessList();
99     }
100
101     switchChange(slicing, i) {
102         console.log(slicing, i, "slicing");
103         this.modalService.confirm({
104             nzTitle: '<i>Are you sure you want to perform this task?</i>',
105             nzContent: '<b>Name:' + slicing.order_name + '</b>',
106             nzOnOk: () => {
107                 let paramsObj = {
108                     serviceId: slicing.order_id
109                 };
110                 if (slicing.order_status === 'activated') {
111                     this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
112                 } else {
113                     this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
114                 }
115             },
116             nzCancelText: 'No',
117             nzOnCancel: () => {
118                 let singleSlicing = Object.assign({}, this.listOfData[i]);
119                 this.listOfData[i] = singleSlicing;
120                 this.listOfData = [...this.listOfData];
121             }
122         });
123     }
124     changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
125         this.loading = true;
126         this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
127             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
128             this.loading = false;
129             if (+result_code === 200) {
130                 this.getCSMFBusinessList();
131             } else {
132                 let singleSlicing = Object.assign({}, this.listOfData[index]);
133                 this.listOfData[index] = singleSlicing;
134                 this.listOfData = [...this.listOfData];
135                 this.getCSMFBusinessList();
136             }
137             this.getCSMFBusinessList();
138         }, () => {
139             this.loading = false;
140             let singleSlicing = Object.assign({}, this.listOfData[index]);
141             this.listOfData[index] = singleSlicing;
142             this.listOfData = [...this.listOfData];
143             this.getCSMFBusinessList();
144         })
145     }
146
147     terminate(slicing,index) {
148         console.log(slicing, "slicing");
149         this.modalService.confirm({
150             nzTitle: 'Are you sure you want to terminate this task?',
151             nzContent: '<b>Name:&nbsp;</b>' + slicing.order_name,
152             nzOnOk: () => {
153                 let paramsObj = { serviceId: slicing.order_id };
154                 this.terminateStart[index] = true;
155                 this.loading = true;
156                 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
157                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
158                     this.loading = false;
159                     if (+result_code === 200) {
160                         this.getCSMFBusinessList();
161                     } else {
162                         this.terminateStart[index] = false;
163                     }
164                 }, () => {
165                     this.loading = false;
166                     this.terminateStart[index] = false;
167                 })
168             },
169             nzCancelText: 'No',
170             nzOnCancel: () => {
171                 console.info('Cancel termination')
172             }
173         });
174     }
175     queryProgress(obj, index, callback) {
176         return new Promise(res => {
177             let requery = () => {
178                 this.myhttp.getSlicingBusinessProgress(obj)
179                     .subscribe((data) => {
180                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
181                         if (+result_code === 200) {
182                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
183                                 callback(data.result_body);
184                                 let progressSetTimeOut = setTimeout(() => {
185                                     requery();
186                                 }, 5000);
187                                 this.progressingTimer.push({
188                                     id: obj.serviceId,
189                                     timer: progressSetTimeOut
190                                 })
191                             } else {
192                                 this.progressingTimer.forEach((item) => {
193                                     if (item.serviceId === obj.serviceId) {
194                                         clearInterval(item.timer);
195                                     }
196                                 });
197                                 res(data.result_body);
198                             }
199                         } else {
200                             this.progressingTimer.forEach((item) => {
201                                 if (item.serviceId === obj.serviceId) {
202                                     clearInterval(item.timer);
203                                 }
204                             });
205                             this.getCSMFBusinessList();
206                             this.message.error(result_message);
207                         }
208                     }, (err) => {
209                         this.progressingTimer.forEach((item) => {
210                             if (item.serviceId === obj.serviceId) {
211                                 clearInterval(item.timer);
212                             }
213                         });
214                         this.getCSMFBusinessList();
215                         this.message.error(err);
216                     })
217             };
218             requery();
219         })
220     }
221
222     OrderModelShow(){
223         this.businessOrderShow = true;
224     }
225     orderModelClose($event){
226         console.log($event,"$event------")
227         this.businessOrderShow = $event;
228         this.getCSMFBusinessList();
229     }
230 }