4bf55dde2861981a4917bb866ea52e54b757e9b2
[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 = ["北京;北京市;海淀区", "北京;北京市;西城区", "北京;北京市;昌平区"].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         this.slicingInstances = {
148           currentPage: '1',
149           pageSize: '10',
150           isLoading: false,
151           total: 0,
152           flag: false,
153           list: [{
154             service_instance_id: this.selectedServiceId,
155             service_instance_name: this.selectedServiceName
156           }]
157         }
158         // 子网实例
159         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};
160         this.subnetDataFormatting(subnetData, 0);
161         // 前端模拟数据
162         let area = ["北京;北京市;海淀区", "北京;北京市;西城区", "北京;北京市;昌平区"]
163         // this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list } 
164         this.slicingSubnet[0].params = { an_latency, an_5qi, an_coverage_area_ta_list:area } 
165         this.slicingSubnet[1].params = { tn_latency, tn_bandwidth };
166         this.slicingSubnet[2].params = { 
167           cn_service_snssai,
168           cn_resource_sharing_level,
169           cn_ue_mobility_level,
170           cn_latency,
171           cn_max_number_of_ues,
172           cn_activity_factor,
173           cn_exp_data_rate_dl,
174           cn_exp_data_rate_ul,
175           cn_area_traffic_cap_dl,
176           cn_area_traffic_cap_ul 
177         };
178       } else {
179         this.message.error('Failed to get data')
180       }
181     })
182   }
183
184   openSlicingInstance ( bool: boolean): void {
185     const { total, currentPage, pageSize} = this.slicingInstances;
186     if (bool && !total) {
187       this.slicingInstances.list = [];
188       this.getSlicingInstances(currentPage, pageSize)
189     }
190   }
191
192   getNextPageData ():void {
193     const { total, currentPage, pageSize} = this.slicingInstances;
194     if (total - (+currentPage * +pageSize) > 0 ) {
195       if (this.slicingInstances.flag) return;
196       this.slicingInstances.flag = true
197       this.getSlicingInstances(currentPage, pageSize)
198       this.slicingInstances.currentPage = (+this.slicingInstances.currentPage +1).toString();
199     }
200   }
201
202   getSlicingInstances(pageNo: string, pageSize: string): void {
203     this.slicingInstances.isLoading = true;
204     this.http.getSlicingInstance(pageNo, pageSize).subscribe ( res => {
205       const { result_header: { result_code }, result_body } = res;
206       setTimeout( () => {
207         if (+result_code === 200) {
208           const { nsi_service_instances, record_number } = result_body;
209           this.slicingInstances.total = record_number;
210           this.slicingInstances.list.push(...nsi_service_instances);
211         } else {
212           this.message.error('Failed to get slicing instance ID')
213         }
214         this.slicingInstances.isLoading = false;
215         this.slicingInstances.flag = false;
216       },2000)
217
218     })
219   }
220
221
222   slicingInstanceChange ():void {
223     this.isDisabled = true;
224     // 获取切片子网实例数据
225     this.http.getSlicingSubnetInstance(this.selectedServiceId).subscribe( res => {
226       const { result_header: { result_code }, result_body, record_number} = res;
227       if (+result_code === 200) {
228         this.subnetDataFormatting(result_body, record_number)
229       } else {
230         this.message.error('Failed to get slicing subnet instance ID')
231       }
232     }) 
233     this.slicingInstances.list.forEach (item => {
234       if (item.service_instance_id === this.selectedServiceId) {
235         this.selectedServiceName = item.service_instance_name;
236       }
237     })
238   }
239
240   subnetDataFormatting ( subnetData: any, total: number): void{
241     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;
242     this.slicingSubnet[0].slicingId = an_suggest_nssi_id;
243     this.slicingSubnet[0].slicingName = an_suggest_nssi_name;
244     this.slicingSubnet[0].total = total;
245     this.slicingSubnet[0].currentPage = '1'; 
246     this.slicingSubnet[0].instances = [{
247       service_instance_id: an_suggest_nssi_id,
248       service_instance_name: an_suggest_nssi_name
249     }];
250
251     this.slicingSubnet[1].slicingId = tn_suggest_nssi_id;
252     this.slicingSubnet[1].slicingName = tn_suggest_nssi_name;
253     this.slicingSubnet[1].total = total;
254     this.slicingSubnet[1].currentPage = '1'; 
255     this.slicingSubnet[1].instances =  [{
256       service_instance_id: tn_suggest_nssi_id,
257       service_instance_name: tn_suggest_nssi_name
258     }];
259
260     this.slicingSubnet[2].slicingId = cn_suggest_nssi_id;
261     this.slicingSubnet[2].slicingName = cn_suggest_nssi_name;
262     this.slicingSubnet[2].total = total;
263     this.slicingSubnet[2].currentPage = '1'; 
264     this.slicingSubnet[2].instances = [{
265       service_instance_id: cn_suggest_nssi_id,
266       service_instance_name: cn_suggest_nssi_name
267     }];
268   }
269
270   resetSlicingInstance (): void {
271     this.selectedServiceId = '';
272     this.selectedServiceName = '';
273     this.slicingSubnet.map( item => {
274       item.slicingId = '';
275       item.slicingName = '';
276     })
277     this.isDisabled = false;
278   }
279   
280   openSubnetInstances (bool: boolean, instance: any): void {
281     if(bool && !instance.total) {
282       instance.instances = []
283       this.getSubnetInstances(instance)
284     }
285   }
286
287   getNextPageSubnet (instance: any): void{
288     const { total, currentPage, pageSize} = instance;
289     if(total - (+currentPage * +pageSize) > 0 ){
290       if (instance.flag) return;
291       instance.flag = true;
292       this.getSubnetInstances(instance);
293       let count = +instance.currentPage;
294       instance.currentPage = (++count).toString();
295     }
296   }
297
298   getSubnetInstances (instance: any): void {
299     instance.isLoading = true;
300     const { context, currentPage, pageSize } = instance;
301     this.http.getSubnetInContext(context, currentPage, pageSize).subscribe( res => {
302       const { result_header: { result_code }, result_body } = res;
303       if (+result_code === 200) {
304         const { nssi_service_instances, record_number } = result_body;
305         this.slicingSubnet.map (item => {
306           if (item.context === context) {
307             item.total = record_number;
308             setTimeout(() => {
309               item.instances.push(...nssi_service_instances);
310               item.isLoading = false;
311               item.flag = false;
312             },2000)
313           }
314         })
315       } else {
316         this.message.error('Failed to get slicing subnet instance ID');
317       }
318     })
319   }
320
321   slicingSubnetChange (instance: any): void {
322     instance.instances.forEach( item => {
323       if (instance.slicingId === item.service_instance_id) {
324         instance.slicingName = item.service_instance_name; 
325       }
326     })
327   }
328
329   restSubnetInstance (instance: any): void {
330     instance.slicingId = '';
331     instance.slicingName = '';
332   }
333
334   showParamsModel (item: any): void {
335     this.isShowParams = true;
336     this.paramsTitle = item.title;
337     this.params = item.params
338   }
339
340   changeParams (params: any): void {
341     const index = this.paramsTitle === 'An' ? 0 : (this.paramsTitle === 'Tn' ? 1 : 2);
342     this.slicingSubnet[index].params = params
343   }
344
345   handleCancel(bool: boolean = false) {
346     this.showDetail = false;
347     this.cancel.emit({showDetail: this.showDetail, bool});
348   }
349   handleOk() {
350     this.loading = true;
351     const { selectedServiceId, selectedServiceName, slicingSubnet, checkDetail, businessRequirement, NSTinfo } = this;
352     const nsi_nssi_info: object = {
353       suggest_nsi_id:  selectedServiceId,
354       suggest_nsi_name: selectedServiceName,
355       an_suggest_nssi_id: slicingSubnet[0].slicingId,
356       an_suggest_nssi_name: slicingSubnet[0].slicingName,
357       ...slicingSubnet[0].params,
358       tn_suggest_nssi_id: slicingSubnet[1].slicingId,
359       tn_suggest_nssi_name: slicingSubnet[1].slicingName,
360       ...slicingSubnet[1].params,
361       cn_suggest_nssi_id: slicingSubnet[2].slicingId,
362       cn_suggest_nssi_name: slicingSubnet[2].slicingName,
363       ...slicingSubnet[2].params,
364     }
365     delete businessRequirement[0].area
366     let reqBody = {...checkDetail[0], business_demand_info: businessRequirement[0], nst_info: NSTinfo[0], nsi_nssi_info};
367     delete reqBody.service_snssai;
368     // this.notification1.notificationStart('Task', 'Sumbit', this.taskId)
369     this.http.submitSlicing(reqBody).subscribe (res => {
370       const { result_header: { result_code } } = res;
371       if (+result_code === 200) {
372         this.notification1.notificationSuccess('Task', 'Sumbit', this.taskId)
373       } else {
374         this.notification1.notificationFailed('Task', 'Sumbit', this.taskId)
375       }
376       this.loading = false;
377       this.handleCancel(true);
378     })
379   }
380 }