userInfo_redis = new HashMap<>();
userInfo_redis.put("github_name", "admin");
- userInfo_redis.put("github_id", 0000);
+ userInfo_redis.put("github_id", 10000);
userInfo_redis.put("avatar_url", "https://www.baidu.com");
userInfo_redis.put("authority", list_Authority);
redisUtil.hmset(token_ + token, userInfo_redis, tokenExpire);
-
-
// 创建一个已认证的token
// UsernamePasswordAuthenticationToken authenticationToken1 = new UsernamePasswordAuthenticationToken(userInfo_redis.get("github_name").toString(),
// userInfo_redis.get("github_name").toString(), (int)userInfo_redis.get("github_name"), token, "user", AuthorityUtils.createAuthorityList(Authority));
diff --git a/src/main/java/io/qyi/e5/outlook/bean/OutlookListVo.java b/src/main/java/io/qyi/e5/outlook/bean/OutlookListVo.java
new file mode 100644
index 0000000..edd1fca
--- /dev/null
+++ b/src/main/java/io/qyi/e5/outlook/bean/OutlookListVo.java
@@ -0,0 +1,26 @@
+package io.qyi.e5.outlook.bean;
+
+import lombok.Data;
+
+/**
+ * @program: e5
+ * @description:
+ * @author: 落叶随风
+ * @create: 2020-12-10 16:54
+ **/
+@Data
+public class OutlookListVo {
+ private int id;
+ private String clientId;
+ private String clientSecret;
+ private Integer cronTimeRandomStart;
+ private Integer cronTimeRandomEnd;
+ /*名称*/
+ private String name;
+ /*描述*/
+ private String describes;
+ /*下次调用时间*/
+ private long nextTime;
+ /*运行状态*/
+ private int status;
+}
diff --git a/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java b/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java
index cb6adc5..97727cf 100644
--- a/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java
+++ b/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java
@@ -10,8 +10,9 @@ import lombok.Data;
**/
@Data
public class OutlookVo {
+ private int id;
private String clientId;
private String clientSecret;
- private int cronTimeRandomStart;
- private int cronTimeRandomEnd;
+ private Integer cronTimeRandomStart;
+ private Integer cronTimeRandomEnd;
}
diff --git a/src/main/java/io/qyi/e5/outlook/bean/bo/insertOneBO.java b/src/main/java/io/qyi/e5/outlook/bean/bo/insertOneBO.java
new file mode 100644
index 0000000..22c03df
--- /dev/null
+++ b/src/main/java/io/qyi/e5/outlook/bean/bo/insertOneBO.java
@@ -0,0 +1,15 @@
+package io.qyi.e5.outlook.bean.bo;
+
+import lombok.Data;
+
+/**
+ * @program: e5
+ * @description:
+ * @author: 落叶随风
+ * @create: 2020-12-10 15:47
+ **/
+@Data
+public class insertOneBO {
+ private String name;
+ private String describe;
+}
diff --git a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java
index 300e725..fb2ece7 100644
--- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java
+++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java
@@ -4,8 +4,11 @@ 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.security.UsernamePasswordAuthenticationToken;
+import io.qyi.e5.outlook.bean.OutlookListVo;
import io.qyi.e5.outlook.bean.OutlookVo;
+import io.qyi.e5.outlook.bean.bo.insertOneBO;
import io.qyi.e5.outlook.entity.Outlook;
import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.util.ResultUtil;
@@ -15,6 +18,10 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
/**
*
* 前端控制器
@@ -30,15 +37,25 @@ public class OutlookController {
@Autowired
IOutlookService outlookService;
- @PostMapping("/save")
- public Result save(@RequestParam String client_id, @RequestParam String client_secret) {
+ @PostMapping("/insertOne")
+ public ResultVO insertOne(@RequestBody insertOneBO bo) {
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
- if (outlookService.save(client_id, client_secret, authentication.getGithub_id())) {
- return ResultUtil.success();
- }
- return ResultUtil.error(ResultEnum.UNKNOWN_ERROR);
+ Outlook outlook = outlookService.insertOne(bo.getName(), bo.getDescribe(), authentication.getGithub_id());
+ OutlookVo vo = new OutlookVo();
+ BeanUtils.copyProperties(outlook, vo);
+ return new ResultVO<>(vo);
}
+ @PostMapping("/save")
+ public ResultVO save(@RequestParam String client_id, @RequestParam String client_secret,@RequestParam int outlook_id) {
+ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
+ if (outlookService.save(client_id, client_secret, outlook_id, authentication.getGithub_id())) {
+ return new ResultVO<>();
+ }
+ return new ResultVO<>();
+ }
+
+
@PostMapping("/saveRandomTime")
public Result saveRandomTime(@RequestParam int cronTime, @RequestParam String crondomTime) {
String[] split = crondomTime.split("-");
@@ -86,4 +103,21 @@ public class OutlookController {
}
return ResultUtil.success(vo);
}
+
+
+ @GetMapping("/getOutlookList")
+ public Result getOutlookList() {
+ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
+ int github_id = authentication.getGithub_id();
+ List outlooklist = outlookService.getOutlooklist(github_id);
+ List vo = new ArrayList<>();
+ outlooklist.forEach(outlook -> {
+ OutlookListVo v = new OutlookListVo();
+ BeanUtils.copyProperties(outlook, v);
+ vo.add(v);
+ });
+ return ResultUtil.success(vo);
+ }
+
+
}
diff --git a/src/main/java/io/qyi/e5/outlook/entity/Outlook.java b/src/main/java/io/qyi/e5/outlook/entity/Outlook.java
index 99c3e19..bc22a80 100644
--- a/src/main/java/io/qyi/e5/outlook/entity/Outlook.java
+++ b/src/main/java/io/qyi/e5/outlook/entity/Outlook.java
@@ -2,14 +2,16 @@ package io.qyi.e5.outlook.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
+
import java.io.Serializable;
+
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
*
- *
+ *
*
*
* @author 落叶
@@ -58,6 +60,11 @@ public class Outlook implements Serializable {
*/
private Integer cronTimeRandomEnd;
+ /*名称*/
+ private String name;
+
+ /*描述*/
+ private String describes;
}
diff --git a/src/main/java/io/qyi/e5/outlook/mapper/OutlookMapper.java b/src/main/java/io/qyi/e5/outlook/mapper/OutlookMapper.java
index 78fbf11..abe9dd9 100644
--- a/src/main/java/io/qyi/e5/outlook/mapper/OutlookMapper.java
+++ b/src/main/java/io/qyi/e5/outlook/mapper/OutlookMapper.java
@@ -12,5 +12,5 @@ import io.qyi.e5.outlook.entity.Outlook;
* @since 2020-02-24
*/
public interface OutlookMapper extends BaseMapper {
-
+ Outlook selectOutlookOne(int id, int github_id);
}
diff --git a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java
index 5d2252d..1c42561 100644
--- a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java
+++ b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java
@@ -17,13 +17,17 @@ public interface IOutlookService extends IService {
boolean getTokenAndSave(String code,String client_id,String client_secret,String redirect_uri,String grant_type) throws Exception;
- boolean save(String client_id,String client_secret,int github_id);
+ Outlook insertOne(String name, String describe, int github_id);
- boolean saveRandomTime(int github_id,int cron_time,int cron_time_random_start,int cron_time_random_end);
+ boolean save(String client_id, String client_secret, int outlook_id, int github_id);
+
+ boolean saveRandomTime(int github_id, int cron_time, int cron_time_random_start, int cron_time_random_end);
int getMailList(Outlook outlook) throws Exception;
List findAll();
int deleteInfo(int github_id);
+
+ List getOutlooklist(int github_id);
}
diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java
index 00e5c64..03d050c 100644
--- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java
+++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java
@@ -8,16 +8,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+import io.qyi.e5.config.APiCode;
+import io.qyi.e5.config.exception.APIException;
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.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.Value;
import org.springframework.stereotype.Service;
+import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -75,35 +78,48 @@ public class OutlookServiceImpl extends ServiceImpl impl
}
@Override
- public boolean save(String client_id, String client_secret, int github_id) {
+ public Outlook insertOne(String name, String describe, int github_id) {
+ if (StringUtils.isBlank(name)) {
+ throw new APIException(APiCode.OUTLOOK_NAME_NOT_NULL);
+ }
+ Outlook outlook = new Outlook();
+ outlook.setName(name);
+ outlook.setDescribes(describe);
+ outlook.setGithubId(github_id);
+ logger.info(outlook.toString());
+ if (baseMapper.insert(outlook) != 1) {
+ throw new APIException(APiCode.OUTLOOK_INSERT_ERROR);
+ }
+ return outlook;
+ }
+
+ @Override
+ public boolean save(String client_id, String client_secret, int outlook_id, int github_id) {
if (github_id == 0) {
- return false;
+ throw new APIException(APiCode.OUTLOOK_NAME_NOT_NULL);
+ }
+ if (outlook_id == 0) {
+ throw new APIException("缺少参数!");
}
QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("github_id", github_id)
- .or().eq("client_id", client_id);
- Outlook outlook1 = baseMapper.selectOne(queryWrapper);
-// 有数据
- if (outlook1 != null) {
- outlook1.setClientId(client_id)
- .setClientSecret(client_secret);
+// HashMap sc = new HashMap<>();
+// sc.put("github_id", github_id);
+// sc.put("id", outlook_id);
+// queryWrapper.allEq(sc);
+ queryWrapper.eq("github_id", github_id).eq("id", outlook_id);
+ /*2020-12-10 mybatis plus问题导致会被截断*/
+// Outlook outlook1 = baseMapper.selectOne(queryWrapper);
- int i = baseMapper.update(outlook1, queryWrapper);
- if (i == 1) {
- return true;
- }
- } else {
- Outlook outlook = new Outlook();
- outlook.setClientId(client_id)
- .setClientSecret(client_secret)
- .setGithubId(github_id);
- int i = baseMapper.insert(outlook);
- if (i == 1) {
- return true;
- }
+ Outlook outlook1 = baseMapper.selectOutlookOne(outlook_id,github_id );
+ if (outlook1 == null) {
+ throw new APIException("未查询到此条记录!");
}
-
- return false;
+ outlook1.setClientId(client_id);
+ outlook1.setClientSecret(client_secret);
+ if (baseMapper.update(outlook1, queryWrapper) != 1) {
+ throw new APIException("更新记录失败!");
+ }
+ return true;
}
@Override
@@ -154,7 +170,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
String message = json.getJSONObject("error").getString("message");
/*如果出现的错误是没有message中收集的,那么就认为是无法刷新的情况。比如 用户取消了授权、删除了key*/
if (!errorCheck(message)) {
- throw new Exception("无法刷新令牌!code:3" + message);
+ throw new Exception("无法刷新令牌!code:3" + message);
}
logger.info("令牌过期!");
/*刷新令牌*/
@@ -166,7 +182,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
s = MailList(token);
json = JSON.parseObject(s);
if (json.containsKey("error")) {
- throw new Exception("无法刷新令牌!code:2,错误消息: "+ json.getJSONObject("error").getString("message"));
+ throw new Exception("无法刷新令牌!code:2,错误消息: " + json.getJSONObject("error").getString("message"));
}
}
logger.info("邮件列表请求成功!" + s);
@@ -207,7 +223,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
head.put("Content-Type", "application/json");
head.put("Authorization", access_token);
/*不用管邮件内容*/
- OkHttpClientUtil.doGet("https://graph.microsoft.com/v1.0/me/messages/" + id, null,head, null);
+ OkHttpClientUtil.doGet("https://graph.microsoft.com/v1.0/me/messages/" + id, null, head, null);
}
return count;
}
@@ -216,7 +232,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
Map head = new HashMap<>();
head.put("Content-Type", "application/json");
head.put("Authorization", access_token);
- String s = OkHttpClientUtil.doGet("https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject",null, head, null);
+ String s = OkHttpClientUtil.doGet("https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject", null, head, null);
logger.debug("请求邮件列表返回数据:" + s);
return s;
}
@@ -238,7 +254,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
JSONObject jsonObject = JSON.parseObject(s);
if (!jsonObject.containsKey("access_token")) {
logger.info("返回的access_token字段不存在");
- throw new Exception("返回的access_token字段不存在,无法刷新令牌! 需要重新授权!" );
+ throw new Exception("返回的access_token字段不存在,无法刷新令牌! 需要重新授权!");
}
outlook.setRefreshToken(jsonObject.getString("refresh_token"));
outlook.setAccessToken(jsonObject.getString("access_token"));
@@ -271,4 +287,12 @@ public class OutlookServiceImpl extends ServiceImpl impl
}
return false;
}
+
+ @Override
+ public List getOutlooklist(int github_id) {
+ QueryWrapper qw = new QueryWrapper().eq("github_id", github_id);
+ List outlooks = baseMapper.selectList(qw);
+ return outlooks;
+ }
+
}
diff --git a/src/main/resources/mapper/outlook/OutlookMapper.xml b/src/main/resources/mapper/outlook/OutlookMapper.xml
index d597ed9..cc7974c 100644
--- a/src/main/resources/mapper/outlook/OutlookMapper.xml
+++ b/src/main/resources/mapper/outlook/OutlookMapper.xml
@@ -1,5 +1,8 @@
+