1、爬虫日志功能前端页面实现
2、api日志页面查询条件bug修改 ,input框的model值需要有值(null也行),不然无法输入,巨坑 3、其他前端页面细微调整
This commit is contained in:
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="request" :show-overflow-tooltip="true">
|
||||
<template slot-scope="scope">
|
||||
<span>{{scope.row.request!==""?scope.row.request:"-"}}</span>
|
||||
<span>{{ scope.row.request !== "" ? scope.row.request : "-" }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="响应参数" align="center" prop="response" :show-overflow-tooltip="true"/>
|
||||
|
|
@ -205,7 +205,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {listLog, getLog, delLog, getApiName} from "@/api/business/log/apilog";
|
||||
import {listLog, delLog, getApiName} from "@/api/business/log/apilog";
|
||||
|
||||
export default {
|
||||
name: "Apilog",
|
||||
|
|
@ -230,11 +230,16 @@ export default {
|
|||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 查询参数
|
||||
// 查询参数 需要给一个null值,否则input框等无法输入
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
apiName: null
|
||||
apiName: null,
|
||||
url:null,
|
||||
request:null,
|
||||
response:null,
|
||||
isSuccess:null,
|
||||
method:null,
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
|
|
@ -257,6 +262,9 @@ export default {
|
|||
this.getList();
|
||||
this.getApiName()
|
||||
},
|
||||
|
||||
// todo 条件搜索bug
|
||||
|
||||
methods: {
|
||||
//获取所有api名称
|
||||
getApiName() {
|
||||
|
|
@ -279,27 +287,7 @@ export default {
|
|||
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() {
|
||||
this.queryParams.pageNum = 1;
|
||||
|
|
@ -337,22 +325,7 @@ export default {
|
|||
this.single = selection.length !== 1
|
||||
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) {
|
||||
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;
|
||||
|
||||
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.service.WebmagicLogService;
|
||||
import com.xjs.web.MyBaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 爬虫日志控制器
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-02-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("reptileLog")
|
||||
@Api(tags = "业务模块-爬虫日志")
|
||||
public class WebmagicLogController {
|
||||
public class WebmagicLogController extends MyBaseController {
|
||||
|
||||
@Autowired
|
||||
private WebmagicLogService webmagicLogService;
|
||||
|
||||
|
||||
|
||||
//-----------------------内部调用rpc------------------------
|
||||
|
||||
@PostMapping("saveForPRC")
|
||||
@ApiOperation("供AOP切面RPC远程调用")
|
||||
public R<Object> saveReptileLog(@RequestBody WebmagicLog 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)
|
||||
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.xjs.reptileLog.domain.WebmagicLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* WebmagicLog mapper
|
||||
* @author xiejs
|
||||
|
|
@ -10,4 +12,30 @@ import com.xjs.reptileLog.domain.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.xjs.reptileLog.domain.WebmagicLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 爬虫日志 Service接口
|
||||
* @author xiejs
|
||||
|
|
@ -10,4 +12,30 @@ import com.xjs.reptileLog.domain.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 org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-02-17
|
||||
|
|
@ -13,4 +16,43 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
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
|
||||
* @since 2022-02-15
|
||||
*/
|
||||
|
|
@ -44,7 +45,7 @@ public class SinaNewsTask {
|
|||
|
||||
Document document = Jsoup.parse(html);
|
||||
|
||||
count = this.parse(document,count);
|
||||
count = this.parse(document, count);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
|
@ -55,36 +56,32 @@ public class SinaNewsTask {
|
|||
* 解析dom
|
||||
*
|
||||
* @param document dom
|
||||
* @param count 循环次数
|
||||
* @param count 循环次数
|
||||
*/
|
||||
private Long parse(Document document,Long count) {
|
||||
try {
|
||||
//获取子链接
|
||||
Elements nav_mod_1 = document.getElementsByClass("nav-mod-1");
|
||||
Elements link = nav_mod_1.select("ul > li > a");
|
||||
List<Map<String, String>> hrefList = link.stream().map(a -> {
|
||||
String href = a.attr("href");
|
||||
String text = a.text();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(text, href);
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
hrefList.removeIf(s -> s.containsKey("javascript:;"));
|
||||
private Long parse(Document document, Long count) {
|
||||
//获取子链接
|
||||
Elements nav_mod_1 = document.getElementsByClass("nav-mod-1");
|
||||
Elements link = nav_mod_1.select("ul > li > a");
|
||||
List<Map<String, String>> hrefList = link.stream().map(a -> {
|
||||
String href = a.attr("href");
|
||||
String text = a.text();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(text, href);
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
hrefList.removeIf(s -> s.containsKey("javascript:;"));
|
||||
|
||||
for (Map<String, String> map : hrefList) {
|
||||
Set<Map.Entry<String, String>> entrySet = map.entrySet();
|
||||
for (Map.Entry<String, String> entry : entrySet) {
|
||||
String html = httpUtils.doGetHtml(entry.getValue());
|
||||
Document docChild = Jsoup.parse(html);
|
||||
for (Map<String, String> map : hrefList) {
|
||||
Set<Map.Entry<String, String>> entrySet = map.entrySet();
|
||||
for (Map.Entry<String, String> entry : entrySet) {
|
||||
String html = httpUtils.doGetHtml(entry.getValue());
|
||||
Document docChild = Jsoup.parse(html);
|
||||
|
||||
//计数
|
||||
count++;
|
||||
Long newCount = this.parseChile(docChild, entry.getKey(), count);
|
||||
|
||||
count =this.parseChile(docChild, entry.getKey(),count);
|
||||
}
|
||||
count = count + newCount;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
|
@ -95,7 +92,7 @@ public class SinaNewsTask {
|
|||
* @param docChild 子
|
||||
* @param key key
|
||||
*/
|
||||
private Long parseChile(Document docChild, String key,Long count) {
|
||||
private Long parseChile(Document docChild, String key, Long count) {
|
||||
try {
|
||||
Elements a = docChild.getElementsByTag("a");
|
||||
ArrayList<String> link = new ArrayList<>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue