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