From ae03f4dc6ec134a2b7d54ca33fac1862c3a574d3 Mon Sep 17 00:00:00 2001 From: TANGWY Date: Sat, 22 Jun 2024 23:14:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layout/manage/manage.component.html | 2 +- .../config/layout/manage/manage.component.ts | 40 +------ .../layout/manage/path/path.component.html | 10 +- .../layout/manage/path/path.component.ts | 105 +++++++++++++++++- .../config/layout/manage/utils/utils.ts | 33 ++++++ 5 files changed, 148 insertions(+), 42 deletions(-) create mode 100644 src/app/routes/config/layout/manage/utils/utils.ts diff --git a/src/app/routes/config/layout/manage/manage.component.html b/src/app/routes/config/layout/manage/manage.component.html index 1b3ff6e..2fb79ae 100644 --- a/src/app/routes/config/layout/manage/manage.component.html +++ b/src/app/routes/config/layout/manage/manage.component.html @@ -1,5 +1,5 @@
-

接口访问统计

+
时间选择:
diff --git a/src/app/routes/config/layout/manage/manage.component.ts b/src/app/routes/config/layout/manage/manage.component.ts index 3a34909..a2feeaf 100644 --- a/src/app/routes/config/layout/manage/manage.component.ts +++ b/src/app/routes/config/layout/manage/manage.component.ts @@ -5,11 +5,7 @@ import { CacheService } from '../../service/cache/cache.service'; import { PathComponent } from './path/path.component'; import { ProcessComponent } from './process/process.component'; import { Subscription } from 'rxjs'; -import * as XLSX from 'xlsx'; -import { saveAs } from 'file-saver'; - -const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'; -const EXCEL_EXTENSION = '.xlsx'; +import { exportAsExcelFile, convertKeys } from './utils/utils'; // data mapping // IP const ipKeyMaps = { @@ -78,19 +74,6 @@ export class ManageComponent implements OnInit { public cache: CacheService ) { } - exportAsExcelFile(json: any[], excelFileName: string): void { - const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json); - const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] }; - const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); - this.saveAsExcelFile(excelBuffer, excelFileName); - } - private saveAsExcelFile(buffer: any, fileName: string): void { - const data: Blob = new Blob([buffer], { - type: EXCEL_TYPE - }); - saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION); - } - private getAnalysisResult(startDate,endDate,queryDates){ // 获取es的查询最大日期范围 this.noticeService.getQueryRange().subscribe(resp => { console.log("resp.retcode"+resp.retcode); @@ -102,6 +85,7 @@ export class ManageComponent implements OnInit { }else{ this.submitLoading = true; this.noticeService.getUebaResult({"type":this.dimension,"startDate":startDate,"endDate":endDate}).subscribe(resp => { + this.listOfData = []; if (resp.code === 200) { this.summary_detal_data = resp switch(this.dimension.toString()){ @@ -192,8 +176,8 @@ export class ManageComponent implements OnInit { break; } console.log(JSON.stringify(keysMap)); - var data =this.convertKeys(this.listOfData,keysMap) - this.exportAsExcelFile(data,fileName); + var data =convertKeys(this.listOfData,keysMap) + exportAsExcelFile(data,fileName); } showModel(data){ @@ -220,7 +204,7 @@ export class ManageComponent implements OnInit { [data.key]: tmpdata } - this.detail_data =diagData; + this.detail_data = diagData; console.log(JSON.stringify(this.detail_data)); this.isVisible=true; } @@ -235,20 +219,6 @@ export class ManageComponent implements OnInit { } }); } -convertKeys(excelData: Raw[], keysMap: Record): Target[] { - return excelData.map(excelItem => { - const reorderedItem: any = {}; - - // 按照keysMap中定义的顺序重建对象 - Object.entries(keysMap).forEach(([originalKey, newKey]) => { - if (excelItem.hasOwnProperty(originalKey)) { - reorderedItem[newKey] = excelItem[originalKey]; - } - }); - - return reorderedItem; - }); - } mockData={ "message": "success", diff --git a/src/app/routes/config/layout/manage/path/path.component.html b/src/app/routes/config/layout/manage/path/path.component.html index 0c49475..84e20d9 100644 --- a/src/app/routes/config/layout/manage/path/path.component.html +++ b/src/app/routes/config/layout/manage/path/path.component.html @@ -2,12 +2,14 @@ -
+
+
访问源IP 访问频次 + 白/灰名单状态 操作 @@ -15,6 +17,7 @@ {{ data.req_ip }} {{ data.req_frequency }} + {{ (data.is_in_white_list===0 && data.is_in_grey_list===0)? "无":data.is_in_white_list===1?"白名单":(data.is_in_white_list===0 && data.is_in_grey_list===1)?"灰名单":"无" }} 白名单 @@ -30,6 +33,7 @@ 账号 访问频次 工号 + 白/灰名单状态 操作 @@ -54,12 +58,13 @@ 访问IP 访问账号 访问频次 + 白/灰名单状态 工号 操作 - + {{ data.interface_addr }} {{ data.req_ip }} {{ data.req_account }} @@ -81,6 +86,7 @@ 访问IP 访问账号 访问频次 + 白/灰名单状态 工号 操作 diff --git a/src/app/routes/config/layout/manage/path/path.component.ts b/src/app/routes/config/layout/manage/path/path.component.ts index e06e23b..d462732 100644 --- a/src/app/routes/config/layout/manage/path/path.component.ts +++ b/src/app/routes/config/layout/manage/path/path.component.ts @@ -1,14 +1,46 @@ -import { Component, Input, OnInit, OnChanges, SimpleChanges } from '@angular/core'; +import { Component, Input, OnInit, OnChanges, SimpleChanges, Output } from '@angular/core'; import { NzMessageService } from 'ng-zorro-antd'; import { NoticeService } from '../../../service/https/notice.service'; +import { exportAsExcelFile, convertKeys } from '../utils/utils'; + +// data mapping +// IP +const ipKeyMaps = { + 'req_ip': '访问源IP', +'req_frequency': '访问频次' +}; + +const accountKeyMaps = { +'req_account': '账号', +'req_frequency': '访问频次', + 'req_jobnum': '工号' +}; + +const interfaceKeyMaps = { +'interface_addr': '接口地址', + 'req_ip': '访问IP', +'req_account': '访问账号', +'req_frequency': '访问频次' , +'req_jobnum': '工号' +}; + +const menuKeyMaps = { + 'menu_name': '菜单名称', +'req_ip': '访问IP', +'req_account': '访问账号', +'req_frequency': '访问频次' , +'req_jobnum': '工号' +}; @Component({ selector: 'app-path', templateUrl: './path.component.html', styleUrls: ['./path.component.styl'] }) + export class PathComponent implements OnInit, OnChanges { @Input() detail_data: any; + // @Output() detailDataChange = new EventEmitter(); data; viewType = 0; whiteListParam = {}; @@ -29,7 +61,7 @@ export class PathComponent implements OnInit, OnChanges { // if (this.detail_data == null) { // this.detail_data = JSON.parse(jsonStr); // } - this.parseData(); + if (this.rules === undefined) { this.noticeService.getDefaultRule().subscribe( resp => { @@ -107,7 +139,7 @@ export class PathComponent implements OnInit, OnChanges { } this.noticeService.addWhitelist(this.whiteListParam).subscribe( resp => { - if (resp.status === 200) { + if (resp.code === 200) { this.message.success('添加白名单成功!'); this.data[index]['is_in_white_list'] = 1; } else { @@ -118,6 +150,19 @@ export class PathComponent implements OnInit, OnChanges { this.message.error('服务器错误'); } ); + var log_params = { + "action":"add wihte list", + "params":this.whiteListParam + } + + this.noticeService.writeAuditlog(log_params).subscribe(resp => { + if (resp.code !== 200) { + this.message.error("审计日志记录失败"); + } + }, + error => { + this.message.error('服务器错误'); + }); } clickGreyList(data) { @@ -149,7 +194,7 @@ export class PathComponent implements OnInit, OnChanges { this.greyListParam["type"]=0; this.noticeService.addGreyList(this.greyListParam).subscribe( resp => { - if (resp.status === 200) { + if (resp.code === 200) { this.message.success('添加灰名单成功!'); this.data[index]['is_in_grey_list'] = 1; } else { @@ -160,6 +205,20 @@ export class PathComponent implements OnInit, OnChanges { this.message.error('服务器错误'); } ); + + var log_params = { + "action":"add greyList", + "params":this.greyListParam + } + + this.noticeService.writeAuditlog(log_params).subscribe(resp => { + if (resp.code!== 200) { + this.message.error("审计日志记录失败"); + } + }, + error => { + this.message.error('服务器错误'); + }); } clickFrequency(data) { @@ -196,5 +255,43 @@ export class PathComponent implements OnInit, OnChanges { return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; } + exportExcel(){ + var keysMap :any; + var fileName = ""; + switch(this.viewType){ + case 1: + keysMap= ipKeyMaps; + fileName="ip维度" + break; + case 2: + keysMap= accountKeyMaps; + fileName="账号维度" + break; + case 3: + keysMap= interfaceKeyMaps; + fileName="接口维度" + break; + case 4: + keysMap= menuKeyMaps; + fileName="菜单维度" + break; + } + console.log(JSON.stringify(keysMap)); + var data =convertKeys(this.data,keysMap) + exportAsExcelFile(data,fileName); + } + + + // async getval(){ + // const [ewAssetDetailsRes, assetTypeRes] = await Promise.all([ + // this.noticeService.getUebaResult(this.di), + // this.noticeService.getQueryRange(this.di) + // ]); + + // if(ewAssetDetailsRes && assetTypeRes){ + // this.ewAssetDetails = ewAssetDetailsRes.data; + // this.assetType = assetTypeRes.data; + // } + // } } diff --git a/src/app/routes/config/layout/manage/utils/utils.ts b/src/app/routes/config/layout/manage/utils/utils.ts new file mode 100644 index 0000000..a7caaa6 --- /dev/null +++ b/src/app/routes/config/layout/manage/utils/utils.ts @@ -0,0 +1,33 @@ +import * as XLSX from 'xlsx'; +import { saveAs } from 'file-saver'; + +const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'; +const EXCEL_EXTENSION = '.xlsx'; +export function exportAsExcelFile(json: any[], excelFileName: string): void { + const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json); + const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] }; + const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); + saveAsExcelFile(excelBuffer, excelFileName); +} + +export function saveAsExcelFile(buffer: any, fileName: string): void { +const data: Blob = new Blob([buffer], { + type: EXCEL_TYPE +}); +saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION); +} + +export function convertKeys(excelData: Raw[], keysMap: Record): Target[] { + return excelData.map(excelItem => { + const reorderedItem: any = {}; + + // 按照keysMap中定义的顺序重建对象 + Object.entries(keysMap).forEach(([originalKey, newKey]) => { + if (excelItem.hasOwnProperty(originalKey)) { + reorderedItem[newKey] = excelItem[originalKey]; + } + }); + + return reorderedItem; + }); + } \ No newline at end of file