951060505e826689097f1b97b81ae6fd1ffbafa6
[usecase-ui.git] /
1 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2 import { NzMessageService } from 'ng-zorro-antd';
3 import { SlicingTaskServices } from '../../../../../core/services/slicingTaskServices'
4
5 @Component({
6         selector: 'app-check-process-model',
7         templateUrl: './check-process-model.component.html',
8         styleUrls: ['./check-process-model.component.less']
9 })
10 export class CheckProcessModelComponent implements OnInit {
11
12         @Input() moduleTitle: string;
13         @Input() showProcess: boolean;
14         @Input() taskId: string;
15         @Input() moduleOperation: string;
16
17         @Output() cancel = new EventEmitter<boolean>();
18
19         constructor(private http: SlicingTaskServices, private message: NzMessageService) { }
20
21         checkDetail: any[];
22         businessRequirement: any[];
23         NSTinfo: any[];
24         data: any[];
25         currentProgress: number = 1;
26         timer: any = null;
27         isSpinning: boolean = false;
28         isGetData: boolean = false;
29
30         ngOnInit() { }
31
32         ngOnChanges() {
33                 if (this.showProcess) {
34                         this.isSpinning = true;
35                         this.getInfo();
36                         this.getProgress();
37                 } else {
38                         clearTimeout(this.timer);
39                         this.isGetData = false;
40                 }
41         }
42
43         getInfo(): void {
44                 this.http.getSlicingBasicInfo(this.taskId).subscribe(res => {
45                         const { result_body, result_header: { result_code } } = res;
46                         if (+result_code === 200) {
47                                 const {
48                                         task_id,
49                                         task_name,
50                                         create_time,
51                                         processing_status,
52                                         business_demand_info,
53                                         nst_info,
54                                         business_demand_info: { service_snssai, coverage_area_ta_list }
55                                 } = result_body;
56                                 // 处理配置审核详情数据
57                                 this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
58                                 // 业务需求信息数据
59                                 business_demand_info.area = coverage_area_ta_list.map(item => {
60                                         item = item.split(';').join(' - ')
61                                         return item
62                                 })
63                                 // 前端模拟数据
64                                 let area = ["Beijing;Beijing;Haidian District", "Beijing;Beijing;Xicheng District", "Beijing;Beijing;Changping District"].map(item => {
65                                         item = item.split(';').join(' - ')
66                                         return item
67                                 })
68                                 this.businessRequirement = [{ ...business_demand_info, area }];
69                                 // 匹配NST信息
70                                 this.NSTinfo = [nst_info];
71                         } else {
72                                 const errorMessage = this.moduleOperation === 'Creating' ? 'Failed to get data' : 'Viewing results failed';
73                                 this.message.error(errorMessage);
74                         }
75                         this.isLoadingShow();
76                 }, ({ status, statusText }) => {
77                         this.message.error(status + ' (' + statusText + ')');
78                         this.isLoadingShow();
79                 })
80         }
81
82         isLoadingShow() {
83                 if (this.isGetData) {
84                         this.isSpinning = false;
85                 } else {
86                         this.isGetData = true;
87                 }
88         }
89
90         getProgress(): void {
91                 this.http.getSlicingCreateProgress(this.taskId).subscribe(res => {
92                         const { result_body, result_header: { result_code } } = res;
93                         if (+result_code === 200) {
94                                 this.data = [];
95                                 const nssiList: string[] = ['an', 'tn', 'cn'];
96                                 nssiList.forEach( item => {
97                                         const progress: number = +result_body[item +'_progress']; 
98                                         const title: string = item.charAt(0).toUpperCase() + item.slice(1);
99                                         let status: string = result_body[item +'_status'];
100                                         if ((progress || progress === 0) && status) {
101                                                 let currentProgress = 1
102                                                 if (progress === 100 && status === 'finished') {
103                                                         currentProgress = 3;
104                                                         status = 'finish'
105                                                 }
106                                                 const obj = { progress, currentProgress, title, status };
107                                                 this.data.push(obj)
108                                         }
109                                 })
110                                 this.data = [this.data];
111                                 let flag: boolean = false;
112                                 nssiList.forEach(item => {
113                                         if (result_body[item +'_status'] === 'processing' && result_body[item +'_progress'] !== 0) {
114                                                 flag = true;
115                                         }
116                                 })
117                                 if (flag) {
118                                         this.timer = setTimeout(() => {
119                                                 this.getProgress()
120                                         }, 5000)
121                                 }
122                         } else {
123                                 this.message.error('Failed to get progress')
124                         }
125                         this.isLoadingShow();
126                 }, ({ status, statusText }) => {
127                         this.message.error(status + ' (' + statusText + ')');
128                         this.isLoadingShow();
129                 })
130         }
131
132         handleCancel() {
133                 this.showProcess = false;
134                 this.cancel.emit(this.showProcess)
135         }
136 }