Commit 930f4017 by wqc

删掉多余注册的多个分页插件

parent 20f008fa
package com.zq.common.config.base;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
@Configuration
public class MybatisConfig {
/**
* MybatisPlus分页插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
/**
* 官方原话
* MybatisPlus新的分页插件,一缓和二缓遵循mybatis的规则,
* 需要设置 MybatisConfiguration#useDeprecatedExecutor = false
* 避免缓存出现问题(该属性会在旧插件移除后一同移除)
*/
@SuppressWarnings(value = {"deprecation"})
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.setUseDeprecatedExecutor(false);
}
// pagehelper分页插件
@Bean
public PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
properties.put("helperDialect", "mysql");
pageInterceptor.setProperties(properties);
return pageInterceptor;
}
}
package com.zq.dataoperation.config; package com.zq.common.config.mybatis;
import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor; import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -10,8 +11,14 @@ import org.springframework.context.annotation.Configuration; ...@@ -10,8 +11,14 @@ import org.springframework.context.annotation.Configuration;
import java.util.Properties; import java.util.Properties;
/**
* Mybatis配置
*
* @author wilmiam
* @since 2021-07-09 17:51
*/
@Configuration @Configuration
public class MybatisPlusConfig { public class MybatisConfig {
/** /**
* MybatisPlus分页插件 * MybatisPlus分页插件
...@@ -19,7 +26,7 @@ public class MybatisPlusConfig { ...@@ -19,7 +26,7 @@ public class MybatisPlusConfig {
@Bean @Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor; return interceptor;
} }
...@@ -37,13 +44,16 @@ public class MybatisPlusConfig { ...@@ -37,13 +44,16 @@ public class MybatisPlusConfig {
/** /**
* pagehelper分页插件 * pagehelper分页插件
*
* @return
*/ */
@Bean @Bean
public PageInterceptor pageInterceptor() { public PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor(); PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties(); Properties properties = new Properties();
properties.put("helperDialect", "mysql"); properties.setProperty("helperDialect", "mysql");
pageInterceptor.setProperties(properties); pageInterceptor.setProperties(properties);
return pageInterceptor; return pageInterceptor;
} }
}
\ No newline at end of file }
package com.zq.common.utils; package com.zq.common.utils;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList;
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.zq.common.exception.BusinessException; import com.zq.common.exception.BusinessException;
import com.zq.common.vo.PageReqVo; import com.zq.common.vo.PageReqVo;
import com.zq.common.vo.PageVo; import com.zq.common.vo.PageVo;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
...@@ -18,6 +25,7 @@ import java.util.function.Function; ...@@ -18,6 +25,7 @@ import java.util.function.Function;
* @author * @author
* @since 2019-04-02 * @since 2019-04-02
*/ */
@Slf4j
public abstract class PagingUtils { public abstract class PagingUtils {
/** /**
...@@ -29,9 +37,22 @@ public abstract class PagingUtils { ...@@ -29,9 +37,22 @@ public abstract class PagingUtils {
* @param <Q> * @param <Q>
* @return * @return
*/ */
@SuppressWarnings("all")
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, Function<Q, List<R>> rowsLoader) { public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, Function<Q, List<R>> rowsLoader) {
PageHelper.startPage(reqVo.getPage(), reqVo.getSize()); return paging(reqVo, rowsLoader, true);
}
/**
* pagehelper分页插件
*
* @param reqVo
* @param rowsLoader
* @param <R>
* @param <Q>
* @return
*/
@SuppressWarnings("all")
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, Function<Q, List<R>> rowsLoader, boolean searchCount) {
PageHelper.startPage(reqVo.getPage(), reqVo.getSize(), searchCount);
com.github.pagehelper.Page<R> page = (com.github.pagehelper.Page) rowsLoader.apply(reqVo); com.github.pagehelper.Page<R> page = (com.github.pagehelper.Page) rowsLoader.apply(reqVo);
return PageVo.ofReqVo(reqVo, page.getResult(), Long.valueOf(page.getTotal()).intValue()); return PageVo.ofReqVo(reqVo, page.getResult(), Long.valueOf(page.getTotal()).intValue());
} }
...@@ -47,15 +68,30 @@ public abstract class PagingUtils { ...@@ -47,15 +68,30 @@ public abstract class PagingUtils {
* @return * @return
*/ */
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Class<R> clazz) { public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Class<R> clazz) {
R instance; return paging(reqVo, mapper, clazz, true);
}
/**
* mybatis-plus自带分页插件
*
* @param reqVo
* @param mapper
* @param clazz
* @param <R>
* @param <Q>
* @return
*/
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Class<R> clazz, boolean searchCount) {
R entity;
try { try {
instance = clazz.newInstance(); entity = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
throw new BusinessException("分页类型转换错误"); throw new BusinessException("分页类型转换错误");
} }
BeanUtil.copyProperties(reqVo, instance); BeanUtil.copyProperties(reqVo, entity);
IPage<R> page = new Page<>(reqVo.getPage(), reqVo.getSize()); Page<R> page = new Page<>(reqVo.getPage(), reqVo.getSize());
page = mapper.selectPage(page, Wrappers.lambdaQuery(instance)); page.setSearchCount(searchCount);
page = mapper.selectPage(page, Wrappers.lambdaQuery(entity));
return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue()); return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue());
} }
...@@ -64,14 +100,26 @@ public abstract class PagingUtils { ...@@ -64,14 +100,26 @@ public abstract class PagingUtils {
* *
* @param reqVo * @param reqVo
* @param mapper * @param mapper
* @param clazz
* @param <R> * @param <R>
* @param <Q> * @param <Q>
* @return * @return
*/ */
@SuppressWarnings("all") public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Wrapper<R> lambdaQuery) {
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, LambdaQueryWrapper<R> lambdaQuery) { return paging(reqVo, mapper, lambdaQuery, true);
IPage<R> page = new Page<>(reqVo.getPage(), reqVo.getSize()); }
/**
* mybatis-plus自带分页插件
*
* @param reqVo
* @param mapper
* @param <R>
* @param <Q>
* @return
*/
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Wrapper<R> lambdaQuery, boolean searchCount) {
Page<R> page = new Page<>(reqVo.getPage(), reqVo.getSize());
page.setSearchCount(searchCount);
page = mapper.selectPage(page, lambdaQuery); page = mapper.selectPage(page, lambdaQuery);
return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue()); return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue());
} }
...@@ -81,23 +129,75 @@ public abstract class PagingUtils { ...@@ -81,23 +129,75 @@ public abstract class PagingUtils {
* *
* @param reqVo * @param reqVo
* @param mapper * @param mapper
* @param clazz
* @param <R> * @param <R>
* @param <Q> * @param <Q>
* @return * @return
*/ */
@SuppressWarnings("all") public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, LambdaQueryWrapper<R> lambdaQuery, Class<R> clazz) {
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Class<R> clazz, LambdaQueryWrapper<R> lambdaQuery) { return paging(reqVo, mapper, lambdaQuery, clazz, true);
R instance; }
/**
* mybatis-plus自带分页插件
*
* @param reqVo
* @param mapper
* @param <R>
* @param <Q>
* @return
*/
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, LambdaQueryWrapper<R> lambdaQuery, Class<R> clazz, boolean searchCount) {
R entity;
try { try {
instance = clazz.newInstance(); entity = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
throw new BusinessException("分页类型转换错误"); throw new BusinessException("分页类型转换错误");
} }
BeanUtil.copyProperties(reqVo, instance);
IPage<R> page = new Page<>(reqVo.getPage(), reqVo.getSize()); // 已设置在lambdaQuery的字段实体类中不应该重复设置
page = mapper.selectPage(page, lambdaQuery.setEntity(instance)); String[] whereFields = getWhereFields(lambdaQuery);
BeanUtil.copyProperties(reqVo, entity, whereFields);
lambdaQuery.setEntity(entity);
Page<R> page = new Page<>(reqVo.getPage(), reqVo.getSize());
page.setSearchCount(searchCount);
page = mapper.selectPage(page, lambdaQuery);
return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue()); return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue());
} }
/**
* 获取设置的条件字段名
*
* @param lambdaQuery
* @param <R>
* @return
*/
public static <R> String[] getWhereFields(LambdaQueryWrapper<R> lambdaQuery) {
List<String> fields = new ArrayList<>();
MergeSegments expression = lambdaQuery.getExpression();
NormalSegmentList normal = expression.getNormal();
for (int i = 0; i < normal.size(); i++) {
if (i + 1 >= normal.size()) {
break;
}
ISqlSegment nextSegment = normal.get(i + 1);
if (nextSegment instanceof SqlKeyword) {
ISqlSegment sqlSegment = normal.get(i);
String segment = sqlSegment.getSqlSegment();
if (segment.startsWith("#{")) {
continue;
}
String field = StrUtil.toCamelCase(segment.toLowerCase());
fields.add(field);
}
}
return fields.toArray(new String[]{});
}
} }
...@@ -17,6 +17,7 @@ package com.zq.dataoperation.config;/* ...@@ -17,6 +17,7 @@ package com.zq.dataoperation.config;/*
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.zq.common.base.SecurityProperties; import com.zq.common.base.SecurityProperties;
import com.zq.common.config.redis.RedisUtils; import com.zq.common.config.redis.RedisUtils;
import com.zq.common.context.ThreadContext;
import com.zq.common.utils.TokenUtils; import com.zq.common.utils.TokenUtils;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -70,6 +71,7 @@ TokenFilter extends GenericFilterBean { ...@@ -70,6 +71,7 @@ TokenFilter extends GenericFilterBean {
} }
} }
filterChain.doFilter(servletRequest, servletResponse); filterChain.doFilter(servletRequest, servletResponse);
ThreadContext.close();
} }
} }
...@@ -14,8 +14,6 @@ import io.swagger.annotations.ApiOperation; ...@@ -14,8 +14,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@Api(tags = "通用查询") @Api(tags = "通用查询")
......
...@@ -33,7 +33,7 @@ public class DataCollectLogService extends ServiceImpl<DataCollectTaskLogDao, Da ...@@ -33,7 +33,7 @@ public class DataCollectLogService extends ServiceImpl<DataCollectTaskLogDao, Da
public PageVo getList(DataCollectLogReq req) { public PageVo getList(DataCollectLogReq req) {
LambdaQueryWrapper<DataCollectTaskLog> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DataCollectTaskLog> wrapper = new LambdaQueryWrapper<>();
PageVo pageVo = PagingUtils.paging(req, dataCollectTaskLogDao, DataCollectTaskLog.class, wrapper); PageVo pageVo = PagingUtils.paging(req, dataCollectTaskLogDao, wrapper,DataCollectTaskLog.class);
List<DataCollectTaskLogResp> taskLogRespList = new ArrayList<>(pageVo.getRows().size()); List<DataCollectTaskLogResp> taskLogRespList = new ArrayList<>(pageVo.getRows().size());
for (Object row : pageVo.getRows()) { for (Object row : pageVo.getRows()) {
DataCollectTaskLog dataCollectTaskLog = (DataCollectTaskLog) row; DataCollectTaskLog dataCollectTaskLog = (DataCollectTaskLog) row;
...@@ -53,4 +53,4 @@ public class DataCollectLogService extends ServiceImpl<DataCollectTaskLogDao, Da ...@@ -53,4 +53,4 @@ public class DataCollectLogService extends ServiceImpl<DataCollectTaskLogDao, Da
public List<DataCollectFileLog> file(Integer id){ public List<DataCollectFileLog> file(Integer id){
return dataCollectFileLogDao.selectList(new LambdaQueryWrapper<DataCollectFileLog>().eq(DataCollectFileLog::getDataCollectSettingFileId, id)); return dataCollectFileLogDao.selectList(new LambdaQueryWrapper<DataCollectFileLog>().eq(DataCollectFileLog::getDataCollectSettingFileId, id));
} }
} }
\ No newline at end of file
...@@ -49,7 +49,7 @@ public class DataCollectService extends ServiceImpl<DataCollectDao, DataCollectS ...@@ -49,7 +49,7 @@ public class DataCollectService extends ServiceImpl<DataCollectDao, DataCollectS
private DataCollectSettingApiParaDao dataCollectSettingApiParaDao; private DataCollectSettingApiParaDao dataCollectSettingApiParaDao;
public PageVo<DataCollectSetting> getList(DataCollectReq req) { public PageVo<DataCollectSetting> getList(DataCollectReq req) {
return PagingUtils.paging(req, dataCollectDao, DataCollectSetting.class, new LambdaQueryWrapper<>()); return PagingUtils.paging(req, dataCollectDao, new LambdaQueryWrapper<>(), DataCollectSetting.class);
} }
public DataCollectSettingResp get(Integer id){ public DataCollectSettingResp get(Integer id){
...@@ -136,4 +136,4 @@ public class DataCollectService extends ServiceImpl<DataCollectDao, DataCollectS ...@@ -136,4 +136,4 @@ public class DataCollectService extends ServiceImpl<DataCollectDao, DataCollectS
throw new BusinessException("不支持的类型"); throw new BusinessException("不支持的类型");
} }
} }
} }
\ No newline at end of file
...@@ -7,9 +7,20 @@ spring: ...@@ -7,9 +7,20 @@ spring:
user: user:
name: admin name: admin
password: 123456 password: 123456
eureka: eureka: # 相关文章:https://blog.csdn.net/weixin_49149614/article/details/121059046
instance: instance:
hostname: 127.0.0.1 #设置使用IP注册就会优先使用IP,hostname则无效
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
server:
# 关闭自我保护机制(程序停掉了还注册的问题)
enable-self-preservation: false
# 主动检测失效间隔,配置成3秒,默认60000
eviction-interval-timer-in-ms: 3000
# 拉取服务的时候,不从ReadOnlyCacheMap里查,直接从ReadWriteCacheMap取。
use-read-only-response-cache: false # 关闭从ReadOnlyCacheMap拉取数据。
# 缩短ReadWriteCacheMap向ReadOnlyCacheMap同步的时间间隔,默认30秒
response-cache-update-interval-ms: 3000 # 减少readWrite 和 readOnly 同步时间间隔。readWrite更新到readOnly
client: client:
# 表示是否将自己注册到Eureka Server,默认为true。 # 表示是否将自己注册到Eureka Server,默认为true。
register-with-eureka: false register-with-eureka: false
...@@ -17,4 +28,4 @@ eureka: ...@@ -17,4 +28,4 @@ eureka:
fetch-registry: false fetch-registry: false
# 设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://127.0.0.1:8000/eureka ;多个地址可使用,分隔 # 设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://127.0.0.1:8000/eureka ;多个地址可使用,分隔
service-url: service-url:
defaultZone: http://admin:123456@127.0.0.1:8800/eureka/ defaultZone: http://admin:123456@127.0.0.1:8800/eureka/
\ No newline at end of file
...@@ -15,5 +15,6 @@ eureka: ...@@ -15,5 +15,6 @@ eureka:
lease-expiration-duration-in-seconds: 6 #告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,将我踢出掉。 lease-expiration-duration-in-seconds: 6 #告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,将我踢出掉。
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
client: client:
registry-fetch-interval-seconds: 6 #从服务端注册表中获取注册信息的时间间隔(s)
serviceUrl: serviceUrl:
defaultZone: http://admin:123456@127.0.0.1:8800/eureka/ defaultZone: http://admin:123456@127.0.0.1:8800/eureka/
...@@ -17,6 +17,7 @@ package com.zq.model.config;/* ...@@ -17,6 +17,7 @@ package com.zq.model.config;/*
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.zq.common.base.SecurityProperties; import com.zq.common.base.SecurityProperties;
import com.zq.common.config.redis.RedisUtils; import com.zq.common.config.redis.RedisUtils;
import com.zq.common.context.ThreadContext;
import com.zq.common.utils.TokenUtils; import com.zq.common.utils.TokenUtils;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -70,6 +71,8 @@ TokenFilter extends GenericFilterBean { ...@@ -70,6 +71,8 @@ TokenFilter extends GenericFilterBean {
} }
} }
filterChain.doFilter(servletRequest, servletResponse); filterChain.doFilter(servletRequest, servletResponse);
ThreadContext.close();
} }
} }
package com.zq.spiderflow.core.handlle; package com.zq.spiderflow.core.handlle;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.core.exception.RpaException; import com.zq.spiderflow.core.exception.RpaException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import com.zq.spiderflow.core.vo.ResultVo;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
......
...@@ -5,6 +5,7 @@ import java.util.List; ...@@ -5,6 +5,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zq.spiderflow.core.vo.SpiderFlowVo;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.zq.spiderflow.core.model.SpiderFlow; import com.zq.spiderflow.core.model.SpiderFlow;
...@@ -71,4 +72,7 @@ public interface SpiderFlowMapper extends BaseMapper<SpiderFlow>{ ...@@ -71,4 +72,7 @@ public interface SpiderFlowMapper extends BaseMapper<SpiderFlow>{
@Select("select COUNT(id) from sp_flow where id = #{id}") @Select("select COUNT(id) from sp_flow where id = #{id}")
Integer getCountById(@Param("id")String id); Integer getCountById(@Param("id")String id);
@Select("select * from sp_flow p where p.name like '%${vo.name}%' limit #{vo.page},#{vo.size}")
List<SpiderFlowVo> getPageList(@Param("vo") SpiderFlowVo vo);
} }
...@@ -4,9 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -4,9 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.core.mapper.FlowNoticeMapper; import com.zq.spiderflow.core.mapper.FlowNoticeMapper;
import com.zq.spiderflow.core.mapper.SpiderFlowMapper; import com.zq.spiderflow.core.mapper.SpiderFlowMapper;
import com.zq.spiderflow.core.vo.ResultVo;
import com.zq.spiderflow.core.vo.SpiderFlowVo; import com.zq.spiderflow.core.vo.SpiderFlowVo;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -230,4 +231,22 @@ public class SpiderFlowService extends ServiceImpl<SpiderFlowMapper, SpiderFlow> ...@@ -230,4 +231,22 @@ public class SpiderFlowService extends ServiceImpl<SpiderFlowMapper, SpiderFlow>
public Integer getFlowMaxTaskId(String flowId){ public Integer getFlowMaxTaskId(String flowId){
return sfMapper.getFlowMaxTaskId(flowId); return sfMapper.getFlowMaxTaskId(flowId);
} }
public PageVo<SpiderFlowVo> getPageList(SpiderFlowVo vo) {
List<SpiderFlowVo> pageList = sfMapper.getPageList(vo);
int start=0;
PageVo<SpiderFlowVo> pageVo = new PageVo<>();
if (vo.getPage() - 1 == 0) {
pageVo.setStart(0);
start = 0;
} else {
pageVo.setStart((vo.getPage() - 1) * vo.getSize());
start = (vo.getPage() - 1) * vo.getSize();
}
pageVo.setPage(vo.getPage());
pageVo.setSize(vo.getSize());
pageVo.setRows(pageList);
pageVo.setTotal(pageList.size());
return pageVo;
}
} }
package com.zq.spiderflow.core.vo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResultVo<T> implements Serializable {
private boolean success;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
private int errCode;
private String errMsg;
private T data;
public static ResultVo success() {
return success(null);
}
public static <E> ResultVo<E> success(E data) {
ResultVo<E> result = new ResultVo<>();
result.setSuccess(true);
result.setData(data);
return result;
}
public static ResultVo fail(String errMsg) {
return fail(500, errMsg);
}
public static ResultVo fail(int errCode, String errMsg) {
ResultVo result = new ResultVo<>();
result.setSuccess(false);
result.setErrCode(errCode);
result.setErrMsg(errMsg);
return result;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getErrCode() {
return errCode;
}
public void setErrCode(int errCode) {
this.errCode = errCode;
}
public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
...@@ -15,22 +15,22 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -15,22 +15,22 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
@EnableScheduling @EnableScheduling
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.zq.spiderflow", "com.zq.common.config.base"})
@MapperScan({"com.zq.spiderflow.*.mapper", "com.zq.spiderflow.dao"}) @MapperScan({"com.zq.spiderflow.*.mapper", "com.zq.spiderflow.dao"})
public class SpiderApplication implements ServletContextInitializer{ public class SpiderApplication implements ServletContextInitializer {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
SpringApplication.run(SpiderApplication.class, args); SpringApplication.run(SpiderApplication.class, args);
} }
@Override @Override
public void onStartup(ServletContext servletContext) throws ServletException { public void onStartup(ServletContext servletContext) throws ServletException {
//设置文本缓存1M //设置文本缓存1M
servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", Integer.toString((1024 * 1024))); servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize", Integer.toString((1024 * 1024)));
} }
@Bean @Bean
public PaginationInterceptor paginationInterceptor() { public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor(); return new PaginationInterceptor();
} }
......
package com.zq.spiderflow.configuration;/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.zq.common.base.SecurityProperties;
import com.zq.common.config.redis.RedisUtils;
import com.zq.common.vo.AppTokenVo;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.DatatypeConverter;
import java.security.Key;
import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
* @author /
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class AppTokenUtils implements InitializingBean {
private RedisUtils redisUtils;
private static final String APP_TOKEN_KEY = "appToken";
private static Key key;
private static SignatureAlgorithm signatureAlgorithm;
@Override
public void afterPropertiesSet() {
signatureAlgorithm = SignatureAlgorithm.HS512;
byte[] keyBytes = DatatypeConverter.parseBase64Binary(SecurityProperties.BASE64SECRET);
key = new SecretKeySpec(keyBytes, signatureAlgorithm.getJcaName());
}
public static String createToken(AppTokenVo tokenVo, long minutes) {
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
JwtBuilder jwtBuilder = Jwts.builder()
.setSubject(tokenVo.getPhone())
.setIssuedAt(now)
.claim(APP_TOKEN_KEY, tokenVo)
.signWith(signatureAlgorithm, key)
// 加入ID确保生成的 Token 都不一致
.setId(tokenVo.getUserId().toString());
if (minutes >= 0) {
long expMillis = nowMillis + (minutes * 60 * 1000);
Date exp = new Date(expMillis);
jwtBuilder.setExpiration(exp);
}
return jwtBuilder.compact();
}
public static AppTokenVo getAppTokenVo(String token) {
try {
Claims claims = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary(SecurityProperties.BASE64SECRET))
.parseClaimsJws(token)
.getBody();
// fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException
return JSON.parseObject(JSON.toJSONString(claims.get(APP_TOKEN_KEY)), AppTokenVo.class);
} catch (Exception e) {
return null;
}
}
/**
* @param token 需要检查的token
*/
public void checkRenewal(String token) {
// 判断是否续期token,计算token的过期时间
long time = redisUtils.getExpire(SecurityProperties.ONLINEKEY + token) * 1000;
Date expireDate = DateUtil.offset(new Date(), DateField.MILLISECOND, (int) time);
// 判断当前时间与过期时间的时间差
long differ = expireDate.getTime() - System.currentTimeMillis();
// 如果在续期检查的范围内,则续期
if (differ <= SecurityProperties.DETECT) {
long renew = time + SecurityProperties.RENEW;
redisUtils.expire(SecurityProperties.ONLINEKEY + token, renew, TimeUnit.MILLISECONDS);
}
}
public static String resolveToken(HttpServletRequest request) {
String bearerToken = request.getHeader(SecurityProperties.HEADER);
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith(SecurityProperties.getTokenStartWith())) {
// 去掉令牌前缀
return bearerToken.replace(SecurityProperties.getTokenStartWith(), "");
}
return null;
}
}
package com.zq.spiderflow.configuration;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
@Configuration
public class MybatisPlusConfig {
/**
* MybatisPlus分页插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
/**
* 官方原话
* MybatisPlus新的分页插件,一缓和二缓遵循mybatis的规则,
* 需要设置 MybatisConfiguration#useDeprecatedExecutor = false
* 避免缓存出现问题(该属性会在旧插件移除后一同移除)
*/
@SuppressWarnings(value = {"deprecation"})
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.setUseDeprecatedExecutor(false);
}
/**
* pagehelper分页插件
*/
@Bean
public PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
properties.put("helperDialect", "mysql");
pageInterceptor.setProperties(properties);
return pageInterceptor;
}
}
package com.zq.spiderflow.configuration;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.NetUtil;
import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author wilmiam
* @since 2021/11/12 11:19
*/
@Component
@ConfigurationProperties(prefix = "project")
public class ProjectConfig {
public static String version = "v1.1";
public static String windowsPath = "D:\\jcy-file";
public static String linuxPath = "/instrument";
public static final String MAPPER_PATH = "/instrument/**";
public static final String HOME_URL = "http://" + NetUtil.getLocalhostStr() + ":9679/";
public static final String SALT = "MaiLu/1301";
public static final String SYSTEM_TAG = "oa-instrument";
public void setVersion(String version) {
ProjectConfig.version = version;
}
public void setWindowsPath(String windowsPath) {
ProjectConfig.windowsPath = windowsPath;
if (FileUtil.exist(windowsPath)) {
FileUtil.mkdir(windowsPath);
}
}
public void setLinuxPath(String linuxPath) {
ProjectConfig.linuxPath = linuxPath;
if (FileUtil.exist(linuxPath)) {
FileUtil.mkdir(linuxPath);
}
}
/**
* 获取当前系统路径
*
* @return
*/
public static String getSysPath() {
OsInfo osInfo = SystemUtil.getOsInfo();
if (osInfo.isWindows()) {
return windowsPath;
} else if (osInfo.isLinux()) {
return linuxPath;
}
return linuxPath;
}
}
...@@ -17,6 +17,7 @@ package com.zq.spiderflow.configuration;/* ...@@ -17,6 +17,7 @@ package com.zq.spiderflow.configuration;/*
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.zq.common.base.SecurityProperties; import com.zq.common.base.SecurityProperties;
import com.zq.common.config.redis.RedisUtils; import com.zq.common.config.redis.RedisUtils;
import com.zq.common.context.ThreadContext;
import com.zq.common.utils.TokenUtils; import com.zq.common.utils.TokenUtils;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -70,6 +71,8 @@ TokenFilter extends GenericFilterBean { ...@@ -70,6 +71,8 @@ TokenFilter extends GenericFilterBean {
} }
} }
filterChain.doFilter(servletRequest, servletResponse); filterChain.doFilter(servletRequest, servletResponse);
ThreadContext.close();
} }
} }
package com.zq.spiderflow.controller; package com.zq.spiderflow.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.entity.MetaDataCategory; import com.zq.spiderflow.entity.MetaDataCategory;
import com.zq.spiderflow.service.MetaDataCategoryService; import com.zq.spiderflow.service.MetaDataCategoryService;
import com.zq.spiderflow.util.AssertUtils; import com.zq.spiderflow.util.AssertUtils;
import com.zq.spiderflow.vo.MetaDataCategoryReq; import com.zq.spiderflow.vo.MetaDataCategoryReq;
import com.zq.spiderflow.vo.PageVo;
import com.zq.spiderflow.vo.ResultVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
......
package com.zq.spiderflow.controller; package com.zq.spiderflow.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.entity.MetaData; import com.zq.spiderflow.entity.MetaData;
import com.zq.spiderflow.service.MetaDataService; import com.zq.spiderflow.service.MetaDataService;
import com.zq.spiderflow.util.AssertUtils; import com.zq.spiderflow.util.AssertUtils;
import com.zq.spiderflow.vo.MetaDataReq; import com.zq.spiderflow.vo.MetaDataReq;
import com.zq.spiderflow.vo.MetaDataVo; import com.zq.spiderflow.vo.MetaDataVo;
import com.zq.spiderflow.vo.PageVo;
import com.zq.spiderflow.vo.ResultVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.zq.common.vo.PageVo;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
......
package com.zq.spiderflow.controller; package com.zq.spiderflow.controller;
import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.entity.MetaDataMapping; import com.zq.spiderflow.entity.MetaDataMapping;
import com.zq.spiderflow.service.MetaDataMappingService; import com.zq.spiderflow.service.MetaDataMappingService;
import com.zq.spiderflow.service.MetaDataService; import com.zq.spiderflow.service.MetaDataService;
import com.zq.spiderflow.util.AssertUtils; import com.zq.spiderflow.util.AssertUtils;
import com.zq.spiderflow.vo.MetaDataMappingReq; import com.zq.spiderflow.vo.MetaDataMappingReq;
import com.zq.spiderflow.vo.PageVo;
import com.zq.spiderflow.vo.ResultVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
......
package com.zq.spiderflow.controller; package com.zq.spiderflow.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zq.common.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.zq.common.vo.ResultVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zq.spiderflow.core.service.SpiderFlowService; import com.zq.spiderflow.core.service.SpiderFlowService;
import com.zq.spiderflow.core.utils.ExecutorsUtils; import com.zq.spiderflow.core.utils.ExecutorsUtils;
import com.zq.spiderflow.core.vo.SpiderFlowVo; import com.zq.spiderflow.core.vo.SpiderFlowVo;
import com.zq.spiderflow.vo.ResultVo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
...@@ -102,8 +99,8 @@ public class SpiderFlowController { ...@@ -102,8 +99,8 @@ public class SpiderFlowController {
* @return Page<SpiderFlow> 所有爬虫的列表页 * @return Page<SpiderFlow> 所有爬虫的列表页
*/ */
@PostMapping("/list") @PostMapping("/list")
public IPage<SpiderFlow> list(@RequestBody SpiderFlowVo vo) { public PageVo<SpiderFlowVo> list(@RequestBody SpiderFlowVo vo) {
return spiderFlowService.page(new Page<SpiderFlow>(vo.getPage(),vo.getSize()),new LambdaQueryWrapper<SpiderFlow>().like(SpiderFlow ::getName,vo.getName())); return spiderFlowService.getPageList(vo);
} }
@RequestMapping("/save") @RequestMapping("/save")
......
package com.zq.spiderflow.controller; package com.zq.spiderflow.controller;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.core.service.SpiderFlowService; import com.zq.spiderflow.core.service.SpiderFlowService;
import com.zq.spiderflow.vo.ResultVo;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
......
...@@ -11,4 +11,6 @@ import java.util.List; ...@@ -11,4 +11,6 @@ import java.util.List;
public interface MetaDataDao extends BaseMapper<MetaData> { public interface MetaDataDao extends BaseMapper<MetaData> {
List<MetaDataVo> getPage(@Param("req") MetaDataReq req); List<MetaDataVo> getPage(@Param("req") MetaDataReq req);
List<MetaDataVo> getPageList(@Param("req") MetaDataReq req);
} }
...@@ -2,11 +2,11 @@ package com.zq.spiderflow.service; ...@@ -2,11 +2,11 @@ package com.zq.spiderflow.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.common.utils.PagingUtils;
import com.zq.common.vo.PageVo;
import com.zq.spiderflow.dao.MetaDataCategoryDao; import com.zq.spiderflow.dao.MetaDataCategoryDao;
import com.zq.spiderflow.entity.MetaDataCategory; import com.zq.spiderflow.entity.MetaDataCategory;
import com.zq.spiderflow.util.PagingUtils;
import com.zq.spiderflow.vo.MetaDataCategoryReq; import com.zq.spiderflow.vo.MetaDataCategoryReq;
import com.zq.spiderflow.vo.PageVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -23,11 +23,11 @@ public class MetaDataCategoryService extends ServiceImpl<MetaDataCategoryDao, Me ...@@ -23,11 +23,11 @@ public class MetaDataCategoryService extends ServiceImpl<MetaDataCategoryDao, Me
return PagingUtils.paging(req, metaDataCategoryDao, wrapper, MetaDataCategory.class); return PagingUtils.paging(req, metaDataCategoryDao, wrapper, MetaDataCategory.class);
} }
public List<MetaDataCategory> getCategoryTree(Integer categoryCode, Integer currentLevel){ public List<MetaDataCategory> getCategoryTree(Integer categoryCode, Integer currentLevel) {
List<MetaDataCategory> list; List<MetaDataCategory> list;
if(null == categoryCode){ if (null == categoryCode) {
list = lambdaQuery().eq(MetaDataCategory::getStandardLevel, 0).list(); list = lambdaQuery().eq(MetaDataCategory::getStandardLevel, 0).list();
}else { } else {
list = lambdaQuery().eq(MetaDataCategory::getCategoryCode, categoryCode).eq(MetaDataCategory::getStandardLevel, ++currentLevel).orderByAsc(MetaDataCategory::getId).list(); list = lambdaQuery().eq(MetaDataCategory::getCategoryCode, categoryCode).eq(MetaDataCategory::getStandardLevel, ++currentLevel).orderByAsc(MetaDataCategory::getId).list();
} }
return list; return list;
......
...@@ -2,14 +2,14 @@ package com.zq.spiderflow.service; ...@@ -2,14 +2,14 @@ package com.zq.spiderflow.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.common.utils.PagingUtils;
import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo;
import com.zq.spiderflow.dao.MetaDataMappingDao; import com.zq.spiderflow.dao.MetaDataMappingDao;
import com.zq.spiderflow.entity.MetaDataMapping; import com.zq.spiderflow.entity.MetaDataMapping;
import com.zq.spiderflow.util.AssertUtils; import com.zq.spiderflow.util.AssertUtils;
import com.zq.spiderflow.util.PagingUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.zq.spiderflow.vo.MetaDataMappingReq; import com.zq.spiderflow.vo.MetaDataMappingReq;
import com.zq.spiderflow.vo.PageVo;
import com.zq.spiderflow.vo.ResultVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
......
...@@ -8,24 +8,25 @@ import cn.hutool.poi.excel.ExcelReader; ...@@ -8,24 +8,25 @@ import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zq.common.utils.PagingUtils;
import com.zq.common.vo.PageVo;
import com.zq.spiderflow.core.exception.BusinessException; import com.zq.spiderflow.core.exception.BusinessException;
import com.zq.spiderflow.dao.MetaDataDao; import com.zq.spiderflow.dao.MetaDataDao;
import com.zq.spiderflow.dao.MetaDataMappingDao; import com.zq.spiderflow.dao.MetaDataMappingDao;
import com.zq.spiderflow.entity.MetaData; import com.zq.spiderflow.entity.MetaData;
import com.zq.spiderflow.entity.MetaDataCategory; import com.zq.spiderflow.entity.MetaDataCategory;
import com.zq.spiderflow.entity.MetaDataMapping; import com.zq.spiderflow.entity.MetaDataMapping;
import com.zq.spiderflow.util.PagingUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.spiderflow.vo.MetaDataReq; import com.zq.spiderflow.vo.MetaDataReq;
import com.zq.spiderflow.vo.MetaDataVo; import com.zq.spiderflow.vo.MetaDataVo;
import com.zq.spiderflow.vo.PageVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
public class MetaDataService extends ServiceImpl<MetaDataDao, MetaData> { public class MetaDataService extends ServiceImpl<MetaDataDao, MetaData> {
...@@ -46,19 +47,34 @@ public class MetaDataService extends ServiceImpl<MetaDataDao, MetaData> { ...@@ -46,19 +47,34 @@ public class MetaDataService extends ServiceImpl<MetaDataDao, MetaData> {
// return metaDataDao.selectList(new LambdaQueryWrapper<MetaData>().eq(MetaData::getCategoryId, categoryId)); // return metaDataDao.selectList(new LambdaQueryWrapper<MetaData>().eq(MetaData::getCategoryId, categoryId));
// } // }
public PageVo<MetaData> getPageByCategoryId(MetaDataReq req) { public PageVo<MetaDataVo> getPageByCategoryId(MetaDataReq req) {
// 获取类别目录id参数 // 获取类别目录id参数
Long categoryId = req.getCategoryId(); Long categoryId = req.getCategoryId();
// 获取模糊查询的条件 // 获取模糊查询的条件
String metaName = req.getMetaName(); String metaName = req.getMetaName();
LambdaQueryWrapper<MetaData> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MetaData> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MetaData::getCategoryId, categoryId); // wrapper.eq(MetaData::getCategoryId, categoryId).last("LIMIT 10");
// 判断模糊查询的条件是否为空或空字符串 // 判断模糊查询的条件是否为空或空字符串
if (StringUtils.isNotBlank(metaName)) { if (StringUtils.isNotBlank(metaName)) {
// 如果不为空或空字符串,添加一个模糊查询的条件 // 如果不为空或空字符串,添加一个模糊查询的条件
wrapper.like(MetaData::getMetaName, metaName); wrapper.like(MetaData::getMetaName, metaName);
} }
return PagingUtils.paging(req, metaDataDao, wrapper, MetaData.class);
List<MetaDataVo> pageList = metaDataDao.getPageList(req);
int start=0;
PageVo<MetaDataVo> pageVo = new PageVo<>();
if (req.getPage() - 1 == 0) {
pageVo.setStart(0);
start = 0;
} else {
pageVo.setStart((req.getPage() - 1) * req.getSize());
start = (req.getPage() - 1) * req.getSize();
}
pageVo.setPage(req.getPage());
pageVo.setSize(req.getSize());
pageVo.setRows(pageList);
pageVo.setTotal(pageList.size());
return pageVo;
// LambdaQueryWrapper<MetaDataMapping> mappingWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<MetaDataMapping> mappingWrapper = new LambdaQueryWrapper<>();
// List<MetaData> metaDatas = metaDataDao.selectList(wrapper.eq(MetaData::getCategoryId, categoryId)); // List<MetaData> metaDatas = metaDataDao.selectList(wrapper.eq(MetaData::getCategoryId, categoryId));
// MetaDataReq metaDataReq = new MetaDataReq(); // MetaDataReq metaDataReq = new MetaDataReq();
...@@ -160,7 +176,7 @@ public class MetaDataService extends ServiceImpl<MetaDataDao, MetaData> { ...@@ -160,7 +176,7 @@ public class MetaDataService extends ServiceImpl<MetaDataDao, MetaData> {
if (StringUtils.isNotBlank(req.getEnglishName())) { if (StringUtils.isNotBlank(req.getEnglishName())) {
queryWrapper.like(MetaData::getEnglishName, req.getEnglishName()); queryWrapper.like(MetaData::getEnglishName, req.getEnglishName());
} }
return PagingUtils.paging(req, metaDataDao, queryWrapper, MetaData.class); return PagingUtils.paging(req,metaDataDao,queryWrapper,MetaData.class);
} }
public List<MetaDataReq> getMetaByTable(MetaDataReq req) { public List<MetaDataReq> getMetaByTable(MetaDataReq req) {
......
package com.zq.spiderflow.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.zq.spiderflow.core.exception.BusinessException;
import com.zq.spiderflow.vo.PageReqVo;
import com.zq.spiderflow.vo.PageVo;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public abstract class PagingUtils {
/**
* pagehelper分页插件
*
* @param reqVo
* @param rowsLoader
* @param <R>
* @param <Q>
* @return
*/
@SuppressWarnings("all")
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, Function<Q, List<R>> rowsLoader) {
PageHelper.startPage(reqVo.getPage(), reqVo.getSize());
com.github.pagehelper.Page<R> page = (com.github.pagehelper.Page) rowsLoader.apply(reqVo);
return PageVo.ofReqVo(reqVo, page.getResult(), Long.valueOf(page.getTotal()).intValue());
}
/**
* mybatis-plus自带分页插件
*
* @param reqVo
* @param mapper
* @param clazz
* @param <R>
* @param <Q>
* @return
*/
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, Class<R> clazz) {
R entity;
try {
entity = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new BusinessException("分页类型转换错误");
}
BeanUtil.copyProperties(reqVo, entity);
IPage<R> page = new Page<>(reqVo.getPage(), reqVo.getSize());
page = mapper.selectPage(page, Wrappers.lambdaQuery(entity));
return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue());
}
/**
* mybatis-plus自带分页插件
*
* @param reqVo
* @param mapper
* @param <R>
* @param <Q>
* @return
*/
@SuppressWarnings("all")
public static <R, Q extends PageReqVo> PageVo<R> paging(Q reqVo, BaseMapper<R> mapper, LambdaQueryWrapper<R> lambdaQuery, Class<R> clazz) {
R entity;
try {
entity = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new BusinessException("分页类型转换错误");
}
// 已设置在lambdaQuery的字段实体类中不应该重复设置
String[] whereFields = getWhereFields(lambdaQuery);
BeanUtil.copyProperties(reqVo, entity, whereFields);
lambdaQuery.setEntity(entity);
IPage<R> page = new Page<>(reqVo.getPage(), reqVo.getSize());
page = mapper.selectPage(page, lambdaQuery);
return PageVo.ofReqVo(reqVo, page.getRecords(), Long.valueOf(page.getTotal()).intValue());
}
/**
* 获取设置的条件字段名
*
* @param lambdaQuery
* @param <R>
* @return
*/
public static <R> String[] getWhereFields(LambdaQueryWrapper<R> lambdaQuery) {
List<String> fields = new ArrayList<>();
MergeSegments expression = lambdaQuery.getExpression();
NormalSegmentList normal = expression.getNormal();
int index = 0;
for (ISqlSegment iSqlSegment : normal) {
if (index % 4 == 0) {
String field = StrUtil.toCamelCase(iSqlSegment.getSqlSegment());
fields.add(field);
}
index++;
}
return fields.toArray(new String[]{});
}
}
package com.zq.spiderflow.vo; package com.zq.spiderflow.vo;
import com.zq.common.vo.PageReqVo;
import lombok.Data; import lombok.Data;
@Data @Data
......
package com.zq.spiderflow.vo; package com.zq.spiderflow.vo;
import com.zq.common.vo.PageReqVo;
import lombok.Data; import lombok.Data;
@Data @Data
......
...@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; ...@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import com.zq.common.vo.PageReqVo;
@Data @Data
@Builder @Builder
......
...@@ -2,15 +2,18 @@ package com.zq.spiderflow.vo; ...@@ -2,15 +2,18 @@ package com.zq.spiderflow.vo;
import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date; import java.util.Date;
@Data @Data
@Builder @Builder
@AllArgsConstructor
@NoArgsConstructor
public class MetaDataVo { public class MetaDataVo {
private Long id;
/** /**
* 数据元名称 * 数据元名称
......
package com.zq.spiderflow.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class PageReqVo {
/**
* 每页显示行数默认为20
*/
private static final int DEFAULT_SIZE = 20;
private int page = 1;
private int size = DEFAULT_SIZE;
private String sort;
private String dir;
public static PageReqVo of(int page, int size) {
PageReqVo pageReqVo = new PageReqVo();
pageReqVo.setPage(page);
pageReqVo.setSize(size);
return pageReqVo;
}
public PageReqVo() {
}
@JsonIgnore
public int getOffset() {
return (getPage() - 1) * getSize();
}
public int getPage() {
// default to the first page
return page > 0 ? page : 1;
}
public void setPage(int page) {
this.page = page;
}
public int getSize() {
return size > 0 ? size : DEFAULT_SIZE;
}
public void setSize(int size) {
this.size = size;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getDir() {
return dir;
}
public void setDir(String dir) {
this.dir = dir;
}
}
package com.zq.spiderflow.vo;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.List;
@JsonPropertyOrder({"start", "size", "total", "rows"})
public class PageVo<T>{
private int start;
private int size;
private int total;
private List<T> rows;
public static <E> PageVo<E> ofReqVo(PageReqVo reqVo, List<E> rows, int total) {
PageVo<E> pageVo = new PageVo<>();
pageVo.setSize(reqVo.getSize());
pageVo.setStart(reqVo.getOffset());
pageVo.setTotal(total);
pageVo.setRows(rows);
return pageVo;
}
public PageVo() {
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
package com.zq.spiderflow.vo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResultVo<T> implements Serializable {
private boolean success;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
private int errCode;
private String errMsg;
private T data;
public static ResultVo success() {
return success(null);
}
public static <E> ResultVo<E> success(E data) {
ResultVo<E> result = new ResultVo<>();
result.setSuccess(true);
result.setData(data);
return result;
}
public static ResultVo fail(String errMsg) {
return fail(500, errMsg);
}
public static ResultVo fail(int errCode, String errMsg) {
ResultVo result = new ResultVo<>();
result.setSuccess(false);
result.setErrCode(errCode);
result.setErrMsg(errMsg);
return result;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getErrCode() {
return errCode;
}
public void setErrCode(int errCode) {
this.errCode = errCode;
}
public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
...@@ -61,10 +61,10 @@ spider: ...@@ -61,10 +61,10 @@ spider:
end: 流程执行完毕:{name},结束时间:{currentDate} end: 流程执行完毕:{name},结束时间:{currentDate}
exception: 流程发生异常:{name},异常时间:{currentDate} exception: 流程发生异常:{name},异常时间:{currentDate}
logging: #logging:
level: # level:
org.apache.http: INFO # org.apache.http: INFO
org.quartz: INFO # org.quartz: INFO
#设置chrome的WebDriver驱动路径 #设置chrome的WebDriver驱动路径
...@@ -74,9 +74,9 @@ selenium: ...@@ -74,9 +74,9 @@ selenium:
# mybatis plus 配置 # mybatis plus 配置
mybatis-plus: mybatis-plus:
configuration: # configuration:
jdbc-type-for-null: null # jdbc-type-for-null: null
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config: global-config:
db-config: db-config:
select-strategy: not_empty select-strategy: not_empty
......
spring: spring:
profiles:
active: @profiles.active@
cloud: cloud:
config: config:
name: config name: config
profile: @profiles.active@ profile: ${spring.profiles.active}
discovery: discovery:
enabled: true enabled: true
service-id: CONFIG-SERVER service-id: CONFIG-SERVER
uri: http://127.0.0.1:8300/ username: admin
password: 123456
eureka: eureka:
instance: instance:
prefer-ip-address: true # 使用IP注册服务 prefer-ip-address: true
lease-renewal-interval-in-seconds: 2 #每间隔1s,向服务端发送一次心跳,证明自己依然"存活" lease-renewal-interval-in-seconds: 2 #向服务端发送心跳间隔
lease-expiration-duration-in-seconds: 6 #告诉服务端,如果我2s之内没有给你发心跳,就代表我"死"了,将我踢出掉。 lease-expiration-duration-in-seconds: 6 #告诉服务端多少秒没收到心跳将我踢出掉
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client: client:
registry-fetch-interval-seconds: 6 #从服务端注册表中获取注册信息的时间间隔
serviceUrl: serviceUrl:
defaultZone: http://admin:123456@127.0.0.1:8800/eureka/ defaultZone: http://admin:123456@127.0.0.1:8800/eureka/
\ No newline at end of file
#Feign 超时配置
feign:
client:
config:
default:
connect-timeout: 2000 # 连接超时时间 ms
read-timeout: 10000 # 读取超时时间 ms
logger-level: BASIC # 仅记录请求的方法,URL以及响应状态码和执行时间
ribbon:
# ribbon服务列表刷新间隔(单位ms)
ServerListRefreshInterval: 2000
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zq.spiderflow.dao.MetaDataDao"> <mapper namespace="com.zq.spiderflow.dao.MetaDataDao">
<select id="getPage" resultType="com.zq.spiderflow.vo.MetaDataVo"> <select id="getPage" resultType="com.zq.spiderflow.vo.MetaDataVo">
SELECT SELECT
m.*, m.*,
...@@ -20,4 +21,7 @@ ...@@ -20,4 +21,7 @@
</where> </where>
ORDER BY m.ID DESC ORDER BY m.ID DESC
</select> </select>
<select id="getPageList" resultType="com.zq.spiderflow.vo.MetaDataVo">
select * FROM meta_data me WHERE me.category_id = #{req.categoryId} LIMIT #{req.page},#{req.size}
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment