mirror of https://github.com/elunez/eladmin
产品统计查询
parent
53e42224aa
commit
4a51325b5a
|
@ -120,7 +120,7 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
|
||||||
targetPredicateList.add(customerNamePredicate);
|
targetPredicateList.add(customerNamePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("createTime")));
|
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("updateTime")));
|
||||||
|
|
||||||
if(CollectionUtils.isEmpty(targetPredicateList)){
|
if(CollectionUtils.isEmpty(targetPredicateList)){
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -10,4 +10,36 @@ import me.zhengjie.annotation.Query;
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ProductCountQueryCriteria {
|
public class ProductCountQueryCriteria {
|
||||||
|
//产品名称
|
||||||
|
private String productName;
|
||||||
|
|
||||||
|
//产品类别名称
|
||||||
|
private String productCategoryName;
|
||||||
|
|
||||||
|
//产品系列名称
|
||||||
|
private String productSeriesName;
|
||||||
|
|
||||||
|
public String getProductName() {
|
||||||
|
return productName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductName(String productName) {
|
||||||
|
this.productName = productName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProductCategoryName() {
|
||||||
|
return productCategoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductCategoryName(String productCategoryName) {
|
||||||
|
this.productCategoryName = productCategoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProductSeriesName() {
|
||||||
|
return productSeriesName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductSeriesName(String productSeriesName) {
|
||||||
|
this.productSeriesName = productSeriesName;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,9 @@ import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
|
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
|
||||||
import me.zhengjie.modules.wms.bd.repository.ProductInfoRepository;
|
import me.zhengjie.modules.wms.bd.repository.ProductInfoRepository;
|
||||||
import me.zhengjie.modules.wms.bd.service.mapper.ProductInfoMapper;
|
import me.zhengjie.modules.wms.bd.service.mapper.ProductInfoMapper;
|
||||||
|
import me.zhengjie.modules.wms.customerOrder.domain.CustomerOrder;
|
||||||
import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount;
|
import me.zhengjie.modules.wms.sr.productCount.domain.ProductCount;
|
||||||
|
import me.zhengjie.utils.StringUtils;
|
||||||
import me.zhengjie.utils.ValidationUtil;
|
import me.zhengjie.utils.ValidationUtil;
|
||||||
import me.zhengjie.modules.wms.sr.productCount.repository.ProductCountRepository;
|
import me.zhengjie.modules.wms.sr.productCount.repository.ProductCountRepository;
|
||||||
import me.zhengjie.modules.wms.sr.productCount.service.ProductCountService;
|
import me.zhengjie.modules.wms.sr.productCount.service.ProductCountService;
|
||||||
|
@ -12,14 +14,24 @@ import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountDTO;
|
||||||
import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountQueryCriteria;
|
import me.zhengjie.modules.wms.sr.productCount.service.dto.ProductCountQueryCriteria;
|
||||||
import me.zhengjie.modules.wms.sr.productCount.service.mapper.ProductCountMapper;
|
import me.zhengjie.modules.wms.sr.productCount.service.mapper.ProductCountMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import me.zhengjie.utils.PageUtil;
|
import me.zhengjie.utils.PageUtil;
|
||||||
import me.zhengjie.utils.QueryHelp;
|
import me.zhengjie.utils.QueryHelp;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jie
|
* @author jie
|
||||||
|
@ -43,6 +55,42 @@ public class ProductCountServiceImpl implements ProductCountService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object queryAll(ProductCountQueryCriteria criteria, Pageable pageable){
|
public Object queryAll(ProductCountQueryCriteria criteria, Pageable pageable){
|
||||||
|
|
||||||
|
Specification<ProductCount> specification = new Specification<ProductCount>() {
|
||||||
|
@Override
|
||||||
|
public Predicate toPredicate(Root<ProductCount> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
||||||
|
|
||||||
|
List<Predicate> targetPredicateList = new ArrayList<>();
|
||||||
|
|
||||||
|
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
|
||||||
|
targetPredicateList.add(statusPredicate);
|
||||||
|
|
||||||
|
|
||||||
|
if(!StringUtils.isEmpty(criteria.getProductName())){
|
||||||
|
Predicate customerOrderCodePredicate = criteriaBuilder.like(root.get("productName").as(String.class), "%" + criteria.getProductName() + "%");
|
||||||
|
targetPredicateList.add(customerOrderCodePredicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!StringUtils.isEmpty(criteria.getProductCategoryName())){
|
||||||
|
Predicate customerNamePredicate = criteriaBuilder.like(root.get("productCategoryName").as(String.class), "%" + criteria.getProductCategoryName() + "%");
|
||||||
|
targetPredicateList.add(customerNamePredicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!StringUtils.isEmpty(criteria.getProductSeriesName())){
|
||||||
|
Predicate customerNamePredicate = criteriaBuilder.like(root.get("productSeriesName").as(String.class), "%" + criteria.getProductSeriesName() + "%");
|
||||||
|
targetPredicateList.add(customerNamePredicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("gmtUpdate")));
|
||||||
|
|
||||||
|
if(CollectionUtils.isEmpty(targetPredicateList)){
|
||||||
|
return null;
|
||||||
|
}else{
|
||||||
|
return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Page<ProductCount> page = productCountRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
Page<ProductCount> page = productCountRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||||
return PageUtil.toPage(page.map(productCountMapper::toDto));
|
return PageUtil.toPage(page.map(productCountMapper::toDto));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue