This commit is contained in:
APLS 2020-03-23 01:09:44 +08:00
parent 5281af66f3
commit d853ab365a
14 changed files with 81 additions and 36 deletions

View File

@ -2,10 +2,16 @@
e5续订
用到技术
spring boot
<br>
rabbitMq
<br>
Redis
<br>
Mysql
<br>
Mybatis Plus
<br>
Security
<br>
log4j2

View File

@ -52,7 +52,7 @@ public class AutoGenerator_ {
gc.setAuthor("落叶");
gc.setOpen(false);
// 是否覆盖
gc.setFileOverride(true);
gc.setFileOverride(false);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);

View File

@ -21,15 +21,16 @@ import java.util.UUID;
public class TestController {
@Autowired
RabbitTemplate rabbitTemplate;
@GetMapping("/send")
public void aaa(){
public void aaa() {
CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend("delay", "delay", "ttt", message -> {
MessageProperties messageProperties = message.getMessageProperties();
// 设置这条消息的过期时间
messageProperties.setExpiration("10000");
messageProperties.setExpiration("5000");
return message;
}, correlationData);
}

View File

@ -8,9 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
@ -48,9 +46,15 @@ public class WebController {
if (one != null) {
model.addAttribute("client_id", one.getClientId());
model.addAttribute("client_secret", one.getClientSecret());
model.addAttribute("cron_time", one.getCronTime());
model.addAttribute("cron_time_random_start", one.getCronTimeRandomStart());
model.addAttribute("cron_time_random_end", one.getCronTimeRandomEnd());
} else {
model.addAttribute("client_id", "");
model.addAttribute("client_secret", "");
model.addAttribute("cron_time", 0);
model.addAttribute("cron_time_random_start", 0);
model.addAttribute("cron_time_random_end", 0);
}
model.addAttribute("welcome", "hello fishpro");

View File

@ -3,7 +3,6 @@ package io.qyi.e5.outlook.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
import io.qyi.e5.outlook.entity.Outlook;
import io.qyi.e5.outlook.mapper.OutlookMapper;
import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.util.EncryptUtil;
import io.qyi.e5.util.redis.RedisUtil;
@ -30,9 +29,6 @@ public class AuthController {
@Autowired
RedisUtil redisUtil;
@Autowired
OutlookMapper outlookMapper;
@Autowired
IOutlookService outlookService;
@ -52,7 +48,7 @@ public class AuthController {
// 这里不应该查询在进行授权时因该把基础数据丢到redis
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
outlookQueryWrapper.eq("github_id", redisUtil.get(states + state));
Outlook outlook = outlookMapper.selectOne(outlookQueryWrapper);
Outlook outlook = outlookService.getOne(outlookQueryWrapper);
// 删除redis中的此键
redisUtil.del(states + state);
if (outlook == null) {
@ -77,7 +73,7 @@ public class AuthController {
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
outlookQueryWrapper.eq("github_id", authentication.getGithub_id());
Outlook outlook = outlookMapper.selectOne(outlookQueryWrapper);
Outlook outlook = outlookService.getOne(outlookQueryWrapper);
if (outlook != null) {
// 生成随机uuid标识用户

View File

@ -34,4 +34,13 @@ public class OutlookController {
}
return ResultUtil.error(ResultEnum.UNKNOWN_ERROR);
}
@PostMapping("/saveRandomTime")
public Result saveRandomTime(@RequestParam int cronTime,@RequestParam int crondomTime) {
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
if (outlookService.saveRandomTime(cronTime,0,0)) {
return ResultUtil.success();
}
return ResultUtil.error(ResultEnum.UNKNOWN_ERROR);
}
}

View File

@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
* </p>
*
* @author 落叶
* @since 2020-02-24
* @since 2020-03-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ -43,5 +43,20 @@ public class Outlook implements Serializable {
private String accessToken;
/**
* 刷新时间间隔
*/
private Integer cronTime;
/**
* 随机时间开始
*/
private Integer cronTimeRandomStart;
/**
* 随机时间结束
*/
private Integer cronTimeRandomEnd;
}

View File

@ -1,7 +1,7 @@
package io.qyi.e5.outlook.mapper;
import io.qyi.e5.outlook.entity.Outlook;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.qyi.e5.outlook.entity.Outlook;
/**
* <p>

View File

@ -1,7 +1,7 @@
package io.qyi.e5.outlook.service;
import io.qyi.e5.outlook.entity.Outlook;
import com.baomidou.mybatisplus.extension.service.IService;
import io.qyi.e5.outlook.entity.Outlook;
import java.util.List;
@ -19,6 +19,8 @@ public interface IOutlookService extends IService<Outlook> {
boolean save(String client_id,String client_secret,int github_id);
boolean saveRandomTime(int github_id,int cron_time,int cron_time_random_start,int cron_time_random_end);
boolean getMailList(Outlook outlook);
List<Outlook> findAll();

View File

@ -2,18 +2,15 @@ package io.qyi.e5.outlook.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.qyi.e5.github.entity.Github;
import io.qyi.e5.outlook.entity.Outlook;
import io.qyi.e5.outlook.mapper.OutlookMapper;
import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.outlook_log.service.IOutlookLogService;
import io.qyi.e5.util.netRequest.OkHttpClientUtil;
import io.qyi.e5.util.netRequest.OkHttpRequestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -110,6 +107,12 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
return false;
}
@Override
public boolean saveRandomTime(int github_id, int cron_time, int cron_time_random_start, int cron_time_random_end) {
return false;
}
@Override
public List<Outlook> findAll() {
return baseMapper.selectList(null);
@ -160,6 +163,7 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
}
// 刷新令牌同时更新数据库中的令牌
public String refresh_token(Outlook outlook) {
Map<String, Object> head = new HashMap<>();

View File

@ -2,13 +2,10 @@ package io.qyi.e5.outlook_log.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
import io.qyi.e5.outlook.entity.Outlook;
import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.outlook_log.entity.OutlookLog;
import io.qyi.e5.outlook_log.mapper.OutlookLogMapper;
import io.qyi.e5.outlook_log.service.IOutlookLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -20,10 +17,7 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* <p>

View File

@ -3,11 +3,13 @@ package io.qyi.e5.service.rabbitMQ.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import io.qyi.e5.outlook.service.IOutlookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
@ -22,20 +24,13 @@ import java.io.IOException;
public class ListenerImpl {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
IOutlookService outlookService;
@RabbitHandler
@RabbitListener(queues = "delay_queue2", containerFactory = "rabbitListenerContainerFactory")
public void listen(Message message, Channel channel) throws IOException {
try {
logger.info("消费者开始处理消息: {}" ,new String(message.getBody()));
// JSONObject data = JSON.parseObject(new String(message.getBody()));
// String token = data.getString("token");
logger.info("消费者1开始处理消息 {},时间戳:{}" ,new String(message.getBody()),System.currentTimeMillis());
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
logger.info("处理完成!");
} catch (IOException e) {
channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
e.printStackTrace();
}
}
}

View File

@ -44,6 +44,25 @@
<button id="findLog" class="mdui-btn mdui-color-theme-accent mdui-ripple">查询日志</button>
</div>
<#--时间设置-->
<div class="mdui-table-fluid table-container floats">
<div class="mdui-textfield">
<label class="mdui-textfield-label" style="font-weight: 500;">调用时间间隔</label>
<input id="client_secret" class="mdui-textfield-input" type="text" value="${cron_time!}"/>
</div>
<div class="mdui-textfield">
<label class="mdui-textfield-label" style="font-weight: 500;">随机时间范围</label>
<input id="client_secret" class="mdui-textfield-input" type="text"
value="${cron_time_random_start!}-${cron_time_random_end!}"/>
</div>
<ol>
<li>调用时间间隔,单位 秒。</li>
<li>随机时间范围格式“10-30”指的是 调用时间间隔+取范围中的一个值,进行调用。</li>
<li>调用时间间隔不得大于12小时也就是43200秒</li>
</ol>
<button id="save_random_time" class="mdui-btn mdui-color-theme-accent mdui-ripple">保存</button>
</div>
</body>
<script src="//www.mdui.org/source/dist/js/mdui.min.js"></script>
<script type="text/javascript">
@ -51,7 +70,7 @@
//日志查询
$("#findLog").click(function () {
var url = "/outlookLog/findLog"
window.open(url,'_blank')
window.open(url, '_blank')
})
// 授权
$("#authorization").click(function () {