🎨 Improving structure / format of the code. 格式化代码

This commit is contained in:
冷冷 2024-03-28 14:17:04 +08:00
parent 3c2bd9ce53
commit c4483ebb11
7 changed files with 728 additions and 784 deletions

View File

@ -45,33 +45,33 @@ import org.springframework.context.annotation.Scope;
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
public class PigFeignAutoConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.sentinel.enabled")
public Feign.Builder feignSentinelBuilder() {
return PigSentinelFeign.builder();
}
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.sentinel.enabled")
public Feign.Builder feignSentinelBuilder() {
return PigSentinelFeign.builder();
}
@Bean
@ConditionalOnMissingBean
public BlockExceptionHandler blockExceptionHandler(ObjectMapper objectMapper) {
return new PigUrlBlockHandler(objectMapper);
}
@Bean
@ConditionalOnMissingBean
public BlockExceptionHandler blockExceptionHandler(ObjectMapper objectMapper) {
return new PigUrlBlockHandler(objectMapper);
}
@Bean
@ConditionalOnMissingBean
public RequestOriginParser requestOriginParser() {
return new PigHeaderRequestOriginParser();
}
@Bean
@ConditionalOnMissingBean
public RequestOriginParser requestOriginParser() {
return new PigHeaderRequestOriginParser();
}
/**
* add http connection close header
* @return
*/
@Bean
public PigFeignRequestCloseInterceptor pigFeignRequestCloseInterceptor() {
return new PigFeignRequestCloseInterceptor();
}
/**
* add http connection close header
*
* @return
*/
@Bean
public PigFeignRequestCloseInterceptor pigFeignRequestCloseInterceptor() {
return new PigFeignRequestCloseInterceptor();
}
}

View File

@ -11,13 +11,13 @@ import org.springframework.http.HttpHeaders;
*/
public class PigFeignRequestCloseInterceptor implements RequestInterceptor {
/**
* set connection close
*
* @param template
*/
@Override
public void apply(feign.RequestTemplate template) {
template.header(HttpHeaders.CONNECTION, "close");
}
/**
* set connection close
* @param template
*/
@Override
public void apply(feign.RequestTemplate template) {
template.header(HttpHeaders.CONNECTION, "close");
}
}

View File

@ -46,56 +46,59 @@ import java.util.stream.Collectors;
@Slf4j
public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver {
/**
* 判断Controller是否包含page 参数
*
* @param parameter 参数
* @return 是否过滤
*/
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().equals(Page.class);
}
/**
* 判断Controller是否包含page 参数
* @param parameter 参数
* @return 是否过滤
*/
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().equals(Page.class);
}
/**
* @param parameter 入参集合
* @param mavContainer model view
* @param webRequest web相关
* @param binderFactory 入参解析
* @return 检查后新的page对象
* <p>
* page 只支持查询 GET .如需解析POST获取请求报文体处理
*/
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
/**
* @param parameter 入参集合
* @param mavContainer model view
* @param webRequest web相关
* @param binderFactory 入参解析
* @return 检查后新的page对象
* <p>
* page 只支持查询 GET .如需解析POST获取请求报文体处理
*/
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
String[] ascs = request.getParameterValues("ascs");
String[] descs = request.getParameterValues("descs");
String current = request.getParameter("current");
String size = request.getParameter("size");
String[] ascs = request.getParameterValues("ascs");
String[] descs = request.getParameterValues("descs");
String current = request.getParameter("current");
String size = request.getParameter("size");
Page<?> page = new Page<>();
if (StrUtil.isNotBlank(current)) {
page.setCurrent(Long.parseLong(current));
}
Page<?> page = new Page<>();
if (StrUtil.isNotBlank(current)) {
page.setCurrent(Long.parseLong(current));
}
if (StrUtil.isNotBlank(size)) {
page.setSize(Long.parseLong(size));
}
if (StrUtil.isNotBlank(size)) {
page.setSize(Long.parseLong(size));
}
List<OrderItem> orderItemList = new ArrayList<>();
Optional.ofNullable(ascs)
.ifPresent(s -> orderItemList.addAll(
Arrays.stream(s).filter(asc -> !SqlInjectionUtils.check(asc)).map(OrderItem::asc).collect(Collectors.toList())));
Optional.ofNullable(descs)
.ifPresent(s -> orderItemList.addAll(
Arrays.stream(s).filter(desc -> !SqlInjectionUtils.check(desc)).map(OrderItem::desc).collect(Collectors.toList())));
page.addOrder(orderItemList);
List<OrderItem> orderItemList = new ArrayList<>();
Optional.ofNullable(ascs)
.ifPresent(s -> orderItemList.addAll(Arrays.stream(s)
.filter(asc -> !SqlInjectionUtils.check(asc))
.map(OrderItem::asc)
.collect(Collectors.toList())));
Optional.ofNullable(descs)
.ifPresent(s -> orderItemList.addAll(Arrays.stream(s)
.filter(desc -> !SqlInjectionUtils.check(desc))
.map(OrderItem::desc)
.collect(Collectors.toList())));
page.addOrder(orderItemList);
return page;
}
return page;
}
}

View File

@ -21,62 +21,58 @@ import org.springframework.data.redis.core.RedisTemplate;
@EnableConfigurationProperties(GatewayConfigProperties.class)
public class GatewayConfiguration {
/**
* 创建密码解码器过滤器
*
* @param modifyRequestBodyGatewayFilterFactory 修改请求体网关过滤器工厂
* @param configProperties 配置属性
* @return 密码解码器过滤器
*/
@Bean
public PasswordDecoderFilter passwordDecoderFilter(
ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory,
GatewayConfigProperties configProperties) {
return new PasswordDecoderFilter(modifyRequestBodyGatewayFilterFactory, configProperties);
}
/**
* 创建密码解码器过滤器
* @param modifyRequestBodyGatewayFilterFactory 修改请求体网关过滤器工厂
* @param configProperties 配置属性
* @return 密码解码器过滤器
*/
@Bean
public PasswordDecoderFilter passwordDecoderFilter(
ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory,
GatewayConfigProperties configProperties) {
return new PasswordDecoderFilter(modifyRequestBodyGatewayFilterFactory, configProperties);
}
/**
* 创建PigRequest全局过滤器
*
* @return PigRequest全局过滤器
*/
@Bean
public PigRequestGlobalFilter pigRequestGlobalFilter() {
return new PigRequestGlobalFilter();
}
/**
* 创建PigRequest全局过滤器
* @return PigRequest全局过滤器
*/
@Bean
public PigRequestGlobalFilter pigRequestGlobalFilter() {
return new PigRequestGlobalFilter();
}
/**
* 创建验证码网关过滤器
*
* @param configProperties 配置属性
* @param redisTemplate Redis模板
* @return 验证码网关过滤器
*/
@Bean
public ValidateCodeGatewayFilter validateCodeGatewayFilter(GatewayConfigProperties configProperties, RedisTemplate redisTemplate) {
return new ValidateCodeGatewayFilter(configProperties, redisTemplate);
}
/**
* 创建验证码网关过滤器
* @param configProperties 配置属性
* @param redisTemplate Redis模板
* @return 验证码网关过滤器
*/
@Bean
public ValidateCodeGatewayFilter validateCodeGatewayFilter(GatewayConfigProperties configProperties,
RedisTemplate redisTemplate) {
return new ValidateCodeGatewayFilter(configProperties, redisTemplate);
}
/**
* 创建全局异常处理程序
*
* @param objectMapper 对象映射器
* @return 全局异常处理程序
*/
@Bean
public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) {
return new GlobalExceptionHandler(objectMapper);
}
/**
* 创建全局异常处理程序
* @param objectMapper 对象映射器
* @return 全局异常处理程序
*/
@Bean
public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) {
return new GlobalExceptionHandler(objectMapper);
}
/**
* 创建图片验证码处理器
*
* @param redisTemplate Redis模板
* @return 图片验证码处理器
*/
@Bean
public ImageCodeHandler imageCodeHandler(RedisTemplate redisTemplate) {
return new ImageCodeHandler(redisTemplate);
}
/**
* 创建图片验证码处理器
* @param redisTemplate Redis模板
* @return 图片验证码处理器
*/
@Bean
public ImageCodeHandler imageCodeHandler(RedisTemplate redisTemplate) {
return new ImageCodeHandler(redisTemplate);
}
}

View File

@ -257,7 +257,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 根据数据权限查询全部的用户信息
List<UserVO> voList = baseMapper.selectVoList(userDTO);
// 转换成execl 对象输出
return voList.stream().map(userVO -> {
return voList.stream().map(userVO -> {
UserExcelVO excelVO = new UserExcelVO();
BeanUtils.copyProperties(userVO, excelVO);
String roleNameList = userVO.getRoleList()

View File

@ -69,8 +69,7 @@ public class SysJobController {
/**
* 定时任务分页查询
*
* @param page 分页对象
* @param page 分页对象
* @param sysJob 定时任务调度表
* @return R
*/
@ -78,17 +77,16 @@ public class SysJobController {
@Operation(description = "分页定时业务查询")
public R getSysJobPage(Page page, SysJob sysJob) {
LambdaQueryWrapper<SysJob> wrapper = Wrappers.<SysJob>lambdaQuery()
.like(StrUtil.isNotBlank(sysJob.getJobName()), SysJob::getJobName, sysJob.getJobName())
.like(StrUtil.isNotBlank(sysJob.getJobGroup()), SysJob::getJobGroup, sysJob.getJobGroup())
.eq(StrUtil.isNotBlank(sysJob.getJobStatus()), SysJob::getJobStatus, sysJob.getJobGroup())
.eq(StrUtil.isNotBlank(sysJob.getJobExecuteStatus()), SysJob::getJobExecuteStatus,
sysJob.getJobExecuteStatus());
.like(StrUtil.isNotBlank(sysJob.getJobName()), SysJob::getJobName, sysJob.getJobName())
.like(StrUtil.isNotBlank(sysJob.getJobGroup()), SysJob::getJobGroup, sysJob.getJobGroup())
.eq(StrUtil.isNotBlank(sysJob.getJobStatus()), SysJob::getJobStatus, sysJob.getJobGroup())
.eq(StrUtil.isNotBlank(sysJob.getJobExecuteStatus()), SysJob::getJobExecuteStatus,
sysJob.getJobExecuteStatus());
return R.ok(sysJobService.page(page, wrapper));
}
/**
* 通过id查询定时任务
*
* @param id id
* @return R
*/
@ -100,7 +98,6 @@ public class SysJobController {
/**
* 新增定时任务,默认新增状态为1已发布
*
* @param sysJob 定时任务调度表
* @return R
*/
@ -109,13 +106,8 @@ public class SysJobController {
@PreAuthorize("@pms.hasPermission('job_sys_job_add')")
@Operation(description = "新增定时任务")
public R save(@RequestBody SysJob sysJob) {
long count = sysJobService
.count(Wrappers.query(
SysJob.builder()
.jobName(sysJob.getJobName())
.jobGroup(sysJob.getJobGroup())
.build()
));
long count = sysJobService.count(
Wrappers.query(SysJob.builder().jobName(sysJob.getJobName()).jobGroup(sysJob.getJobGroup()).build()));
if (count > 0) {
return R.failed("任务重复,请检查此组内是否已包含同名任务");
@ -127,7 +119,6 @@ public class SysJobController {
/**
* 修改定时任务
*
* @param sysJob 定时任务调度表
* @return R
*/
@ -139,10 +130,11 @@ public class SysJobController {
sysJob.setUpdateBy(SecurityUtils.getUser().getUsername());
SysJob querySysJob = this.sysJobService.getById(sysJob.getJobId());
if (PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType().equals(querySysJob.getJobStatus())) {
//如修改暂停的需更新调度器
// 如修改暂停的需更新调度器
this.taskUtil.addOrUpateJob(sysJob, scheduler);
sysJobService.updateById(sysJob);
} else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) {
}
else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) {
sysJobService.updateById(sysJob);
}
return R.ok();
@ -150,7 +142,6 @@ public class SysJobController {
/**
* 通过id删除定时任务
*
* @param id id
* @return R
*/
@ -163,7 +154,8 @@ public class SysJobController {
if (PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType().equals(querySysJob.getJobStatus())) {
this.taskUtil.removeJob(querySysJob, scheduler);
this.sysJobService.removeById(id);
} else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) {
}
else if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) {
this.sysJobService.removeById(id);
}
return R.ok();
@ -171,7 +163,6 @@ public class SysJobController {
/**
* 暂停全部定时任务
*
* @return R
*/
@SysLog("暂停全部定时任务")
@ -184,19 +175,19 @@ public class SysJobController {
new LambdaQueryWrapper<SysJob>().eq(SysJob::getJobStatus, PigQuartzEnum.JOB_STATUS_RUNNING.getType()));
if (count <= 0) {
return R.ok("无正在运行定时任务");
} else {
}
else {
// 更新定时任务状态条件运行状态2更新为暂停状态3
this.sysJobService.update(
SysJob.builder().jobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()).build(),
new UpdateWrapper<SysJob>().lambda().eq(SysJob::getJobStatus,
PigQuartzEnum.JOB_STATUS_RUNNING.getType()));
new UpdateWrapper<SysJob>().lambda()
.eq(SysJob::getJobStatus, PigQuartzEnum.JOB_STATUS_RUNNING.getType()));
return R.ok("暂停成功");
}
}
/**
* 启动全部定时任务
*
* @return
*/
@SysLog("启动全部暂停的定时任务")
@ -206,16 +197,14 @@ public class SysJobController {
public R startJobs() {
// 更新定时任务状态条件暂停状态3更新为运行状态2
this.sysJobService.update(SysJob.builder().jobStatus(PigQuartzEnum.JOB_STATUS_RUNNING.getType()).build(),
new UpdateWrapper<SysJob>().lambda().eq(SysJob::getJobStatus,
PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()));
new UpdateWrapper<SysJob>().lambda()
.eq(SysJob::getJobStatus, PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()));
taskUtil.startJobs(scheduler);
return R.ok();
}
/**
* 刷新全部定时任务
* 暂停和运行的添加到调度器其他状态从调度器移除
*
* 刷新全部定时任务 暂停和运行的添加到调度器其他状态从调度器移除
* @return R
*/
@SysLog("刷新全部定时任务")
@ -227,7 +216,8 @@ public class SysJobController {
if (PigQuartzEnum.JOB_STATUS_RUNNING.getType().equals(sysjob.getJobStatus())
|| PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType().equals(sysjob.getJobStatus())) {
taskUtil.addOrUpateJob(sysjob, scheduler);
} else {
}
else {
taskUtil.removeJob(sysjob, scheduler);
}
});
@ -236,7 +226,6 @@ public class SysJobController {
/**
* 启动定时任务
*
* @param jobId 任务id
* @return R
*/
@ -250,7 +239,7 @@ public class SysJobController {
return R.failed("无此定时任务,请确认");
}
//如果定时任务不存在强制状态为1已发布
// 如果定时任务不存在强制状态为1已发布
if (!scheduler.checkExists(TaskUtil.getJobKey(querySysJob))) {
querySysJob.setJobStatus(PigQuartzEnum.JOB_STATUS_RELEASE.getType());
log.warn("定时任务不在quartz中,任务id:{},强制状态为已发布并加入调度器", jobId);
@ -258,18 +247,18 @@ public class SysJobController {
if (PigQuartzEnum.JOB_STATUS_RELEASE.getType().equals(querySysJob.getJobStatus())) {
taskUtil.addOrUpateJob(querySysJob, scheduler);
} else {
}
else {
taskUtil.resumeJob(querySysJob, scheduler);
}
// 更新定时任务状态为运行状态2
this.sysJobService.updateById(
SysJob.builder().jobId(jobId).jobStatus(PigQuartzEnum.JOB_STATUS_RUNNING.getType()).build());
this.sysJobService
.updateById(SysJob.builder().jobId(jobId).jobStatus(PigQuartzEnum.JOB_STATUS_RUNNING.getType()).build());
return R.ok();
}
/**
* 启动定时任务
*
* @param jobId 任务id
* @return R
*/
@ -280,7 +269,7 @@ public class SysJobController {
public R runJob(@PathVariable("id") Long jobId) throws SchedulerException {
SysJob querySysJob = this.sysJobService.getById(jobId);
//执行定时任务前判定任务是否在quartz中
// 执行定时任务前判定任务是否在quartz中
if (!scheduler.checkExists(TaskUtil.getJobKey(querySysJob))) {
querySysJob.setJobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType());
log.warn("立刻执行定时任务-定时任务不在quartz中,任务id:{},强制状态为暂停并加入调度器", jobId);
@ -292,7 +281,6 @@ public class SysJobController {
/**
* 暂停定时任务
*
* @return
*/
@SysLog("暂停定时任务")
@ -302,15 +290,16 @@ public class SysJobController {
public R shutdownJob(@PathVariable("id") Long id) {
SysJob querySysJob = this.sysJobService.getById(id);
// 更新定时任务状态条件运行状态2更新为暂停状态3
this.sysJobService.updateById(SysJob.builder().jobId(querySysJob.getJobId())
.jobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType()).build());
this.sysJobService.updateById(SysJob.builder()
.jobId(querySysJob.getJobId())
.jobStatus(PigQuartzEnum.JOB_STATUS_NOT_RUNNING.getType())
.build());
taskUtil.pauseJob(querySysJob, scheduler);
return R.ok();
}
/**
* 唯一标识查询定时执行日志
*
* @return
*/
@GetMapping("/job-log")
@ -321,20 +310,18 @@ public class SysJobController {
/**
* 检验任务名称和任务组联合是否唯一
*
* @return
*/
@GetMapping("/is-valid-task-name")
@Operation(description = "检验任务名称和任务组联合是否唯一")
public R isValidTaskName(@RequestParam String jobName, @RequestParam String jobGroup) {
return this.sysJobService
.count(Wrappers.query(SysJob.builder().jobName(jobName).jobGroup(jobGroup).build())) > 0
? R.failed("任务重复,请检查此组内是否已包含同名任务") : R.ok();
.count(Wrappers.query(SysJob.builder().jobName(jobName).jobGroup(jobGroup).build())) > 0
? R.failed("任务重复,请检查此组内是否已包含同名任务") : R.ok();
}
/**
* 导出任务
*
* @param sysJob
* @return
*/