1、爬虫日志功能前端页面实现

2、api日志页面查询条件bug修改 ,input框的model值需要有值(null也行),不然无法输入,巨坑
3、其他前端页面细微调整
pull/254/head
xjs 4 years ago
parent ede181d001
commit 2f75b19ccd

@ -0,0 +1,18 @@
import request from '@/utils/request'
// 查询爬虫日志列表
export function listWebmagicLog(query) {
return request({
url: '/log/reptileLog/list',
method: 'get',
params: query
})
}
// 删除爬虫日志
export function delWebmagicLog(id) {
return request({
url: '/log/reptileLog/' + id,
method: 'delete'
})
}

@ -131,7 +131,7 @@
<el-table-column label="请求方法" align="center" prop="method" :show-overflow-tooltip="true"/> <el-table-column label="请求方法" align="center" prop="method" :show-overflow-tooltip="true"/>
<el-table-column label="请求参数" align="center" prop="request" :show-overflow-tooltip="true"> <el-table-column label="请求参数" align="center" prop="request" :show-overflow-tooltip="true">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{scope.row.request!==""?scope.row.request:"-"}}</span> <span>{{ scope.row.request !== "" ? scope.row.request : "-" }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="响应参数" align="center" prop="response" :show-overflow-tooltip="true"/> <el-table-column label="响应参数" align="center" prop="response" :show-overflow-tooltip="true"/>
@ -205,7 +205,7 @@
</template> </template>
<script> <script>
import {listLog, getLog, delLog, getApiName} from "@/api/business/log/apilog"; import {listLog, delLog, getApiName} from "@/api/business/log/apilog";
export default { export default {
name: "Apilog", name: "Apilog",
@ -230,11 +230,16 @@ export default {
title: "", title: "",
// //
open: false, open: false,
// // nullinput
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
apiName: null apiName: null,
url:null,
request:null,
response:null,
isSuccess:null,
method:null,
}, },
// //
form: {}, form: {},
@ -257,6 +262,9 @@ export default {
this.getList(); this.getList();
this.getApiName() this.getApiName()
}, },
// todo bug
methods: { methods: {
//api //api
getApiName() { getApiName() {
@ -279,27 +287,7 @@ export default {
this.loading = false; this.loading = false;
}); });
}, },
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
apiName: null,
url: null,
method: null,
request: null,
response: null,
isSuccess: null,
createTime: null
};
this.request = null
this.response = null
this.resetForm("form");
},
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
@ -337,22 +325,7 @@ export default {
this.single = selection.length !== 1 this.single = selection.length !== 1
this.multiple = !selection.length this.multiple = !selection.length
}, },
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加日志";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getLog(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改日志";
});
},
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const ids = row.id || this.ids; const ids = row.id || this.ids;

@ -0,0 +1,260 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :rules="queryRules" :inline="true" v-show="showSearch"
label-width="68px">
<el-form-item label="爬虫名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入爬虫名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="爬虫地址" prop="url">
<el-input
v-model="queryParams.url"
placeholder="请输入爬虫地址"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="请求时间" prop="beginRequestTime">
<el-input
v-model.number="queryParams.beginRequestTime"
placeholder=""
size="small"
style="width: 90px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item prop="endRequestTime">
-
<el-input
v-model.number="queryParams.endRequestTime"
placeholder=""
size="small"
style="width: 90px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
v-model="daterangeCreateTime"
size="small"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery('queryForm')"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['log:webmagicLog:remove']"
>删除
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['log:webmagicLog:export']"
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="webmagicLogList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="爬虫名称" align="center" prop="name"/>
<el-table-column label="爬虫地址" align="center" prop="url" :show-overflow-tooltip="true"/>
<el-table-column label="请求时间" align="center" prop="requestTime">
<template slot-scope="scope">
<span>{{ Math.round(scope.row.requestTime / 1000) }}</span>
</template>
</el-table-column>
<el-table-column label="复杂度" align="center" prop="complexRate">
<template slot-scope="scope">
<span>{{ scope.row.complexRate }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
<el-table-column label="请求结果" align="center" prop="status">
<template slot-scope="scope">
<el-tag :type="scope.row.status===1?'success':'danger'">
{{ scope.row.status === 1 ? '成功' : '失败' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['log:webmagicLog:remove']"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
</template>
<script>
import {listWebmagicLog, delWebmagicLog} from "@/api/business/log/reptilelog";
export default {
name: "ReptileLog",
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
webmagicLogList: [],
//
title: "",
//
open: false,
//
daterangeCreateTime: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
url: null,
requestTime: null,
createTime: null,
beginRequestTime: null,
endRequestTime: null,
},
//
form: {},
//
queryRules: {
beginRequestTime: [
{ type: 'number', message: '必须数字!', trigger: 'blur'}
],
endRequestTime: [
{ type: 'number', message: '必须数字!', trigger: 'blur'}
],
},
};
},
created() {
this.getList();
},
methods: {
/** 查询爬虫日志列表 */
getList() {
this.loading = true;
if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
this.queryParams.createTime = this.daterangeCreateTime[0];
this.queryParams.endCreateTime = this.daterangeCreateTime[1];
}
listWebmagicLog(this.queryParams).then(response => {
this.webmagicLogList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 搜索按钮操作 */
handleQuery(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.queryParams.pageNum = 1;
this.getList();
} else {
console.log('error submit!!');
return false;
}
});
},
/** 重置按钮操作 */
resetQuery() {
this.daterangeCreateTime = [];
this.queryParams.createTime = null
this.queryParams.endCreateTime = null
//
this.resetForm("queryForm");
this.handleQuery("queryForm");
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$modal.confirm('是否确认删除爬虫日志编号为"' + ids + '"的数据项?').then(function () {
return delWebmagicLog(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
});
},
/** 导出按钮操作 */
handleExport() {
this.download('log/reptileLog/export', {
...this.queryParams
}, `webmagicLog_${new Date().getTime()}.xlsx`)
}
}
};
</script>

@ -1,38 +1,82 @@
package com.xjs.reptileLog.controller; package com.xjs.reptileLog.controller;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.xjs.reptileLog.domain.WebmagicLog; import com.xjs.reptileLog.domain.WebmagicLog;
import com.xjs.reptileLog.service.WebmagicLogService; import com.xjs.reptileLog.service.WebmagicLogService;
import com.xjs.web.MyBaseController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RestController; import java.util.List;
/** /**
* *
*
* @author xiejs * @author xiejs
* @since 2022-02-17 * @since 2022-02-17
*/ */
@RestController @RestController
@RequestMapping("reptileLog") @RequestMapping("reptileLog")
@Api(tags = "业务模块-爬虫日志") @Api(tags = "业务模块-爬虫日志")
public class WebmagicLogController { public class WebmagicLogController extends MyBaseController {
@Autowired @Autowired
private WebmagicLogService webmagicLogService; private WebmagicLogService webmagicLogService;
//-----------------------内部调用rpc------------------------ //-----------------------内部调用rpc------------------------
@PostMapping("saveForPRC") @PostMapping("saveForPRC")
@ApiOperation("供AOP切面RPC远程调用") @ApiOperation("供AOP切面RPC远程调用")
public R<Object> saveReptileLog(@RequestBody WebmagicLog webmagicLog) { public R<Object> saveReptileLog(@RequestBody WebmagicLog webmagicLog) {
boolean save = webmagicLogService.save(webmagicLog); boolean save = webmagicLogService.save(webmagicLog);
return save?R.ok():R.fail(); return save ? R.ok() : R.fail();
}
//------------------代码生成----------------------------
/**
*
*/
@RequiresPermissions("log:webmagicLog:list")
@GetMapping("/list")
public TableDataInfo list(WebmagicLog webmagicLog) {
startPage();
List<WebmagicLog> list = webmagicLogService.selectWebmagicLogList(webmagicLog);
return getDataTable(list);
} }
/**
*
*/
@RequiresPermissions("log:webmagicLog:export")
@Log(title = "爬虫日志", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, WebmagicLog webmagicLog) {
List<WebmagicLog> list = webmagicLogService.selectWebmagicLogList(webmagicLog);
ExcelUtil<WebmagicLog> util = new ExcelUtil<>(WebmagicLog.class);
util.exportExcel(response, list, "爬虫日志数据");
}
/**
*
*/
@RequiresPermissions("log:webmagicLog:remove")
@Log(title = "爬虫日志", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(webmagicLogService.deleteWebmagicLogByIds(ids));
}
} }

@ -47,4 +47,19 @@ public class WebmagicLog implements Serializable {
@TableField(fill = FieldFill.INSERT) @TableField(fill = FieldFill.INSERT)
private Date createTime; private Date createTime;
@TableField(exist = false)
private Date endCreateTime;
/**
* Start
*/
@TableField(exist = false)
private Long beginRequestTime;
/**
* End
*/
@TableField(exist = false)
private Long endRequestTime;
} }

@ -3,6 +3,8 @@ package com.xjs.reptileLog.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xjs.reptileLog.domain.WebmagicLog; import com.xjs.reptileLog.domain.WebmagicLog;
import java.util.List;
/** /**
* WebmagicLog mapper * WebmagicLog mapper
* @author xiejs * @author xiejs
@ -10,4 +12,30 @@ import com.xjs.reptileLog.domain.WebmagicLog;
*/ */
public interface WebmagicLogMapper extends BaseMapper<WebmagicLog> { public interface WebmagicLogMapper extends BaseMapper<WebmagicLog> {
//--------------------代码生成-----------------------
/**
*
*
* @param webmagicLog
* @return
*/
public List<WebmagicLog> selectWebmagicLogList(WebmagicLog webmagicLog);
/**
*
*
* @param id
* @return
*/
public int deleteWebmagicLogById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteWebmagicLogByIds(Long[] ids);
} }

@ -3,6 +3,8 @@ package com.xjs.reptileLog.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.xjs.reptileLog.domain.WebmagicLog; import com.xjs.reptileLog.domain.WebmagicLog;
import java.util.List;
/** /**
* Service * Service
* @author xiejs * @author xiejs
@ -10,4 +12,30 @@ import com.xjs.reptileLog.domain.WebmagicLog;
*/ */
public interface WebmagicLogService extends IService<WebmagicLog> { public interface WebmagicLogService extends IService<WebmagicLog> {
//------------------------代码生成-------------------------
/**
*
*
* @param webmagicLog
* @return
*/
public List<WebmagicLog> selectWebmagicLogList(WebmagicLog webmagicLog);
/**
*
*
* @param ids
* @return
*/
public int deleteWebmagicLogByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteWebmagicLogById(Long id);
} }

@ -6,6 +6,9 @@ import com.xjs.reptileLog.mapper.WebmagicLogMapper;
import com.xjs.reptileLog.service.WebmagicLogService; import com.xjs.reptileLog.service.WebmagicLogService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/** /**
* @author xiejs * @author xiejs
* @since 2022-02-17 * @since 2022-02-17
@ -13,4 +16,43 @@ import org.springframework.stereotype.Service;
@Service @Service
public class WebmagicLogServiceImpl extends ServiceImpl<WebmagicLogMapper, WebmagicLog> implements WebmagicLogService { public class WebmagicLogServiceImpl extends ServiceImpl<WebmagicLogMapper, WebmagicLog> implements WebmagicLogService {
@Resource
private WebmagicLogMapper webmagicLogMapper;
//------------------------代码生成-----------------------------
/**
*
*
* @param webmagicLog
* @return
*/
@Override
public List<WebmagicLog> selectWebmagicLogList(WebmagicLog webmagicLog) {
return webmagicLogMapper.selectWebmagicLogList(webmagicLog);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteWebmagicLogByIds(Long[] ids) {
return webmagicLogMapper.deleteWebmagicLogByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteWebmagicLogById(Long id) {
return webmagicLogMapper.deleteWebmagicLogById(id);
}
} }

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xjs.reptileLog.mapper.WebmagicLogMapper">
<resultMap type="com.xjs.reptileLog.domain.WebmagicLog" id="WebmagicLogResult">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="url" column="url"/>
<result property="status" column="status"/>
<result property="requestTime" column="request_time"/>
<result property="createTime" column="create_time"/>
<result property="complexRate" column="complex_rate"/>
</resultMap>
<sql id="selectWebmagicLogVo">
select id, name, url, request_time, create_time, complex_rate, status
from webmagic_log
</sql>
<select id="selectWebmagicLogList" parameterType="com.xjs.reptileLog.domain.WebmagicLog"
resultMap="WebmagicLogResult">
<include refid="selectWebmagicLogVo"/>
<where>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="url != null and url != ''">and url like concat('%', #{url}, '%')</if>
<if test="beginRequestTime != null and endRequestTime != null">
and request_time between #{beginRequestTime} and #{endRequestTime}
</if>
<if test="createTime != null and endCreateTime != null">and create_time between #{createTime} and
#{endCreateTime}
</if>
</where>
order by create_time desc
</select>
<delete id="deleteWebmagicLogById" parameterType="Long">
delete
from webmagic_log
where id = #{id}
</delete>
<delete id="deleteWebmagicLogByIds" parameterType="String">
delete from webmagic_log where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

@ -19,6 +19,7 @@ import java.util.stream.Collectors;
/** /**
* *
*
* @author xiejs * @author xiejs
* @since 2022-02-15 * @since 2022-02-15
*/ */
@ -44,7 +45,7 @@ public class SinaNewsTask {
Document document = Jsoup.parse(html); Document document = Jsoup.parse(html);
count = this.parse(document,count); count = this.parse(document, count);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }
@ -55,36 +56,32 @@ public class SinaNewsTask {
* dom * dom
* *
* @param document dom * @param document dom
* @param count * @param count
*/ */
private Long parse(Document document,Long count) { private Long parse(Document document, Long count) {
try { //获取子链接
//获取子链接 Elements nav_mod_1 = document.getElementsByClass("nav-mod-1");
Elements nav_mod_1 = document.getElementsByClass("nav-mod-1"); Elements link = nav_mod_1.select("ul > li > a");
Elements link = nav_mod_1.select("ul > li > a"); List<Map<String, String>> hrefList = link.stream().map(a -> {
List<Map<String, String>> hrefList = link.stream().map(a -> { String href = a.attr("href");
String href = a.attr("href"); String text = a.text();
String text = a.text(); Map<String, String> map = new HashMap<>();
Map<String, String> map = new HashMap<>(); map.put(text, href);
map.put(text, href); return map;
return map; }).collect(Collectors.toList());
}).collect(Collectors.toList()); hrefList.removeIf(s -> s.containsKey("javascript:;"));
hrefList.removeIf(s -> s.containsKey("javascript:;"));
for (Map<String, String> map : hrefList) {
for (Map<String, String> map : hrefList) { Set<Map.Entry<String, String>> entrySet = map.entrySet();
Set<Map.Entry<String, String>> entrySet = map.entrySet(); for (Map.Entry<String, String> entry : entrySet) {
for (Map.Entry<String, String> entry : entrySet) { String html = httpUtils.doGetHtml(entry.getValue());
String html = httpUtils.doGetHtml(entry.getValue()); Document docChild = Jsoup.parse(html);
Document docChild = Jsoup.parse(html);
Long newCount = this.parseChile(docChild, entry.getKey(), count);
//计数
count++; count = count + newCount;
count =this.parseChile(docChild, entry.getKey(),count);
}
} }
} catch (Exception e) {
log.error(e.getMessage());
} }
return count; return count;
} }
@ -95,7 +92,7 @@ public class SinaNewsTask {
* @param docChild * @param docChild
* @param key key * @param key key
*/ */
private Long parseChile(Document docChild, String key,Long count) { private Long parseChile(Document docChild, String key, Long count) {
try { try {
Elements a = docChild.getElementsByTag("a"); Elements a = docChild.getElementsByTag("a");
ArrayList<String> link = new ArrayList<>(); ArrayList<String> link = new ArrayList<>();

Loading…
Cancel
Save