|
|
@@ -341,40 +341,42 @@ public class ContractBillService {
|
|
|
public Page<ContractBill> arrearsContractBill(String search, LocalDate start, LocalDate end, Pageable pageable) {
|
|
|
List<Long> breaks = new ArrayList<>();
|
|
|
contractRepo.findByStatus(ContractStatus.BREAK).forEach(contract -> breaks.add(contract.getId()));
|
|
|
- List<Long> enabledStore = storeInfoRepo.findAllByStoreStatus(StoreStatus.BUSINESS).stream()
|
|
|
- .map(StoreInfo::getId).collect(Collectors.toList());
|
|
|
- List<Long> disabledContractIds = contractStoreRepo.findAllByStoreIdNotIn(enabledStore).stream()
|
|
|
- .map(ContractStore::getContractId).collect(Collectors.toList());
|
|
|
- return contractBillRepo.findAll((Specification<ContractBill>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = new ArrayList<>();
|
|
|
- and.add(criteriaBuilder.not(root.get("contractId").in(breaks)));
|
|
|
- and.add(criteriaBuilder.not(root.get("contractId").in(disabledContractIds)));
|
|
|
- and.add(criteriaBuilder.lessThan(root.get("rest"), BigDecimal.ZERO));
|
|
|
- if (StringUtils.isNotBlank(search)) {
|
|
|
- List<Long> customerIds = customerRepo.findByCoFullNameLikeOrCoSimpleNameLike(search, search)
|
|
|
- .stream()
|
|
|
- .map(Customer::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<Long> contracts = contractRepo.findAllByCustomerIdIn(customerIds)
|
|
|
- .stream()
|
|
|
- .map(Contract::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- and.add(root.get("contractId").in(contracts));
|
|
|
- }
|
|
|
- and.add(criteriaBuilder.not(criteriaBuilder.equal(root.get("status"), BillStatus.COMPLETED)));
|
|
|
- if (SecurityUtils.hasRole(Authority.NAME.ROLE_SALE)) {
|
|
|
- and.add(criteriaBuilder.equal(root.get("saleId"), SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
- }
|
|
|
- and.add(criteriaBuilder.not(criteriaBuilder.equal(root.get("recharged"), root.get("money"))));
|
|
|
- if (start != null & end != null) {
|
|
|
- and.add(criteriaBuilder
|
|
|
- .between(root.get("startTime"), start.atStartOfDay(), end.atTime(LocalTime.MAX)));
|
|
|
- }
|
|
|
- if (start == null) {
|
|
|
- and.add(criteriaBuilder
|
|
|
- .lessThanOrEqualTo(root.get("startTime"), LocalDate.now().atTime(LocalTime.MAX)));
|
|
|
- }
|
|
|
- return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
- }, pageable);
|
|
|
+ breaks.addAll(contractStoreRepo.findByStoreId(433L).stream()
|
|
|
+ .map(ContractStore::getContractId).collect(Collectors.toList()));
|
|
|
+ Page<ContractBill> orig = contractBillRepo
|
|
|
+ .findAll((Specification<ContractBill>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ and.add(criteriaBuilder.lessThan(root.get("rest"), BigDecimal.ZERO));
|
|
|
+ if (StringUtils.isNotBlank(search)) {
|
|
|
+ List<Long> customerIds = customerRepo.findByCoFullNameLikeOrCoSimpleNameLike(search, search)
|
|
|
+ .stream()
|
|
|
+ .map(Customer::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Long> contracts = contractRepo.findAllByCustomerIdIn(customerIds)
|
|
|
+ .stream()
|
|
|
+ .map(Contract::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ and.add(root.get("contractId").in(contracts));
|
|
|
+ }
|
|
|
+ and.add(criteriaBuilder.not(criteriaBuilder.equal(root.get("status"), BillStatus.COMPLETED)));
|
|
|
+ if (SecurityUtils.hasRole(Authority.NAME.ROLE_SALE)) {
|
|
|
+ and.add(criteriaBuilder
|
|
|
+ .equal(root.get("saleId"), SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
+ }
|
|
|
+ and.add(criteriaBuilder.not(criteriaBuilder.equal(root.get("recharged"), root.get("money"))));
|
|
|
+ if (start != null & end != null) {
|
|
|
+ and.add(criteriaBuilder
|
|
|
+ .between(root.get("startTime"), start.atStartOfDay(), end.atTime(LocalTime.MAX)));
|
|
|
+ }
|
|
|
+ if (start == null) {
|
|
|
+ and.add(criteriaBuilder
|
|
|
+ .lessThanOrEqualTo(root.get("startTime"), LocalDateTime.now()));
|
|
|
+ }
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ }, pageable);
|
|
|
+ List<ContractBill> content = orig.getContent();
|
|
|
+ List<ContractBill> result = content.stream()
|
|
|
+ .filter(contractBill -> !breaks.contains(contractBill.getContractId())).collect(Collectors.toList());
|
|
|
+ return new PageImpl<>(result, pageable, orig.getTotalElements());
|
|
|
}
|
|
|
}
|