客户订单分页查询

pull/451/head
starrysky 2019-08-30 09:38:12 +08:00
parent 6f46a259f4
commit e66523c346
6 changed files with 64 additions and 6 deletions

View File

@ -19,6 +19,10 @@ public interface ProductInfoRepository extends JpaRepository<ProductInfo, Long>,
*/
ProductInfo findByIdAndStatusTrue(long id);
ProductInfo findByProductCode(String productCode);
/**
*
* @param id

View File

@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.customerOrder.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.sql.Timestamp;
import java.io.Serializable;
@ -17,6 +19,7 @@ import java.io.Serializable;
public class CustomerOrderProduct implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ -54,10 +57,12 @@ public class CustomerOrderProduct implements Serializable {
// 创建时间
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
// 更新时间
@Column(name = "update_time")
@CreationTimestamp
private Timestamp updateTime;
// 状态

View File

@ -2,7 +2,11 @@ package me.zhengjie.modules.wms.customerOrder.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
import me.zhengjie.modules.wms.bd.repository.CustomerInfoRepository;
import me.zhengjie.modules.wms.bd.repository.ProductInfoRepository;
import me.zhengjie.modules.wms.bd.service.dto.SupplierInfoDTO;
import me.zhengjie.modules.wms.bd.service.mapper.CustomerInfoMapper;
import me.zhengjie.modules.wms.customerOrder.domain.CustomerOrderProduct;
import me.zhengjie.modules.wms.customerOrder.repository.CustomerOrderRepository;
@ -20,6 +24,7 @@ import me.zhengjie.modules.wms.customerOrder.service.mapper.CustomerOrderMapper;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@ -37,6 +42,11 @@ import me.zhengjie.utils.PageUtil;
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
* @date 2019-08-03
@ -63,10 +73,42 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
@Autowired
private CustomerInfoRepository customerInfoRepository;
@Autowired
private ProductInfoRepository productInfoRepository;
@Override
public Object queryAll(CustomerOrderQueryCriteria criteria, Pageable pageable){
Page<CustomerOrder> page = customerOrderRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(customerOrderMapper::toDto));
Specification<CustomerOrder> specification = new Specification<CustomerOrder>() {
@Override
public Predicate toPredicate(Root<CustomerOrder> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> targetPredicateList = new ArrayList<>();
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
targetPredicateList.add(statusPredicate);
if(CollectionUtils.isEmpty(targetPredicateList)){
return null;
}else{
return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()]));
}
}
};
Page<CustomerOrder> page = customerOrderRepository.findAll(specification, pageable);
Page<CustomerOrderDTO> customerOrderDTOPage = page.map(customerOrderMapper::toDto);
if(null != customerOrderDTOPage){
List<CustomerOrderDTO> customerOrderDTOList = customerOrderDTOPage.getContent();
if(!CollectionUtils.isEmpty(customerOrderDTOList)){
for(CustomerOrderDTO customerOrderDTO : customerOrderDTOList){
List<CustomerOrderProduct> customerOrderProductList = customerOrderProductRepository.findByCustomerOrderIdAndStatusTrue(customerOrderDTO.getId());
List<CustomerOrderProductDTO> customerOrderProductDTOList = customerOrderProductMapper.toDto(customerOrderProductList);
customerOrderDTO.setCustomerOrderProductList(customerOrderProductDTOList);
}
}
}
return PageUtil.toPage(customerOrderDTOPage);
}
@Override
@ -127,6 +169,9 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
BeanUtils.copyProperties(customerOrderProductRequest, customerOrderProduct);
customerOrderProduct.setCustomerOrderId(customerOrder.getId());
customerOrderProduct.setStatus(true);
ProductInfo productInfo = productInfoRepository.findByProductCode(customerOrderProductRequest.getProductCode());
customerOrderProduct.setProductId(productInfo.getId());
customerOrderProductList.add(customerOrderProduct);
}
customerOrderProductRepository.saveAll(customerOrderProductList);

View File

@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.invoice.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.sql.Timestamp;
import java.io.Serializable;
@ -23,10 +25,12 @@ public class InvoiceProduct implements Serializable {
// 创建时间
@Column(name = "create_status")
@CreationTimestamp
private Timestamp createStatus;
// 更新时间
@Column(name = "update_status")
@CreationTimestamp
private Timestamp updateStatus;
// 状态
@ -54,8 +58,8 @@ public class InvoiceProduct implements Serializable {
private Long customerOrderNumber;
// 实际发货单数量
@Column(name = "acutal_invoice_number",nullable = false)
private Long acutalInvoiceNumber;
@Column(name = "actual_invoice_number",nullable = false)
private Long actualInvoiceNumber;
// 瘦瘦金额
@Column(name = "sale_price")

View File

@ -39,7 +39,7 @@ public class InvoiceProductDTO implements Serializable {
private Long customerOrderNumber;
// 实际发货单数量
private Long acutalInvoiceNumber;
private Long actualInvoiceNumber;
// 瘦瘦金额
private Long salePrice;

View File

@ -3,7 +3,7 @@ server:
spring:
profiles:
active: dev
active: prod
jackson:
time-zone: GMT+8
data: