|
@@ -7,10 +7,14 @@ import com.huimv.produce.repo.ProdDayWeightEntity;
|
|
|
import com.huimv.produce.repo.ProdDayWeightRepo;
|
|
|
import com.huimv.produce.service.IWeight;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.*;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import javax.persistence.criteria.*;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -89,4 +93,42 @@ public class WeightImpl implements IWeight {
|
|
|
return new Result(10001, "暂无数据.", false);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getWeightOnPage
|
|
|
+ * @Description : 分页查询称重记录
|
|
|
+ * @Params : [farmId, startDate, endDate, pageNo, pageSize]
|
|
|
+ * @Return : com.huimv.common.utils.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/12/7
|
|
|
+ * @Time : 14:56
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getWeightOnPage(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) {
|
|
|
+ Specification<ProdDayWeightEntity> sf = (Specification<ProdDayWeightEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ //
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ if (null != farmId) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("farmId").as(Integer.class), farmId));
|
|
|
+ }
|
|
|
+ if (null != startDate) {
|
|
|
+ predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(Date.class), startDate));
|
|
|
+ }
|
|
|
+ if (null != endDate) {
|
|
|
+ predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(Date.class), endDate));
|
|
|
+ }
|
|
|
+ //
|
|
|
+ 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,applyRepo.listApply(pageable,applyId));
|
|
|
+ return new Result(ResultCode.SUCCESS, dayWeightRepo.findAll(sf, pageable));
|
|
|
+ }
|
|
|
}
|