切换到jackson #10
@@ -2,10 +2,10 @@ package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
@@ -59,5 +59,5 @@ public interface WebUpdateInfoService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
JSONObject getLastestUpdateTime();
|
||||
Map<String, Object> getLastestUpdateTime();
|
||||
}
|
||||
|
||||
@@ -10,20 +10,17 @@ import cn.celess.blog.service.WebUpdateInfoService;
|
||||
import cn.celess.blog.util.DateFormatUtil;
|
||||
import cn.celess.blog.util.HttpUtil;
|
||||
import cn.celess.blog.util.ModalTrans;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
@@ -84,24 +81,25 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getLastestUpdateTime() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||
jsonObject.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
||||
public Map<String, Object> getLastestUpdateTime() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||
map.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
||||
try {
|
||||
JSONArray array = JSONArray.fromObject(HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1"));
|
||||
JSONObject object = array.getJSONObject(0);
|
||||
JSONObject commit = object.getJSONObject("commit");
|
||||
jsonObject.put("lastCommit", commit.getString("message"));
|
||||
jsonObject.put("committerAuthor", commit.getJSONObject("committer").getString("name"));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat();
|
||||
Instant parse = Instant.parse(commit.getJSONObject("committer").getString("date"));
|
||||
jsonObject.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
||||
jsonObject.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + object.getString("sha"));
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root = mapper.readTree(HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1"));
|
||||
Iterator<JsonNode> elements = root.elements();
|
||||
JsonNode next = elements.next();
|
||||
JsonNode commit = next.get("commit");
|
||||
map.put("lastCommit", commit.get("message"));
|
||||
map.put("committerAuthor", commit.get("committer").get("name"));
|
||||
Instant parse = Instant.parse(commit.get("committer").get("date").asText());
|
||||
map.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
||||
map.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + next.get("sha").asText());
|
||||
} catch (IOException e) {
|
||||
log.info("网络请求失败{}", e.getMessage());
|
||||
}
|
||||
return jsonObject;
|
||||
return map;
|
||||
}
|
||||
|
||||
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
||||
|
||||
@@ -3,7 +3,8 @@ package cn.celess.blog.util;
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.User;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import net.sf.json.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,24 +32,27 @@ public class RedisUserUtil {
|
||||
return user;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public User getWithOutExc() {
|
||||
String token = request.getHeader("Authorization");
|
||||
if (token == null || token.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String email = jwtUtil.getUsernameFromToken(token);
|
||||
return (User) JSONObject.toBean(JSONObject.fromObject(redisUtil.get(email + "-login")), User.class);
|
||||
return new ObjectMapper().readValue(redisUtil.get(email + "-login"), User.class);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public User set(User user) {
|
||||
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
||||
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||
return user;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public User set(User user, boolean isRemember) {
|
||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
||||
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||
request.getSession().setAttribute("email", user.getEmail());
|
||||
return user;
|
||||
|
||||
Reference in New Issue
Block a user