Commit 3abfeea8 authored by Junling Bu's avatar Junling Bu
Browse files

修复商品排序问题

parent d2a561f3
...@@ -44,6 +44,10 @@ public class LitemallBrandService { ...@@ -44,6 +44,10 @@ public class LitemallBrandService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return brandMapper.selectByExample(example); return brandMapper.selectByExample(example);
} }
......
...@@ -5,6 +5,7 @@ import org.linlinjava.litemall.db.dao.LitemallCartMapper; ...@@ -5,6 +5,7 @@ import org.linlinjava.litemall.db.dao.LitemallCartMapper;
import org.linlinjava.litemall.db.domain.LitemallCart; import org.linlinjava.litemall.db.domain.LitemallCart;
import org.linlinjava.litemall.db.domain.LitemallCartExample; import org.linlinjava.litemall.db.domain.LitemallCartExample;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -77,14 +78,18 @@ public class LitemallCartService { ...@@ -77,14 +78,18 @@ public class LitemallCartService {
LitemallCartExample example = new LitemallCartExample(); LitemallCartExample example = new LitemallCartExample();
LitemallCartExample.Criteria criteria = example.createCriteria(); LitemallCartExample.Criteria criteria = example.createCriteria();
if(userId != null){ if(!StringUtils.isEmpty(userId)){
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
} }
if(goodsId != null){ if(!StringUtils.isEmpty(goodsId)){
criteria.andGoodsIdEqualTo(goodsId); criteria.andGoodsIdEqualTo(goodsId);
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
return cartMapper.selectByExample(example); return cartMapper.selectByExample(example);
} }
......
...@@ -63,6 +63,10 @@ public class LitemallCategoryService { ...@@ -63,6 +63,10 @@ public class LitemallCategoryService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return categoryMapper.selectByExample(example); return categoryMapper.selectByExample(example);
} }
......
...@@ -61,6 +61,10 @@ public class LitemallCollectService { ...@@ -61,6 +61,10 @@ public class LitemallCollectService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return collectMapper.selectByExample(example); return collectMapper.selectByExample(example);
} }
......
...@@ -83,6 +83,10 @@ public class LitemallCommentService { ...@@ -83,6 +83,10 @@ public class LitemallCommentService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return commentMapper.selectByExample(example); return commentMapper.selectByExample(example);
} }
......
package org.linlinjava.litemall.db.service;
import org.springframework.stereotype.Service;
@Service
public class LitemallCouponService {
}
...@@ -53,6 +53,10 @@ public class LitemallFootprintService { ...@@ -53,6 +53,10 @@ public class LitemallFootprintService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return footprintMapper.selectByExample(example); return footprintMapper.selectByExample(example);
} }
......
...@@ -20,31 +20,6 @@ public class LitemallGoodsAttributeService { ...@@ -20,31 +20,6 @@ public class LitemallGoodsAttributeService {
return goodsAttributeMapper.selectByExample(example); return goodsAttributeMapper.selectByExample(example);
} }
public List<LitemallGoodsAttribute> querySelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
LitemallGoodsAttributeExample example = new LitemallGoodsAttributeExample();
LitemallGoodsAttributeExample.Criteria criteria = example.createCriteria();
if(goodsId != null){
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
PageHelper.startPage(page, size);
return goodsAttributeMapper.selectByExample(example);
}
public int countSelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
LitemallGoodsAttributeExample example = new LitemallGoodsAttributeExample();
LitemallGoodsAttributeExample.Criteria criteria = example.createCriteria();
if(goodsId != null){
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
return (int)goodsAttributeMapper.countByExample(example);
}
public void updateById(LitemallGoodsAttribute goodsAttribute) { public void updateById(LitemallGoodsAttribute goodsAttribute) {
goodsAttributeMapper.updateByPrimaryKeySelective(goodsAttribute); goodsAttributeMapper.updateByPrimaryKeySelective(goodsAttribute);
} }
......
...@@ -58,31 +58,32 @@ public class LitemallGoodsService { ...@@ -58,31 +58,32 @@ public class LitemallGoodsService {
return (int)goodsMapper.countByExample(example); return (int)goodsMapper.countByExample(example);
} }
public List<LitemallGoods> querySelective(Integer catId, Integer brandId, String keyword, Integer isHot, Integer isNew, Integer offset, Integer limit, String sort) { public List<LitemallGoods> querySelective(Integer catId, Integer brandId, String keyword, Boolean isHot, Boolean isNew, Integer offset, Integer limit, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria = example.createCriteria(); LitemallGoodsExample.Criteria criteria = example.createCriteria();
if(catId != null && catId != 0){ if(!StringUtils.isEmpty(catId) && catId != 0){
criteria.andCategoryIdEqualTo(catId); criteria.andCategoryIdEqualTo(catId);
} }
if(brandId != null){ if(!StringUtils.isEmpty(brandId)){
criteria.andBrandIdEqualTo(brandId); criteria.andBrandIdEqualTo(brandId);
} }
if(isNew != null){ if(!StringUtils.isEmpty(isNew)){
criteria.andIsNewEqualTo(isNew.intValue() == 1); criteria.andIsNewEqualTo(isNew);
} }
if(isHot != null){ if(!StringUtils.isEmpty(isHot)){
criteria.andIsHotEqualTo(isHot.intValue() == 1); criteria.andIsHotEqualTo(isHot);
} }
if(keyword != null){ if(!StringUtils.isEmpty(keyword)){
criteria.andKeywordsLike("%" + keyword + "%"); criteria.andKeywordsLike("%" + keyword + "%");
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if(sort != null){ if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort); example.setOrderByClause(sort + " " + order);
} }
if(limit != null && offset != null) {
if(!StringUtils.isEmpty(limit) && !StringUtils.isEmpty(offset)) {
PageHelper.startPage(offset, limit); PageHelper.startPage(offset, limit);
} }
...@@ -90,7 +91,7 @@ public class LitemallGoodsService { ...@@ -90,7 +91,7 @@ public class LitemallGoodsService {
return goodsMapper.selectByExampleSelective(example ,columns); return goodsMapper.selectByExampleSelective(example ,columns);
} }
public int countSelective(Integer catId, Integer brandId, String keyword, Integer isHot, Integer isNew, Integer offset, Integer limit, String sort) { public int countSelective(Integer catId, Integer brandId, String keyword, Boolean isHot, Boolean isNew, Integer offset, Integer limit, String sort, String order) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria = example.createCriteria(); LitemallGoodsExample.Criteria criteria = example.createCriteria();
...@@ -101,10 +102,10 @@ public class LitemallGoodsService { ...@@ -101,10 +102,10 @@ public class LitemallGoodsService {
criteria.andBrandIdEqualTo(brandId); criteria.andBrandIdEqualTo(brandId);
} }
if(isNew != null){ if(isNew != null){
criteria.andIsNewEqualTo(isNew.intValue() == 1); criteria.andIsNewEqualTo(isNew);
} }
if(isHot != null){ if(isHot != null){
criteria.andIsHotEqualTo(isHot.intValue() == 1); criteria.andIsHotEqualTo(isHot);
} }
if(keyword != null){ if(keyword != null){
criteria.andKeywordsLike("%" + keyword + "%"); criteria.andKeywordsLike("%" + keyword + "%");
...@@ -182,7 +183,7 @@ public class LitemallGoodsService { ...@@ -182,7 +183,7 @@ public class LitemallGoodsService {
return (int)goodsMapper.countByExample(example); return (int)goodsMapper.countByExample(example);
} }
public List<Integer> getCatIds(Integer brandId, String keyword, Integer isHot, Integer isNew) { public List<Integer> getCatIds(Integer brandId, String keyword, Boolean isHot, Boolean isNew) {
LitemallGoodsExample example = new LitemallGoodsExample(); LitemallGoodsExample example = new LitemallGoodsExample();
LitemallGoodsExample.Criteria criteria = example.createCriteria(); LitemallGoodsExample.Criteria criteria = example.createCriteria();
...@@ -190,10 +191,10 @@ public class LitemallGoodsService { ...@@ -190,10 +191,10 @@ public class LitemallGoodsService {
criteria.andBrandIdEqualTo(brandId); criteria.andBrandIdEqualTo(brandId);
} }
if(isNew != null){ if(isNew != null){
criteria.andIsNewEqualTo(isNew.intValue() == 1); criteria.andIsNewEqualTo(isNew);
} }
if(isHot != null){ if(isHot != null){
criteria.andIsHotEqualTo(isHot.intValue() == 1); criteria.andIsHotEqualTo(isHot);
} }
if(keyword != null){ if(keyword != null){
criteria.andKeywordsLike("%" + keyword + "%"); criteria.andKeywordsLike("%" + keyword + "%");
......
...@@ -27,31 +27,6 @@ public class LitemallGoodsSpecificationService { ...@@ -27,31 +27,6 @@ public class LitemallGoodsSpecificationService {
return goodsSpecificationMapper.selectByPrimaryKey(id); return goodsSpecificationMapper.selectByPrimaryKey(id);
} }
public List<LitemallGoodsSpecification> querySelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
LitemallGoodsSpecificationExample example = new LitemallGoodsSpecificationExample();
LitemallGoodsSpecificationExample.Criteria criteria = example.createCriteria();
if(goodsId != null){
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
PageHelper.startPage(page, size);
return goodsSpecificationMapper.selectByExample(example);
}
public int countSelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
LitemallGoodsSpecificationExample example = new LitemallGoodsSpecificationExample();
LitemallGoodsSpecificationExample.Criteria criteria = example.createCriteria();
if(goodsId != null){
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
return (int)goodsSpecificationMapper.countByExample(example);
}
public void updateById(LitemallGoodsSpecification goodsSpecification) { public void updateById(LitemallGoodsSpecification goodsSpecification) {
goodsSpecificationMapper.updateByPrimaryKeySelective(goodsSpecification); goodsSpecificationMapper.updateByPrimaryKeySelective(goodsSpecification);
} }
...@@ -70,15 +45,6 @@ public class LitemallGoodsSpecificationService { ...@@ -70,15 +45,6 @@ public class LitemallGoodsSpecificationService {
goodsSpecificationMapper.insertSelective(goodsSpecification); goodsSpecificationMapper.insertSelective(goodsSpecification);
} }
public Integer[] queryIdsByGid(Integer goodsId) {
List<LitemallGoodsSpecification> goodsSpecificationList = queryByGid(goodsId);
Integer[] ids = new Integer[goodsSpecificationList.size()];
for(int i = 0; i < ids.length; i++){
ids[i] = goodsSpecificationList.get(i).getId();
}
return ids;
}
private class VO { private class VO {
private String name; private String name;
private List<LitemallGoodsSpecification> valueList; private List<LitemallGoodsSpecification> valueList;
......
...@@ -38,6 +38,10 @@ public class LitemallIssueService { ...@@ -38,6 +38,10 @@ public class LitemallIssueService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return issueMapper.selectByExample(example); return issueMapper.selectByExample(example);
} }
......
...@@ -53,6 +53,10 @@ public class LitemallKeywordService { ...@@ -53,6 +53,10 @@ public class LitemallKeywordService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
return keywordsMapper.selectByExample(example); return keywordsMapper.selectByExample(example);
} }
......
...@@ -75,7 +75,7 @@ public class LitemallOrderService { ...@@ -75,7 +75,7 @@ public class LitemallOrderService {
public List<LitemallOrder> queryByOrderStatus(Integer userId, List<Short> orderStatus) { public List<LitemallOrder> queryByOrderStatus(Integer userId, List<Short> orderStatus) {
LitemallOrderExample example = new LitemallOrderExample(); LitemallOrderExample example = new LitemallOrderExample();
example.orderBy(LitemallOrder.Column.addTime.desc()); example.setOrderByClause(LitemallOrder.Column.addTime.desc());
LitemallOrderExample.Criteria criteria = example.or(); LitemallOrderExample.Criteria criteria = example.or();
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
if(orderStatus != null) { if(orderStatus != null) {
...@@ -112,6 +112,10 @@ public class LitemallOrderService { ...@@ -112,6 +112,10 @@ public class LitemallOrderService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return orderMapper.selectByExample(example); return orderMapper.selectByExample(example);
} }
......
...@@ -24,31 +24,6 @@ public class LitemallProductService { ...@@ -24,31 +24,6 @@ public class LitemallProductService {
return productMapper.selectByPrimaryKey(id); return productMapper.selectByPrimaryKey(id);
} }
public List<LitemallProduct> querySelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
LitemallProductExample example = new LitemallProductExample();
LitemallProductExample.Criteria criteria = example.createCriteria();
if(goodsId != null){
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
PageHelper.startPage(page, size);
return productMapper.selectByExample(example);
}
public int countSelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
LitemallProductExample example = new LitemallProductExample();
LitemallProductExample.Criteria criteria = example.createCriteria();
if(goodsId != null){
criteria.andGoodsIdEqualTo(goodsId);
}
criteria.andDeletedEqualTo(false);
return (int)productMapper.countByExample(example);
}
public void updateById(LitemallProduct product) { public void updateById(LitemallProduct product) {
productMapper.updateByPrimaryKeySelective(product); productMapper.updateByPrimaryKeySelective(product);
} }
......
...@@ -32,9 +32,14 @@ public class LitemallRegionService { ...@@ -32,9 +32,14 @@ public class LitemallRegionService {
if(!StringUtils.isEmpty(name)){ if(!StringUtils.isEmpty(name)){
criteria.andNameLike("%" + name + "%"); criteria.andNameLike("%" + name + "%");
} }
if(code != null){ if(!StringUtils.isEmpty(code)){
criteria.andCodeEqualTo(code); criteria.andCodeEqualTo(code);
} }
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return regionMapper.selectByExample(example); return regionMapper.selectByExample(example);
} }
......
...@@ -57,6 +57,10 @@ public class LitemallSearchHistoryService { ...@@ -57,6 +57,10 @@ public class LitemallSearchHistoryService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return searchHistoryMapper.selectByExample(example); return searchHistoryMapper.selectByExample(example);
} }
......
...@@ -58,6 +58,10 @@ public class LitemallStorageService { ...@@ -58,6 +58,10 @@ public class LitemallStorageService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
return storageMapper.selectByExample(example); return storageMapper.selectByExample(example);
} }
......
...@@ -66,6 +66,10 @@ public class LitemallTopicService { ...@@ -66,6 +66,10 @@ public class LitemallTopicService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
return topicMapper.selectByExampleWithBLOBs(example); return topicMapper.selectByExampleWithBLOBs(example);
} }
......
...@@ -44,6 +44,10 @@ public class LitemallUserService { ...@@ -44,6 +44,10 @@ public class LitemallUserService {
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
return userMapper.selectByExample(example); return userMapper.selectByExample(example);
} }
......
package org.linlinjava.litemall.db.util;
public class SortUtil {
public static final String goodsSort(String sort, String order){
if(sort == null){
return null;
}
String sortWithOrder = "";
if(sort.equalsIgnoreCase("price")){
sortWithOrder = "retail_price";
}
else if(sort.equalsIgnoreCase("default") || sort.equalsIgnoreCase("category")){
return null;
}
else{
return null;
}
if(order == null) {
return sortWithOrder;
}
if(order.equalsIgnoreCase("asc")){
sortWithOrder += " ASC";
}
else if(order.equalsIgnoreCase("DESC")){
sortWithOrder += " DESC";
}
return sortWithOrder;
}
}
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