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

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

parent d40b9146
package org.linlinjava.litemall.admin.web;
import com.github.pagehelper.PageInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
......@@ -41,7 +42,7 @@ public class AdminUserController {
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
List<LitemallUser> userList = userService.querySelective(username, mobile, page, limit, sort, order);
int total = userService.countSeletive(username, mobile, page, limit, sort, order);
long total = PageInfo.of(userList).getTotal();
Map<String, Object> data = new HashMap<>();
data.put("total", total);
data.put("items", userList);
......@@ -51,11 +52,11 @@ public class AdminUserController {
@GetMapping("/username")
public Object username(@NotEmpty String username) {
int total = userService.countSeletive(username, null, null, null, null, null);
if (total == 0) {
return ResponseUtil.ok("存在");
boolean exist = userService.checkByUsername(username);
if (exist) {
return ResponseUtil.ok("存在");
}
return ResponseUtil.ok("存在");
return ResponseUtil.ok("存在");
}
private Object validate(LitemallUser user) {
......
......@@ -42,21 +42,6 @@ public class LitemallAdService {
return adMapper.selectByExample(example);
}
public int countSelective(String name, String content, Integer page, Integer size, String sort, String order) {
LitemallAdExample example = new LitemallAdExample();
LitemallAdExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
if (!StringUtils.isEmpty(content)) {
criteria.andContentLike("%" + content + "%");
}
criteria.andDeletedEqualTo(false);
return (int) adMapper.countByExample(example);
}
public int updateById(LitemallAd ad) {
ad.setUpdateTime(LocalDateTime.now());
return adMapper.updateByPrimaryKeySelective(ad);
......
......@@ -75,19 +75,4 @@ public class LitemallAddressService {
PageHelper.startPage(page, limit);
return addressMapper.selectByExample(example);
}
public int countSelective(Integer userId, String name, Integer page, Integer limit, String sort, String order) {
LitemallAddressExample example = new LitemallAddressExample();
LitemallAddressExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
return (int) addressMapper.countByExample(example);
}
}
......@@ -45,18 +45,6 @@ public class LitemallAdminService {
return adminMapper.selectByExampleSelective(example, result);
}
public int countSelective(String username, Integer page, Integer size, String sort, String order) {
LitemallAdminExample example = new LitemallAdminExample();
LitemallAdminExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%");
}
criteria.andDeletedEqualTo(false);
return (int) adminMapper.countByExample(example);
}
public int updateById(LitemallAdmin admin) {
admin.setUpdateTime(LocalDateTime.now());
return adminMapper.updateByPrimaryKeySelective(admin);
......
......@@ -56,21 +56,6 @@ public class LitemallBrandService {
return brandMapper.selectByExample(example);
}
public int countSelective(String id, String name, Integer page, Integer size, String sort, String order) {
LitemallBrandExample example = new LitemallBrandExample();
LitemallBrandExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(id)) {
criteria.andIdEqualTo(Integer.valueOf(id));
}
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
return (int) brandMapper.countByExample(example);
}
public int updateById(LitemallBrand brand) {
brand.setUpdateTime(LocalDateTime.now());
return brandMapper.updateByPrimaryKeySelective(brand);
......
......@@ -93,21 +93,6 @@ public class LitemallCartService {
return cartMapper.selectByExample(example);
}
public int countSelective(Integer userId, Integer goodsId, Integer page, Integer limit, String sort, String order) {
LitemallCartExample example = new LitemallCartExample();
LitemallCartExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if (goodsId != null) {
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
return (int) cartMapper.countByExample(example);
}
public void deleteById(Integer id) {
cartMapper.logicalDeleteByPrimaryKey(id);
}
......
......@@ -73,21 +73,6 @@ public class LitemallCategoryService {
return categoryMapper.selectByExample(example);
}
public int countSelective(String id, String name, Integer page, Integer size, String sort, String order) {
LitemallCategoryExample example = new LitemallCategoryExample();
LitemallCategoryExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(id)) {
criteria.andIdEqualTo(Integer.valueOf(id));
}
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
return (int) categoryMapper.countByExample(example);
}
public int updateById(LitemallCategory category) {
category.setUpdateTime(LocalDateTime.now());
return categoryMapper.updateByPrimaryKeySelective(category);
......
......@@ -71,19 +71,4 @@ public class LitemallCollectService {
PageHelper.startPage(page, size);
return collectMapper.selectByExample(example);
}
public int countSelective(String userId, String valueId, Integer page, Integer size, String sort, String order) {
LitemallCollectExample example = new LitemallCollectExample();
LitemallCollectExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(userId)) {
criteria.andUserIdEqualTo(Integer.valueOf(userId));
}
if (!StringUtils.isEmpty(valueId)) {
criteria.andValueIdEqualTo(Integer.valueOf(valueId));
}
criteria.andDeletedEqualTo(false);
return (int) collectMapper.countByExample(example);
}
}
......@@ -24,12 +24,6 @@ public class LitemallCommentService {
return commentMapper.selectByExample(example);
}
public int countGoodsByGid(Integer id, int offset, int limit) {
LitemallCommentExample example = new LitemallCommentExample();
example.or().andValueIdEqualTo(id).andTypeEqualTo((byte) 0).andDeletedEqualTo(false);
return (int) commentMapper.countByExample(example);
}
public List<LitemallComment> query(Byte type, Integer valueId, Integer showType, Integer offset, Integer limit) {
LitemallCommentExample example = new LitemallCommentExample();
example.setOrderByClause(LitemallComment.Column.addTime.desc());
......@@ -44,7 +38,7 @@ public class LitemallCommentService {
return commentMapper.selectByExample(example);
}
public int count(Byte type, Integer valueId, Integer showType, Integer offset, Integer size) {
public int count(Byte type, Integer valueId, Integer showType) {
LitemallCommentExample example = new LitemallCommentExample();
if (showType == 0) {
example.or().andValueIdEqualTo(valueId).andTypeEqualTo(type).andDeletedEqualTo(false);
......@@ -85,21 +79,6 @@ public class LitemallCommentService {
return commentMapper.selectByExample(example);
}
public int countSelective(String userId, String valueId, Integer page, Integer size, String sort, String order) {
LitemallCommentExample example = new LitemallCommentExample();
LitemallCommentExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(userId)) {
criteria.andUserIdEqualTo(Integer.valueOf(userId));
}
if (!StringUtils.isEmpty(valueId)) {
criteria.andValueIdEqualTo(Integer.valueOf(valueId)).andTypeEqualTo((byte) 0);
}
criteria.andDeletedEqualTo(false);
return (int) commentMapper.countByExample(example);
}
public void deleteById(Integer id) {
commentMapper.logicalDeleteByPrimaryKey(id);
}
......
......@@ -133,28 +133,6 @@ public class LitemallCouponService {
return couponMapper.selectByExample(example);
}
public int countSelective(String name, Short type, Short status, Integer page, Integer limit, String sort, String order) {
LitemallCouponExample example = new LitemallCouponExample();
LitemallCouponExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
if (type != null) {
criteria.andTypeEqualTo(type);
}
if (status != null) {
criteria.andStatusEqualTo(status);
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
return (int)couponMapper.countByExample(example);
}
public void add(LitemallCoupon coupon) {
coupon.setAddTime(LocalDateTime.now());
coupon.setUpdateTime(LocalDateTime.now());
......
......@@ -60,32 +60,6 @@ public class LitemallCouponUserService {
return couponUserMapper.selectByExample(example);
}
public int countList(Integer userId, Integer couponId, Short status, Integer page, Integer size, String sort, String order) {
LitemallCouponUserExample example = new LitemallCouponUserExample();
LitemallCouponUserExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if(couponId != null){
criteria.andCouponIdEqualTo(couponId);
}
if (status != null) {
criteria.andStatusEqualTo(status);
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
if (!StringUtils.isEmpty(page) && !StringUtils.isEmpty(size)) {
PageHelper.startPage(page, size);
}
return (int)couponUserMapper.countByExample(example);
}
public List<LitemallCouponUser> queryAll(Integer userId, Integer couponId) {
return queryList(userId, couponId, CouponUserConstant.STATUS_USABLE, null, null, "add_time", "desc");
}
......
......@@ -45,18 +45,4 @@ public class LitemallFeedbackService {
PageHelper.startPage(page, limit);
return feedbackMapper.selectByExample(example);
}
public int countSelective(Integer userId, String username, Integer page, Integer limit, String sort, String order) {
LitemallFeedbackExample example = new LitemallFeedbackExample();
LitemallFeedbackExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%");
}
criteria.andDeletedEqualTo(false);
return (int) feedbackMapper.countByExample(example);
}
}
......@@ -24,12 +24,6 @@ public class LitemallFootprintService {
return footprintMapper.selectByExample(example);
}
public int countByAddTime(Integer userId, Integer page, Integer size) {
LitemallFootprintExample example = new LitemallFootprintExample();
example.or().andUserIdEqualTo(userId).andDeletedEqualTo(false);
return (int) footprintMapper.countByExample(example);
}
public LitemallFootprint findById(Integer id) {
return footprintMapper.selectByPrimaryKey(id);
}
......@@ -63,19 +57,4 @@ public class LitemallFootprintService {
PageHelper.startPage(page, size);
return footprintMapper.selectByExample(example);
}
public int countSelective(String userId, String goodsId, Integer page, Integer size, String sort, String order) {
LitemallFootprintExample example = new LitemallFootprintExample();
LitemallFootprintExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(userId)) {
criteria.andUserIdEqualTo(Integer.valueOf(userId));
}
if (!StringUtils.isEmpty(goodsId)) {
criteria.andGoodsIdEqualTo(Integer.valueOf(goodsId));
}
criteria.andDeletedEqualTo(false);
return (int) footprintMapper.countByExample(example);
}
}
......@@ -121,46 +121,11 @@ public class LitemallGoodsService {
example.setOrderByClause(sort + " " + order);
}
if (!StringUtils.isEmpty(limit) && !StringUtils.isEmpty(offset)) {
PageHelper.startPage(offset, limit);
}
PageHelper.startPage(offset, limit);
return goodsMapper.selectByExampleSelective(example, columns);
}
public int countSelective(Integer catId, Integer brandId, String keywords, Boolean isHot, Boolean isNew, Integer offset, Integer limit, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria1 = example.or();
LitemallGoodsExample.Criteria criteria2 = example.or();
if (!StringUtils.isEmpty(catId) && catId != 0) {
criteria1.andCategoryIdEqualTo(catId);
criteria2.andCategoryIdEqualTo(catId);
}
if (!StringUtils.isEmpty(brandId)) {
criteria1.andBrandIdEqualTo(brandId);
criteria2.andBrandIdEqualTo(brandId);
}
if (!StringUtils.isEmpty(isNew)) {
criteria1.andIsNewEqualTo(isNew);
criteria2.andIsNewEqualTo(isNew);
}
if (!StringUtils.isEmpty(isHot)) {
criteria1.andIsHotEqualTo(isHot);
criteria2.andIsHotEqualTo(isHot);
}
if (!StringUtils.isEmpty(keywords)) {
criteria1.andKeywordsLike("%" + keywords + "%");
criteria2.andNameLike("%" + keywords + "%");
}
criteria1.andIsOnSaleEqualTo(true);
criteria2.andIsOnSaleEqualTo(true);
criteria1.andDeletedEqualTo(false);
criteria2.andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
}
public List<LitemallGoods> querySelective(String goodsSn, String name, Integer page, Integer size, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria = example.createCriteria();
......@@ -181,21 +146,6 @@ public class LitemallGoodsService {
return goodsMapper.selectByExampleWithBLOBs(example);
}
public int countSelective(String goodsSn, String name, Integer page, Integer size, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(goodsSn)) {
criteria.andGoodsSnEqualTo(goodsSn);
}
if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%");
}
criteria.andDeletedEqualTo(false);
return (int) goodsMapper.countByExample(example);
}
/**
* 获取某个商品信息,包含完整信息
*
......
......@@ -89,12 +89,6 @@ public class LitemallGrouponRulesService {
return grouponList;
}
public int countList(int offset, int limit, String sort, String order) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
example.or().andDeletedEqualTo(false);
return (int) mapper.countByExample(example);
}
/**
* 判断某个团购活动是否已经过期
*
......@@ -129,18 +123,6 @@ public class LitemallGrouponRulesService {
return mapper.selectByExample(example);
}
public int countSelective(String goodsId, Integer page, Integer limit, String sort, String order) {
LitemallGrouponRulesExample example = new LitemallGrouponRulesExample();
LitemallGrouponRulesExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(goodsId)) {
criteria.andGoodsIdEqualTo(Integer.parseInt(goodsId));
}
criteria.andDeletedEqualTo(false);
return (int) mapper.countByExample(example);
}
public void delete(Integer id) {
mapper.logicalDeleteByPrimaryKey(id);
}
......
......@@ -133,18 +133,4 @@ public class LitemallGrouponService {
PageHelper.startPage(page, size);
return mapper.selectByExample(example);
}
public int countSelective(String rulesId, Integer page, Integer limit, String sort, String order) {
LitemallGrouponExample example = new LitemallGrouponExample();
LitemallGrouponExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(rulesId)) {
criteria.andRulesIdEqualTo(Integer.parseInt(rulesId));
}
criteria.andDeletedEqualTo(false);
criteria.andPayedEqualTo(true);
criteria.andGrouponIdEqualTo(0);
return (int) mapper.countByExample(example);
}
}
......@@ -49,18 +49,6 @@ public class LitemallIssueService {
return issueMapper.selectByExample(example);
}
public int countSelective(String question, Integer page, Integer size, String sort, String order) {
LitemallIssueExample example = new LitemallIssueExample();
LitemallIssueExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(question)) {
criteria.andQuestionLike("%" + question + "%");
}
criteria.andDeletedEqualTo(false);
return (int) issueMapper.countByExample(example);
}
public int updateById(LitemallIssue issue) {
issue.setUpdateTime(LocalDateTime.now());
return issueMapper.updateByPrimaryKeySelective(issue);
......
......@@ -56,22 +56,6 @@ public class LitemallKeywordService {
return keywordsMapper.selectByExample(example);
}
public int countSelective(String keyword, String url, Integer page, Integer limit, String sort, String order) {
LitemallKeywordExample example = new LitemallKeywordExample();
LitemallKeywordExample.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(keyword)) {
criteria.andKeywordLike("%" + keyword + "%");
}
if (!StringUtils.isEmpty(url)) {
criteria.andUrlLike("%" + url + "%");
}
criteria.andDeletedEqualTo(false);
PageHelper.startPage(page, limit);
return (int) keywordsMapper.countByExample(example);
}
public void add(LitemallKeyword keywords) {
keywords.setAddTime(LocalDateTime.now());
keywords.setUpdateTime(LocalDateTime.now());
......
......@@ -115,21 +115,6 @@ public class LitemallOrderService {
return litemallOrderMapper.selectByExample(example);
}
public int countSelective(Integer userId, String orderSn, List<Short> orderStatusArray, Integer page, Integer size, String sort, String order) {
LitemallOrderExample example = new LitemallOrderExample();
LitemallOrderExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if (!StringUtils.isEmpty(orderSn)) {
criteria.andOrderSnEqualTo(orderSn);
}
criteria.andDeletedEqualTo(false);
return (int) litemallOrderMapper.countByExample(example);
}
public int updateWithOptimisticLocker(LitemallOrder order) {
LocalDateTime preUpdateTime = order.getUpdateTime();
order.setUpdateTime(LocalDateTime.now());
......
......@@ -56,7 +56,6 @@ public class LitemallPermissionService {
}
public boolean checkSuperPermission(Integer roleId) {
Set<String> permissions = new HashSet<String>();
if(roleId == null){
return false;
}
......
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