797165f6f2c426c41bca26f573fd605824ed1802
[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
16         @Output() cancel = new EventEmitter<boolean>();
17
18         constructor(private http: SlicingTaskServices, private message: NzMessageService) { }
19
20         checkDetail: any[];
21         businessRequirement: any[];
22         NSTinfo: any[];
23         data: any[];
24         currentProgress: number = 1;
25         timer: any = null;
26         isSpinning: boolean = false;
27         isGetData: boolean = false;
28
29         ngOnInit() { }
30
31         ngOnChanges() {
32                 if (this.showProcess) {
33                         this.isSpinning = true;
34                         this.getInfo();
35                         this.getProgress();
36                 } else {
37                         clearTimeout(this.timer);
38                         this.isGetData = false;
39                 }
40         }
41
42         getInfo(): void {
43                 this.http.getSlicingBasicInfo(this.taskId).subscribe(res => {
44                         if (this.isGetData) {
45                                 this.isSpinning = false;
46                         } else {
47                                 this.isGetData = true;
48                         }
49                         const { result_body, result_header: { result_code } } = res;
50                         if (+result_code === 200) {
51                                 const {
52                                         task_id,
53                                         task_name,
54                                         create_time,
55                                         processing_status,
56                                         business_demand_info,
57                                         nst_info,
58                                         business_demand_info: { service_snssai, coverage_area_ta_list }
59                                 } = result_body;
60                                 // 处理配置审核详情数据
61                                 this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
62                                 // 业务需求信息数据
63                                 business_demand_info.area = coverage_area_ta_list.map(item => {
64                                         item = item.split(';').join(' - ')
65                                         return item
66                                 })
67                                 // 前端模拟数据
68                                 let area = ["北京;北京市;海淀区", "北京;北京市;西城区", "北京;北京市;昌平区"].map(item => {
69                                         item = item.split(';').join(' - ')
70                                         return item
71                                 })
72                                 this.businessRequirement = [{...business_demand_info, area}];
73                                 // 匹配NST信息
74                                 this.NSTinfo = [nst_info];
75                         } else {
76                                 const errorMessage = this.moduleTitle === '切片创建中' ? 'Failed to get data' : 'Viewing results failed';
77                                 this.message.error(errorMessage)
78                         }
79                 })
80         }
81
82         getProgress(): void {
83                 this.http.getSlicingCreateProgress(this.taskId).subscribe(res => {
84                         if (this.isGetData) {
85                                 this.isSpinning = false;
86                         } else {
87                                 this.isGetData = true;
88                         }
89                         const { result_body, result_header: { result_code } } = res;
90                         if (+result_code === 200) {
91                                 this.data = [];
92                                 Object.keys(result_body).forEach(item => {
93                                         let currentProgress = 1
94                                         let status = 'process';
95                                         if (+result_body[item] === 100) {
96                                                 currentProgress = 2;
97                                                 status = 'finish'
98                                         }
99                                         const title = item === 'an_progress' ? 'An' : (item === 'tn_progress' ? 'Tn' : 'Cn')
100                                         let obj = { [item]: result_body[item], currentProgress, title, status };
101                                         this.data.push(obj)
102                                 })
103                                 this.data = [this.data];
104                                 let flag: boolean = false;
105                                 Object.values(result_body).forEach(item => {
106                                         if (item !== 100) {
107                                                 flag = true;
108                                         }
109                                 })
110                                 if (flag) {
111                                         this.timer = setTimeout(() => {
112                                                 this.getProgress()
113                                         }, 5000)
114                                 }
115                         } else {
116                                 this.message.error('Failed to get progress')
117                         }
118                 })
119         }
120
121         handleCancel() {
122                 this.showProcess = false;
123                 this.cancel.emit(this.showProcess)
124         }
125 }