76f0bcdff389f983ae782063e3e66e0e3eb4b9a1
[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: boolean = false;
40     businessOrderShow: boolean = false;
41     getCSMFBusinessList() {
42         this.loading = true;
43         // this.isSelect = false;
44         this.listOfData = [];
45         let paramsObj = {
46             status: this.selectedValue,
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');
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 = true;
70                             this.queryProgress(obj, index, updata).then((res) => {
71                                 item.last_operation_progress = '100';
72                                 this.getCSMFBusinessList();
73                             })
74                         }
75                         return item
76                     });
77                 }
78             }
79         })
80     }
81
82     getListOfProcessingStatus() {
83         this.pageIndex = 1;
84         this.pageSize = 10;
85         this.progressingTimer.forEach((item) => {
86             clearInterval(item.timer);
87         });
88         this.progressingTimer = [];
89         this.getCSMFBusinessList();
90     }
91
92     searchData(reset: boolean = false) {
93         this.progressingTimer.forEach((item) => {
94             clearInterval(item.timer);
95         });
96         this.progressingTimer = [];
97         this.getCSMFBusinessList();
98     }
99
100     switchChange(slicing, i) {
101         console.log(slicing, i, "slicing");
102         this.modalService.confirm({
103             nzTitle: '<i>Are you sure you want to perform this task?</i>',
104             nzContent: '<b>Name:' + slicing.order_name + '</b>',
105             nzOnOk: () => {
106                 let paramsObj = {
107                     serviceId: slicing.order_id
108                 };
109                 if (slicing.order_status === 'activated') {
110                     this.changeActivate(paramsObj, false, slicing, "deactivate", "deactivated", i)
111                 } else {
112                     this.changeActivate(paramsObj, true, slicing, "activate", "activated", i);
113                 }
114             },
115             nzCancelText: 'No',
116             nzOnCancel: () => {
117                 let singleSlicing = Object.assign({}, this.listOfData[i]);
118                 this.listOfData[i] = singleSlicing;
119                 this.listOfData = [...this.listOfData];
120             }
121         });
122     }
123     changeActivate(paramsObj, isActivate, slicing, activateValue, finished, index) {
124         this.loading = true;
125         this.myhttp.changeActivateSlicingService(paramsObj, isActivate).subscribe(res => {
126             const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
127             this.loading = false;
128             if (+result_code === 200) {
129                 this.getCSMFBusinessList();
130             } else {
131                 let singleSlicing = Object.assign({}, this.listOfData[index]);
132                 this.listOfData[index] = singleSlicing;
133                 this.listOfData = [...this.listOfData];
134                 this.getCSMFBusinessList();
135             }
136             this.getCSMFBusinessList();
137         }, () => {
138             this.loading = false;
139             let singleSlicing = Object.assign({}, this.listOfData[index]);
140             this.listOfData[index] = singleSlicing;
141             this.listOfData = [...this.listOfData];
142             this.getCSMFBusinessList();
143         })
144     }
145
146     terminate(slicing) {
147         console.log(slicing, "slicing");
148         this.modalService.confirm({
149             nzTitle: 'Are you sure you want to terminate this task?',
150             nzContent: '<b>Name:&nbsp;</b>' + slicing.order_name,
151             nzOnOk: () => {
152                 let paramsObj = { serviceId: slicing.order_id };
153                 this.terminateStart = true;
154                 this.loading = true;
155                 this.myhttp.terminateSlicingService(paramsObj).subscribe(res => {
156                     const { result_header: { result_code, result_message }, result_body: { operation_id } } = res;
157                     this.loading = false;
158                     if (+result_code === 200) {
159                         this.getCSMFBusinessList();
160                     } else {
161                         this.terminateStart = false;
162                     }
163                 }, () => {
164                     this.loading = false;
165                     this.terminateStart = false;
166                 })
167             },
168             nzCancelText: 'No',
169             nzOnCancel: () => {
170                 console.info('Cancel termination')
171             }
172         });
173     }
174     queryProgress(obj, index, callback) {
175         return new Promise(res => {
176             let requery = () => {
177                 this.myhttp.getSlicingBusinessProgress(obj)
178                     .subscribe((data) => {
179                         const { result_header: { result_code, result_message }, result_body: { operation_id } } = data;
180                         if (+result_code === 200) {
181                             if (data.result_body.operation_progress && Number(data.result_body.operation_progress) < 100) {
182                                 callback(data.result_body);
183                                 let progressSetTimeOut = setTimeout(() => {
184                                     requery();
185                                 }, 5000);
186                                 this.progressingTimer.push({
187                                     id: obj.serviceId,
188                                     timer: progressSetTimeOut
189                                 })
190                             } else {
191                                 this.progressingTimer.forEach((item) => {
192                                     if (item.serviceId === obj.serviceId) {
193                                         clearInterval(item.timer);
194                                     }
195                                 });
196                                 res(data.result_body);
197                             }
198                         } else {
199                             this.progressingTimer.forEach((item) => {
200                                 if (item.serviceId === obj.serviceId) {
201                                     clearInterval(item.timer);
202                                 }
203                             });
204                             this.getCSMFBusinessList();
205                             this.message.error(result_message);
206                         }
207                     }, (err) => {
208                         this.progressingTimer.forEach((item) => {
209                             if (item.serviceId === obj.serviceId) {
210                                 clearInterval(item.timer);
211                             }
212                         });
213                         this.getCSMFBusinessList();
214                         this.message.error(err);
215                     })
216             };
217             requery();
218         })
219     }
220
221     OrderModelShow(){
222         this.businessOrderShow = true;
223     }
224 }