Changes
commit
0b46a71dab
|
@ -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,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-auth/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-common/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-gateway/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-modules/bwie-friend/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-modules/bwie-log/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-modules/bwie-red/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/bwie-modules/bwie-system/src/main/java" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliEqualsAvoidNull" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliMissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliWrapperTypeEquality" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" 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,61 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-auth</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.bwie</groupId>
|
||||||
|
<artifactId>bwie-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--短信依赖 5条依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpcore</artifactId>
|
||||||
|
<version>4.4.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-util</artifactId>
|
||||||
|
<version>9.3.7.v20160115</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.bwie.auth;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients(basePackages = "com.bwie.**")
|
||||||
|
public class AuthApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AuthApp.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.bwie.auth.controller;
|
||||||
|
|
||||||
|
import com.bwie.auth.service.AuthRegService;
|
||||||
|
import com.bwie.auth.service.AuthService;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.LoginRequest;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
|
||||||
|
public class AuthController {
|
||||||
|
|
||||||
|
private final AuthService authService;
|
||||||
|
private final AuthRegService authRegService;
|
||||||
|
|
||||||
|
public AuthController(AuthService authService, AuthRegService authRegService) {
|
||||||
|
this.authService = authService;
|
||||||
|
this.authRegService = authRegService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
Result login(@RequestBody @Validated LoginRequest loginRequest){
|
||||||
|
return Result.success(authService.login(loginRequest));
|
||||||
|
}
|
||||||
|
@PostMapping("/sendcode")
|
||||||
|
Result sendcode(@RequestParam String userTel){
|
||||||
|
authRegService.sendcode(userTel);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
@PostMapping("/reg")
|
||||||
|
Result reg(@RequestBody @Validated RegRequest request){
|
||||||
|
authRegService.reg(request);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("getInfo")
|
||||||
|
User getInfo(){
|
||||||
|
return authRegService.getInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.bwie.auth.service;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
|
||||||
|
public interface AuthRegService {
|
||||||
|
void sendcode(String userTel);
|
||||||
|
void reg(RegRequest request);
|
||||||
|
User getInfo();
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.bwie.auth.service;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.request.LoginRequest;
|
||||||
|
import com.bwie.common.domain.response.JwtResponse;
|
||||||
|
|
||||||
|
public interface AuthService {
|
||||||
|
JwtResponse login(LoginRequest loginRequest);
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.bwie.auth.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.bwie.auth.service.AuthRegService;
|
||||||
|
import com.bwie.auth.util.MsgUtil;
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import com.bwie.common.constant.TokenConstants;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.redis.RedisCache;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AuthRegServiceImpl implements AuthRegService {
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
private final RemoteUserService remoteUserService;
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
private final MsgUtil msgUtil;
|
||||||
|
|
||||||
|
public AuthRegServiceImpl(RedisCache redisCache, RemoteUserService remoteUserService, HttpServletRequest request, MsgUtil msgUtil) {
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
this.remoteUserService = remoteUserService;
|
||||||
|
this.request = request;
|
||||||
|
this.msgUtil = msgUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendcode(String userTel) {
|
||||||
|
String s = RandomUtil.randomNumbers(4);
|
||||||
|
redisCache.setCacheObject("code:"+userTel,s,Long.valueOf(5), TimeUnit.MINUTES);
|
||||||
|
msgUtil.sendMsg(userTel,s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reg(RegRequest request) {
|
||||||
|
Result<User> findtel = remoteUserService.findtel(request.getUserTel());
|
||||||
|
Assert.isTrue(findtel.isSuccess(),"注册失败");
|
||||||
|
User data = findtel.getData();
|
||||||
|
Assert.isNull(data,"电话已存在");
|
||||||
|
|
||||||
|
String cacheObject = redisCache.getCacheObject("code:" + request.getUserTel());
|
||||||
|
Assert.isTrue(cacheObject.equals(request.getUserCode()),"验证码错误");
|
||||||
|
Result<String> add=remoteUserService.adduser(
|
||||||
|
RegRequest.builder()
|
||||||
|
.userName(request.getUserName())
|
||||||
|
.userPwd(request.getUserPwd())
|
||||||
|
.userSex(request.getUserSex())
|
||||||
|
.userAddr(request.getUserAddr())
|
||||||
|
.userBirth(request.getUserBirth())
|
||||||
|
.userTel(request.getUserTel())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
Assert.isTrue(add.isSuccess(),"注册失败");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User getInfo() {
|
||||||
|
User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + request.getHeader(JwtConstants.USER_KEY));
|
||||||
|
return cacheObject;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.bwie.auth.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.http.server.HttpServerRequest;
|
||||||
|
import com.bwie.auth.service.AuthService;
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import com.bwie.common.constant.TokenConstants;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.LoginRequest;
|
||||||
|
import com.bwie.common.domain.response.JwtResponse;
|
||||||
|
import com.bwie.common.redis.RedisCache;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.common.utils.IdUtils;
|
||||||
|
import com.bwie.common.utils.JwtUtils;
|
||||||
|
import com.bwie.common.utils.SecurityUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AuthServiceImpl implements AuthService {
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
private final RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
|
||||||
|
public AuthServiceImpl(RedisCache redisCache, RemoteUserService remoteUserService) {
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
this.remoteUserService = remoteUserService;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JwtResponse login(LoginRequest loginRequest) {
|
||||||
|
Result<User> findname = remoteUserService.findname(loginRequest.getUserName());
|
||||||
|
Assert.isTrue(findname.isSuccess(),"用户登陆失败");
|
||||||
|
User data = findname.getData();
|
||||||
|
Assert.notNull(data,"用户不存在");
|
||||||
|
Assert.isTrue(
|
||||||
|
SecurityUtils.matchesPassword(
|
||||||
|
loginRequest.getUserPwd(),data.getSalt(),data.getUserPwd()
|
||||||
|
),"用户或密码错误"
|
||||||
|
);
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
String userkey = IdUtils.genId();
|
||||||
|
map.put(JwtConstants.USER_KEY,userkey);
|
||||||
|
map.put(JwtConstants.DETAILS_USER_ID,data.getUserId());
|
||||||
|
map.put(JwtConstants.DETAILS_USERNAME,data.getUserName());
|
||||||
|
String token = JwtUtils.createToken(map);
|
||||||
|
redisCache.setCacheObject(TokenConstants.LOGIN_TOKEN_KEY+userkey
|
||||||
|
,data,TokenConstants.EXPIRATION, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
Result<List<User>> users=remoteUserService.findfriends(data.getUserId());
|
||||||
|
|
||||||
|
for (User user : users.getData()) {
|
||||||
|
redisCache.setCacheObject("用户:"+data.getUserId(),user);
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteUserService.updtime(data.getUserId());
|
||||||
|
|
||||||
|
return JwtResponse.builder()
|
||||||
|
.token(token)
|
||||||
|
.expirTime(TokenConstants.EXPIRATION)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,320 @@
|
||||||
|
package com.bwie.auth.util;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HttpUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static <T> List<T> doGet(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys
|
||||||
|
,Class<T> clazz)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||||
|
if(headers!=null){
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
HttpResponse execute = httpClient.execute(request);
|
||||||
|
String s = EntityUtils.toString(execute.getEntity(),"UTF-8");
|
||||||
|
List<T> ts = JSON.parseArray(s, clazz);
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post form
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param bodys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
Map<String, String> bodys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bodys != null) {
|
||||||
|
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||||
|
|
||||||
|
for (String key : bodys.keySet()) {
|
||||||
|
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||||
|
}
|
||||||
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||||
|
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
|
request.setEntity(formEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post String
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post stream
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put String
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put stream
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doDelete(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||||
|
StringBuilder sbUrl = new StringBuilder();
|
||||||
|
sbUrl.append(host);
|
||||||
|
if (!StringUtils.isBlank(path)) {
|
||||||
|
sbUrl.append(path);
|
||||||
|
}
|
||||||
|
if (null != querys) {
|
||||||
|
StringBuilder sbQuery = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbQuery.append("&");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append(query.getValue());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isBlank(query.getKey())) {
|
||||||
|
sbQuery.append(query.getKey());
|
||||||
|
if (!StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append("=");
|
||||||
|
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbUrl.append("?").append(sbQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sbUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient wrapClient(String host) {
|
||||||
|
HttpClient httpClient = new DefaultHttpClient();
|
||||||
|
if (host.startsWith("https://")) {
|
||||||
|
sslClient(httpClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sslClient(HttpClient httpClient) {
|
||||||
|
try {
|
||||||
|
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||||
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.init(null, new TrustManager[] { tm }, null);
|
||||||
|
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||||
|
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||||
|
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||||
|
registry.register(new Scheme("https", 443, ssf));
|
||||||
|
} catch (KeyManagementException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.bwie.auth.util;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @version 1.0.0
|
||||||
|
* @ClassName MsgUtil.java
|
||||||
|
* @Description TODO
|
||||||
|
* @createTime 2022年05月26日 15:49:00
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MsgUtil {
|
||||||
|
|
||||||
|
|
||||||
|
// //列表添加
|
||||||
|
// //@CacheConfig(cacheNames = "aaa")
|
||||||
|
// //列表
|
||||||
|
// //@Cacheable
|
||||||
|
// //实时更新
|
||||||
|
// //@CacheEvict(allEntries = true)
|
||||||
|
//
|
||||||
|
// @Cacheable(key = "#phone",value = "bbb")
|
||||||
|
// public String getCacheCode(String phone){
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @CachePut(key = "#codeEntity.phone",value = "bbb")
|
||||||
|
// public String saveCacheCode(CodeEntity codeEntity){
|
||||||
|
//
|
||||||
|
// return codeEntity.getCode();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 858f87d76b7f4e618a5f7e1557f1d529
|
||||||
|
|
||||||
|
public void sendMsg(String phone,String code){
|
||||||
|
String host = "https://gyytz.market.alicloudapi.com";
|
||||||
|
String path = "/sms/smsSend";
|
||||||
|
String method = "POST";
|
||||||
|
String appcode = "13a8b5b781bc4c458ce2de65ed79be80";
|
||||||
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
|
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||||
|
headers.put("Authorization", "APPCODE " + appcode);
|
||||||
|
Map<String, String> querys = new HashMap<String, String>();
|
||||||
|
querys.put("mobile", phone);
|
||||||
|
querys.put("param", "**code**:"+code+",**minute**:5");
|
||||||
|
|
||||||
|
//smsSignId(短信前缀)和templateId(短信模板),可登录国阳云控制台自助申请。参考文档:http://help.guoyangyun.com/Problem/Qm.html
|
||||||
|
|
||||||
|
querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
|
||||||
|
querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
|
||||||
|
Map<String, String> bodys = new HashMap<String, String>();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* 重要提示如下:
|
||||||
|
* HttpUtils请从\r\n\t \t* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java\r\n\t \t* 下载
|
||||||
|
*
|
||||||
|
* 相应的依赖请参照
|
||||||
|
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||||
|
*/
|
||||||
|
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||||
|
System.out.println(response.toString());
|
||||||
|
//获取response的body
|
||||||
|
System.out.println(EntityUtils.toString(response.getEntity()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9001
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-auth
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-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>
|
||||||
|
<!-- bootstrap 启动器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringCloud Alibaba Nacos Config -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringCloud Alibaba Sentinel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 负载均衡-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringCloud Openfeign -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- JWT -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
<version>0.9.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Alibaba Fastjson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.80</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Boot Redis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- FastJson2 json工具 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.42</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Druid -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
<version>1.2.8</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mysql Connector -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.33</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis-plus 配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis 依赖配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Hibernate Validator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</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.3</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- lombok依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringBoot 测试框架 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson</artifactId>
|
||||||
|
<version>3.16.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.bwie.common.config;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONReader;
|
||||||
|
import com.alibaba.fastjson2.JSONWriter;
|
||||||
|
import com.alibaba.fastjson2.filter.Filter;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.SerializationException;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis使用FastJson序列化
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||||
|
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(
|
||||||
|
"org.springframework", "com");
|
||||||
|
|
||||||
|
private Class<T> clazz;
|
||||||
|
|
||||||
|
public FastJson2JsonRedisSerializer(Class<T> clazz) {
|
||||||
|
super();
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] serialize (T t) throws SerializationException {
|
||||||
|
if (t == null) {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T deserialize (byte[] bytes) throws SerializationException {
|
||||||
|
if (bytes == null || bytes.length <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String str = new String(bytes, DEFAULT_CHARSET);
|
||||||
|
|
||||||
|
return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.bwie.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,65 @@
|
||||||
|
package com.bwie.common.config;
|
||||||
|
|
||||||
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis配置
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableCaching
|
||||||
|
public class RedisConfig extends CachingConfigurerSupport {
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
|
public RedisTemplate<Object, Object> redisTemplate (RedisConnectionFactory connectionFactory) {
|
||||||
|
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||||
|
template.setConnectionFactory(connectionFactory);
|
||||||
|
|
||||||
|
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
||||||
|
|
||||||
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||||
|
template.setKeySerializer(new StringRedisSerializer());
|
||||||
|
template.setValueSerializer(serializer);
|
||||||
|
|
||||||
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
||||||
|
template.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
template.setHashValueSerializer(serializer);
|
||||||
|
|
||||||
|
template.afterPropertiesSet();
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DefaultRedisScript<Long> limitScript () {
|
||||||
|
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
|
||||||
|
redisScript.setScriptText(limitScriptText());
|
||||||
|
redisScript.setResultType(Long.class);
|
||||||
|
return redisScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流脚本
|
||||||
|
*/
|
||||||
|
private String limitScriptText () {
|
||||||
|
return "local key = KEYS[1]\n" +
|
||||||
|
"local count = tonumber(ARGV[1])\n" +
|
||||||
|
"local time = tonumber(ARGV[2])\n" +
|
||||||
|
"local current = redis.call('get', key);\n" +
|
||||||
|
"if current and tonumber(current) > count then\n" +
|
||||||
|
" return tonumber(current);\n" +
|
||||||
|
"end\n" +
|
||||||
|
"current = redis.call('incr', key)\n" +
|
||||||
|
"if tonumber(current) == 1 then\n" +
|
||||||
|
" redis.call('expire', key, time)\n" +
|
||||||
|
"end\n" +
|
||||||
|
"return tonumber(current);";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.bwie.common.config;
|
||||||
|
|
||||||
|
|
||||||
|
import org.redisson.Redisson;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.redisson.config.Config;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: demo02
|
||||||
|
* @BelongsPackage: com.bw.config
|
||||||
|
* @Author: zhupengfei
|
||||||
|
* @CreateTime: 2022-12-24 09:26
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedissonConfig {
|
||||||
|
|
||||||
|
@Bean(destroyMethod = "shutdown") // 服务停止后调用 shutdown 方法。
|
||||||
|
public RedissonClient redisson() throws IOException {
|
||||||
|
System.out.println("配置类初始加载......");
|
||||||
|
// 1.创建配置
|
||||||
|
Config config = new Config();
|
||||||
|
// 集群模式
|
||||||
|
// config.useClusterServers().addNodeAddress("redis://127.0.0.1:6379", "redis://127.0.0.1:6378").setPassword("yourPassword");
|
||||||
|
// 单节点模式
|
||||||
|
config.useSingleServer()
|
||||||
|
.setAddress("redis://124.221.177.197:6379")
|
||||||
|
.setPassword("admin111."); // 添加这行来设置密码
|
||||||
|
// 2.根据 Config 创建出 RedissonClient 实例。
|
||||||
|
return Redisson.create(config);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.bwie.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 系统常量
|
||||||
|
* @author DongZl
|
||||||
|
*/
|
||||||
|
public class Constants {
|
||||||
|
/**
|
||||||
|
* 成功标记
|
||||||
|
*/
|
||||||
|
public static final Integer SUCCESS = 200;
|
||||||
|
public static final String SUCCESS_MSG = "操作成功";
|
||||||
|
/**
|
||||||
|
* 失败标记
|
||||||
|
*/
|
||||||
|
public static final Integer ERROR = 500;
|
||||||
|
public static final String ERROR_MSG = "操作异常";
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.bwie.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: Jwt常量
|
||||||
|
*/
|
||||||
|
public class JwtConstants {
|
||||||
|
/**
|
||||||
|
* 用户ID字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_USER_ID = "user_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_USERNAME = "username";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户标识
|
||||||
|
*/
|
||||||
|
public static final String USER_KEY = "user_key";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌秘钥
|
||||||
|
*/
|
||||||
|
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.bwie.common.constant;
|
||||||
|
|
||||||
|
public class ServerNameConstants {
|
||||||
|
|
||||||
|
public final static String SYSTEM_NAME="bwie-system";
|
||||||
|
public final static String LOG_NAME="bwie-es";
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bwie.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 令牌常量
|
||||||
|
*/
|
||||||
|
public class TokenConstants {
|
||||||
|
/**
|
||||||
|
* 缓存有效期,默认720(分钟)
|
||||||
|
*/
|
||||||
|
public final static long EXPIRATION = 720;
|
||||||
|
/**
|
||||||
|
* 缓存刷新时间,默认120(分钟)
|
||||||
|
*/
|
||||||
|
public final static long REFRESH_TIME = 120;
|
||||||
|
/**
|
||||||
|
* 权限缓存前缀
|
||||||
|
*/
|
||||||
|
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||||
|
/**
|
||||||
|
* token标识
|
||||||
|
*/
|
||||||
|
public static final String TOKEN = "token";
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bwie.common.domain;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@TableName(value = "friend")
|
||||||
|
public class Friend {
|
||||||
|
@TableId(value = "fr_id",type = IdType.AUTO)
|
||||||
|
private Long frId;
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private Long userId;
|
||||||
|
@TableField(value = "user_fr")
|
||||||
|
private Long userFr;
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.bwie.common.domain;
|
||||||
|
|
||||||
|
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(value = "log")
|
||||||
|
public class Log {
|
||||||
|
@TableId(value = "log_id",type = IdType.AUTO)
|
||||||
|
private Long logId;
|
||||||
|
@TableField(value = "red_id")
|
||||||
|
private Long redId;
|
||||||
|
@TableField(value = "user_name")
|
||||||
|
private String userName;
|
||||||
|
@TableField(value = "red_theme")
|
||||||
|
private String redTheme;
|
||||||
|
@TableField(value = "log_time")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date logTime;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.bwie.common.domain;
|
||||||
|
|
||||||
|
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 Red {
|
||||||
|
private Long redId;
|
||||||
|
private String redTheme;
|
||||||
|
private Integer redMoney;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date redTime;
|
||||||
|
private Integer redSum;
|
||||||
|
private Double redYu;
|
||||||
|
private Integer redNum;
|
||||||
|
private Integer redLong;
|
||||||
|
private Integer redStatus;
|
||||||
|
private Integer redYn;
|
||||||
|
private Long userId;
|
||||||
|
private String userTel;
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.bwie.common.domain;
|
||||||
|
|
||||||
|
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.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.utils.IdUtils;
|
||||||
|
import com.bwie.common.utils.SecurityUtils;
|
||||||
|
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(value = "user")
|
||||||
|
public class User {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long userId;
|
||||||
|
@TableField(value = "user_name")
|
||||||
|
private String userName;
|
||||||
|
@TableField(value = "user_pwd")
|
||||||
|
private String userPwd;
|
||||||
|
|
||||||
|
private String salt;
|
||||||
|
@TableField(value = "user_tel")
|
||||||
|
private String userTel;
|
||||||
|
@TableField(value = "user_birth")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date userBirth;
|
||||||
|
@TableField(value = "user_addr")
|
||||||
|
private String userAddr;
|
||||||
|
@TableField(value = "user_sex")
|
||||||
|
private String userSex;
|
||||||
|
@TableField(value = "user_time")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date userTime;
|
||||||
|
@TableField(value = "user_yu")
|
||||||
|
private Double userYu;
|
||||||
|
@TableField(value = "user_status")
|
||||||
|
private Integer userStatus;
|
||||||
|
|
||||||
|
public static User addBuild(RegRequest request){
|
||||||
|
String salt = IdUtils.genId();
|
||||||
|
String s = SecurityUtils.encryptPassword(request.getUserPwd(), salt);
|
||||||
|
return User.builder()
|
||||||
|
.userYu(0.0)
|
||||||
|
.userPwd(s)
|
||||||
|
.userName(request.getUserName())
|
||||||
|
.salt(salt)
|
||||||
|
.userTel(request.getUserTel())
|
||||||
|
.userAddr(request.getUserAddr())
|
||||||
|
.userBirth(request.getUserBirth())
|
||||||
|
.userSex(request.getUserSex())
|
||||||
|
.userStatus(3)
|
||||||
|
.userTime(null)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
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 AddLog {
|
||||||
|
private Long redId;
|
||||||
|
private String userName;
|
||||||
|
private String redTheme;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class DelRequest {
|
||||||
|
private Long userFr;
|
||||||
|
private String userTel;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FriendRequest {
|
||||||
|
private String userName;
|
||||||
|
private String userSex;
|
||||||
|
private Long userId;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class LoginRequest {
|
||||||
|
@NotBlank(message = "用户名不为空")
|
||||||
|
private String userName;
|
||||||
|
@NotBlank(message = "密码不为空")
|
||||||
|
private String userPwd;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
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 RedRequest {
|
||||||
|
private Integer start;
|
||||||
|
private Integer end;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date redTime;
|
||||||
|
private Long userId;
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
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 javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class RegRequest {
|
||||||
|
@NotBlank(message = "用户名不为空")
|
||||||
|
private String userName;
|
||||||
|
@NotBlank(message = "密码不为空")
|
||||||
|
private String userPwd;
|
||||||
|
@NotBlank(message = "验证码不为空")
|
||||||
|
private String userCode;
|
||||||
|
@NotBlank(message = "手机号不为空")
|
||||||
|
@Pattern(regexp = "^(?:(?:\\+|00)86)?1\\d{10}$",message = "手机号格式不正确")
|
||||||
|
private String userTel;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date userBirth;
|
||||||
|
private String userAddr;
|
||||||
|
private String userSex;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SendredRequest {
|
||||||
|
private Long redId;
|
||||||
|
private String redTheme;
|
||||||
|
private Integer redMoney;
|
||||||
|
private Integer redSum;
|
||||||
|
private Integer redLong;
|
||||||
|
private Long userId;
|
||||||
|
private List<Integer> users;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class ShowRequest {
|
||||||
|
private String userName;
|
||||||
|
private String userSex;
|
||||||
|
private String addrName;
|
||||||
|
private Integer sort;
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.bwie.common.domain.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class SnatchingQuest {
|
||||||
|
private Long redId;
|
||||||
|
private Integer redMoney;
|
||||||
|
private String redTheme;
|
||||||
|
private Integer redSum;
|
||||||
|
private Double redYu;
|
||||||
|
private Integer redNum;
|
||||||
|
private Double increMoney;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.bwie.common.domain.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class JwtResponse {
|
||||||
|
private String token;
|
||||||
|
private Long expirTime;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.bwie.common.domain.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class Users {
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
private String userName;
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.bwie.common.handler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.validation.ObjectError;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Log4j2
|
||||||
|
@Configuration
|
||||||
|
public class GlobalExceptionHandle {
|
||||||
|
|
||||||
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||||
|
public Result<String> runtimeException(MethodArgumentNotValidException exception){
|
||||||
|
log.error("请求异常:[{}]",exception.getMessage(),exception);
|
||||||
|
return Result.error(
|
||||||
|
JSONObject.toJSONString(
|
||||||
|
exception.getBindingResult().getAllErrors()
|
||||||
|
.stream()
|
||||||
|
.map(ObjectError::getDefaultMessage)
|
||||||
|
.toArray()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// return Result.error(
|
||||||
|
// exception.getBindingResult().getAllErrors()
|
||||||
|
// .stream()
|
||||||
|
// .map(ObjectError::getDefaultMessage)
|
||||||
|
// .collect(Collectors.joining()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ExceptionHandler(value = IllegalArgumentException.class)
|
||||||
|
public Result<String> illegalArgumentExceptionHandle(IllegalArgumentException exception){
|
||||||
|
log.error("请求异常[{}]",exception.getMessage(),exception);
|
||||||
|
return Result.error(exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,260 @@
|
||||||
|
package com.bwie.common.redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.BoundSetOperations;
|
||||||
|
import org.springframework.data.redis.core.HashOperations;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* spring redis 工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
**/
|
||||||
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
|
@Component
|
||||||
|
public class RedisCache {
|
||||||
|
@Autowired
|
||||||
|
public RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存基本的对象,Integer、String、实体类等
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param value 缓存的值
|
||||||
|
*/
|
||||||
|
public <T> void setCacheObject (final String key, final T value) {
|
||||||
|
redisTemplate.opsForValue().set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存基本的对象,Integer、String、实体类等
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param value 缓存的值
|
||||||
|
* @param timeout 时间
|
||||||
|
* @param timeUnit 时间颗粒度
|
||||||
|
*/
|
||||||
|
public <T> void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
|
||||||
|
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param timeout 超时时间
|
||||||
|
*
|
||||||
|
* @return true=设置成功;false=设置失败
|
||||||
|
*/
|
||||||
|
public boolean expire (final String key, final long timeout) {
|
||||||
|
return expire(key, timeout, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param timeout 超时时间
|
||||||
|
* @param unit 时间单位
|
||||||
|
*
|
||||||
|
* @return true=设置成功;false=设置失败
|
||||||
|
*/
|
||||||
|
public boolean expire (final String key, final long timeout, final TimeUnit unit) {
|
||||||
|
return Boolean.TRUE.equals(redisTemplate.expire(key, timeout, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
*
|
||||||
|
* @return 有效时间
|
||||||
|
*/
|
||||||
|
public long getExpire (final String key) {
|
||||||
|
return redisTemplate.getExpire(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断 key是否存在
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
*
|
||||||
|
* @return true 存在 false不存在
|
||||||
|
*/
|
||||||
|
public Boolean hasKey (String key) {
|
||||||
|
return redisTemplate.hasKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的基本对象。
|
||||||
|
*
|
||||||
|
* @param key 缓存键值
|
||||||
|
*
|
||||||
|
* @return 缓存键值对应的数据
|
||||||
|
*/
|
||||||
|
public <T> T getCacheObject (final String key) {
|
||||||
|
ValueOperations<String, T> operation = redisTemplate.opsForValue();
|
||||||
|
return operation.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单个对象
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public boolean deleteObject (final String key) {
|
||||||
|
return redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除集合对象
|
||||||
|
*
|
||||||
|
* @param collection 多个对象
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean deleteObject (final Collection collection) {
|
||||||
|
return redisTemplate.delete(collection) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存List数据
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param dataList 待缓存的List数据
|
||||||
|
*
|
||||||
|
* @return 缓存的对象
|
||||||
|
*/
|
||||||
|
public <T> long setCacheList (final String key, final List<T> dataList) {
|
||||||
|
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
|
||||||
|
return count == null ? 0 : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的list对象
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
*
|
||||||
|
* @return 缓存键值对应的数据
|
||||||
|
*/
|
||||||
|
public <T> List<T> getCacheList (final String key) {
|
||||||
|
return redisTemplate.opsForList().range(key, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存Set
|
||||||
|
*
|
||||||
|
* @param key 缓存键值
|
||||||
|
* @param dataSet 缓存的数据
|
||||||
|
*
|
||||||
|
* @return 缓存数据的对象
|
||||||
|
*/
|
||||||
|
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
|
||||||
|
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||||
|
for (T t : dataSet) {
|
||||||
|
setOperation.add(t);
|
||||||
|
}
|
||||||
|
return setOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的set
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T> Set<T> getCacheSet (final String key) {
|
||||||
|
return redisTemplate.opsForSet().members(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存Map
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @param dataMap
|
||||||
|
*/
|
||||||
|
public <T> void setCacheMap (final String key, final Map<String, T> dataMap) {
|
||||||
|
if (dataMap != null) {
|
||||||
|
redisTemplate.opsForHash().putAll(key, dataMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的Map
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T> Map<String, T> getCacheMap (final String key) {
|
||||||
|
return redisTemplate.opsForHash().entries(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 往Hash中存入数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
public <T> void setCacheMapValue (final String key, final String hKey, final T value) {
|
||||||
|
redisTemplate.opsForHash().put(key, hKey, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Hash中的数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
*
|
||||||
|
* @return Hash中的对象
|
||||||
|
*/
|
||||||
|
public <T> T getCacheMapValue (final String key, final String hKey) {
|
||||||
|
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
|
||||||
|
return opsForHash.get(key, hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取多个Hash中的数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKeys Hash键集合
|
||||||
|
*
|
||||||
|
* @return Hash对象集合
|
||||||
|
*/
|
||||||
|
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
|
||||||
|
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除Hash中的某条数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
*
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
public boolean deleteCacheMapValue (final String key, final String hKey) {
|
||||||
|
return redisTemplate.opsForHash().delete(key, hKey) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的基本对象列表
|
||||||
|
*
|
||||||
|
* @param pattern 字符串前缀
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
public Collection<String> keys (final String pattern) {
|
||||||
|
return redisTemplate.keys(pattern);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.bwie.common.remote.log;
|
||||||
|
|
||||||
|
import com.bwie.common.constant.ServerNameConstants;
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.remote.log.factory.RemoteLogFactory;
|
||||||
|
import com.bwie.common.remote.system.factory.RemoteUserFactory;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@FeignClient(
|
||||||
|
name = ServerNameConstants.LOG_NAME,
|
||||||
|
fallbackFactory = RemoteLogFactory.class
|
||||||
|
)
|
||||||
|
public interface RemoteLogService {
|
||||||
|
|
||||||
|
@PostMapping("addlog")
|
||||||
|
Result addlog(@RequestBody Log build);
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.bwie.common.remote.log.factory;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.remote.log.RemoteLogService;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class RemoteLogFactory implements FallbackFactory<RemoteLogService> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteLogService create(Throwable cause) {
|
||||||
|
|
||||||
|
|
||||||
|
return new RemoteLogService() {
|
||||||
|
@Override
|
||||||
|
public Result addlog(Log build) {
|
||||||
|
log.error("添加日志远程调用失败,[{}-{}]",build,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.bwie.common.remote.system;
|
||||||
|
|
||||||
|
import com.bwie.common.constant.ServerNameConstants;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.remote.system.factory.RemoteUserFactory;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@FeignClient(
|
||||||
|
name = ServerNameConstants.SYSTEM_NAME,
|
||||||
|
fallbackFactory = RemoteUserFactory.class
|
||||||
|
)
|
||||||
|
public interface RemoteUserService {
|
||||||
|
@PostMapping("findname")
|
||||||
|
public Result<User> findname(@RequestParam String userName);
|
||||||
|
|
||||||
|
@PostMapping("findtel")
|
||||||
|
Result<User> findtel(@RequestParam String userTel);
|
||||||
|
|
||||||
|
@PostMapping("adduser")
|
||||||
|
Result<String> adduser(@RequestBody RegRequest build);
|
||||||
|
|
||||||
|
@PostMapping("findfriends")
|
||||||
|
Result<List<User>> findfriends(@RequestParam Long userId);
|
||||||
|
|
||||||
|
@PostMapping("updmoney")
|
||||||
|
public Result updmoney(@RequestBody SendredRequest sendredRequest);
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("backmoney")
|
||||||
|
Result backmoney(@RequestBody List<Red> findred);
|
||||||
|
|
||||||
|
@PostMapping("updtime")
|
||||||
|
Result updtime(@RequestParam Long userId);
|
||||||
|
|
||||||
|
@PostMapping("addmoney")
|
||||||
|
Result addmoney(@RequestParam Long userId, Double increMoney);
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.bwie.common.remote.system.factory;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class RemoteUserFactory implements FallbackFactory<RemoteUserService> {
|
||||||
|
@Override
|
||||||
|
public RemoteUserService create(Throwable cause) {
|
||||||
|
return new RemoteUserService() {
|
||||||
|
@Override
|
||||||
|
public Result<User> findname(String userName) {
|
||||||
|
log.error("查找用户远程调用失败:[{}-{}]",userName,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<User> findtel(String userTel) {
|
||||||
|
log.error("查找电话远程调用失败,[{}-{}]",userTel,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<String> adduser(RegRequest build) {
|
||||||
|
log.error("添加用户远程调用失败,[{}-{}]",build,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<User>> findfriends(Long userId) {
|
||||||
|
log.error("查找朋友远程调用失败,[{}-{}]",userId,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result updmoney(SendredRequest sendredRequest) {
|
||||||
|
log.error("修改余额远程调用失败,[{}-{}]",sendredRequest,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result backmoney(List<Red> findred) {
|
||||||
|
log.error("修改余额远程调用失败,[{}-{}]",findred,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result updtime(Long userId) {
|
||||||
|
log.error("修改登陆状态,时间远程调用失败,[{}-{}]",userId,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result addmoney(Long userId, Double increMoney) {
|
||||||
|
log.error("抢到红包增加余额远程调用失败,[{}-{}]",userId,cause.getMessage(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.bwie.common.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 列表返回结果集
|
||||||
|
*/
|
||||||
|
@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,63 @@
|
||||||
|
package com.bwie.common.result;
|
||||||
|
|
||||||
|
|
||||||
|
import com.bwie.common.constant.Constants;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 响应信息主体
|
||||||
|
* @author DongZl
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/** 成功 */
|
||||||
|
public static final int SUCCESS = Constants.SUCCESS;
|
||||||
|
/** 失败 */
|
||||||
|
public static final int FAIL = Constants.ERROR;
|
||||||
|
private int code;
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
public static <T> Result<T> success() {
|
||||||
|
return restResult(null, SUCCESS, Constants.SUCCESS_MSG);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
return restResult(data, SUCCESS, Constants.SUCCESS_MSG);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> success(T data, String msg) {
|
||||||
|
return restResult(data, SUCCESS, msg);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> error() {
|
||||||
|
return restResult(null, FAIL, Constants.ERROR_MSG);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> error(String msg) {
|
||||||
|
return restResult(null, FAIL, msg);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> error(T data) {
|
||||||
|
return restResult(data, FAIL, Constants.ERROR_MSG);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> error(T data, String msg) {
|
||||||
|
return restResult(data, FAIL, msg);
|
||||||
|
}
|
||||||
|
public static <T> Result<T> error(int code, String msg) {
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
private static <T> Result<T> restResult(T data, int code, String msg) {
|
||||||
|
Result<T> apiResult = new Result<>();
|
||||||
|
apiResult.setCode(code);
|
||||||
|
apiResult.setData(data);
|
||||||
|
apiResult.setMsg(msg);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess(){
|
||||||
|
return this.code==SUCCESS;
|
||||||
|
}
|
||||||
|
public boolean isError(){
|
||||||
|
return !isSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bwie.common.utils;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: ID生成工具类
|
||||||
|
* @Date 2024-1-10 下午 08:26
|
||||||
|
*/
|
||||||
|
public class IdUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成UUID
|
||||||
|
* @return UUID
|
||||||
|
*/
|
||||||
|
public static String genId(){
|
||||||
|
return UUID.randomUUID().toString().replace("-", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.bwie.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Jwt工具类
|
||||||
|
* @author DongZl
|
||||||
|
*/
|
||||||
|
public class JwtUtils {
|
||||||
|
|
||||||
|
public static String secret = JwtConstants.SECRET;
|
||||||
|
/**
|
||||||
|
* 从数据声明生成令牌
|
||||||
|
*
|
||||||
|
* @param claims 数据声明
|
||||||
|
* @return 令牌
|
||||||
|
*/
|
||||||
|
public static String createToken(Map<String, Object> claims){
|
||||||
|
String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 从令牌中获取数据声明
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 数据声明
|
||||||
|
*/
|
||||||
|
public static Claims parseToken(String token){
|
||||||
|
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户标识
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserKey(String token){
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, JwtConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户标识
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserKey(Claims claims){
|
||||||
|
return getValue(claims, JwtConstants.USER_KEY);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户ID
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserId(String token){
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USER_ID);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取用户ID
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户ID
|
||||||
|
*/
|
||||||
|
public static String getUserId(Claims claims){
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USER_ID);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据令牌获取用户名
|
||||||
|
*
|
||||||
|
* @param token 令牌
|
||||||
|
* @return 用户名
|
||||||
|
*/
|
||||||
|
public static String getUserName(String token){
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取用户名
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @return 用户名
|
||||||
|
*/
|
||||||
|
public static String getUserName(Claims claims){
|
||||||
|
return getValue(claims, JwtConstants.DETAILS_USERNAME);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取键值
|
||||||
|
*
|
||||||
|
* @param claims 身份信息
|
||||||
|
* @param key 键
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
public static String getValue(Claims claims, String key){
|
||||||
|
Object obj = claims.get(key);
|
||||||
|
return obj == null ? "" : obj.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.bwie.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
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 rawPassword 真实密码
|
||||||
|
* @param encodedPassword 加密后字符
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean matchesPassword (String rawPassword, String salt, String encodedPassword) {
|
||||||
|
return encryptMD5(rawPassword, 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();
|
||||||
|
return Base64.getEncoder().encodeToString(digest);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.bwie.common.utils;
|
||||||
|
|
||||||
|
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,8 @@
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
com.bwie.common.config.MybatisPlusConfig,\
|
||||||
|
com.bwie.common.handler.GlobalExceptionHandle,\
|
||||||
|
com.bwie.common.config.RedisConfig,\
|
||||||
|
com.bwie.common.redis.RedisCache,\
|
||||||
|
com.bwie.common.remote.system.factory.RemoteUserFactory,\
|
||||||
|
com.bwie.common.remote.log.factory.RemoteLogFactory,\
|
||||||
|
com.bwie.common.config.RedissonConfig
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-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.bwie</groupId>
|
||||||
|
<artifactId>bwie-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 网关依赖 -->
|
||||||
|
<!-- SpringCloud Gateway -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringCloud Alibaba Sentinel Gateway -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 引入阿里巴巴sentinel限流 依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.bwie.gateway;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
|
||||||
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
|
public class GatewayApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(GatewayApp.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.bwie.gateway.config;
|
||||||
|
|
||||||
|
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
|
||||||
|
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
|
||||||
|
import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecation: 网关限流控件
|
||||||
|
* @author DongZl
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class GatewaySentinelConfig {
|
||||||
|
/**
|
||||||
|
* 查看解析器
|
||||||
|
*/
|
||||||
|
private final List<ViewResolver> viewResolvers;
|
||||||
|
/**
|
||||||
|
* 服务器编解码器配置
|
||||||
|
*/
|
||||||
|
private final ServerCodecConfigurer serverCodecConfigurer;
|
||||||
|
public GatewaySentinelConfig(ObjectProvider<List<ViewResolver>> viewResolversProvider,
|
||||||
|
ServerCodecConfigurer serverCodecConfigurer) {
|
||||||
|
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
|
||||||
|
this.serverCodecConfigurer = serverCodecConfigurer;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sentinel 网关块异常处理程序
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
|
||||||
|
// 给 Spring Cloud Gateway 注册块异常处理程序。
|
||||||
|
return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化网关配置
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void doInit() {
|
||||||
|
initGatewayRules();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 配置限流规则
|
||||||
|
*/
|
||||||
|
private void initGatewayRules() {
|
||||||
|
Set<GatewayFlowRule> rules = new HashSet<>();
|
||||||
|
rules.add(new GatewayFlowRule("cloud-user")
|
||||||
|
// 限流阈值
|
||||||
|
.setCount(1)
|
||||||
|
// 统计时间窗口,单位是秒,默认是 1 秒
|
||||||
|
.setIntervalSec(5)
|
||||||
|
);
|
||||||
|
//添加到限流规则当中
|
||||||
|
GatewayRuleManager.loadRules(rules);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.bwie.gateway.config;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 放行白名单配置
|
||||||
|
* @author DongZl
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@RefreshScope
|
||||||
|
@ConfigurationProperties(prefix = "ignore")
|
||||||
|
@Data
|
||||||
|
@Log4j2
|
||||||
|
public class IgnoreWhiteConfig {
|
||||||
|
/**
|
||||||
|
* 放行白名单配置,网关不校验此处的白名单
|
||||||
|
*/
|
||||||
|
private List<String> whites = new ArrayList<>();
|
||||||
|
|
||||||
|
public void setWhites(List<String> whites) {
|
||||||
|
log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites));
|
||||||
|
this.whites = whites;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.bwie.gateway.filters;
|
||||||
|
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import com.bwie.common.constant.TokenConstants;
|
||||||
|
import com.bwie.common.redis.RedisCache;
|
||||||
|
import com.bwie.common.utils.JwtUtils;
|
||||||
|
import com.bwie.common.utils.StringUtils;
|
||||||
|
import com.bwie.gateway.config.IgnoreWhiteConfig;
|
||||||
|
import com.bwie.gateway.utils.GatewayUtils;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class AuthFilter implements GlobalFilter, Ordered {
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
private final IgnoreWhiteConfig ignoreWhiteConfig;
|
||||||
|
|
||||||
|
public AuthFilter(RedisCache redisCache, IgnoreWhiteConfig ignoreWhiteConfig) {
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
this.ignoreWhiteConfig = ignoreWhiteConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
|
HttpHeaders headers = request.getHeaders();
|
||||||
|
HttpMethod method = request.getMethod();
|
||||||
|
ServerHttpRequest.Builder mutate = request.mutate();
|
||||||
|
String path = request.getURI().getPath();
|
||||||
|
System.out.println("path = " + path);
|
||||||
|
System.out.println("method = " + method);
|
||||||
|
if(StringUtils.matches(path,ignoreWhiteConfig.getWhites())){
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
|
String first = headers.getFirst(TokenConstants.TOKEN);
|
||||||
|
if(StringUtils.isEmpty(first)){
|
||||||
|
return GatewayUtils.errorResponse(exchange,"令牌不能为空");
|
||||||
|
}
|
||||||
|
Claims claims = JwtUtils.parseToken(first);
|
||||||
|
if(claims==null){
|
||||||
|
return GatewayUtils.errorResponse(exchange,"令牌已过期或验证不正确");
|
||||||
|
}
|
||||||
|
String userKey = JwtUtils.getUserKey(claims);
|
||||||
|
Boolean b = redisCache.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||||
|
if(!b){
|
||||||
|
return GatewayUtils.errorResponse(exchange,"登陆状态已过期");
|
||||||
|
}
|
||||||
|
String userId = JwtUtils.getUserId(claims);
|
||||||
|
String userName = JwtUtils.getUserName(claims);
|
||||||
|
GatewayUtils.addHander(mutate, JwtConstants.USER_KEY,userKey);
|
||||||
|
GatewayUtils.addHander(mutate,JwtConstants.DETAILS_USERNAME,userName);
|
||||||
|
GatewayUtils.addHander(mutate,JwtConstants.DETAILS_USER_ID,userId);
|
||||||
|
GatewayUtils.removeHeader(mutate,TokenConstants.TOKEN);
|
||||||
|
|
||||||
|
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||||
|
}
|
||||||
|
//@Override
|
||||||
|
//public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
// List<String> whites = ignoreWhiteConfig.getWhites();
|
||||||
|
// String path = exchange.getRequest().getURI().getPath();
|
||||||
|
// System.out.println("path >>>>>>>>>>>>>>>>>>>>>>>> = " + path);
|
||||||
|
// if(StringUtils.matches(path,whites)){
|
||||||
|
// return chain.filter(exchange);
|
||||||
|
// }
|
||||||
|
// String first = exchange.getRequest().getHeaders().getFirst(TokenConstants.TOKEN);
|
||||||
|
// if(null==first){
|
||||||
|
// return GatewayUtils.errorResponse(exchange,"token不为空");
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// JwtUtils.parseToken(first);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// return GatewayUtils.errorResponse(exchange,"token格式不正确");
|
||||||
|
// }
|
||||||
|
// String userKey = JwtUtils.getUserKey(first);
|
||||||
|
// if(!redisCache.hasKey(TokenConstants.LOGIN_TOKEN_KEY+userKey)){
|
||||||
|
// return GatewayUtils.errorResponse(exchange,"token已过期");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// redisCache.expire(TokenConstants.LOGIN_TOKEN_KEY+userKey,30, TimeUnit.MINUTES);
|
||||||
|
// return chain.filter(exchange);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.bwie.gateway.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.common.utils.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;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
public class GatewayUtils {
|
||||||
|
public static void addHander(ServerHttpRequest.Builder mutate,String key,Object value) {
|
||||||
|
if(StringUtils.isEmpty(key)){
|
||||||
|
log.warn("添加请求头参数键不可以为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(value==null){
|
||||||
|
log.warn("添加请求头参数:[{}]值为空",key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String string = value.toString();
|
||||||
|
mutate.header(key,string);
|
||||||
|
log.info("添加请求头参数成功 - 键:{[]},值:{[]}",key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
public static Mono<Void> errorResponse(ServerWebExchange exchange,String msg){
|
||||||
|
ServerHttpResponse response = exchange.getResponse();
|
||||||
|
response.setStatusCode(HttpStatus.OK);
|
||||||
|
response.getHeaders().add(HttpHeaders.CONTENT_TYPE,"application/json");
|
||||||
|
Result<Object> error = Result.error(msg);
|
||||||
|
String jsonString = JSONObject.toJSONString(error);
|
||||||
|
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]",
|
||||||
|
exchange.getRequest().getPath(),msg,jsonString);
|
||||||
|
DataBuffer wrap = response.bufferFactory().wrap(jsonString.getBytes());
|
||||||
|
return response.writeWith(Mono.just(wrap));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 18080
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-gateway
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
main:
|
||||||
|
# 允许使用循环引用
|
||||||
|
allow-circular-references: true
|
||||||
|
# 允许定义相同的bean对象 去覆盖原有的
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-friend</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.bwie</groupId>
|
||||||
|
<artifactId>bwie-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--短信依赖 5条依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpcore</artifactId>
|
||||||
|
<version>4.4.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-util</artifactId>
|
||||||
|
<version>9.3.7.v20160115</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.bwie.friend;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients(basePackages = "com.bwie.**")
|
||||||
|
@MapperScan("com.bwie.friend.mapper")
|
||||||
|
public class FriendApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(FriendApp.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
package com.bwie.friend.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import com.bwie.common.constant.TokenConstants;
|
||||||
|
import com.bwie.common.domain.Friend;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.DelRequest;
|
||||||
|
import com.bwie.common.domain.request.FriendRequest;
|
||||||
|
import com.bwie.common.domain.request.ShowRequest;
|
||||||
|
import com.bwie.common.redis.RedisCache;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.friend.service.FriendService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@ResponseBody
|
||||||
|
public class FriendController {
|
||||||
|
|
||||||
|
|
||||||
|
private final FriendService friendService;
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
|
||||||
|
public FriendController(FriendService friendService, RedisCache redisCache, HttpServletRequest request) {
|
||||||
|
this.friendService = friendService;
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("addfriend")
|
||||||
|
Result addfriend(@RequestParam Long userId) {
|
||||||
|
friendService.save(
|
||||||
|
Friend.builder()
|
||||||
|
.userId(userId)
|
||||||
|
.userFr(getInfo().getUserId()).build()
|
||||||
|
);
|
||||||
|
friendService.save(
|
||||||
|
Friend.builder()
|
||||||
|
.userId(getInfo().getUserId())
|
||||||
|
.userFr(userId).build()
|
||||||
|
);
|
||||||
|
return friendService.addfriend();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("show")
|
||||||
|
public Result show(@RequestBody FriendRequest friendRequest){
|
||||||
|
Result result = friendService.show(friendRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("delfriend")
|
||||||
|
public Result delfriend(@RequestBody DelRequest delRequest){
|
||||||
|
Result result = friendService.delfriend(delRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("showall")
|
||||||
|
public Result showall(@RequestBody ShowRequest showRequest){
|
||||||
|
Result result = friendService.showall(showRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("showfriend")
|
||||||
|
public Result showfriend(){
|
||||||
|
|
||||||
|
Result result = friendService.showfriend();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public User getInfo() {
|
||||||
|
User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + request.getHeader(JwtConstants.USER_KEY));
|
||||||
|
return cacheObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bwie.friend.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bwie.common.domain.Friend;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.FriendRequest;
|
||||||
|
import com.bwie.common.domain.request.ShowRequest;
|
||||||
|
import com.bwie.common.domain.response.Users;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface FriendMapper extends BaseMapper<Friend> {
|
||||||
|
List<User> show(FriendRequest friendRequest);
|
||||||
|
|
||||||
|
void delfriend(@Param("userFr") Long userFr, @Param("userId") Long userId);
|
||||||
|
|
||||||
|
List<User> showall(ShowRequest showRequest);
|
||||||
|
|
||||||
|
|
||||||
|
List<Users> showfriend(Long userId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.bwie.friend.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bwie.common.domain.Friend;
|
||||||
|
import com.bwie.common.domain.request.DelRequest;
|
||||||
|
import com.bwie.common.domain.request.FriendRequest;
|
||||||
|
import com.bwie.common.domain.request.ShowRequest;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
|
||||||
|
public interface FriendService extends IService<Friend> {
|
||||||
|
|
||||||
|
Result show(FriendRequest friendRequest);
|
||||||
|
|
||||||
|
Result showfriend();
|
||||||
|
|
||||||
|
Result delfriend(DelRequest delRequest);
|
||||||
|
Result showall(ShowRequest showRequest);
|
||||||
|
|
||||||
|
Result addfriend();
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.bwie.friend.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import com.bwie.common.constant.TokenConstants;
|
||||||
|
import com.bwie.common.domain.Friend;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.DelRequest;
|
||||||
|
import com.bwie.common.domain.request.FriendRequest;
|
||||||
|
import com.bwie.common.domain.request.ShowRequest;
|
||||||
|
import com.bwie.common.domain.response.Users;
|
||||||
|
import com.bwie.common.redis.RedisCache;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.friend.mapper.FriendMapper;
|
||||||
|
import com.bwie.friend.service.FriendService;
|
||||||
|
import com.bwie.friend.util.MsgUtil;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Log4j2
|
||||||
|
public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> implements FriendService {
|
||||||
|
private final FriendMapper friendMapper;
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
private final RemoteUserService remoteUserService;
|
||||||
|
private final MsgUtil msgUtil;
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
|
||||||
|
|
||||||
|
public FriendServiceImpl(FriendMapper friendMapper, HttpServletRequest request, RemoteUserService remoteUserService, MsgUtil msgUtil, RedisCache redisCache) {
|
||||||
|
this.friendMapper = friendMapper;
|
||||||
|
this.request = request;
|
||||||
|
this.remoteUserService = remoteUserService;
|
||||||
|
this.msgUtil = msgUtil;
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result show(FriendRequest friendRequest) {
|
||||||
|
Long userId = getInfo().getUserId();
|
||||||
|
friendRequest.setUserId(userId);;
|
||||||
|
List<User> show = friendMapper.show(friendRequest);
|
||||||
|
return Result.success(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result showfriend() {
|
||||||
|
Long userId = getInfo().getUserId();
|
||||||
|
List<Users> showfriend = friendMapper.showfriend(userId);
|
||||||
|
return Result.success(showfriend);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result delfriend(DelRequest delRequest) {
|
||||||
|
|
||||||
|
friendMapper.delfriend(delRequest.getUserFr(),getInfo().getUserId());
|
||||||
|
log.info("您好!您的好友[{}],在[{}]把您删除",getInfo().getUserName(),new Date().toLocaleString());
|
||||||
|
msgUtil.sendMsg(delRequest.getUserTel(),"1234");
|
||||||
|
return Result.success("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result showall(ShowRequest showRequest) {
|
||||||
|
showRequest.setUserId(getInfo().getUserId());
|
||||||
|
List<User> showall = friendMapper.showall(showRequest);
|
||||||
|
return Result.success(showall);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result addfriend() {
|
||||||
|
redisCache.deleteObject("用户:"+getInfo().getUserId());
|
||||||
|
|
||||||
|
Result<List<User>> findfriends = remoteUserService.findfriends(getInfo().getUserId());
|
||||||
|
|
||||||
|
for (User user : findfriends.getData()) {
|
||||||
|
redisCache.setCacheObject("用户:"+user.getUserId(),user);
|
||||||
|
}
|
||||||
|
return Result.success("添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getInfo() {
|
||||||
|
User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + request.getHeader(JwtConstants.USER_KEY));
|
||||||
|
return cacheObject;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,319 @@
|
||||||
|
package com.bwie.friend.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HttpUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static <T> List<T> doGet(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys
|
||||||
|
,Class<T> clazz)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||||
|
if(headers!=null){
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
HttpResponse execute = httpClient.execute(request);
|
||||||
|
String s = EntityUtils.toString(execute.getEntity(),"UTF-8");
|
||||||
|
List<T> ts = JSON.parseArray(s, clazz);
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post form
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param bodys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
Map<String, String> bodys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bodys != null) {
|
||||||
|
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||||
|
|
||||||
|
for (String key : bodys.keySet()) {
|
||||||
|
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||||
|
}
|
||||||
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||||
|
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
|
request.setEntity(formEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post String
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post stream
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put String
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put stream
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doDelete(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||||
|
StringBuilder sbUrl = new StringBuilder();
|
||||||
|
sbUrl.append(host);
|
||||||
|
if (!StringUtils.isBlank(path)) {
|
||||||
|
sbUrl.append(path);
|
||||||
|
}
|
||||||
|
if (null != querys) {
|
||||||
|
StringBuilder sbQuery = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbQuery.append("&");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append(query.getValue());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isBlank(query.getKey())) {
|
||||||
|
sbQuery.append(query.getKey());
|
||||||
|
if (!StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append("=");
|
||||||
|
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbUrl.append("?").append(sbQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sbUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient wrapClient(String host) {
|
||||||
|
HttpClient httpClient = new DefaultHttpClient();
|
||||||
|
if (host.startsWith("https://")) {
|
||||||
|
sslClient(httpClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sslClient(HttpClient httpClient) {
|
||||||
|
try {
|
||||||
|
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||||
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.init(null, new TrustManager[] { tm }, null);
|
||||||
|
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||||
|
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||||
|
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||||
|
registry.register(new Scheme("https", 443, ssf));
|
||||||
|
} catch (KeyManagementException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.bwie.friend.util;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @version 1.0.0
|
||||||
|
* @ClassName MsgUtil.java
|
||||||
|
* @Description TODO
|
||||||
|
* @createTime 2022年05月26日 15:49:00
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MsgUtil {
|
||||||
|
|
||||||
|
|
||||||
|
// //列表添加
|
||||||
|
// //@CacheConfig(cacheNames = "aaa")
|
||||||
|
// //列表
|
||||||
|
// //@Cacheable
|
||||||
|
// //实时更新
|
||||||
|
// //@CacheEvict(allEntries = true)
|
||||||
|
//
|
||||||
|
// @Cacheable(key = "#phone",value = "bbb")
|
||||||
|
// public String getCacheCode(String phone){
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @CachePut(key = "#codeEntity.phone",value = "bbb")
|
||||||
|
// public String saveCacheCode(CodeEntity codeEntity){
|
||||||
|
//
|
||||||
|
// return codeEntity.getCode();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 858f87d76b7f4e618a5f7e1557f1d529
|
||||||
|
|
||||||
|
public void sendMsg(String phone,String code){
|
||||||
|
String host = "https://gyytz.market.alicloudapi.com";
|
||||||
|
String path = "/sms/smsSend";
|
||||||
|
String method = "POST";
|
||||||
|
String appcode = "13a8b5b781bc4c458ce2de65ed79be80";
|
||||||
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
|
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||||
|
headers.put("Authorization", "APPCODE " + appcode);
|
||||||
|
Map<String, String> querys = new HashMap<String, String>();
|
||||||
|
querys.put("mobile", phone);
|
||||||
|
querys.put("param", "**code**:"+code+",**minute**:5");
|
||||||
|
|
||||||
|
//smsSignId(短信前缀)和templateId(短信模板),可登录国阳云控制台自助申请。参考文档:http://help.guoyangyun.com/Problem/Qm.html
|
||||||
|
|
||||||
|
querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
|
||||||
|
querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
|
||||||
|
Map<String, String> bodys = new HashMap<String, String>();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* 重要提示如下:
|
||||||
|
* HttpUtils请从\r\n\t \t* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java\r\n\t \t* 下载
|
||||||
|
*
|
||||||
|
* 相应的依赖请参照
|
||||||
|
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||||
|
*/
|
||||||
|
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||||
|
System.out.println(response.toString());
|
||||||
|
//获取response的body
|
||||||
|
System.out.println(EntityUtils.toString(response.getEntity()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9003
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-friend
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bwie.friend.mapper.FriendMapper">
|
||||||
|
|
||||||
|
<delete id="delfriend">
|
||||||
|
delete
|
||||||
|
from friend
|
||||||
|
where user_id=#{userId} and user_fr=#{userFr}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="show" resultType="com.bwie.common.domain.User">
|
||||||
|
SELECT u.* from
|
||||||
|
(SELECT user_fr from user u left join friend f on f.user_id=u.user_id
|
||||||
|
WHERE u.user_id=#{userId}) a
|
||||||
|
left join user u on u.user_id=a.user_fr
|
||||||
|
|
||||||
|
|
||||||
|
<where>
|
||||||
|
<if test="null!=userName and ''!=userName">
|
||||||
|
and u.user_name like concat('%',#{userName},'%')
|
||||||
|
</if>
|
||||||
|
<if test="null!=userSex and ''!=userSex">
|
||||||
|
and u.user_sex=#{userSex}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
<select id="showall" resultType="com.bwie.common.domain.User">
|
||||||
|
SELECT u.*
|
||||||
|
FROM
|
||||||
|
user u
|
||||||
|
WHERE u.user_id NOT IN (SELECT user_fr
|
||||||
|
FROM friend f
|
||||||
|
LEFT JOIN user u ON f.user_id = u.user_id
|
||||||
|
WHERE u.user_id = #{userId}) and u.user_id <> #{userId}
|
||||||
|
<where>
|
||||||
|
<if test="null!=userName and ''!=userName">
|
||||||
|
and u.user_name like concat('%',#{userName},'%')
|
||||||
|
</if>
|
||||||
|
<if test="null!=userSex and ''!=userSex">
|
||||||
|
and u.user_sex=#{userSex}
|
||||||
|
</if>
|
||||||
|
<if test="null!=addrName and ''!=addrName">
|
||||||
|
and addr_name like concat('%',#{addrName},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by u.user_time
|
||||||
|
<if test="1==sort">
|
||||||
|
desc
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="showfriend" resultType="com.bwie.common.domain.response.Users">
|
||||||
|
SELECT u.user_name,u.user_id from (SELECT user_fr from user u left join friend f on f.user_id=u.user_id
|
||||||
|
WHERE u.user_id=#{userId}) a left join user u on u.user_id=a.user_fr
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-log</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.bwie</groupId>
|
||||||
|
<artifactId>bwie-common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
|
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- <!– Pagehelper –>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.github.pagehelper</groupId>-->
|
||||||
|
<!-- <artifactId>pagehelper-spring-boot-starter</artifactId>-->
|
||||||
|
<!-- <version>1.4.1</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bwie.log;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableFeignClients(basePackages = "com.bwie.**")
|
||||||
|
@MapperScan("com.bwie.log.mapper")
|
||||||
|
@EnableScheduling
|
||||||
|
public class LogApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(LogApp.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.bwie.log.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
|
import org.elasticsearch.client.RestClient;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "es")
|
||||||
|
@Data
|
||||||
|
public class InitEsRes {
|
||||||
|
private String host;
|
||||||
|
private int port;
|
||||||
|
private String scheme;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestHighLevelClient restHighLevelClient(){
|
||||||
|
return new RestHighLevelClient(
|
||||||
|
RestClient.builder(new HttpHost(host,port,scheme))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.bwie.log.controller;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.log.mapper.LogMapper;
|
||||||
|
import com.bwie.log.service.LogService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@ResponseBody
|
||||||
|
public class LogController {
|
||||||
|
private final LogService logService;
|
||||||
|
|
||||||
|
|
||||||
|
public LogController(LogService logService) {
|
||||||
|
this.logService = logService;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("addlog")
|
||||||
|
Result addlog(@RequestBody Log build){
|
||||||
|
logService.save(build);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("showlog")
|
||||||
|
public Result showlog(Long redId){
|
||||||
|
return Result.success(logService.showlog(redId));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.bwie.log.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
|
||||||
|
public interface LogMapper extends BaseMapper<Log> {
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.bwie.log.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface LogService extends IService<Log> {
|
||||||
|
void addbach(List<Log> logs);
|
||||||
|
|
||||||
|
List<Log> showlog(Long redId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package com.bwie.log.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
import com.bwie.log.mapper.LogMapper;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.client.RequestOptions;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
|
import org.elasticsearch.common.unit.Fuzziness;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.search.SearchHit;
|
||||||
|
import org.elasticsearch.search.SearchHits;
|
||||||
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||||
|
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||||
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LogServiceImpl extends ServiceImpl<LogMapper,Log> implements LogService {
|
||||||
|
|
||||||
|
private final RestHighLevelClient client;
|
||||||
|
|
||||||
|
public LogServiceImpl(RestHighLevelClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addbach(List<Log> logs) {
|
||||||
|
BulkRequest bulkRequest = new BulkRequest();
|
||||||
|
|
||||||
|
if(logs.size()>0){
|
||||||
|
for (Log log : logs) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
String s = objectMapper.writeValueAsString(log);
|
||||||
|
bulkRequest.add(new IndexRequest("log").id(log.getLogId().toString())
|
||||||
|
.source(s, XContentType.JSON));
|
||||||
|
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
client.bulk(bulkRequest, RequestOptions.DEFAULT);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Log> showlog(Long redId) {
|
||||||
|
SearchRequest searchRequest = new SearchRequest("log");
|
||||||
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
|
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
||||||
|
|
||||||
|
if(null!=redId&&!redId.equals("")){
|
||||||
|
boolQueryBuilder.must(QueryBuilders.termQuery("redId",redId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
searchSourceBuilder.query(boolQueryBuilder);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
searchRequest.source(searchSourceBuilder);
|
||||||
|
ArrayList<Log> logs = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
SearchResponse search = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||||
|
|
||||||
|
SearchHits hits = search.getHits();
|
||||||
|
for (SearchHit hit : hits) {
|
||||||
|
|
||||||
|
|
||||||
|
String sourceAsString = hit.getSourceAsString();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
Log log1 = objectMapper.readValue(sourceAsString, Log.class);
|
||||||
|
|
||||||
|
logs.add(log1);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.bwie.log.task;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
import com.bwie.log.mapper.LogMapper;
|
||||||
|
import com.bwie.log.service.LogService;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MyTask {
|
||||||
|
|
||||||
|
private final LogService logService;
|
||||||
|
private final LogMapper logMapper;
|
||||||
|
|
||||||
|
public MyTask(LogService logService, LogMapper logMapper) {
|
||||||
|
this.logService = logService;
|
||||||
|
this.logMapper = logMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0/10 * * * * *")
|
||||||
|
public void addb(){
|
||||||
|
LambdaQueryWrapper<Log> logLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
List<Log> logs = logMapper.selectList(logLambdaQueryWrapper);
|
||||||
|
logService.addbach(logs);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9004
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-es
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bwie.log.mapper.LogMapper">
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-red</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.bwie</groupId>
|
||||||
|
<artifactId>bwie-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Pagehelper -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>1.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--短信依赖 5条依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpcore</artifactId>
|
||||||
|
<version>4.4.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-util</artifactId>
|
||||||
|
<version>9.3.7.v20160115</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.bwie.red;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
@EnableFeignClients(basePackages = "com.bwie.**")
|
||||||
|
@EnableScheduling
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
public class RedApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RedApp.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.bwie.red.controller;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.request.RedRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.domain.request.SnatchingQuest;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.red.service.RedService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@ResponseBody()
|
||||||
|
public class RedController {
|
||||||
|
|
||||||
|
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
private final RedService redService;
|
||||||
|
|
||||||
|
public RedController(HttpServletRequest request, RedService redService) {
|
||||||
|
this.request = request;
|
||||||
|
this.redService = redService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("show")
|
||||||
|
public Result show(@RequestBody RedRequest redRequest){
|
||||||
|
Result result = redService.show(redRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("sendred")
|
||||||
|
public Result sendred(@RequestBody SendredRequest sendredRequest){
|
||||||
|
Result result = redService.sendred(sendredRequest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@PostMapping("snatching")
|
||||||
|
Result snatching(@RequestBody SnatchingQuest snatchingQuest){
|
||||||
|
Result result = redService.snatching(snatchingQuest);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.bwie.red.mapper;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.request.RedRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.domain.request.SnatchingQuest;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RedMapper {
|
||||||
|
List<Red> show(RedRequest redRequest);
|
||||||
|
|
||||||
|
void addred(SendredRequest sendredRequest);
|
||||||
|
|
||||||
|
void updred();
|
||||||
|
|
||||||
|
List<Red> findred();
|
||||||
|
|
||||||
|
void addgrab(@Param("redId") Long redId, @Param("users") List<Integer> users);
|
||||||
|
|
||||||
|
void updgrab(SnatchingQuest snatchingQuest);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.bwie.red.service;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.request.RedRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.domain.request.SnatchingQuest;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
|
||||||
|
public interface RedService {
|
||||||
|
Result show(RedRequest redRequest);
|
||||||
|
Result sendred(SendredRequest sendredRequest);
|
||||||
|
Result snatching(SnatchingQuest snatchingQuest);
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
package com.bwie.red.service.impl;
|
||||||
|
|
||||||
|
import com.bwie.common.constant.JwtConstants;
|
||||||
|
import com.bwie.common.constant.TokenConstants;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import com.bwie.common.domain.Log;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RedRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.domain.request.SnatchingQuest;
|
||||||
|
import com.bwie.common.redis.RedisCache;
|
||||||
|
import com.bwie.common.remote.log.RemoteLogService;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
|
||||||
|
import com.bwie.red.mapper.RedMapper;
|
||||||
|
import com.bwie.red.service.RedService;
|
||||||
|
import com.bwie.red.util.MsgUtil;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RedServiceImpl implements RedService {
|
||||||
|
private final RedMapper redMapper;
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
private final RemoteUserService remoteUserService;
|
||||||
|
private final RemoteLogService remoteLogService;
|
||||||
|
private final MsgUtil msgUtil;
|
||||||
|
|
||||||
|
|
||||||
|
public RedServiceImpl(RedMapper redMapper, HttpServletRequest request, RedissonClient redissonClient, RedisCache redisCache, RemoteUserService remoteUserService, RemoteLogService remoteLogService, MsgUtil msgUtil) {
|
||||||
|
this.redMapper = redMapper;
|
||||||
|
this.request = request;
|
||||||
|
this.redissonClient = redissonClient;
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
this.remoteUserService = remoteUserService;
|
||||||
|
this.remoteLogService = remoteLogService;
|
||||||
|
this.msgUtil = msgUtil;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result show(RedRequest redRequest) {
|
||||||
|
Long userId = getInfo().getUserId();
|
||||||
|
redRequest.setUserId(userId);
|
||||||
|
List<Red> show = redMapper.show(redRequest);
|
||||||
|
return Result.success(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result sendred(SendredRequest sendredRequest) {
|
||||||
|
sendredRequest.setUserId(getInfo().getUserId());
|
||||||
|
if(sendredRequest.getRedMoney()>300||sendredRequest.getRedMoney()>getInfo().getUserYu()){
|
||||||
|
return Result.error("红包金额不可以大于300元,红包金额小于用户金额");
|
||||||
|
}
|
||||||
|
if(sendredRequest.getRedSum()>sendredRequest.getUsers().size()&&sendredRequest.getRedSum()<=0){
|
||||||
|
return Result.error("红包个数错误");
|
||||||
|
}
|
||||||
|
if(sendredRequest.getRedMoney()/ sendredRequest.getRedSum()<=0.01){
|
||||||
|
return Result.error("红包个数错误");
|
||||||
|
}
|
||||||
|
redMapper.addred(sendredRequest);
|
||||||
|
remoteUserService.updmoney(sendredRequest);
|
||||||
|
redMapper.addgrab(sendredRequest.getRedId(),sendredRequest.getUsers());
|
||||||
|
return Result.success("发送成功");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result snatching(SnatchingQuest snatchingQuest) {
|
||||||
|
RLock one = redissonClient.getLock("one");
|
||||||
|
try {
|
||||||
|
one.tryLock(2, TimeUnit.MINUTES);
|
||||||
|
if(snatchingQuest.getRedYu()/snatchingQuest.getRedNum()==0.01){
|
||||||
|
snatchingQuest.setIncreMoney(0.01);
|
||||||
|
}
|
||||||
|
if (snatchingQuest.getRedYu()/snatchingQuest.getRedNum()>0.01) {
|
||||||
|
snatchingQuest.setIncreMoney((snatchingQuest.getRedYu()/snatchingQuest.getRedNum())-0.01*(snatchingQuest.getRedNum()-1));
|
||||||
|
}
|
||||||
|
// snatchingQuest.setUserId(getInfo().getUserId());
|
||||||
|
//修改红包余额 红包个数 是否抢到
|
||||||
|
redMapper.updgrab(snatchingQuest);
|
||||||
|
//修改余额 user表
|
||||||
|
remoteUserService.addmoney(getInfo().getUserId(),snatchingQuest.getIncreMoney());
|
||||||
|
//发送短信
|
||||||
|
msgUtil.sendMsg(getInfo().getUserTel(),"1111");
|
||||||
|
//添加日志记录表
|
||||||
|
Log build = Log.builder().redId(snatchingQuest.getRedId())
|
||||||
|
.userName(getInfo().getUserName())
|
||||||
|
.redTheme(snatchingQuest.getRedTheme())
|
||||||
|
.logTime(new Date())
|
||||||
|
.build();
|
||||||
|
remoteLogService.addlog(build);
|
||||||
|
|
||||||
|
if(one.isHeldByCurrentThread()){
|
||||||
|
if(one.isLocked()){
|
||||||
|
one.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.success("抢红包成功");
|
||||||
|
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
if(one.isHeldByCurrentThread()){
|
||||||
|
if(one.isLocked()){
|
||||||
|
one.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.error("系统繁忙");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getInfo() {
|
||||||
|
User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + request.getHeader(JwtConstants.USER_KEY));
|
||||||
|
return cacheObject;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.bwie.red.task;
|
||||||
|
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.remote.system.RemoteUserService;
|
||||||
|
|
||||||
|
import com.bwie.red.mapper.RedMapper;
|
||||||
|
import com.bwie.red.util.MsgUtil;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class MyTask {
|
||||||
|
|
||||||
|
private final RemoteUserService remoteUserService;
|
||||||
|
private final RedMapper redMapper;
|
||||||
|
|
||||||
|
private final MsgUtil msgUtil;
|
||||||
|
|
||||||
|
public MyTask(RemoteUserService remoteUserService, RedMapper redMapper, MsgUtil msgUtil) {
|
||||||
|
this.remoteUserService = remoteUserService;
|
||||||
|
this.redMapper = redMapper;
|
||||||
|
this.msgUtil = msgUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0/30 * * * * *")
|
||||||
|
public void findred(){
|
||||||
|
//发送短信提示
|
||||||
|
List<Red> findred = redMapper.findred();
|
||||||
|
for (Red red : findred) {
|
||||||
|
log.info("您在{}时间发送的红包{},总金额{},还剩余{}现已全部退回",red.getRedTime(),red.getRedTheme(),red.getRedMoney(),red.getRedYu());
|
||||||
|
msgUtil.sendMsg(red.getUserTel(),"456");
|
||||||
|
}
|
||||||
|
if(!findred.isEmpty()){
|
||||||
|
//金额退回
|
||||||
|
remoteUserService.backmoney(findred);
|
||||||
|
//修改红包状态
|
||||||
|
redMapper.updred();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,319 @@
|
||||||
|
package com.bwie.red.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HttpUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static <T> List<T> doGet(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys
|
||||||
|
,Class<T> clazz)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||||
|
if(headers!=null){
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
HttpResponse execute = httpClient.execute(request);
|
||||||
|
String s = EntityUtils.toString(execute.getEntity(),"UTF-8");
|
||||||
|
List<T> ts = JSON.parseArray(s, clazz);
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post form
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param bodys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
Map<String, String> bodys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bodys != null) {
|
||||||
|
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||||
|
|
||||||
|
for (String key : bodys.keySet()) {
|
||||||
|
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||||
|
}
|
||||||
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||||
|
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
|
request.setEntity(formEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post String
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post stream
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put String
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put stream
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doDelete(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||||
|
StringBuilder sbUrl = new StringBuilder();
|
||||||
|
sbUrl.append(host);
|
||||||
|
if (!StringUtils.isBlank(path)) {
|
||||||
|
sbUrl.append(path);
|
||||||
|
}
|
||||||
|
if (null != querys) {
|
||||||
|
StringBuilder sbQuery = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbQuery.append("&");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append(query.getValue());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isBlank(query.getKey())) {
|
||||||
|
sbQuery.append(query.getKey());
|
||||||
|
if (!StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append("=");
|
||||||
|
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbUrl.append("?").append(sbQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sbUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient wrapClient(String host) {
|
||||||
|
HttpClient httpClient = new DefaultHttpClient();
|
||||||
|
if (host.startsWith("https://")) {
|
||||||
|
sslClient(httpClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sslClient(HttpClient httpClient) {
|
||||||
|
try {
|
||||||
|
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||||
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.init(null, new TrustManager[] { tm }, null);
|
||||||
|
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||||
|
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||||
|
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||||
|
registry.register(new Scheme("https", 443, ssf));
|
||||||
|
} catch (KeyManagementException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.bwie.red.util;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
* @version 1.0.0
|
||||||
|
* @ClassName MsgUtil.java
|
||||||
|
* @Description TODO
|
||||||
|
* @createTime 2022年05月26日 15:49:00
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MsgUtil {
|
||||||
|
|
||||||
|
|
||||||
|
// //列表添加
|
||||||
|
// //@CacheConfig(cacheNames = "aaa")
|
||||||
|
// //列表
|
||||||
|
// //@Cacheable
|
||||||
|
// //实时更新
|
||||||
|
// //@CacheEvict(allEntries = true)
|
||||||
|
//
|
||||||
|
// @Cacheable(key = "#phone",value = "bbb")
|
||||||
|
// public String getCacheCode(String phone){
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @CachePut(key = "#codeEntity.phone",value = "bbb")
|
||||||
|
// public String saveCacheCode(CodeEntity codeEntity){
|
||||||
|
//
|
||||||
|
// return codeEntity.getCode();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 858f87d76b7f4e618a5f7e1557f1d529
|
||||||
|
|
||||||
|
public void sendMsg(String phone,String code){
|
||||||
|
String host = "https://gyytz.market.alicloudapi.com";
|
||||||
|
String path = "/sms/smsSend";
|
||||||
|
String method = "POST";
|
||||||
|
String appcode = "13a8b5b781bc4c458ce2de65ed79be80";
|
||||||
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
|
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||||
|
headers.put("Authorization", "APPCODE " + appcode);
|
||||||
|
Map<String, String> querys = new HashMap<String, String>();
|
||||||
|
querys.put("mobile", phone);
|
||||||
|
querys.put("param", "**code**:"+code+",**minute**:5");
|
||||||
|
|
||||||
|
//smsSignId(短信前缀)和templateId(短信模板),可登录国阳云控制台自助申请。参考文档:http://help.guoyangyun.com/Problem/Qm.html
|
||||||
|
|
||||||
|
querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
|
||||||
|
querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
|
||||||
|
Map<String, String> bodys = new HashMap<String, String>();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* 重要提示如下:
|
||||||
|
* HttpUtils请从\r\n\t \t* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java\r\n\t \t* 下载
|
||||||
|
*
|
||||||
|
* 相应的依赖请参照
|
||||||
|
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||||
|
*/
|
||||||
|
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||||
|
System.out.println(response.toString());
|
||||||
|
//获取response的body
|
||||||
|
System.out.println(EntityUtils.toString(response.getEntity()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9005
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-red
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bwie.red.mapper.RedMapper">
|
||||||
|
<insert id="addred" keyProperty="redId" useGeneratedKeys="true">
|
||||||
|
insert into red
|
||||||
|
(`red_theme`,`red_money`,`red_time`,`red_sum`,`red_yu`,`red_num`,`red_long`,`red_status`,`red_yn`,`user_id`)
|
||||||
|
values
|
||||||
|
(#{redTheme},#{redMoney},now(),#{redSum},#{redMoney},#{redSum},#{redLong},1,1,#{userId})
|
||||||
|
</insert>
|
||||||
|
<insert id="addgrab">
|
||||||
|
insert into grab (`user_id`,`red_id`)
|
||||||
|
values
|
||||||
|
<foreach collection="users" separator="," item="userId">
|
||||||
|
(#{userId},#{redId})
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
</insert>
|
||||||
|
<update id="updred">
|
||||||
|
update red set red_status=2 where red_status=1 and
|
||||||
|
TIMESTAMPDIFF(MINUTE,red_time,now())>=red_long
|
||||||
|
</update>
|
||||||
|
<update id="updgrab">
|
||||||
|
update red set red_yu=red_yu-#{increMoney} ,red_num=red_num-1 ,red_yn=2 where red_id=#{redId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="show" resultType="com.bwie.common.domain.Red">
|
||||||
|
SELECt r.* from red r
|
||||||
|
left join grab g on g.red_id=r.red_id
|
||||||
|
|
||||||
|
<where>
|
||||||
|
<if test="null!=userId">
|
||||||
|
and g.user_id=#{userId} or r.user_id =#{userId}
|
||||||
|
</if>
|
||||||
|
<if test="null!=start">
|
||||||
|
and red_money >=#{start}
|
||||||
|
</if>
|
||||||
|
<if test="null!=end">
|
||||||
|
and red_money <=#{end}
|
||||||
|
</if>
|
||||||
|
<if test="null!=redTime">
|
||||||
|
and date(red_time)=#{redTime}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
group by r.red_id
|
||||||
|
</select>
|
||||||
|
<select id="findred" resultType="com.bwie.common.domain.Red">
|
||||||
|
select r.*,user_tel
|
||||||
|
from red r left join user u on u.user_id=r.user_id
|
||||||
|
where red_status=1 and
|
||||||
|
TIMESTAMPDIFF(MINUTE,red_time,now())>=red_long
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-system</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.bwie</groupId>
|
||||||
|
<artifactId>bwie-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.bwie.system;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients( basePackages = {"com.bwie.**"})
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@MapperScan("com.bwie.system.mapper")
|
||||||
|
public class SysApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SysApp.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.bwie.system.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.RegRequest;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.common.result.Result;
|
||||||
|
import com.bwie.system.service.SysService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@ResponseBody
|
||||||
|
public class SysController {
|
||||||
|
|
||||||
|
private final SysService sysService;
|
||||||
|
|
||||||
|
public SysController(SysService sysService) {
|
||||||
|
this.sysService = sysService;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("findname")
|
||||||
|
public Result<User> findname(@RequestParam String userName){
|
||||||
|
return Result.success(sysService.findname(userName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("findtel")
|
||||||
|
Result<User> findtel(@RequestParam String userTel){
|
||||||
|
return Result.success(sysService.findtel(userTel));
|
||||||
|
}
|
||||||
|
@PostMapping("adduser")
|
||||||
|
Result<String> adduser(@RequestBody RegRequest build){
|
||||||
|
sysService.save(
|
||||||
|
User.addBuild(build));
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("findfriends")
|
||||||
|
Result<List<User>> findfriends(@RequestParam Long userId){
|
||||||
|
return Result.success(sysService.findfriends(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("updtime")
|
||||||
|
Result updtime(@RequestParam Long userId){
|
||||||
|
sysService.updtime(userId);
|
||||||
|
Result<String> result = Result.success("登录时间修改成功");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("updmoney")
|
||||||
|
public Result updmoney(@RequestBody SendredRequest sendredRequest){
|
||||||
|
sysService.updmoney(sendredRequest);
|
||||||
|
Result<String> result = Result.success("扣除余额成功");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("bsckmoney")
|
||||||
|
Result backmoney(@RequestBody List<Red> findred){
|
||||||
|
sysService.backmoney(findred);
|
||||||
|
Result<String> result = Result.success("退还成功");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("addmoney")
|
||||||
|
Result addmoney(@RequestParam Long userId, Double increMoney){
|
||||||
|
sysService.addmoney(userId,increMoney);
|
||||||
|
Result<String> result = Result.success("红包到账成功");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.bwie.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface SysMapper extends BaseMapper<User> {
|
||||||
|
List<User> findfriends(Long userId);
|
||||||
|
|
||||||
|
void updmoney(SendredRequest sendredRequest);
|
||||||
|
|
||||||
|
void backmoney(Double redYu,Long userId);
|
||||||
|
void updtime(Long userId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bwie.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface SysService extends IService<User> {
|
||||||
|
User findname(String userName);
|
||||||
|
|
||||||
|
User findtel(String userTel);
|
||||||
|
|
||||||
|
List<User> findfriends(Long userId);
|
||||||
|
void updmoney(SendredRequest sendredRequest);
|
||||||
|
|
||||||
|
|
||||||
|
void backmoney(List<Red> findred);
|
||||||
|
void updtime(Long userId);
|
||||||
|
|
||||||
|
void addmoney(Long userId, Double increMoney);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.bwie.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bwie.common.domain.Red;
|
||||||
|
import com.bwie.common.domain.User;
|
||||||
|
import com.bwie.common.domain.request.SendredRequest;
|
||||||
|
import com.bwie.system.mapper.SysMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysServiceImpl extends ServiceImpl<SysMapper,User> implements SysService{
|
||||||
|
|
||||||
|
private final SysMapper sysMapper;
|
||||||
|
|
||||||
|
public SysServiceImpl(SysMapper sysMapper) {
|
||||||
|
this.sysMapper = sysMapper;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User findname(String userName) {
|
||||||
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(User::getUserName,userName);
|
||||||
|
return getOne(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User findtel(String userTel) {
|
||||||
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(User::getUserTel,userTel);
|
||||||
|
return getOne(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> findfriends(Long userId) {
|
||||||
|
return sysMapper.findfriends(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updmoney(SendredRequest sendredRequest) {
|
||||||
|
sysMapper.updmoney(sendredRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void backmoney(List<Red> findred) {
|
||||||
|
for (Red red : findred) {
|
||||||
|
sysMapper.backmoney(red.getRedYu(),red.getUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updtime(Long userId) {
|
||||||
|
sysMapper.updtime(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addmoney(Long userId, Double increMoney) {
|
||||||
|
sysMapper.backmoney(increMoney,userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9002
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: bwie-system
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 124.221.177.197:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bwie.system.mapper.SysMapper">
|
||||||
|
<update id="addmoney">
|
||||||
|
update user set user_yu =user_yu+#{redYu} where user_id=#{userId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="findfriends" resultType="com.bwie.common.domain.User">
|
||||||
|
SELECT u.* from (SELECT user_fr from user u left join friend f on f.user_id=u.user_id
|
||||||
|
WHERE u.user_id=#{userId}) a left join user u on u.user_id=a.user_fr
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updmoney">
|
||||||
|
update user set user_yu =user_yu-#{redMoney} where user_id=#{userId}
|
||||||
|
</update>
|
||||||
|
<update id="backmoney">
|
||||||
|
update user set user_yu =user_yu+#{redYu} where user_id=#{userId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updtime">
|
||||||
|
update user set user_time =now() ,user_status=1 where user_id=#{userId}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?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.bwie</groupId>
|
||||||
|
<artifactId>work111</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-modules</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>
|
||||||
|
|
||||||
|
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue