f3024586adaba7a4cc7aad860a72b456e4ca4038
[usecase-ui.git] /
1 import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { SlicingTaskServices } from '../../../../../core/services/slicingTaskServices';
4
5 @Component({
6   selector: 'app-slicing-task-model',
7   templateUrl: './slicing-task-model.component.html',
8   styleUrls: ['./slicing-task-model.component.less']
9 })
10 export class SlicingTaskModelComponent implements OnInit {
11   @Input() showDetail: boolean;
12   @Input() moduleTitle: string;
13   @Input() taskId: string;
14   @Output() cancel = new EventEmitter<object>();
15   @ViewChild('notification') notification1: any;
16
17   constructor(private http: SlicingTaskServices, private message: NzMessageService) { }
18
19   // 配置审核详情
20   checkDetail: any[] = [{}];
21   //业务需求信息
22   businessRequirement: any[] = [];
23   //匹配NST信息 
24   NSTinfo: object[] = [{}];
25   // 共享切片实例
26   selectedServiceId: string;
27   selectedServiceName: string;
28   slicingInstances: any;
29   // 子网实例
30   slicingSubnet: any[] = [
31     {
32       title: 'An',
33       context: 'an',
34       slicingId: '',
35       slicingName: '',
36       total: 0,
37       currentPage: '1',
38       pageSize: '10',
39       isLoading: false,
40       flag: false,
41       instances: []
42     },
43     {
44       title: 'Tn',
45       context: 'tn',
46       slicingId: '',
47       slicingName: '',
48       total: 0,
49       currentPage: '1',
50       pageSize: '10',
51       isLoading: false,
52       flag: false,
53       instances: []
54     },
55     {
56       title: 'Cn',
57       context: 'cn',
58       slicingId: '',
59       slicingName: '',
60       total: 0,
61       currentPage: '1',
62       pageSize: '10',
63       isLoading: false,
64       flag: false,
65       instances: []
66     }
67   ]
68   isDisabled: boolean = true;
69   // 子网参数
70   isShowParams: boolean;
71   paramsTitle: string;
72   params: any;
73   // 获取数据loading
74   isSpinning: boolean = false;
75   loading: boolean = false;
76
77
78   ngOnInit() { }
79
80   ngOnChanges() {
81     if (this.showDetail) {
82       this.isSpinning = true;
83       this.getautidInfo();
84     } else {
85       this.isDisabled = true;
86     }
87   }
88
89   getautidInfo(): void {
90     this.http.getAuditInfo(this.taskId).subscribe(res => {
91       const { result_header: { result_code } } = res;
92       this.isSpinning = false;
93       if (+result_code === 200) {
94         const {
95           task_id,
96           task_name,
97           create_time,
98           processing_status,
99           business_demand_info,
100           nst_info,
101           nsi_nssi_info,
102           business_demand_info: { service_snssai, coverage_area_ta_list }
103         } = res.result_body;
104         const {
105           suggest_nsi_id,
106           suggest_nsi_name,
107           an_suggest_nssi_id,
108           an_suggest_nssi_name,
109           tn_suggest_nssi_id,
110           tn_suggest_nssi_name,
111           cn_suggest_nssi_id,
112           cn_suggest_nssi_name,
113           an_latency,
114           an_5qi,
115           an_coverage_area_ta_list,
116           tn_latency,
117           tn_bandwidth,
118           cn_service_snssai,
119           cn_resource_sharing_level,
120           cn_ue_mobility_level,
121           cn_latency,
122           cn_max_number_of_ues,
123           cn_activity_factor,
124           cn_exp_data_rate_dl,
125           cn_exp_data_rate_ul,
126           cn_area_traffic_cap_dl,
127           cn_area_traffic_cap_ul
128         } = nsi_nssi_info;
129         // 处理配置审核详情数据
130         this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
131         // 业务需求信息数据
132         business_demand_info.area = coverage_area_ta_list.map(item => {
133           item = item.split(';').join(' - ')
134           return item
135         })
136         // 前端模拟数据
137         let areaList = ["Haidian District;Beijing;Beijing", "Xicheng District;Beijing;Beijing", "Changping District;Beijing;Beijing"].map(item => {
138           item = item.split(';').join(' - ')
139           return item
140         })
141         this.businessRequirement = [{ ...business_demand_info, area: areaList }];
142         // 匹配NST信息
143         this.NSTinfo = [nst_info];
144         // 共享切片实例
145         this.selectedServiceId = suggest_nsi_id;
146         this.selectedServiceName = suggest_nsi_name;
147         if (!this.selectedServiceId || !this.selectedServiceName) {
148           this.isDisabled = false;
149         }
150         this.slicingInstances = {
151           currentPage: '1',
152           pageSize: '10',
153           isLoading: false,
154           total: 0,
155           flag: false,
156           list: [{
157             service_instance_id: this.selectedServiceId,
158             service_instance_name: this.selectedServiceName
159           }]
160         }
161         // 子网实例
162         let subnetData = { an_suggest_nssi_id, an_suggest_nssi_name, tn_suggest_nssi_id, tn_suggest_nssi_name, cn_suggest_nssi_id, cn_suggest_nssi_name };
163         this.subnetDataFormatting(subnetData, 0);
164         // 前端模拟数据
165         let area = ["Beijing;Beijing;Haidian District", "Beijing;Beijing;Xicheng District", "Beijing;Beijing;Changping District"]
166         // this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list } 
167         this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list: area }
168         this.slicingSubnet[1].params = { tn_latency, tn_bandwidth };
169         this.slicingSubnet[2].params = {
170           cn_service_snssai,
171           cn_resource_sharing_level,
172           cn_ue_mobility_level,
173           cn_latency,
174           cn_max_number_of_ues,
175           cn_activity_factor,
176           cn_exp_data_rate_dl,
177           cn_exp_data_rate_ul,
178           cn_area_traffic_cap_dl,
179           cn_area_traffic_cap_ul
180         };
181       } else {
182         this.message.error('Failed to get data')
183       }
184     }, ({ status, statusText }) => {
185       this.message.error(status + ' (' + statusText + ')');
186       this.isSpinning = false;
187     })
188   }
189
190   openSlicingInstance(bool: boolean): void {
191     const { total, currentPage, pageSize } = this.slicingInstances;
192     if (bool && !total) {
193       this.slicingInstances.list = [];
194       this.getSlicingInstances(currentPage, pageSize)
195     }
196   }
197
198   getNextPageData(): void {
199     const { total, currentPage, pageSize } = this.slicingInstances;
200     if (total - (+currentPage * +pageSize) > 0) {
201       if (this.slicingInstances.flag) return;
202       this.slicingInstances.flag = true
203       this.getSlicingInstances(currentPage, pageSize)
204       this.slicingInstances.currentPage = (+this.slicingInstances.currentPage + 1).toString();
205     }
206   }
207
208   getSlicingInstances(pageNo: string, pageSize: string): void {
209     this.slicingInstances.isLoading = true;
210     this.http.getSlicingInstance(pageNo, pageSize).subscribe(res => {
211       const { result_header: { result_code }, result_body } = res;
212       setTimeout(() => {
213         if (+result_code === 200) {
214           const { nsi_service_instances, record_number } = result_body;
215           this.slicingInstances.total = record_number;
216           this.slicingInstances.list.push(...nsi_service_instances);
217         } else {
218           this.message.error('Failed to get slicing instance ID')
219         }
220         this.slicingInstances.isLoading = false;
221         this.slicingInstances.flag = false;
222       }, 2000)
223     }, ({ status, statusText }) => {
224       this.message.error(status + ' (' + statusText + ')');
225       this.slicingInstances.isLoading = false;
226       this.slicingInstances.flag = false;
227     })
228   }
229
230
231   slicingInstanceChange(): void {
232     this.isDisabled = true;
233     this.selectedServiceName = '';
234     // 获取切片子网实例数据
235     this.http.getSlicingSubnetInstance(this.selectedServiceId).subscribe(res => {
236       const { result_header: { result_code }, result_body, record_number } = res;
237       if (+result_code === 200) {
238         this.subnetDataFormatting(result_body, record_number);
239       } else {
240         this.subnetDataFormatting({}, 1);
241         this.message.error('Failed to get slicing subnet instance ID');
242       }
243     }, ({ status, statusText }) => {
244       this.message.error(status + ' (' + statusText + ')');
245     })
246     this.slicingInstances.list.forEach(item => {
247       if (item.service_instance_id === this.selectedServiceId) {
248         this.selectedServiceName = item.service_instance_name;
249       }
250     })
251   }
252
253   subnetDataFormatting(subnetData: any, total: number): void {
254     const { an_suggest_nssi_id, an_suggest_nssi_name, tn_suggest_nssi_id, tn_suggest_nssi_name, cn_suggest_nssi_id, cn_suggest_nssi_name } = subnetData;
255     this.slicingSubnet[0].slicingId = an_suggest_nssi_id;
256     this.slicingSubnet[0].slicingName = an_suggest_nssi_name;
257     this.slicingSubnet[0].total = total;
258     this.slicingSubnet[0].currentPage = '1';
259     this.slicingSubnet[0].instances = [{
260       service_instance_id: an_suggest_nssi_id,
261       service_instance_name: an_suggest_nssi_name
262     }];
263
264     this.slicingSubnet[1].slicingId = tn_suggest_nssi_id;
265     this.slicingSubnet[1].slicingName = tn_suggest_nssi_name;
266     this.slicingSubnet[1].total = total;
267     this.slicingSubnet[1].currentPage = '1';
268     this.slicingSubnet[1].instances = [{
269       service_instance_id: tn_suggest_nssi_id,
270       service_instance_name: tn_suggest_nssi_name
271     }];
272
273     this.slicingSubnet[2].slicingId = cn_suggest_nssi_id;
274     this.slicingSubnet[2].slicingName = cn_suggest_nssi_name;
275     this.slicingSubnet[2].total = total;
276     this.slicingSubnet[2].currentPage = '1';
277     this.slicingSubnet[2].instances = [{
278       service_instance_id: cn_suggest_nssi_id,
279       service_instance_name: cn_suggest_nssi_name
280     }];
281   }
282
283   resetSlicingInstance(): void {
284     this.selectedServiceId = '';
285     this.selectedServiceName = '';
286     this.slicingSubnet.map(item => {
287       item.slicingId = '';
288       item.slicingName = '';
289     })
290     this.isDisabled = false;
291   }
292
293   openSubnetInstances(bool: boolean, instance: any): void {
294     if (bool && !instance.total) {
295       instance.instances = []
296       this.getSubnetInstances(instance)
297     }
298   }
299
300   getNextPageSubnet(instance: any): void {
301     const { total, currentPage, pageSize } = instance;
302     if (total - (+currentPage * +pageSize) > 0) {
303       if (instance.flag) return;
304       instance.flag = true;
305       this.getSubnetInstances(instance);
306       let count = +instance.currentPage;
307       instance.currentPage = (++count).toString();
308     }
309   }
310
311   getSubnetInstances(instance: any): void {
312     instance.isLoading = true;
313     const { context, currentPage, pageSize } = instance;
314     this.http.getSubnetInContext(context, currentPage, pageSize).subscribe(res => {
315       const { result_header: { result_code }, result_body } = res;
316       if (+result_code === 200) {
317         const { nssi_service_instances, record_number } = result_body;
318         this.slicingSubnet.map(item => {
319           if (item.context === context) {
320             item.total = record_number;
321             item.instances.push(...nssi_service_instances);
322           }
323         })
324       } else {
325         this.message.error('Failed to get slicing subnet instance ID');
326       }
327       instance.isLoading = false;
328       instance.flag = false;
329     }, ({ status, statusText }) => {
330       this.message.error(status + ' (' + statusText + ')');
331       instance.isLoading = false;
332       instance.flag = false;
333     })
334   }
335
336   slicingSubnetChange(instance: any): void {
337     instance.slicingName = ''
338     instance.instances.forEach(item => {
339       if (instance.slicingId === item.service_instance_id) {
340         instance.slicingName = item.service_instance_name;
341       }
342     })
343   }
344
345   restSubnetInstance(instance: any): void {
346     instance.slicingId = '';
347     instance.slicingName = '';
348   }
349
350   showParamsModel(item: any): void {
351     this.isShowParams = true;
352     this.paramsTitle = item.title;
353     this.params = item.params
354   }
355
356   changeParams(params: any): void {
357     const index = this.paramsTitle === 'An' ? 0 : (this.paramsTitle === 'Tn' ? 1 : 2);
358     this.slicingSubnet[index].params = params
359   }
360
361   handleCancel(bool: boolean = false) {
362     this.showDetail = false;
363     this.cancel.emit({ showDetail: this.showDetail, bool });
364   }
365   handleOk() {
366     this.loading = true;
367     const { selectedServiceId, selectedServiceName, slicingSubnet, checkDetail, businessRequirement, NSTinfo } = this;
368     const nsi_nssi_info: object = {
369       suggest_nsi_id: selectedServiceId,
370       suggest_nsi_name: selectedServiceName,
371       an_suggest_nssi_id: slicingSubnet[0].slicingId,
372       an_suggest_nssi_name: slicingSubnet[0].slicingName,
373       ...slicingSubnet[0].params,
374       tn_suggest_nssi_id: slicingSubnet[1].slicingId,
375       tn_suggest_nssi_name: slicingSubnet[1].slicingName,
376       ...slicingSubnet[1].params,
377       cn_suggest_nssi_id: slicingSubnet[2].slicingId,
378       cn_suggest_nssi_name: slicingSubnet[2].slicingName,
379       ...slicingSubnet[2].params,
380     }
381     delete businessRequirement[0].area
382     let reqBody = { ...checkDetail[0], business_demand_info: businessRequirement[0], nst_info: NSTinfo[0], nsi_nssi_info };
383     delete reqBody.service_snssai;
384     this.http.submitSlicing(reqBody).subscribe(res => {
385       const { result_header: { result_code } } = res;
386       if (+result_code === 200) {
387         this.notification1.notificationSuccess('Task', 'Sumbit', this.taskId)
388       } else {
389         this.notification1.notificationFailed('Task', 'Sumbit', this.taskId)
390       }
391       this.loading = false;
392       this.handleCancel(true);
393     }, ({ status, statusText }) => {
394       this.message.error(status + ' (' + statusText + ')');
395       this.loading = false;
396     })
397   }
398 }