Skip to content

Commit

Permalink
Merge pull request #19 from BingChunMoLi/develop
Browse files Browse the repository at this point in the history
refactor(v3.3.5): DI方式改变,修改前端文档
  • Loading branch information
BingChunMoLi authored Dec 18, 2021
2 parents d45669c + 12238b6 commit 386963e
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 105 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.bingchunmoli</groupId>
<artifactId>moliapi</artifactId>
<version>3.3.4</version>
<version>3.3.5</version>
<name>MoLiApi</name>
<description>MoLiApi</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public Object getAllBingImage() {
return bingService.getAllBingImage();
}

@GetMapping("task")
/**
* 执行定时任务补充需要
* @return 已执行
* // @GetMapping("task")
*/
public String invokeBingTask() {
bingTask.getBingImage();
return "已执行";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import com.bingchunmoli.api.bing.bean.enums.BingEnum;
import com.bingchunmoli.api.bing.mapper.BingImageMapper;
import com.bingchunmoli.api.bing.service.IBingService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
* @author BingChunMoLi
*/
@Service
@RequiredArgsConstructor
public class BingServiceImpl extends ServiceImpl<BingImageMapper, BingImage> implements IBingService {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
private final RedisTemplate<String, Object> redisTemplate;

@Override
public BingImage getAllBingImage() {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/bingchunmoli/api/bing/task/BingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.bingchunmoli.api.bing.bean.BingImageVO;
import com.bingchunmoli.api.bing.bean.enums.BingEnum;
import com.bingchunmoli.api.bing.service.IBingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
Expand All @@ -23,12 +23,10 @@
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class BingTask {

@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private IBingService bingService;
private final RedisTemplate<String, Object> redisTemplate;
private final IBingService bingService;

@Retryable(value = Exception.class, backoff = @Backoff(delay = 5000L, multiplier = 3))
@Scheduled(cron = "0 0 0 * * ?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.bingchunmoli.api.bean.ApiConstant;
import com.bingchunmoli.api.shici.service.IShiCiService;
import com.bingchunmoli.api.yiyan.service.IYiYanService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.data.redis.core.RedisTemplate;
Expand All @@ -15,15 +15,12 @@
*/
@Slf4j
@Component
@RequiredArgsConstructor
@ConditionalOnBean(value = {IYiYanService.class, IShiCiService.class, RedisTemplate.class})
public class RedisCommandLineRunner implements CommandLineRunner {

@Autowired
IYiYanService yiYanService;
@Autowired
IShiCiService shiCiService;
@Autowired
RedisTemplate<String, Object> redisTemplate;
private final IYiYanService yiYanService;
private final IShiCiService shiCiService;
private final RedisTemplate<String, Object> redisTemplate;

@Override
public void run(String... args) {
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/com/bingchunmoli/api/ip/controller/IpController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,7 @@
*/
@RestController
public class IpController {
private final String UNKNOWN = "UNKNOWN";

@GetMapping("ip")
public String getIp(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip != null && ip.length() != 0 && ! UNKNOWN.equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个ip值,第一个ip才是真实ip
if (ip.contains(",")) {
ip = ip.split(",")[0];
}
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}

@GetMapping("ip2")
public String ip(HttpServletRequest request) {
return ServletUtil.getClientIP(request, (String[]) null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.bingchunmoli.api.bean.ApiConstant;
import com.bingchunmoli.api.shici.service.IShiCiService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -19,13 +19,11 @@
* @since 2020-11-11
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("shici")
public class ShiCiController {
@Autowired
IShiCiService shiCiService;

@Autowired
RedisTemplate<String, Object> redisTemplate;
private final IShiCiService shiCiService;
private final RedisTemplate<String, Object> redisTemplate;


@GetMapping("{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.bingchunmoli.api.shici.bean.ShiCi;
import com.bingchunmoli.api.shici.mapper.ShiCiMapper;
import com.bingchunmoli.api.shici.service.IShiCiService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

Expand All @@ -22,11 +22,10 @@
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ShiCiServiceImpl extends ServiceImpl<ShiCiMapper, ShiCi> implements IShiCiService {
@Autowired
private ShiCiMapper shiCiMapper;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
private final ShiCiMapper shiCiMapper;
private final RedisTemplate<String, Object> redisTemplate;

@Override
public Object findRandomShiCi() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import com.bingchunmoli.api.tencent.bean.enums.QZSizeEnum;
import com.bingchunmoli.api.tencent.service.IQqService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
Expand All @@ -22,10 +22,10 @@
**/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("tencent")
public class QqController {
@Resource
private IQqService qqService;
private final IQqService qqService;

@ApiOperation("返回QQ头像")
@GetMapping(value = "qq", produces = MediaType.IMAGE_JPEG_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

import com.bingchunmoli.api.bean.ApiConstant;
import com.bingchunmoli.api.yiyan.service.IYiYanService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
* @author BingChunMoLi
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("yiyan")
public class YiYanController {

@Autowired
private IYiYanService yiyanService;

@Autowired
private RedisTemplate<String, Object> redisTemplate;
private final IYiYanService yiYanService;
private final RedisTemplate<String, Object> redisTemplate;

@GetMapping("{id}")
public Object getYiYan(@PathVariable Integer id) {
Object yiYan = redisTemplate.opsForList().index(ApiConstant.YI_YAN, id);
if (yiYan == null) {
return yiyanService.getById(id);
return yiYanService.getById(id);
}
return yiYan;
}
Expand All @@ -36,6 +33,6 @@ public Object getYiYan(@PathVariable Integer id) {
@GetMapping("random")
@CrossOrigin
public Object getRandomYiYan() {
return yiyanService.findRandomYiYan();
return yiYanService.findRandomYiYan();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.bingchunmoli.api.yiyan.bean.YiYan;
import com.bingchunmoli.api.yiyan.mapper.YiYanMapper;
import com.bingchunmoli.api.yiyan.service.IYiYanService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

Expand All @@ -15,13 +15,10 @@
* @author BingChunMoLi
*/
@Service
@RequiredArgsConstructor
public class YiYanServiceImpl extends ServiceImpl<YiYanMapper, YiYan> implements IYiYanService {

@Autowired
YiYanMapper yiYanMapper;

@Autowired
RedisTemplate<String, Object> redisTemplate;
private final YiYanMapper yiYanMapper;
private final RedisTemplate<String, Object> redisTemplate;

@Override
public Object findRandomYiYan() {
Expand Down
17 changes: 5 additions & 12 deletions src/main/resources/static/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
<!--
* @Author: 冰彦糖
* @Date: 2020-11-07 00:16:41
* @LastEditTime: 2020-11-28 20:57:23
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \undefinedd:\Github\JAVA\api\docs\README.md
-->

# emm,说点什么好呢?无话可说可还行..

这是一个简单的API

## 接口说明

目前仅支持https://api.bingchunmoli.com 并且使用了HSTS,不过加入了 HSTS Preload List
目前仅支持https://api.bingchunmoli.com 并且使用了HSTS, 并且加入了 HSTS Preload List

## swagger接口文档

[https://api.bingchunmoli.com/doc.html](https://api.bingchunmoli.com/doc.html)

注: 此网站支持PWA

44 changes: 32 additions & 12 deletions src/main/resources/static/tencent.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
<!--
* @Author: 冰彦糖
* @Date: 2020-11-28 14:23:15
* @LastEditTime: 2020-11-28 20:52:14
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \static\tencent\QQ头像.md
-->

## <span id="QQ头像">QQ头像</spsn>

> https://api.bingchunmoli.com/tencent/qq
Expand Down Expand Up @@ -60,7 +51,30 @@ https://api.bingchunmoli.com/tencent/qq/json?qq=3239720020

### <span id="QQ头像加密版">QQ头像加密版</spsn>

> https://api.bingchunmoli.com/tencent/qq/encrpt
> https://api.bingchunmoli.com/tencent/qq/encrypt
请求方式: Get

请求参数: qq,size

名称|类型|是否必须|描述
:-:|:-:|:-:|:-:
qq|number(Intger)|是|QQ账号 size|number(Intger)|否|图片大小,默认值140 限定可选值(仅支持):

名称|值|描述
:-:|:-:|:-:
size|40|40*40px size|100|100*100px size|140|140*140px size|160|160*160px size|640|640*640px

请求示例:
https://api.bingchunmoli.com/tencent/encrypt?qq=3239720020

成功返回示例:
![成功返回QQ头像加密版](https://api.bingchunmoli.com/tencent/qq/encrypt?qq=3239720020)


### <span id="QQ头像加密版">QQ头像加密版-JSON</spsn>

> https://api.bingchunmoli.com/tencent/qq/json/encrypt
请求方式: Get

Expand All @@ -75,10 +89,16 @@ qq|number(Intger)|是|QQ账号 size|number(Intger)|否|图片大小,默认值140
size|40|40*40px size|100|100*100px size|140|140*140px size|160|160*160px size|640|640*640px

请求示例:
https://api.bingchunmoli.com/tencent/encrpt?qq=3239720020
https://api.bingchunmoli.com/tencent/qq/json/encrypt?qq=3239720020

成功返回示例:
![成功返回QQ头像加密版](https://api.bingchunmoli.com/tencent/encrpt?qq=3239720020)
```json
{
"code": "00000",
"msg": "一切OK",
"data": "https://thirdqq.qlogo.cn/g?b=sdk&k=7PImib6cWLxKdWGiaUjLGtRg&s=140&t=1581145018"
}
```

## <span id="QQ空间头像">QQ空间头像</spsn>

Expand Down

0 comments on commit 386963e

Please sign in to comment.