当前位置: 首页 > news >正文

springboot 查询

ServiceImpl中

getBaseMapper()的使用

public IPage<ProductPageVO> getProductPage(Integer regionOrCityCode, Integer brandId, LocalDate usedDate, Page<ProductPageVO> page) {return getBaseMapper().getProductPage(regionOrCityCode, brandId, usedDate, page);}

optional的使用

        //查询产品Optional<ProductManage> optionalProductManage = productManageService.lambdaQuery().eq(BaseEntity::getId, productId).oneOpt();if (optionalProductManage.isEmpty()) {return null;}ProductManage productManage = optionalProductManage.get();

lamdaquery 查询+流操作获取vo

 List<CarInfoVO.Insure.Term> terms = insureTermService.lambdaQuery().in(BaseEntity::getId, termIds).orderByDesc(InsureTerm::getSort).list().stream().map(term -> {//对item进行遍历CarInfoVO.Insure.Term termVo = new CarInfoVO.Insure.Term();termVo.setTitle(term.getTitle());termVo.setSketch(term.getSketch());termVo.setDetail(term.getDetails());return termVo;}).collect(Collectors.toList());//聚集元素

流操作之分组

  Map<String, List<CarInfoVO.GeneralConfiguration>> subscribeMap =universalConfigureService.lambdaQuery().in(UniversalConfigure::getParentId, subscribes).eq(UniversalConfigure::getStatus, 1).orderByDesc(UniversalConfigure::getSort).list().stream().collect(Collectors.groupingBy(UniversalConfigure::getParentId,//对数据进行分组,指定分组的keyCollectors.mapping(item -> {//组建分组中的valueCarInfoVO.GeneralConfiguration generalConfiguration = new CarInfoVO.GeneralConfiguration();generalConfiguration.setTitle(item.getTitle());generalConfiguration.setSketch(item.getSketch());generalConfiguration.setDetail(item.getDetail());if (StringUtils.isNotBlank(item.getMaterialId())) {Optional<MaterialConfigure> optional =materialConfigureService.lambdaQuery().eq(BaseEntity::getId, item.getMaterialId()).oneOpt();if (!optional.isEmpty()) {generalConfiguration.setIcon(ossUtil.getCacheSignedUrl(optional.get().getUrl()));}}return generalConfiguration;}, Collectors.toList())));

流操作之排序

 List<CarInfoVO.Car> cars = carManages.stream().map(carManage -> {CarInfoVO.Car car = new CarInfoVO.Car();car.setCarId(carManage.getId());car.setTitle(carManage.getTitle());car.setStatus(carManage.getStatus());car.setPrice(carManage.getPrice());car.setCreateTime(carManage.getCreateTime());//车辆关系表Map<Integer, List<String>> carRelations = carManageRelationService.lambdaQuery().eq(CarManageRelation::getCarId, carManage.getId()).isNotNull(CarManageRelation::getRelationId).orderByDesc(CarManageRelation::getSort).list().stream().collect(Collectors.groupingBy(CarManageRelation::getType, Collectors.mapping(CarManageRelation::getRelationId, Collectors.toList())));//排期判断Integer integer = 0;List<String> tenancyIds = carRelations.get(1);//查询租期信息if (CollectionUtils.isNotEmpty(tenancyIds)) {//取最小租期Optional<TenancyConfigure> optional = tenancyConfigureService.lambdaQuery().in(BaseEntity::getId, tenancyIds).orderByAsc(TenancyConfigure::getDuration).last("limit 1").oneOpt();if (!optional.isEmpty()) {//结束时间LocalDate endDate = usedDate.plusDays(optional.get().getDuration() * 30);if (usedDate.isAfter(carManage.getStartTime().toLocalDate()) && endDate.isBefore(carManage.getEndTime().toLocalDate())) {//查询有无排期integer = scheduleServerUtil.searchScheduleRequest(carManage.getCarId(), usedDate, endDate, false);}}}car.setSchedule(integer != 0 ? 1 : 0);car.setRegistrationTime(carManage.getRegistrationTime().getYear() + "年" + carManage.getRegistrationTime().getMonthValue() + "月");car.setCarModelTerritory(carManage.getCarModelTerritory());car.setCurrentMileage(carManage.getCurrentMileage());car.setCarNumber(carManage.getCarNumber());Optional<MaterialConfigure> optional = materialConfigureService.lambdaQuery().eq(BaseEntity::getId, carManage.getCarCoverId()).oneOpt();if (!optional.isEmpty()) {car.setDisplay(ossUtil.getCacheSignedUrl(optional.get().getUrl()));}//外观 内饰 空间List<String> pictureRelationIds = new ArrayList<>();pictureRelationIds.addAll(carRelations.get(4));pictureRelationIds.addAll(carRelations.get(5));pictureRelationIds.addAll(carRelations.get(6));if (CollectionUtils.isNotEmpty(pictureRelationIds)) {Map<String, String> collect1 = materialConfigureService.lambdaQuery().in(BaseEntity::getId, pictureRelationIds).list().stream().collect(Collectors.toMap(BaseEntity::getId, MaterialConfigure::getUrl));List<String> collect2 = pictureRelationIds.stream().map(item -> ossUtil.getCacheSignedUrl(collect1.get(item))).collect(Collectors.toList());car.setPictures(collect2);}//自定义配置List<String> customCarConfigIds = carRelations.get(2);if (CollectionUtils.isNotEmpty(customCarConfigIds)) {List<CarInfoVO.Car.CustomCarConfig> collect = carConfigureService.lambdaQuery().in(BaseEntity::getId, customCarConfigIds).orderByDesc(CarConfigure::getSort).list().stream().map(item -> {CarInfoVO.Car.CustomCarConfig customCarConfig = new CarInfoVO.Car.CustomCarConfig();customCarConfig.setTitle(item.getTitle());customCarConfig.setResume(item.getResume());customCarConfig.setDetail(item.getDetails());return customCarConfig;}).collect(Collectors.toList());car.setCustomCarConfigs(collect);}return car;})//排序.sorted(Comparator.comparing(CarInfoVO.Car::getSchedule).reversed().thenComparing(CarInfoVO.Car::getPrice).thenComparing(CarInfoVO.Car::getCreateTime)).collect(Collectors.toList());

流操作之取大小

 List<CarManage> carManages = carManageService.lambdaQuery().eq(CarManage::getProductId, productId).eq(CarManage::getStatus, 1).list();Optional<CarManage> min = carManages.stream().min(Comparator.comparing(CarManage::getMarketPrice));if (!min.isEmpty()) {carInfoVO.setGuidePriceMin(min.get().getMarketPrice());}

流操作之过滤出指定字段

 //所有产品List<ProductManage> list = productManageService.lambdaQuery().in(ProductManage::getCityCode, allCities).eq(ProductManage::getStatus, 1).le(ProductManage::getStartTime, usedDate).ge(ProductManage::getEndTime, usedDate).list();if (ObjectUtils.isEmpty(list)) {return new ArrayList<>();}//查询产品下是否存在车辆 没有车辆不显示车系List<String> productIds = list.stream().map(BaseEntity::getId).collect(Collectors.toList());
http://www.lryc.cn/news/268444.html

相关文章:

  • 【分布式链路追踪技术】sleuth+zipkin
  • Windows 源码编译 MariaDB
  • 【动画视频生成】
  • 《Spring Cloud学习笔记:微服务保护Sentinel》
  • 解密负载均衡:如何平衡系统负载(下)
  • go 源码解读 - sync.Mutex
  • 机器学习系列--R语言随机森林进行生存分析(1)
  • <JavaEE> TCP 的通信机制(四) -- 流量控制 和 拥塞控制
  • 智慧监控平台/AI智能视频EasyCVR接口调用编辑通道详细步骤
  • Go语言实现KV存储系统:前言
  • 代码随想录刷题笔记(DAY1)
  • Linux域名IP映射
  • postman使用-03发送请求
  • 【Spring实战】09 MyBatis Generator
  • 【自然语言处理】【大模型】 ΨPO:一个理解人类偏好学习的统一理论框架
  • 计算机网络——传输层(五)
  • python3处理docx并flask显示
  • Python:正则表达式速通,码上上手!
  • centos7安装nginx并安装部署前端
  • Hive实战:统计总分与平均分
  • Linux:不同计算机使用NFS共享资源
  • leetcode贪心算法题总结(一)
  • SQL高级:窗口函数
  • Excel formulas 使用总结(更新中)
  • 华为OD机试 - 两个字符串间的最短路径问题(Java JS Python C)
  • 强敌环伺:金融业信息安全威胁分析——钓鱼和恶意软件
  • 1月1日起,贵阳市退役军人可以免费乘坐公交地铁
  • 网络隔离后,怎样建立高效安全的数据安全交换通道?
  • Python:PyTorch
  • CentOS 5/6/7 基于开源项目制作openssh 9.6p1 rpm包—— 筑梦之路