调整数据库字段,优化部分接口 #1
@@ -1,5 +1,6 @@
|
|||||||
package cn.celess.blog.service;
|
package cn.celess.blog.service;
|
||||||
|
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
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 net.sf.json.JSONObject;
|
||||||
@@ -45,7 +46,7 @@ public interface WebUpdateInfoService {
|
|||||||
* @param page 数据页
|
* @param page 数据页
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
PageInfo<WebUpdateModel> pages(int count, int page);
|
PageData<WebUpdateModel> pages(int count, int page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部的更新记录
|
* 获取全部的更新记录
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package cn.celess.blog.service.serviceimpl;
|
|||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.exception.MyException;
|
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 cn.celess.blog.util.HttpUtil;
|
||||||
|
import cn.celess.blog.util.ModalTrans;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -39,11 +41,11 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
WebUpdate webUpdate = new WebUpdate(info, new Date());
|
WebUpdate webUpdate = new WebUpdate(info);
|
||||||
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new MyException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
return trans(webUpdate);
|
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,26 +67,20 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
}
|
}
|
||||||
webUpdate.setUpdateInfo(info);
|
webUpdate.setUpdateInfo(info);
|
||||||
webUpdateInfoMapper.update(id, info);
|
webUpdateInfoMapper.update(id, info);
|
||||||
return trans(webUpdate);
|
return ModalTrans.webUpdate(webUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<WebUpdateModel> pages(int count, int page) {
|
public PageData<WebUpdateModel> pages(int count, int page) {
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
||||||
PageInfo pageInfo = new PageInfo(updateList);
|
return new PageData<WebUpdateModel>(new PageInfo<WebUpdate>(updateList), list2List(updateList));
|
||||||
pageInfo.setList(list2List(updateList));
|
|
||||||
return pageInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WebUpdateModel> findAll() {
|
public List<WebUpdateModel> findAll() {
|
||||||
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
||||||
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
return list2List(all);
|
||||||
for (WebUpdate w : all) {
|
|
||||||
webUpdateModels.add(trans(w));
|
|
||||||
}
|
|
||||||
return webUpdateModels;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,14 +106,7 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
|
|
||||||
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
||||||
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
||||||
for (WebUpdate w : webUpdates) {
|
webUpdates.forEach(update -> webUpdateModels.add(ModalTrans.webUpdate(update)));
|
||||||
webUpdateModels.add(trans(w));
|
|
||||||
}
|
|
||||||
return webUpdateModels;
|
return webUpdateModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebUpdateModel trans(WebUpdate webUpdate) {
|
|
||||||
return new WebUpdateModel(webUpdate.getId(), webUpdate.getUpdateInfo(), DateFormatUtil.get(webUpdate.getUpdateTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.*;
|
||||||
import cn.celess.blog.entity.Category;
|
import cn.celess.blog.entity.model.*;
|
||||||
import cn.celess.blog.entity.Tag;
|
|
||||||
import cn.celess.blog.entity.User;
|
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
|
||||||
import cn.celess.blog.entity.model.CategoryModel;
|
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,4 +55,13 @@ public class ModalTrans {
|
|||||||
BeanUtils.copyProperties(tag, model);
|
BeanUtils.copyProperties(tag, model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static WebUpdateModel webUpdate(WebUpdate update) {
|
||||||
|
WebUpdateModel model = new WebUpdateModel();
|
||||||
|
model.setId(update.getId());
|
||||||
|
model.setInfo(update.getUpdateInfo());
|
||||||
|
model.setTime(DateFormatUtil.get(update.getUpdateTime()));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import net.sf.json.JSONArray;
|
import net.sf.json.JSONArray;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -104,17 +104,15 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(object.getJSONObject(Result));
|
||||||
PageInfo pageInfo = (PageInfo) JSONObject.toBean(object.getJSONObject(Result), PageInfo.class);
|
PageData<WebUpdateModel> pageData = (PageData<WebUpdateModel>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
||||||
assertNotEquals(0, pageInfo.getEndRow());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageInfo.getStartRow());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageInfo.getPageNum());
|
for (Object o : pageData.getList()) {
|
||||||
assertEquals(10, pageInfo.getPageSize());
|
|
||||||
pageInfo.getList().forEach(o -> {
|
|
||||||
WebUpdateModel model = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
WebUpdateModel model = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertNotNull(model.getTime());
|
assertNotNull(model.getTime());
|
||||||
assertNotNull(model.getInfo());
|
assertNotNull(model.getInfo());
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user