多用户第一个版本

This commit is contained in:
APLS 2020-12-20 00:21:50 +08:00
parent 7ba2e24e32
commit c7f02347f9
8 changed files with 185 additions and 10 deletions

View File

@ -20,7 +20,7 @@ public class OutlookListVo {
/*描述*/ /*描述*/
private String describes; private String describes;
/*下次调用时间*/ /*下次调用时间*/
private long nextTime; private Integer nextTime;
/*运行状态*/ /*运行状态*/
private int status; private int status;
} }

View File

@ -134,7 +134,7 @@ public class OutlookController {
return ResultUtil.success(vo); return ResultUtil.success(vo);
} }
/** /**
* 设置状态暂停状态 * 设置暂停状态
* @title setPause * @title setPause
* @description * @description
* @author 落叶随风 * @author 落叶随风
@ -149,11 +149,27 @@ public class OutlookController {
outlookService.setPause(authentication.getGithub_id(),id); outlookService.setPause(authentication.getGithub_id(),id);
return ResultUtil.success(); return ResultUtil.success();
} }
/**
* 设置运行状态
* @title setPause
* @description
* @author 落叶随风
* @param: id outlook id
* @updateTime 2020/12/13 19:24
* @return: io.qyi.e5.bean.result.Result
* @throws
*/
@GetMapping("/setStart") @GetMapping("/setStart")
public Result setStart(@RequestParam int id) { public Result setStart(@RequestParam int id) {
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
outlookService.setStart(authentication.getGithub_id(),id); outlookService.setStart(authentication.getGithub_id(),id);
return ResultUtil.success(); return ResultUtil.success();
} }
@GetMapping("/delete")
public Result delete(@RequestParam int id) {
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
outlookService.delete(authentication.getGithub_id(),id);
return ResultUtil.success();
}
} }

View File

@ -73,4 +73,7 @@ public class Outlook implements Serializable {
*/ */
private Integer status; private Integer status;
/*下次调用时间*/
private Integer nextTime;
} }

View File

@ -34,4 +34,20 @@ public interface IOutlookService extends IService<Outlook> {
void setPause(int github_id, int outlookId); void setPause(int github_id, int outlookId);
void setStart(int github_id, int outlookId); void setStart(int github_id, int outlookId);
/**
* 更新数据
*
* @param github_id: github_id
* @param outlookId: outlookId
* @param outlook: 更新的数据
* @Author: 落叶随风
* @Date: 2020/12/19 21:29
* @Return: * @return: void
*/
void update(int github_id, int outlookId, Outlook outlook);
void delete(int github_id, int outlookId);
boolean isStatusRun(int github_id, int outlookId);
} }

View File

@ -14,13 +14,14 @@ import io.qyi.e5.outlook.entity.Outlook;
import io.qyi.e5.outlook.mapper.OutlookMapper; import io.qyi.e5.outlook.mapper.OutlookMapper;
import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.util.netRequest.*; import io.qyi.e5.util.netRequest.*;
import io.qyi.e5.util.redis.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -42,6 +43,8 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
@Value("${outlook.errorMsg}") @Value("${outlook.errorMsg}")
private String[] errorMsg; private String[] errorMsg;
@Autowired
RedisUtil redisUtil;
// 2020-03-2 10:38 这里需要进行查询判断数据库是否有内容再进行插入 // 2020-03-2 10:38 这里需要进行查询判断数据库是否有内容再进行插入
@Override @Override
@ -69,6 +72,8 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
Outlook outlook = new Outlook(); Outlook outlook = new Outlook();
outlook.setAccessToken(access_token) outlook.setAccessToken(access_token)
.setRefreshToken(refresh_token) .setRefreshToken(refresh_token)
.setStatus(3)
.setIdToken(id_token); .setIdToken(id_token);
UpdateWrapper<Outlook> outlookUpdateWrapper = new UpdateWrapper<>(); UpdateWrapper<Outlook> outlookUpdateWrapper = new UpdateWrapper<>();
outlookUpdateWrapper.eq("client_id", client_id); outlookUpdateWrapper.eq("client_id", client_id);
@ -77,6 +82,15 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
} }
} }
/*
*
* @param name: 插入一条新列表
* @param describe: 描述
* @param github_id: github_id
* @Author: 落叶随风
* @Date: 2020/12/19 21:25
* @Return: * @return: io.qyi.e5.outlook.entity.Outlook
*/
@Override @Override
public Outlook insertOne(String name, String describe, int github_id) { public Outlook insertOne(String name, String describe, int github_id) {
if (StringUtils.isBlank(name)) { if (StringUtils.isBlank(name)) {
@ -92,7 +106,16 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
} }
return outlook; return outlook;
} }
/*
* 保存key
* @param client_id:
* @param client_secret:
* @param outlook_id:
* @param github_id:
* @Author: 落叶随风
* @Date: 2020/12/19 21:24
* @Return: * @return: boolean
*/
@Override @Override
public boolean save(String client_id, String client_secret, int outlook_id, int github_id) { public boolean save(String client_id, String client_secret, int outlook_id, int github_id) {
if (github_id == 0) { if (github_id == 0) {
@ -124,7 +147,17 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
} }
return true; return true;
} }
/*
* 保存随机调用时间
* @param github_id: github_id
* @param cron_time: cron_time
* @param outlook_id: outlook_id
* @param cron_time_random_start: 开始时间
* @param cron_time_random_end: 结束时间
* @Author: 落叶随风
* @Date: 2020/12/19 21:24
* @Return: * @return: boolean
*/
@Override @Override
public boolean saveRandomTime(int github_id, int cron_time, int outlook_id, int cron_time_random_start, int cron_time_random_end) { public boolean saveRandomTime(int github_id, int cron_time, int outlook_id, int cron_time_random_start, int cron_time_random_end) {
if (github_id == 0 || outlook_id == 0) { if (github_id == 0 || outlook_id == 0) {
@ -147,7 +180,12 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
} }
return false; return false;
} }
/*
* 查询所有列表
* @Author: 落叶随风
* @Date: 2020/12/19 21:23
* @Return: * @return: java.util.List<io.qyi.e5.outlook.entity.Outlook>
*/
@Override @Override
public List<Outlook> findAll() { public List<Outlook> findAll() {
return baseMapper.selectList(null); return baseMapper.selectList(null);
@ -169,6 +207,13 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
return baseMapper.delete(outlookQueryWrapper); return baseMapper.delete(outlookQueryWrapper);
} }
/*
* 调用邮件列表
* @param outlook:
* @Author: 落叶随风
* @Date: 2020/12/19 21:22
* @Return: * @return: int
*/
@Override @Override
public int getMailList(Outlook outlook) throws Exception { public int getMailList(Outlook outlook) throws Exception {
String s = MailList(outlook.getAccessToken()); String s = MailList(outlook.getAccessToken());
@ -237,6 +282,15 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
return count; return count;
} }
/**
* @title 获取邮件列表默认5封
* @description
* @author 落叶随风
* @param: access_token
* @updateTime 2020/12/19 21:17
* @return: java.lang.String
* @throws
*/
public String MailList(String access_token) throws Exception { public String MailList(String access_token) throws Exception {
Map<String, String> head = new HashMap<>(); Map<String, String> head = new HashMap<>();
head.put("Content-Type", "application/json"); head.put("Content-Type", "application/json");
@ -297,12 +351,32 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
return false; return false;
} }
/**
* @title 获取本账号下的outlook 应用列表
* @description
* @author 落叶随风
* @param: github_id
* @updateTime 2020/12/19 21:16
* @return: java.util.List<io.qyi.e5.outlook.entity.Outlook>
* @throws
*/
@Override @Override
public List<Outlook> getOutlooklist(int github_id) { public List<Outlook> getOutlooklist(int github_id) {
QueryWrapper<Outlook> qw = new QueryWrapper<Outlook>().eq("github_id", github_id); QueryWrapper<Outlook> qw = new QueryWrapper<Outlook>().eq("github_id", github_id);
List<Outlook> outlooks = baseMapper.selectList(qw); List<Outlook> outlooks = baseMapper.selectList(qw);
return outlooks; return outlooks;
} }
/**
* 设置暂停状态
* @title setPause
* @description
* @author 落叶随风
* @param: github_id
* @param: outlookId
* @updateTime 2020/12/19 21:16
* @throws
*/
@Override @Override
public void setPause(int github_id, int outlookId) { public void setPause(int github_id, int outlookId) {
UpdateWrapper<Outlook> up = new UpdateWrapper<>(); UpdateWrapper<Outlook> up = new UpdateWrapper<>();
@ -312,7 +386,7 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
throw new APIException("查无此记录!"); throw new APIException("查无此记录!");
} }
/*只允许运行状态的应用设置暂停*/ /*只允许运行状态的应用设置暂停*/
if (outlook.getStatus() != 2) { if (outlook.getStatus() != 3) {
throw new APIException("只允许 运行状态 的应用设置暂停!"); throw new APIException("只允许 运行状态 的应用设置暂停!");
} }
if (baseMapper.update(new Outlook().setStatus(2), up) != 1) { if (baseMapper.update(new Outlook().setStatus(2), up) != 1) {
@ -320,6 +394,16 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
} }
} }
/**
* 设置开始状态
* @title setStart
* @description
* @author 落叶随风
* @param: github_id
* @param: outlookId
* @updateTime 2020/12/19 21:16
* @throws
*/
@Override @Override
public void setStart(int github_id, int outlookId) { public void setStart(int github_id, int outlookId) {
UpdateWrapper<Outlook> up = new UpdateWrapper<>(); UpdateWrapper<Outlook> up = new UpdateWrapper<>();
@ -328,5 +412,45 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
throw new APIException("更新失败!"); throw new APIException("更新失败!");
} }
} }
/**
* 更新数据
* @param github_id: github_id
* @param outlookId: outlookId
* @param outlook: 更新的数据
* @Author: 落叶随风
* @Date: 2020/12/19 21:29
* @Return: * @return: void
*/
@Override
public void update(int github_id, int outlookId, Outlook outlook) {
UpdateWrapper<Outlook> uw = new UpdateWrapper<>();
uw.eq("id", outlookId);
uw.eq("github_id", github_id);
baseMapper.update(outlook, uw);
}
@Override
public void delete(int github_id, int outlookId) {
QueryWrapper<Outlook> wp = new QueryWrapper<>();
wp.eq("github_id", github_id);
wp.eq("id", outlookId);
if (baseMapper.delete(wp) != 1) {
log.error("删除数据失败! github_id:{github_id} - outlookId:{outlookId}");
throw new APIException("删除失败!");
}
}
@Override
public boolean isStatusRun(int github_id, int outlookId){
QueryWrapper<Outlook> wp = new QueryWrapper<>();
wp.eq("github_id", github_id);
wp.eq("id", outlookId);
Outlook outlook = baseMapper.selectOne(wp);
if (outlook != null) {
if (outlook.getStatus() == 3) {
return true;
}
}
return false;
}
} }

View File

@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import io.qyi.e5.outlook.bean.OutlookMq; import io.qyi.e5.outlook.bean.OutlookMq;
import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.outlook_log.service.IOutlookLogService;
import io.qyi.e5.service.task.ITask; import io.qyi.e5.service.task.ITask;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -30,6 +31,8 @@ public class ListenerImpl {
IOutlookService outlookService; IOutlookService outlookService;
@Autowired @Autowired
ITask Task; ITask Task;
@Autowired
IOutlookLogService outlookLogService;
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@ -42,7 +45,13 @@ public class ListenerImpl {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
/*再次进行添加任务*/ /*再次进行添加任务*/
if (b) { if (b) {
if (outlookService.isStatusRun(mq.getGithubId(), mq.getOutlookId())) {
Task.sendTaskOutlookMQ(mq.getGithubId(), mq.getOutlookId()); Task.sendTaskOutlookMQ(mq.getGithubId(), mq.getOutlookId());
} else {
outlookLogService.addLog(mq.getGithubId(), mq.getOutlookId(), "error", 0, "检测到手动设置了运行状态,停止调用!");
}
} else {
outlookLogService.addLog(mq.getGithubId(), mq.getOutlookId(), "error", 0, "执行失败,结束调用!");
} }
} }
} }

View File

@ -59,8 +59,11 @@ public class TaskImpl implements ITask {
/*将此用户信息加入redis如果存在则代表在队列中同时提前10秒过期*/ /*将此用户信息加入redis如果存在则代表在队列中同时提前10秒过期*/
String rsKey = "user.mq:" + github_id + ".outlookId:" + outlookId; String rsKey = "user.mq:" + github_id + ".outlookId:" + outlookId;
if (!redisUtil.hasKey(rsKey)) { if (!redisUtil.hasKey(rsKey)) {
redisUtil.set(rsKey, 0, Expiration - 10); redisUtil.set(rsKey, (System.currentTimeMillis() / 1000) + Expiration, Expiration - 10);
OutlookMq mq = new OutlookMq(github_id, outlookId); OutlookMq mq = new OutlookMq(github_id, outlookId);
Outlook ol = new Outlook();
ol.setNextTime((int) ((System.currentTimeMillis() / 1000) + Expiration));
outlookService.update(github_id,outlookId,ol);
send(mq, Expiration * 1000); send(mq, Expiration * 1000);
} else { } else {
logger.info("Key 存在,不执行{}",rsKey); logger.info("Key 存在,不执行{}",rsKey);
@ -111,6 +114,10 @@ public class TaskImpl implements ITask {
if (error_count >= errorCountMax) { if (error_count >= errorCountMax) {
outlookLogService.addLog(github_id, outlookId,"error", 0, e.getMessage()); outlookLogService.addLog(github_id, outlookId,"error", 0, e.getMessage());
outlookLogService.addLog(github_id, outlookId,"error", 0, "检测到3次连续错误下次将不再自动调用请修正错误后再授权开启续订。"); outlookLogService.addLog(github_id, outlookId,"error", 0, "检测到3次连续错误下次将不再自动调用请修正错误后再授权开启续订。");
/*设置状态为停止*/
Outlook outlook = new Outlook();
outlook.setStatus(5);
outlookService.update(github_id,outlookId,outlook);
isExecuteE5 = false; isExecuteE5 = false;
} else { } else {
redisUtil.incr(errorKey, 1); redisUtil.incr(errorKey, 1);

View File

@ -1 +1 @@
spring.profiles.active=online spring.profiles.active=dev