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

设计模式 外观模式 门面模式

结构性模式-外观模式

门面模式

适用场景:如果你需要一个指向复杂子系统的直接接口, 且该接口的功能有限, 则可以使用外观模式。

image-20241129210823339

不用关心后面的查询具体操作

/*** 聚合查询接口*/
@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {@Resourceprivate SearchFacade searchFacade;@PostMapping("/all")public BaseResponse<SearchVo> searchAll(@RequestBody SearchQueryRequest searchQueryRequest, HttpServletRequest httpServletRequest) {SearchVo searchVo = searchFacade.searchAll(searchQueryRequest, httpServletRequest);return ResultUtils.success(searchVo);}
}

复杂查询逻辑放在SearchFacade里面

package com.xiaofei.site.search.controller;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaofei.site.search.common.BaseResponse;
import com.xiaofei.site.search.common.ResultUtils;
import com.xiaofei.site.search.model.dto.image.ImageQueryRequest;
import com.xiaofei.site.search.model.dto.post.PostQueryRequest;
import com.xiaofei.site.search.model.dto.search.SearchQueryRequest;
import com.xiaofei.site.search.model.dto.user.UserQueryRequest;
import com.xiaofei.site.search.model.entity.Image;
import com.xiaofei.site.search.model.enums.SearchTypeEnum;
import com.xiaofei.site.search.model.vo.PostVO;
import com.xiaofei.site.search.model.vo.SearchVo;
import com.xiaofei.site.search.model.vo.UserVO;
import com.xiaofei.site.search.service.ImageService;
import com.xiaofei.site.search.service.PostService;
import com.xiaofei.site.search.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;/*** @author tuaofei* @description 查询-门面模式* @date 2024/11/29*/
@Component
@Slf4j
public class SearchFacade {@Resourceprivate PostService postService;@Resourceprivate UserService userService;@Resourceprivate ImageService imageService;@ResourceThreadPoolTaskExecutor threadPoolTaskExecutor;public SearchVo searchAll(@RequestBody SearchQueryRequest searchQueryRequest, HttpServletRequest httpServletRequest) {SearchVo searchVo = new SearchVo();if (searchQueryRequest == null) {return searchVo;}String searchText = searchQueryRequest.getSearchText();String searchType = searchQueryRequest.getSearchType();if (StringUtils.isBlank(searchType)) {CompletableFuture<Page<PostVO>> postTask = CompletableFuture.supplyAsync(() -> {PostQueryRequest postQueryRequest = new PostQueryRequest();postQueryRequest.setSearchText(searchText);Page<PostVO> postVOPage = postService.listPostVoPage(postQueryRequest, httpServletRequest);return postVOPage;}, threadPoolTaskExecutor);CompletableFuture<Page<UserVO>> userTask = CompletableFuture.supplyAsync(() -> {UserQueryRequest userQueryRequest = new UserQueryRequest();userQueryRequest.setUserName(searchText);Page<UserVO> userVOPage = userService.listUserVoPage(userQueryRequest);return userVOPage;}, threadPoolTaskExecutor);CompletableFuture<Page<Image>> imageTask = CompletableFuture.supplyAsync(() -> {ImageQueryRequest imageQueryRequest = new ImageQueryRequest();imageQueryRequest.setSearchText(searchText);Page<Image> imagePage = imageService.getImageByPage(imageQueryRequest);return imagePage;}, threadPoolTaskExecutor);CompletableFuture.allOf(postTask, userTask, imageTask);try {Page<PostVO> postVOPage = postTask.get();searchVo.setPostList(postVOPage.getRecords());Page<UserVO> userVOPage = userTask.get();searchVo.setUserList(userVOPage.getRecords());Page<Image> imagePage = imageTask.get();searchVo.setImageList(imagePage.getRecords());} catch (InterruptedException | ExecutionException e) {e.printStackTrace();}} else {SearchTypeEnum searchTypeEnum = SearchTypeEnum.getEnumByValue(searchType);switch (searchTypeEnum) {case POST:PostQueryRequest postQueryRequest = new PostQueryRequest();postQueryRequest.setSearchText(searchText);Page<PostVO> postVOPage = postService.listPostVoPage(postQueryRequest, httpServletRequest);searchVo.setPostList(postVOPage.getRecords());break;case USER:UserQueryRequest userQueryRequest = new UserQueryRequest();userQueryRequest.setUserName(searchText);Page<UserVO> userVOPage = userService.listUserVoPage(userQueryRequest);searchVo.setUserList(userVOPage.getRecords());break;case IMAGE:ImageQueryRequest imageQueryRequest = new ImageQueryRequest();imageQueryRequest.setSearchText(searchText);Page<Image> imagePage = imageService.getImageByPage(imageQueryRequest);searchVo.setImageList(imagePage.getRecords());break;default:break;}}return searchVo;}
}

相关文章:

设计模式 外观模式 门面模式

结构性模式-外观模式 门面模式 适用场景&#xff1a;如果你需要一个指向复杂子系统的直接接口&#xff0c; 且该接口的功能有限&#xff0c; 则可以使用外观模式。 不用关心后面的查询具体操作 /*** 聚合查询接口*/ RestController RequestMapping("/search") Slf…...

Prophet时间序列算法总结及python实现案例

目录 一、prophet理论总结二、python导入模块方式三、python实现案例3.1帮助信息3.2 案例 四、参考学习 一、prophet理论总结 prophet模型是facebook开源的一个时间序列预测算法。[1][2]&#xff0c;该算法主要为处理具有周期性、趋势变化以及缺失值和异常值的时间序列数据而设…...

远程调用 rpc 、 open feign

在学习黑马 springcloud 视频的时候&#xff0c;看到 open feign 使用&#xff0c; 就是 http 封装。 spring框架三部曲&#xff0c;导入依赖&#xff0c;加配置&#xff0c;使用api。...

Redis的几种持久化方式

Redis 提供了两种主要的持久化方式&#xff0c;它们分别是&#xff1a; 1. RDB&#xff08;Redis Database Snapshotting&#xff09; RDB 是 Redis 的一种数据持久化方式&#xff0c;它会在指定的时间间隔内对 Redis 中的数据进行快照并保存到硬盘上。 特点&#xff1a; 触…...

论文笔记(五十九)A survey of robot manipulation in contact

A survey of robot manipulation in contact 文章概括摘要1. 引言解释柔顺性控制的概念&#xff1a;应用实例&#xff1a; 2. 需要接触操控的任务2.1 环境塑造2.2 工件对齐2.3 关节运动2.4 双臂接触操控 3. 接触操控中的控制3.1 力控制3.2 阻抗控制3.3 顺应控制 4. 接触操控中的…...

c#控制台程序26-30

26.寻找并输出11至999之间的数m&#xff0c;它满足m,m2和m3均为回文数。所谓回文数是指其各位数字左右对称的整数&#xff0c;例如121&#xff0c;676&#xff0c;94249等。满足上述条件的数如m11,m2121,m31331皆为回文数。请编制函数实现此功能&#xff0c;如果是回文数&#…...

环形链表系列导学

问题描述 给定一个单链表,可能存在一个环。我们的目标是找到环的入口节点,即从这个节点开始,链表进入循环。如果没有环,则返回 null。 将链表问题转化为数学问题 状态序列与循环 我们可以将链表节点视为状态,每个节点的 next 指针代表状态转移函数 f f f。从头节点开始,我…...

IDEA2024创建一个spingboot项目

以下是创建一个基本的 Spring Boot 项目的步骤和示例&#xff1a; 初始化一个springboot工程其实有许多方法&#xff0c;笔者这里挑了一个最快捷的方式搭建一个项目。我们直接通过官方平台&#xff08;start.spring.io&#xff09;进行配置&#xff0c;然后下载压缩包就可以获取…...

Nginx:ssl

目录 部署ssl前提 nginx部署ssl证书 部署ssl部署建议 部署ssl前提 网站有域名根据域名申请到ssl证书&#xff0c;并下载证书部署到nginx中 部署了ssl证书后&#xff0c;访问的流量是加密的。 nginx部署ssl证书 #80端口跳转到443 server {listen 80;return 302 https://1…...

QT配置文件详解

TEMPLATElib TEMPLATE变量用于指定项目模板类型&#xff0c;其值可以是以下几种&#xff1a; app&#xff1a;建立一个应用程序的makefile&#xff0c;这是默认值。lib&#xff1a;建立一个库的makefile。vcapp&#xff1a;建立一个应用程序的Visual Studio项目文件。vclib&a…...

根据合约地址判断合约协议的方法

判断合约协议之前&#xff0c;需要了解一下什么是ERC165协议&#xff1a; ERC165 是以太坊中用于标准化接口检测的协议&#xff0c;由 Fabian Vogelsteller 在 2018 年创建 &#xff0c;其核心内容主要包括以下方面&#xff1a; 接口定义 单一函数接口&#xff1a;ERC165 协议…...

联想YOGA Pro 14s至尊版电脑找不到独立显卡(N卡)问题,也无法安装驱动的问题

问题描述 电脑是联想YOGA Pro 14s至尊版&#xff0c;电脑上装的独立显卡是4060&#xff0c;一直是能够使用独立显卡的。然而有两次突然就找不到显卡了&#xff0c;NVIDIA CONTROL PANEL也消失了&#xff0c;而且也无法安装驱动。具体表现如下&#xff1a; 无法连接外接显示器…...

Spring Web开发注解和请求(1)

大家好我是小帅&#xff0c;今天我们来学习Spring Web MVC框架&#xff08;入门级&#xff09; 文章目录 1. 什么是 Spring Web MVC&#xff1f;1.1 MVC 定义1.2 什么是Spring MVC ? 2. 学习Spring MVC2.1 建⽴连接第一个spring MVC程序 3. web开发注解的解释3.1RestControlle…...

Supervisor使用教程

文章目录 [toc] Supervisor使用教程平台要求 安装supervisor本文测试的时候是使用Linux的yum安装的&#xff08;其它方式未做测试&#xff09;加入系统守护进行 Supervisor使用教程 在项目中&#xff0c;经常有脚本需要常驻运行的需求。以PHP脚本为例&#xff0c;最简单的方式…...

Spark基本命令详解

文章目录 Spark基本命令详解一、引言二、Spark Core 基本命令1、Transformations&#xff08;转换操作&#xff09;1.1、groupBy(func)1.2、filter(func) 2、Actions&#xff08;动作操作&#xff09;2.1、distinct([numTasks])2.2、sortBy(func, [ascending], [numTasks]) 三、…...

Three.js 相机视角的平滑过渡与点击模型切换视角

在 Three.js 中&#xff0c;实现相机视角的平滑过渡和点击模型切换到查看模型视角是一个常见且有用的功能。这种效果不仅能提升用户体验&#xff0c;还能为场景互动添加更多的动态元素。 1. 基本设置 首先&#xff0c;我们需要创建一个基本的 Three.js 场景&#xff0c;包括相…...

jenken 打包linux包遇到的问题(环境变量)

环境变量问题 我们jenkens 打包的时候 远程打包 通过ssh 去在服务器上调用脚本 环境变量没有去自动加载 代码打包的时候总是提示相关的so文件找不到 解决方案在 相关程序的make之前 把环境变量加在前面 我这里直接将变量加载代码的最前面...

使用 Go 语言中的 Context 取消协程执行

使用 Go 语言中的 Context 取消协程执行 在 Go 语言中&#xff0c;协程&#xff08;goroutine&#xff09;是一种轻量级的线程&#xff0c;非常适合处理并发任务。然而&#xff0c;如何优雅地取消正在运行的协程是一个常见的问题。本文将通过一个具体的例子来展示如何使用 con…...

python图像彩色数字化

效果展示&#xff1a; 目录结构&#xff1a; alphabets.py GENERAL {"simple": "%#*-:. ","complex": "$B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_~<>i!lI;:,\"^. " } # Full list could be found here…...

cesium 3dtile ClippingPlanes 多边形挖洞ClippingPlaneCollection

原理就是3dtiles里面的属性clippingPlanes 采用ClippingPlaneCollection&#xff0c;构成多边形来挖洞。 其次就是xyz法向量挖洞 clippingPlanes: new this.ffCesium.Cesium.ClippingPlaneCollection({unionClippingRegions: true, // true 表示多个切割面能合并为一个有效的…...

【OSG学习笔记】Day 18: 碰撞检测与物理交互

物理引擎&#xff08;Physics Engine&#xff09; 物理引擎 是一种通过计算机模拟物理规律&#xff08;如力学、碰撞、重力、流体动力学等&#xff09;的软件工具或库。 它的核心目标是在虚拟环境中逼真地模拟物体的运动和交互&#xff0c;广泛应用于 游戏开发、动画制作、虚…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

MySQL 隔离级别:脏读、幻读及不可重复读的原理与示例

一、MySQL 隔离级别 MySQL 提供了四种隔离级别,用于控制事务之间的并发访问以及数据的可见性,不同隔离级别对脏读、幻读、不可重复读这几种并发数据问题有着不同的处理方式,具体如下: 隔离级别脏读不可重复读幻读性能特点及锁机制读未提交(READ UNCOMMITTED)允许出现允许…...

阿里云ACP云计算备考笔记 (5)——弹性伸缩

目录 第一章 概述 第二章 弹性伸缩简介 1、弹性伸缩 2、垂直伸缩 3、优势 4、应用场景 ① 无规律的业务量波动 ② 有规律的业务量波动 ③ 无明显业务量波动 ④ 混合型业务 ⑤ 消息通知 ⑥ 生命周期挂钩 ⑦ 自定义方式 ⑧ 滚的升级 5、使用限制 第三章 主要定义 …...

线程同步:确保多线程程序的安全与高效!

全文目录&#xff1a; 开篇语前序前言第一部分&#xff1a;线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分&#xff1a;synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分&#xff…...

Auto-Coder使用GPT-4o完成:在用TabPFN这个模型构建一个预测未来3天涨跌的分类任务

通过akshare库&#xff0c;获取股票数据&#xff0c;并生成TabPFN这个模型 可以识别、处理的格式&#xff0c;写一个完整的预处理示例&#xff0c;并构建一个预测未来 3 天股价涨跌的分类任务 用TabPFN这个模型构建一个预测未来 3 天股价涨跌的分类任务&#xff0c;进行预测并输…...

P3 QT项目----记事本(3.8)

3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...

Linux 中如何提取压缩文件 ?

Linux 是一种流行的开源操作系统&#xff0c;它提供了许多工具来管理、压缩和解压缩文件。压缩文件有助于节省存储空间&#xff0c;使数据传输更快。本指南将向您展示如何在 Linux 中提取不同类型的压缩文件。 1. Unpacking ZIP Files ZIP 文件是非常常见的&#xff0c;要在 …...

【 java 虚拟机知识 第一篇 】

目录 1.内存模型 1.1.JVM内存模型的介绍 1.2.堆和栈的区别 1.3.栈的存储细节 1.4.堆的部分 1.5.程序计数器的作用 1.6.方法区的内容 1.7.字符串池 1.8.引用类型 1.9.内存泄漏与内存溢出 1.10.会出现内存溢出的结构 1.内存模型 1.1.JVM内存模型的介绍 内存模型主要分…...

comfyui 工作流中 图生视频 如何增加视频的长度到5秒

comfyUI 工作流怎么可以生成更长的视频。除了硬件显存要求之外还有别的方法吗&#xff1f; 在ComfyUI中实现图生视频并延长到5秒&#xff0c;需要结合多个扩展和技巧。以下是完整解决方案&#xff1a; 核心工作流配置&#xff08;24fps下5秒120帧&#xff09; #mermaid-svg-yP…...