当前位置: 首页 > 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 表示多个切割面能合并为一个有效的…...

Qwen3-ASR-1.7B部署案例:AI初创公司低成本构建ASR SaaS服务

Qwen3-ASR-1.7B部署案例&#xff1a;AI初创公司低成本构建ASR SaaS服务 想象一下&#xff0c;你是一家AI初创公司的技术负责人&#xff0c;老板给你下了个任务&#xff1a;两周内&#xff0c;为公司的新产品上线一个语音转文字&#xff08;ASR&#xff09;功能。要求是识别要准…...

League-Toolkit:英雄联盟智能助手的全方位解决方案

League-Toolkit&#xff1a;英雄联盟智能助手的全方位解决方案 【免费下载链接】League-Toolkit 兴趣使然的、简单易用的英雄联盟工具集。支持战绩查询、自动秒选等功能。基于 LCU API。 项目地址: https://gitcode.com/gh_mirrors/le/League-Toolkit 在快节奏的英雄联盟…...

AI 开发实战:需求变更后,如何让 AI 自动补回归范围

AI 开发实战&#xff1a;需求变更后&#xff0c;如何让 AI 自动补回归范围 一、这个问题为什么值得专门拿出来做&#xff1f; 在 AI 工程落地里&#xff0c;真正拖慢团队的往往不是模型本身&#xff0c;而是流程和协作方式没有跟上。 围绕“需求变更后&#xff0c;如何让 AI 自…...

从零开始:使用Python Add-in快速构建ArcGIS自定义工具条

1. Python Add-in入门&#xff1a;ArcGIS插件开发新选择 第一次接触ArcGIS插件开发时&#xff0c;我被各种复杂的开发方式搞得晕头转向。直到发现了Python Add-in这个神器&#xff0c;才发现原来开发自定义工具条可以这么简单&#xff01;Python Add-in是Esri在ArcGIS 10.1引入…...

ESP32远程识别模块完整指南:如何实现无人机合规飞行

ESP32远程识别模块完整指南&#xff1a;如何实现无人机合规飞行 【免费下载链接】ArduRemoteID RemoteID support using OpenDroneID 项目地址: https://gitcode.com/gh_mirrors/ar/ArduRemoteID 随着全球无人机法规日益严格&#xff0c;FAA和欧盟都要求无人机必须配备专…...

3种方法永久保存QQ空间历史说说:GetQzonehistory实战指南

3种方法永久保存QQ空间历史说说&#xff1a;GetQzonehistory实战指南 【免费下载链接】GetQzonehistory 获取QQ空间发布的历史说说 项目地址: https://gitcode.com/GitHub_Trending/ge/GetQzonehistory 为什么需要GetQzonehistory&#xff1a;三个真实场景 想象一下&am…...

企业级Java SMB客户端:jcifs-ng深度架构解析与实战指南

企业级Java SMB客户端&#xff1a;jcifs-ng深度架构解析与实战指南 【免费下载链接】jcifs-ng A cleaned-up and improved version of the jCIFS library 项目地址: https://gitcode.com/gh_mirrors/jc/jcifs-ng jcifs-ng是一个经过彻底重构和优化的Java SMB客户端库&am…...

Synology Photos CPU驱动人脸识别补丁:解锁旧设备AI相册的终极方案

Synology Photos CPU驱动人脸识别补丁&#xff1a;解锁旧设备AI相册的终极方案 【免费下载链接】Synology_Photos_Face_Patch Synology Photos Facial Recognition Patch 项目地址: https://gitcode.com/gh_mirrors/sy/Synology_Photos_Face_Patch 还在为群晖NAS无法使用…...

LyricsX:重构Mac音乐体验的智能歌词助手

LyricsX&#xff1a;重构Mac音乐体验的智能歌词助手 【免费下载链接】Lyrics Swift-based iTunes plug-in to display lyrics on the desktop. 项目地址: https://gitcode.com/gh_mirrors/lyr/Lyrics 当你在Mac上沉浸于音乐世界时&#xff0c;是否曾因无法同步显示歌词而…...

vLLM-v0.17.1部署教程:vLLM+NGINX实现SSL/TLS加密API服务

vLLM-v0.17.1部署教程&#xff1a;vLLMNGINX实现SSL/TLS加密API服务 1. vLLM框架简介 vLLM是一个专注于大语言模型(LLM)推理和服务的高性能开源库。它最初由加州大学伯克利分校的天空计算实验室开发&#xff0c;现已发展成为一个由学术界和工业界共同维护的社区项目。 这个框…...