修改接口名和响应内容
This commit is contained in:
@@ -39,7 +39,7 @@ public class WebUpdateInfoController {
|
|||||||
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
public Response page(@RequestParam("page") int page, @RequestParam("count") int count) {
|
||||||
return ResponseUtil.success(webUpdateInfoService.pages(count, page));
|
return ResponseUtil.success(webUpdateInfoService.pages(count, page));
|
||||||
}
|
}
|
||||||
@GetMapping("/lastestUpdateTime")
|
@GetMapping("/lastestUpdate")
|
||||||
public Response lastestUpdateTime() {
|
public Response lastestUpdateTime() {
|
||||||
return ResponseUtil.success(webUpdateInfoService.getLastestUpdateTime());
|
return ResponseUtil.success(webUpdateInfoService.getLastestUpdateTime());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ public interface WebUpdateInfoMapper {
|
|||||||
|
|
||||||
List<WebUpdate> findAll();
|
List<WebUpdate> findAll();
|
||||||
|
|
||||||
Date getLastestOne();
|
WebUpdate getLastestOne();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.celess.blog.service;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -58,5 +59,5 @@ public interface WebUpdateInfoService {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getLastestUpdateTime();
|
JSONObject getLastestUpdateTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,17 @@ import cn.celess.blog.exception.MyException;
|
|||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import cn.celess.blog.service.WebUpdateInfoService;
|
import cn.celess.blog.service.WebUpdateInfoService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.blog.util.DateFormatUtil;
|
||||||
|
import cn.celess.blog.util.HttpUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import net.sf.json.JSONArray;
|
||||||
|
import net.sf.json.JSONObject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -80,8 +86,23 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLastestUpdateTime() {
|
public JSONObject getLastestUpdateTime() {
|
||||||
return DateFormatUtil.get(webUpdateInfoMapper.getLastestOne());
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||||
|
jsonObject.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)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
jsonObject.put("lastCommit", null);
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
||||||
|
|||||||
@@ -39,8 +39,8 @@
|
|||||||
select *
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
</select>
|
</select>
|
||||||
<select id="getLastestOne" resultType="date">
|
<select id="getLastestOne" resultMap="webUpdateResultMap">
|
||||||
select update_time
|
select *
|
||||||
from web_update
|
from web_update
|
||||||
order by update_id desc
|
order by update_id desc
|
||||||
limit 1
|
limit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user