Merge pull request 'dev-v2' (#3) from dev-v2 into master-v2
Reviewed-on: #3
This commit is contained in:
commit
107e2cb85e
|
@ -0,0 +1,7 @@
|
|||
**/target/
|
||||
.idea
|
||||
*.iml
|
||||
*.class
|
||||
#*Test.java
|
||||
#**/test/
|
||||
logs
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -2,15 +2,54 @@
|
|||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="spzx-model" />
|
||||
<module name="common-util" />
|
||||
<module name="service-product-client" />
|
||||
<module name="common-service" />
|
||||
<module name="service-order-client" />
|
||||
<module name="service-user-client" />
|
||||
<module name="common-log" />
|
||||
<module name="service-order" />
|
||||
<module name="service-pay" />
|
||||
<module name="spzx-model" />
|
||||
<module name="spzx-server-gateway" />
|
||||
<module name="service-product" />
|
||||
<module name="service-user" />
|
||||
<module name="service-cart" />
|
||||
<module name="spzx-manager" />
|
||||
<module name="service-cart-client" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="common-web" target="17" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="common-log" options="-parameters" />
|
||||
<module name="common-service" options="-parameters" />
|
||||
<module name="common-util" options="-parameters" />
|
||||
<module name="common-web" options="-parameters" />
|
||||
<module name="service-cart" options="-parameters" />
|
||||
<module name="service-cart-client" options="-parameters" />
|
||||
<module name="service-order" options="-parameters" />
|
||||
<module name="service-order-client" options="-parameters" />
|
||||
<module name="service-pay" options="-parameters" />
|
||||
<module name="service-product" options="-parameters" />
|
||||
<module name="service-product-client" options="-parameters" />
|
||||
<module name="service-user" options="-parameters" />
|
||||
<module name="service-user-client" options="-parameters" />
|
||||
<module name="spzx-common" options="" />
|
||||
<module name="spzx-manager" options="-parameters" />
|
||||
<module name="spzx-model" options="-parameters" />
|
||||
<module name="spzx-parent-v2" options="" />
|
||||
<module name="spzx-server-gateway" options="-parameters" />
|
||||
<module name="spzx-service" options="" />
|
||||
<module name="spzx-service-client" options="" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="db_spzx@106.15.251.123" uuid="83fbf708-5dbd-4ac9-80b8-e3b47596811f">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<imported>true</imported>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://106.15.251.123:3305/db_spzx?serverTimezone=GMT</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="2@47.120.65.66" uuid="7948c4f2-c26d-4886-b6da-d40f6a617678">
|
||||
<driver-ref>redis</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<imported>true</imported>
|
||||
<jdbc-driver>jdbc.RedisDriver</jdbc-driver>
|
||||
<jdbc-url>jdbc:redis://47.120.65.66:6379/2</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
|
@ -1,41 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-log/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-service/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-service/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-service/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-util/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-util/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-util/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/common-web/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-common/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-manager/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-manager/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-manager/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-model/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-model/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-model/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/common-service/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/common-service/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/common-service/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/common-util/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/common-util/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/common-util/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-common/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-manager/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-manager/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-manager/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-model/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-model/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/spzx-model/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-parent/src/main/resources-filtered" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-server-gateway/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/service-cart-client/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/service-order-client/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/service-product-client/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/service-user-client/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service-client/untitled/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/service-cart/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/service-order/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/service-pay/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/service-product/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/service-user/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/spzx-service/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources-filtered" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -4,12 +4,15 @@
|
|||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/spzx-parent/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="ignoredFiles">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$/spzx-common/common-web/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/spzx-service-client/untitled/pom.xml" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
119
pom.xml
119
pom.xml
|
@ -1,25 +1,106 @@
|
|||
<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>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<!-- 指定父工程 -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>spzx-parent</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>spzx-common</module>
|
||||
<module>spzx-model</module>
|
||||
<module>spzx-manager</module>
|
||||
</modules>
|
||||
<name>spzx-parent</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>spzx-common</module>
|
||||
<module>spzx-model</module>
|
||||
<module>spzx-manager</module>
|
||||
<module>spzx-common/common-log</module>
|
||||
<module>spzx-service</module>
|
||||
<module>spzx-service/service-product</module>
|
||||
<module>spzx-server-gateway</module>
|
||||
<module>spzx-service-client</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mysql.verison>8.0.30</mysql.verison>
|
||||
<fastjson.version>2.0.47</fastjson.version>
|
||||
<lombok.version>1.18.20</lombok.version>
|
||||
<mybatis.version>3.0.1</mybatis.version>
|
||||
<pagehelper.version>2.1.0</pagehelper.version>
|
||||
<cloud.version>2022.0.2</cloud.version>
|
||||
<alibaba.version>2022.0.0.0-RC2</alibaba.version>
|
||||
<alipay.version>4.8.73.ALL</alipay.version>
|
||||
<minio.version>8.5.9</minio.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 管理依赖,版本锁定 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- mybatis和spring boot整合的起步依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis.version}</version>
|
||||
</dependency>
|
||||
<!-- mysql驱动 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<!--fastjson-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<!-- lombok依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
<!-- 分页插件 -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>${pagehelper.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!--导入支付宝支付sdk-->
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
<version>${alipay.version}</version>
|
||||
</dependency>
|
||||
<!-- minio -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>${minio.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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.atguigu</groupId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>common-log</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>common-log</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-util</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,18 @@
|
|||
package com.atguigu.log.annotation;
|
||||
|
||||
import com.atguigu.log.aspect.LogAspect;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
// 开启动类中开启包扫描也可以,
|
||||
// 如果不想这样写可以按照下面定义一个切面类,
|
||||
// 之后在SpringBoot中加入这个注解,让其扫描到
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Import(value = LogAspect.class)
|
||||
public @interface EnableLogAspect {
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.atguigu.log.annotation;
|
||||
|
||||
import com.atguigu.log.enums.OperatorType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log { // 自定义操作日志记录注解
|
||||
String title(); // 模块名称
|
||||
|
||||
OperatorType operatorType() default OperatorType.MANAGE; // 操作人类别
|
||||
|
||||
int businessType(); // 业务类型(0其它 1新增 2修改 3删除)
|
||||
|
||||
boolean isSaveRequestData() default true; // 是否保存请求的参数
|
||||
|
||||
boolean isSaveResponseData() default true; // 是否保存响应的参数
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.atguigu.log.aspect;
|
||||
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.log.service.AsyncOperaLogService;
|
||||
import com.atguigu.log.utils.LogUtil;
|
||||
import com.atguigu.spzx.model.entity.system.SysOperLog;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LogAspect {
|
||||
@Autowired
|
||||
private AsyncOperaLogService asyncOperaLogService;
|
||||
|
||||
@Around(value = "@annotation(sysLog)")
|
||||
public Object doAroundAdvice(ProceedingJoinPoint joinPoint, Log sysLog) {
|
||||
String title = sysLog.title();
|
||||
log.info("请求了===>:{}", title);
|
||||
|
||||
// 构建前置参数
|
||||
SysOperLog sysOperLog = new SysOperLog();
|
||||
LogUtil.beforeHandleLog(sysLog, joinPoint, sysOperLog);
|
||||
Object proceed = null;
|
||||
|
||||
try {
|
||||
proceed = joinPoint.proceed();
|
||||
// 执行业务方法
|
||||
LogUtil.afterHandleLog(sysLog, proceed, sysOperLog, 0, null);
|
||||
// 构建响应结果参数
|
||||
} catch (Throwable e) { // 代码执行进入到catch中,
|
||||
// 业务方法执行产生异常
|
||||
LogUtil.afterHandleLog(sysLog, proceed, sysOperLog, 1, e.getMessage());
|
||||
throw new BunnyException(e.getMessage());
|
||||
}
|
||||
|
||||
// 保存日志数据
|
||||
asyncOperaLogService.saveSysOperaLog(sysOperLog);
|
||||
|
||||
// 返回执行结果
|
||||
return proceed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.atguigu.log.enums;
|
||||
|
||||
// 操作人类别
|
||||
public enum OperatorType {
|
||||
OTHER,// 其他
|
||||
MANAGE,// 后台用户
|
||||
MOBILE// 手机端用户
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.atguigu.log.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysOperLog;
|
||||
|
||||
// 保存日志数据
|
||||
public interface AsyncOperaLogService {
|
||||
void saveSysOperaLog(SysOperLog sysOperLog);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.atguigu.log.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.model.entity.system.SysOperLog;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LogUtil {
|
||||
|
||||
// 操作执行之后调用
|
||||
public static void afterHandleLog(Log sysLog, Object proceed, SysOperLog sysOperLog, int status, String errorMsg) {
|
||||
if (sysLog.isSaveResponseData()) {
|
||||
sysOperLog.setJsonResult(JSON.toJSONString(proceed));
|
||||
}
|
||||
sysOperLog.setStatus(status);
|
||||
sysOperLog.setErrorMsg(errorMsg);
|
||||
}
|
||||
|
||||
// 操作执行之前调用
|
||||
public static void beforeHandleLog(Log sysLog, ProceedingJoinPoint joinPoint, SysOperLog sysOperLog) {
|
||||
|
||||
// 设置操作模块名称
|
||||
sysOperLog.setTitle(sysLog.title());
|
||||
sysOperLog.setOperatorType(sysLog.operatorType().name());
|
||||
|
||||
// 获取目标方法信息
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = methodSignature.getMethod();
|
||||
sysOperLog.setMethod(method.getDeclaringClass().getName());
|
||||
// 获取请求相关参数
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = requestAttributes.getRequest();
|
||||
sysOperLog.setRequestMethod(request.getMethod());
|
||||
sysOperLog.setOperUrl(request.getRequestURI());
|
||||
sysOperLog.setOperIp(request.getRemoteAddr());
|
||||
// 设置请求参数
|
||||
if (sysLog.isSaveRequestData()) {
|
||||
String requestMethod = sysOperLog.getRequestMethod();
|
||||
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
||||
String params = Arrays.toString(joinPoint.getArgs());
|
||||
sysOperLog.setOperParam(params);
|
||||
}
|
||||
}
|
||||
sysOperLog.setOperName(BaseContext.getSysUser().getName());
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
@ -11,13 +11,66 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<name>common-service</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 自己的模块 -->
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-util</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- spring boot web开发所需要的起步依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!--支持配置属性类,yml文件中可以提示配置项-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.2.1</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>12.0.5</version>
|
||||
</dependency>
|
||||
<!-- openfeign依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>15</source>
|
||||
<target>15</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.atguigu;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.atguigu.anno;
|
||||
|
||||
import com.atguigu.interceptor.feign.UserTokenFeignInterceptor;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
// com.atguigu.spzx.common.anno;
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = ElementType.TYPE)
|
||||
@Import(value = UserTokenFeignInterceptor.class)
|
||||
public @interface EnableUserTokenFeignInterceptor {
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.atguigu.config;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class Knife4jConfig {
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
log.info("尚品甑选API接口文档");
|
||||
|
||||
// 设定作者
|
||||
return new OpenAPI().info(new Info().title("尚品甑选API接口文档")
|
||||
.version("1.0").description("尚品甑选API接口文档").contact(new Contact().name("bunny")));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi adminApi() {
|
||||
log.info("admin请求接口");
|
||||
|
||||
return GroupedOpenApi.builder().group("admin请求接口").pathsToMatch("/admin/**").build();// 接口请求路径规则
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi productApi() {
|
||||
log.info("商品管理接口");
|
||||
|
||||
return GroupedOpenApi.builder().group("商品管理接口").pathsToMatch("/api/product/**").build(); // 接口请求路径规则
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi userApi() {
|
||||
log.info("用户接口");
|
||||
|
||||
return GroupedOpenApi.builder().group("用户接口").pathsToMatch("/api/user/**").build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.atguigu.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
/**
|
||||
* 使用StringRedisSerializer序列化为字符串
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory connectionFactory) {
|
||||
log.info("RedisConfiguration===>使用StringRedisSerializer序列化为字符串");
|
||||
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(connectionFactory);
|
||||
// 设置key序列化为string
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// 设置value序列化为JSON,使用GenericJackson2JsonRedisSerializer替换默认序列化
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题
|
||||
*/
|
||||
@Bean
|
||||
@SuppressWarnings("all")
|
||||
public CacheManager cacheManager(RedisConnectionFactory factory) {
|
||||
log.info("RedisConfiguration===>解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题");
|
||||
|
||||
StringRedisSerializer redisSerializer = new StringRedisSerializer();
|
||||
// 配置序列化
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
|
||||
RedisCacheConfiguration redisCacheConfiguration = config
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jsonRedisSerializer()));
|
||||
|
||||
RedisCacheManager cacheManager = RedisCacheManager.builder(factory)
|
||||
.cacheDefaults(redisCacheConfiguration).build();
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定的日期模式
|
||||
*/
|
||||
public Jackson2JsonRedisSerializer<Object> jsonRedisSerializer() {
|
||||
log.info("RedisConfiguration===>指定的日期模式");
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// 设置ObjectMapper访问权限
|
||||
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
// 记录序列化之后的数据类型,方便反序列化
|
||||
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
// 关闭默认的日期格式化方式,默认UTC日期格式 yyyy-MM-dd’T’HH:mm:ss.SSS
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
// LocalDatetime序列化,默认不兼容jdk8日期序列化
|
||||
JavaTimeModule timeModule = new JavaTimeModule();
|
||||
timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
mapper.registerModule(timeModule);
|
||||
return new Jackson2JsonRedisSerializer<>(mapper, Object.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class ResourceConfiguration extends WebMvcConfiguration {
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
log.info("设置静态资源映射");
|
||||
|
||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.atguigu.config;
|
||||
|
||||
import com.atguigu.interceptor.LoginAuthInterceptor;
|
||||
import com.atguigu.interceptor.UserLoginAuthInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Slf4j
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
@Autowired
|
||||
private LoginAuthInterceptor loginAuthInterceptor;
|
||||
@Autowired
|
||||
private UserLoginAuthInterceptor userLoginAuthInterceptor;
|
||||
|
||||
/**
|
||||
* * 解决跨域
|
||||
*
|
||||
* @param registry 跨域注册表
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
log.info("WebMvcConfiguration===>开始跨域注册表...");
|
||||
|
||||
registry.addMapping("/admin/**")// 添加路径规则
|
||||
.allowCredentials(true)// 是否允许在跨域的情况下传递Cookie
|
||||
.allowedOriginPatterns("*")// 允许请求来源的域规则
|
||||
.allowedMethods("*").allowedHeaders("*");// 允许所有的请求头
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义拦截器
|
||||
*
|
||||
* @param registry InterceptorRegistry
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
||||
|
||||
// 拦截后台管理内容
|
||||
String[] loginAuthInterceptors = {"/admin/system/index/login", "/admin/system/index/generateValidateCode", "/admin/product/category/exportData"};
|
||||
registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**")
|
||||
.excludePathPatterns(loginAuthInterceptors);
|
||||
|
||||
// 拦截前台内容
|
||||
registry.addInterceptor(userLoginAuthInterceptor).addPathPatterns("/api/**");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.atguigu.handler;
|
||||
|
||||
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
// 自定义异常信息
|
||||
@ExceptionHandler(BunnyException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(BunnyException exception) {
|
||||
log.error("GlobalExceptionHandler===>自定义异常信息:{}", exception.getMessage());
|
||||
|
||||
Integer code = exception.getCode() != null ? exception.getCode() : 500;
|
||||
return Result.error(null, code, exception.getMessage());
|
||||
}
|
||||
|
||||
// 运行时异常信息
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(RuntimeException exception) {
|
||||
log.error("GlobalExceptionHandler===>运行时异常信息:{}", exception.getMessage());
|
||||
|
||||
return Result.error(null, 500, "出错了啦");
|
||||
}
|
||||
|
||||
// 捕获系统异常
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Result<Object> error(Exception exception) {
|
||||
log.error("GlobalExceptionHandler===>系统异常信息:{}", exception.getMessage());
|
||||
|
||||
return Result.error(null, 500, exception.getMessage());
|
||||
}
|
||||
|
||||
// 特定异常处理
|
||||
@ExceptionHandler(ArithmeticException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> error(ArithmeticException exception) {
|
||||
log.error("GlobalExceptionHandler===>特定异常信息:{}", exception.getMessage());
|
||||
|
||||
return Result.error(null, 500, exception.getMessage());
|
||||
}
|
||||
|
||||
// spring security异常
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
@ResponseBody
|
||||
public Result<String> error(AccessDeniedException exception) throws AccessDeniedException {
|
||||
log.error("GlobalExceptionHandler===>spring security异常:{}", exception.getMessage());
|
||||
|
||||
return Result.error(ResultCodeEnum.PERMISSION);
|
||||
}
|
||||
|
||||
// 处理SQL异常
|
||||
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
|
||||
@ResponseBody
|
||||
public Result<String> exceptionHandler(SQLIntegrityConstraintViolationException exception) {
|
||||
log.error("GlobalExceptionHandler===>处理SQL异常:{}", exception.getMessage());
|
||||
|
||||
String message = exception.getMessage();
|
||||
if (message.contains("Duplicate entry")) {
|
||||
// 截取用户名
|
||||
String username = message.split(" ")[2];
|
||||
// 错误信息
|
||||
String errorMessage = username + MessageConstant.ALREADY_EXISTS;
|
||||
return Result.error(errorMessage);
|
||||
} else {
|
||||
return Result.error(MessageConstant.UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.atguigu.interceptor;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.utils.InterceptorUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class LoginAuthInterceptor implements HandlerInterceptor {
|
||||
@Autowired
|
||||
RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler) throws Exception {
|
||||
log.info("LoginAuthInterceptor===>preHandle拦截请求前");
|
||||
|
||||
String method = request.getMethod();
|
||||
String token = request.getHeader("token");
|
||||
|
||||
// 判断当前拦截到的是Controller方法还是其它资源
|
||||
if ("OPTIONS".equals(method) || !(handler instanceof HandlerMethod)) return true;
|
||||
|
||||
// 当前token为空
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
InterceptorUtil.unLoginInterceptor(response);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取用户信息不存在
|
||||
Object sysUserObject = redisTemplate.opsForValue().get(token);
|
||||
String sysUserString = JSON.toJSONString(sysUserObject);
|
||||
if (sysUserObject == null) {
|
||||
InterceptorUtil.unLoginInterceptor(response);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 将用户信息放到ThreadLocal中
|
||||
SysUser sysUser = JSON.parseObject(sysUserString, SysUser.class);
|
||||
BaseContext.setSysUser(sysUser);
|
||||
BaseContext.setUserId(sysUser.getId());
|
||||
|
||||
// 更新Redis过期时间
|
||||
redisTemplate.expire(token, 7, TimeUnit.DAYS);
|
||||
|
||||
// 放行
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求完成后删除ThreadLocal
|
||||
*/
|
||||
@Override
|
||||
public void afterCompletion(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler, @Nullable Exception ex) throws Exception {
|
||||
BaseContext.removeSysUser();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.atguigu.interceptor;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class UserLoginAuthInterceptor implements HandlerInterceptor {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
|
||||
String token = request.getHeader("token");
|
||||
|
||||
if (!StringUtils.isEmpty(token)) {
|
||||
Object userJSON = redisTemplate.opsForValue().get(token);
|
||||
String userJSONString = JSON.toJSONString(userJSON);
|
||||
BaseContext.setUserInfo(JSON.parseObject(userJSONString, UserInfo.class));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, @Nullable Exception ex) throws Exception {
|
||||
BaseContext.removeUserInfo();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.atguigu.interceptor.feign;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
public class UserTokenFeignInterceptor implements RequestInterceptor {
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
assert requestAttributes != null;
|
||||
HttpServletRequest request = requestAttributes.getRequest();
|
||||
String token = request.getHeader("token");
|
||||
requestTemplate.header("token", token);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.atguigu.utils;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CategoryHelper {
|
||||
/**
|
||||
* 构建树型结构
|
||||
*
|
||||
* @param categoryList 分类列表
|
||||
* @return 结构列表
|
||||
*/
|
||||
public static List<Category> buildTree(List<Category> categoryList) {
|
||||
ArrayList<Category> tree = new ArrayList<>();
|
||||
// 将菜单进行遍历
|
||||
categoryList.forEach(category -> {
|
||||
if (category.getParentId() == 0) {
|
||||
tree.add(getChildren(category, categoryList));
|
||||
}
|
||||
});
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将List<SysMenu>对象转换成List<SysMenuVo>对象
|
||||
*
|
||||
* @param categoryList 全部菜单列表
|
||||
* @return 系统菜单响应结果实体类列表
|
||||
*/
|
||||
public static Category getChildren(Category category, List<Category> categoryList) {
|
||||
// 遍历所有菜单数据,判断id和parentID对应关系
|
||||
category.setChildren(new ArrayList<>());
|
||||
|
||||
categoryList.forEach(menu -> {
|
||||
if (menu.getChildren() == null) menu.setChildren(new ArrayList<>());
|
||||
if (category.getId().equals(menu.getParentId())) {
|
||||
category.getChildren().add(getChildren(menu, categoryList));
|
||||
}
|
||||
});
|
||||
|
||||
return category;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.atguigu.utils;
|
||||
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class EmptyUtil {
|
||||
/**
|
||||
* 判断内容是否为空
|
||||
*
|
||||
* @param val 值
|
||||
* @param errorMessage 如果为空的错误信息
|
||||
*/
|
||||
public void isEmpty(Object val, String errorMessage) {
|
||||
if (val == null || val.toString().isEmpty()) {
|
||||
throw new BunnyException(null, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断内容是否为空
|
||||
*
|
||||
* @param val 值
|
||||
* @param errorMessage 如果为空的错误信息
|
||||
*/
|
||||
public void isNotEmpty(Object val, String errorMessage) {
|
||||
if (val != null) {
|
||||
throw new BunnyException(null, errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,238 @@
|
|||
package com.atguigu.utils;
|
||||
|
||||
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 javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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 {
|
||||
public static HttpResponse doGet(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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(), StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!sbQuery.isEmpty()) {
|
||||
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,41 @@
|
|||
package com.atguigu.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
public class InterceptorUtil {
|
||||
/**
|
||||
* 用户未登录返回响应
|
||||
*
|
||||
* @param response 返回体
|
||||
*/
|
||||
public static void unLoginInterceptor(HttpServletResponse response) throws IOException {
|
||||
log.warn("InterceptorUtil===>用户未登录");
|
||||
customLoginInterceptor(response, MessageConstant.USER_NOT_LOGIN, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户登录失败
|
||||
*
|
||||
* @param response HttpServletResponse
|
||||
* @param message 消息
|
||||
* @param data 内容
|
||||
*/
|
||||
public static void customLoginInterceptor(HttpServletResponse response, String message, String data) throws IOException {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
Result<String> result = new Result<>();
|
||||
result.setCode(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
result.setData(data);
|
||||
result.setMessage(message);
|
||||
// 将消息写入响应体
|
||||
response.getWriter().write(JSON.toJSONString(result));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.atguigu.utils;
|
||||
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MenuHelper {
|
||||
/**
|
||||
* 构建树型结构
|
||||
*
|
||||
* @param sysMenuList 系统菜单列表
|
||||
* @return 菜单结构列表
|
||||
*/
|
||||
public static List<SysMenu> buildTree(List<SysMenu> sysMenuList) {
|
||||
ArrayList<SysMenu> tress = new ArrayList<>();
|
||||
// 把菜单数据进行遍历
|
||||
sysMenuList.forEach(sysMenu -> {
|
||||
if (sysMenu.getParentId() == 0) tress.add(getChildren(sysMenu, sysMenuList));
|
||||
});
|
||||
return tress;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建递归循环
|
||||
*
|
||||
* @param sysMenu 当前菜单对象
|
||||
* @param sysMenuList 全部菜单列表
|
||||
* @return 菜单
|
||||
*/
|
||||
private static SysMenu getChildren(SysMenu sysMenu, List<SysMenu> sysMenuList) {
|
||||
// 遍历所有菜单数据,判断id和parentID对应关系
|
||||
sysMenu.setChildren(new ArrayList<>());
|
||||
|
||||
sysMenuList.forEach(menu -> {
|
||||
if (menu.getChildren() == null) menu.setChildren(new ArrayList<>());
|
||||
if (sysMenu.getId().equals(menu.getParentId())) {
|
||||
sysMenu.getChildren().add(getChildren(menu, sysMenuList));
|
||||
}
|
||||
});
|
||||
|
||||
return sysMenu;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将List<SysMenu>对象转换成List<SysMenuVo>对象
|
||||
*
|
||||
* @param menus 全部菜单列表
|
||||
* @return 系统菜单响应结果实体类列表
|
||||
*/
|
||||
public static List<SysMenuVo> buildMenus(List<SysMenu> menus) {
|
||||
LinkedList<SysMenuVo> sysMenuVos = new LinkedList<>();
|
||||
|
||||
menus.forEach(menu -> {
|
||||
SysMenuVo menuVo = new SysMenuVo();
|
||||
menuVo.setTitle(menu.getTitle());
|
||||
menuVo.setName(menu.getComponent());
|
||||
|
||||
List<SysMenu> children = menu.getChildren();
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
menuVo.setChildren(buildMenus(children));
|
||||
}
|
||||
sysMenuVos.add(menuVo);
|
||||
});
|
||||
return sysMenuVos;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.atguigu.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.constant.RedisUserConstant;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RedisUtils {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
public static String getCartKey(Long userId) {
|
||||
return RedisUserConstant.REDIS_CART_KEY + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis通过token获取用户信息
|
||||
*
|
||||
* @param token 请求key的token
|
||||
* @return 用户信息
|
||||
*/
|
||||
public UserInfo getUserInfo(String token) {
|
||||
// 获取用户信息字符串
|
||||
Object object = redisTemplate.opsForValue().get(token);
|
||||
String jsonString = JSON.toJSONString(object);
|
||||
if (StringUtils.isEmpty(jsonString)) {
|
||||
throw new BunnyException(MessageConstant.USER_DOES_NOT_EXIST);
|
||||
}
|
||||
// 转为UserInfo类
|
||||
return JSON.parseObject(jsonString, UserInfo.class);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
@ -11,13 +11,27 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<name>common-util</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- fastjson依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<!-- minio -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
</dependency>
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.atguigu;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ExceptionConstant {
|
||||
public static final String USER_NOT_FOUND = "用户不存在";
|
||||
public static final String USERNAME_IS_EMPTY = "用户名不能为空";
|
||||
public static final String PASSWORD_ERROR = "密码错误";
|
||||
public static final String PASSWORD_IS_EMPTY = "密码不能为空";
|
||||
public static final String CAPTCHA_IS_EMPTY = "提交验证码不能为空";
|
||||
public static final String KEY_IS_EMPTY = "验证码key不能为空";
|
||||
public static final String VERIFICATION_CODE_DOES_NOT_MATCH = "验证码不匹配";
|
||||
public static final String VERIFICATION_CODE_IS_EMPTY = "验证码失效或不存在";
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
public class LocalDateTimeConstant {
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
public static final String DEFAULT_DATE_TIME_SECOND_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
/**
|
||||
* 信息提示常量类
|
||||
*/
|
||||
public class MessageConstant {
|
||||
public static final String PASSWORD_ERROR = "密码错误";
|
||||
public static final String OLD_PASSWORD_ERROR = "旧密码不匹配";
|
||||
public static final String OLD_PASSWORD_SAME_NEW_PASSWORD = "旧密码与新密码相同";
|
||||
public static final String ACCOUNT_NOT_FOUND = "账号不存在";
|
||||
public static final String ACCOUNT_LOCKED = "账号被锁定";
|
||||
public static final String UNKNOWN_ERROR = "未知错误";
|
||||
public static final String USER_NOT_LOGIN = "用户未登录";
|
||||
public static final String USER_TOKEN_OUT_OF_DATE = "用户登录过期";
|
||||
public static final String LOGIN_FAILED = "登录失败";
|
||||
public static final String UPLOAD_FAILED = "文件上传失败";
|
||||
public static final String PASSWORD_EDIT_FAILED = "密码修改失败";
|
||||
public static final String ALREADY_EXISTS = "已存在";
|
||||
public static final String REQUEST_NOT_EMPTY = "请求不为空";
|
||||
public static final String UPDATE_ID_IS_NOT_EMPTY = "删除id不能为空";
|
||||
public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空";
|
||||
public static final String MENU_IS_NOT_EXIST = "菜单不存在";
|
||||
public static final String SAVE_DTO_IS_NULL = "添加参数不能为空";
|
||||
public static final String UPDATE_DTO_IS_NULL = "修改参数不能为空";
|
||||
public static final String FIND_ID_IS_NOT_EMPTY = "查询ID不能为空";
|
||||
public static final String MESSAGE_CODE_NOT_PASS = "短信验证码未过期";
|
||||
public static final String MESSAGE_CODE_UNAUTHORIZED = "短信验证码未授权,请联系管理员";
|
||||
public static final String VERIFICATION_CODE_ERROR = "验证码错误";
|
||||
public static final String USER_DOES_NOT_EXIST = "用户不存在";
|
||||
public static final String USER_DOES_IS_EXIST = "用户已存在";
|
||||
public static final String VERIFICATION_CODE_IS_EMPTY = "请先发送验证码";
|
||||
public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空";
|
||||
public static final String TOKEN_IS_EMPTY = "token为空";
|
||||
public static final String DATA_IS_EMPTY = "数据为空";
|
||||
public static final String STOCK_LESS = "库存不足";
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
/**
|
||||
* 密码常量
|
||||
*/
|
||||
public class PasswordConstant {
|
||||
// 默认密码
|
||||
public static final String DEFAULT_PASSWORD = "123456";
|
||||
// JWT密码
|
||||
public static final String DEFAULT_JWT_PASSWORD = "123456";
|
||||
// 默认头像
|
||||
public static final String AVTAR = "https://oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg";
|
||||
// 设置token过期时间
|
||||
public static final long TOKEN_EXPIRATION = 365L * 24 * 60 * 60 * 1000;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Redis用户前缀设置
|
||||
*/
|
||||
@Data
|
||||
public class RedisUserConstant {
|
||||
public static final String REDIS_CART_KEY = "cart::";
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
/**
|
||||
* 状态常量,启用或者禁用
|
||||
*/
|
||||
public class StatusConstant {
|
||||
// 启用为1
|
||||
public static final Integer ENABLE = 1;
|
||||
// 禁用为0
|
||||
public static final Integer DISABLE = 0;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.atguigu.constant;
|
||||
|
||||
public class UserConstant {
|
||||
public static final String USER_AVATAR = "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132";
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.atguigu.context;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.spzx.model.entity.user.UserInfo;
|
||||
|
||||
public class BaseContext {
|
||||
public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
||||
public static ThreadLocal<SysUser> sysUserThreadLocal = new ThreadLocal<>();
|
||||
public static ThreadLocal<UserInfo> userInfoThreadLocal = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 获取当前用户id
|
||||
*/
|
||||
public static Long getUserId() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户id
|
||||
*/
|
||||
public static void setUserId(Long userId) {
|
||||
threadLocal.set(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 系统用户实体类
|
||||
*/
|
||||
public static SysUser getSysUser() {
|
||||
return sysUserThreadLocal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前 系统用户实体类
|
||||
*/
|
||||
public static void setSysUser(SysUser sysUser) {
|
||||
sysUserThreadLocal.set(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 用户实体类
|
||||
*/
|
||||
public static UserInfo getUserInfo() {
|
||||
return userInfoThreadLocal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前 用户实体类
|
||||
*/
|
||||
public static void setUserInfo(UserInfo userInfo) {
|
||||
userInfoThreadLocal.set(userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出当前id
|
||||
*/
|
||||
public static void remove() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出当前 系统用户实体类
|
||||
*/
|
||||
public static void removeSysUser() {
|
||||
sysUserThreadLocal.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出当前 用户实体类
|
||||
*/
|
||||
public static void removeUserInfo() {
|
||||
userInfoThreadLocal.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.atguigu.exception;
|
||||
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@ToString
|
||||
@Slf4j
|
||||
public class BunnyException extends RuntimeException {
|
||||
Integer code;// 状态码
|
||||
String message;// 描述信息
|
||||
|
||||
public BunnyException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BunnyException(String message) {
|
||||
super(message);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BunnyException(ResultCodeEnum codeEnum) {
|
||||
super(codeEnum.getMessage());
|
||||
this.code = codeEnum.getCode();
|
||||
this.message = codeEnum.getMessage();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.atguigu.lib;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public final class MD5 {
|
||||
public static String encrypt(String strSrc) {
|
||||
try {
|
||||
char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
byte[] bytes = strSrc.getBytes();
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(bytes);
|
||||
bytes = md.digest();
|
||||
int j = bytes.length;
|
||||
char[] chars = new char[j * 2];
|
||||
int k = 0;
|
||||
for (byte b : bytes) {
|
||||
chars[k++] = hexChars[b >>> 4 & 0xf];
|
||||
chars[k++] = hexChars[b & 0xf];
|
||||
}
|
||||
return new String(chars);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("MD5加密出错!!+" + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(MD5.encrypt("111111"));
|
||||
}
|
||||
}
|
|
@ -1,27 +1,38 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>spzx-common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>spzx-common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>spzx-common</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>common-util</module>
|
||||
<module>common-service</module>
|
||||
</modules>
|
||||
<name>spzx-common</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>common-util</module>
|
||||
<module>common-service</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<!-- 自己的模块 -->
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- hutool工具包 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.25</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
FROM openjdk:17
|
||||
MAINTAINER bunny
|
||||
|
||||
#系统编码
|
||||
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
|
||||
|
||||
# 设置时区,构建镜像时执行的命令
|
||||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
RUN echo "Asia/Shanghai" > /etc/timezone
|
||||
|
||||
# 设定工作目录
|
||||
WORKDIR /home/bunny
|
||||
|
||||
# 复制jar包
|
||||
COPY target/*.jar /home/bunny/app.jar
|
||||
|
||||
#启动容器时的进程
|
||||
ENTRYPOINT ["java","-jar","/home/bunny/app.jar"]
|
||||
|
||||
#暴露 8080 端口
|
||||
EXPOSE 8501
|
|
@ -1,23 +1,112 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>spzx-manager</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>spzx-manager</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spzx-manager</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<name>spzx-manager</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<docker.repostory>192.168.1.4:1100</docker.repostory>
|
||||
<docker.registry.name>spzx</docker.registry.name>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
<!-- 自己的模块 -->
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- spring boot web开发所需要的起步依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- Spring的test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<!-- redis的起步依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- mybatis的起步依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- mysql驱动 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- 分页插件 -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<!--将插件绑定在某个phase执行-->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>build-image</id>
|
||||
<!--将插件绑定在package这个phase(阶段)上。也就是说,用户只需执行mvn package,就会自动执行mvn docker:build-->
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
<goal>push</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<serverId>harbor</serverId>
|
||||
<registryUrl>http://${docker.repostory}</registryUrl>
|
||||
<!-- 配置docker主机地址 -->
|
||||
<dockerHost>http://192.168.1.4:2375</dockerHost>
|
||||
<!--指定生成的镜像名-->
|
||||
<imageName>
|
||||
${docker.repostory}/${docker.registry.name}/${project.artifactId}:${project.version}
|
||||
</imageName>
|
||||
<!-- 指定 dockerfile 路径-->
|
||||
<dockerDirectory>${project.basedir}</dockerDirectory>
|
||||
<!-- 是否跳过docker构建 -->
|
||||
<skipDockerBuild>false</skipDockerBuild>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.atguigu;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.atguigu.spzx.manger;
|
||||
|
||||
import com.atguigu.log.annotation.EnableLogAspect;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement // 开启注解方式的事务管理
|
||||
@EnableCaching// 开启缓存注解
|
||||
@EnableScheduling
|
||||
@ComponentScan("com.atguigu")
|
||||
@EnableLogAspect// 开启切面类
|
||||
@MapperScan("com.atguigu.spzx.manger.mapper")
|
||||
@Slf4j
|
||||
public class MangerApplication {
|
||||
public static void main(String[] args) {
|
||||
log.info("启动===>MangerApplication");
|
||||
SpringApplication.run(MangerApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.BrandService;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "品牌管理")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/product/brand")
|
||||
public class BrandController {
|
||||
@Autowired
|
||||
private BrandService brandService;
|
||||
|
||||
@Log(title = "品牌列表分页查询", businessType = 0)
|
||||
@Operation(summary = "品牌列表分页查询", description = "品牌列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
|
||||
PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "品牌添加", businessType = 1)
|
||||
@Operation(summary = "品牌添加", description = "品牌添加")
|
||||
@PostMapping("save")
|
||||
public Result<Brand> save(@RequestBody Brand brand) {
|
||||
brandService.save(brand);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改品牌", businessType = 2)
|
||||
@Operation(summary = "修改品牌", description = "修改品牌")
|
||||
@PutMapping("updateById")
|
||||
public Result<Brand> updateById(@RequestBody Brand brand) {
|
||||
brandService.updateById(brand);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "删除品牌", businessType = 3)
|
||||
@Operation(summary = "删除品牌", description = "删除品牌")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> deleteById(@PathVariable Long id) {
|
||||
brandService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "品牌列表", businessType = 0)
|
||||
@Operation(summary = "品牌列表", description = "品牌列表接口")
|
||||
@GetMapping("findAll")
|
||||
public Result<List<Brand>> findAll() {
|
||||
List<Brand> list = brandService.findAll();
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.CategoryBrandService;
|
||||
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
|
||||
import com.atguigu.spzx.model.entity.product.CategoryBrand;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "分类品牌")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/product/categoryBrand")
|
||||
public class CategoryBrandController {
|
||||
@Autowired
|
||||
private CategoryBrandService categoryBrandService;
|
||||
|
||||
@Log(title = "分类品牌列表", businessType = 0)
|
||||
@Operation(summary = "分类品牌列表", description = "分类品牌列表接口")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, CategoryBrandDto dto) {
|
||||
PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page, limit, dto);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 1)
|
||||
@Operation(summary = "添加功能", description = "添加功能")
|
||||
@PostMapping("save")
|
||||
public Result<CategoryBrand> save(@RequestBody CategoryBrand categoryBrand) {
|
||||
categoryBrandService.save(categoryBrand);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 2)
|
||||
@Operation(summary = "修改功能", description = "修改功能")
|
||||
@PutMapping("updateById")
|
||||
public Result<CategoryBrand> updateById(@RequestBody CategoryBrand categoryBrand) {
|
||||
categoryBrandService.updateById(categoryBrand);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 3)
|
||||
@Operation(summary = "删除功能", description = "删除功能")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> deleteById(@PathVariable Long id) {
|
||||
categoryBrandService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.CategoryService;
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "分类管理")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/product/category")
|
||||
public class CategoryController {
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Log(title = "根据parentId获取下级节点", businessType = 0)
|
||||
@Operation(summary = "根据parentId获取下级节点", description = "根据parentId获取下级节点")
|
||||
@GetMapping(value = "findCategoryList/{parentId}")
|
||||
public Result<List<Category>> findByParentId(@PathVariable Long parentId) {
|
||||
List<Category> list = categoryService.findByParentId(parentId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "导出数据", description = "导出数据")
|
||||
@GetMapping(value = "/exportData")
|
||||
public void exportData(HttpServletResponse response) {
|
||||
categoryService.exportData(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "导入功能", description = "导入功能")
|
||||
@PostMapping("importData")
|
||||
public Result<String> importData(MultipartFile file) {
|
||||
categoryService.importData(file);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.FileUploadService;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Tag(name = "上传文件接口")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system")
|
||||
public class FileUploadController {
|
||||
@Autowired
|
||||
private FileUploadService fileUploadService;
|
||||
|
||||
@Log(title = "上传文件", businessType = 0)
|
||||
@Operation(summary = "上传文件", description = "上传文件内容")
|
||||
@PostMapping("fileUpload")
|
||||
public Result<String> fileUploadService(@RequestParam(value = "file") MultipartFile file) {
|
||||
String fileUrl = fileUploadService.uploadFile(file);
|
||||
return Result.success(fileUrl);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||
import com.atguigu.spzx.manger.service.SysUserService;
|
||||
import com.atguigu.spzx.manger.service.ValidateCodeService;
|
||||
import com.atguigu.spzx.model.dto.system.LoginDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
import com.atguigu.spzx.model.vo.system.ValidateCodeVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "用户相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/index")
|
||||
public class IndexController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private ValidateCodeService validateCodeService;
|
||||
|
||||
@Operation(summary = "生成验证码", description = "生成验证码信息")
|
||||
@GetMapping("generateValidateCode")
|
||||
public Result<ValidateCodeVo> generateValidateCode() {
|
||||
ValidateCodeVo vo = validateCodeService.generateValidateCode();
|
||||
return Result.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "登录请求", description = "登录请求实现")
|
||||
@PostMapping("login")
|
||||
public Result<LoginVo> login(@RequestBody LoginDto loginDto) {
|
||||
LoginVo vo = sysUserService.login(loginDto);
|
||||
return Result.success(vo);
|
||||
}
|
||||
|
||||
@Log(title = "获取登录用户信息", businessType = 0)
|
||||
@Operation(summary = "获取登录用户信息", description = "获取当前登录用户信息")
|
||||
@GetMapping("getUserInfo")
|
||||
public Result<SysUser> getUserInfo() {
|
||||
SysUser sysUser = BaseContext.getSysUser();
|
||||
return Result.success(sysUser);
|
||||
}
|
||||
|
||||
@Operation(summary = "用户退出", description = "用户退出接口")
|
||||
@GetMapping("logout")
|
||||
public Result<String> logout(@RequestHeader(name = "token") String token) {
|
||||
sysUserService.logout(token);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "动态菜单", businessType = 0)
|
||||
@Operation(summary = "动态菜单", description = "动态菜单")
|
||||
@GetMapping("menus")
|
||||
public Result<List<SysMenuVo>> menus() {
|
||||
List<SysMenuVo> sysMenuVoList = sysMenuService.findUserMenuList();
|
||||
return Result.success(sysMenuVoList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.OrderInfoService;
|
||||
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
|
||||
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "统计查询")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/order/orderInfo")
|
||||
public class OrderInfoController {
|
||||
|
||||
@Autowired
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@Log(title = "统计查询", businessType = 0)
|
||||
@Operation(summary = "统计查询", description = "统计查询")
|
||||
@GetMapping("/getOrderStatisticsData")
|
||||
public Result<OrderStatisticsVo> getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
|
||||
OrderStatisticsVo orderStatisticsVo = orderInfoService.getOrderStatisticsData(orderStatisticsDto);
|
||||
return Result.success(orderStatisticsVo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.CategoryBrandService;
|
||||
import com.atguigu.spzx.manger.service.ProductService;
|
||||
import com.atguigu.spzx.model.dto.product.ProductDto;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.entity.product.Product;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "商品管理")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/product/product")
|
||||
public class ProductController {
|
||||
@Autowired
|
||||
private ProductService productService;
|
||||
@Autowired
|
||||
private CategoryBrandService categoryBrandService;
|
||||
|
||||
@Log(title = "列表查询", businessType = 0)
|
||||
@Operation(summary = "列表查询", description = "列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<Product>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, ProductDto dto) {
|
||||
PageInfo<Product> pageInfo = productService.findByPage(page, limit, dto);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 1)
|
||||
@Operation(summary = "添加功能", description = "添加功能")
|
||||
@GetMapping("findBrandByCategoryId/{categoryId}")
|
||||
public Result<List<Brand>> findBrandByCategoryId(@PathVariable Long categoryId) {
|
||||
List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
|
||||
return Result.success(brandList);
|
||||
}
|
||||
|
||||
@Log(title = "保存商品数据接口", businessType = 2)
|
||||
@Operation(summary = "保存商品数据接口", description = "保存商品数据接口")
|
||||
@PostMapping("save")
|
||||
public Result<Product> save(@RequestBody Product product) {
|
||||
productService.save(product);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "查询商品详情", businessType = 0)
|
||||
@Operation(summary = "查询商品详情", description = "查询商品详情")
|
||||
@GetMapping("getById/{id}")
|
||||
public Result<Product> getById(@PathVariable Long id) {
|
||||
Product product = productService.getById(id);
|
||||
return Result.success(product);
|
||||
}
|
||||
|
||||
@Log(title = "查询商品详情", businessType = 1)
|
||||
@Operation(summary = "保存修改数据接口", description = "保存修改数据接口")
|
||||
@PutMapping("updateById")
|
||||
public Result<Product> updateById(@Parameter(name = "product", description = "请求参数实体类", required = true) @RequestBody Product product) {
|
||||
productService.updateById(product);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "查询商品详情", businessType = 3)
|
||||
@Operation(summary = "删除商品", description = "删除商品")
|
||||
@DeleteMapping("/deleteById/{id}")
|
||||
public Result<Long> deleteById(@Parameter(name = "id", description = "商品id", required = true) @PathVariable Long id) {
|
||||
productService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "商品审核", businessType = 0)
|
||||
@Operation(summary = "商品审核", description = "商品审核")
|
||||
@GetMapping("/updateAuditStatus/{id}/{auditStatus}")
|
||||
public Result<Product> updateAuditStatus(@PathVariable Long id, @PathVariable Integer auditStatus) {
|
||||
productService.updateAuditStatus(id, auditStatus);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "商品上下架", businessType = 0)
|
||||
@Operation(summary = "商品上下架", description = "商品上下架")
|
||||
@GetMapping("/updateStatus/{id}/{status}")
|
||||
public Result<Product> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
|
||||
productService.updateStatus(id, status);
|
||||
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.ProductSpecService;
|
||||
import com.atguigu.spzx.model.entity.product.ProductSpec;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "商品规格管理")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/product/productSpec")
|
||||
public class ProductSpecController {
|
||||
@Autowired
|
||||
private ProductSpecService productSpecService;
|
||||
|
||||
@Log(title = "列表查询", businessType = 0)
|
||||
@Operation(summary = "列表查询", description = "列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<ProductSpec>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
|
||||
PageInfo<ProductSpec> pageInfo = productSpecService.findByPage(page, limit);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加功能", businessType = 1)
|
||||
@Operation(summary = "添加功能", description = "添加功能")
|
||||
@PostMapping("save")
|
||||
public Result<ProductSpec> save(@RequestBody ProductSpec productSpec) {
|
||||
productSpecService.save(productSpec);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改功能", businessType = 2)
|
||||
@Operation(summary = "修改功能", description = "修改功能")
|
||||
@PutMapping("updateById")
|
||||
public Result<ProductSpec> updateById(@RequestBody ProductSpec productSpec) {
|
||||
productSpecService.updateById(productSpec);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "删除功能", businessType = 3)
|
||||
@Operation(summary = "删除功能", description = "删除功能")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> removeById(@PathVariable Long id) {
|
||||
productSpecService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "加载商品规格数据", businessType = 0)
|
||||
@Operation(summary = "加载商品规格数据", description = "加载商品规格数据")
|
||||
@GetMapping("findAll")
|
||||
public Result<List<ProductSpec>> findAll() {
|
||||
List<ProductSpec> list = productSpecService.findAll();
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.ProductUnitService;
|
||||
import com.atguigu.spzx.model.entity.base.ProductUnit;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "品牌数据")
|
||||
@RestController
|
||||
@RequestMapping("/admin/product/productUnit")
|
||||
public class ProductUnitController {
|
||||
@Autowired
|
||||
private ProductUnitService productUnitService;
|
||||
|
||||
@Log(title = "加载商品单元数据", businessType = 0)
|
||||
@Operation(summary = "加载商品单元数据", description = "加载商品单元数据")
|
||||
@GetMapping("findAll")
|
||||
public Result<List<ProductUnit>> findAll() {
|
||||
List<ProductUnit> productUnitList = productUnitService.findAll();
|
||||
return Result.success(productUnitList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "菜单管理接口")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/system/sysMenu")
|
||||
public class SysMenuController {
|
||||
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Log(title = "查询菜单", businessType = 0)
|
||||
@Operation(summary = "查询菜单", description = "查询菜单内容")
|
||||
@GetMapping("/findNodes")
|
||||
public Result<List<SysMenu>> findNodes() {
|
||||
List<SysMenu> list = sysMenuService.findNodes();
|
||||
return Result.build(list, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Log(title = "添加菜单", businessType = 1)
|
||||
@Operation(summary = "添加菜单", description = "添加菜单")
|
||||
@PostMapping("save")
|
||||
public Result<SysMenu> save(@RequestBody SysMenu sysMenu) {
|
||||
sysMenuService.save(sysMenu);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改菜单", businessType = 2)
|
||||
@Operation(summary = "修改菜单", description = "修改菜单")
|
||||
@PutMapping("update")
|
||||
public Result<SysMenu> update(@RequestBody SysMenu sysMenu) {
|
||||
sysMenuService.update(sysMenu);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "删除菜单", businessType = 3)
|
||||
@Operation(summary = "删除菜单", description = "删除菜单")
|
||||
@DeleteMapping("removeById/{id}")
|
||||
public Result<Long> removeById(@PathVariable Long id) {
|
||||
sysMenuService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysRoleService;
|
||||
import com.atguigu.spzx.model.dto.system.AssginRoleDto;
|
||||
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysRole;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.system.AllRolesVo;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "角色相关接口")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/system/sysRole")
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Log(title = "查询角色分页", businessType = 0)
|
||||
@Operation(summary = "查询角色分页", description = "查询角色信息返回分页")
|
||||
@PostMapping("findByPage/{pageNum}/{pageSize}")
|
||||
public Result<PageInfo<SysRole>> findByPage(@RequestBody SysRoleDto sysRoleDto,
|
||||
@PathVariable(value = "pageNum") Integer pageNum, @PathVariable(value = "pageSize") Integer pageSize) {
|
||||
PageInfo<SysRole> pageInfo = sysRoleService.findByPage(sysRoleDto, pageNum, pageSize);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "添加角色", businessType = 1)
|
||||
@Operation(summary = "添加角色", description = "添加角色相关内容")
|
||||
@PostMapping(value = "saveSysRole")
|
||||
public Result<SysRole> saveSysRole(@RequestBody SysRole sysRole) {
|
||||
sysRoleService.saveSysRole(sysRole);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "修改角色", businessType = 2)
|
||||
@Operation(summary = "修改角色", description = "修改角色相关信息")
|
||||
@PutMapping(value = "updateSysRole")
|
||||
public Result<SysRole> updateSysRole(@RequestBody SysRole sysRole) {
|
||||
sysRoleService.updateSysRole(sysRole);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "根据角色id删除角色", businessType = 3)
|
||||
@Operation(summary = "根据角色id删除角色", description = "根据角色id删除角色信息")
|
||||
@DeleteMapping(value = "deleteById/{roleId}")
|
||||
public Result<AssginRoleDto> deleteById(@PathVariable(value = "roleId") Long roleId) {
|
||||
sysRoleService.deleteById(roleId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "查询所有角色", businessType = 0)
|
||||
@Operation(summary = "查询所有角色", description = "查询所有角色信息")
|
||||
@GetMapping(value = "findAllRoles/{userId}")
|
||||
public Result<AllRolesVo> findAllRoles(@PathVariable(value = "userId") Long userId) {
|
||||
AllRolesVo allRolesList = sysRoleService.findAllRoles(userId);
|
||||
return Result.success(allRolesList);
|
||||
}
|
||||
|
||||
@Log(title = "保存角色数据", businessType = 1)
|
||||
@Operation(summary = "保存角色数据", description = "保存角色数据信息")
|
||||
@PostMapping("doAssign")
|
||||
public Result<AssginRoleDto> doAssign(@RequestBody AssginRoleDto assginRoleDto) {
|
||||
sysRoleService.doAssign(assginRoleDto);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysRoleMenuService;
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.system.SysRoleMenuVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "分配菜单")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/system/sysRoleMenu")
|
||||
public class SysRoleMenuController {
|
||||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
@Log(title = "查询菜单", businessType = 0)
|
||||
@Operation(summary = "查询菜单", description = "查询菜单")
|
||||
@GetMapping(value = "findSysRoleMenuByRoleId/{roleId}")
|
||||
public Result<SysRoleMenuVo> findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
|
||||
SysRoleMenuVo sysRoleMenuList = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
|
||||
return Result.success(sysRoleMenuList);
|
||||
}
|
||||
|
||||
@Log(title = "保存菜单", businessType = 1)
|
||||
@Operation(summary = "保存菜单", description = "保存菜单")
|
||||
@PostMapping("doAssign")
|
||||
public Result<AssginMenuDto> doAssign(@RequestBody AssginMenuDto assginMenuDto) {
|
||||
sysRoleMenuService.doAssign(assginMenuDto);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.log.annotation.Log;
|
||||
import com.atguigu.spzx.manger.service.SysUserService;
|
||||
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "用户管理接口")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/system/sysUser")
|
||||
public class SysUserController {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Log(title = "查询用户", businessType = 0)
|
||||
@Operation(summary = "查询用户", description = "查询用户信息")
|
||||
@GetMapping(value = "findByPage/{pageNum}/{pageSize}")
|
||||
public Result<PageInfo<SysUser>> findByPage(SysUserDto sysUserDto,
|
||||
@PathVariable(value = "pageNum") Integer pageNum,
|
||||
@PathVariable(value = "pageSize") Integer pageSize) {
|
||||
PageInfo<SysUser> userPageInfo = sysUserService.findByPage(sysUserDto, pageNum, pageSize);
|
||||
return Result.success(userPageInfo);
|
||||
}
|
||||
|
||||
@Log(title = "根据id删除用户", businessType = 3)
|
||||
@Operation(summary = "添加用户", description = "添加用户信息")
|
||||
@PostMapping(value = "saveSysUser")
|
||||
public Result<SysUser> saveSysUser(@RequestBody SysUser sysUser) {
|
||||
sysUserService.saveSysUser(sysUser);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "根据id删除用户", businessType = 3)
|
||||
@Operation(summary = "修改用户", description = "修改用户信息")
|
||||
@PutMapping("updateSysUser")
|
||||
public Result<SysUser> updateSysUser(@RequestBody SysUser sysUser) {
|
||||
sysUserService.updateSysUser(sysUser);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Log(title = "根据id删除用户", businessType = 3)
|
||||
@Operation(summary = "根据id删除用户", description = "删除用户信息")
|
||||
@DeleteMapping(value = "deleteById/{userId}")
|
||||
public Result<SysUser> deleteById(@PathVariable(value = "userId") Long userId) {
|
||||
sysUserService.deleteById(userId);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.atguigu.spzx.manger.excel;
|
||||
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.atguigu.spzx.manger.mapper.CategoryMapper;
|
||||
import com.atguigu.spzx.model.vo.product.CategoryExcelVo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class CategoryExcelListener<T> extends AnalysisEventListener<T> {
|
||||
// 每个5条存储数据库,方便垃圾回收
|
||||
private static final int BATCH_COUNT = 100;
|
||||
// 缓存的数据
|
||||
private final List<CategoryExcelVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
// 获取mapper对象
|
||||
private final CategoryMapper categoryMapper;
|
||||
|
||||
@Override
|
||||
public void invoke(T t, AnalysisContext analysisContext) {
|
||||
CategoryExcelVo data = (CategoryExcelVo) t;
|
||||
cachedDataList.add(data);
|
||||
if (cachedDataList.size() >= BATCH_COUNT) {
|
||||
saveData();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
// excel解析完毕以后需要执行的代码
|
||||
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
|
||||
saveData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入数据库
|
||||
*/
|
||||
private void saveData() {
|
||||
categoryMapper.batchInsert(cachedDataList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.atguigu.spzx.manger.excel;
|
||||
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ExcelListener<T> extends AnalysisEventListener<T> {
|
||||
// 可以通过实例获取该值
|
||||
private final List<T> dataList = new ArrayList<T>();
|
||||
|
||||
// 每解析一行数据就会调用一次该方法
|
||||
@Override
|
||||
|
||||
public void invoke(T t, AnalysisContext analysisContext) {
|
||||
// 数据存储到list,供批量处理,或后续自己业务逻辑处理。
|
||||
dataList.add(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
// excel解析完毕以后需要执行的代码
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BrandMapper {
|
||||
/**
|
||||
* 查找分页品牌
|
||||
*
|
||||
* @return 品牌列表
|
||||
*/
|
||||
List<Brand> findByPage();
|
||||
|
||||
/**
|
||||
* 品牌添加
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void save(Brand brand);
|
||||
|
||||
/**
|
||||
* 修改品牌
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void updateById(Brand brand);
|
||||
|
||||
/**
|
||||
* 根据id删除品牌
|
||||
*
|
||||
* @param id 品牌id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 品牌列表
|
||||
*
|
||||
* @return 品牌列表
|
||||
*/
|
||||
List<Brand> findAll();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.entity.product.CategoryBrand;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryBrandMapper {
|
||||
/**
|
||||
* 分类品牌列表
|
||||
*
|
||||
* @param dto 搜索条件实体类
|
||||
* @return PageInfo<CategoryBrand>
|
||||
*/
|
||||
List<CategoryBrand> findByPage(CategoryBrandDto dto);
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param categoryBrand 分类品牌实体类
|
||||
*/
|
||||
void save(CategoryBrand categoryBrand);
|
||||
|
||||
void updateById(CategoryBrand categoryBrand);
|
||||
|
||||
/**
|
||||
* 删除功能
|
||||
*
|
||||
* @param id 删除的ID
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param categoryId 查询ID
|
||||
* @return List<Brand>
|
||||
*/
|
||||
List<Brand> findBrandByCategoryId(Long categoryId);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
import com.atguigu.spzx.model.vo.product.CategoryExcelVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
/**
|
||||
* 根据分类id查询它下面的所有的子分类数据
|
||||
*
|
||||
* @param parentId 父级ID
|
||||
* @return 分类实体类列表
|
||||
*/
|
||||
List<Category> selectByParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 查询该分类下子分类的数量
|
||||
*
|
||||
* @param id ID
|
||||
* @return int
|
||||
*/
|
||||
int countByParentId(Long id);
|
||||
|
||||
/**
|
||||
* 读取所以分类数据
|
||||
*
|
||||
* @return 分类实体类列表
|
||||
*/
|
||||
List<Category> selectAll();
|
||||
|
||||
/**
|
||||
* 批量插入数据库
|
||||
*
|
||||
* @param cachedDataList Excel表品牌管理实体类
|
||||
*/
|
||||
void batchInsert(List<CategoryExcelVo> cachedDataList);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.order.OrderStatistics;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface OrderInfoMapper {
|
||||
|
||||
/**
|
||||
* 查询指定日期产生的订单数据
|
||||
*
|
||||
* @param createTime 创建时间
|
||||
* @return OrderStatistics
|
||||
*/
|
||||
OrderStatistics selectOrderStatistics(String createTime);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
|
||||
import com.atguigu.spzx.model.entity.order.OrderStatistics;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderStatisticsMapper {
|
||||
/**
|
||||
* 插入
|
||||
*
|
||||
* @param orderStatistics 订单
|
||||
*/
|
||||
void insert(OrderStatistics orderStatistics);
|
||||
|
||||
/**
|
||||
* 查询统计结果数据
|
||||
*
|
||||
* @param orderStatisticsDto 搜索条件实体类
|
||||
* @return 搜索条件实体类列表
|
||||
*/
|
||||
List<OrderStatistics> selectList(OrderStatisticsDto orderStatisticsDto);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.ProductDetails;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ProductDetailsMapper {
|
||||
/**
|
||||
* 保存数据
|
||||
*
|
||||
* @param productDetails 商品实体类
|
||||
*/
|
||||
void save(ProductDetails productDetails);
|
||||
|
||||
/**
|
||||
* 根据商品的id查询商品详情数据
|
||||
*
|
||||
* @param id 查询的ID
|
||||
* @return ProductDetails
|
||||
*/
|
||||
ProductDetails selectByProductId(Long id);
|
||||
|
||||
/**
|
||||
* 修改商品的详情数据
|
||||
*
|
||||
* @param productDetails ProductDetails
|
||||
*/
|
||||
void updateById(ProductDetails productDetails);
|
||||
|
||||
/**
|
||||
* 根据商品的id删除商品的详情数据
|
||||
*
|
||||
* @param id 删除ID
|
||||
*/
|
||||
void deleteByProductId(Long id);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.dto.product.ProductDto;
|
||||
import com.atguigu.spzx.model.entity.product.Product;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductMapper {
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @return 查询结果
|
||||
*/
|
||||
List<Product> findByPage(ProductDto dto);
|
||||
|
||||
/**
|
||||
* 保存商品数据
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
void save(Product product);
|
||||
|
||||
/**
|
||||
* 根据id查询商品数据
|
||||
*
|
||||
* @param id 查询的ID
|
||||
* @return 商品实体类
|
||||
*/
|
||||
Product selectById(Long id);
|
||||
|
||||
/**
|
||||
* 修改商品基本数据
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
void updateById(Product product);
|
||||
|
||||
/**
|
||||
* 根据id删除商品基本数据
|
||||
*
|
||||
* @param id 删除ID
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.ProductSku;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSkuMapper {
|
||||
/**
|
||||
* 保存数据
|
||||
*
|
||||
* @param productSku 商品实体类
|
||||
*/
|
||||
void save(ProductSku productSku);
|
||||
|
||||
/**
|
||||
* 根据商品的id查询sku数据
|
||||
*
|
||||
* @param id 查询的ID
|
||||
* @return 商品实体类列表
|
||||
*/
|
||||
List<ProductSku> selectByProductId(Long id);
|
||||
|
||||
/**
|
||||
* 修改商品的sku数据
|
||||
*
|
||||
* @param productSku 商品实体类
|
||||
*/
|
||||
void updateById(ProductSku productSku);
|
||||
|
||||
/**
|
||||
* 根据商品id删除商品的sku数据
|
||||
*
|
||||
* @param id 删除ID
|
||||
*/
|
||||
void deleteByProductId(Long id);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.ProductSpec;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSpecMapper {
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @return 分页结果
|
||||
*/
|
||||
List<ProductSpec> findByPage();
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param productSpec 商品规格实体类
|
||||
*/
|
||||
void save(ProductSpec productSpec);
|
||||
|
||||
/**
|
||||
* 修改功能
|
||||
*
|
||||
* @param productSpec 商品规格实体类
|
||||
*/
|
||||
void updateById(ProductSpec productSpec);
|
||||
|
||||
/**
|
||||
* 删除功能
|
||||
*
|
||||
* @param id 要删除的ID
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 加载商品规格数据
|
||||
*
|
||||
* @return 列表
|
||||
*/
|
||||
List<ProductSpec> findAll();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.base.ProductUnit;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductUnitMapper {
|
||||
/**
|
||||
* 加载商品单元数据
|
||||
*
|
||||
* @return 产品单元实体类列表
|
||||
*/
|
||||
List<ProductUnit> findAll();
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysMenuMapper {
|
||||
/**
|
||||
* 查询菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectAll();
|
||||
|
||||
/**
|
||||
* 插入菜单
|
||||
*
|
||||
* @param sysMenu 系统菜单实体类
|
||||
*/
|
||||
void insert(SysMenu sysMenu);
|
||||
|
||||
/**
|
||||
* 根据id修改菜单
|
||||
*
|
||||
* @param sysMenu 系统菜单实体类
|
||||
*/
|
||||
void update(SysMenu sysMenu);
|
||||
|
||||
/**
|
||||
* 根据id查询菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
* @return 是否存在
|
||||
*/
|
||||
int countByParentId(Long id);
|
||||
|
||||
/**
|
||||
* 根据id删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 根据用户ID查找
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据父级ID查询菜单
|
||||
*
|
||||
* @param id 父级ID
|
||||
* @return 系统菜单实体类
|
||||
*/
|
||||
SysMenu selectParentMenu(Long id);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysOperLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysOperaLogMapper {
|
||||
/**
|
||||
* 异步执行保存日志操作
|
||||
*
|
||||
* @param sysOperaLog SysOperaLog
|
||||
*/
|
||||
void insert(SysOperLog sysOperaLog);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper {
|
||||
/**
|
||||
* 查询角色信息
|
||||
*
|
||||
* @param sysRoleDto 请求参数实体类
|
||||
* @return List<SysRole
|
||||
*/
|
||||
List<SysRole> findByPage(SysRoleDto sysRoleDto);
|
||||
|
||||
/**
|
||||
* 添加角色相关内容
|
||||
*
|
||||
* @param sysRole 角色实体类
|
||||
*/
|
||||
void saveSysRole(SysRole sysRole);
|
||||
|
||||
/**
|
||||
* 修改角色相关信息
|
||||
*
|
||||
* @param sysRole 角色实体类
|
||||
*/
|
||||
void updateSysRole(SysRole sysRole);
|
||||
|
||||
/**
|
||||
* 根据角色id删除角色
|
||||
*
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
void deleteById(Long roleId);
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 所有角色
|
||||
*/
|
||||
List<SysRole> findAllRoles();
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper {
|
||||
List<Long> findSysRoleMenuByRoleId(Long roleId);
|
||||
|
||||
void doAssign(AssginMenuDto assginMenuDto);
|
||||
|
||||
void deleteByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 将该id的菜单设置为半开
|
||||
*
|
||||
* @param parentId 父级ID
|
||||
*/
|
||||
void updateSysRoleMenuIsHalf(Long parentId);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleUserMapper {
|
||||
/**
|
||||
* 根据用户id删除内容
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 分配角色数据
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
void doAssign(Long userId, Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户id查询内容
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
List<Long> findSysUserRoleByUserId(Long userId);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserMapper {
|
||||
/**
|
||||
* * 根据username查询用户信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
SysUser selectByUsername(String username);
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
*
|
||||
* @param sysUserDto 用户请求参数实体类
|
||||
* @return List<SysUser>
|
||||
*/
|
||||
List<SysUser> findByPage(SysUserDto sysUserDto);
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
void save(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
void updateSysUser(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 根据id删除用户
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void deleteById(Long userId);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.atguigu.spzx.manger.properties;
|
||||
|
||||
import io.minio.MinioClient;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "bunny.minio")
|
||||
@Data
|
||||
public class MinioProperties {
|
||||
private String endpointUrl;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String bucketName;
|
||||
|
||||
@Bean
|
||||
public MinioClient minioClient() {
|
||||
return MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BrandService {
|
||||
/**
|
||||
* 品牌列表查询
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页大小
|
||||
* @return 品牌分页结果
|
||||
*/
|
||||
PageInfo<Brand> findByPage(Integer page, Integer limit);
|
||||
|
||||
/**
|
||||
* 品牌添加
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void save(Brand brand);
|
||||
|
||||
/**
|
||||
* 修改品牌
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void updateById(Brand brand);
|
||||
|
||||
/**
|
||||
* 根据id删除品牌
|
||||
*
|
||||
* @param id 品牌id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 品牌列表
|
||||
*
|
||||
* @return 品牌列表
|
||||
*/
|
||||
List<Brand> findAll();
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.entity.product.CategoryBrand;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CategoryBrandService {
|
||||
/**
|
||||
* 分类品牌列表
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页限制
|
||||
* @param dto 搜索条件实体类
|
||||
* @return PageInfo<CategoryBrand>
|
||||
*/
|
||||
PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto dto);
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param categoryBrand 分类品牌实体类
|
||||
*/
|
||||
void save(CategoryBrand categoryBrand);
|
||||
|
||||
/**
|
||||
* 修改功能
|
||||
*
|
||||
* @param categoryBrand 分类品牌实体类
|
||||
*/
|
||||
void updateById(CategoryBrand categoryBrand);
|
||||
|
||||
/**
|
||||
* 删除功能
|
||||
*
|
||||
* @param id 删除的ID
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param categoryId 查询ID
|
||||
* @return List<Brand>
|
||||
*/
|
||||
List<Brand> findBrandByCategoryId(Long categoryId);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CategoryService {
|
||||
/**
|
||||
* 根据父级id查找
|
||||
*
|
||||
* @param parentId 父级id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<Category> findByParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
void exportData(HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 导入功能
|
||||
*
|
||||
* @param file Excel文件
|
||||
*/
|
||||
void importData(MultipartFile file);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface FileUploadService {
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 上传的文件
|
||||
* @return file的地址
|
||||
*/
|
||||
String uploadFile(MultipartFile file);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
|
||||
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
|
||||
|
||||
public interface OrderInfoService {
|
||||
/**
|
||||
* 统计查询
|
||||
*
|
||||
* @param orderStatisticsDto 搜索条件实体类
|
||||
* @return 统计结果实体类
|
||||
*/
|
||||
OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto);
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
|
||||
import com.atguigu.spzx.model.dto.product.ProductDto;
|
||||
import com.atguigu.spzx.model.entity.product.Product;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface ProductService {
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @param page 当前也
|
||||
* @param limit 每页限制
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto dto);
|
||||
|
||||
/**
|
||||
* 保存商品数据接口
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
void save(Product product);
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
*
|
||||
* @param id 查询ID
|
||||
* @return 商品实体类
|
||||
*/
|
||||
Product getById(Long id);
|
||||
|
||||
/**
|
||||
* 保存修改数据接口
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
void updateById(Product product);
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*
|
||||
* @param id 删除ID
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 商品审核
|
||||
*
|
||||
* @param id 审核ID
|
||||
* @param auditStatus 审核状态
|
||||
*/
|
||||
void updateAuditStatus(Long id, Integer auditStatus);
|
||||
|
||||
/**
|
||||
* 商品上下架
|
||||
*
|
||||
* @param id 上下架ID
|
||||
* @param status 上下架状态
|
||||
*/
|
||||
void updateStatus(Long id, Integer status);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.ProductSpec;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductSpecService {
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页限制
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageInfo<ProductSpec> findByPage(Integer page, Integer limit);
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param productSpec 商品规格实体类
|
||||
*/
|
||||
void save(ProductSpec productSpec);
|
||||
|
||||
/**
|
||||
* 修改功能
|
||||
*
|
||||
* @param productSpec 商品规格实体类
|
||||
*/
|
||||
void updateById(ProductSpec productSpec);
|
||||
|
||||
/**
|
||||
* 删除功能
|
||||
*
|
||||
* @param id 要删除的ID
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 加载商品规格数据
|
||||
*
|
||||
* @return 列表
|
||||
*/
|
||||
List<ProductSpec> findAll();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.base.ProductUnit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductUnitService {
|
||||
/**
|
||||
* 加载商品单元数据
|
||||
*
|
||||
* @return 产品单元实体类列表
|
||||
*/
|
||||
List<ProductUnit> findAll();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysMenuService {
|
||||
/**
|
||||
* 查询菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findNodes();
|
||||
|
||||
/**
|
||||
* 添加菜单
|
||||
*
|
||||
* @param sysMenu 系统菜单实体类
|
||||
*/
|
||||
void save(SysMenu sysMenu);
|
||||
|
||||
/**
|
||||
* 修改菜单
|
||||
*
|
||||
* @param sysMenu 系统菜单实体类
|
||||
*/
|
||||
void update(SysMenu sysMenu);
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
void removeById(Long id);
|
||||
|
||||
/**
|
||||
* 动态菜单
|
||||
*
|
||||
* @return 动态菜单列表
|
||||
*/
|
||||
List<SysMenuVo> findUserMenuList();
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
import com.atguigu.spzx.model.vo.system.SysRoleMenuVo;
|
||||
|
||||
public interface SysRoleMenuService {
|
||||
/**
|
||||
* 查询菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 查询菜单返回实体类
|
||||
*/
|
||||
SysRoleMenuVo findSysRoleMenuByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 保存菜单
|
||||
*
|
||||
* @param assginMenuDto 请求参数实体类
|
||||
*/
|
||||
void doAssign(AssginMenuDto assginMenuDto);
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.AssginRoleDto;
|
||||
import com.atguigu.spzx.model.dto.system.SysRoleDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysRole;
|
||||
import com.atguigu.spzx.model.vo.system.AllRolesVo;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface SysRoleService {
|
||||
/**
|
||||
* 查询角色信息返回分页
|
||||
*
|
||||
* @param sysRoleDto 请求参数实体类
|
||||
* @param pageNum 当前也
|
||||
* @param pageSize 分页大小
|
||||
* @return 返回分页结果
|
||||
*/
|
||||
PageInfo<SysRole> findByPage(SysRoleDto sysRoleDto, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 添加角色相关内容
|
||||
*
|
||||
* @param sysRole 角色实体类
|
||||
*/
|
||||
void saveSysRole(SysRole sysRole);
|
||||
|
||||
/**
|
||||
* 修改角色相关信息
|
||||
*
|
||||
* @param sysRole 角色实体类
|
||||
*/
|
||||
void updateSysRole(SysRole sysRole);
|
||||
|
||||
/**
|
||||
* 根据角色id删除角色
|
||||
*
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
void deleteById(Long roleId);
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 所有角色信息
|
||||
*/
|
||||
AllRolesVo findAllRoles(Long userId);
|
||||
|
||||
/**
|
||||
* 保存角色数据
|
||||
*
|
||||
* @param assginRoleDto 请求参数实体类
|
||||
*/
|
||||
void doAssign(AssginRoleDto assginRoleDto);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.LoginDto;
|
||||
import com.atguigu.spzx.model.dto.system.SysUserDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface SysUserService {
|
||||
/**
|
||||
* * 登录请求实现
|
||||
*
|
||||
* @param loginDto 登录请求参数
|
||||
* @return 登录后结果
|
||||
*/
|
||||
LoginVo login(LoginDto loginDto);
|
||||
|
||||
/**
|
||||
* * 用户退出接口
|
||||
*
|
||||
* @param token token值
|
||||
*/
|
||||
void logout(String token);
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
*
|
||||
* @param sysUserDto 用户请求体
|
||||
* @param pageNum 当前页
|
||||
* @param pageSize 一页大小
|
||||
* @return 用户分页结果
|
||||
*/
|
||||
PageInfo<SysUser> findByPage(SysUserDto sysUserDto, Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
void saveSysUser(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*
|
||||
* @param sysUser 系统用户实体类
|
||||
*/
|
||||
void updateSysUser(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 根据id删除用户
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void deleteById(Long userId);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.vo.system.ValidateCodeVo;
|
||||
|
||||
public interface ValidateCodeService {
|
||||
/**
|
||||
* 生成验证码信息
|
||||
*
|
||||
* @return 验证码响应结果实体类
|
||||
*/
|
||||
ValidateCodeVo generateValidateCode();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import com.atguigu.log.service.AsyncOperaLogService;
|
||||
import com.atguigu.spzx.manger.mapper.SysOperaLogMapper;
|
||||
import com.atguigu.spzx.model.entity.system.SysOperLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AsyncOperaLogServiceImpl implements AsyncOperaLogService {
|
||||
@Autowired
|
||||
private SysOperaLogMapper sysOperaLogMapper;
|
||||
|
||||
/**
|
||||
* 异步执行保存日志操作
|
||||
*
|
||||
* @param sysOperaLog SysOperLog
|
||||
*/
|
||||
@Async
|
||||
@Override
|
||||
public void saveSysOperaLog(SysOperLog sysOperaLog) {
|
||||
sysOperaLogMapper.insert(sysOperaLog);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.spzx.manger.mapper.BrandMapper;
|
||||
import com.atguigu.spzx.manger.service.BrandService;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BrandServiceImpl implements BrandService {
|
||||
@Autowired
|
||||
private BrandMapper brandMapper;
|
||||
@Autowired
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 品牌列表查询
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页大小
|
||||
* @return 品牌分页结果
|
||||
*/
|
||||
@Override
|
||||
public PageInfo<Brand> findByPage(Integer page, Integer limit) {
|
||||
Page<Brand> startPage = PageHelper.startPage(page, limit);
|
||||
|
||||
// 查找分页品牌
|
||||
List<Brand> brandList = brandMapper.findByPage();
|
||||
startPage.close();
|
||||
return new PageInfo<>(brandList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 品牌添加
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
@Override
|
||||
public void save(Brand brand) {
|
||||
brandMapper.save(brand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改品牌
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
@Override
|
||||
public void updateById(Brand brand) {
|
||||
// 插入时不能为空
|
||||
emptyUtil.isEmpty(brand, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
|
||||
brandMapper.updateById(brand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除品牌
|
||||
*
|
||||
* @param id 品牌id
|
||||
*/
|
||||
@Override
|
||||
public void deleteById(Long id) {
|
||||
// 判断ID不能为空
|
||||
emptyUtil.isEmpty(id, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
|
||||
brandMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 品牌列表
|
||||
*
|
||||
* @return 品牌列表
|
||||
*/
|
||||
@Override
|
||||
public List<Brand> findAll() {
|
||||
return brandMapper.findAll();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.manger.mapper.CategoryBrandMapper;
|
||||
import com.atguigu.spzx.manger.service.CategoryBrandService;
|
||||
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.entity.product.CategoryBrand;
|
||||
import com.atguigu.utils.EmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CategoryBrandServiceImpl implements CategoryBrandService {
|
||||
@Autowired
|
||||
private CategoryBrandMapper categoryBrandMapper;
|
||||
@Autowired
|
||||
private EmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 分类品牌列表
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页限制
|
||||
* @param dto 搜索条件实体类
|
||||
* @return PageInfo<CategoryBrand>
|
||||
*/
|
||||
@Override
|
||||
public PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto dto) {
|
||||
Page<Object> startPage = PageHelper.startPage(page, limit);
|
||||
List<CategoryBrand> categoryBrandList = categoryBrandMapper.findByPage(dto);
|
||||
|
||||
// 关闭资源
|
||||
startPage.close();
|
||||
return new PageInfo<>(categoryBrandList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param categoryBrand 分类品牌实体类
|
||||
*/
|
||||
@Override
|
||||
public void save(CategoryBrand categoryBrand) {
|
||||
if (categoryBrand == null) {
|
||||
throw new BunnyException(MessageConstant.SAVE_DTO_IS_NULL);
|
||||
}
|
||||
categoryBrandMapper.save(categoryBrand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改功能
|
||||
*
|
||||
* @param categoryBrand 分类品牌实体类
|
||||
*/
|
||||
@Override
|
||||
public void updateById(CategoryBrand categoryBrand) {
|
||||
if (categoryBrand == null) {
|
||||
throw new BunnyException(MessageConstant.UPDATE_DTO_IS_NULL);
|
||||
}
|
||||
categoryBrandMapper.updateById(categoryBrand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除功能
|
||||
*
|
||||
* @param id 删除的ID
|
||||
*/
|
||||
@Override
|
||||
public void deleteById(Long id) {
|
||||
emptyUtil.isEmpty(id, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
categoryBrandMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加功能
|
||||
*
|
||||
* @param categoryId 查询ID
|
||||
* @return List<Brand>
|
||||
*/
|
||||
@Override
|
||||
public List<Brand> findBrandByCategoryId(Long categoryId) {
|
||||
emptyUtil.isEmpty(categoryId, MessageConstant.FIND_ID_IS_NOT_EMPTY);
|
||||
return categoryBrandMapper.findBrandByCategoryId(categoryId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.manger.excel.CategoryExcelListener;
|
||||
import com.atguigu.spzx.manger.mapper.CategoryMapper;
|
||||
import com.atguigu.spzx.manger.service.CategoryService;
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
import com.atguigu.spzx.model.vo.product.CategoryExcelVo;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
/**
|
||||
* 根据parentId获取下级节点
|
||||
*
|
||||
* @param parentId 父级ID
|
||||
* @return 分类实体类列表
|
||||
*/
|
||||
@Override
|
||||
public List<Category> findByParentId(Long parentId) {
|
||||
// 根据分类id查询它下面的所有的子分类数据
|
||||
List<Category> categoryList = categoryMapper.selectByParentId(parentId);
|
||||
if (!CollectionUtils.isEmpty(categoryList)) {
|
||||
categoryList.forEach(item -> {
|
||||
// 查询该分类下子分类的数量
|
||||
int count = categoryMapper.countByParentId(item.getId());
|
||||
item.setHasChildren(count > 0);
|
||||
});
|
||||
}
|
||||
return categoryList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
@Override
|
||||
public void exportData(HttpServletResponse response) {
|
||||
try {
|
||||
// 1. 设置响应头信息
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
String filename = URLEncoder.encode("分类数据", StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + filename + ".xlsx");
|
||||
|
||||
// 查询数据库中的数据
|
||||
List<Category> categoryList = categoryMapper.selectAll();
|
||||
ArrayList<CategoryExcelVo> excelVoArrayList = new ArrayList<>();
|
||||
|
||||
// 将从数据库中查询到的Category对象转换成CategoryExcelVo对象
|
||||
categoryList.forEach(category -> {
|
||||
CategoryExcelVo vo = new CategoryExcelVo();
|
||||
BeanUtils.copyProperties(category, vo, CategoryExcelVo.class);
|
||||
excelVoArrayList.add(vo);
|
||||
});
|
||||
// 写出数据到浏览器端
|
||||
EasyExcel.write(response.getOutputStream(), CategoryExcelVo.class).sheet("分类数据").doWrite(excelVoArrayList);
|
||||
} catch (IOException exception) {
|
||||
log.error("文件写入失败:{}", exception.getMessage());
|
||||
throw new BunnyException(ResultCodeEnum.WRITE_FILE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入功能
|
||||
*
|
||||
* @param file Excel文件
|
||||
*/
|
||||
@Override
|
||||
public void importData(MultipartFile file) {
|
||||
// 创建监听器对象,传递mapper对象
|
||||
CategoryExcelListener<CategoryExcelVo> listener = new CategoryExcelListener<>(categoryMapper);
|
||||
// 调用read方法读取excel数据
|
||||
try {
|
||||
EasyExcel.read(file.getInputStream(), CategoryExcelVo.class, listener).sheet().doRead();
|
||||
} catch (IOException e) {
|
||||
throw new BunnyException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.manger.properties.MinioProperties;
|
||||
import com.atguigu.spzx.manger.service.FileUploadService;
|
||||
import io.minio.BucketExistsArgs;
|
||||
import io.minio.MakeBucketArgs;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.PutObjectArgs;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FileUploadServiceImpl implements FileUploadService {
|
||||
@Autowired
|
||||
MinioClient minioClient;
|
||||
@Autowired
|
||||
private MinioProperties minioProperties;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file 上传的文件
|
||||
* @return file的地址
|
||||
*/
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file) {
|
||||
String bucketName = minioProperties.getBucketName();
|
||||
String dir = DateUtil.format(new Date(), "yyyy-MM-dd");
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String filename = dir + "/" + uuid + "-" + file.getOriginalFilename();
|
||||
|
||||
try {
|
||||
boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||
// 判断桶是否存在
|
||||
if (!bucketExists) {
|
||||
log.warn("minio桶不存在:{}", bucketName);
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
}
|
||||
|
||||
minioClient.putObject(PutObjectArgs.builder().bucket(bucketName)
|
||||
.stream(file.getInputStream(), file.getSize(), -1)
|
||||
.object(filename).build());
|
||||
|
||||
return minioProperties.getEndpointUrl() + "/" + minioProperties.getBucketName() + "/" + filename;
|
||||
} catch (Exception exception) {
|
||||
throw new BunnyException(exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue