mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 03:38:53 +00:00
~
This commit is contained in:
parent
23d8501ee4
commit
06b57d758d
@ -3,6 +3,8 @@ package io.qyi.e5.outlook.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.qyi.e5.bean.result.Result;
|
||||
import io.qyi.e5.bean.result.ResultEnum;
|
||||
import io.qyi.e5.config.ResultVO;
|
||||
import io.qyi.e5.config.exception.APIException;
|
||||
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
|
||||
import io.qyi.e5.outlook.entity.Outlook;
|
||||
import io.qyi.e5.outlook.service.IOutlookService;
|
||||
@ -49,7 +51,7 @@ public class AuthController {
|
||||
@RequestMapping("/receive")
|
||||
public Result Receive(String code, String state, String session_state) throws Exception {
|
||||
if (!redisUtil.hasKey(states + state)) {
|
||||
return ResultUtil.error(-1, "state已过期,请到用户中心重新授权!");
|
||||
throw new APIException("state已过期,请到用户中心重新授权!");
|
||||
}
|
||||
/*这里不应该查询,在进行授权时因该把基础数据丢到redis*/
|
||||
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
|
||||
@ -58,13 +60,13 @@ public class AuthController {
|
||||
/*删除redis中的此键*/
|
||||
redisUtil.del(states + state);
|
||||
if (outlook == null) {
|
||||
return ResultUtil.error(-2, "没有查询到此用户,请检查是否在系统中注册!");
|
||||
throw new APIException("没有查询到此用户,请检查是否在系统中注册!");
|
||||
}
|
||||
System.out.println(outlook);
|
||||
boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), "https://e5.qyi.io/outlook/auth2/receive"
|
||||
, "authorization_code");
|
||||
if (!authorization_code) {
|
||||
return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!");
|
||||
throw new APIException("clientId 或 clientSecret 填写错误!授权失败!");
|
||||
}
|
||||
/*添加此用户进消息队列*/
|
||||
Task.sendTaskOutlookMQ(outlook.getGithubId());
|
||||
@ -72,16 +74,17 @@ public class AuthController {
|
||||
}
|
||||
|
||||
@RequestMapping("/getAuthorizeUrl")
|
||||
public Result getAuthorizeUrl() {
|
||||
public Result getAuthorizeUrl(int id) {
|
||||
// 查询此用户的github_id与
|
||||
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
outlookQueryWrapper.eq("github_id", authentication.getGithub_id());
|
||||
outlookQueryWrapper.eq("id", id);
|
||||
Outlook outlook = outlookService.getOne(outlookQueryWrapper);
|
||||
|
||||
if (outlook != null) {
|
||||
if (outlook.getClientId().length() < 1 || outlook.getClientSecret().length() < 1) {
|
||||
return ResultUtil.error(ResultEnum.NO_DATA_FOUND);
|
||||
throw new APIException("没有设置key你授权啥呢!!!");
|
||||
}
|
||||
// 生成随机uuid标识用户
|
||||
String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString());
|
||||
@ -89,7 +92,8 @@ public class AuthController {
|
||||
String url = String.format(authorizeUrl, outlook.getClientId(), "https://e5.qyi.io/outlook/auth2/receive", state);
|
||||
return ResultUtil.success(url);
|
||||
} else {
|
||||
return ResultUtil.error(ResultEnum.NO_DATA_FOUND);
|
||||
throw new APIException("没有此记录");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -134,6 +134,27 @@ public class OutlookController {
|
||||
});
|
||||
return ResultUtil.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态暂停状态
|
||||
* @title setPause
|
||||
* @description
|
||||
* @author 落叶随风
|
||||
* @param: id outlook id
|
||||
* @updateTime 2020/12/13 19:24
|
||||
* @return: io.qyi.e5.bean.result.Result
|
||||
* @throws
|
||||
*/
|
||||
@GetMapping("/setPause")
|
||||
public Result setPause(@RequestParam int id) {
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
outlookService.setPause(authentication.getGithub_id(),id);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
@GetMapping("/setStart")
|
||||
public Result setStart(@RequestParam int id) {
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
outlookService.setStart(authentication.getGithub_id(),id);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,4 +30,8 @@ public interface IOutlookService extends IService<Outlook> {
|
||||
int deleteInfo(int github_id);
|
||||
|
||||
List<Outlook> getOutlooklist(int github_id);
|
||||
|
||||
void setPause(int github_id, int outlookId);
|
||||
|
||||
void setStart(int github_id, int outlookId);
|
||||
}
|
||||
|
@ -117,7 +117,8 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
|
||||
outlook1.setClientId(client_id);
|
||||
outlook1.setClientSecret(client_secret);
|
||||
outlook1.setStep(1)
|
||||
.setStatus(8);;
|
||||
.setStatus(8);
|
||||
;
|
||||
if (baseMapper.update(outlook1, queryWrapper) != 1) {
|
||||
throw new APIException("更新记录失败!");
|
||||
}
|
||||
@ -125,7 +126,7 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
|
||||
}
|
||||
|
||||
@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) {
|
||||
throw new APIException("缺少参数!");
|
||||
}
|
||||
@ -302,5 +303,30 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
|
||||
List<Outlook> outlooks = baseMapper.selectList(qw);
|
||||
return outlooks;
|
||||
}
|
||||
@Override
|
||||
public void setPause(int github_id, int outlookId) {
|
||||
UpdateWrapper<Outlook> up = new UpdateWrapper<>();
|
||||
up.eq("github_id", github_id).eq("id", outlookId);
|
||||
Outlook outlook = baseMapper.selectOne(up);
|
||||
if (outlook == null) {
|
||||
throw new APIException("查无此记录!");
|
||||
}
|
||||
/*只允许运行状态的应用设置暂停*/
|
||||
if (outlook.getStatus() != 2) {
|
||||
throw new APIException("只允许 运行状态 的应用设置暂停!");
|
||||
}
|
||||
if (baseMapper.update(new Outlook().setStatus(2), up) != 1) {
|
||||
throw new APIException("更新失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStart(int github_id, int outlookId) {
|
||||
UpdateWrapper<Outlook> up = new UpdateWrapper<>();
|
||||
up.eq("github_id", github_id).eq("id", outlookId);
|
||||
if (baseMapper.update(new Outlook().setStatus(6), up) != 1) {
|
||||
throw new APIException("更新失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,13 @@ package io.qyi.e5.outlook_log.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.gson.Gson;
|
||||
import io.qyi.e5.bean.result.Result;
|
||||
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.bena.LogVo;
|
||||
import io.qyi.e5.outlook_log.entity.OutlookLog;
|
||||
import io.qyi.e5.outlook_log.service.IOutlookLogService;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import io.qyi.e5.util.ResultUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -17,9 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Iterator;
|
||||
@ -53,12 +52,12 @@ public class OutlookLogController {
|
||||
|
||||
@GetMapping("/findLog")
|
||||
@ResponseBody
|
||||
public String findLog(){
|
||||
public Result findLog(@RequestParam int outlookId){
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
int github_id = authentication.getGithub_id();
|
||||
|
||||
QueryWrapper<OutlookLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("github_id", github_id).orderByDesc("call_time");
|
||||
queryWrapper.eq("github_id", github_id).eq("outlook_id", outlookId).orderByAsc("call_time");
|
||||
List<OutlookLog> list = outlookLogService.list(queryWrapper);
|
||||
Iterator<OutlookLog> iterator = list.iterator();
|
||||
List<LogVo> logVo = new LinkedList<>();
|
||||
@ -68,19 +67,7 @@ public class OutlookLogController {
|
||||
BeanUtils.copyProperties(next,vo);
|
||||
logVo.add(vo);
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(logVo);
|
||||
}
|
||||
|
||||
@GetMapping("/exec111111")
|
||||
public void s() throws Exception {
|
||||
List<Outlook> list = outlookService.findAll();
|
||||
logger.info(String.valueOf(list.size()));
|
||||
for (Outlook outlook :list) {
|
||||
logger.info(outlook.toString());
|
||||
outlookService.getMailList(outlook);
|
||||
}
|
||||
|
||||
return ResultUtil.success(logVo);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ public class OutlookLog implements Serializable {
|
||||
*/
|
||||
private Integer githubId;
|
||||
|
||||
/**
|
||||
* outlook_id
|
||||
*/
|
||||
private Integer outlookId;
|
||||
|
||||
/**
|
||||
* 调用时间
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user