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