3ccd8698c7129f8c94bcceab10a07372d56c0fa8
[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<boolean>();
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: '无线域',
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: '传输域',
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: '核心域',
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   
76
77   ngOnInit() { }
78   
79   ngOnChanges() {
80     if (this.showDetail) {
81       this.isSpinning = true;
82       this.getautidInfo();
83     } else {
84       this.isDisabled = true;
85     }
86   }
87
88   getautidInfo(): void {
89     this.http.getAuditInfo(this.taskId).subscribe( res => {
90       const { result_header: { result_code } } = res;
91       this.isSpinning = false;
92       if (+result_code === 200) {
93         const { 
94           task_id, 
95           task_name, 
96           create_time, 
97           processing_status, 
98           business_demand_info, 
99           nst_info, 
100           nsi_nssi_info, 
101           business_demand_info: { service_snssai, coverage_area_ta_list } 
102         } = res.result_body;
103         const { 
104           suggest_nsi_id, 
105           suggest_nsi_name, 
106           an_suggest_nssi_id, 
107           an_suggest_nssi_name, 
108           tn_suggest_nssi_id, 
109           tn_suggest_nssi_name, 
110           cn_suggest_nssi_id, 
111           cn_suggest_nssi_name,
112           an_latency,
113           an_5qi,
114           an_coverage_area_ta_list, 
115           tn_latency,
116           tn_bandwidth,
117           cn_service_snssai,
118           cn_resource_sharing_level,
119           cn_ue_mobility_level,
120           cn_latency,
121           cn_max_number_of_ues,
122           cn_activity_factor,
123           cn_exp_data_rate_dl,
124           cn_exp_data_rate_ul,
125           cn_area_traffic_cap_dl,
126           cn_area_traffic_cap_ul
127         } = nsi_nssi_info;
128         // 处理配置审核详情数据
129         this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
130         // 业务需求信息数据
131         business_demand_info.area = coverage_area_ta_list.map(item => {
132           item = item.split(';').join('-')
133           return item
134         })
135         this.businessRequirement = [business_demand_info];
136         // 匹配NST信息
137         this.NSTinfo = [nst_info];
138         // 共享切片实例
139         this.selectedServiceId = suggest_nsi_id;
140         this.selectedServiceName = suggest_nsi_name;
141         this.slicingInstances = {
142           currentPage: '1',
143           pageSize: '10',
144           isLoading: false,
145           total: 0,
146           flag: false,
147           list: [{
148             service_instance_id: this.selectedServiceId,
149             service_instance_name: this.selectedServiceName
150           }]
151         }
152         // 子网实例
153         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};
154         this.subnetDataFormatting(subnetData, 0);
155         this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list } 
156         this.slicingSubnet[1].params = { tn_latency, tn_bandwidth };
157         this.slicingSubnet[2].params = { 
158           cn_service_snssai,
159           cn_resource_sharing_level,
160           cn_ue_mobility_level,
161           cn_latency,
162           cn_max_number_of_ues,
163           cn_activity_factor,
164           cn_exp_data_rate_dl,
165           cn_exp_data_rate_ul,
166           cn_area_traffic_cap_dl,
167           cn_area_traffic_cap_ul 
168         };
169       } else {
170         this.message.error('Failed to get data')
171       }
172     })
173   }
174
175   openSlicingInstance ( bool: boolean): void {
176     const { total, currentPage, pageSize} = this.slicingInstances;
177     if (bool && !total) {
178       this.slicingInstances.list = [];
179       this.getSlicingInstances(currentPage, pageSize)
180     }
181   }
182
183   getNextPageData ():void {
184     const { total, currentPage, pageSize} = this.slicingInstances;
185     if (total - (+currentPage * +pageSize) > 0 ) {
186       if (this.slicingInstances.flag) return;
187       this.slicingInstances.flag = true
188       this.getSlicingInstances(currentPage, pageSize)
189       this.slicingInstances.currentPage = (+this.slicingInstances.currentPage +1).toString();
190     }
191   }
192
193   getSlicingInstances(pageNo: string, pageSize: string): void {
194     this.slicingInstances.isLoading = true;
195     this.http.getSlicingInstance(pageNo, pageSize).subscribe ( res => {
196       const { result_header: { result_code }, result_body } = res;
197       setTimeout( () => {
198         if (+result_code === 200) {
199           const { nsi_service_instances, record_number } = result_body;
200           this.slicingInstances.total = record_number;
201           this.slicingInstances.list.push(...nsi_service_instances);
202         } else {
203           this.message.error('Failed to get slicing instance ID')
204         }
205         this.slicingInstances.isLoading = false;
206         this.slicingInstances.flag = false;
207       },2000)
208
209     })
210   }
211
212
213   slicingInstanceChange ():void {
214     this.isDisabled = true;
215     // 获取切片子网实例数据
216     this.http.getSlicingSubnetInstance(this.selectedServiceId).subscribe( res => {
217       const { result_header: { result_code }, result_body, record_number} = res;
218       if (+result_code === 200) {
219         this.subnetDataFormatting(result_body, record_number)
220       } else {
221         this.message.error('Failed to get slicing subnet instance ID')
222       }
223     }) 
224     this.slicingInstances.list.forEach (item => {
225       if (item.service_instance_id === this.selectedServiceId) {
226         this.selectedServiceName = item.service_instance_name;
227       }
228     })
229   }
230
231   subnetDataFormatting ( subnetData: any, total: number): void{
232     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;
233     this.slicingSubnet[0].slicingId = an_suggest_nssi_id;
234     this.slicingSubnet[0].slicingName = an_suggest_nssi_name;
235     this.slicingSubnet[0].total = total;
236     this.slicingSubnet[0].currentPage = '1'; 
237     this.slicingSubnet[0].instances = [{
238       service_instance_id: an_suggest_nssi_id,
239       service_instance_name: an_suggest_nssi_name
240     }];
241
242     this.slicingSubnet[1].slicingId = tn_suggest_nssi_id;
243     this.slicingSubnet[1].slicingName = tn_suggest_nssi_name;
244     this.slicingSubnet[1].total = total;
245     this.slicingSubnet[1].currentPage = '1'; 
246     this.slicingSubnet[1].instances =  [{
247       service_instance_id: tn_suggest_nssi_id,
248       service_instance_name: tn_suggest_nssi_name
249     }];
250
251     this.slicingSubnet[2].slicingId = cn_suggest_nssi_id;
252     this.slicingSubnet[2].slicingName = cn_suggest_nssi_name;
253     this.slicingSubnet[2].total = total;
254     this.slicingSubnet[2].currentPage = '1'; 
255     this.slicingSubnet[2].instances = [{
256       service_instance_id: cn_suggest_nssi_id,
257       service_instance_name: cn_suggest_nssi_name
258     }];
259   }
260
261   resetSlicingInstance (): void {
262     this.selectedServiceId = '';
263     this.selectedServiceName = '';
264     this.slicingSubnet.map( item => {
265       item.slicingId = '';
266       item.slicingName = '';
267     })
268     this.isDisabled = false;
269   }
270   
271   openSubnetInstances (bool: boolean, instance: any): void {
272     if(bool && !instance.total) {
273       instance.instances = []
274       this.getSubnetInstances(instance)
275     }
276   }
277
278   getNextPageSubnet (instance: any): void{
279     const { total, currentPage, pageSize} = instance;
280     if(total - (+currentPage * +pageSize) > 0 ){
281       if (instance.flag) return;
282       instance.flag = true;
283       this.getSubnetInstances(instance);
284       let count = +instance.currentPage;
285       instance.currentPage = (++count).toString();
286     }
287   }
288
289   getSubnetInstances (instance: any): void {
290     instance.isLoading = true;
291     const { context, currentPage, pageSize } = instance;
292     this.http.getSubnetInContext(context, currentPage, pageSize).subscribe( res => {
293       const { result_header: { result_code }, result_body } = res;
294       if (+result_code === 200) {
295         const { nssi_service_instances, record_number } = result_body;
296         this.slicingSubnet.map (item => {
297           if (item.context === context) {
298             item.total = record_number;
299             setTimeout(() => {
300               item.instances.push(...nssi_service_instances);
301               item.isLoading = false;
302               item.flag = false;
303             },2000)
304           }
305         })
306       } else {
307         this.message.error('Failed to get slicing subnet instance ID');
308       }
309     })
310   }
311
312   slicingSubnetChange (instance: any): void {
313     instance.instances.forEach( item => {
314       if (instance.slicingId === item.service_instance_id) {
315         instance.slicingName = item.service_instance_name; 
316       }
317     })
318   }
319
320   restSubnetInstance (instance: any): void {
321     instance.slicingId = '';
322     instance.slicingName = '';
323   }
324
325   showParamsModel (item: any): void {
326     this.isShowParams = true;
327     this.paramsTitle = item.title;
328     this.params = item.params
329   }
330
331   changeParams (params: any): void {
332     const index = this.paramsTitle === '无线域' ? 0 : (this.paramsTitle === '传输域' ? 1 : 2);
333     this.slicingSubnet[index].params = params
334   }
335
336   handleCancel() {
337     this.showDetail = false;
338     this.cancel.emit(this.showDetail);
339   }
340   handleOk() {
341     const { selectedServiceId, selectedServiceName, slicingSubnet, checkDetail, businessRequirement, NSTinfo } = this;
342     const nsi_nssi_info: object = {
343       suggest_nsi_id:  selectedServiceId,
344       suggest_nsi_name: selectedServiceName,
345       an_suggest_nssi_id: slicingSubnet[0].slicingId,
346       an_suggest_nssi_name: slicingSubnet[0].slicingName,
347       ...slicingSubnet[0].params,
348       tn_suggest_nssi_id: slicingSubnet[1].slicingId,
349       tn_suggest_nssi_name: slicingSubnet[1].slicingName,
350       ...slicingSubnet[1].params,
351       cn_suggest_nssi_id: slicingSubnet[2].slicingId,
352       cn_suggest_nssi_name: slicingSubnet[2].slicingName,
353       ...slicingSubnet[2].params,
354     }
355     delete businessRequirement[0].area
356     let reqBody = {...checkDetail[0], business_demand_info: businessRequirement[0], nst_info: NSTinfo[0], nsi_nssi_info};
357     delete reqBody.service_snssai;
358     this.notification1.notificationStart('Task', 'Sumbit', this.taskId)
359     this.http.submitSlicing(reqBody).subscribe (res => {
360       const { result_header: { result_code } } = res;
361       if (+result_code === 200) {
362         this.handleCancel();
363         this.notification1.notificationSuccess('Task', 'Sumbit', this.taskId)
364       } else {
365         this.notification1.notificationFailed('Task', 'Sumbit', this.taskId)
366       }
367     })
368   }
369 }