mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-11 00:22:49 +00:00
优化日志
This commit is contained in:
parent
6a34c86fb8
commit
82e161ef38
Binary file not shown.
@ -23,29 +23,6 @@ export class Utils {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IP获得请求地址
|
||||
* @param ip 为空时则为当前请求的IP地址
|
||||
*/
|
||||
async getIpAddr(ctx: Context, ip?: string | string[]) {
|
||||
try {
|
||||
if (!ip) {
|
||||
ip = await this.getReqIP(ctx);
|
||||
}
|
||||
const bst = new ipdb.BaseStation(`${this.baseDir}/comm/ipipfree.ipdb`);
|
||||
const result = bst.findInfo(ip, 'CN');
|
||||
const addArr: any = [];
|
||||
if (result) {
|
||||
addArr.push(result.countryName);
|
||||
addArr.push(result.regionName);
|
||||
addArr.push(result.cityName);
|
||||
return _.uniq(addArr).join('');
|
||||
}
|
||||
} catch (err) {
|
||||
return '无法获取地址信息';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除对象的空值属性
|
||||
* @param obj
|
||||
|
||||
@ -17,7 +17,7 @@ import { BaseSysLogService } from '../../../service/sys/log';
|
||||
url: ['add'],
|
||||
},
|
||||
pageQueryOp: {
|
||||
keyWordLikeFields: ['b.name', 'a.ipAddr'],
|
||||
keyWordLikeFields: ['b.name', 'a.action', 'a.ip'],
|
||||
select: ['a.*', 'b.name'],
|
||||
join: [
|
||||
{
|
||||
|
||||
@ -18,10 +18,6 @@ export class BaseSysLogEntity extends BaseEntity {
|
||||
@Column({ comment: 'ip', nullable: true })
|
||||
ip: string;
|
||||
|
||||
@Index()
|
||||
@Column({ comment: 'ip地址', nullable: true, length: 50 })
|
||||
ipAddr: string;
|
||||
|
||||
@Column({ comment: '参数', nullable: true, type: 'json' })
|
||||
params: string;
|
||||
}
|
||||
|
||||
@ -37,10 +37,6 @@ export class BaseSysLogService extends BaseService {
|
||||
const sysLog = new BaseSysLogEntity();
|
||||
sysLog.userId = userId;
|
||||
sysLog.ip = typeof ip === 'string' ? ip : ip.join(',');
|
||||
const ipAddrArr = [];
|
||||
for (const e of sysLog.ip.split(','))
|
||||
ipAddrArr.push(await this.utils.getIpAddr(context, e));
|
||||
sysLog.ipAddr = ipAddrArr.join(',');
|
||||
sysLog.action = url.split('?')[0];
|
||||
sysLog.params = params;
|
||||
await this.baseSysLogEntity.insert(sysLog);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user