首页 > 数据库 >jpaJAVASql

jpaJAVASql

时间:2022-08-24 19:25:30浏览次数:50  
标签:QCarInfo qCarInfo expression QCarBinding jpaJAVASql eq carListPCInputParam

        QCarInfo qCarInfo = QCarInfo.qCarInfo;
        BooleanExpression expression = qCarInfo.valid.eq(true);
        if(StringUtils.isNotEmpty(carListPCInputParam.getSnCode())){
            expression = expression.and(qCarInfo.snCode.contains(carListPCInputParam.getSnCode()));
        }

        if(!Objects.isNull(carListPCInputParam.getBrandId())){
            expression = expression.and(qCarInfo.brandId.eq(carListPCInputParam.getBrandId()));
        }

        if(StringUtils.isNotEmpty(carListPCInputParam.getImei())){
            expression = expression.and(qCarInfo.imei.contains(carListPCInputParam.getImei()));
        }

        if(StringUtils.isNotEmpty(carListPCInputParam.getVinNumber())){
            expression = expression.and(qCarInfo.vinNumber.contains(carListPCInputParam.getVinNumber()));
        }

        if(!Objects.isNull(carListPCInputParam.getState())){
            expression = expression.and(qCarInfo.state.eq(carListPCInputParam.getState()));
        }
        if(!Objects.isNull(carListPCInputParam.getBindingstate())){
            expression = expression.leftJoin(QCarBinding.qCarBinding).on(QCarInfo.qCarInfo.id.eq(QCarBinding.qCarBinding.carId)).contains();
        }
        
        
        JPAExpressions.selectFrom()
        Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
        Page<CarInfo> carInfoPage = carInfoRepository.findAll(expression, PageRequest.of(carListPCInputParam.getPage(), carListPCInputParam.getSize(), sort));

        //提取carModel需要的内容输出CarModelOutput
        List<CarInfoToPC.CarInfoToPCList> carInfoToPCList = OutputUtils.ModelListToOutputList(carInfoPage.getContent(),CarInfoToPC.CarInfoToPCList.class);

        return new RestPage<CarInfoToPC.CarInfoToPCList>(carInfoPage,carInfoToPCList);
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		   @Override
    public RestPage<CarInfoToPC.CarInfoToPCList> carList(CarInfoInput.CarListPCInputParam carListPCInputParam) throws InstantiationException, IllegalAccessException {


        JPAQueryFactory jpaQueryFactory = new JPAQueryFactory(entityManager);

        List<CarInfoToPC.CarInfoToPCList> fetch = jpaQueryFactory.select(Projections.constructor(
                CarInfoToPC.CarInfoToPCList.class,
                QCarInfo.qcarInfo
        )).from(QCarInfo.qcarInfo).fetch();

//        JPQLQuery<CarInfoToPC.CarInfoToPCList> leftJoin = JPAExpressions
//                .select(
//                        Projections.bean(
//                                CarInfoToPC.CarInfoToPCList.class,
//                                QCarInfo.qCarInfo,
//                                QCarBinding.qCarBinding.state.as("bindingState"),
//                                QCarBinding.qCarBinding.bindingTime.as("bindingTime")
//                        )
//                ).from(QCarInfo.qCarInfo).leftJoin(QCarBinding.qCarBinding).on(QCarInfo.qCarInfo.id.eq(QCarBinding.qCarBinding.carId));
//        QueryResults<CarInfoToPC.CarInfoToPCList> carInfoQueryResults = leftJoin.fetchResults();
//
//        BooleanExpression expression = QCarInfo.qCarInfo.valid.eq(true);
//        if(StringUtils.isNotEmpty(carListPCInputParam.getSnCode())){
//            expression = expression.and(QCarInfo.qCarInfo.snCode.contains(carListPCInputParam.getSnCode()));
//        }
//
//        if(!Objects.isNull(carListPCInputParam.getBrandId())){
//            expression = expression.and(QCarInfo.qCarInfo.brandId.eq(carListPCInputParam.getBrandId()));
//        }
//
//        if(StringUtils.isNotEmpty(carListPCInputParam.getImei())){
//            expression = expression.and(QCarInfo.qCarInfo.imei.contains(carListPCInputParam.getImei()));
//        }
//
//        if(StringUtils.isNotEmpty(carListPCInputParam.getVinNumber())){
//            expression = expression.and(QCarInfo.qCarInfo.vinNumber.contains(carListPCInputParam.getVinNumber()));
//        }
//
//        if(!Objects.isNull(carListPCInputParam.getState())){
//            expression = expression.and(QCarInfo.qCarInfo.state.eq(carListPCInputParam.getState()));
//        }
//
//        if(!Objects.isNull(carListPCInputParam.getBindingstate())){
//            expression = expression.and(QCarBinding.qCarBinding.state.eq(carListPCInputParam.getBindingstate()));
//        }
//        JPQLQuery<CarInfoToPC.CarInfoToPCList> where = leftJoin.where(expression);
//        //排序
//        JPQLQuery<CarInfoToPC.CarInfoToPCList> orderBy = where.orderBy(QCarInfo.qCarInfo.createTime.desc());
//        //分页
//        JPQLQuery<CarInfoToPC.CarInfoToPCList> limit = orderBy.offset(carListPCInputParam.getPage().longValue() * carListPCInputParam.getSize().longValue())
//                .limit(carListPCInputParam.getSize().longValue()).fetchAll();
//
////        QueryResults<CarInfoToPC.CarInfoToPCList> carInfoQueryResults = limit.fetchResults();
//
//
//        System.out.println(carInfoQueryResults.getResults());
//        System.out.println(carInfoQueryResults.getLimit());
//        System.out.println(carInfoQueryResults.getOffset());
//        System.out.println(carInfoQueryResults.getTotal());
//
//
//
//        //提取carModel需要的内容输出CarModelOutput
////        List<CarInfoToPC.CarInfoToPCList> carInfoToPCList = OutputUtils.ModelListToOutputList(carInfoPage.getContent(),CarInfoToPC.CarInfoToPCList.class);

        return null;
    }

标签:QCarInfo,qCarInfo,expression,QCarBinding,jpaJAVASql,eq,carListPCInputParam
From: https://www.cnblogs.com/Arborblog/p/16621278.html

相关文章