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