初始化
commit
1af860b3e9
|
@ -0,0 +1,38 @@
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8">
|
||||||
|
<file url="file://$PROJECT_DIR$/common/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/common/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/gateway/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/gateway/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/order-service/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/order-service/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/plane-service/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/plane-service/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/user-service/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/user-service/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,177 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_month</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- nacos服务发现依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- loadbalancer负载均衡 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- nacos配置文件 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- bootstrap优先启动文件 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- feign客户端 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- feign的httpclient客户端 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-httpclient</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- amqp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- elasticsearch -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>co.elastic.clients</groupId>
|
||||||
|
<artifactId>elasticsearch-java</artifactId>
|
||||||
|
<version>8.11.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jackson-databind -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.12.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jwt令牌校验 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.auth0</groupId>
|
||||||
|
<artifactId>java-jwt</artifactId>
|
||||||
|
<version>4.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Hibernate Validator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mysql -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- druid连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
<version>1.2.20</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatisPlus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- redis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- redis连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- fastjson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.42</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Apache Lang3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- hutool工具包 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.20</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- javax.annotation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.annotation</groupId>
|
||||||
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
|
<version>1.3.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.ysy.common.config;
|
||||||
|
|
||||||
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
|
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
||||||
|
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
|
import org.elasticsearch.client.RestClient;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "elasticsearch")
|
||||||
|
@Data
|
||||||
|
public class ElasticClient {
|
||||||
|
private String protocol;
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ElasticsearchClient getElasticsearchClient() {
|
||||||
|
RestClient restclient = RestClient.builder(new HttpHost(host, port, protocol)).build();
|
||||||
|
RestClientTransport transport = new RestClientTransport(restclient, new JacksonJsonpMapper());
|
||||||
|
return new ElasticsearchClient(transport);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.ysy.common.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Binding;
|
||||||
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
|
import org.springframework.amqp.core.DirectExchange;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
|
||||||
|
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
|
||||||
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||||
|
import org.springframework.amqp.support.converter.MessageConverter;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty(name = "spring.rabbitmq.listener.simple.retry.enabled", havingValue = "true")
|
||||||
|
public class ErrorMessageConfig {
|
||||||
|
@Bean
|
||||||
|
public DirectExchange errorMessageExchange(){
|
||||||
|
return new DirectExchange("error.direct");
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Queue errorQueue(){
|
||||||
|
return new Queue("error.queue", true);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Binding errorBinding(Queue errorQueue, DirectExchange errorMessageExchange){
|
||||||
|
return BindingBuilder.bind(errorQueue).to(errorMessageExchange).with("error");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){
|
||||||
|
return new RepublishMessageRecoverer(rabbitTemplate, "error.direct", "error");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 替换默认JDK序列化,org.springframework.amqp.support.converter.MessageConverter
|
||||||
|
* @return 用json格式替代默认格式
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MessageConverter jsonConverter() {
|
||||||
|
return new Jackson2JsonMessageConverter();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ysy.common.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: Mybatis-Plus配置
|
||||||
|
* @Date 2024-1-10 下午 05:12
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
public MybatisPlusConfig () {
|
||||||
|
System.out.println("初始化-----------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加分页插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.ysy.common.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.core.ReturnedMessage;
|
||||||
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||||
|
import org.springframework.amqp.support.converter.MessageConverter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
public class RabbitPublisherConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
//设置开启Mandatory,才能触发回调函数,无论消息推送结果怎么样都强制调用回调函数
|
||||||
|
rabbitTemplate.setMandatory(true);
|
||||||
|
rabbitTemplate.setConfirmCallback(this);
|
||||||
|
rabbitTemplate.setReturnsCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* confirm回调,(前提: 确认模式开启:publisher-confirm-type: correlated)
|
||||||
|
* CorrelationData数据可以在rabbitTemplate.convertAndSend时传入,并这种CorrelationData的setId参数,回调时能取到
|
||||||
|
* @param correlationData 相关数据,可以在发送消息时,进行设置该参数
|
||||||
|
* @param ack 结果
|
||||||
|
* @param cause 原因
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||||
|
if (ack) {
|
||||||
|
log.info("【ConfirmCallback】消息已经送达Exchange,ack已发");
|
||||||
|
} else {
|
||||||
|
log.warn("【ConfirmCallback】消息没有送达Exchange");
|
||||||
|
// todo 做一些处理,让消息再次发送。 消息缓存或入库,邮件提醒运维
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return函数,(前提:退回模式开启:yml中publisher-returns: true)
|
||||||
|
* @param returned 返回的信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void returnedMessage(ReturnedMessage returned) {
|
||||||
|
log.debug("收到消息的return callback,exchange:{}, key:{}, msg:{}, code:{}, text:{}",
|
||||||
|
returned.getExchange(), returned.getRoutingKey(), returned.getMessage(),
|
||||||
|
returned.getReplyCode(), returned.getReplyText());
|
||||||
|
// todo 处理 邮件发送,缓存或存到数据库
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.ysy.common.contant;
|
||||||
|
|
||||||
|
public class ResultConstants {
|
||||||
|
public final static int SUCCESS_CODE = 200;
|
||||||
|
public final static int FAIL_CODE = 300;
|
||||||
|
public final static int ERROR_CODE = 500;
|
||||||
|
public final static String SUCCESS_MSG = "success";
|
||||||
|
public final static String FAIL_MSG = "fail";
|
||||||
|
public final static String ERROR_MSG = "error";
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.common.contant;
|
||||||
|
|
||||||
|
public class TokenConstants {
|
||||||
|
public final static String TOKEN = "token";
|
||||||
|
public final static String TOKEN_LOGIN = "tokenLogin";
|
||||||
|
public final static String TOKEN_KEY = "tokenKey";
|
||||||
|
public final static String USER_ID = "userId";
|
||||||
|
public final static String USER_NAME = "username";
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_company")
|
||||||
|
public class Company {
|
||||||
|
@TableId(value = "cid", type = IdType.AUTO)
|
||||||
|
private Long cid;
|
||||||
|
@TableField("company_name")
|
||||||
|
private String companyName;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_destination")
|
||||||
|
public class Destination {
|
||||||
|
@TableId(value = "did", type = IdType.AUTO)
|
||||||
|
private Long did;
|
||||||
|
@TableField("destination_name")
|
||||||
|
private String destinationName;
|
||||||
|
private Long pid;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_module")
|
||||||
|
public class Module {
|
||||||
|
@TableId(value = "mid", type = IdType.AUTO)
|
||||||
|
private Long mid;
|
||||||
|
@TableField("module_name")
|
||||||
|
private String moduleName;
|
||||||
|
private Long cid;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_order")
|
||||||
|
public class Order {
|
||||||
|
@TableId(value = "oid", type = IdType.AUTO)
|
||||||
|
private Long oid;
|
||||||
|
private Long pid;
|
||||||
|
@TableField("passenger_id")
|
||||||
|
private Long passengerId;
|
||||||
|
@TableField("take_price")
|
||||||
|
private Integer takePrice;
|
||||||
|
private Integer rate;
|
||||||
|
private Boolean state;
|
||||||
|
private Long uid;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Plane plane;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Passenger passenger;
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_passenger")
|
||||||
|
public class Passenger {
|
||||||
|
@TableId(value = "pid", type = IdType.AUTO)
|
||||||
|
private Long pid;
|
||||||
|
@TableField("passenger_name")
|
||||||
|
private String passengerName;
|
||||||
|
private String id;
|
||||||
|
private Long uid;
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_plane")
|
||||||
|
public class Plane {
|
||||||
|
@TableId(value = "pid", type = IdType.AUTO)
|
||||||
|
private Long pid;
|
||||||
|
@TableField("plane_num")
|
||||||
|
private String planeNum;
|
||||||
|
private Long sid;
|
||||||
|
private Long eid;
|
||||||
|
private Long mid;
|
||||||
|
private Long cid;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField("start_time")
|
||||||
|
private Date startTime;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField("end_time")
|
||||||
|
private Date endTime;
|
||||||
|
private Integer price;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String startPlace;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String endPlace;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String moduleName;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String companyName;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.ysy.common.domain.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName("t_user")
|
||||||
|
public class User {
|
||||||
|
@TableId(value = "uid", type = IdType.AUTO)
|
||||||
|
private Long uid;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private Boolean role;
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ysy.common.domain.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageResult<T> implements Serializable {
|
||||||
|
|
||||||
|
private long total;
|
||||||
|
|
||||||
|
private List<T> list;
|
||||||
|
|
||||||
|
public PageResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageResult(long total, List<T> list) {
|
||||||
|
this.total = total;
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> PageResult<T> toPageResult(long total, List<T> list){
|
||||||
|
return new PageResult(total , list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
|
||||||
|
return Result.success(PageResult.toPageResult(total, list));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.ysy.common.domain.result;
|
||||||
|
|
||||||
|
import com.ysy.common.contant.ResultConstants;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class R {
|
||||||
|
private final static int SUCCESS_CODE = ResultConstants.SUCCESS_CODE;
|
||||||
|
|
||||||
|
private final static int FAIL_CODE = ResultConstants.FAIL_CODE;
|
||||||
|
|
||||||
|
private final static int ERROR_CODE = ResultConstants.ERROR_CODE;
|
||||||
|
|
||||||
|
private final static String SUCCESS_MSG = ResultConstants.SUCCESS_MSG;
|
||||||
|
|
||||||
|
private final static String FAIL_MSG = ResultConstants.FAIL_MSG;
|
||||||
|
|
||||||
|
private final static String ERROR_MSG = ResultConstants.ERROR_MSG;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
private String msg;
|
||||||
|
private Map<String, Object> data;
|
||||||
|
|
||||||
|
public R(Integer code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public R(Integer code, String msg, String key, Object value) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
this.data = new HashMap<>();
|
||||||
|
this.data.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//成功结果集
|
||||||
|
public static R success() {
|
||||||
|
return new R(SUCCESS_CODE, SUCCESS_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(String msg) {
|
||||||
|
return new R(SUCCESS_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(Map<String, Object> data) {
|
||||||
|
return new R(SUCCESS_CODE, SUCCESS_MSG, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(String key, Object value) {
|
||||||
|
return new R(SUCCESS_CODE, SUCCESS_MSG, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R success(String msg, String key, Object value) {
|
||||||
|
return new R(SUCCESS_CODE, msg, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//失败结果集
|
||||||
|
public static R fail() {
|
||||||
|
return new R(FAIL_CODE, FAIL_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R fail(String msg) {
|
||||||
|
return new R(FAIL_CODE, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//错误结果集
|
||||||
|
public static R error() {
|
||||||
|
return new R(ERROR_CODE, ERROR_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static R error(String msg) {
|
||||||
|
return new R(ERROR_CODE, msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.ysy.common.domain.result;
|
||||||
|
|
||||||
|
import com.ysy.common.contant.ResultConstants;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final int SUCCESS = ResultConstants.SUCCESS_CODE;
|
||||||
|
|
||||||
|
public static final int FAIL = ResultConstants.FAIL_CODE;
|
||||||
|
|
||||||
|
public static final int ERROR = ResultConstants.ERROR_CODE;
|
||||||
|
|
||||||
|
public static final String SUCCESS_MSG = ResultConstants.SUCCESS_MSG;
|
||||||
|
|
||||||
|
public static final String FAIL_MSG = ResultConstants.FAIL_MSG;
|
||||||
|
|
||||||
|
public static final String ERROR_MSG = ResultConstants.ERROR_MSG;
|
||||||
|
|
||||||
|
//field
|
||||||
|
private int code;
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> Result<T> success() {
|
||||||
|
return restResult(SUCCESS, SUCCESS_MSG, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(String msg) {
|
||||||
|
return restResult(SUCCESS, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
return restResult(SUCCESS, SUCCESS_MSG, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(String msg, T data) {
|
||||||
|
return restResult(SUCCESS, msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> fail() {
|
||||||
|
return restResult(FAIL, FAIL_MSG, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> fail(String msg) {
|
||||||
|
return restResult(FAIL, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error() {
|
||||||
|
return restResult(ERROR, ERROR_MSG, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error(String msg) {
|
||||||
|
return restResult(ERROR, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> Result<T> restResult(int code, String msg, T data) {
|
||||||
|
Result<T> apiResult = new Result<>();
|
||||||
|
apiResult.setCode(code);
|
||||||
|
apiResult.setMsg(msg);
|
||||||
|
apiResult.setData(data);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
* @return 成功:true
|
||||||
|
*/
|
||||||
|
public boolean isSuccess(){
|
||||||
|
return this.code == SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
* @return 失败:false
|
||||||
|
*/
|
||||||
|
public boolean isError(){
|
||||||
|
return !isSuccess();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.ysy.common.domain.vo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class PassengerVO {
|
||||||
|
@NotBlank(message = "用户名不能为空")
|
||||||
|
private String passengerName;
|
||||||
|
@NotBlank(message = "身份证不能为空")
|
||||||
|
private String id;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ysy.common.domain.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class PlaneVO {
|
||||||
|
private String company;
|
||||||
|
private String startPlace;
|
||||||
|
private String endPlace;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date startTime;
|
||||||
|
|
||||||
|
private Integer pageNum = 1;
|
||||||
|
private Integer pageSize = 3;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.ysy.common.domain.vo;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class UserVO {
|
||||||
|
@NotBlank(message = "用户名不能为空")
|
||||||
|
private String username;
|
||||||
|
@NotBlank(message = "密码不能为空")
|
||||||
|
private String password;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ysy.common.exception;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.ysy.common.domain.result.R;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
@ExceptionHandler(IllegalArgumentException.class)
|
||||||
|
public R illegalArgumentExceptionHandler(IllegalArgumentException e) {
|
||||||
|
log.error("服务端报错:[{}]", e.getMessage(), e.getLocalizedMessage(), e);
|
||||||
|
return R.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
public R methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
|
||||||
|
log.error("服务端报错:[{}]", e.getMessage(), e.getLocalizedMessage(), e);
|
||||||
|
return R.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.ysy.common.remote;
|
||||||
|
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
@FeignClient(value = "planeService", path = "plane")
|
||||||
|
public interface PlaneServiceRemote {
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<Plane> byId(@PathVariable Long id);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.ysy.common.remote;
|
||||||
|
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
@FeignClient(value = "userService", path = "user")
|
||||||
|
public interface UserServiceRemote {
|
||||||
|
@GetMapping("/passenger/{id}")
|
||||||
|
public Result<Passenger> passengerById(@PathVariable Long id);
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.ysy.common.utils.gateway;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import com.ysy.common.utils.tools.StringUtils;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 网关处理工具类
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class GatewayUtils {
|
||||||
|
/**
|
||||||
|
* 添加请求头参数
|
||||||
|
* @param mutate 修改对象
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
|
||||||
|
if (StringUtils.isEmpty(key)){
|
||||||
|
log.warn("添加请求头参数键不可以为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (value == null) {
|
||||||
|
log.warn("添加请求头参数:[{}]值为空",key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String valueStr = value.toString();
|
||||||
|
mutate.header(key, valueStr);
|
||||||
|
log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除请求头参数
|
||||||
|
* @param mutate 修改对象
|
||||||
|
* @param key 键
|
||||||
|
*/
|
||||||
|
public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
|
||||||
|
if (StringUtils.isEmpty(key)){
|
||||||
|
log.warn("删除请求头参数键不可以为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
|
||||||
|
log.info("删除请求头参数 - 键:[{}]",key);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 错误结果响应
|
||||||
|
* @param exchange 响应上下文
|
||||||
|
* @param msg 响应消息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg) {
|
||||||
|
ServerHttpResponse response = exchange.getResponse();
|
||||||
|
//设置HTTP响应头状态
|
||||||
|
response.setStatusCode(HttpStatus.OK);
|
||||||
|
//设置HTTP响应头文本格式
|
||||||
|
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
|
||||||
|
//定义响应内容
|
||||||
|
Result<String> result = Result.error(msg);
|
||||||
|
String resultJson = JSONObject.toJSONString(result);
|
||||||
|
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
|
||||||
|
DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
|
||||||
|
//进行响应
|
||||||
|
return response.writeWith(Mono.just(dataBuffer));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.ysy.common.utils.jwt;
|
||||||
|
|
||||||
|
import com.auth0.jwt.JWT;
|
||||||
|
import com.auth0.jwt.JWTVerifier;
|
||||||
|
import com.auth0.jwt.algorithms.Algorithm;
|
||||||
|
import com.auth0.jwt.interfaces.Claim;
|
||||||
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class JwtUtil {
|
||||||
|
private final static Date EXPIRE_TIME = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24L);
|
||||||
|
private final static String SECRET = "qwertyuiopasdfghjkl";
|
||||||
|
private final static String CLAIM_NAME = "claim_name";
|
||||||
|
|
||||||
|
public static String createToken(Map<String, Object> claim) {
|
||||||
|
String token = JWT.create()
|
||||||
|
.withClaim(CLAIM_NAME, claim)
|
||||||
|
//.withExpiresAt(EXPIRE_TIME)
|
||||||
|
.sign(Algorithm.HMAC256(SECRET));
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DecodedJWT decodedJWT(String token) {
|
||||||
|
JWTVerifier build = JWT.require(Algorithm.HMAC256(SECRET))
|
||||||
|
.build();
|
||||||
|
DecodedJWT decodedJWT = build.verify(token);
|
||||||
|
return decodedJWT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Claim getClaim(String token) {
|
||||||
|
DecodedJWT decodedJWT = decodedJWT(token);
|
||||||
|
Map<String, Claim> claims = decodedJWT.getClaims();
|
||||||
|
return claims.get(CLAIM_NAME);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.ysy.common.utils.jwt;
|
||||||
|
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全服务工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class SecurityUtils {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成BCryptPasswordEncoder密码
|
||||||
|
*
|
||||||
|
* @param password 密码
|
||||||
|
*
|
||||||
|
* @return 加密字符串
|
||||||
|
*/
|
||||||
|
public static String encryptPassword (String password, String salt) {
|
||||||
|
return encryptMD5(password, salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断密码是否相同
|
||||||
|
*
|
||||||
|
* @param password 真实密码
|
||||||
|
* @param encodedPassword 加密后字符
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean matchesPassword (String password, String salt, String encodedPassword) {
|
||||||
|
return encryptMD5(password, salt).equals(encodedPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算字符串的MD5加密值,并返回Base64编码的字符串。
|
||||||
|
* @param password 要加密的字符串
|
||||||
|
* @return 加密后的Base64编码字符串
|
||||||
|
*/
|
||||||
|
public static String encryptMD5(String password, String salt) {
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
md.update((password + salt).getBytes()); // 加盐处理
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
String encodeToString = Base64.getEncoder().encodeToString(digest);
|
||||||
|
return encodeToString;
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.ysy.common.utils.tools;
|
||||||
|
|
||||||
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 字符串处理工具类
|
||||||
|
*/
|
||||||
|
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 判断一个对象是否为空
|
||||||
|
*
|
||||||
|
* @param object Object
|
||||||
|
* @return true:为空 false:非空
|
||||||
|
*/
|
||||||
|
public static boolean isNull(Object object) {
|
||||||
|
return object == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||||||
|
*
|
||||||
|
* @param coll 要判断的Collection
|
||||||
|
* @return true:为空 false:非空
|
||||||
|
*/
|
||||||
|
public static boolean isEmpty(Collection<?> coll) {
|
||||||
|
return isNull(coll) || coll.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
||||||
|
*
|
||||||
|
* @param str 指定字符串
|
||||||
|
* @param strs 需要检查的字符串数组
|
||||||
|
* @return 是否匹配
|
||||||
|
*/
|
||||||
|
public static boolean matches(String str, List<String> strs) {
|
||||||
|
if (isEmpty(str) || isEmpty(strs)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String pattern : strs) {
|
||||||
|
if (isMatch(pattern, str))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断url是否与规则配置:
|
||||||
|
* ? 表示单个字符;
|
||||||
|
* * 表示一层路径内的任意字符串,不可跨层级;
|
||||||
|
* ** 表示任意层路径;
|
||||||
|
*
|
||||||
|
* @param pattern 匹配规则
|
||||||
|
* @param url 需要匹配的url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isMatch(String pattern, String url) {
|
||||||
|
AntPathMatcher matcher = new AntPathMatcher();
|
||||||
|
return matcher.match(pattern, url);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
com.ysy.common.config.ElasticClient
|
||||||
|
com.ysy.common.config.ErrorMessageConfig
|
||||||
|
com.ysy.common.config.MybatisPlusConfig
|
||||||
|
com.ysy.common.config.RabbitPublisherConfig
|
||||||
|
com.ysy.common.exception.GlobalExceptionHandler
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_month</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>gateway</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 网关依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.ysy.gateway;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class GatewayApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(GatewayApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.ysy.gateway.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ConfigurationProperties(prefix = "auth")
|
||||||
|
@Component
|
||||||
|
@RefreshScope
|
||||||
|
public class AuthProperties {
|
||||||
|
private List<String> excludePaths;
|
||||||
|
private List<String> includePaths;
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.ysy.gateway.filter;
|
||||||
|
|
||||||
|
import com.auth0.jwt.interfaces.Claim;
|
||||||
|
import com.ysy.common.utils.gateway.GatewayUtils;
|
||||||
|
import com.ysy.common.utils.jwt.JwtUtil;
|
||||||
|
import com.ysy.common.utils.tools.StringUtils;
|
||||||
|
import com.ysy.gateway.config.AuthProperties;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.server.RequestPath;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Order(1)
|
||||||
|
@Slf4j
|
||||||
|
public class UserGlobalFilter implements GlobalFilter {
|
||||||
|
@Autowired
|
||||||
|
private AuthProperties authProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
|
String path = request.getPath().toString();
|
||||||
|
HttpMethod method = request.getMethod();
|
||||||
|
log.info("请求方式:{},请求路径:{}", path, method);
|
||||||
|
|
||||||
|
boolean matches = StringUtils.matches(path, authProperties.getExcludePaths());
|
||||||
|
|
||||||
|
if (matches) {
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
|
|
||||||
|
String token = request.getHeaders().getFirst("token");
|
||||||
|
if (StringUtils.isNull(token)) {
|
||||||
|
return GatewayUtils.errorResponse(exchange, "请先登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
Claim claim = null;
|
||||||
|
try {
|
||||||
|
claim = JwtUtil.getClaim(token);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return GatewayUtils.errorResponse(exchange, "非法参数,请重新登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Boolean.FALSE.equals(stringRedisTemplate.hasKey(token))) {
|
||||||
|
return GatewayUtils.errorResponse(exchange, "会话已过期,请重新登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
Object uid = claim.asMap().get("uid");
|
||||||
|
String username = (String) claim.asMap().get("username");
|
||||||
|
Object role = claim.asMap().get("role");
|
||||||
|
|
||||||
|
ServerHttpRequest.Builder mutate = request.mutate();
|
||||||
|
GatewayUtils.addHeader(mutate, "uid", uid);
|
||||||
|
GatewayUtils.addHeader(mutate, "username", username);
|
||||||
|
GatewayUtils.addHeader(mutate, "role", role);
|
||||||
|
|
||||||
|
GatewayUtils.removeHeader(mutate, "token");
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
server:
|
||||||
|
port: 10010
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: gateway
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#nacos配置文件配置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
- data-id: common.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_month</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>order-service</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 自定义公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.ysy.order;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients(basePackages = "com.ysy.common.remote")
|
||||||
|
public class OrderServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(OrderServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,130 @@
|
||||||
|
package com.ysy.order.controller;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.shaded.com.google.protobuf.Message;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.ysy.common.domain.po.Order;
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import com.ysy.common.remote.PlaneServiceRemote;
|
||||||
|
import com.ysy.common.remote.UserServiceRemote;
|
||||||
|
import com.ysy.order.service.OrderService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/order")
|
||||||
|
@Slf4j
|
||||||
|
public class OrderController {
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserServiceRemote userServiceRemote;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlaneServiceRemote planeServiceRemote;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result<List<Order>> list() {
|
||||||
|
String role = request.getHeader("role");
|
||||||
|
if (role.equals("true")) {
|
||||||
|
List<Order> orderList = orderService.list(new LambdaQueryWrapper<Order>()
|
||||||
|
.eq(Order::getState, false)
|
||||||
|
);
|
||||||
|
orderList.forEach(order -> {
|
||||||
|
order.setPassenger(userServiceRemote
|
||||||
|
.passengerById(order.getPassengerId())
|
||||||
|
.getData()
|
||||||
|
);
|
||||||
|
order.setPlane(planeServiceRemote
|
||||||
|
.byId(order.getPid())
|
||||||
|
.getData()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return Result.success(orderList);
|
||||||
|
}
|
||||||
|
|
||||||
|
Long uid = Long.valueOf(request.getHeader("uid"));
|
||||||
|
List<Order> orderList = orderService.list(new LambdaQueryWrapper<Order>()
|
||||||
|
.eq(Order::getUid, uid)
|
||||||
|
.eq(Order::getState, false)
|
||||||
|
);
|
||||||
|
orderList.forEach(order -> {
|
||||||
|
order.setPassenger(userServiceRemote
|
||||||
|
.passengerById(order.getPassengerId())
|
||||||
|
.getData()
|
||||||
|
);
|
||||||
|
order.setPlane(planeServiceRemote
|
||||||
|
.byId(order.getPid())
|
||||||
|
.getData()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return Result.success(orderList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Result<String> addByOrder(@RequestBody Order order) {
|
||||||
|
String username = request.getHeader("username");
|
||||||
|
Passenger passenger = userServiceRemote.passengerById(order.getPassengerId()).getData();
|
||||||
|
Order build = Order.builder()
|
||||||
|
.pid(order.getPlane().getPid())
|
||||||
|
.rate(order.getRate())
|
||||||
|
.state(false)
|
||||||
|
.takePrice(order.getTakePrice())
|
||||||
|
.passengerId(passenger.getPid())
|
||||||
|
.uid(passenger.getUid())
|
||||||
|
.build();
|
||||||
|
orderService.save(build);
|
||||||
|
|
||||||
|
rabbitTemplate.convertAndSend("simple.exchange",
|
||||||
|
"msg","恭喜用户:" + username + ",预定机票成功");
|
||||||
|
return Result.success("添加订单成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/refund/{id}")
|
||||||
|
public Result<Integer> refundById(@PathVariable String id) {
|
||||||
|
Order order = orderService.getById(id);
|
||||||
|
Plane plane = planeServiceRemote.byId(order.getPid()).getData();
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
long endTime = plane.getEndTime().getTime();
|
||||||
|
//起飞前一周
|
||||||
|
if (endTime - now >= 7 * 24 * 1000 * 60 * 60L) {
|
||||||
|
return Result.success((int) ((order.getTakePrice() - 50) * 0.4) + 50);
|
||||||
|
}
|
||||||
|
//起飞大于两天
|
||||||
|
if (endTime - now >= 48 * 1000 * 60 * 60L) {
|
||||||
|
return Result.success((int) ((order.getTakePrice() - 50) * 0.6) + 50);
|
||||||
|
}
|
||||||
|
//起飞大于两小时
|
||||||
|
if (endTime - now >= 4 * 1000 * 60 * 60L) {
|
||||||
|
return Result.success((int) ((order.getTakePrice() - 50) * 0.9));
|
||||||
|
}
|
||||||
|
return Result.success(order.getTakePrice() - 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/confirm/{id}")
|
||||||
|
public Result<String> confirmById(@PathVariable String id) {
|
||||||
|
Order order = orderService.getById(id);
|
||||||
|
order.setState(true);
|
||||||
|
orderService.updateById(order);
|
||||||
|
return Result.success("退票成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RabbitListener(queues = "simple")
|
||||||
|
public void getMessage(String msg) {
|
||||||
|
log.info("消费消息成功:" + msg);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.order.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Order;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OrderMapper extends BaseMapper<Order> {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.ysy.order.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ysy.common.domain.po.Order;
|
||||||
|
|
||||||
|
public interface OrderService extends IService<Order> {
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.ysy.order.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ysy.common.domain.po.Order;
|
||||||
|
import com.ysy.order.mapper.OrderMapper;
|
||||||
|
import com.ysy.order.service.OrderService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
|
||||||
|
implements OrderService {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
██ ██ ████████ ██ ██
|
||||||
|
░░██ ██ ██░░░░░░ ░░██ ██
|
||||||
|
░░████ ░██ ░░████
|
||||||
|
░░██ ░█████████ ░░██
|
||||||
|
░██ ░░░░░░░░██ ░██
|
||||||
|
░██ ░██ ░██
|
||||||
|
░██ ████████ ░██
|
||||||
|
░░ ░░░░░░░░ ░░
|
||||||
|
:: ysy boot :: version 1.0
|
|
@ -0,0 +1,45 @@
|
||||||
|
server:
|
||||||
|
#服务端口
|
||||||
|
port: 10003
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: orderService
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#cluster-name: SH #服务集群设置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-mysql.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-rabbitmq.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_month</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>plane-service</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 自定义公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,72 @@
|
||||||
|
package com.ysy.plane;
|
||||||
|
|
||||||
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
|
import co.elastic.clients.elasticsearch.core.BulkResponse;
|
||||||
|
import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.ysy.common.domain.po.Company;
|
||||||
|
import com.ysy.common.domain.po.Module;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import com.ysy.plane.mapper.CompanyMapper;
|
||||||
|
import com.ysy.plane.mapper.DestinationMapper;
|
||||||
|
import com.ysy.plane.mapper.ModuleMapper;
|
||||||
|
import com.ysy.plane.mapper.PlaneMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableScheduling
|
||||||
|
public class PlaneServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(PlaneServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
@Autowired
|
||||||
|
private CompanyMapper companyMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ModuleMapper moduleMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlaneMapper planeMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DestinationMapper destinationMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ElasticsearchClient elasticsearchClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在spring启动时,将航空公司和飞机型号列表存入redis,飞机列表es全量同步
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "*/10 * * * * ?")
|
||||||
|
public void run() {
|
||||||
|
List<Plane> planeList = planeMapper.selectList(null);
|
||||||
|
planeList.forEach(plane -> {
|
||||||
|
plane.setStartPlace(destinationMapper.selectById(plane.getSid()).getDestinationName());
|
||||||
|
plane.setEndPlace(destinationMapper.selectById(plane.getEid()).getDestinationName());
|
||||||
|
plane.setModuleName(moduleMapper.selectById(plane.getMid()).getModuleName());
|
||||||
|
plane.setCompanyName(companyMapper.selectById(plane.getCid()).getCompanyName());
|
||||||
|
});
|
||||||
|
|
||||||
|
ArrayList<BulkOperation> bulkOperations = new ArrayList<>();
|
||||||
|
planeList.forEach(plane -> {
|
||||||
|
bulkOperations.add(BulkOperation.of(b -> b.index(i -> i.id(String.valueOf(plane.getPid())).document(plane))));
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
BulkResponse bulkResponse = elasticsearchClient.bulk(b -> b.operations(bulkOperations).index("plane"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.ysy.plane.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.ysy.common.domain.po.Company;
|
||||||
|
import com.ysy.common.domain.po.Module;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import com.ysy.common.domain.result.PageResult;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import com.ysy.common.domain.vo.PlaneVO;
|
||||||
|
import com.ysy.plane.mapper.CompanyMapper;
|
||||||
|
import com.ysy.plane.mapper.ModuleMapper;
|
||||||
|
import com.ysy.plane.service.PlaneService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/plane")
|
||||||
|
public class PlaneController {
|
||||||
|
@Autowired
|
||||||
|
private PlaneService planeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CompanyMapper companyMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ModuleMapper moduleMapper;
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
public Result<PageResult<Plane>> list(@RequestBody PlaneVO planeVO) {
|
||||||
|
return planeService.getPlaneListByPlaneVO(planeVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<Plane> byId(@PathVariable Long id) {
|
||||||
|
Plane plane = planeService.getPlaneById(id);
|
||||||
|
return Result.success(plane);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Result<String> add() {
|
||||||
|
return Result.success("添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/company/list")
|
||||||
|
public Result<List<Company>> companyList() {
|
||||||
|
List<Company> companyList = companyMapper.selectList(null);
|
||||||
|
return Result.success(companyList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/module/list")
|
||||||
|
public Result<List<Module>> moduleList() {
|
||||||
|
List<Module> moduleList = moduleMapper.selectList(null);
|
||||||
|
return Result.success(moduleList);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.plane.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Company;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CompanyMapper extends BaseMapper<Company> {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.plane.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Destination;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface DestinationMapper extends BaseMapper<Destination> {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.plane.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Module;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ModuleMapper extends BaseMapper<Module> {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.plane.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface PlaneMapper extends BaseMapper<Plane> {
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.ysy.plane.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import com.ysy.common.domain.result.PageResult;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import com.ysy.common.domain.vo.PlaneVO;
|
||||||
|
|
||||||
|
public interface PlaneService extends IService<Plane> {
|
||||||
|
Result<PageResult<Plane>> getPlaneListByPlaneVO(PlaneVO planeVO);
|
||||||
|
|
||||||
|
Plane getPlaneById(Long id);
|
||||||
|
}
|
|
@ -0,0 +1,151 @@
|
||||||
|
package com.ysy.plane.service.impl;
|
||||||
|
|
||||||
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||||
|
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||||
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||||
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||||
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||||
|
import co.elastic.clients.elasticsearch.core.search.HighlightField;
|
||||||
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||||
|
import co.elastic.clients.json.JsonData;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ysy.common.domain.po.Plane;
|
||||||
|
import com.ysy.common.domain.result.PageResult;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import com.ysy.common.domain.vo.PlaneVO;
|
||||||
|
import com.ysy.plane.mapper.PlaneMapper;
|
||||||
|
import com.ysy.plane.service.PlaneService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PlaneServiceImpl extends ServiceImpl<PlaneMapper, Plane>
|
||||||
|
implements PlaneService {
|
||||||
|
@Autowired
|
||||||
|
private ElasticsearchClient elasticsearchClient;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<PageResult<Plane>> getPlaneListByPlaneVO(PlaneVO planeVO) {
|
||||||
|
SearchRequest.Builder searchBuilder = new SearchRequest.Builder().index("plane");
|
||||||
|
List<Query> queryList = new ArrayList<>();
|
||||||
|
Integer from = (planeVO.getPageNum() - 1) * planeVO.getPageSize();
|
||||||
|
|
||||||
|
//查询航空公司
|
||||||
|
if (StringUtils.isNotBlank(planeVO.getCompany())) {
|
||||||
|
Query query = new Query.Builder()
|
||||||
|
.match(m -> m
|
||||||
|
.field("companyName")
|
||||||
|
.query(planeVO.getCompany())
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
queryList.add(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询出发地
|
||||||
|
if (StringUtils.isNotBlank(planeVO.getStartPlace())) {
|
||||||
|
Query query = new Query.Builder()
|
||||||
|
.match(m -> m
|
||||||
|
.field("startPlace")
|
||||||
|
.query(planeVO.getStartPlace())
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
queryList.add(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询目的地
|
||||||
|
if (StringUtils.isNotBlank(planeVO.getEndPlace())) {
|
||||||
|
Query query = new Query.Builder()
|
||||||
|
.match(m -> m
|
||||||
|
.field("endPlace")
|
||||||
|
.query(planeVO.getEndPlace())
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
queryList.add(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询出发时间
|
||||||
|
if (planeVO.getStartTime() != null) {
|
||||||
|
Query query = new Query.Builder()
|
||||||
|
.range(m -> m
|
||||||
|
.field("startTime")
|
||||||
|
.gte((JsonData) planeVO.getStartTime())
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
queryList.add(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchRequest searchRequest = searchBuilder
|
||||||
|
.query(q -> q
|
||||||
|
.bool(b -> b
|
||||||
|
.must(queryList)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.highlight(h -> h
|
||||||
|
.fields("companyName", HighlightField.of(q -> q.matchedFields("companyName")))
|
||||||
|
.preTags("<font color='red'>")
|
||||||
|
.postTags("</font>")
|
||||||
|
)
|
||||||
|
.from(from)
|
||||||
|
.size(planeVO.getPageSize())
|
||||||
|
.sort(s -> s
|
||||||
|
.field(f -> f
|
||||||
|
.field("startTime")
|
||||||
|
.order(SortOrder.Desc)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
//获取查询响应对象
|
||||||
|
SearchResponse<Plane> searchResponse = null;
|
||||||
|
try {
|
||||||
|
searchResponse = elasticsearchClient.search(searchRequest, Plane.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//遍历集合
|
||||||
|
List<Plane> planeList = new ArrayList<>();
|
||||||
|
long total = searchResponse.hits().total().value();
|
||||||
|
for (Hit<Plane> hit : searchResponse.hits().hits()) {
|
||||||
|
Map<String, List<String>> highlight = hit.highlight();
|
||||||
|
Plane source = hit.source();
|
||||||
|
if (!highlight.isEmpty()) {
|
||||||
|
String companyName = highlight.get("companyName").get(0);
|
||||||
|
source.setCompanyName(companyName);
|
||||||
|
}
|
||||||
|
planeList.add(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PageResult.toResult(total, planeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plane getPlaneById(Long id) {
|
||||||
|
SearchResponse<Plane> searchResponse = null;
|
||||||
|
try {
|
||||||
|
searchResponse = elasticsearchClient
|
||||||
|
.search(s -> s
|
||||||
|
.query(q -> q
|
||||||
|
.match(m -> m
|
||||||
|
.field("pid")
|
||||||
|
.query(id)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.index("plane")
|
||||||
|
, Plane.class
|
||||||
|
);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Plane source = searchResponse.hits().hits().get(0).source();
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
██ ██ ████████ ██ ██
|
||||||
|
░░██ ██ ██░░░░░░ ░░██ ██
|
||||||
|
░░████ ░██ ░░████
|
||||||
|
░░██ ░█████████ ░░██
|
||||||
|
░██ ░░░░░░░░██ ░██
|
||||||
|
░██ ░██ ░██
|
||||||
|
░██ ████████ ░██
|
||||||
|
░░ ░░░░░░░░ ░░
|
||||||
|
:: ysy boot :: version 1.0
|
|
@ -0,0 +1,42 @@
|
||||||
|
server:
|
||||||
|
#服务端口
|
||||||
|
port: 10002
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: planeService
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#cluster-name: SH #服务集群设置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-mysql.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_month</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>common</module>
|
||||||
|
<module>gateway</module>
|
||||||
|
<module>user-service</module>
|
||||||
|
<module>order-service</module>
|
||||||
|
<module>plane-service</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<relativePath/>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
|
<version>2022.0.0.0-RC2</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>2022.0.0</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>senior_grade5_month</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>user-service</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 自定义公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ysy</groupId>
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.ysy.user;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class UserServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(UserServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.ysy.user.controller;
|
||||||
|
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import com.ysy.common.domain.result.Result;
|
||||||
|
import com.ysy.common.domain.vo.PassengerVO;
|
||||||
|
import com.ysy.common.domain.vo.UserVO;
|
||||||
|
import com.ysy.user.mapper.PassengerMapper;
|
||||||
|
import com.ysy.user.service.UserService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PassengerMapper passengerMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
public Result<String> login(@RequestBody @Validated UserVO userVO) {
|
||||||
|
String token = userService.loginByUserVO(userVO);
|
||||||
|
return Result.success("登录成功", token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/passenger/list")
|
||||||
|
public Result<List<Passenger>> passengerList() {
|
||||||
|
List<Passenger> passengerList = userService.passengerList();
|
||||||
|
return Result.success(passengerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/passenger/{id}")
|
||||||
|
public Result<Passenger> passengerById(@PathVariable Long id) {
|
||||||
|
Passenger passenger = passengerMapper.selectById(id);
|
||||||
|
return Result.success(passenger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/passenger/add")
|
||||||
|
public Result<String> passengerAdd(@RequestBody @Validated PassengerVO passengerVO) {
|
||||||
|
userService.passengerAddByPassengerVO(passengerVO);
|
||||||
|
return Result.success("添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/check")
|
||||||
|
public Result<String> check() {
|
||||||
|
String role = request.getHeader("role");
|
||||||
|
if (role.equals("false")) {
|
||||||
|
return Result.fail("非管理员不能添加");
|
||||||
|
}
|
||||||
|
return Result.success("管理员验证通过");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.user.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface PassengerMapper extends BaseMapper<Passenger> {
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ysy.user.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ysy.common.domain.po.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.ysy.user.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import com.ysy.common.domain.po.User;
|
||||||
|
import com.ysy.common.domain.vo.PassengerVO;
|
||||||
|
import com.ysy.common.domain.vo.UserVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface UserService extends IService<User> {
|
||||||
|
String loginByUserVO(UserVO userVO);
|
||||||
|
|
||||||
|
void passengerAddByPassengerVO(PassengerVO passengerVO);
|
||||||
|
|
||||||
|
List<Passenger> passengerList();
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.ysy.user.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ysy.common.domain.po.Passenger;
|
||||||
|
import com.ysy.common.domain.po.User;
|
||||||
|
import com.ysy.common.domain.vo.PassengerVO;
|
||||||
|
import com.ysy.common.domain.vo.UserVO;
|
||||||
|
import com.ysy.common.utils.jwt.JwtUtil;
|
||||||
|
import com.ysy.user.mapper.PassengerMapper;
|
||||||
|
import com.ysy.user.mapper.UserMapper;
|
||||||
|
import com.ysy.user.service.UserService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||||
|
implements UserService {
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PassengerMapper passengerMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loginByUserVO(UserVO userVO) {
|
||||||
|
User user = getOne(
|
||||||
|
new LambdaQueryWrapper<User>()
|
||||||
|
.eq(User::getUsername, userVO.getUsername()));
|
||||||
|
|
||||||
|
Assert.notNull(user, "用户不存在");
|
||||||
|
|
||||||
|
Assert.isTrue(user.getPassword().equals(userVO.getPassword()), "密码错误");
|
||||||
|
|
||||||
|
Map<String, Object> claim = BeanUtil.beanToMap(user, new HashMap<>(), false, false);
|
||||||
|
String token = JwtUtil.createToken(claim);
|
||||||
|
|
||||||
|
stringRedisTemplate.opsForValue().set(token, "login", 15, TimeUnit.MINUTES);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Passenger> passengerList() {
|
||||||
|
Long uid = Long.valueOf(request.getHeader("uid"));
|
||||||
|
List<Passenger> passengerList = passengerMapper
|
||||||
|
.selectList(new LambdaQueryWrapper<Passenger>()
|
||||||
|
.eq(Passenger::getUid, uid)
|
||||||
|
);
|
||||||
|
return passengerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void passengerAddByPassengerVO(PassengerVO passengerVO) {
|
||||||
|
Long uid = Long.valueOf(request.getHeader("uid"));
|
||||||
|
Passenger passenger = Passenger.builder()
|
||||||
|
.passengerName(passengerVO.getPassengerName())
|
||||||
|
.id(passengerVO.getId())
|
||||||
|
.uid(uid)
|
||||||
|
.build();
|
||||||
|
passengerMapper.insert(passenger);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
██ ██ ████████ ██ ██
|
||||||
|
░░██ ██ ██░░░░░░ ░░██ ██
|
||||||
|
░░████ ░██ ░░████
|
||||||
|
░░██ ░█████████ ░░██
|
||||||
|
░██ ░░░░░░░░██ ░██
|
||||||
|
░██ ░██ ░██
|
||||||
|
░██ ████████ ░██
|
||||||
|
░░ ░░░░░░░░ ░░
|
||||||
|
:: ysy boot :: version 1.0
|
|
@ -0,0 +1,42 @@
|
||||||
|
server:
|
||||||
|
#服务端口
|
||||||
|
port: 10001
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
#服务名称
|
||||||
|
name: userService
|
||||||
|
profiles:
|
||||||
|
#配置文件生效环境
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
#nacos服务器地址
|
||||||
|
server-addr: http://124.70.132.13:8848
|
||||||
|
#nacos服务发现配置
|
||||||
|
discovery:
|
||||||
|
#nacos服务注册命名空间ID,默认为public
|
||||||
|
namespace: 2e6a4975-46b3-4035-b77d-92b05ae48a66
|
||||||
|
#cluster-name: SH #服务集群设置
|
||||||
|
config:
|
||||||
|
#指定读取命名空间配置,默认为public
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
#nacos配置文件类型
|
||||||
|
file-extension: yaml
|
||||||
|
#共享配置
|
||||||
|
shared-configs:
|
||||||
|
- data-id: common.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-mysql.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
- data-id: common-redis.yaml
|
||||||
|
group: SPRING_CLOUD_COMMONS
|
||||||
|
refresh: true
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue