Skip to content

Commit

Permalink
Merge pull request #23 from BingChunMoLi/develop
Browse files Browse the repository at this point in the history
feat(3.7.0): 新增邮件通知,更多的天气查询,查询地址
  • Loading branch information
BingChunMoLi authored May 15, 2022
2 parents 5ac0270 + 7d8b13b commit 14cf1af
Show file tree
Hide file tree
Showing 39 changed files with 15,885 additions and 94 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
7. 随机一言或制定
8. QQ头像获取(支持多种方式)
9. QQ空间头像获取(支持多种方式)
10. 天气查询
10. 天气查询
11. Hosts订阅
12. 随机图
13. 迅雷链接转换
40 changes: 29 additions & 11 deletions 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.5.0</version>
<version>3.7.0</version>
<name>MoLiApi</name>
<description>MoLiApi</description>

Expand All @@ -20,12 +20,13 @@
<mybatis-plus.version>3.5.1</mybatis-plus.version>
<swagger.version>3.0.0</swagger.version>
<knife4j.version>3.0.3</knife4j.version>
<fastjson.version>1.2.78</fastjson.version>
<fastjson.version>2.0.2</fastjson.version>
<docker-plugin.version>1.4.9</docker-plugin.version>
<aspectjweaver.version>1.9.7</aspectjweaver.version>
<hutool.version>5.7.17</hutool.version>
<zxing.version>3.4.1</zxing.version>
<aspectjweaver.version>1.9.9.1</aspectjweaver.version>
<hutool.version>5.7.22</hutool.version>
<zxing.version>3.5.0</zxing.version>
<emoji.version>5.1.1</emoji.version>
<ip2region.version>1.7.2</ip2region.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -114,14 +115,13 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.0</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.0</version>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>${ip2region.version}</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -162,6 +162,24 @@
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>com.github.shalousun</groupId>
<artifactId>smart-doc-maven-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<configFile>./src/main/resources/smart-doc.json</configFile>
<projectName>MoLiApi</projectName>
<includes>com.bingchunmoli</includes>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>html</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/bingchunmoli/api/bean/MailMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.bingchunmoli.api.bean;

import lombok.Builder;
import lombok.Data;

/**
* @author MoLi
*/
@Data
@Builder
public class MailMessage {
/**
* 来自
*/
private String from;
/**
* 发送至
*/
private String to;
/**
* 标题
*/
private String title;
/**
* 正文
*/
private String body;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.RestController;

/**
* bing每日美图
* @author BingChunMoLi
*/
@RestController
Expand All @@ -16,16 +17,28 @@
public class BingController {
private final IBingService bingService;

/**
* @apiNote 每日随机图国内版
* @return bing图片对象|
*/
@GetMapping("cn")
public BingImageVO cnBingImage() {
return bingService.getCnBingImage();
}

/**
* @apiNote 每日随机图国际版
* @return bing图片对象|
*/
@GetMapping("en")
public BingImageVO enBingImage() {
return bingService.getEnBingImage();
}

/**
* @apiNote 每日随机图
* @return bing图片对象|
*/
@GetMapping("all")
public Object getAllBingImage() {
return bingService.getAllBingImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ErrorController implements org.springframework.boot.web.servlet.err
ResourceLoader resourceLoader;

/**
* 有好错误返回页面
* 友好错误返回页面
* @param request 请求
* @param response 响应
* @return ModelAndView视图
Expand Down Expand Up @@ -69,6 +69,12 @@ public BufferedImage handleError(HttpServletRequest request, HttpServletResponse
}


/**
* 友好错误信息
* @param request 请求
* @param response 响应
* @return ResultVO<String>
*/
@RequestMapping(value = "/error", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResultVO<Object> handleErrorBody(HttpServletRequest request, HttpServletResponse response){
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Boolean containsEmoji(String emoji) {
}

/**
* 通过tag方式获取对应的所有Emoji表情
* @apiNote 通过tag方式获取对应的所有Emoji表情
*
* @param tag tag标签,例如“happy”
* @return Emoji表情集合,如果找不到返回null
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/bingchunmoli/api/even/MailMessageEven.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bingchunmoli.api.even;

import com.bingchunmoli.api.bean.MailMessage;
import org.springframework.context.ApplicationEvent;

/**
* @author MoLi
*/
public class MailMessageEven extends ApplicationEvent {
public MailMessageEven(MailMessage mailMessage) {
super(mailMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;

/**
* hosts订阅
* @author BingChunMoLi
*/

Expand All @@ -25,8 +26,8 @@ public class HostController {
private final IHostService hostService;

/**
* 暂有问题
* @param type 请求类型
* 根据参数获取hosts
* @param type 请求类型|0
* @return json的Host序列化
*/
@GetMapping("json")
Expand All @@ -36,7 +37,7 @@ public String getHosts(@RequestParam(defaultValue = "0") ArrayList<Integer> type

/**
* raw的host
* @param type 请求类型
* @param type 请求类型|0
* @param response servlet响应
* @throws IOException response返回可能引发异常
*/
Expand All @@ -46,6 +47,12 @@ public void getRaw(@RequestParam(defaultValue="0") ArrayList<Integer> type, Http
response.getOutputStream().print(hostService.getHosts(type));
}

/**
* 下载文件的hosts
* @param type 请求了行|0
* @param response servlet响应
* @throws IOException esponse返回可能引发异常
*/
@GetMapping("file")
public void getFile(@RequestParam(defaultValue = "0") ArrayList<Integer> type, HttpServletResponse response) throws IOException {
response.setHeader("Content-Disposition", "attachment;fileName=hosts");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.awt.image.BufferedImage;

/**
* 随机图
* @author BingChunMoLi
*/
@RestController
Expand All @@ -22,21 +23,28 @@ public class ImgController {

private final IImgService imgService;

@GetMapping("json")
public String randomImgUrl() {
return "http://test";
}

/**
* 手机版
* @return BufferedImage|图片
*/
@GetMapping(value = "mobile", produces = MediaType.IMAGE_JPEG_VALUE)
public BufferedImage randomImgByMobile() {
return imgService.getRandomImageMobile();
}

/**
* pc图片 使用ResponseEntity写出
* @return ResponseEntity<FileSystemResource>|ResponseEntity<FileSystemResource>
*/
@GetMapping(value = "pc",produces = MediaType.IMAGE_JPEG_VALUE)
public ResponseEntity<FileSystemResource> randomImgByPc1(){
return ResponseEntity.ok(new FileSystemResource(imgService.getRandomImgByRedis(ApiConstant.PC_IMG)));
}

/**
* pc图片 备用写法,使用BufferedImage对象写出
* @return BufferedImage|图片
*/
@GetMapping(value = "pc1", produces = MediaType.IMAGE_JPEG_VALUE)
public BufferedImage randomImgByPc() {
return imgService.getRandomImageByPc();
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/com/bingchunmoli/api/img/task/ImgTask.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.bingchunmoli.api.img.task;

import com.bingchunmoli.api.bean.ApiConstant;
import com.bingchunmoli.api.bean.MailMessage;
import com.bingchunmoli.api.even.MailMessageEven;
import com.bingchunmoli.api.img.service.IImgService;
import com.bingchunmoli.api.properties.ApiKeyProperties;
import com.bingchunmoli.api.utils.SendMailUtil;
import com.bingchunmoli.api.utils.ServerSauce;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
Expand All @@ -23,6 +27,8 @@ public class ImgTask {
private final IImgService imgService;
private final ServerSauce serverSauce;
private final RedisTemplate<String, Object> redisTemplate;
private final SendMailUtil sendMailUtil;
private final ApplicationEventPublisher applicationEventPublisher;

@Scheduled(cron = "0 0 0 1 * ?")
public void saveImg() {
Expand All @@ -33,19 +39,22 @@ public void saveImg() {
} catch (IOException e) {
e.printStackTrace();
serverSauce.send("pc定时任务失败", "异常信息: " + e.getMessage() + " ");
applicationEventPublisher.publishEvent(new MailMessageEven(MailMessage.builder().title("pc定时任务失败").body("异常信息: " + e.getMessage() + " ").build()));
}
try {
mobilePath = imgService.getImgListByFileSystem(apiKeyProperties.getMobilePath());
} catch (IOException e) {
e.printStackTrace();
serverSauce.send("mobile定时任务失败", "异常信息: " + e.getMessage() + " ");
applicationEventPublisher.publishEvent(new MailMessageEven(MailMessage.builder().title("mobile定时任务失败").body("异常信息: " + e.getMessage() + " ").build()));
}
assert pcPath != null;
assert mobilePath != null;
redisTemplate.opsForList().trim(ApiConstant.PC_IMG, -2, -1);
redisTemplate.opsForList().leftPushAll(ApiConstant.PC_IMG, pcPath.stream().map(Path::toString).toArray());
redisTemplate.opsForList().trim(ApiConstant.MOBILE_IMG, -1,-2);
redisTemplate.opsForList().leftPushAll(ApiConstant.MOBILE_IMG, mobilePath.stream().map(Path::toString).toArray());
redisTemplate.opsForList().trim(ApiConstant.PC_IMG, - 2, - 1);
redisTemplate.opsForList().leftPushAll(ApiConstant.PC_IMG, pcPath.stream().map(Path :: toString).toArray());
redisTemplate.opsForList().trim(ApiConstant.MOBILE_IMG, - 1, - 2);
redisTemplate.opsForList().leftPushAll(ApiConstant.MOBILE_IMG, mobilePath.stream().map(Path :: toString).toArray());
serverSauce.send("随机图定时任务 更新成功", "更新PC图片:" + pcPath.size() + " 更新移动图片:" + mobilePath.size());
applicationEventPublisher.publishEvent(new MailMessageEven(MailMessage.builder().title("随机图定时任务 更新成功").body("更新PC图片:" + pcPath.size() + " 更新移动图片:" + mobilePath.size()).build()));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.bingchunmoli.api.init;

import com.bingchunmoli.api.bean.ApiConstant;
import com.bingchunmoli.api.bean.MailMessage;
import com.bingchunmoli.api.bean.enums.ProfileEnum;
import com.bingchunmoli.api.even.MailMessageEven;
import com.bingchunmoli.api.img.task.ImgTask;
import com.bingchunmoli.api.shici.service.IShiCiService;
import com.bingchunmoli.api.yiyan.service.IYiYanService;
Expand All @@ -10,10 +12,13 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
* @author BingChunMoLi
*/
Expand All @@ -27,32 +32,23 @@ public class RedisCommandLineRunner implements CommandLineRunner {
private final IShiCiService shiCiService;
private final RedisTemplate<String, Object> redisTemplate;
private final ImgTask imgTask;
private final ApplicationEventPublisher applicationEventPublisher;
@Value("${spring.profiles.active}")
String profile;

@Override
public void run(String... args) {
Long yiYanLen = redisTemplate.opsForList().size(ApiConstant.YI_YAN);
if (yiYanLen == null || yiYanLen == 0) {
log.info("yiYan数据初始化中");
redisTemplate.opsForList().leftPushAll(ApiConstant.YI_YAN, yiYanService.list().toArray());
log.info("yiYan初始化完成");
} else {
log.info("yiYan数据不需要初始化");
}
Long shiCiLen = redisTemplate.opsForList().size(ApiConstant.SHI_CI);
if (shiCiLen == null || shiCiLen == 0) {
log.info("shiCi数据初始化中");
redisTemplate.opsForList().leftPushAll(ApiConstant.SHI_CI, shiCiService.list().toArray());
log.info("shiCi初始化完成");
} else {
log.info("shiCi数据不需要初始化");
}
if (ProfileEnum.DEV.getProfile().equalsIgnoreCase(profile)) {
log.info("dev环境,不初始化随即图");
}else {
if (! ProfileEnum.DEV.getProfile().equalsIgnoreCase(profile)) {
imgTask.saveImg();
log.info("随机图初始化完成");
}
applicationEventPublisher.publishEvent(new MailMessageEven(MailMessage.builder().title("系统初始化完成").body("系统初始化完成, 初始化当前时间:" + LocalDateTime.now()).build()));
}
}
Loading

0 comments on commit 14cf1af

Please sign in to comment.