代码提交

dev
TANGWY 4 months ago
parent eb6db892d9
commit ae03f4dc6e
  1. 2
      src/app/routes/config/layout/manage/manage.component.html
  2. 38
      src/app/routes/config/layout/manage/manage.component.ts
  3. 8
      src/app/routes/config/layout/manage/path/path.component.html
  4. 105
      src/app/routes/config/layout/manage/path/path.component.ts
  5. 33
      src/app/routes/config/layout/manage/utils/utils.ts

@ -1,5 +1,5 @@
<div class="container"> <div class="container">
<h1>接口访问统计</h1> <!-- <h1>统计分析</h1> -->
<div class="seach"> <div class="seach">
<div class="form-item"> <div class="form-item">
<div class="form-label">时间选择:</div> <div class="form-label">时间选择:</div>

@ -5,11 +5,7 @@ import { CacheService } from '../../service/cache/cache.service';
import { PathComponent } from './path/path.component'; import { PathComponent } from './path/path.component';
import { ProcessComponent } from './process/process.component'; import { ProcessComponent } from './process/process.component';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import * as XLSX from 'xlsx'; import { exportAsExcelFile, convertKeys } from './utils/utils';
import { saveAs } from 'file-saver';
const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
const EXCEL_EXTENSION = '.xlsx';
// data mapping // data mapping
// IP // IP
const ipKeyMaps = { const ipKeyMaps = {
@ -78,19 +74,6 @@ export class ManageComponent implements OnInit {
public cache: CacheService 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的查询最大日期范围 private getAnalysisResult(startDate,endDate,queryDates){ // 获取es的查询最大日期范围
this.noticeService.getQueryRange().subscribe(resp => { this.noticeService.getQueryRange().subscribe(resp => {
console.log("resp.retcode"+resp.retcode); console.log("resp.retcode"+resp.retcode);
@ -102,6 +85,7 @@ export class ManageComponent implements OnInit {
}else{ }else{
this.submitLoading = true; this.submitLoading = true;
this.noticeService.getUebaResult({"type":this.dimension,"startDate":startDate,"endDate":endDate}).subscribe(resp => { this.noticeService.getUebaResult({"type":this.dimension,"startDate":startDate,"endDate":endDate}).subscribe(resp => {
this.listOfData = [];
if (resp.code === 200) { if (resp.code === 200) {
this.summary_detal_data = resp this.summary_detal_data = resp
switch(this.dimension.toString()){ switch(this.dimension.toString()){
@ -192,8 +176,8 @@ export class ManageComponent implements OnInit {
break; break;
} }
console.log(JSON.stringify(keysMap)); console.log(JSON.stringify(keysMap));
var data =this.convertKeys(this.listOfData,keysMap) var data =convertKeys(this.listOfData,keysMap)
this.exportAsExcelFile(data,fileName); exportAsExcelFile(data,fileName);
} }
showModel(data){ showModel(data){
@ -235,20 +219,6 @@ export class ManageComponent implements OnInit {
} }
}); });
} }
convertKeys<Raw = any, Target = any>(excelData: Raw[], keysMap: Record<string, string>): 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={ mockData={
"message": "success", "message": "success",

@ -3,11 +3,13 @@
<!-- <div>cdfddffff</div> --> <!-- <div>cdfddffff</div> -->
<div > <div >
<div style="display: flex;justify-content: right;"><button nz-button (click)="exportExcel()">导出</button></div>
<nz-table *ngIf="viewType === 1" #basicTable [nzData]="data" [nzPageSize]="10" nzShowSizeChanger [nzPageSize]="10" [nzPageSizeOptions]="[10, 20, 50, 100]"> <nz-table *ngIf="viewType === 1" #basicTable [nzData]="data" [nzPageSize]="10" nzShowSizeChanger [nzPageSize]="10" [nzPageSizeOptions]="[10, 20, 50, 100]">
<thead> <thead>
<tr> <tr>
<th>访问源IP</th> <th>访问源IP</th>
<th>访问频次</th> <th>访问频次</th>
<th>白/灰名单状态</th>
<th nzRight>操作</th> <th nzRight>操作</th>
</tr> </tr>
</thead> </thead>
@ -15,6 +17,7 @@
<tr *ngFor="let data of basicTable.data"> <tr *ngFor="let data of basicTable.data">
<td>{{ data.req_ip }}</td> <td>{{ data.req_ip }}</td>
<td><a (click)="clickFrequency(data)">{{ data.req_frequency }}</a></td> <td><a (click)="clickFrequency(data)">{{ data.req_frequency }}</a></td>
<td>{{ (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)?"灰名单":"无" }}</td>
<td nzRight> <td nzRight>
<a *ngIf="!data.is_in_white_list" (click)="clickWihteList(data)">白名单</a> <a *ngIf="!data.is_in_white_list" (click)="clickWihteList(data)">白名单</a>
<nz-divider *ngIf="!data.is_in_white_list && !data.is_in_grey_list" nzType="vertical"></nz-divider> <nz-divider *ngIf="!data.is_in_white_list && !data.is_in_grey_list" nzType="vertical"></nz-divider>
@ -30,6 +33,7 @@
<th>账号</th> <th>账号</th>
<th>访问频次</th> <th>访问频次</th>
<th>工号</th> <th>工号</th>
<th>白/灰名单状态</th>
<th nzRight>操作</th> <th nzRight>操作</th>
</tr> </tr>
</thead> </thead>
@ -54,12 +58,13 @@
<th>访问IP</th> <th>访问IP</th>
<th>访问账号</th> <th>访问账号</th>
<th>访问频次</th> <th>访问频次</th>
<th>白/灰名单状态</th>
<th>工号</th> <th>工号</th>
<th nzRight>操作</th> <th nzRight>操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let data of basicTable.dat"> <tr *ngFor="let data of basicTable.data">
<td>{{ data.interface_addr }}</td> <td>{{ data.interface_addr }}</td>
<td>{{ data.req_ip }}</td> <td>{{ data.req_ip }}</td>
<td>{{ data.req_account }}</td> <td>{{ data.req_account }}</td>
@ -81,6 +86,7 @@
<th>访问IP</th> <th>访问IP</th>
<th>访问账号</th> <th>访问账号</th>
<th>访问频次</th> <th>访问频次</th>
<th>白/灰名单状态</th>
<th>工号</th> <th>工号</th>
<th nzRight>操作</th> <th nzRight>操作</th>
</tr> </tr>

@ -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 { NzMessageService } from 'ng-zorro-antd';
import { NoticeService } from '../../../service/https/notice.service'; 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({ @Component({
selector: 'app-path', selector: 'app-path',
templateUrl: './path.component.html', templateUrl: './path.component.html',
styleUrls: ['./path.component.styl'] styleUrls: ['./path.component.styl']
}) })
export class PathComponent implements OnInit, OnChanges { export class PathComponent implements OnInit, OnChanges {
@Input() detail_data: any; @Input() detail_data: any;
// @Output() detailDataChange = new EventEmitter();
data; data;
viewType = 0; viewType = 0;
whiteListParam = {}; whiteListParam = {};
@ -29,7 +61,7 @@ export class PathComponent implements OnInit, OnChanges {
// if (this.detail_data == null) { // if (this.detail_data == null) {
// this.detail_data = JSON.parse(jsonStr); // this.detail_data = JSON.parse(jsonStr);
// } // }
this.parseData();
if (this.rules === undefined) { if (this.rules === undefined) {
this.noticeService.getDefaultRule().subscribe( this.noticeService.getDefaultRule().subscribe(
resp => { resp => {
@ -107,7 +139,7 @@ export class PathComponent implements OnInit, OnChanges {
} }
this.noticeService.addWhitelist(this.whiteListParam).subscribe( this.noticeService.addWhitelist(this.whiteListParam).subscribe(
resp => { resp => {
if (resp.status === 200) { if (resp.code === 200) {
this.message.success('添加白名单成功!'); this.message.success('添加白名单成功!');
this.data[index]['is_in_white_list'] = 1; this.data[index]['is_in_white_list'] = 1;
} else { } else {
@ -118,6 +150,19 @@ export class PathComponent implements OnInit, OnChanges {
this.message.error('服务器错误'); 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) { clickGreyList(data) {
@ -149,7 +194,7 @@ export class PathComponent implements OnInit, OnChanges {
this.greyListParam["type"]=0; this.greyListParam["type"]=0;
this.noticeService.addGreyList(this.greyListParam).subscribe( this.noticeService.addGreyList(this.greyListParam).subscribe(
resp => { resp => {
if (resp.status === 200) { if (resp.code === 200) {
this.message.success('添加灰名单成功!'); this.message.success('添加灰名单成功!');
this.data[index]['is_in_grey_list'] = 1; this.data[index]['is_in_grey_list'] = 1;
} else { } else {
@ -160,6 +205,20 @@ export class PathComponent implements OnInit, OnChanges {
this.message.error('服务器错误'); 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) { clickFrequency(data) {
@ -196,5 +255,43 @@ export class PathComponent implements OnInit, OnChanges {
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; 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;
// }
// }
} }

@ -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<Raw = any, Target = any>(excelData: Raw[], keysMap: Record<string, string>): 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;
});
}
Loading…
Cancel
Save