修改数据库 outlook_log-> call_time、result 为int

This commit is contained in:
LuoYe_MyWork 2020-04-14 16:39:49 +08:00
parent 9f49dbf8ec
commit 738bc0976a
10 changed files with 93 additions and 32 deletions

View File

@ -45,30 +45,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("HttpSecurity http");
/*http.authorizeRequests().antMatchers("/").permitAll();
http.authorizeRequests().anyRequest().authenticated();
http.logout().permitAll();
http.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login1")
.successHandler(securityAuthenticationHandler)
.failureHandler(securityAuthenticationHandler)
// .loginProcessingUrl("api/getInfo")
.permitAll()
.and()
.logout()
.logoutUrl("logout")
.logoutSuccessHandler( securityAuthenticationHandler);*/
http.addFilterBefore(new LinkTokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
http.csrf().disable()
.apply(usernamePasswordAuthenticationConfig);
/*关闭创建session*/
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.formLogin()
/*formLogin()
.loginPage("/user/login")// 登陆页面
.loginProcessingUrl("/user/loginFrom")// 登陆表单提交请求
.and()
.authorizeRequests().antMatchers("/user/login", "/user/loginFrom", "/auth2/getGithubUrl").permitAll()// 指定相应的请求 不需要验证
.and()*/
http.authorizeRequests().antMatchers("/user/login", "/user/loginFrom", "/auth2/getGithubUrl").permitAll()// 指定相应的请求 不需要验证
// .and()
// .authorizeRequests().antMatchers("/quartz/**").permitAll()//测试
.anyRequest()// 任何请求

View File

@ -52,7 +52,7 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter {
HttpServletResponse response = httpServletResponse;
response.setHeader("Access-Control-Allow-Origin","*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "\"GET, HEAD, POST");
response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token");
/*如果是OPTIONS则结束请求*/

View File

@ -12,4 +12,6 @@ import lombok.Data;
public class OutlookVo {
private String clientId;
private String clientSecret;
private int cronTimeRandomStart;
private int cronTimeRandomEnd;
}

View File

@ -139,7 +139,7 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
String code = json.getJSONObject("error").getString("code");
String message = json.getJSONObject("error").getString("message");
if (!errorCheck(message)) {
outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:3", "0", message);
outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:3", 0, message);
return false;
}
// CompactToken validation failed with reason code: 80049228
@ -152,11 +152,11 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
s = MailList(token);
json = JSON.parseObject(s);
if (json.containsKey("error")) {
outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:2", "0", json.getJSONObject("error").getString("message"));
outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌!code:2", 1, json.getJSONObject("error").getString("message"));
return false;
}
}
outlookLogService.addLog(outlook.getGithubId(), "ok", "1", "");
outlookLogService.addLog(outlook.getGithubId(), "ok", 1, "");
return true;
} catch (Exception e) {
e.printStackTrace();
@ -191,7 +191,7 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
JSONObject jsonObject = JSON.parseObject(s);
if (!jsonObject.containsKey("access_token")) {
logger.info("返回的access_token字段不存在");
outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌! 需要重新授权!", "0", s);
outlookLogService.addLog(outlook.getGithubId(), "无法刷新令牌! 需要重新授权!", 0, s);
// 字段不存在
return null;
}
@ -202,14 +202,14 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
queryWrapper.eq("client_id", outlook.getClientId());
if (baseMapper.update(outlook, queryWrapper) != 1) {
logger.info("返更新行数不为1");
outlookLogService.addLog(outlook.getGithubId(), "更新数据库时发现有重复的key", "0", "");
outlookLogService.addLog(outlook.getGithubId(), "更新数据库时发现有重复的key", 0, "");
return null;
}
return outlook.getAccessToken();
// 更新数据库
} catch (Exception e) {
e.printStackTrace();
outlookLogService.addLog(outlook.getGithubId(), e.getMessage(), "0", e.getMessage());
outlookLogService.addLog(outlook.getGithubId(), e.getMessage(), 0, e.getMessage());
return null;
}
}

View File

@ -0,0 +1,18 @@
package io.qyi.e5.outlook_log.bena;
import lombok.Data;
/**
* 返回给浏览器的字段
* @program: e5
* @description:
* @author: 落叶随风
* @create: 2020-04-14 15:05
**/
@Data
public class LogVo {
private int callTime;
private int result;
private String msg;
private String originalMsg;
}

View File

@ -6,10 +6,13 @@ import com.google.gson.Gson;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
@ -19,6 +22,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
@ -48,15 +53,23 @@ public class OutlookLogController {
@GetMapping("/findLog")
@ResponseBody
public String findLog(Model model){
public String findLog(){
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
int github_id = authentication.getGithub_id();
QueryWrapper<OutlookLog> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("github_id", github_id);
List<OutlookLog> list = outlookLogService.list(queryWrapper);
Iterator<OutlookLog> iterator = list.iterator();
List<LogVo> logVo = new LinkedList<>();
while (iterator.hasNext()) {
OutlookLog next = iterator.next();
LogVo vo = new LogVo();
BeanUtils.copyProperties(next,vo);
logVo.add(vo);
}
Gson gson = new Gson();
return gson.toJson(list);
return gson.toJson(logVo);
}
@GetMapping("/exec111111")

View File

@ -33,12 +33,12 @@ public class OutlookLog implements Serializable {
/**
* 调用时间
*/
private String callTime;
private Integer callTime;
/**
* 调用结果
*/
private String result;
private Integer result;
/**
* 如果有错误原因则记录

View File

@ -12,6 +12,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2020-03-03
*/
public interface IOutlookLogService extends IService<OutlookLog> {
void addLog(int githubId, String msg,String result,String original_msg);
void addLog(int githubId, String msg,int result,String original_msg);
}

View File

@ -17,11 +17,11 @@ import org.springframework.stereotype.Service;
@Service
public class OutlookLogServiceImpl extends ServiceImpl<OutlookLogMapper, OutlookLog> implements IOutlookLogService {
@Override
public void addLog(int githubId, String msg, String result,String original_msg) {
public void addLog(int githubId, String msg, int result,String original_msg) {
OutlookLog outlookLog = new OutlookLog();
outlookLog.setGithubId(githubId)
.setResult(result.equals("1") ? "1" : "0")
.setCallTime(String.valueOf(System.currentTimeMillis() / 1000))
.setResult(result)
.setCallTime((int) (System.currentTimeMillis() / 1000))
.setMsg(msg)
.setOriginalMsg(original_msg);

View File

@ -0,0 +1,42 @@
package io.qyi.e5.util;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @program: e5
* @description:
* @author: 落叶随风
* @create: 2020-04-14 15:26
**/
public class DateUtil {
/**
* 时间戳转换成日期格式字符串
* @param seconds 精确到秒的字符串
* @param format 格式
* @return
*/
public static String timeStamp2Date(String seconds,String format) {
if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
return "";
}
if(format == null || format.isEmpty()){
format = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(seconds+"000")));
}
/**
* 日期格式字符串转换成时间戳
* @param date_str 字符串日期
* @param format yyyy-MM-dd HH:mm:ss
* @return
*/
public static String date2TimeStamp(String date_str,String format){
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return String.valueOf(sdf.parse(date_str).getTime()/1000);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}