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