Commit 01c18313 authored by Junling Bu's avatar Junling Bu
Browse files

chore: 利用PageHelper的PageInfo简化代码。

parent d40b9146
......@@ -51,17 +51,4 @@ public class LitemallRegionService {
PageHelper.startPage(page, size);
return regionMapper.selectByExample(example);
}
public int countSelective(String name, Integer code, Integer page, Integer size, String sort, String order) {
LitemallRegionExample example = new LitemallRegionExample();
LitemallRegionExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
if (code != null) {
criteria.andCodeEqualTo(code);
}
return (int) regionMapper.countByExample(example);
}
}
......@@ -54,23 +54,6 @@ public class LitemallRoleService {
return roleMapper.selectByExample(example);
}
public int countSelective(String roleName, Integer page, Integer size, String sort, String order) {
LitemallRoleExample example = new LitemallRoleExample();
LitemallRoleExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(roleName)) {
criteria.andNameEqualTo("%" + roleName + "%");
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size);
return (int)roleMapper.countByExample(example);
}
public LitemallRole findById(Integer id) {
return roleMapper.selectByPrimaryKey(id);
}
......
......@@ -54,19 +54,4 @@ public class LitemallSearchHistoryService {
PageHelper.startPage(page, size);
return searchHistoryMapper.selectByExample(example);
}
public int countSelective(String userId, String keyword, Integer page, Integer size, String sort, String order) {
LitemallSearchHistoryExample example = new LitemallSearchHistoryExample();
LitemallSearchHistoryExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(userId)) {
criteria.andUserIdEqualTo(Integer.valueOf(userId));
}
if (!StringUtils.isEmpty(keyword)) {
criteria.andKeywordLike("%" + keyword + "%");
}
criteria.andDeletedEqualTo(false);
return (int) searchHistoryMapper.countByExample(example);
}
}
......@@ -62,19 +62,4 @@ public class LitemallStorageService {
PageHelper.startPage(page, limit);
return storageMapper.selectByExample(example);
}
public int countSelective(String key, String name, Integer page, Integer size, String sort, String order) {
LitemallStorageExample example = new LitemallStorageExample();
LitemallStorageExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(key)) {
criteria.andKeyEqualTo(key);
}
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
return (int) storageMapper.countByExample(example);
}
}
......@@ -82,21 +82,6 @@ public class LitemallTopicService {
return topicMapper.selectByExampleWithBLOBs(example);
}
public int countSelective(String title, String subtitle, Integer page, Integer size, String sort, String order) {
LitemallTopicExample example = new LitemallTopicExample();
LitemallTopicExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(title)) {
criteria.andTitleLike("%" + title + "%");
}
if (!StringUtils.isEmpty(subtitle)) {
criteria.andSubtitleLike("%" + subtitle + "%");
}
criteria.andDeletedEqualTo(false);
return (int) topicMapper.countByExample(example);
}
public int updateById(LitemallTopic topic) {
topic.setUpdateTime(LocalDateTime.now());
LitemallTopicExample example = new LitemallTopicExample();
......
......@@ -66,21 +66,6 @@ public class LitemallUserService {
return userMapper.selectByExample(example);
}
public int countSeletive(String username, String mobile, Integer page, Integer size, String sort, String order) {
LitemallUserExample example = new LitemallUserExample();
LitemallUserExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%");
}
if (!StringUtils.isEmpty(mobile)) {
criteria.andMobileEqualTo(mobile);
}
criteria.andDeletedEqualTo(false);
return (int) userMapper.countByExample(example);
}
public int count() {
LitemallUserExample example = new LitemallUserExample();
example.or().andDeletedEqualTo(false);
......@@ -94,6 +79,12 @@ public class LitemallUserService {
return userMapper.selectByExample(example);
}
public boolean checkByUsername(String username) {
LitemallUserExample example = new LitemallUserExample();
example.or().andUsernameEqualTo(username).andDeletedEqualTo(false);
return userMapper.countByExample(example) != 0;
}
public List<LitemallUser> queryByMobile(String mobile) {
LitemallUserExample example = new LitemallUserExample();
example.or().andMobileEqualTo(mobile).andDeletedEqualTo(false);
......
package org.linlinjava.litemall.wx.web;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
......@@ -110,8 +111,8 @@ public class WxCommentController {
*/
@GetMapping("count")
public Object count(@NotNull Byte type, @NotNull Integer valueId) {
int allCount = commentService.count(type, valueId, 0, 0, 0);
int hasPicCount = commentService.count(type, valueId, 1, 0, 0);
int allCount = commentService.count(type, valueId, 0);
int hasPicCount = commentService.count(type, valueId, 1);
Map<String, Object> data = new HashMap<String, Object>();
data.put("allCount", allCount);
data.put("hasPicCount", hasPicCount);
......@@ -135,7 +136,7 @@ public class WxCommentController {
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
List<LitemallComment> commentList = commentService.query(type, valueId, showType, page, size);
int count = commentService.count(type, valueId, showType, page, size);
long count = PageInfo.of(commentList).getTotal();
List<Map<String, Object>> commentVoList = new ArrayList<>(commentList.size());
for (LitemallComment comment : commentList) {
......
package org.linlinjava.litemall.wx.web;
import com.github.pagehelper.PageInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.JacksonUtil;
......@@ -81,7 +82,7 @@ public class WxFootprintController {
}
List<LitemallFootprint> footprintList = footprintService.queryByAddTime(userId, page, size);
int count = footprintService.countByAddTime(userId, page, size);
long count = PageInfo.of(footprintList).getTotal();
int totalPages = (int) Math.ceil((double) count / size);
List<Object> footprintVoList = new ArrayList<>(footprintList.size());
......
package org.linlinjava.litemall.wx.web;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.mysql.jdbc.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
......@@ -10,7 +12,6 @@ import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.GetRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -122,7 +123,7 @@ public class WxGoodsController {
Callable<Map> commentsCallable = () -> {
List<LitemallComment> comments = commentService.queryGoodsByGid(id, 0, 2);
List<Map<String, Object>> commentsVo = new ArrayList<>(comments.size());
int commentCount = commentService.countGoodsByGid(id, 0, 2);
long commentCount = PageInfo.of(comments).getTotal();
for (LitemallComment comment : comments) {
Map<String, Object> c = new HashMap<>();
c.put("id", comment.getId());
......@@ -265,7 +266,6 @@ public class WxGoodsController {
//查询列表数据
List<LitemallGoods> goodsList = goodsService.querySelective(categoryId, brandId, keyword, isHot, isNew, page, size, sort, order);
int total = goodsService.countSelective(categoryId, brandId, keyword, isHot, isNew, page, size, sort, order);
// 查询商品所属类目列表。
List<Integer> goodsCatIds = goodsService.getCatIds(brandId, keyword, isHot, isNew);
......@@ -278,8 +278,9 @@ public class WxGoodsController {
Map<String, Object> data = new HashMap<>();
data.put("goodsList", goodsList);
data.put("count", PageInfo.of(goodsList).getTotal());
data.put("filterCategoryList", categoryList);
data.put("count", total);
return ResponseUtil.ok(data);
}
......
package org.linlinjava.litemall.wx.web;
import com.github.pagehelper.PageInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.express.ExpressService;
......@@ -66,8 +67,8 @@ public class WxGrouponController {
@RequestParam(defaultValue = "10") Integer size,
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
Object topicList = grouponRulesService.queryList(page, size, sort, order);
int total = grouponRulesService.countList(page, size, sort, order);
List<Map<String, Object>> topicList = grouponRulesService.queryList(page, size, sort, order);
long total = PageInfo.of(topicList).getTotal();
Map<String, Object> data = new HashMap<String, Object>();
data.put("data", topicList);
data.put("count", total);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment