diff --git a/README.md b/README.md index e367d50..c0ee744 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -# market +# 线上营销管理平台——说明 + + +``` +获取代码后,将数据库指向自己团队的数据库。 +12312311 +``` \ No newline at end of file diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..a2a3040 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,31 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/mvnw b/backend/mvnw new file mode 100644 index 0000000..a16b543 --- /dev/null +++ b/backend/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/backend/mvnw.cmd b/backend/mvnw.cmd new file mode 100644 index 0000000..c8d4337 --- /dev/null +++ b/backend/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/backend/pom.xml b/backend/pom.xml new file mode 100644 index 0000000..b34a42a --- /dev/null +++ b/backend/pom.xml @@ -0,0 +1,198 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.2.RELEASE + + + com.universe + marketing-mgt + 0.0.1-SNAPSHOT + marketing + Demo project for Spring Boot + + + 1.8 + 1.8 + 1.2.70 + 2.2.0.RELEASE + + + + + + com.github.pagehelper + pagehelper + 5.1.10 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.apache.commons + commons-lang3 + 3.4 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.apache.shiro + shiro-core + 1.7.1 + + + io.jsonwebtoken + jjwt + 0.9.1 + + + + com.baomidou + mybatis-plus-extension + 3.4.0 + + + com.baomidou + mybatis-plus-boot-starter + 3.0.5 + + + org.postgresql + postgresql + ${postgresql.version} + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + + + + com.alibaba + fastjson + ${fastjson.version} + + + junit + junit + test + + + + com.google.code.gson + gson + 2.8.2 + + + commons-io + commons-io + 2.4 + + + + + com.thoughtworks.xstream + xstream + 1.4.10 + + + + org.dom4j + dom4j + 2.0.0 + + + org.apache.poi + poi + 4.1.2 + + + + cn.hutool + hutool-all + 5.7.4 + + + javax.persistence + persistence-api + 1.0.2 + provided + + + + + + + + + src/main/java + + **/*.xml + + + + src/main/resources + + **/* + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/backend/src/main/java/com/universe/MarketingMgtApplication.java b/backend/src/main/java/com/universe/MarketingMgtApplication.java new file mode 100644 index 0000000..37a8020 --- /dev/null +++ b/backend/src/main/java/com/universe/MarketingMgtApplication.java @@ -0,0 +1,16 @@ +package com.universe; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; + + +@SpringBootApplication//(scanBasePackages = {"com.universe"}) +@MapperScan("com.universe.marketing.*.mapper") +public class MarketingMgtApplication { + public static void main(String[] args) { + SpringApplication.run(MarketingMgtApplication.class, args); + } +} diff --git a/backend/src/main/java/com/universe/aop/LogAspect.java b/backend/src/main/java/com/universe/aop/LogAspect.java new file mode 100644 index 0000000..8ad6d79 --- /dev/null +++ b/backend/src/main/java/com/universe/aop/LogAspect.java @@ -0,0 +1,94 @@ +package com.universe.aop; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; +import java.util.Optional; + +/** + * @author yuanjs + * @description: + * @date 2020-04-08 11:30 + */ +@Slf4j +@Aspect +@Component +public class LogAspect { + + + + @Pointcut("@annotation(io.swagger.annotations.ApiOperation)") + public void pointCut() { + //定义切点 + } + +// /** +// * 发送日志 +// * @param logStr +// */ +// private void sendLog(String cookies,String logStr) { +// new Thread(() -> { +// try { +// Map ck=HttpUtil.cookieToMap(cookies); +// HashMap hash = new HashMap<>(); +// hash.put("userName", hash.get("username")); +// hash.put("projectId", hash.get("projectid")); +// hash.put("content", logStr); +// HttpUtil.sendPostRequest(url, hash); +// } catch (Exception ex) { +// log.error("LogAspect中向远程发送日志失败"); +// } +// }).start(); +// } + + + @Before("pointCut()") + public void before(JoinPoint joinPoint) { + try { + + RequestAttributes ra = RequestContextHolder.getRequestAttributes(); + + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + HttpServletRequest request = (HttpServletRequest) ra.resolveReference(RequestAttributes.REFERENCE_REQUEST); + String cookiesStr = request.getHeader("Cookie"); + if (!StringUtils.isEmpty(cookiesStr)) { + log.info(cookiesStr); + } + //处理cookies + + Api api = method.getDeclaringClass().getAnnotation(Api.class); + String apiValue = "", operationValue = ""; + if (api != null) { + apiValue = api.value(); + } + ApiOperation operation = method.getAnnotation(ApiOperation.class); + if (operation != null) { + operationValue = operation.value(); + } + + String logContent = String.format("%s-%s", apiValue, operationValue); + log.info(logContent); + + } catch (Exception ex) { + log.error("LogAspect采集日志发生错误"); + log.error(ex.getMessage(), ex); + } + } +} diff --git a/backend/src/main/java/com/universe/config/DirtyDataRunnerImpl.java b/backend/src/main/java/com/universe/config/DirtyDataRunnerImpl.java new file mode 100644 index 0000000..f6f4a41 --- /dev/null +++ b/backend/src/main/java/com/universe/config/DirtyDataRunnerImpl.java @@ -0,0 +1,23 @@ +package com.universe.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * @author yuanjs + * @description: + * @date 2020-06-22 8:04 + */ +@Slf4j +@Component +@Order(value = 1) +public class DirtyDataRunnerImpl implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + log.debug("SpringBoot启动后执行……"); + + } +} diff --git a/backend/src/main/java/com/universe/config/InterceptorConfig.java b/backend/src/main/java/com/universe/config/InterceptorConfig.java new file mode 100644 index 0000000..6bd2fd7 --- /dev/null +++ b/backend/src/main/java/com/universe/config/InterceptorConfig.java @@ -0,0 +1,24 @@ +package com.universe.config; + +import com.universe.config.Login.LoginInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 登录拦截器 + */ +@Configuration +public class InterceptorConfig implements WebMvcConfigurer { +// @Override +// public void addInterceptors(InterceptorRegistry registry) { +// registry.addInterceptor(LoginInterceptor()) +// .addPathPatterns("/**") +// .excludePathPatterns("/login"); +// } + @Bean + public LoginInterceptor LoginInterceptor(){ + return new LoginInterceptor(); + } +} diff --git a/backend/src/main/java/com/universe/config/Login/LoginInterceptor.java b/backend/src/main/java/com/universe/config/Login/LoginInterceptor.java new file mode 100644 index 0000000..130953d --- /dev/null +++ b/backend/src/main/java/com/universe/config/Login/LoginInterceptor.java @@ -0,0 +1,29 @@ +package com.universe.config.Login; + + +import com.universe.marketing.users.entity.Users; +import com.universe.marketing.users.mapper.UsersMapper; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.HandlerInterceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class LoginInterceptor implements HandlerInterceptor { + @Autowired + private UsersMapper usersMapper; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + String name = request.getHeader("name"); + if (StringUtils.isBlank(name)) { + return false; + } + Users users = usersMapper.selectByUsername(name); + if (users == null) { + return false; + } + return true; + } +} diff --git a/backend/src/main/java/com/universe/config/MPConfig.java b/backend/src/main/java/com/universe/config/MPConfig.java new file mode 100644 index 0000000..3241b2e --- /dev/null +++ b/backend/src/main/java/com/universe/config/MPConfig.java @@ -0,0 +1,18 @@ +package com.universe.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class MPConfig implements WebMvcConfigurer { + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor(){ + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL)); + return interceptor; + } +} diff --git a/backend/src/main/java/com/universe/config/MybatisPlusConfig.java b/backend/src/main/java/com/universe/config/MybatisPlusConfig.java new file mode 100644 index 0000000..ecad4d3 --- /dev/null +++ b/backend/src/main/java/com/universe/config/MybatisPlusConfig.java @@ -0,0 +1,47 @@ +package com.universe.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@MapperScan("com.mapper") +@EnableTransactionManagement //自动管理实务,默认开启 +@Configuration //配置类 +public class MybatisPlusConfig { + //注册乐观锁插件 + @Bean + public OptimisticLockerInterceptor optimisticLockerInterceptor(){ + return new OptimisticLockerInterceptor(); + } + +/* //分页插件 + @Bean + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + }*/ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor(){ + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return interceptor; + } + +/* //逻辑删除组件 + @Bean + public ISqlInjector sqlInjector(){ + return new LogicSqlInjector(); + } + + @Bean + @Profile({"dev","test"})//设置dev,test环境开启, 保证我们的效率 + public PerformanceInterceptor performanceInterceptor(){ + PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor(); + performanceInterceptor.setMaxTime(1000);//设置sql执行的最大时间,如果超过就不执行(单位:毫秒ms) + performanceInterceptor.setFormat(true);//开启格式化支持 + return performanceInterceptor; + }*/ +} diff --git a/backend/src/main/java/com/universe/config/Swagger2Config.java b/backend/src/main/java/com/universe/config/Swagger2Config.java new file mode 100644 index 0000000..143b44f --- /dev/null +++ b/backend/src/main/java/com/universe/config/Swagger2Config.java @@ -0,0 +1,49 @@ +package com.universe.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + + +@Configuration +@EnableSwagger2 +public class Swagger2Config { + /** + * 用于配置swagger2,包含文档基本信息 + * 指定swagger2的作用域(这里指定包路径下的所有API) + * @return Docket + */ + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + //指定需要扫描的controller + .apis(RequestHandlerSelectors.basePackage("com.universe.marketing")) + .paths(PathSelectors.any()) + .build(); + } + + /** + * 构建文档基本信息,用于页面显示,可以包含版本、 + * 联系人信息、服务地址、文档描述信息等 + * @return ApiInfo + */ + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + //标题 + .title("线上营销管理平台后端服务API说明文档") + .description("通过访问swagger-ui.html,实现接口测试、文档生成") + .termsOfServiceUrl("http://localhost:8080") + //设置联系方式 + .contact(new Contact("Lordinloft Universe Origin", "https://blog.csdn.net/p_programmer", "lordinloft@163.com")) + .version("1.0").build(); + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/universe/handler/AllExceptionHandler.java b/backend/src/main/java/com/universe/handler/AllExceptionHandler.java new file mode 100644 index 0000000..d0df2fa --- /dev/null +++ b/backend/src/main/java/com/universe/handler/AllExceptionHandler.java @@ -0,0 +1,20 @@ +package com.universe.handler; + + +import com.universe.marketing.product.pojo.vo.Result; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + + +//对加了@Controller 注解的方法进行拦截处理 AOP实现 +@ControllerAdvice +public class AllExceptionHandler { + //进行异常处理,处理Exception。class异常 + @ResponseBody + @ExceptionHandler(Exception.class) + public Result doException(Exception ex){ + ex.printStackTrace(); + return Result.fail("系统内部异常!"); + } +} diff --git a/backend/src/main/java/com/universe/handler/BusinessException.java b/backend/src/main/java/com/universe/handler/BusinessException.java new file mode 100644 index 0000000..db924a7 --- /dev/null +++ b/backend/src/main/java/com/universe/handler/BusinessException.java @@ -0,0 +1,14 @@ +package com.universe.handler; + +/** + * @author yuanjs + * @description: + * @date 2019-11-23 20:14 + */ +public class BusinessException extends RuntimeException { + + public BusinessException(String message) { + super(message); + } + +} \ No newline at end of file diff --git a/backend/src/main/java/com/universe/handler/ErrorInfo.java b/backend/src/main/java/com/universe/handler/ErrorInfo.java new file mode 100644 index 0000000..f4a0eb2 --- /dev/null +++ b/backend/src/main/java/com/universe/handler/ErrorInfo.java @@ -0,0 +1,20 @@ +package com.universe.handler; + +import lombok.Data; + +/** + * @author yuanjs + * @description: + * @date 2019-11-23 20:13 + */ +@Data +public class ErrorInfo { + + public static final Integer OK = 0; + public static final Integer ERROR = 500; + private String errorType; + private Integer code; + private String message; + private String url; + private T exception; +} diff --git a/backend/src/main/java/com/universe/handler/GlobalExceptionHandler.java b/backend/src/main/java/com/universe/handler/GlobalExceptionHandler.java new file mode 100644 index 0000000..55920fc --- /dev/null +++ b/backend/src/main/java/com/universe/handler/GlobalExceptionHandler.java @@ -0,0 +1,15 @@ +package com.universe.handler; + +import com.universe.marketing.users.entity.Utils.R; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +@ControllerAdvice +public class GlobalExceptionHandler { + @ExceptionHandler(BusinessException.class) + @ResponseBody + public R handle(BusinessException be){ + return R.fail(be.getMessage()); + } +} diff --git a/backend/src/main/java/com/universe/marketing/client/controller/ClientController.java b/backend/src/main/java/com/universe/marketing/client/controller/ClientController.java new file mode 100644 index 0000000..f1062ae --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/controller/ClientController.java @@ -0,0 +1,50 @@ +package com.universe.marketing.client.controller; + +import com.github.pagehelper.PageInfo; +import com.universe.marketing.client.pojo.dto.ClientDto; +import com.universe.marketing.client.pojo.entity.ClientEntity; +import com.universe.marketing.client.pojo.vo.Result; +import com.universe.marketing.client.service.ClientService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + + +@Api(value = "客户信息管理",tags = {"客户信息管理"}) +@RestController +@RequestMapping("/client") +public class ClientController { + @Autowired + private ClientService clientService; + @ApiOperation(value = "分页查询客户信息") + @PostMapping("/select") + public PageInfo query( + @RequestParam(defaultValue = "1") int pageNum, + @RequestParam(defaultValue = "#{T(java.lang.Integer).MAX_VALUE}") int pageSize) { + return clientService.query(pageNum, pageSize); + } + + @ApiOperation(value = "添加客户信息") + @PostMapping("/add") + public Result insertClient(ClientDto clientDto){ + return clientService.insertClient(clientDto); + } + @ApiOperation(value = "修改客户信息") + @PostMapping("/update") + public Result updateClient(ClientDto clientDto){ + Result flag = clientService.updateClient(clientDto); + return flag; + } + @ApiOperation(value = "删除客户信息") + @PostMapping("/delete") + public Result deleteClient(String clientId){ + Result flag = clientService.deleteClient(clientId); + return flag; + } + @ApiOperation(value = "查询客户信息") + @GetMapping("/query") + public ClientEntity selectClient(String clientId){ + return clientService.selectClient(clientId); + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/universe/marketing/client/mapper/ClientMapper.java b/backend/src/main/java/com/universe/marketing/client/mapper/ClientMapper.java new file mode 100644 index 0000000..6856f52 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/mapper/ClientMapper.java @@ -0,0 +1,13 @@ +package com.universe.marketing.client.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.client.pojo.entity.ClientEntity; +import org.springframework.stereotype.Repository; + + + +@Repository + +public interface ClientMapper extends BaseMapper { +} diff --git a/backend/src/main/java/com/universe/marketing/client/pojo/dto/ClientDto.java b/backend/src/main/java/com/universe/marketing/client/pojo/dto/ClientDto.java new file mode 100644 index 0000000..349b9b7 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/pojo/dto/ClientDto.java @@ -0,0 +1,19 @@ +package com.universe.marketing.client.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 数据传输对象 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ClientDto { + private String clientId; + private String clientName; + private String clientPhone; + private String clientAddress; +} + diff --git a/backend/src/main/java/com/universe/marketing/client/pojo/entity/ClientEntity.java b/backend/src/main/java/com/universe/marketing/client/pojo/entity/ClientEntity.java new file mode 100644 index 0000000..5591344 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/pojo/entity/ClientEntity.java @@ -0,0 +1,19 @@ +package com.universe.marketing.client.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +/** + * 实体类 + */ +@Data +@TableName("client_manage") +public class ClientEntity { + @TableId + private String clientId; + private String clientName; + private String clientPhone; + private String clientAddress; + +} diff --git a/backend/src/main/java/com/universe/marketing/client/pojo/vo/ClientVo.java b/backend/src/main/java/com/universe/marketing/client/pojo/vo/ClientVo.java new file mode 100644 index 0000000..1ce6c5b --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/pojo/vo/ClientVo.java @@ -0,0 +1,14 @@ +package com.universe.marketing.client.pojo.vo; + +import lombok.Data; + +/** + * 视图对象 + */ +@Data +public class ClientVo { + private String clientId; + private String clientName; + private String clientPhone; + private String clientAddress; +} diff --git a/backend/src/main/java/com/universe/marketing/client/pojo/vo/Result.java b/backend/src/main/java/com/universe/marketing/client/pojo/vo/Result.java new file mode 100644 index 0000000..05314b5 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/pojo/vo/Result.java @@ -0,0 +1,64 @@ +package com.universe.marketing.client.pojo.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 返回的结果集 + */ +@Data +public class Result implements Serializable { + private int code; //200成功, 400失败 + private String msg; + private Object data; + + + public static Result success() { + return success(200, "操作成功!", null); + } + + public static Result success(String msg) { + return success(200, msg, null); + } + + public static Result success(Object data) { + return success(200, "操作成功!", data); + } + + public static Result success(String msg, Object data) { + return success(200, msg, data); + } + + public static Result success(int code, String msg, Object data) { + Result r = new Result(); + r.setCode(code); + r.setMsg(msg); + r.setData(data); + return r; + } + + public static Result fail() { + return success(400, "操作失败!", null); + } + + public static Result fail(Object data) { + return fail(400, "操作失败!", data); + } + + public static Result fail(String msg) { + return fail(400, msg, null); + } + + public static Result fail(String msg, Object data) { + return fail(400, msg, data); + } + + public static Result fail(int code, String msg, Object data) { + Result r = new Result(); + r.setCode(code); + r.setMsg(msg); + r.setData(data); + return r; + } +} diff --git a/backend/src/main/java/com/universe/marketing/client/service/ClientService.java b/backend/src/main/java/com/universe/marketing/client/service/ClientService.java new file mode 100644 index 0000000..6e80f1e --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/service/ClientService.java @@ -0,0 +1,20 @@ +package com.universe.marketing.client.service; + +import com.github.pagehelper.PageInfo; +import com.universe.marketing.client.pojo.dto.ClientDto; +import com.universe.marketing.client.pojo.entity.ClientEntity; +import com.universe.marketing.client.pojo.vo.Result; + + +public interface ClientService { + //添加客户信息 + Result insertClient(ClientDto clientDto); + //删除客户信息 + Result deleteClient(String clientId); + //修改客户信息 + Result updateClient(ClientDto clientDto); + //分页查询 + PageInfo query(int pageNum, int pageSize); + //查询客户信息 + ClientEntity selectClient(String clientId); +} diff --git a/backend/src/main/java/com/universe/marketing/client/service/impl/ClientServiceImpl.java b/backend/src/main/java/com/universe/marketing/client/service/impl/ClientServiceImpl.java new file mode 100644 index 0000000..2cab95d --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/client/service/impl/ClientServiceImpl.java @@ -0,0 +1,73 @@ +package com.universe.marketing.client.service.impl; + + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.universe.marketing.client.mapper.ClientMapper; +import com.universe.marketing.client.pojo.dto.ClientDto; +import com.universe.marketing.client.pojo.entity.ClientEntity; +import com.universe.marketing.client.pojo.vo.Result; +import com.universe.marketing.client.service.ClientService; +import com.universe.utils.*; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ClientServiceImpl implements ClientService { + @Autowired + private ClientMapper clientMapper; + + @Override + public Result insertClient(ClientDto clientDto) { + ClientEntity clientEntity = new ClientEntity(); + BeanUtils.copyProperties(clientDto,clientEntity); + clientEntity.setClientId(UUIDUtils.generateId()); + if(clientMapper.insert(clientEntity)>0){ + return Result.success("客户信息添加成功"); + }return Result.fail("客户信息添加失败"); + } + + @Override + public Result deleteClient(String clientId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ClientEntity::getClientId,clientId); + int id = clientMapper.delete(wrapper); + if(id>0){ + return Result.success("客户信息删除成功"); + }return Result.fail("客户信息删除失败"); + } + + @Override + public Result updateClient(ClientDto clientDto) { + + String id = clientDto.getClientId(); + ClientEntity client = new ClientEntity(); + client.setClientId(id); + BeanUtils.copyProperties(clientDto,client); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ClientEntity::getClientId, id); + + if(clientMapper.update(client, wrapper)>0){ + return Result.success("客户信息修改成功"); + }return Result.fail("客户信息修改失败"); + } + + + @Override + public PageInfo query(int pageNum, int pageSize) { + PageHelper.startPage(pageNum, pageSize); + return new PageInfo(clientMapper.selectList(null)); + } + + @Override + public ClientEntity selectClient(String clientId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ClientEntity::getClientId,clientId); + return clientMapper.selectOne(wrapper); + } + +} + + diff --git a/backend/src/main/java/com/universe/marketing/login/controller/LoginController.java b/backend/src/main/java/com/universe/marketing/login/controller/LoginController.java new file mode 100644 index 0000000..b15eff7 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/controller/LoginController.java @@ -0,0 +1,40 @@ +package com.universe.marketing.login.controller; + +import com.universe.marketing.login.pojo.dto.LoginDto; +import com.universe.marketing.login.service.LoginService; +import com.universe.marketing.product.pojo.vo.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@CrossOrigin +@RestController +@Api(value = "登录",tags = {"登录"}) +public class LoginController { + @Autowired + LoginService loginService; + + @ApiOperation(value = "登录") + @PostMapping("/login") + public Result login(@RequestBody LoginDto loginDto){ + return loginService.login(loginDto); + } + + @ApiOperation(value = "退出登录") + @GetMapping("loginOut") + public Result logout(@RequestHeader("Authorization") String token){ + return loginService.loginOut(token); + } + + /** + * 获取用户信息 + * @param token (头部信息) + * @return + */ + @ApiOperation(value = "获取用户信息") + @PostMapping("/user/current") + public Result currentUser(@RequestHeader("Authorization") String token){ + return loginService.findUserByToken(token); + } +} diff --git a/backend/src/main/java/com/universe/marketing/login/mapper/UserMapper.java b/backend/src/main/java/com/universe/marketing/login/mapper/UserMapper.java new file mode 100644 index 0000000..b87c96a --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/mapper/UserMapper.java @@ -0,0 +1,9 @@ +package com.universe.marketing.login.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.login.pojo.po.User; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserMapper extends BaseMapper { +} diff --git a/backend/src/main/java/com/universe/marketing/login/pojo/dto/LoginDto.java b/backend/src/main/java/com/universe/marketing/login/pojo/dto/LoginDto.java new file mode 100644 index 0000000..563f6a0 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/pojo/dto/LoginDto.java @@ -0,0 +1,14 @@ +package com.universe.marketing.login.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class LoginDto { + private String username; + private String password; +} diff --git a/backend/src/main/java/com/universe/marketing/login/pojo/dto/RegisterDto.java b/backend/src/main/java/com/universe/marketing/login/pojo/dto/RegisterDto.java new file mode 100644 index 0000000..9e22bd5 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/pojo/dto/RegisterDto.java @@ -0,0 +1,4 @@ +package com.universe.marketing.login.pojo.dto; + +public class RegisterDto { +} diff --git a/backend/src/main/java/com/universe/marketing/login/pojo/po/User.java b/backend/src/main/java/com/universe/marketing/login/pojo/po/User.java new file mode 100644 index 0000000..ce4e93f --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/pojo/po/User.java @@ -0,0 +1,18 @@ +package com.universe.marketing.login.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +@TableName("users") +public class User { + private String id; + private String enabled; + private String name; + private String password; + private long telNumber; + private String realName; + private String roleName; +} diff --git a/backend/src/main/java/com/universe/marketing/login/service/Impl/LoginServiceImpl.java b/backend/src/main/java/com/universe/marketing/login/service/Impl/LoginServiceImpl.java new file mode 100644 index 0000000..ddf8d2d --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/service/Impl/LoginServiceImpl.java @@ -0,0 +1,94 @@ +package com.universe.marketing.login.service.Impl; + + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.universe.marketing.login.mapper.UserMapper; +import com.universe.marketing.login.pojo.dto.LoginDto; +import com.universe.marketing.login.pojo.po.User; +import com.universe.marketing.login.service.LoginService; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.utils.ChUtils.JWTUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +@Service +@Transactional //事务回滚 理应加载接口类上 这里只有一个实现类 +public class LoginServiceImpl implements LoginService { + @Autowired + UserMapper userMapper; + @Autowired + private RedisTemplate redisTemplate; + + private static final String slat = "chh!@#"; + + @Override + public Result login(LoginDto loginDto) { + if(StringUtils.isBlank(loginDto.getUsername()) || StringUtils.isBlank(loginDto.getUsername())){ + return Result.fail("用户名或密码为空"); + } + //String password = DigestUtils.md5Hex(loginDto.getPassword() + slat); + User existUser = isExistUser(loginDto.getUsername(), loginDto.getPassword()); + if(existUser==null) { + return new Result().fail("用户名或密码错误"); + } + String token = JWTUtils.createToken(existUser.getId()); + redisTemplate.opsForValue().set("TOKEN_" + token, JSON.toJSONString(existUser), 1, TimeUnit.DAYS); + return Result.succ("登录成功!", token); + } + + /** + * 检擦用户名密码是否正确 + * @param username + * @param password + * @return + */ + private User isExistUser(String username, String password) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(User::getName, username); + wrapper.eq(User::getPassword, password); + return userMapper.selectOne(wrapper); + } + + @Override + public Result loginOut(String token) { + redisTemplate.delete("TOKEN_" + token); + return Result.succ("成功退出!"); + } + + @Override + public Result findUserByToken(String token) { + User user = checkToken(token); + if(user!=null){ + return Result.succ(user); + } + return Result.fail(); + } + + /** + * 检查token是否正确 + * @param token + * @return + */ + public User checkToken(String token) { + //验证Token + if(StringUtils.isBlank(token)){//是否为空 + return null; + } + Map stringObjectMap = JWTUtils.checkToken(token); + if(stringObjectMap == null){ + return null; + } + String userJson = redisTemplate.opsForValue().get("TOKEN_" + token); + if(StringUtils.isBlank(userJson)){ + return null; + } + User user = JSON.parseObject(userJson, User.class); + return user; + } +} diff --git a/backend/src/main/java/com/universe/marketing/login/service/LoginService.java b/backend/src/main/java/com/universe/marketing/login/service/LoginService.java new file mode 100644 index 0000000..36460ad --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/login/service/LoginService.java @@ -0,0 +1,10 @@ +package com.universe.marketing.login.service; + +import com.universe.marketing.login.pojo.dto.LoginDto; +import com.universe.marketing.product.pojo.vo.Result; + +public interface LoginService { + Result login(LoginDto loginDto); + Result loginOut(String token); + Result findUserByToken(String token); +} diff --git a/backend/src/main/java/com/universe/marketing/product/controller/ProductController.java b/backend/src/main/java/com/universe/marketing/product/controller/ProductController.java new file mode 100644 index 0000000..d4e6f86 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/controller/ProductController.java @@ -0,0 +1,51 @@ +package com.universe.marketing.product.controller; + +import com.universe.marketing.product.mapper.ProductMapper; +import com.universe.marketing.product.pojo.dto.PageParamDto; +import com.universe.marketing.product.pojo.dto.ProductDto; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.product.service.Impl.ProductServiceImpl; +import com.universe.marketing.product.service.ProductService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@CrossOrigin +@RestController +@RequestMapping("/product") +@Api(value = "产品管理",tags = {"产品管理"}) +public class ProductController { + @Autowired + private ProductService productService; + + @ApiOperation(value = "添加产品") + @PostMapping("/add") + public Result addProduct(@RequestBody ProductDto productDto){ + return productService.addProduct(productDto); + } + + @ApiOperation(value = "修改产品信息") + @PostMapping("/update") + public Result updateProduct(@RequestBody ProductDto productDto){ + return productService.updateProduct(productDto); + } + + @ApiOperation(value = "删除产品信息") + @PostMapping("/del/{productId}") + public Result delProduct(@PathVariable("productId") String productId){ + return productService.delProductById(productId); + } + + @ApiOperation(value = "查询产品名称和种类列表") + @GetMapping("/list") + public Result queryList(){ + return Result.succ(productService.queryProductList()); + } + + @ApiOperation(value = "分页查询产品列表") + @PostMapping("/query/page") + public Result queryPageProductList(@RequestBody PageParamDto pageParamDto){ + return productService.queryPageProduceList(pageParamDto); + } +} diff --git a/backend/src/main/java/com/universe/marketing/product/controller/SortController.java b/backend/src/main/java/com/universe/marketing/product/controller/SortController.java new file mode 100644 index 0000000..97524ce --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/controller/SortController.java @@ -0,0 +1,38 @@ +package com.universe.marketing.product.controller; + + +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.product.service.SortService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@CrossOrigin +@RestController +@RequestMapping("sort") +@Api(value = "分类管理",tags = {"分类管理"}) +public class SortController { + + @Autowired + private SortService sortService; + + @ApiOperation(value = "添加分类") + @PostMapping("add") + public Result addSort(@RequestParam String sortName){ + return sortService.addSort(sortName); + } + + @ApiOperation(value = "删除分类") + @PostMapping("del/{sortId}") + public Result delSort(@PathVariable("sortId") String sortId){ + return sortService.delSort(sortId); + } + + @ApiOperation(value = "查询分类列表") + @GetMapping("list") + public Result allSort(){ + return sortService.queryAllSort(); + } + +} diff --git a/backend/src/main/java/com/universe/marketing/product/mapper/ProductMapper.java b/backend/src/main/java/com/universe/marketing/product/mapper/ProductMapper.java new file mode 100644 index 0000000..7ff0978 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/mapper/ProductMapper.java @@ -0,0 +1,19 @@ +package com.universe.marketing.product.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.product.pojo.po.Product; +import com.universe.marketing.product.pojo.vo.ProductShowListVo; +import com.universe.marketing.product.pojo.vo.ProductSortListVo; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ProductMapper extends BaseMapper { + //查询商品的基础信息列表 + List queryProductList(); + //根据商品名称分页模糊查询商品列表 + List queryPageProductList(int pageSize, int pageNum, String query); + //获取模糊查询的条数 total + int queryPageProductCount(String query); +} diff --git a/backend/src/main/java/com/universe/marketing/product/mapper/SortMapper.java b/backend/src/main/java/com/universe/marketing/product/mapper/SortMapper.java new file mode 100644 index 0000000..1f74ba5 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/mapper/SortMapper.java @@ -0,0 +1,9 @@ +package com.universe.marketing.product.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.product.pojo.po.Sort; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SortMapper extends BaseMapper { +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/dto/PageParamDto.java b/backend/src/main/java/com/universe/marketing/product/pojo/dto/PageParamDto.java new file mode 100644 index 0000000..6e3bfe3 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/dto/PageParamDto.java @@ -0,0 +1,11 @@ +package com.universe.marketing.product.pojo.dto; + +import lombok.Data; + +@Data +public class PageParamDto { + private int pageSize = 1;//每页显示条数 + private int pageNum = 10;//每页个数 + private String query; + +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/dto/ProductDto.java b/backend/src/main/java/com/universe/marketing/product/pojo/dto/ProductDto.java new file mode 100644 index 0000000..98f8c29 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/dto/ProductDto.java @@ -0,0 +1,24 @@ +package com.universe.marketing.product.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 接受上传的商品信息 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProductDto { + private String productId; + private String productName ; + private String productDescribe; + private Double productPricePurchase; + private Double productPriceShipment; + private Double productPriceSuggest; + private String productFormat; + private Integer state; + private String personId; + private String sortId; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/po/Product.java b/backend/src/main/java/com/universe/marketing/product/pojo/po/Product.java new file mode 100644 index 0000000..8e929be --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/po/Product.java @@ -0,0 +1,56 @@ +package com.universe.marketing.product.pojo.po; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "product_manage") +public class Product { + @TableId(type = IdType.ASSIGN_UUID) + @TableField("product_id") + private String productId; + + @TableField("product_name") + private String productName; + + @TableField("product_describe") + private String productDescribe; + + @TableField("product_price_purchase") + private Double productPricePurchase; //进价 + + @TableField("product_price_shipment") + private Double productPriceShipment;//出货价 + + @TableField("product_price_suggest") + private Double productPriceSuggest;//建议零售价 + + @TableField("product_format") + private String productFormat; + + @TableField("state") + private Integer state; + + @TableField("create_datetime") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date createDatetime; + + @TableField("update_datetime") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateDatetime; + + @TableField("person_id") + private String personId; + + @TableField("sort_id") + private String sortId; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/po/Sort.java b/backend/src/main/java/com/universe/marketing/product/pojo/po/Sort.java new file mode 100644 index 0000000..93bf3e3 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/po/Sort.java @@ -0,0 +1,18 @@ +package com.universe.marketing.product.pojo.po; + + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("product_sort") +public class Sort { + @TableId() + private String sortId; + private String sortName; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductListVo.java b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductListVo.java new file mode 100644 index 0000000..b8720a5 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductListVo.java @@ -0,0 +1,9 @@ +package com.universe.marketing.product.pojo.vo; + +import lombok.Data; + +@Data +public class ProductListVo { + private String productId; + private String productName; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductPageListVo.java b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductPageListVo.java new file mode 100644 index 0000000..6551e45 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductPageListVo.java @@ -0,0 +1,15 @@ +package com.universe.marketing.product.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProductPageListVo { + private Integer total; + private List productShowList; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductShowListVo.java b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductShowListVo.java new file mode 100644 index 0000000..4a6f334 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductShowListVo.java @@ -0,0 +1,25 @@ +package com.universe.marketing.product.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProductShowListVo { + private String productId; + private String productName; + private String productDescribe; + private Double productPricePurchase; //进价 + private Double productPriceShipment;//出货价 + private Double productPriceSuggest;//建议零售价 + private String productFormat; + private Integer state; + private Date createDatetime; + private Date updateDatetime; + private String name; + private String sortName; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductSortListVo.java b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductSortListVo.java new file mode 100644 index 0000000..bbe3069 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/vo/ProductSortListVo.java @@ -0,0 +1,13 @@ +package com.universe.marketing.product.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ProductSortListVo { + private String productName; + private Double productPricePurchase; + private String sortName; + private String productId; +} diff --git a/backend/src/main/java/com/universe/marketing/product/pojo/vo/Result.java b/backend/src/main/java/com/universe/marketing/product/pojo/vo/Result.java new file mode 100644 index 0000000..e5ebd7d --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/pojo/vo/Result.java @@ -0,0 +1,61 @@ +package com.universe.marketing.product.pojo.vo; + +import lombok.Data; + +import java.io.Serializable; + +//返回的结果集 +@Data +public class Result implements Serializable { + private int code; //200成功, 400失败 + private String msg; + private Object data; + + public static Result succ(){ + return succ(200, "操作成功!", null); + } + + public static Result succ(String msg){ + return succ(200, msg, null); + } + + public static Result succ(Object data){ + return succ(200, "操作成功!", data); + } + + public static Result succ(String msg, Object data){ + return succ(200, msg, data); + } + + public static Result succ(int code, String msg, Object data){ + Result r = new Result(); + r.setCode(code); + r.setMsg(msg); + r.setData(data); + return r; + } + + public static Result fail(){ + return succ(400, "操作失败!", null); + } + + public static Result fail(Object data){ + return fail(400, "操作失败!", data); + } + + public static Result fail(String msg){ + return fail(400, msg, null); + } + + public static Result fail(String msg, Object data){ + return fail(400, msg, data); + } + + public static Result fail(int code, String msg, Object data){ + Result r = new Result(); + r.setCode(code); + r.setMsg(msg); + r.setData(data); + return r; + } +} diff --git a/backend/src/main/java/com/universe/marketing/product/service/Impl/ProductServiceImpl.java b/backend/src/main/java/com/universe/marketing/product/service/Impl/ProductServiceImpl.java new file mode 100644 index 0000000..5e42803 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/service/Impl/ProductServiceImpl.java @@ -0,0 +1,79 @@ +package com.universe.marketing.product.service.Impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.universe.marketing.product.mapper.ProductMapper; +import com.universe.marketing.product.pojo.dto.ProductDto; +import com.universe.marketing.product.pojo.dto.PageParamDto; +import com.universe.marketing.product.pojo.po.Product; +import com.universe.marketing.product.pojo.vo.ProductPageListVo; +import com.universe.marketing.product.pojo.vo.ProductShowListVo; +import com.universe.marketing.product.pojo.vo.ProductSortListVo; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.product.service.ProductService; +import com.universe.utils.UuidUtil; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +@Service +public class ProductServiceImpl implements ProductService { + @Autowired + private ProductMapper productMapper; + + @Override + public Result addProduct(ProductDto productDto) { + Product product = new Product(); + BeanUtils.copyProperties(productDto, product); + product.setProductId(UuidUtil.getUuid()); + //添加 + if(productMapper.insert(product)>0){ + return Result.succ("商品添加成功!"); + } + return Result.fail("商品添加失败!请检查参数"); + } + + @Override + public Result delProductById(String productId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Product::getProductId, productId); + //删除 + if(productMapper.delete(wrapper)>0){ + return Result.succ("删除成功!"); + } + return Result.fail("删除失败!"); + } + + @Override + public Result updateProduct(ProductDto productDto) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Product::getProductId, productDto.getProductId()); + Product product = new Product(); + BeanUtils.copyProperties(productDto, product); + product.setUpdateDatetime(new Date()); + //修改 + if(productMapper.update(product, wrapper)>0){ + return Result.succ("商品修改成功!"); + } + return Result.fail("商品修改失败!请检查参数"); + } + + @Override + public Result queryPageProduceList(PageParamDto pageParamDto) { + //查询total + int total = productMapper.queryPageProductCount(pageParamDto.getQuery()); + //获取符合条件的商品列表 + List list = productMapper.queryPageProductList(pageParamDto.getPageNum()*(pageParamDto.getPageSize()-1), + pageParamDto.getPageNum(), + pageParamDto.getQuery()); + return Result.succ(new ProductPageListVo(total, list)); + } + + @Override + public Result queryProductList() { + List list = productMapper.queryProductList(); + return Result.succ(list); + } +} diff --git a/backend/src/main/java/com/universe/marketing/product/service/Impl/SortServiceImpl.java b/backend/src/main/java/com/universe/marketing/product/service/Impl/SortServiceImpl.java new file mode 100644 index 0000000..b1c0a37 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/service/Impl/SortServiceImpl.java @@ -0,0 +1,44 @@ +package com.universe.marketing.product.service.Impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.universe.marketing.product.mapper.SortMapper; +import com.universe.marketing.product.pojo.po.Sort; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.product.service.SortService; +import com.universe.utils.UuidUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +@Service +public class SortServiceImpl implements SortService { + + @Autowired + private SortMapper sortMapper; + + @Override + public Result addSort(String sortName) { + + Sort sort = new Sort(UuidUtil.getUuid(), sortName); + System.out.println(sort); + if(sortMapper.insert(sort)>0){ + return Result.succ("添加分类成功!"); + } + return Result.fail("添加分类失败!"); + } + + @Override + public Result delSort(String sortId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Sort::getSortId, sortId); + if(sortMapper.delete(wrapper)>0){ + return Result.succ("删除分类成功!"); + } + return Result.fail("删除分类失败!"); + } + + @Override + public Result queryAllSort() { + return Result.succ(sortMapper.selectList(null)); + } +} diff --git a/backend/src/main/java/com/universe/marketing/product/service/ProductService.java b/backend/src/main/java/com/universe/marketing/product/service/ProductService.java new file mode 100644 index 0000000..27d6bb8 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/service/ProductService.java @@ -0,0 +1,18 @@ +package com.universe.marketing.product.service; + +import com.universe.marketing.product.pojo.dto.ProductDto; +import com.universe.marketing.product.pojo.dto.PageParamDto; +import com.universe.marketing.product.pojo.vo.Result; + +public interface ProductService { + //添加商品 + Result addProduct(ProductDto productDto); + //删除商品 + Result delProductById(String productId); + //更新商品 + Result updateProduct(ProductDto productDto); + //分页查询商品 + Result queryPageProduceList(PageParamDto pageParamDto); + //查询商品的名称喝种类名称 + Result queryProductList(); +} diff --git a/backend/src/main/java/com/universe/marketing/product/service/SortService.java b/backend/src/main/java/com/universe/marketing/product/service/SortService.java new file mode 100644 index 0000000..772a387 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/product/service/SortService.java @@ -0,0 +1,12 @@ +package com.universe.marketing.product.service; + +import com.universe.marketing.product.pojo.vo.Result; + +public interface SortService { + //添加分类 + Result addSort(String sortName); + //删除分类 + Result delSort(String sortId); + //查询分类列表 + Result queryAllSort(); +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/controller/PurchaseController.java b/backend/src/main/java/com/universe/marketing/purchase/controller/PurchaseController.java new file mode 100644 index 0000000..db1dab3 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/controller/PurchaseController.java @@ -0,0 +1,52 @@ +package com.universe.marketing.purchase.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.purchase.mapper.PurchaseMapper; +import com.universe.marketing.purchase.pojo.dto.PurchaseDto; +import com.universe.marketing.purchase.pojo.dto.PurchaseSonDto; +import com.universe.marketing.purchase.pojo.dto.QueryPurchasePageDto; +import com.universe.marketing.purchase.pojo.dto.QueryPurchaseSonListDto; +import com.universe.marketing.purchase.pojo.po.Purchase; +import com.universe.marketing.purchase.service.PurchaseService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.text.ParseException; + +@CrossOrigin +@RestController +@RequestMapping("/purchase") +@Api(value = "进货管理",tags = {"进货管理"}) +public class PurchaseController { + + @Autowired + PurchaseService purchaseService; + + @PostMapping("/son/add") + @ApiOperation(value = "添加进货分表信息") + public Result addPurchaseSon(@RequestBody PurchaseSonDto purchaseSonDto){ + return purchaseService.insertPurchaseSonMsg(purchaseSonDto); + } + + @PostMapping("/add") + @ApiOperation(value = "添加进货总表信息") + public Result addPurchase(@RequestBody PurchaseDto purchaseDto){ + return purchaseService.insertPurchaseMsg(purchaseDto); + } + + @PostMapping("/son/list") + @ApiOperation(value = "根据进货总表Id查询对应信息") + public Result queryPurchaseSonList(@RequestBody QueryPurchaseSonListDto queryDto){ + return purchaseService.queryPurchaseSonById(queryDto); + } + + @PostMapping("/page/list") + @ApiOperation(value = "分页模糊查询进货总表信息") + public Result queryPurchasePageList(@RequestBody QueryPurchasePageDto queryDto) throws ParseException { + return purchaseService.queryPurchasePage(queryDto); + } + +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseMapper.java b/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseMapper.java new file mode 100644 index 0000000..db27925 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseMapper.java @@ -0,0 +1,15 @@ +package com.universe.marketing.purchase.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.purchase.pojo.po.Purchase; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface PurchaseMapper extends BaseMapper { + //分页模糊查询进货表的列表(根据开始时间和负责人 选填) + List queryPageList(int pageNum, int pageSize, String person, String beginTime); + //查询符合条件的列表个数 total + int queryPageListCount(String person, String beginTime); +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseSonMapper.java b/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseSonMapper.java new file mode 100644 index 0000000..8640623 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseSonMapper.java @@ -0,0 +1,14 @@ +package com.universe.marketing.purchase.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.purchase.pojo.po.PurchaseSon; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface PurchaseSonMapper extends BaseMapper { + //查询当前进货分表的列表 + List queryNowPurchaseSonList(List list); +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseSwapMapper.java b/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseSwapMapper.java new file mode 100644 index 0000000..9be9930 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/mapper/PurchaseSwapMapper.java @@ -0,0 +1,20 @@ +package com.universe.marketing.purchase.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.purchase.pojo.po.PurchaseSwap; +import com.universe.marketing.purchase.pojo.vo.PurchaseSonVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface PurchaseSwapMapper extends BaseMapper { + //绑定进货表和进货分表 + int insertSwap(@Param("purchaseId")String purchaseId, List list); + //通过进货表来查询进货分表的列表信息 + List queryPurchaseSonById(String purchaseId, List list, int pageNum, int pageSize); + //查询符合条件的进货子表数目 + int queryPurchaseSonCount(List purchaseIds); +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/PurchaseDto.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/PurchaseDto.java new file mode 100644 index 0000000..7fa0ec3 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/PurchaseDto.java @@ -0,0 +1,17 @@ +package com.universe.marketing.purchase.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PurchaseDto { + private String msg; + private String purchaseChargePersonId; + private List purchaseSonList; + private Double totalPrice; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/PurchaseSonDto.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/PurchaseSonDto.java new file mode 100644 index 0000000..1a2f7ce --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/PurchaseSonDto.java @@ -0,0 +1,18 @@ +package com.universe.marketing.purchase.pojo.dto; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PurchaseSonDto { + private String sort_id; + private String productId; + private Integer purchaseCount; + private String productName; + private String msg; + private Double totalPrice; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/QueryPurchasePageDto.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/QueryPurchasePageDto.java new file mode 100644 index 0000000..3f55c17 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/QueryPurchasePageDto.java @@ -0,0 +1,13 @@ +package com.universe.marketing.purchase.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class QueryPurchasePageDto { + private int pageSize = 1;//每页显示条数 + private int pageNum = 10;//每页个数 + private String person; + private String beginTime; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/QueryPurchaseSonListDto.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/QueryPurchaseSonListDto.java new file mode 100644 index 0000000..43fd366 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/dto/QueryPurchaseSonListDto.java @@ -0,0 +1,14 @@ +package com.universe.marketing.purchase.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class QueryPurchaseSonListDto { + private int pageSize = 1;//每页显示条数 + private int pageNum = 10;//每页个数 + private String purchaseId; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/po/Purchase.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/po/Purchase.java new file mode 100644 index 0000000..17260f5 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/po/Purchase.java @@ -0,0 +1,33 @@ +package com.universe.marketing.purchase.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("purchase") +public class Purchase { + @TableId + @TableField("purchase_id") + private String purchaseId; + @TableField("create_datetime") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date createDatetime; + @TableField("purchase_charge_person_id") + private String purchaseChargePersonId; + @TableField("purchase_state") + private Integer purchaseState; + @TableField("msg") + private String msg; + @TableField("total_price") + private Double totalPrice; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/po/PurchaseSon.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/po/PurchaseSon.java new file mode 100644 index 0000000..7805a34 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/po/PurchaseSon.java @@ -0,0 +1,39 @@ +package com.universe.marketing.purchase.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("purchase_sort") +public class PurchaseSon { + @TableId + @TableField("id") + private String id; + @TableField("sort_id") + private String sort_id; + @TableField("purchase_count") + Integer purchaseCount; + @TableField("purchase_state") + private Integer purchaseState; + @TableField("manage_datetime") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date manageDatetime; + @TableField("msg") + private String msg; + @TableField("total_price") + private double totalPrice; + @TableField("purchase_name") + private String purchaseName; + @TableField("product_id") + private String productId; + +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/po/PurchaseSwap.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/po/PurchaseSwap.java new file mode 100644 index 0000000..9ca2a26 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/po/PurchaseSwap.java @@ -0,0 +1,20 @@ +package com.universe.marketing.purchase.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("purchase_swap") +public class PurchaseSwap { + @TableId + @TableField("id") + private String id; + @TableField("purchase_id") + private String purchaseId; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseListVo.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseListVo.java new file mode 100644 index 0000000..ec2c523 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseListVo.java @@ -0,0 +1,16 @@ +package com.universe.marketing.purchase.pojo.vo; + +import com.universe.marketing.purchase.pojo.po.Purchase; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@AllArgsConstructor +@Data +@NoArgsConstructor +public class PurchaseListVo { + private Integer total; + private List pageList; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchasePageListVo.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchasePageListVo.java new file mode 100644 index 0000000..d5c85ba --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchasePageListVo.java @@ -0,0 +1,22 @@ +package com.universe.marketing.purchase.pojo.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PurchasePageListVo { + private String purchaseId; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date createDatetime; + private String name; + private Integer purchaseState; + private String msg; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseSonPageVo.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseSonPageVo.java new file mode 100644 index 0000000..99fbc3c --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseSonPageVo.java @@ -0,0 +1,15 @@ +package com.universe.marketing.purchase.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PurchaseSonPageVo { + private Integer total; + List purchaseSonList; +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseSonVo.java b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseSonVo.java new file mode 100644 index 0000000..c8006f7 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/pojo/vo/PurchaseSonVo.java @@ -0,0 +1,24 @@ +package com.universe.marketing.purchase.pojo.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Date; + +@Data +@AllArgsConstructor +public class PurchaseSonVo { + private String id; + private String sortName; + private Integer purchaseCount; + private Integer purchaseState; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date manageDatetime; + private String msg; + private String purchaseName; + private double totalPrice; + +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/service/Impl/PurchaseServiceImpl.java b/backend/src/main/java/com/universe/marketing/purchase/service/Impl/PurchaseServiceImpl.java new file mode 100644 index 0000000..c57a931 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/service/Impl/PurchaseServiceImpl.java @@ -0,0 +1,134 @@ +package com.universe.marketing.purchase.service.Impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.purchase.mapper.PurchaseMapper; +import com.universe.marketing.purchase.mapper.PurchaseSonMapper; +import com.universe.marketing.purchase.mapper.PurchaseSwapMapper; +import com.universe.marketing.purchase.pojo.dto.PurchaseDto; +import com.universe.marketing.purchase.pojo.dto.PurchaseSonDto; +import com.universe.marketing.purchase.pojo.dto.QueryPurchasePageDto; +import com.universe.marketing.purchase.pojo.dto.QueryPurchaseSonListDto; +import com.universe.marketing.purchase.pojo.po.Purchase; +import com.universe.marketing.purchase.pojo.po.PurchaseSon; +import com.universe.marketing.purchase.pojo.po.PurchaseSwap; +import com.universe.marketing.purchase.pojo.vo.PurchaseListVo; +import com.universe.marketing.purchase.pojo.vo.PurchaseSonPageVo; +import com.universe.marketing.purchase.pojo.vo.PurchaseSonVo; +import com.universe.marketing.purchase.service.PurchaseService; +import com.universe.marketing.store.mapper.ProductStoreMapper; +import com.universe.utils.BeanUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +@Service +public class PurchaseServiceImpl implements PurchaseService { + + @Autowired + PurchaseMapper purchaseMapper; + @Autowired + PurchaseSonMapper purchaseSonMapper; + @Autowired + PurchaseSwapMapper purchaseSwapMapper; + @Autowired + ProductStoreMapper productStoreMapper; + @Override + public Result insertPurchaseSonMsg(PurchaseSonDto purchaseSonDto) { + PurchaseSon purchaseSon = new PurchaseSon(); + BeanUtil.copyNotNullBean(purchaseSonDto, purchaseSon); + purchaseSon.setId(UUID.randomUUID().toString()); + purchaseSon.setPurchaseName(purchaseSonDto.getProductName()); + if(purchaseSonMapper.insert(purchaseSon)>0){ + return Result.succ("进货分表添加成功!", purchaseSon.getId()); + } + return Result.fail("进货分表添加失败!"); + } + + @Override + @Transactional + public Result insertPurchaseMsg(PurchaseDto purchaseDto) { + double total = 0; + Purchase purchase = new Purchase(); + BeanUtil.copyNotNullBean(purchaseDto, purchase); + purchase.setPurchaseId(UUID.randomUUID().toString()); + //获取子项的id列表 + List purchaseSonList = purchaseDto.getPurchaseSonList(); + + + //取得当前上传中的进货子项列表product_id, purchase_count, total_price + List list = purchaseSonMapper.queryNowPurchaseSonList(purchaseSonList); + + + //将其加入库存中,修改库存 + for(PurchaseSon data:list){ + total+=data.getTotalPrice(); + //获取当前库存product_id, purchase_count + int count = productStoreMapper.queryStoreCount(data.getProductId()); + if(productStoreMapper.updateStoreByPurchaseSon(data.getProductId(), data.getPurchaseCount()+count)<1){ + return Result.fail("修改库存失败!"); + } + } + //添加总表价格 + purchase.setTotalPrice(total); + if(purchaseMapper.insert(purchase)==0){ + return Result.fail("插入进货主表失败!"); + } + if(insertPurchaseSwap(purchase.getPurchaseId(), purchaseDto.getPurchaseSonList())==0){ + return Result.fail("绑定进货主分表信息失败!"); + } + return Result.succ("添加进货成功!"); + } + + @Override + public int insertPurchaseSwap(String purchaseId, List purchaseSonList) { + return purchaseSwapMapper.insertSwap(purchaseId, purchaseSonList); + } + + @Override + public Result queryPurchaseSonById(QueryPurchaseSonListDto queryDto) { + List purchaseIds = new ArrayList<>(); + //查询该主表下分表的id列表 + LambdaQueryWrapper swapWrapper = new LambdaQueryWrapper<>(); + swapWrapper.select(PurchaseSwap::getId); + swapWrapper.eq(PurchaseSwap::getPurchaseId, queryDto.getPurchaseId()); + List purchaseSwaps = purchaseSwapMapper.selectList(swapWrapper); + //取出分表id列表 + for(PurchaseSwap data:purchaseSwaps){ + purchaseIds.add(data.getId().trim()); + } + //根据分表id查询数据 + List list = purchaseSwapMapper.queryPurchaseSonById(queryDto.getPurchaseId(), + purchaseIds, + queryDto.getPageNum(), + queryDto.getPageNum()*(queryDto.getPageSize()-1)); + + int total = purchaseSwapMapper.queryPurchaseSonCount(purchaseIds); + return Result.succ(new PurchaseSonPageVo(total, list)); + } + + @Override + public Result queryPurchasePage(QueryPurchasePageDto queryDto) throws ParseException { + String time1 = queryDto.getBeginTime(); + /*String time=""; + Long time1=null; + if(!"".equals(queryDto.getBeginTime())){ + time = queryDto.getBeginTime(); + Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(time); + time1 = parse.getTime(); + }*/ + System.out.println(time1); + List list = purchaseMapper.queryPageList(queryDto.getPageNum(), + queryDto.getPageNum()*(queryDto.getPageSize()-1), queryDto.getPerson(), time1); + int total = purchaseMapper.queryPageListCount(queryDto.getPerson(), time1); + return Result.succ(new PurchaseListVo(total, list)); + } + +} diff --git a/backend/src/main/java/com/universe/marketing/purchase/service/PurchaseService.java b/backend/src/main/java/com/universe/marketing/purchase/service/PurchaseService.java new file mode 100644 index 0000000..d2ac8f8 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/purchase/service/PurchaseService.java @@ -0,0 +1,23 @@ +package com.universe.marketing.purchase.service; + +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.purchase.pojo.dto.PurchaseDto; +import com.universe.marketing.purchase.pojo.dto.PurchaseSonDto; +import com.universe.marketing.purchase.pojo.dto.QueryPurchasePageDto; +import com.universe.marketing.purchase.pojo.dto.QueryPurchaseSonListDto; + +import java.text.ParseException; +import java.util.List; + +public interface PurchaseService { + //上传进货分表数据 + Result insertPurchaseSonMsg(PurchaseSonDto purchaseSonDto); + //上传整体进货表的数据 + Result insertPurchaseMsg(PurchaseDto purchaseDto); + //添加进货主表和分表的关联信息 + int insertPurchaseSwap(String purchaseId, ListpurchaseSonList); + //根据主表查询对应子表的信息 + Result queryPurchaseSonById(QueryPurchaseSonListDto queryDto); + //分页查询进货总表的列表信息(根据负责人和生成时间) + Result queryPurchasePage(QueryPurchasePageDto queryDto) throws ParseException; +} diff --git a/backend/src/main/java/com/universe/marketing/store/controller/StoreController.java b/backend/src/main/java/com/universe/marketing/store/controller/StoreController.java new file mode 100644 index 0000000..3ca3ef8 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/controller/StoreController.java @@ -0,0 +1,41 @@ +package com.universe.marketing.store.controller; + +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.store.mapper.ProductStoreMapper; +import com.universe.marketing.store.pojo.dto.PageParamDto; +import com.universe.marketing.store.pojo.dto.UpdateStoreDto; +import com.universe.marketing.store.service.Impl.StoreServiceImpl; +import com.universe.marketing.store.service.StoreService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@CrossOrigin +@RestController +@RequestMapping("/store") +@Api(value = "库存管理",tags = {"库存管理"}) +public class StoreController { + @Autowired + private StoreService storeService; + @Autowired + private ProductStoreMapper storeMapper; + + @PostMapping("page/list") + @ApiOperation(value = "分页模糊查询库存列表") + public Result queryPageLikeList(@RequestBody PageParamDto pageParamDto){ + return storeService.queryPageStoreMSG(pageParamDto); + } + + @PostMapping("update") + @ApiOperation(value = "修改库存信息") + public Result updateStore(@RequestBody UpdateStoreDto updateStoreDto){ + return storeService.updateStoreMSG(updateStoreDto); + } + + @GetMapping("all") + @ApiOperation(value = "查询全部数据") + public Result queryAll(){ + return Result.succ(storeMapper.queryStoreMsg()); + } +} diff --git a/backend/src/main/java/com/universe/marketing/store/mapper/ProductStoreMapper.java b/backend/src/main/java/com/universe/marketing/store/mapper/ProductStoreMapper.java new file mode 100644 index 0000000..140bb0e --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/mapper/ProductStoreMapper.java @@ -0,0 +1,24 @@ +package com.universe.marketing.store.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.purchase.pojo.po.PurchaseSon; +import com.universe.marketing.store.pojo.po.ProductStore; +import com.universe.marketing.store.pojo.vo.StoreVo; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ProductStoreMapper extends BaseMapper { + List queryPageStoreMSG(int pageSize, int pageNum); + //分页模糊查询库存的信息列表 + List queryPageLikeStoreMSG(String query, int pageSize, int pageNum); + //查询所有 + List queryStoreMsg(); + //查询total总数 + int queryTotalStore(String query); + //更新库存的数量 + int updateStoreByPurchaseSon(String pId, Integer count); + //查询商品总数 + int queryStoreCount(String productId); +} diff --git a/backend/src/main/java/com/universe/marketing/store/pojo/dto/PageParamDto.java b/backend/src/main/java/com/universe/marketing/store/pojo/dto/PageParamDto.java new file mode 100644 index 0000000..2643238 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/pojo/dto/PageParamDto.java @@ -0,0 +1,11 @@ +package com.universe.marketing.store.pojo.dto; + +import lombok.Data; + +@Data +public class PageParamDto { + private int pageSize = 10;//每页显示条数 + private int pageNum = 0;//每页个数 + private String query; + +} diff --git a/backend/src/main/java/com/universe/marketing/store/pojo/dto/UpdateStoreDto.java b/backend/src/main/java/com/universe/marketing/store/pojo/dto/UpdateStoreDto.java new file mode 100644 index 0000000..362e542 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/pojo/dto/UpdateStoreDto.java @@ -0,0 +1,17 @@ +package com.universe.marketing.store.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class UpdateStoreDto { + private String storeId; + private String productId; + private String productName; + private Integer total; + private Integer state; + private String sortId; +} diff --git a/backend/src/main/java/com/universe/marketing/store/pojo/po/ProductStore.java b/backend/src/main/java/com/universe/marketing/store/pojo/po/ProductStore.java new file mode 100644 index 0000000..2b89bd8 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/pojo/po/ProductStore.java @@ -0,0 +1,34 @@ +package com.universe.marketing.store.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("product_store") +public class ProductStore { + @TableId + @TableField("store_id") + private String storeId; + @TableField("product_id") + String productId; + @TableField("product_name") + private String productName; + @TableField("total") + Integer total; + @TableField("update_datetime") + private Date updateDatetime; + @TableField("state") + private Integer state; + @TableField("create_datetime") + private Date create_datetime; + @TableField("sort_id") + private String sortId; +} diff --git a/backend/src/main/java/com/universe/marketing/store/pojo/vo/StoreAllVo.java b/backend/src/main/java/com/universe/marketing/store/pojo/vo/StoreAllVo.java new file mode 100644 index 0000000..892a624 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/pojo/vo/StoreAllVo.java @@ -0,0 +1,15 @@ +package com.universe.marketing.store.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class StoreAllVo { + private int total; + private List list; +} diff --git a/backend/src/main/java/com/universe/marketing/store/pojo/vo/StoreVo.java b/backend/src/main/java/com/universe/marketing/store/pojo/vo/StoreVo.java new file mode 100644 index 0000000..1d98b0d --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/pojo/vo/StoreVo.java @@ -0,0 +1,25 @@ +package com.universe.marketing.store.pojo.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class StoreVo { + private String sortName; + private String productId; + private String productName; + private Integer total; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateDatetime; + private Integer state; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date createDatetime; + private String sortId; + private String storeId; +} diff --git a/backend/src/main/java/com/universe/marketing/store/service/Impl/StoreServiceImpl.java b/backend/src/main/java/com/universe/marketing/store/service/Impl/StoreServiceImpl.java new file mode 100644 index 0000000..a10b0ee --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/service/Impl/StoreServiceImpl.java @@ -0,0 +1,51 @@ +package com.universe.marketing.store.service.Impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.store.mapper.ProductStoreMapper; +import com.universe.marketing.store.pojo.dto.PageParamDto; +import com.universe.marketing.store.pojo.dto.UpdateStoreDto; +import com.universe.marketing.store.pojo.po.ProductStore; +import com.universe.marketing.store.pojo.vo.StoreAllVo; +import com.universe.marketing.store.service.StoreService; +import com.universe.utils.BeanUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + + +@Service +public class StoreServiceImpl implements StoreService { + + @Autowired + ProductStoreMapper storeMapper; + + @Override + public Result queryPageStoreMSG(PageParamDto pageParamDto) { + StoreAllVo res = new StoreAllVo(); + //获取返回的列表 + res.setList(storeMapper.queryPageLikeStoreMSG(pageParamDto.getQuery(), + (pageParamDto.getPageSize()-1)*pageParamDto.getPageNum(), pageParamDto.getPageNum())); + //获取分页查询的total + res.setTotal(storeMapper.queryTotalStore(pageParamDto.getQuery())); + return Result.succ(res); + } + + @Override + public Result updateStoreMSG(UpdateStoreDto updateStoreDto) { + ProductStore productStore = new ProductStore(); + BeanUtil.copyNotNullBean(updateStoreDto, productStore); + //添加修改时间属性 + productStore.setUpdateDatetime(new Date()); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ProductStore::getStoreId, updateStoreDto.getStoreId()); + //修改 + if(storeMapper.update(productStore, wrapper)>0){ + return Result.succ("修改库存成功!"); + } + return Result.fail("修改库存失败!"); + } + + +} diff --git a/backend/src/main/java/com/universe/marketing/store/service/StoreService.java b/backend/src/main/java/com/universe/marketing/store/service/StoreService.java new file mode 100644 index 0000000..a01d196 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/store/service/StoreService.java @@ -0,0 +1,12 @@ +package com.universe.marketing.store.service; + +import com.universe.marketing.product.pojo.vo.Result; +import com.universe.marketing.store.pojo.dto.PageParamDto; +import com.universe.marketing.store.pojo.dto.UpdateStoreDto; + +public interface StoreService { + //分页模糊查询库存信息 + Result queryPageStoreMSG(PageParamDto pageParamDto); + //修改库存信息 + Result updateStoreMSG(UpdateStoreDto updateStoreDto); +} diff --git a/backend/src/main/java/com/universe/marketing/users/entity/Menu.java b/backend/src/main/java/com/universe/marketing/users/entity/Menu.java new file mode 100644 index 0000000..3b3d0dd --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/entity/Menu.java @@ -0,0 +1,24 @@ +package com.universe.marketing.users.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.List; + +@Data +@TableName("menu") +public class Menu { + @TableId(value = "id",type = IdType.INPUT) + private String id; + //子Id + private String pid; + private String name; + private String path; + @TableField(exist = false) + private List children; + private String description; + +} diff --git a/backend/src/main/java/com/universe/marketing/users/entity/RoleMenu.java b/backend/src/main/java/com/universe/marketing/users/entity/RoleMenu.java new file mode 100644 index 0000000..3863359 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/entity/RoleMenu.java @@ -0,0 +1,11 @@ +package com.universe.marketing.users.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("role_menu") +public class RoleMenu { + private String roleId; + private String menuId; +} diff --git a/backend/src/main/java/com/universe/marketing/users/entity/Roles.java b/backend/src/main/java/com/universe/marketing/users/entity/Roles.java new file mode 100644 index 0000000..895a907 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/entity/Roles.java @@ -0,0 +1,20 @@ +package com.universe.marketing.users.entity; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("roles") +public class Roles { + + @TableId(value = "id",type = IdType.INPUT) + private String id; + private String name; + private String keyname; + private String description; + + +} diff --git a/backend/src/main/java/com/universe/marketing/users/entity/Users.java b/backend/src/main/java/com/universe/marketing/users/entity/Users.java new file mode 100644 index 0000000..42274df --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/entity/Users.java @@ -0,0 +1,24 @@ +package com.universe.marketing.users.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + + +@Data +@TableName("users") +public class Users { + + @TableId(value = "id",type = IdType.INPUT) + private String id; + private String name; + @JsonIgnore + private String password; + private String realName; + private String telNumber; + private Integer enabled; + private String roleName; + +} \ No newline at end of file diff --git a/backend/src/main/java/com/universe/marketing/users/entity/Utils/R.java b/backend/src/main/java/com/universe/marketing/users/entity/Utils/R.java new file mode 100644 index 0000000..a3acbe2 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/entity/Utils/R.java @@ -0,0 +1,52 @@ +package com.universe.marketing.users.entity.Utils; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class R { + private Integer code; + private Object data; + private String msg; + + + public R(Integer code, Object data) { + this.code = code; + this.data = data; + } + + + public R(String msg) { + this.msg = msg; + } + + public R(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + public static R ok() { + return new R(200, null, null); + } + + public static R ok(Object data) { + return new R(200, data, null); + } + + public static R ok(String msg) { + return new R(200, null, msg); + } + public static R ok(Object data,String msg) { + return new R(200, data, msg); + } + public static R fail(String errorMsg) { + return new R(400, null, errorMsg); + } + + public static R error(Integer code, String msg) { + return new R(code, msg); + } +} diff --git a/backend/src/main/java/com/universe/marketing/users/mapper/MenuMapper.java b/backend/src/main/java/com/universe/marketing/users/mapper/MenuMapper.java new file mode 100644 index 0000000..3113e62 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/mapper/MenuMapper.java @@ -0,0 +1,8 @@ +package com.universe.marketing.users.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.users.entity.Menu; +import org.apache.ibatis.annotations.Mapper; +@Mapper +public interface MenuMapper extends BaseMapper { +} diff --git a/backend/src/main/java/com/universe/marketing/users/mapper/RoleMenuMapper.java b/backend/src/main/java/com/universe/marketing/users/mapper/RoleMenuMapper.java new file mode 100644 index 0000000..ddda05a --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/mapper/RoleMenuMapper.java @@ -0,0 +1,18 @@ +package com.universe.marketing.users.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.users.entity.RoleMenu; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import java.util.List; + +@Mapper +public interface RoleMenuMapper extends BaseMapper { + @Select("select menu_id from role_menu where role_id = #{roleId}") + List selectByRoleId(@Param("roleId") String roleId); + + @Delete("delete from role_menu where role_id=#{roleId}") + int deleteByRoleId(@Param("roleId") String roleId); +} diff --git a/backend/src/main/java/com/universe/marketing/users/mapper/RolesMapper.java b/backend/src/main/java/com/universe/marketing/users/mapper/RolesMapper.java new file mode 100644 index 0000000..93e0898 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/mapper/RolesMapper.java @@ -0,0 +1,21 @@ +package com.universe.marketing.users.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.users.entity.Roles; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + + +import java.util.List; + +/** + * @author yuanjs + * @description: + * @date 2020-04-02 19:19 + */ +@Mapper +public interface RolesMapper extends BaseMapper { + @Select("select id from roles where keyname = #{keyname}") + String selectByRoleName(@Param("keyname") String role); +} diff --git a/backend/src/main/java/com/universe/marketing/users/mapper/UsersMapper.java b/backend/src/main/java/com/universe/marketing/users/mapper/UsersMapper.java new file mode 100644 index 0000000..b970e2e --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/mapper/UsersMapper.java @@ -0,0 +1,23 @@ +package com.universe.marketing.users.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.universe.marketing.users.entity.Users; +import com.universe.marketing.users.vo.UsersParams; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +@Mapper +public interface UsersMapper extends BaseMapper { + + + + @Select("update users set password= #{password,jdbcType=VARCHAR} where name= #{name,jdbcType=VARCHAR}") + void updatepwd(@Param("name") String name, @Param("password") String pwd); + + @Select("select * from users where name = #{name}") + Users selectByUsername(@Param("name") String name); + +} \ No newline at end of file diff --git a/backend/src/main/java/com/universe/marketing/users/service/Impl/MenuServiceImpl.java b/backend/src/main/java/com/universe/marketing/users/service/Impl/MenuServiceImpl.java new file mode 100644 index 0000000..cf883ae --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/Impl/MenuServiceImpl.java @@ -0,0 +1,7 @@ +package com.universe.marketing.users.service.Impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.universe.marketing.users.entity.Menu; + +public interface MenuServiceImpl extends IService { +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/Impl/RoleMenuServiceImpl.java b/backend/src/main/java/com/universe/marketing/users/service/Impl/RoleMenuServiceImpl.java new file mode 100644 index 0000000..7e7a036 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/Impl/RoleMenuServiceImpl.java @@ -0,0 +1,7 @@ +package com.universe.marketing.users.service.Impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.universe.marketing.users.entity.RoleMenu; + +public interface RoleMenuServiceImpl extends IService { +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/Impl/RoleServiceImpl.java b/backend/src/main/java/com/universe/marketing/users/service/Impl/RoleServiceImpl.java new file mode 100644 index 0000000..5e59a73 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/Impl/RoleServiceImpl.java @@ -0,0 +1,7 @@ +package com.universe.marketing.users.service.Impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.universe.marketing.users.entity.Roles; + +public interface RoleServiceImpl extends IService { +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/Impl/UserServiceImpl.java b/backend/src/main/java/com/universe/marketing/users/service/Impl/UserServiceImpl.java new file mode 100644 index 0000000..07f86e2 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/Impl/UserServiceImpl.java @@ -0,0 +1,7 @@ +package com.universe.marketing.users.service.Impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.universe.marketing.users.entity.Users; + +public interface UserServiceImpl extends IService { +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/MenuService.java b/backend/src/main/java/com/universe/marketing/users/service/MenuService.java new file mode 100644 index 0000000..469f007 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/MenuService.java @@ -0,0 +1,54 @@ +package com.universe.marketing.users.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.universe.marketing.users.entity.Menu; +import com.universe.marketing.users.entity.Roles; +import com.universe.marketing.users.mapper.MenuMapper; +import com.universe.marketing.users.service.Impl.MenuServiceImpl; +import com.universe.utils.UUIDUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class MenuService extends ServiceImpl implements MenuServiceImpl { + @Resource + private MenuService menuService; + @Resource + MenuMapper menuMapper; + @Transactional(rollbackFor = Exception.class) + public boolean save(Menu menu) { + if (StringUtils.isEmpty(menu.getId())) { + menu.setId(UUIDUtils.generateId()); + menuMapper.insert(menu); + return true; + } else { + menuMapper.updateById(menu); + return true; + } + } + + + public List findMeus(String name) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if(StringUtils.isNotBlank(name)){ + queryWrapper.like("name",name); + } + + List list = list(queryWrapper); + //找出pid一级菜单 + + List parentNodes = list.stream().filter(menu -> menu.getPid() == null).collect(Collectors.toList()); + //一级菜单的子菜单 + for(Menu menu : parentNodes){ + menu.setChildren(list.stream().filter(m -> menu.getId().equals(m.getPid())).collect(Collectors.toList())); + } + return parentNodes; + } + +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/RoleMenuService.java b/backend/src/main/java/com/universe/marketing/users/service/RoleMenuService.java new file mode 100644 index 0000000..8dc8c06 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/RoleMenuService.java @@ -0,0 +1,51 @@ +package com.universe.marketing.users.service; + +import cn.hutool.core.collection.CollUtil; +import com.universe.marketing.users.entity.Menu; +import com.universe.marketing.users.entity.RoleMenu; +import com.universe.marketing.users.mapper.MenuMapper; +import com.universe.marketing.users.mapper.RoleMenuMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +@Service +public class RoleMenuService { + @Resource + RoleMenuMapper roleMenuMapper; + @Resource + MenuMapper menuMapper; + + + @Transactional + public boolean setRoleMenu(String roleId, List menuIds) { + roleMenuMapper.deleteByRoleId(roleId); + List menuIdsCopy = CollUtil.newArrayList(menuIds); + for(String menuId : menuIds){ + Menu menu = menuMapper.selectById(menuId); + if(menu.getPid()!=null&&!menuIdsCopy.contains(menu.getPid())){ + RoleMenu roleMenu = new RoleMenu(); + roleMenu.setRoleId(roleId); + //要传menu的子ID 不能传主键 + roleMenu.setMenuId(menu.getPid()); + roleMenuMapper.insert(roleMenu); + menuIdsCopy.add(menu.getPid()); + } + RoleMenu roleMenu = new RoleMenu(); + roleMenu.setRoleId(roleId); + roleMenu.setMenuId(menuId); + roleMenuMapper.insert(roleMenu); + } + return true; + } + + + + public List getRoleMenu(String roleId) { + return roleMenuMapper.selectByRoleId(roleId); + } + +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/RolesService.java b/backend/src/main/java/com/universe/marketing/users/service/RolesService.java new file mode 100644 index 0000000..d0a72e0 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/RolesService.java @@ -0,0 +1,71 @@ +package com.universe.marketing.users.service; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + + +import com.universe.marketing.users.entity.Menu; +import com.universe.marketing.users.entity.Roles; + +import com.universe.marketing.users.mapper.MenuMapper; +import com.universe.marketing.users.mapper.RoleMenuMapper; +import com.universe.marketing.users.mapper.RolesMapper; +import com.universe.marketing.users.service.Impl.RoleServiceImpl; +import com.universe.utils.UUIDUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + + +@Service +public class RolesService extends ServiceImpl implements RoleServiceImpl { + + @Autowired + RolesMapper rolesMapper; + @Resource + private RoleMenuMapper roleMenuMapper; + @Resource + private MenuService menuService; + + @Transactional(rollbackFor = Exception.class) + public boolean save(Roles roles) { + if (StringUtils.isEmpty(roles.getId())) { + roles.setId(UUIDUtils.generateId()); + rolesMapper.insert(roles); + return true; + } else { + rolesMapper.updateById(roles); + return true; + } + } + /** + * 获取当前菜单列表 + * @param keyname 角色唯一标识 + * + */ + public List getRoleMenu(String keyname){ + String roleId = rolesMapper.selectByRoleName(keyname); + // 当前角色的所有菜单id集合 + List menuIds = roleMenuMapper.selectByRoleId(roleId); + + // 查出系统所有的菜单(树形) + List menus = menuService.findMeus(""); + // new一个最后筛选完成之后的list + List roleMenus = new ArrayList<>(); + // 筛选当前用户角色的菜单 + for (Menu menu : menus) { + if (menuIds.contains(menu.getId())) { + roleMenus.add(menu); + } + List children = menu.getChildren(); + // removeIf() 移除 children 里面不在 menuIds集合中的 元素 + children.removeIf(child -> !menuIds.contains(child.getId())); + } + return roleMenus; + } +} diff --git a/backend/src/main/java/com/universe/marketing/users/service/UsersService.java b/backend/src/main/java/com/universe/marketing/users/service/UsersService.java new file mode 100644 index 0000000..c8eaa69 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/service/UsersService.java @@ -0,0 +1,107 @@ +package com.universe.marketing.users.service; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.universe.handler.BusinessException; +import com.universe.marketing.users.entity.Menu; +import com.universe.marketing.users.entity.Users; +import com.universe.marketing.users.mapper.RoleMenuMapper; +import com.universe.marketing.users.mapper.RolesMapper; +import com.universe.marketing.users.mapper.UsersMapper; +import com.universe.marketing.users.service.Impl.UserServiceImpl; +import com.universe.utils.UUIDUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author yuanjs + * @description: + * @date 2020-02-05 7:23 + */ +@Service +public class UsersService extends ServiceImpl implements UserServiceImpl { + @Autowired + UsersMapper usersMapper; + @Resource + RolesService rolesService; + + @Transactional(rollbackFor = Exception.class) + public boolean save(Users users) { + Users old = usersMapper.selectByUsername(users.getName()); + if(old!=null){ + if(!old.getId().equals(users.getId())){ + throw new BusinessException("用户名已被占用"); + } + } + if (StrUtil.isEmpty(users.getId())) { + users.setId(UUIDUtils.generateId()); + usersMapper.insert(users); + } else { + users.setPassword(old.getPassword()); + usersMapper.updateById(users); + } + return true; + } + + + public String resetPwd(String userId){ + Users user = usersMapper.selectById(userId); + + Integer integer=(int) (Math.random()*899999+100000); + String password=integer.toString(); + user.setPassword(password); + usersMapper.updatepwd(user.getName(),password); + return password; + } + //获取用户菜单 + public List getUserMenu(String roleName) { + return rolesService.getRoleMenu(roleName); + } + + + //更改密码 + @Transactional(rollbackFor = Exception.class) + public Boolean setPwd(String userId, String password) { + Users user = usersMapper.selectById(userId); + if (user != null) { + usersMapper.updatepwd(user.getName(),password); + return true; + } + return false; + } + + +// public UserRequest login(UserRequest userRequest) { +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("name",userRequest.getName()); +// queryWrapper.eq("password",userRequest.getPassword()); +// try{ +// Users a = getOne(queryWrapper); +// if(a!=null){ +// BeanUtil.copyProperties(a,userRequest,true); +// String token = UUIDUtils.generateId(); +// userRequest.setToken(token); +// //获取role的字符串 +// String role = a.getRoleName(); +// //设置菜单列表 +// List roleMenu = getRoleMenu(role); +// userRequest.setMenus(roleMenu); +// return userRequest; +// } +// else{ +// throw new BusinessException("用户名或密码错误"); +// } +// }catch (Exception e){ +// return null; +// } +// } + + + + +} diff --git a/backend/src/main/java/com/universe/marketing/users/vo/UserRequest.java b/backend/src/main/java/com/universe/marketing/users/vo/UserRequest.java new file mode 100644 index 0000000..6830abc --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/vo/UserRequest.java @@ -0,0 +1,19 @@ +package com.universe.marketing.users.vo; + +import com.universe.marketing.users.entity.Menu; +import lombok.Data; + +import java.util.List; + +/** + * 登录接收信息 + */ +@Data +public class UserRequest { + private String id; + private String name; + private String password; + private String roleName; + private String token; + private List menus; +} diff --git a/backend/src/main/java/com/universe/marketing/users/vo/UsersParams.java b/backend/src/main/java/com/universe/marketing/users/vo/UsersParams.java new file mode 100644 index 0000000..32510e1 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/vo/UsersParams.java @@ -0,0 +1,15 @@ +package com.universe.marketing.users.vo; + +import lombok.Data; + +/** + * @author yuanjs + * @description: + * @date 2020-04-05 11:16 + */ +@Data +public class UsersParams { + private String queryKey; + private Integer enabled; + private String projectId; +} diff --git a/backend/src/main/java/com/universe/marketing/users/web/MenuController.java b/backend/src/main/java/com/universe/marketing/users/web/MenuController.java new file mode 100644 index 0000000..f8d76e1 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/web/MenuController.java @@ -0,0 +1,86 @@ +package com.universe.marketing.users.web; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import com.universe.marketing.users.entity.Menu; + +import com.universe.marketing.users.entity.Utils.R; +import com.universe.marketing.users.service.MenuService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; + + +@Api(value = "菜单管理", tags = {"菜单管理"}) +@RestController +@RequestMapping("/menu") +public class MenuController { + @Resource + MenuService menuService; + + /* @ApiOperation(value = "获取父子信息") + @GetMapping("/list") + public R list(@RequestParam(defaultValue = "") String name){ + return R.ok(menuService.findMeus(name)); + }*/ + @ApiOperation(value = "获取角色的全部菜单ID") + @GetMapping("/ids") + public R MenuIds() { + return R.ok(menuService.list().stream().map(Menu::getId)); + } + + @ApiOperation(value = "保存菜单") + @PostMapping("/save") + public R save(@RequestBody Menu menu) { + boolean flag = menuService.save(menu); + if (flag) { + return R.ok("添加成功"); + } else { + return R.fail("添加失败"); + } + } + + @ApiOperation(value = "更新菜单") + @PutMapping("/update") + public R update(@RequestBody Menu menu) { + boolean flag = menuService.updateById(menu); + if (flag) { + return R.ok("更新成功"); + } else { + return R.fail("更新失败"); + } + } + + @ApiOperation(value = "删除菜单") + @DeleteMapping("/delete/{id}") + public R delete(@PathVariable String id) { + boolean flag = menuService.removeById(id); + if (flag) { + return R.ok("删除成功"); + } else { + return R.fail("删除失败"); + } + } +/* @GetMapping("/lists") + public R List() { + return R.ok(menuService.list(null)); + }*/ + @ApiOperation(value = "分页查询菜单接口") + @GetMapping("/query") + public IPage find( + @RequestParam Integer pageNum, + @RequestParam Integer pageSize, + @RequestParam(defaultValue = "") String name + ){ + IPage page = new Page<>(pageNum,pageSize); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if(!"".equals(name)){ + queryWrapper.like("name",name); + } + return menuService.page(page, queryWrapper); + + } +} diff --git a/backend/src/main/java/com/universe/marketing/users/web/RolesController.java b/backend/src/main/java/com/universe/marketing/users/web/RolesController.java new file mode 100644 index 0000000..f9160c7 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/web/RolesController.java @@ -0,0 +1,102 @@ +package com.universe.marketing.users.web; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.universe.marketing.users.entity.Roles; +import com.universe.marketing.users.entity.Users; +import com.universe.marketing.users.entity.Utils.R; +import com.universe.marketing.users.service.RoleMenuService; +import com.universe.marketing.users.service.RolesService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@Api(value = "角色管理", tags = {"角色权限"}) +@RestController +@RequestMapping("/roles") +public class RolesController { + + @Resource + RolesService rolesService; + @Resource + private RoleMenuService roleMenuService; + + @ApiOperation(value = "分页查询角色") + @GetMapping("/query") + public IPage find( + @RequestParam Integer pageNum, + @RequestParam Integer pageSize + ) { + IPage page = new Page<>(pageNum, pageSize); + return rolesService.page(page); + } + + @ApiOperation(value = "保存角色") + @PostMapping("/save") + public R save(@RequestBody Roles roles) { + boolean flag = rolesService.save(roles); + if (flag) { + return R.ok("添加成功"); + } else { + return R.fail("添加失败"); + } + } + + @ApiOperation(value = "删除角色") + @DeleteMapping("/delete/{id}") + public R delete(@PathVariable String id) { + boolean flag = rolesService.removeById(id); + if (flag) { + return R.ok("删除成功"); + } else { + return R.fail("删除失败"); + } + } + + @ApiOperation(value = "获取角色菜单ID") + @GetMapping("/roleMenu/{roleId}") + public R getRoleMenu(@PathVariable String roleId) { + List list = roleMenuService.getRoleMenu(roleId); + return R.ok(list); + } + + @ApiOperation(value = "更新角色") + @PutMapping("/update") + public R update(@RequestBody Roles role) { + boolean flag = rolesService.updateById(role); + if (flag) { + return R.ok("更新成功"); + } else { + return R.fail("更新失败"); + } + } + + @ApiOperation(value = "设置角色菜单ID") + @PutMapping("/roleMenu/{roleId}") + public R roleMenu(@PathVariable String roleId, @RequestBody List menuIds) { + boolean flag = roleMenuService.setRoleMenu(roleId, menuIds); + if (flag) { + return R.ok("设置成功"); + } else { + return R.fail("设置失败"); + } + } + + @ApiOperation(value = "批量删除菜单") + @PostMapping("/delbatch") + public R delete(@RequestBody List ids) { + boolean flag = rolesService.removeByIds(ids); + if (flag) { + return R.ok("批量删除成功"); + } else { + return R.fail("删除失败"); + } + } + + +} diff --git a/backend/src/main/java/com/universe/marketing/users/web/UsersController.java b/backend/src/main/java/com/universe/marketing/users/web/UsersController.java new file mode 100644 index 0000000..0ddc5e0 --- /dev/null +++ b/backend/src/main/java/com/universe/marketing/users/web/UsersController.java @@ -0,0 +1,156 @@ +package com.universe.marketing.users.web; + + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.universe.marketing.users.entity.Users; +import com.universe.marketing.users.entity.Utils.R; +import com.universe.marketing.users.service.UsersService; +import com.universe.marketing.users.vo.UserRequest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Api(value = "用户管理", tags = {"用户管理"}) +@RestController +@RequestMapping("/users") +public class UsersController { + + @Autowired + UsersService usersService; + + @ApiOperation(value = "保存用户") + @PostMapping("/save") + public R save(@RequestBody Users users) { + if (StringUtils.isEmpty(users.getId())) { + Integer integer = (int) (Math.random() * 899999 + 100000); + String password = integer.toString(); + users.setPassword(password); + boolean flag = usersService.save(users); + if (flag) { + password = users.getPassword(); + String msg = "这是你的账号:" + users.getName() + "! 密码:" + users.getPassword(); + return R.ok(password, msg); + } else { + return R.fail("保存失败"); + } + } else { + usersService.save(users); + return R.ok("账户已保存"); + } + } + + @ApiOperation(value = "获取对应角色的用户") + @GetMapping("/{role}") + public R list_role(@PathVariable String role) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("role_name", role); + return R.ok(usersService.list(queryWrapper)); + } + + @ApiOperation(value = "获取该用户的菜单集合") + @GetMapping("/getmenu") + public R getUserMenu(@RequestBody UserRequest userRequest) { + String roleName = userRequest.getRoleName(); + return R.ok(usersService.getUserMenu(roleName)); + } + + // @ApiOperation(value = "登录") +// @PostMapping("/login") +// public R login(@RequestBody UserRequest userRequest) { +// String name = userRequest.getName(); +// String password = userRequest.getPassword(); +// if (StrUtil.isBlank(name) || StrUtil.isBlank(password)) { +// throw new BusinessException("用户名或密码为空"); +// } +// if(usersService.login(userRequest)!=null){ +// return R.ok(usersService.login(userRequest)); +// }else{ +// throw new BusinessException("用户名或密码错误"); +// } +// } + @ApiOperation(value = "重置密码") + @PutMapping("/reset/{userId}") + public R resetPwd(@PathVariable String userId) { + return R.ok(usersService.resetPwd(userId), "重置后的密码"); + } + + + @ApiOperation(value = "更改密码") + @PutMapping("/set/{userId}") + public R setPwd(@PathVariable String userId,@RequestParam String password) { + boolean flag = usersService.setPwd(userId,password); + if (flag) { + return R.ok("更改成功"); + } else { + return R.fail("更改失败"); + } + } + + @ApiOperation(value = "删除用户") + @DeleteMapping("/delete/{id}") + public R delete(@PathVariable String id) { + boolean flag = usersService.removeById(id); + if (flag) { + return R.ok("删除成功"); + } else { + return R.fail("删除失败"); + } + } + + @ApiOperation(value = "批量删除用户") + @PostMapping("/delbatch") + public R delete(@RequestBody List ids) { + boolean flag = usersService.removeByIds(ids); + if (flag) { + return R.ok("批量删除成功"); + } else { + return R.fail("删除失败"); + } + } + + + @ApiOperation(value = "分页查询用户") + @GetMapping("/query") + //条件查询 + public IPage find( + @RequestParam Integer pageNum, + @RequestParam Integer pageSize, + @RequestParam(defaultValue = "") String roleName, + @RequestParam(defaultValue = "") String telnumber, + @RequestParam(defaultValue = "") String realname) { + IPage page = new Page<>(pageNum, pageSize); + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (!"".equals(roleName)) { + queryWrapper.like("role_name", roleName); + } + if (!"".equals(realname)) { + queryWrapper.like("real_name", realname); + } + if (!"".equals(telnumber)) { + queryWrapper.like("tel_number", telnumber); + } + return usersService.page(page, queryWrapper); + + } + + @ApiOperation(value = "更新用户") + @PutMapping("/update") + public R update(@RequestBody Users user) { + boolean flag = usersService.updateById(user); + if (flag) { + return R.ok("更新成功"); + } else { + return R.fail("更新失败"); + } + } + +} diff --git a/backend/src/main/java/com/universe/utils/AesEncryptUtil.java b/backend/src/main/java/com/universe/utils/AesEncryptUtil.java new file mode 100644 index 0000000..921f03d --- /dev/null +++ b/backend/src/main/java/com/universe/utils/AesEncryptUtil.java @@ -0,0 +1,127 @@ +package com.universe.utils; + +import org.apache.commons.codec.binary.Base64; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +/** + * AES加解密算法 + * @author yuanjs + * @description: + * @date 2020-05-10 21:42 + */ +public class AesEncryptUtil { + + //使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同! + private static String KEY = "1986092719861016"; + + private static String IV = "1986092719861016"; + + + /** + * 加密方法 + * @param data 要加密的数据 + * @param key 加密key + * @param iv 加密iv + * @return 加密的结果 + * @throws Exception + */ + public static String encrypt(String data, String key, String iv) { + try { + + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding + int blockSize = cipher.getBlockSize(); + + byte[] dataBytes = data.getBytes(); + int plaintextLength = dataBytes.length; + if (plaintextLength % blockSize != 0) { + plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize)); + } + + byte[] plaintext = new byte[plaintextLength]; + System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length); + + SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); + IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); + + cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec); + byte[] encrypted = cipher.doFinal(plaintext); + + return new Base64().encodeToString(encrypted); + + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 解密方法 + * @param data 要解密的数据 + * @param key 解密key + * @param iv 解密iv + * @return 解密的结果 + * @throws Exception + */ + public static String desEncrypt(String data, String key, String iv) throws Exception { + try { + byte[] encrypted1 = new Base64().decode(data); + + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES"); + IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes()); + + cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec); + + byte[] original = cipher.doFinal(encrypted1); + String originalString = new String(original); + return originalString.trim(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 使用默认的key和iv加密 + * @param data + * @return + * @throws Exception + */ + public static String encrypt(String data) throws Exception { + return encrypt(data, KEY, IV); + } + + /** + * 使用默认的key和iv解密 + * @param data + * @return + * @throws Exception + */ + public static String desEncrypt(String data) throws Exception { + return desEncrypt(data, KEY, IV); + } + + + +// /** +// * 测试 +// */ +// public static void main(String args[]) throws Exception { +// +// String test1 = "sa"; +// String test =new String(test1.getBytes(),"UTF-8"); +// String data = null; +// String key = KEY; +// String iv = IV; +// // /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4= +// data = encrypt(test, key, iv); +// System.out.println("数据:"+test); +// System.out.println("加密:"+data); +// String jiemi =desEncrypt(data, key, iv).trim(); +// System.out.println("解密:"+jiemi); +// +// +// } +} diff --git a/backend/src/main/java/com/universe/utils/ApplicationContextUtil.java b/backend/src/main/java/com/universe/utils/ApplicationContextUtil.java new file mode 100644 index 0000000..9226829 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ApplicationContextUtil.java @@ -0,0 +1,27 @@ +package com.universe.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +/** + * @author zhuxiaomeng + * @date 2018/1/5. + * @email lenospmiller@gmail.com + */ +public class ApplicationContextUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + ApplicationContextUtil.applicationContext=applicationContext; + } + + public static ApplicationContext getContext(){ + return applicationContext; + } + + public static Object getBean(String arg){ + return applicationContext.getBean(arg); + } +} diff --git a/backend/src/main/java/com/universe/utils/BeanUtil.java b/backend/src/main/java/com/universe/utils/BeanUtil.java new file mode 100644 index 0000000..ae6d1d3 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/BeanUtil.java @@ -0,0 +1,42 @@ +package com.universe.utils; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.BeanWrapper; +import org.springframework.beans.BeanWrapperImpl; + +import java.beans.PropertyDescriptor; +import java.util.HashSet; +import java.util.Set; + +/** + * @author zhuxiaomeng + * @date 2017/12/18. + * @email lenospmiller@gmail.com + * 对象操作 + */ +public class BeanUtil { + + public static String[] getNullPropertyNames(Object source) { + final BeanWrapper src = new BeanWrapperImpl(source); + PropertyDescriptor[] pds = src.getPropertyDescriptors(); + + Set emptyNames = new HashSet<>(); + for (PropertyDescriptor pd : pds) { + Object srcValue = src.getPropertyValue(pd.getName()); + if (srcValue == null){ + emptyNames.add(pd.getName()); + } + } + String[] result = new String[emptyNames.size()]; + return emptyNames.toArray(result); + } + + /** + * 非空拷贝 + * @param source + * @param target + */ + public static void copyNotNullBean(Object source, Object target) { + BeanUtils.copyProperties(source, target, getNullPropertyNames(source)); + } +} diff --git a/backend/src/main/java/com/universe/utils/ChUtils/HttpContextUtils.java b/backend/src/main/java/com/universe/utils/ChUtils/HttpContextUtils.java new file mode 100644 index 0000000..08ebecd --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ChUtils/HttpContextUtils.java @@ -0,0 +1,12 @@ +package com.universe.utils.ChUtils; + +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +public class HttpContextUtils { + public static HttpServletRequest getHttpServletRequest(){ + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + } +} diff --git a/backend/src/main/java/com/universe/utils/ChUtils/IpUtils.java b/backend/src/main/java/com/universe/utils/ChUtils/IpUtils.java new file mode 100644 index 0000000..dfd1afb --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ChUtils/IpUtils.java @@ -0,0 +1,62 @@ +package com.universe.utils.ChUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; + +import javax.servlet.http.HttpServletRequest; + +/**** + * + * Project Name:spring-boot-seckill + *

从http请求中获取ip地址
+ * + * @ClassName: IPUtils + * @date 2019年1月3日 下午6:30:02 + * + * @author youqiang.xiong + * @version 1.0 + * @since + * @see + */ + + +public class IpUtils { + private static Logger logger = LoggerFactory.getLogger(IpUtils.class); + + /** + * 获取IP地址 + * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址 + * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址 + */ + public static String getIpAddr(HttpServletRequest request) { + String ip = null; + try { + ip = request.getHeader("x-forwarded-for"); + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + } catch (Exception e) { + logger.error("IPUtils ERROR ", e); + } + // 使用代理,则获取第一个IP地址 + if (StringUtils.isEmpty(ip) && ip.length() > 15) { + if (ip.indexOf(",") > 0) { + ip = ip.substring(0, ip.indexOf(",")); + } + } + return ip; + } +} diff --git a/backend/src/main/java/com/universe/utils/ChUtils/JWTUtils.java b/backend/src/main/java/com/universe/utils/ChUtils/JWTUtils.java new file mode 100644 index 0000000..9363643 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ChUtils/JWTUtils.java @@ -0,0 +1,40 @@ +package com.universe.utils.ChUtils; + +import io.jsonwebtoken.Jwt; +import io.jsonwebtoken.JwtBuilder; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class JWTUtils { + + private static final String jwtToken = "123456chhh!@#$$"; + + public static String createToken(String userId){ + Map claims = new HashMap<>(); + claims.put("userId",userId); + System.out.println("!!!!!"); + JwtBuilder jwtBuilder = Jwts.builder() + .signWith(SignatureAlgorithm.HS256, jwtToken) // 签发算法,秘钥为jwtToken + .setClaims(claims) // body数据,要唯一,自行设置 + .setIssuedAt(new Date()) // 设置签发时间 + .setExpiration(new Date(System.currentTimeMillis() + 24 * 60 * 60 * 60 * 1000));// 一天的有效时间 + String token = jwtBuilder.compact(); + return token; + } + + public static Map checkToken(String token){ + try { + Jwt parse = Jwts.parser().setSigningKey(jwtToken).parse(token); + return (Map) parse.getBody(); + }catch (Exception e){ + e.printStackTrace(); + } + return null; + + } + +} diff --git a/backend/src/main/java/com/universe/utils/ChUtils/UserThreadLocal.java b/backend/src/main/java/com/universe/utils/ChUtils/UserThreadLocal.java new file mode 100644 index 0000000..faf0d7c --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ChUtils/UserThreadLocal.java @@ -0,0 +1,22 @@ +/* +package com.universe.utils.ChUtils; + + +import com.pojo.po.User; + +public class UserThreadLocal { + //线程变量隔离 + private UserThreadLocal(){} + private static final ThreadLocal LOCAL = new ThreadLocal<>(); + + public static void put(User user){ + LOCAL.set(user); + } + public static User get(){ + return LOCAL.get(); + } + public static void remove(){ + LOCAL.remove(); + } +} +*/ diff --git a/backend/src/main/java/com/universe/utils/ConstantsConfig.java b/backend/src/main/java/com/universe/utils/ConstantsConfig.java new file mode 100644 index 0000000..3862df5 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ConstantsConfig.java @@ -0,0 +1,20 @@ +package com.universe.utils; + +/** + * 常量类 + * @author yuanjs + * @description: + * @date 2020-04-04 22:05 + */ +public class ConstantsConfig { + /** + * 用户绑定小程序时对应的角色代码 + */ + public static final String ROLE_CUSTOMER ="1001"; + + public static final String ROLE_ADMIN ="1"; + + public static final String COUPON_GIFT="赠货券"; + public static final String COUPON_MONEY="满减券"; + +} diff --git a/backend/src/main/java/com/universe/utils/ExportXlsHandler.java b/backend/src/main/java/com/universe/utils/ExportXlsHandler.java new file mode 100644 index 0000000..84ba4f8 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ExportXlsHandler.java @@ -0,0 +1,93 @@ +package com.universe.utils; + +import com.github.pagehelper.PageInfo; +import io.swagger.annotations.ApiModelProperty; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; + +import java.io.ByteArrayOutputStream; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * 导出Excel工具类 + * @author yuanjs + * @description: + * @date 2020-05-05 20:19 + */ +public class ExportXlsHandler { + + public static String toString(Object obj) { + StringBuilder sb = new StringBuilder("{"); + Field[] fields = obj.getClass().getDeclaredFields(); + for (Field field : fields) { + ApiModelProperty apiModelProperty = field.getAnnotation(ApiModelProperty.class); + try { + if (apiModelProperty != null) { + field.setAccessible(true); + if (field.get(obj) != null) { + if (sb.length() > 1) + sb.append(","); + sb.append(String.format("%s:%s", apiModelProperty.value(), field.get(obj).toString())); + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + } + sb.append("}\r\n"); + return sb.toString(); + } + + public static byte[] export(PageInfo pageInfo) throws Exception { + List list = pageInfo.getList(); + List fields = new ArrayList(); + if (list.size() > 0) { + //创建工作薄对象 + HSSFWorkbook workbook = new HSSFWorkbook();//这里也可以设置sheet的Name + //创建工作表对象 + HSSFSheet sheet = workbook.createSheet(); + + Object obj = list.get(0); + Class cls = obj.getClass(); + while (cls != null) { + Field[] fields1 = cls.getDeclaredFields(); + + for (Field field : fields1) { + ApiModelProperty apiOperation = field.getAnnotation(ApiModelProperty.class); + if (apiOperation != null) { + field.setAccessible(true); + fields.add(field); + } + } + cls=cls.getSuperclass(); + } + HSSFRow row = sheet.createRow(0);//设置第一行,从零开始 + for (int i = 0; i < fields.size(); i++) { + row.createCell(i).setCellValue(fields.get(i).getAnnotation(ApiModelProperty.class).value()); + } + for (int k = 0; k < list.size(); k++) { + row = sheet.createRow(k + 1); + Object obj1 = list.get(k); + for (int i = 0; i < fields.size(); i++) { + if (fields.get(i).get(obj1) != null) { + row.createCell(i).setCellValue(fields.get(i).get(obj1).toString()); + } + } + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + workbook.write(outputStream); + byte[] byt = outputStream.toByteArray(); + outputStream.close(); + workbook.close(); + return byt; + } + return new byte[0]; + + } + + +} diff --git a/backend/src/main/java/com/universe/utils/Handler.java b/backend/src/main/java/com/universe/utils/Handler.java new file mode 100644 index 0000000..a7287da --- /dev/null +++ b/backend/src/main/java/com/universe/utils/Handler.java @@ -0,0 +1,70 @@ +package com.universe.utils; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +/** + * 常用工具类 + * @author yuanjs + * @description: + * @date 2020-01-10 22:41 + */ +@Slf4j +public class Handler { + public static String getDateTime(){ + Date date = new Date(); + SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sf.format(date); + } + public static String getDate(){ + Date date = new Date(); + SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); + return sf.format(date); + } + public static Map httpRequest(String req_url) { + StringBuffer buffer = new StringBuffer(); + try { + URL url = new URL(req_url); + HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection(); + + httpUrlConn.setDoOutput(false); + httpUrlConn.setDoInput(true); + httpUrlConn.setUseCaches(false); + + httpUrlConn.setRequestMethod("GET"); + httpUrlConn.connect(); + + // 将返回的输入流转换成字符串 + InputStream inputStream = httpUrlConn.getInputStream(); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8"); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + + String str = null; + while ((str = bufferedReader.readLine()) != null) { + buffer.append(str); + } + bufferedReader.close(); + inputStreamReader.close(); + // 释放资源 + inputStream.close(); + inputStream = null; + httpUrlConn.disconnect(); + + } catch (Exception e) { + log.error(e.getStackTrace().toString()); + } + String r=buffer.toString(); + log.debug("打印微信服务器返回json对象:"+r); + JSONObject jb = JSONObject.parseObject(r); + return (Map)jb; + } +} diff --git a/backend/src/main/java/com/universe/utils/HttpUtil.java b/backend/src/main/java/com/universe/utils/HttpUtil.java new file mode 100644 index 0000000..c067891 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/HttpUtil.java @@ -0,0 +1,53 @@ +package com.universe.utils; + +import org.springframework.http.*; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author yuanjs + * @version 1.0.0 + * @ClassName HttpUtil + * @Description TODO + * @createTime 2021年04月29日 07:55:00 + */ +public class HttpUtil { + /** + * 向目的URL发送post请求 + * @param url 目的url + * @param params 发送的参数 + * @return ResultVO + */ + public static ResultVO sendPostRequest(String url, HashMap params){ + RestTemplate client = new RestTemplate(); + HttpHeaders headers = new HttpHeaders(); + HttpMethod method = HttpMethod.POST; + // 以表单的方式提交 + headers.setContentType(MediaType.APPLICATION_JSON); + //将请求头部和参数合成一个请求 + HttpEntity> requestEntity = new HttpEntity<>(params, headers); + //执行HTTP请求,将返回的结构使用ResultVO类格式化 + ResponseEntity response = client.exchange(url, method, requestEntity, ResultVO.class); + + return response.getBody(); + } + + public static Map cookieToMap(String value) { + Map map = new HashMap(); + value = value.replace(" ", ""); + if (value.contains(";")) { + String values[] = value.split(";"); + for (String val : values) { + String vals[] = val.split("="); + map.put(vals[0], vals[1]); + } + } else { + String values[] = value.split("="); + map.put(values[0], values[1]); + } + return map; + } +} diff --git a/backend/src/main/java/com/universe/utils/Md5Util.java b/backend/src/main/java/com/universe/utils/Md5Util.java new file mode 100644 index 0000000..446e079 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/Md5Util.java @@ -0,0 +1,24 @@ +package com.universe.utils; + +import org.apache.shiro.crypto.hash.Md5Hash; + +/** + * @author zhuxiaomeng + * @date 2017/12/7. + * @email lenospmiller@gmail.com + * 采用md5加密 确保数据安全性 + */ +public class Md5Util { + public static String getMD5(String msg,String salt){ + return new Md5Hash(msg,salt,4).toString(); + } + + /** + * 测试 + * @param args + */ + public static void main(String[] args) { + String str= getMD5("111111","manager"); + System.out.println(str); + } +} diff --git a/backend/src/main/java/com/universe/utils/ResultVO.java b/backend/src/main/java/com/universe/utils/ResultVO.java new file mode 100644 index 0000000..417d20d --- /dev/null +++ b/backend/src/main/java/com/universe/utils/ResultVO.java @@ -0,0 +1,36 @@ +package com.universe.utils; + +import lombok.Data; + +/** + * @author yuanjs + * @version 1.0.0 + * @ClassName ResultVO + * @Description TODO + * @createTime 2021年04月29日 07:56:00 + */ +@Data +public class ResultVO { + + private Integer code; + + private String message; + + private T data; + + public ResultVO() { + } + + public ResultVO(Integer code, String message) { + this.code = code; + this.message = message; + } + + public ResultVO(Integer code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + + +} \ No newline at end of file diff --git a/backend/src/main/java/com/universe/utils/UUIDUtils.java b/backend/src/main/java/com/universe/utils/UUIDUtils.java new file mode 100644 index 0000000..15fb7f0 --- /dev/null +++ b/backend/src/main/java/com/universe/utils/UUIDUtils.java @@ -0,0 +1,14 @@ +package com.universe.utils; + +import java.util.UUID; + +/** + * @author yuanjs + * @description: + * @date 2020-08-01 18:05 + */ +public class UUIDUtils { + public static String generateId() { + return UUID.randomUUID().toString().replace("-",""); + } +} diff --git a/backend/src/main/java/com/universe/utils/UuidUtil.java b/backend/src/main/java/com/universe/utils/UuidUtil.java new file mode 100644 index 0000000..fa6154f --- /dev/null +++ b/backend/src/main/java/com/universe/utils/UuidUtil.java @@ -0,0 +1,14 @@ +package com.universe.utils; + +import java.util.UUID; + +/** + * @author zxm + * @date 2019-11-15. + */ +public class UuidUtil { + + public static String getUuid() { + return UUID.randomUUID().toString().replace("-", "").toLowerCase(); + } +} diff --git a/backend/src/main/resources/WIeFb1sm1s.txt b/backend/src/main/resources/WIeFb1sm1s.txt new file mode 100644 index 0000000..4f3e234 --- /dev/null +++ b/backend/src/main/resources/WIeFb1sm1s.txt @@ -0,0 +1 @@ +1004568cc30d6d90534f8b516015ee42 \ No newline at end of file diff --git a/backend/src/main/resources/application-dev.yml b/backend/src/main/resources/application-dev.yml new file mode 100644 index 0000000..347695f --- /dev/null +++ b/backend/src/main/resources/application-dev.yml @@ -0,0 +1,36 @@ +server: + port: 8080 + +#showSql +logging: + level: + com.universe : debug +spring: + datasource: + username: team5 + password: iop890 + url: jdbc:postgresql://www.victorysoft.online:5432/team5?currentSchema=public&useUnicode=true&characterEncoding=utf8 + driver-class-name: org.postgresql.Driver + redis: + host: 110.40.152.26 + port: 6379 + password: c.h.2000.1125 + + main: + allow-bean-definition-overriding: true + +pagehelper: + helperDialect: postgresql + reasonable: true + supportMethodsArguments: true + params: count=countSql + +#mybatis-plus +mybatis-plus: + mapper-locations: classpath:mapping/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + map-underscore-to-camel-case: true + + + diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml new file mode 100644 index 0000000..76bdfdf --- /dev/null +++ b/backend/src/main/resources/application.yml @@ -0,0 +1,8 @@ +spring: + servlet: + multipart: + max-file-size: 20MB + profiles: + active: dev + + diff --git a/backend/src/main/resources/logback-spring.xml b/backend/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..377f310 --- /dev/null +++ b/backend/src/main/resources/logback-spring.xml @@ -0,0 +1,70 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n + + + + + DEBUG + ACCEPT + DENY + + true + + %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n + + + ${LOG_HOME}/debug.%d.log + + + + + INFO + ACCEPT + DENY + + true + + %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n + + + ${LOG_HOME}/info.%d.log + + + + + WARN + ACCEPT + DENY + + true + + %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n + + + ${LOG_HOME}/warn.%d.log + + + + + ERROR + + true + + %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n + + + ${LOG_HOME}/error.%d.log + + + + + + + + + + \ No newline at end of file diff --git a/backend/src/main/resources/mapping/ProductMapping.xml b/backend/src/main/resources/mapping/ProductMapping.xml new file mode 100644 index 0000000..c3d05cb --- /dev/null +++ b/backend/src/main/resources/mapping/ProductMapping.xml @@ -0,0 +1,35 @@ + + + + + + + + \ No newline at end of file diff --git a/backend/src/main/resources/mapping/ProductStoreMapping.xml b/backend/src/main/resources/mapping/ProductStoreMapping.xml new file mode 100644 index 0000000..0c4495f --- /dev/null +++ b/backend/src/main/resources/mapping/ProductStoreMapping.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + update product_store + set total=#{count} + where product_store.product_id =#{pId} + + + \ No newline at end of file diff --git a/backend/src/main/resources/mapping/PurchaseMapping.xml b/backend/src/main/resources/mapping/PurchaseMapping.xml new file mode 100644 index 0000000..a697008 --- /dev/null +++ b/backend/src/main/resources/mapping/PurchaseMapping.xml @@ -0,0 +1,36 @@ + + + + + + \ No newline at end of file diff --git a/backend/src/main/resources/mapping/PurchaseSonMapping.xml b/backend/src/main/resources/mapping/PurchaseSonMapping.xml new file mode 100644 index 0000000..907ad1d --- /dev/null +++ b/backend/src/main/resources/mapping/PurchaseSonMapping.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/backend/src/main/resources/mapping/PurchaseSwapMaping.xml b/backend/src/main/resources/mapping/PurchaseSwapMaping.xml new file mode 100644 index 0000000..acc71a3 --- /dev/null +++ b/backend/src/main/resources/mapping/PurchaseSwapMaping.xml @@ -0,0 +1,37 @@ + + + + + insert into purchase_swap(purchase_id,id) values + + ('${purchaseId}', '${id}') + + + + + \ No newline at end of file diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js new file mode 100644 index 0000000..a1b7974 --- /dev/null +++ b/frontend/.eslintrc.js @@ -0,0 +1,441 @@ +module.exports = { + root: true, + env: { + node: true, + es6: true, + browser: true, + }, + extends: [ + 'plugin:vue/essential', + 'eslint:recommended', + /*'@vue/prettier ',*/ + '@vue/airbnb', + ], + /*plusins:[ + 'vue' + ],*/ + rules: { + //"off"或者0 关闭规则关闭 + //"warn"或者1 在打开的规则作为警告(不影响退出代码) + //"error"或者2 把规则作为一个错误(退出代码触发时为1) + 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', + 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', + "linebreak-style": [0,"error", "windows"], + "prettier/prettier": [ + "error", + { + // tab缩进大小,默认为2 + "tabWidth": 4, + // 使用tab缩进,默认false + "useTabs": true, + // 使用分号, 默认true + "semi": true, + // 使用单引号, 默认false(在jsx中配置无效, 默认都是双引号) + "singleQuote": false, + // 行尾逗号,默认none,可选 none|es5|all + // es5 包括es5中的数组、对象 + // all 包括函数对象等所有可选 + "trailingComma": 'none', + // 对象中的空格 默认true + // true: { foo: bar } + // false: {foo: bar} + "bracketSpacing": true, + // JSX标签闭合位置 默认false + // false:

+ // true:
+ "jsxBracketSameLine": false, + // 箭头函数参数括号 默认avoid 可选 avoid| always + // avoid 能省略括号的时候就省略 例如x => x + // always 总是有括号 + "arrowParens": 'always' + } + ], + "no-alert": 0, //禁止使用alert confirm prompt + "no-array-constructor": 2, //禁止使用数组构造器 + "no-bitwise": 0, //禁止使用按位运算符 + "no-caller": 1, //禁止使用arguments.caller或arguments.callee + "no-catch-shadow": 2, //禁止catch子句参数与外部作用域变量同名 + "no-class-assign": 2, //禁止给类赋值 + "no-cond-assign": 2, //禁止在条件表达式中使用赋值语句 + "no-const-assign": 2, //禁止修改const声明的变量 + "no-constant-condition": 2, //禁止在条件中使用常量表达式 if(true) if(1) + "no-continue": 0, //禁止使用continue + "no-control-regex": 2, //禁止在正则表达式中使用控制字符 + "no-delete-var": 2, //不能对var声明的变量使用delete操作符 + "no-div-regex": 1, //不能使用看起来像除法的正则表达式/=foo/ + "no-dupe-keys": 2, //在创建对象字面量时不允许键重复 {a:1,a:1} + "no-dupe-args": 2, //函数参数不能重复 + "no-duplicate-case": 2, //switch中的case标签不能重复 + "no-else-return": 2, //如果if语句里面有return,后面不能跟else语句 + "no-empty": 2, //块语句中的内容不能为空 + "no-empty-character-class": 2, //正则表达式中的[]内容不能为空 + "no-empty-label": 0, //禁止使用空label + "no-eq-null": 2, //禁止对null使用==或!=运算符 + "no-eval": 1, //禁止使用eval + "no-ex-assign": 2, //禁止给catch语句中的异常参数赋值 + "no-extend-native": 2, //禁止扩展native对象 + "no-extra-bind": 2, //禁止不必要的函数绑定 + "no-extra-boolean-cast": 2, //禁止不必要的bool转换 + "no-extra-parens": 2, //禁止非必要的括号 + "no-extra-semi": 2, //禁止多余的冒号 + "no-fallthrough": 1, //禁止switch穿透 + "no-floating-decimal": 2, //禁止省略浮点数中的0 .5 3. + "no-func-assign": 2, //禁止重复的函数声明 + "no-implicit-coercion": 1, //禁止隐式转换 + "no-implied-eval": 2, //禁止使用隐式eval + "no-inline-comments": 0, //禁止行内备注 + "no-inner-declarations": [2, "functions"], //禁止在块语句中使用声明(变量或函数) + "no-invalid-regexp": 2, //禁止无效的正则表达式 + "no-invalid-this": 2, //禁止无效的this,只能用在构造器,类,对象字面量 + "no-irregular-whitespace": 2, //不能有不规则的空格 + "no-iterator": 2, //禁止使用__iterator__ 属性 + "no-label-var": 2, //label名不能与var声明的变量名相同 + "no-labels": 2, //禁止标签声明 + "no-lone-blocks": 2, //禁止不必要的嵌套块 + "no-lonely-if": 2, //禁止else语句内只有if语句 + "no-loop-func": 1, //禁止在循环中使用函数(如果没有引用外部变量不形成闭包就可以) + "no-mixed-requires": [0, false], //声明时不能混用声明类型 + "no-mixed-spaces-and-tabs": [2, true], //禁止混用tab和空格 + "no-multi-spaces": 1, //不能用多余的空格 + "no-multi-str": 2, //字符串不能用\换行 + "no-multiple-empty-lines": [1, { + "max": 2 + }], //空行最多不能超过2行 + "no-native-reassign": 2, //不能重写native对象 + "no-negated-in-lhs": 2, //in 操作符的左边不能有! + "no-nested-ternary": 0, //禁止使用嵌套的三目运算 + "no-new": 1, //禁止在使用new构造一个实例后不赋值 + "no-new-func": 1, //禁止使用new Function + "no-new-object": 2, //禁止使用new Object() + "no-new-require": 2, //禁止使用new require + "no-new-wrappers": 2, //禁止使用new创建包装实例,new String new Boolean new Number + "no-obj-calls": 2, //不能调用内置的全局对象,比如Math() JSON() + "no-octal": 2, //禁止使用八进制数字 + "no-octal-escape": 2, //禁止使用八进制转义序列 + "no-param-reassign": 2, //禁止给参数重新赋值 + "no-path-concat": 0, //node中不能使用__dirname或__filename做路径拼接 + "no-plusplus": 0, //禁止使用++,-- + "no-process-env": 0, //禁止使用process.env + "no-process-exit": 0, //禁止使用process.exit() + "no-proto": 2, //禁止使用__proto__属性 + "no-redeclare": 2, //禁止重复声明变量 + "no-regex-spaces": 2, //禁止在正则表达式字面量中使用多个空格 /foo bar/ + "no-restricted-modules": 0, //如果禁用了指定模块,使用就会报错 + "no-return-assign": 1, //return 语句中不能有赋值表达式 + "no-script-url": 0, //禁止使用javascript:void(0) + "no-self-compare": 2, //不能比较自身 + "no-sequences": 0, //禁止使用逗号运算符 + "no-shadow": 2, //外部作用域中的变量不能与它所包含的作用域中的变量或参数同名 + "no-shadow-restricted-names": 2, //严格模式中规定的限制标识符不能作为声明时的变量名使用 + "no-spaced-func": 2, //函数调用时 函数名与()之间不能有空格 + "no-sparse-arrays": 2, //禁止稀疏数组, [1,,2] + "no-sync": 0, //nodejs 禁止同步方法 + "no-ternary": 0, //禁止使用三目运算符 + "no-trailing-spaces": 1, //一行结束后面不要有空格 + "no-this-before-super": 0, //在调用super()之前不能使用this或super + "no-throw-literal": 2, //禁止抛出字面量错误 throw "error"; + "no-undef": 1, //不能有未定义的变量 + "no-undef-init": 2, //变量初始化时不能直接给它赋值为undefined + "no-undefined": 2, //不能使用undefined + "no-unexpected-multiline": 2, //避免多行表达式 + "no-underscore-dangle": 1, //标识符不能以_开头或结尾 + "no-unneeded-ternary": 2, //禁止不必要的嵌套 var isYes = answer === 1 ? true : false; + "no-unreachable": 2, //不能有无法执行的代码 + "no-unused-expressions": 2, //禁止无用的表达式 + "no-unused-vars": [2, { + "vars": "all", + "args": "after-used" + }], //不能有声明后未被使用的变量或参数 + "no-use-before-define": 2, //未定义前不能使用 + "no-useless-call": 2, //禁止不必要的call和apply + "no-void": 2, //禁用void操作符 + "no-var": 0, //禁用var,用let和const代替 + "no-warning-comments": [1, { + "terms": ["todo", "fixme", "xxx"], + "location": "start" + }], //不能有警告备注 + "no-with": 2, //禁用with + + "array-bracket-spacing": [2, "never"], //是否允许非空数组里面有多余的空格 + "arrow-parens": 0, //箭头函数用小括号括起来 + "arrow-spacing": 0, //=>的前/后括号 + "accessor-pairs": 0, //在对象中使用getter/setter + "block-scoped-var": 0, // 在块级作用域外访问块内定义的变量是否报错提示 + "brace-style": [2, '1tbs', {'allowSingleLine': true}], //if while function 后面的{必须与if在同一行,java风格。 + "callback-return": 1, //避免多次调用回调什么的 + "camelcase": 2, //强制驼峰法命名 + "comma-dangle": [2, "always"], // 数组和对象键值对最后一个逗号, never参数:不能带末尾的逗号, always参数:必须带末尾的逗号, + "comma-spacing": 0, //逗号前后的空格 + "comma-style": [2, "last"], //逗号风格,换行时在行首还是行尾 + "complexity": [0, 11], //循环复杂度 + "computed-property-spacing": [0, "never"], //是否允许计算后的键名什么的 + "consistent-return": 0, //return 后面是否允许省略 + "consistent-this": [2, "that"], //this别名 + "constructor-super": 0, //非派生类不能调用super,派生类必须调用super + "curly": [2, "all"], //必须使用 if(){} 中的{} + "default-case": 0, //switch语句最后必须有default + "dot-location": 0, //对象访问符的位置,换行的时候在行首还是行尾 + "dot-notation": [0, { + "allowKeywords": true + }], //避免不必要的方括号 + "eol-last": 0, //文件以单一的换行符结束 + "eqeqeq": 2, //必须使用全等 + "func-names": 0, //函数表达式必须有名字 + "func-style": [0, "declaration"], //函数风格,规定只能使用函数声明/函数表达式 + "generator-star-spacing": 0, //生成器函数*的前后空格 + "guard-for-in": 0, //for in循环要用if语句过滤 + "handle-callback-err": 0, //nodejs 处理错误 + "id-length": 0, //变量名长度 + "indent": ['error', 2, {'SwitchCase': 1}], //缩进风格 + "init-declarations": 0, //声明时必须赋初值 + "key-spacing": [0, { + "beforeColon": false, + "afterColon": true + }], //对象字面量中冒号的前后空格 + "lines-around-comment": 0, //行前/行后备注 + "max-depth": [0, 4], //嵌套块深度 + "max-len": ["error", {code : 300}] , //字符串最大长度 + "max-nested-callbacks": [0, 2], //回调嵌套深度 + "max-params": [0, 3], //函数最多只能有3个参数 + "max-statements": [0, 10], //函数内最多有几个声明 + "new-cap": 2, //函数名首行大写必须使用new方式调用,首行小写必须用不带new方式调用 + "new-parens": 2, //new时必须加小括号 + "newline-after-var": 2, //变量声明后是否需要空一行 + "object-curly-spacing": [0, "never"], //大括号内是否允许不必要的空格 + "object-shorthand": 0, //强制对象字面量缩写语法 + "one-var": 0, //连续声明 + "operator-assignment": [0, "always"], //赋值运算符 += -=什么的 + "operator-linebreak": [2, "after"], //换行时运算符在行尾还是行首 + "padded-blocks": 0, //块语句内行首行尾是否要空行 + "prefer-const": 0, //首选const + "prefer-spread": 0, //首选展开运算 + "prefer-reflect": 0, //首选Reflect的方法 + "quotes": [1, "double"], //引号类型 `` "double" 'single' + "quote-props": [0, "always"], //对象字面量中的属性名是否强制双引号 + "radix": 2, //parseInt必须指定第二个参数 + "id-match": 0, //命名检测 + "require-yield": 0, //生成器函数必须有yield + "semi": [0, "always"], //语句强制分号结尾 + "semi-spacing": [0, { + "before": false, + "after": true + }], //分号前后空格 + "sort-vars": 0, //变量声明时排序 + "space-after-keywords": [0, "always"], //关键字后面是否要空一格 + "space-before-blocks": [0, "always"], //不以新行开始的块{前面要不要有空格 + "space-before-function-paren": [0, "always"], //函数定义时括号前面要不要有空格 + "space-in-parens": [0, "never"], //小括号里面要不要有空格 + "space-infix-ops": 0, //中缀操作符周围要不要有空格 + "space-return-throw-case": 0, //return throw case后面要不要加空格 + "space-unary-ops": [0, { + "words": true, + "nonwords": false + }], //一元运算符的前/后要不要加空格 + "spaced-comment": 0, //注释风格要不要有空格什么的 + "strict": 2, //使用严格模式 + "use-isnan": 2, //禁止比较时使用NaN,只能用isNaN() + "valid-jsdoc": 0, //jsdoc规则 + "valid-typeof": 2, //必须使用合法的typeof的值 + "vars-on-top": 2, //var必须放在作用域顶部 + "wrap-iife": [2, "inside"], //立即执行函数表达式的小括号风格 + "wrap-regex": 0, //正则表达式字面量用小括号包起来 + "yoda": [2, "never"], //禁止尤达条件 + + + /* for vue */ + + // 禁止重复的二级键名 + + // @off 没必要限制 + + 'vue/no-dupe-keys': 'off', + + // 禁止出现语法错误 + + 'vue/no-parsing-error': 'error', + + // 禁止覆盖保留字 + + 'vue/no-reservered-keys': 'error', + + // 组件的 data 属性的值必须是一个函数 + + 'vue/no-shared-component-data': 'off', + + // 禁止