summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/slicing-management/slicing-task-management/check-process-model/check-process-model.component.ts
blob: 181eaf7ab16d7df58743199b52eb802aadef3789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { SlicingTaskServices } from '../../../../../core/services/slicingTaskServices'

@Component({
	selector: 'app-check-process-model',
	templateUrl: './check-process-model.component.html',
	styleUrls: ['./check-process-model.component.less']
})
export class CheckProcessModelComponent implements OnInit {

	@Input() moduleTitle: string;
	@Input() showProcess: boolean;
	@Input() taskId: string;
  	@Input() moduleOperation: string;

	@Output() cancel = new EventEmitter<boolean>();

	constructor(private http: SlicingTaskServices, private message: NzMessageService) { }

	checkDetail: any[];
	businessRequirement: any[];
	NSTinfo: any[];
	data: any[];
	currentProgress: number = 1;
	timer: any = null;
	isSpinning: boolean = false;
	isGetData: boolean = false;

	ngOnInit() { }

	ngOnChanges() {
		if (this.showProcess) {
			this.isSpinning = true;
			this.getInfo();
			this.getProgress();
		} else {
			clearTimeout(this.timer);
			this.isGetData = false;
		}
	}

	getInfo(): void {
		this.http.getSlicingBasicInfo(this.taskId).subscribe(res => {
			const { result_body, result_header: { result_code } } = res;
			if (+result_code === 200) {
				const {
					task_id,
					task_name,
					create_time,
					processing_status,
					business_demand_info,
					nst_info,
					business_demand_info: { service_snssai, coverage_area_ta_list }
				} = result_body;
				// 处理配置审核详情数据
				this.checkDetail = [{ task_id, task_name, create_time, processing_status, service_snssai }];
				// 业务需求信息数据
				business_demand_info.area = coverage_area_ta_list.map(item => {
					item = item.split(';').join(' - ')
					return item
				})
				// 前端模拟数据
				let area = ["北京;北京市;海淀区", "北京;北京市;西城区", "北京;北京市;昌平区"].map(item => {
					item = item.split(';').join(' - ')
					return item
				})
				this.businessRequirement = [{...business_demand_info, area}];
				// 匹配NST信息
				this.NSTinfo = [nst_info];
			} else {
				const errorMessage = this.moduleOperation === 'Creating' ? 'Failed to get data' : 'Viewing results failed';
				this.message.error(errorMessage);
			}
			this.isLoadingShow();
		}, ({status, statusText}) => {
			this.message.error(status + ' (' + statusText + ')');
			this.isLoadingShow();
		})
	}

	isLoadingShow () {
		if (this.isGetData) {
			this.isSpinning = false;
		} else {
			this.isGetData = true;
		}
	}

	getProgress(): void {
		this.http.getSlicingCreateProgress(this.taskId).subscribe(res => {
			const { result_body, result_header: { result_code } } = res;
			if (+result_code === 200) {
				this.data = [];
				Object.keys(result_body).forEach(item => {
					let currentProgress = 1
					let status = 'process';
					if (+result_body[item] === 100) {
						currentProgress = 2;
						status = 'finish'
					}
					const title = item === 'an_progress' ? 'An' : (item === 'tn_progress' ? 'Tn' : 'Cn')
					let obj = { [item]: result_body[item], currentProgress, title, status };
					this.data.push(obj)
				})
				this.data = [this.data];
				let flag: boolean = false;
				Object.values(result_body).forEach(item => {
					if (item !== 100) {
						flag = true;
					}
				})
				if (flag) {
					this.timer = setTimeout(() => {
						this.getProgress()
					}, 5000)
				}
			} else {
				this.message.error('Failed to get progress')
			}
			this.isLoadingShow();
		}, ({status, statusText}) => {
			this.message.error(status + ' (' + statusText + ')');
			this.isLoadingShow();
		})
	}

	handleCancel() {
		this.showProcess = false;
		this.cancel.emit(this.showProcess)
	}
}