|
@@ -2,6 +2,7 @@ package com.huimv.manage.eartag.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.manage.dao.entity.EtApplyEntity;
|
|
|
import com.huimv.manage.dao.entity.EtPackageEntity;
|
|
|
import com.huimv.manage.dao.repo.PackageRepo;
|
|
|
import com.huimv.manage.eartag.service.IPackageService;
|
|
@@ -15,10 +16,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Example;
|
|
|
import org.springframework.data.domain.ExampleMatcher;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.persistence.criteria.Order;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
@@ -49,6 +56,37 @@ public class PackageServiceImpl implements IPackageService {
|
|
|
return new Result(ResultCode.SUCCESS,packageEntityList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result listPackage(Integer applyId, Integer packageId, Date startDate, Date endDate, Integer returnState, Integer pageSize, Integer pageNo) {
|
|
|
+ Specification<EtPackageEntity> spec = (Specification<EtPackageEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ //
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ if (null != applyId) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("applyId").as(Integer.class), applyId));
|
|
|
+ }
|
|
|
+ if (null != startDate) {
|
|
|
+ predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("startDate").as(Date.class), startDate));
|
|
|
+ }
|
|
|
+ if (null != endDate) {
|
|
|
+ predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("endDate").as(Date.class), endDate));
|
|
|
+ }
|
|
|
+ if (null != returnState) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("returnState").as(Integer.class), returnState));
|
|
|
+ }
|
|
|
+ //
|
|
|
+ Predicate[] pred = new Predicate[predList.size()];
|
|
|
+ Predicate and = criteriaBuilder.and(predList.toArray(pred));
|
|
|
+ criteriaQuery.where(and);
|
|
|
+ //
|
|
|
+ List<Order> orders = new ArrayList<>();
|
|
|
+ orders.add(criteriaBuilder.desc(root.get("id")));
|
|
|
+ return criteriaQuery.orderBy(orders).getRestriction();
|
|
|
+ };
|
|
|
+ //分页
|
|
|
+ Pageable pageable = PageRequest.of( pageNo - 1, pageSize);
|
|
|
+ return new Result(ResultCode.SUCCESS, packageRepo.findAll(spec, pageable));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Method : getNewPackage
|
|
|
* @Description :
|