|
|
@@ -1,42 +1,50 @@ |
|
|
|
package com.qtzl.alterSales.manager.handler; |
|
|
|
|
|
|
|
import cn.com.taiji.common.manager.net.http.ServiceHandleException; |
|
|
|
import cn.com.taiji.common.model.dao.Pagination; |
|
|
|
import cn.com.taiji.common.pub.BeanTools; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.qtzl.alterSales.dao.entity.second.AflProductInfo; |
|
|
|
import com.qtzl.alterSales.dao.repo.jpa.second.AflProductInfoRepo; |
|
|
|
import com.qtzl.alterSales.manager.abstracts.AbstractAfterSalesManager; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.UcServiceError; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.sales.AflProductInfoFindPageRequest; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.sales.AflProductInfoFindPageResponse; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.sales.AflProductInfoFindPageViweRequest; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.sales.AflProductInfoFindPageViewRequest; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.sales.AflProductInfoFindPageViewResponse; |
|
|
|
import com.qtzl.alterSales.manager.service.AfterSalesCmd; |
|
|
|
import com.qtzl.alterSales.manager.vo.AflProductInfoFindPageVo; |
|
|
|
import com.txffp.api.core.manager.comm.annotation.ApiHandler; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.data.domain.Page; |
|
|
|
import org.springframework.data.domain.PageRequest; |
|
|
|
import org.springframework.data.domain.Sort; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.persistence.criteria.Predicate; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询产品管理 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@ApiHandler |
|
|
|
public class AflProductFindPageHandler extends AbstractAfterSalesManager<AflProductInfoFindPageViweRequest> { |
|
|
|
public class AflProductFindPageHandler extends AbstractAfterSalesManager<AflProductInfoFindPageViewRequest> { |
|
|
|
|
|
|
|
@Resource |
|
|
|
AflProductInfoRepo aflProductInfoRepo; |
|
|
|
|
|
|
|
|
|
|
|
public AflProductFindPageHandler() { |
|
|
|
super(AfterSalesCmd.FINDPAGEPRODUCTINFO, AflProductInfoFindPageViweRequest.class); |
|
|
|
super(AfterSalesCmd.FINDPAGEPRODUCTINFO, AflProductInfoFindPageViewRequest.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String handleInternal(String filename, AflProductInfoFindPageViweRequest request) throws ServiceHandleException { |
|
|
|
public String handleInternal(String filename, AflProductInfoFindPageViewRequest request) throws ServiceHandleException { |
|
|
|
try { |
|
|
|
Pagination page =select(request); |
|
|
|
return toResponse(page).toJson(); |
|
|
|
// Pagination page =select(request); |
|
|
|
Page<AflProductInfo> page = select(request); |
|
|
|
return toResponse(page,request).toJson(); |
|
|
|
} catch (Exception e) { |
|
|
|
if (e instanceof ServiceHandleException) { |
|
|
|
throw e; |
|
|
@@ -46,23 +54,71 @@ public class AflProductFindPageHandler extends AbstractAfterSalesManager<AflProd |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private AflProductInfoFindPageResponse toResponse(Pagination pagination) { |
|
|
|
final AflProductInfoFindPageResponse response = new AflProductInfoFindPageResponse(); |
|
|
|
BeanTools.copyProperties(pagination, response); |
|
|
|
if (isEmpty(pagination.getResult())) { |
|
|
|
private AflProductInfoFindPageViewResponse toResponse(Page<AflProductInfo> page, AflProductInfoFindPageViewRequest request) { |
|
|
|
final AflProductInfoFindPageViewResponse response = new AflProductInfoFindPageViewResponse(); |
|
|
|
response.setCurrentPage(request.getPageNo()); |
|
|
|
response.setPageSize(request.getPageSize()); |
|
|
|
response.setPageCount(page.getTotalPages()); |
|
|
|
response.setTotalCount(page.getTotalElements()); |
|
|
|
if (isEmpty(page.getContent())) { |
|
|
|
response.setData(Lists.newArrayList()); |
|
|
|
return response; |
|
|
|
} |
|
|
|
response.setData(pagination.getResult(AflProductInfoFindPageVo.class)); |
|
|
|
List<AflProductInfoFindPageVo> formVoList = page.getContent().stream().map(this::toVo).collect(Collectors.toList()); |
|
|
|
response.setData(formVoList); |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
private Pagination select(AflProductInfoFindPageViweRequest request) throws ServiceHandleException { |
|
|
|
|
|
|
|
private Page<AflProductInfo> select(AflProductInfoFindPageViewRequest request) throws ServiceHandleException { |
|
|
|
if (request.getPageSize() > 100) { |
|
|
|
throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请求每页数量过大 " + request.getPageSize()); |
|
|
|
} |
|
|
|
AflProductInfoFindPageRequest queryRequest = new AflProductInfoFindPageRequest(); |
|
|
|
BeanUtil.copyProperties(request, queryRequest); |
|
|
|
return aflProductInfoRepo.page(queryRequest); |
|
|
|
return aflProductInfoRepo.findAll(((root, query, cb) -> { |
|
|
|
List<Predicate> list = Lists.newArrayList(); |
|
|
|
if (!StringUtils.isEmpty(request.getProductCode())) { |
|
|
|
list.add(cb.equal(root.<String>get("productCode"), request.getProductCode())); |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(request.getProductName())) { |
|
|
|
list.add(cb.equal(root.get("productName"), request.getProductName())); |
|
|
|
} |
|
|
|
if (request.getAuditStatus()!=null) { |
|
|
|
list.add(cb.equal(root.<Integer>get("auditStatus"), request.getAuditStatus())); |
|
|
|
} |
|
|
|
if (request.getGroundStatus()!=null) { |
|
|
|
list.add(cb.equal(root.<Integer>get("groundStatus"), request.getGroundStatus())); |
|
|
|
} |
|
|
|
if (request.getGroundTimeEnd()!=null) { |
|
|
|
list.add(cb.lessThanOrEqualTo(root.<Date>get("groundTime"), request.getGroundTimeEnd())); |
|
|
|
} |
|
|
|
if (request.getGroundTimeStart()!=null) { |
|
|
|
list.add(cb.greaterThanOrEqualTo(root.<Date>get("groundTime"), request.getGroundTimeStart())); |
|
|
|
} |
|
|
|
if (request.getUndercarriageTimeEnd()!=null) { |
|
|
|
list.add(cb.lessThanOrEqualTo(root.<Date>get("undercarriageTime"), request.getUndercarriageTimeEnd())); |
|
|
|
} |
|
|
|
if (request.getUndercarriageTimeStart()!=null) { |
|
|
|
list.add(cb.greaterThanOrEqualTo(root.<Date>get("undercarriageTime"), request.getUndercarriageTimeStart())); |
|
|
|
} |
|
|
|
if (request.getInsertTimeEnd()!=null) { |
|
|
|
list.add(cb.lessThanOrEqualTo(root.<Date>get("insertTime"), request.getInsertTimeEnd())); |
|
|
|
} |
|
|
|
if (request.getInsertTimeStart()!=null) { |
|
|
|
list.add(cb.greaterThanOrEqualTo(root.<Date>get("insertTime"), request.getInsertTimeStart())); |
|
|
|
} |
|
|
|
//查询为未删除的数据 |
|
|
|
list.add(cb.equal(root.<Integer>get("isDelete"), 0)); |
|
|
|
Predicate[] p = new Predicate[list.size()]; |
|
|
|
return cb.and(list.toArray(p)); |
|
|
|
}), PageRequest.of(request.getPageNo() - 1, request.getPageSize(), |
|
|
|
Sort.by(Sort.Direction.DESC, "insertTime"))); |
|
|
|
} |
|
|
|
private AflProductInfoFindPageVo toVo(AflProductInfo aflProductInfo) { |
|
|
|
AflProductInfoFindPageVo aflProductInfoFindPageVo = new AflProductInfoFindPageVo(); |
|
|
|
BeanUtils.copyProperties(aflProductInfo,aflProductInfoFindPageVo); |
|
|
|
return aflProductInfoFindPageVo; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|