Skip to content

Commit

Permalink
refactor: ApiProperties->ApiConfig
Browse files Browse the repository at this point in the history
docs: 一些优化
feat: 破坏性改动使用@serial注解不支持jdk17-
  • Loading branch information
BingChunMoLi committed Nov 5, 2022
1 parent db18f50 commit 9d851fc
Show file tree
Hide file tree
Showing 74 changed files with 2,369 additions and 3,074 deletions.
32 changes: 9 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -17,15 +17,16 @@

<properties>
<java.version>17</java.version>
<mybatis-plus.version>3.5.1</mybatis-plus.version>
<mybatis-plus.version>3.5.2</mybatis-plus.version>
<swagger.version>3.0.0</swagger.version>
<knife4j.version>3.0.3</knife4j.version>
<docker-plugin.version>1.4.9</docker-plugin.version>
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>
<hutool.version>5.8.0</hutool.version>
<hutool.version>5.8.9</hutool.version>
<zxing.version>3.5.0</zxing.version>
<emoji.version>5.1.1</emoji.version>
<ip2region.version>1.7.2</ip2region.version>
<h2.version>2.1.214</h2.version>
<ip-info.version>2.1.7</ip-info.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -106,28 +107,13 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<version>2.1.212</version>
</dependency>
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>${ip2region.version}</version>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>com.jthinking.common</groupId>
<artifactId>ip-info</artifactId>
<version>2.1.5</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.maxmind.geoip2</groupId>-->
<!-- <artifactId>geoip2</artifactId>-->
<!-- <version>2.15.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springdoc</groupId>-->
<!-- <artifactId>springdoc-openapi-ui</artifactId>-->
<!-- <version>1.6.8</version>-->
<!-- </dependency>-->
<version>${ip-info.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -170,7 +156,7 @@
<plugin>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc-maven-plugin</artifactId>
<version>2.3.7</version>
<version>2.6.2</version>
<configuration>
<configFile>./src/main/resources/smart-doc.json</configFile>
<projectName>MoLiApi</projectName>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/bingchunmoli/api/bean/ApiConstant.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bingchunmoli.api.bean;

/**
* Api常量
* @author BingChunMoLi
*/
public class ApiConstant {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/bingchunmoli/api/bean/MailMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Data;

/**
* Mail发送实体
* @author MoLi
*/
@Data
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/bingchunmoli/api/bean/ResultVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NoArgsConstructor;

/**
* 业务返回值包装
* @author bingchunmoli
*/
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.HttpStatus;

/**
* 不支持的http响应状态码枚举
* @author bingchunmoli
*/
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import lombok.Getter;

/**
* Profile环境枚举
* @author MoLi
*/

@Getter
@AllArgsConstructor
public enum ProfileEnum {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/bingchunmoli/api/bing/bean/BingImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
* 数据库bing图片实体
* @author bingchunmoli
*/
@Data
@TableName("bing_image")
@NoArgsConstructor
@AllArgsConstructor
public class BingImage implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
* bing接口实体
* @author BingChunMoLi
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
//@ApiModel(value = "Bing每日图片", description = "{\"images\":[{\"startdate\":\"20211007\",\"fullstartdate\":\"202110071600\",\"enddate\":\"20211008\",\"url\":\"/th?id=OHR.FriendlyOctopus_ZH-CN2519447724_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp\",\"urlbase\":\"/th?id=OHR.FriendlyOctopus_ZH-CN2519447724\",\"copyright\":\"海草中的章鱼,法国利翁湾 (© BIOSPHOTO/Alamy)\",\"copyrightlink\":\"https://www.bing.com/search?q=%E7%AB%A0%E9%B1%BC&form=hpcapt&mkt=zh-cn\",\"title\":\"\",\"quiz\":\"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20211007_FriendlyOctopus%22&FORM=HPQUIZ\",\"wp\":true,\"hsh\":\"2e4cdcc79efcd8dd814ce96c12f19125\",\"drk\":1,\"top\":1,\"bot\":1,\"hs\":[]}],\"tooltips\":{\"loading\":\"正在加载...\",\"previous\":\"上一个图像\",\"next\":\"下一个图像\",\"walle\":\"此图片不能下载用作壁纸。\",\"walls\":\"下载今日美图。仅限用作桌面壁纸。\"}}\n")
public class BingImageVO implements Serializable {
@Serial
private static final long serialVersionUID = 2L;
private List<BingImages> images;
private BingTooltips tooltips;
Expand All @@ -24,6 +26,7 @@ public class BingImageVO implements Serializable {
@NoArgsConstructor
@AllArgsConstructor
static class BingImages implements Serializable {
@Serial
private static final long serialVersionUID = 2L;
@JsonProperty("startdate")
private String startDate;
Expand Down Expand Up @@ -51,6 +54,7 @@ static class BingImages implements Serializable {
@NoArgsConstructor
@AllArgsConstructor
static class BingTooltips implements Serializable {
@Serial
private static final long serialVersionUID = 2L;
private String loading;
private String previous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;

/**
* BingRedis缓存Key枚举
* @author BingChunMoLi
*/
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.bingchunmoli.api.bing.bean.BingImage;
import com.bingchunmoli.api.bing.bean.BingImageVO;
import com.bingchunmoli.api.bing.bean.enums.BingEnum;
import com.bingchunmoli.api.bing.service.IBingService;
import com.bingchunmoli.api.bing.service.BingService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,10 +19,10 @@
@RequiredArgsConstructor
@RequestMapping("bing")
public class BingController {
private final IBingService bingService;
private final BingService bingService;

/**
* //@ApiNote 每日随机图国内版
* 每日随机图国内版
*
* @return bing图片对象|
*/
Expand All @@ -32,7 +32,7 @@ public ResultVO<BingImageVO> cnBingImage() {
}

/**
* //@ApiNote 每日随机图国际版
* 每日随机图国际版
*
* @return bing图片对象|
*/
Expand All @@ -42,7 +42,7 @@ public ResultVO<BingImageVO> enBingImage() {
}

/**
* //@ApiNote 每日随机图
* 每日随机图
*
* @return bing图片对象|
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @author BingChunMoLi
*/
public interface IBingService extends IService<BingImage> {
public interface BingService extends IService<BingImage> {
/**
* 获取bing图片
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.bingchunmoli.api.bing.bean.BingImageVO;
import com.bingchunmoli.api.bing.bean.enums.BingEnum;
import com.bingchunmoli.api.bing.mapper.BingImageMapper;
import com.bingchunmoli.api.bing.service.IBingService;
import com.bingchunmoli.api.bing.service.BingService;
import com.bingchunmoli.api.exception.ApiJsonProcessingException;
import com.bingchunmoli.api.utils.RedisUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -25,7 +25,7 @@
*/
@Service
@RequiredArgsConstructor
public class BingServiceImpl extends ServiceImpl<BingImageMapper, BingImage> implements IBingService {
public class BingServiceImpl extends ServiceImpl<BingImageMapper, BingImage> implements BingService {
private final ObjectMapper om;
private final RedisUtil redisUtil;

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/bingchunmoli/api/bing/task/BingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
import cn.hutool.core.date.DateUtil;
import com.bingchunmoli.api.bean.MailMessage;
import com.bingchunmoli.api.bing.bean.BingImage;
import com.bingchunmoli.api.bing.service.IBingService;
import com.bingchunmoli.api.bing.service.BingService;
import com.bingchunmoli.api.even.MailMessageEven;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
* 定时获取bing图片
* @author BingChunMoLi
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class BingTask {
private final RedisTemplate<String, Object> redisTemplate;
private final IBingService bingService;
private final BingService bingService;
private final ApplicationEventPublisher applicationEventPublisher;

@Retryable(value = Exception.class, backoff = @Backoff(delay = 5000L, multiplier = 3))
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/bingchunmoli/api/config/redis/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,4 @@ public RedisSerializer<Object> getRedisSerializer() {
serializer.setObjectMapper(om);
return serializer;
}

// @Bean
// public CacheManager cacheManager(RedisConnectionFactory factory) {
// RedisSerializer<String> redisSerializer = new StringRedisSerializer();
// 配置序列化(解决乱码的问题)
// RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
// 缓存有效期
// .entryTtl(Duration.ZERO)
// 使用StringRedisSerializer来序列化和反序列化redis的key值
// .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
// 使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
// .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer()))
// 禁用空值
// .disableCachingNullValues();
// return RedisCacheManager.builder(factory)
// .cacheDefaults(config)
// .build();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* 跨域设置
* @author BingChunMoLi
*/
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;

/**
* 图片转换器及拦截器注册
* @author bingchunmoli
**/
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Arrays;

/**
* 错误页面与错误信息处理
* 自定义错误页面与错误信息处理
* @author bingchunmoli
*/
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import com.bingchunmoli.api.bean.enums.CodeEnum;
import com.bingchunmoli.api.even.MailMessageEven;
import com.bingchunmoli.api.exception.ApiException;
import com.bingchunmoli.api.exception.ApiFileIsEmptyException;
import com.bingchunmoli.api.exception.ApiJsonProcessingException;
import com.bingchunmoli.api.exception.ApiParamException;
import com.bingchunmoli.api.interceptor.RequestTraceIdInterceptor;
import com.bingchunmoli.api.qrcode.exception.FileIsEmptyException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,8 +22,8 @@
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

/**
* 统一异常处理
* @author 冰彦糖
* @version 0.0.1-SNAPSHOT
**/
@Slf4j
@RestControllerAdvice
Expand All @@ -34,7 +35,7 @@ public class ExceptionControllerAdvice {
private final ObjectMapper om;

@ExceptionHandler
public ResultVO<String> fileIsEmptyException(FileIsEmptyException e) {
public ResultVO<String> fileIsEmptyException(ApiFileIsEmptyException e) {
log.error(getExceptionErrorLogMessage("文件为空,请确认文件是否存在"), e);
ResultVO<String> result = new ResultVO<>(CodeEnum.ERROR, getExceptionJsonMessage());
result.setMsg("文件为空,请确认文件是否存在");
Expand Down Expand Up @@ -62,6 +63,12 @@ public ResultVO<String> apiParamException(ApiParamException e) {
return new ResultVO<>(CodeEnum.ERROR, getExceptionJsonMessage());
}

@ExceptionHandler
public ResultVO<String> apiJsonProcessingException(ApiJsonProcessingException e) {
log.error(getExceptionErrorLogMessage("json转换错误(json格式化不正确)"), e);
return new ResultVO<>(CodeEnum.ERROR, getExceptionJsonMessage());
}

@ExceptionHandler
public ResultVO<String> jsonProcessingException(JsonProcessingException e){
log.error(getExceptionErrorLogMessage("json转换错误(json格式化不正确)"), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.awt.image.BufferedImage;

/**
* 统一响应处理
* @author bingchunmoli
**/
@RestControllerAdvice("com.bingchunmoli.api")
Expand Down
Loading

0 comments on commit 9d851fc

Please sign in to comment.