diff --git a/project06_1/.gitignore b/project06_1/.gitignore new file mode 100644 index 0000000..a2a3040 --- /dev/null +++ b/project06_1/.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/project06_1/.mvn/wrapper/MavenWrapperDownloader.java b/project06_1/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..74f4de4 --- /dev/null +++ b/project06_1/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,118 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed 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. + */ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.5"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/project06_1/.mvn/wrapper/maven-wrapper.jar b/project06_1/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..0d5e649 Binary files /dev/null and b/project06_1/.mvn/wrapper/maven-wrapper.jar differ diff --git a/project06_1/.mvn/wrapper/maven-wrapper.properties b/project06_1/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..7d59a01 --- /dev/null +++ b/project06_1/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar diff --git a/project06_1/mvnw b/project06_1/mvnw new file mode 100644 index 0000000..21d3ee8 --- /dev/null +++ b/project06_1/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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 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.5/maven-wrapper-0.5.5.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.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/project06_1/mvnw.cmd b/project06_1/mvnw.cmd new file mode 100644 index 0000000..84d60ab --- /dev/null +++ b/project06_1/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 Maven2 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 key stroke 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.5/maven-wrapper-0.5.5.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.5/maven-wrapper-0.5.5.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/project06_1/pom.xml b/project06_1/pom.xml new file mode 100644 index 0000000..9b9c231 --- /dev/null +++ b/project06_1/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.8.RELEASE + + + com.orangesale + orange + 0.0.1-SNAPSHOT + orange + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + 3.0.4 + + + org.springframework + spring-web + 5.2.0.RELEASE + + + mysql + mysql-connector-java + 8.0.32 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.projectlombok + lombok + 1.18.10 + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + org.apache.commons + commons-lang3 + 3.4 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/project06_1/src/main/java/com/example/orangesale_end/OrangeApplication.java b/project06_1/src/main/java/com/example/orangesale_end/OrangeApplication.java new file mode 100644 index 0000000..126184f --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/OrangeApplication.java @@ -0,0 +1,13 @@ +package com.example.orangesale_end; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OrangeApplication { + + public static void main(String[] args) { + SpringApplication.run(OrangeApplication.class, args); + } + +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/config/WebMvcConfigure.java b/project06_1/src/main/java/com/example/orangesale_end/config/WebMvcConfigure.java new file mode 100644 index 0000000..a0de7a0 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/config/WebMvcConfigure.java @@ -0,0 +1,30 @@ +package com.example.orangesale_end.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +/** + * @Author zhijun + * @Date 2019/10/11 14:40 + */ +@Configuration +public class WebMvcConfigure extends WebMvcConfigurationSupport { + private static final Logger logger = LoggerFactory.getLogger(WebMvcConfigure.class); + @Value("${uploadFilePath}") + private String uploadFilePath; + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + logger.info(uploadFilePath); + + //和页面有关的静态目录都放在项目的static目录下 + registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); + //上传的图片路径 + registry.addResourceHandler("/uploaded/**").addResourceLocations("file:" + uploadFilePath); + + } +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeMessageController.java b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeMessageController.java new file mode 100644 index 0000000..72f8505 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeMessageController.java @@ -0,0 +1,82 @@ +package com.example.orangesale_end.controller; + +import com.example.orangesale_end.entity.OrangeMessage; +import com.example.orangesale_end.service.MessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@RestController +@RequestMapping("/orange/message") +@CrossOrigin +public class OrangeMessageController { + + @Autowired + private MessageService messageService; + + /** + * 推送消息 + * + * @param message + * @return + */ + @RequestMapping(value = "/pushMessage", method = RequestMethod.POST) + public Map insertMessage(@RequestBody OrangeMessage message) { + Integer insertFlag = messageService.insertMessage(message); + Map map = new HashMap<>(); + if (insertFlag > 0) { + map.put("flag", true); + map.put("msg", "success"); + return map; + } + map.put("flag", false); + map.put("msg", "error"); + return map; + } + + /** + * 消费消息 + * + * @return + */ + @RequestMapping(value = "/consumeMessage", method = RequestMethod.GET) + public Map consumeMessage() { + OrangeMessage orangeMessage = messageService.consumeMessage(); + Map map = new HashMap<>(); + if (Objects.isNull(orangeMessage)) { + map.put("flag", false); + map.put("msg", "consume error"); + return map; + } + map.put("flag", true); + map.put("data", orangeMessage); + return map; + } + + /** + * 设置消息为已使用 + * + * @return + */ + @RequestMapping(value = "/updateMessage", method = RequestMethod.GET) + public Map updateMessage() { + Integer updateFlag = messageService.updateMessage(); + Map map = new HashMap<>(); + if (updateFlag > 0) { + map.put("flag", true); + map.put("msg", "success"); + return map; + } + map.put("flag", false); + map.put("msg", "error"); + return map; + } + +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeProductController.java b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeProductController.java new file mode 100644 index 0000000..6c4523c --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeProductController.java @@ -0,0 +1,152 @@ +package com.example.orangesale_end.controller; + +import com.example.orangesale_end.entity.OrangeProduct; +import com.example.orangesale_end.service.ProductService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.util.*; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@RestController +@RequestMapping("/orange/product") +@CrossOrigin +public class OrangeProductController { + @Autowired + private ProductService productService; + @Value("${uploadFilePath}") + private String uploadFilePath; + + /** + * 根据id查询商品信息 + * + * @param productId + * @return + */ + @RequestMapping(value = "/searchById", method = RequestMethod.POST) + public Map searchProductById(String productId) { + OrangeProduct orangeProduct = productService.selectById(Integer.valueOf(productId)); + Map map = new HashMap<>(); + if (Objects.isNull(orangeProduct)) { + map.put("flag", false); + map.put("msg", "search by id error"); + return map; + } + map.put("flag", true); + map.put("data", orangeProduct); + return map; + } + + /** + * 查询商品详细信息 + * + * @return + */ + @RequestMapping(value = "/search", method = RequestMethod.GET) + public Map searchProduct() { + List productList = productService.selectAll(); + Map map = new HashMap<>(); + if (CollectionUtils.isEmpty(productList)) { + map.put("flag", false); + map.put("msg", "search error"); + return map; + } + map.put("flag", true); + map.put("data", productList); + return map; + } + + /** + * 更新商品信息 + * + * @param orangeProduct + * @return + */ + @RequestMapping(value = "/update", method = RequestMethod.POST) + public Map updateProduct(@RequestBody OrangeProduct orangeProduct) { + Integer updateFlag = productService.updateProduct(orangeProduct); + Map map = new HashMap<>(); + if (updateFlag <= 0) { + map.put("flag", false); + map.put("msg", "search error"); + return map; + } + map.put("flag", true); + map.put("msg", "update success"); + return map; + } + + /** + * 删除商品信息 + * + * @param orangeProduct + * @return + */ + @RequestMapping(value = "/delete", method = RequestMethod.GET) + public Map deleteProduct(@RequestBody OrangeProduct orangeProduct) { + Integer deleteFlag = productService.deleteProduct(orangeProduct); + Map map = new HashMap<>(); + if (deleteFlag <= 0) { + map.put("flag", false); + map.put("msg", "delete error"); + return map; + } + map.put("flag", true); + map.put("msg", "delete success"); + return map; + } + + /** + * 添加商品信息 + * + * @param orangeProduct + * @return + */ + @RequestMapping(value = "/add", method = RequestMethod.POST) + public Map addProduct(@RequestBody OrangeProduct orangeProduct) { + Integer addFlag = productService.addProduct(orangeProduct); + Map map = new HashMap<>(); + if (addFlag <= 0) { + map.put("flag", false); + map.put("msg", "add error"); + return map; + } + map.put("flag", true); + map.put("msg", "add success"); + return map; + } + + /** + * 上传图片 + * + * @param file 上传文件 + * @return + */ + @RequestMapping("/uploadCover") + public Map uploadCover(@RequestParam("file") MultipartFile file) { + Map map = new HashMap<>(); + try { + String fileName = file.getOriginalFilename(); + String changeFileName = uploadFilePath + fileName; + File destFile = new File(changeFileName); + if (!destFile.exists()) { + destFile.getParentFile().mkdirs(); + file.transferTo(destFile); + } + map.put("flag", true); + map.put("data", "http://192.168.0.102:8081/uploaded/" + fileName); + return map; + } catch (Exception e) { + map.put("flag", false); + map.put("msg", "upload error"); + return map; + } + } +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeSaleController.java b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeSaleController.java new file mode 100644 index 0000000..142d6b3 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeSaleController.java @@ -0,0 +1,82 @@ +package com.example.orangesale_end.controller; + +import com.example.orangesale_end.entity.OrangeProductSale; +import com.example.orangesale_end.entity.OrangeSale; +import com.example.orangesale_end.service.SaleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@RestController +@RequestMapping("/orange/sale") +@CrossOrigin +public class OrangeSaleController { + @Autowired + private SaleService saleService; + + /** + * 根据销量从大到小排序 + * + * @return + */ + @RequestMapping(value = "/getBySaleNum", method = RequestMethod.GET) + public Map getBySalesNum() { + List productSaleList = saleService.getProductBySalesNum(); + Map map = new HashMap<>(); + if (CollectionUtils.isEmpty(productSaleList)) { + map.put("flag", false); + map.put("msg", "商品信息为空!"); + return map; + } + map.put("flag", true); + map.put("data", productSaleList); + return map; + } + + /** + * 查询销量信息 + * + * @return + */ + @RequestMapping(value = "/searchSaleNum", method = RequestMethod.GET) + public Map searchSaleNum() { + List list = saleService.searchSaleNum(); + Map map = new HashMap<>(); + if (CollectionUtils.isEmpty(list)) { + map.put("flag", false); + map.put("msg", "商品销量信息为空!"); + return map; + } + map.put("flag", true); + map.put("data", list); + return map; + } + + /** + * 更新销量信息 + * + * @param orangeSale + * @return + */ + @RequestMapping(value = "/updateSaleNum", method = RequestMethod.POST) + public Map updateSaleNum(@RequestBody OrangeSale orangeSale) { + Integer updateFlag = saleService.updateSaleNum(orangeSale); + Map map = new HashMap<>(); + if (updateFlag <= 0) { + map.put("flag", false); + map.put("msg", "update error!"); + return map; + } + map.put("flag", true); + map.put("msg", "update success"); + return map; + } +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeShoppingCartController.java b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeShoppingCartController.java new file mode 100644 index 0000000..74e1082 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeShoppingCartController.java @@ -0,0 +1,15 @@ +package com.example.orangesale_end.controller; + +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@RestController +@RequestMapping("/orange/shoppingCart") +@CrossOrigin +public class OrangeShoppingCartController { +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeUserController.java b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeUserController.java new file mode 100644 index 0000000..747b556 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/controller/OrangeUserController.java @@ -0,0 +1,63 @@ +package com.example.orangesale_end.controller; + +import com.example.orangesale_end.entity.OrangeUser; +import com.example.orangesale_end.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@RestController +@RequestMapping("/orange/user") +@CrossOrigin +public class OrangeUserController { + + @Autowired + private UserService userService; + + /** + * 用户登录验证 + * @param orangeUser + * @return + */ + @RequestMapping(value = "/login", method = RequestMethod.POST) + public Map userLogin(@RequestBody OrangeUser orangeUser) { + Map map = new HashMap<>(); + OrangeUser user = userService.userLogin(orangeUser); + if (Objects.isNull(user)) { + map.put("flag", false); + map.put("msg", "login error"); + return map; + } + map.put("flag", true); + map.put("data", user); + return map; + } + + /** + * 用户注册验证 + * + * @param orangeUser + * @return + */ + @RequestMapping(value = "/register", method = RequestMethod.POST) + public Map userRegister(@RequestBody OrangeUser orangeUser) { + Map map = new HashMap<>(); + Integer insertFlag = userService.userRegister(orangeUser); + if (insertFlag > 0) { + map.put("flag", true); + map.put("msg", "register success"); + return map; + } + map.put("flag", false); + map.put("msg", "register failed"); + return map; + } + +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeMessage.java b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeMessage.java new file mode 100644 index 0000000..0306ae8 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeMessage.java @@ -0,0 +1,17 @@ +package com.example.orangesale_end.entity; + +import lombok.Data; + +import java.sql.Timestamp; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Data +public class OrangeMessage { + private Integer id; + private String content; + private Timestamp sendTime; + private String used; +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeProduct.java b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeProduct.java new file mode 100644 index 0000000..723cb48 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeProduct.java @@ -0,0 +1,21 @@ +package com.example.orangesale_end.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.math.BigDecimal; +import java.sql.Timestamp; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Data +public class OrangeProduct { + private Integer id; + private String name; + private String imgUrl; + private BigDecimal price; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Timestamp addTime; +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeProductSale.java b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeProductSale.java new file mode 100644 index 0000000..7aa5f85 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeProductSale.java @@ -0,0 +1,20 @@ +package com.example.orangesale_end.entity; + +import lombok.Data; + +import java.math.BigDecimal; +import java.sql.Timestamp; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Data +public class OrangeProductSale { + private Integer productId; + private String name; + private String imgUrl; + private BigDecimal price; + private Timestamp addTime; + private Integer salesNum; +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeSale.java b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeSale.java new file mode 100644 index 0000000..c4d8a90 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeSale.java @@ -0,0 +1,14 @@ +package com.example.orangesale_end.entity; + +import lombok.Data; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Data +public class OrangeSale { + private Integer id; + private Integer productId; + private Integer salesNum; +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeShoppingCart.java b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeShoppingCart.java new file mode 100644 index 0000000..e40183d --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeShoppingCart.java @@ -0,0 +1,15 @@ +package com.example.orangesale_end.entity; + +import lombok.Data; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Data +public class OrangeShoppingCart { + private Integer id; + private Integer userId; + private Integer productId; + private Integer num; +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeUser.java b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeUser.java new file mode 100644 index 0000000..5956929 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/entity/OrangeUser.java @@ -0,0 +1,16 @@ +package com.example.orangesale_end.entity; + +import lombok.Data; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Data +public class OrangeUser { + private Integer id; + private String username; + private String password; + private String city; + private String sex; +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/mapper/MessageMapper.java b/project06_1/src/main/java/com/example/orangesale_end/mapper/MessageMapper.java new file mode 100644 index 0000000..f071675 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/mapper/MessageMapper.java @@ -0,0 +1,32 @@ +package com.example.orangesale_end.mapper; + +import com.example.orangesale_end.entity.OrangeMessage; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Mapper +public interface MessageMapper { + + /** + * 插入一条推送消息 + * + * @param message + */ + Integer insertMessage(OrangeMessage message); + + /** + * 更新推送消息 + * + */ + Integer updateMessage(); + + /** + * 获取推送的消息 + * + * @return + */ + OrangeMessage getMessage(); +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/mapper/ProductMapper.java b/project06_1/src/main/java/com/example/orangesale_end/mapper/ProductMapper.java new file mode 100644 index 0000000..88c680e --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/mapper/ProductMapper.java @@ -0,0 +1,55 @@ +package com.example.orangesale_end.mapper; + +import com.example.orangesale_end.entity.OrangeProduct; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Mapper +public interface ProductMapper { + + /** + * 根据商品id查询商品信息 + * + * @param productId + * @return + */ + OrangeProduct selectById(@Param("productId") Integer productId); + + /** + * 查询所有商品信息 + * + * @return + */ + List selectAll(); + + /** + * 更新商品 + * + * @param product + * @return + */ + Integer updateProduct(OrangeProduct product); + + /** + * 删除商品 + * + * @param product + * @return + */ + Integer deleteProduct(OrangeProduct product); + + /** + * 添加商品 + * + * @param orangeProduct + * @return + */ + Integer addProduct(OrangeProduct orangeProduct); + +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/mapper/SaleMapper.java b/project06_1/src/main/java/com/example/orangesale_end/mapper/SaleMapper.java new file mode 100644 index 0000000..b54398c --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/mapper/SaleMapper.java @@ -0,0 +1,40 @@ +package com.example.orangesale_end.mapper; + +import com.example.orangesale_end.entity.OrangeSale; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Mapper +public interface SaleMapper { + /** + * 根据销量查询 + * + * @return + */ + List getBySalesNum(); + + /** + * 设置商品的销量信息 + */ + Integer updateSalesNum(OrangeSale orangeSale); + + /** + * 查询商品的销量信息 + * + * @return + */ + List selectAll(); + + /** + * 插入商品销量信息 + * + * @param orangeSale + * @return + */ + Integer addSalesNum(OrangeSale orangeSale); +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/mapper/ShoppingCartMapper.java b/project06_1/src/main/java/com/example/orangesale_end/mapper/ShoppingCartMapper.java new file mode 100644 index 0000000..7dcf2b3 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/mapper/ShoppingCartMapper.java @@ -0,0 +1,11 @@ +package com.example.orangesale_end.mapper; + +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Mapper +public interface ShoppingCartMapper { +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/mapper/UserMapper.java b/project06_1/src/main/java/com/example/orangesale_end/mapper/UserMapper.java new file mode 100644 index 0000000..013a05e --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/mapper/UserMapper.java @@ -0,0 +1,26 @@ +package com.example.orangesale_end.mapper; + +import com.example.orangesale_end.entity.OrangeUser; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Mapper +public interface UserMapper { + /** + * 用户登录验证 + * @param orangeUser + * @return + */ + OrangeUser userLogin(OrangeUser orangeUser); + + /** + * 用户注册 + * + * @param orangeUser + * @return + */ + Integer userRegister(OrangeUser orangeUser); +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/service/MessageService.java b/project06_1/src/main/java/com/example/orangesale_end/service/MessageService.java new file mode 100644 index 0000000..d76c067 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/service/MessageService.java @@ -0,0 +1,44 @@ +package com.example.orangesale_end.service; + +import com.example.orangesale_end.entity.OrangeMessage; +import com.example.orangesale_end.mapper.MessageMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Service +public class MessageService { + @Autowired + private MessageMapper messageMapper; + + /** + * 推送消息 + * + * @param message + * @return + */ + public Integer insertMessage(OrangeMessage message) { + return messageMapper.insertMessage(message); + } + + /** + * 消费消息 + * + * @return + */ + public OrangeMessage consumeMessage() { + return messageMapper.getMessage(); + } + + /** + * 消息设置为已读 + * + * @return + */ + public Integer updateMessage() { + return messageMapper.updateMessage(); + } +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/service/ProductService.java b/project06_1/src/main/java/com/example/orangesale_end/service/ProductService.java new file mode 100644 index 0000000..85a1ecd --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/service/ProductService.java @@ -0,0 +1,67 @@ +package com.example.orangesale_end.service; + +import com.example.orangesale_end.entity.OrangeProduct; +import com.example.orangesale_end.mapper.ProductMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Service +public class ProductService { + @Autowired + private ProductMapper productMapper; + + /** + * 根据商品id查询商品信息 + * + * @param productId + * @return + */ + public OrangeProduct selectById(Integer productId) { + return productMapper.selectById(productId); + } + + /** + * 查询所有商品信息 + * + * @return + */ + public List selectAll() { + return productMapper.selectAll(); + } + + /** + * 更新商品 + * + * @param product + * @return + */ + public Integer updateProduct(OrangeProduct product) { + return productMapper.updateProduct(product); + } + + /** + * 删除商品 + * + * @param product + * @return + */ + public Integer deleteProduct(OrangeProduct product) { + return productMapper.deleteProduct(product); + } + + /** + * 添加商品 + * + * @param orangeProduct + * @return + */ + public Integer addProduct(OrangeProduct orangeProduct) { + return productMapper.addProduct(orangeProduct); + } +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/service/SaleService.java b/project06_1/src/main/java/com/example/orangesale_end/service/SaleService.java new file mode 100644 index 0000000..d27a32a --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/service/SaleService.java @@ -0,0 +1,110 @@ +package com.example.orangesale_end.service; + +import com.example.orangesale_end.entity.OrangeProduct; +import com.example.orangesale_end.entity.OrangeProductSale; +import com.example.orangesale_end.entity.OrangeSale; +import com.example.orangesale_end.mapper.ProductMapper; +import com.example.orangesale_end.mapper.SaleMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Service +public class SaleService { + + @Autowired + private SaleMapper saleMapper; + @Autowired + private ProductMapper productMapper; + + /** + * 根据销量查询 + * + * @return + */ + private List getBySalesNum() { + return saleMapper.getBySalesNum(); + } + + /** + * 按照销量排序好的商品信息 + * + * @return + */ + public List getProductBySalesNum() { + List saleList = getBySalesNum(); + return selectAllProductSale(saleList); + } + + /** + * 查询销量信息 + */ + public List searchSaleNum() { + List productList = productMapper.selectAll(); + List saleList = saleMapper.selectAll(); + List productIdList = new ArrayList<>(); + List productIdExistList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(productList)) { + for (OrangeProduct orangeProduct : productList) { + productIdList.add(orangeProduct.getId()); + } + } + if (!CollectionUtils.isEmpty(saleList)) { + for (OrangeSale orangeSale : saleList) { + productIdExistList.add(orangeSale.getProductId()); + } + } + if (!CollectionUtils.isEmpty(productIdList)) { + for (Integer productId : productIdExistList) { + if (!productIdList.contains(productId)) { + OrangeSale orangeSale = new OrangeSale(); + orangeSale.setProductId(productId); + orangeSale.setSalesNum(0); + saleMapper.addSalesNum(orangeSale); + } + } + } + saleList = saleMapper.selectAll(); + return selectAllProductSale(saleList); + } + + /** + * 组装商品和销量信息 + * + * @param orangeSaleList + * @return + */ + private List selectAllProductSale(List orangeSaleList) { + List list = new ArrayList<>(); + if (!CollectionUtils.isEmpty(orangeSaleList)) { + for (OrangeSale orangeSale : orangeSaleList) { + OrangeProduct orangeProduct = productMapper.selectById(orangeSale.getProductId()); + OrangeProductSale orangeProductSale = new OrangeProductSale(); + orangeProductSale.setAddTime(orangeProduct.getAddTime()); + orangeProductSale.setImgUrl(orangeProduct.getImgUrl()); + orangeProductSale.setName(orangeProduct.getName()); + orangeProductSale.setPrice(orangeProduct.getPrice()); + orangeProductSale.setSalesNum(orangeSale.getSalesNum()); + list.add(orangeProductSale); + } + } + return list; + } + + /** + * 更新销量信息 + * + * @param orangeSale + * @return + */ + public Integer updateSaleNum(OrangeSale orangeSale) { + return saleMapper.updateSalesNum(orangeSale); + } +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/service/ShoppingCartService.java b/project06_1/src/main/java/com/example/orangesale_end/service/ShoppingCartService.java new file mode 100644 index 0000000..a93bef0 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/service/ShoppingCartService.java @@ -0,0 +1,12 @@ +package com.example.orangesale_end.service; + +import org.springframework.stereotype.Service; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Service +public class ShoppingCartService { + +} diff --git a/project06_1/src/main/java/com/example/orangesale_end/service/UserService.java b/project06_1/src/main/java/com/example/orangesale_end/service/UserService.java new file mode 100644 index 0000000..34f9b98 --- /dev/null +++ b/project06_1/src/main/java/com/example/orangesale_end/service/UserService.java @@ -0,0 +1,35 @@ +package com.example.orangesale_end.service; + +import com.example.orangesale_end.entity.OrangeUser; +import com.example.orangesale_end.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @Author zhijun + * @Date 2019/12/13 + */ +@Service +public class UserService { + @Autowired + private UserMapper userMapper; + + /** 用户登录验证 + * @param orangeUser + * @return + */ + public OrangeUser userLogin(OrangeUser orangeUser) { + return userMapper.userLogin(orangeUser); + } + + /** + * 用户注册 + * + * @param orangeUser + * @return + */ + public Integer userRegister(OrangeUser orangeUser) { + return userMapper.userRegister(orangeUser); + } + +} diff --git a/project06_1/src/main/resources/application.properties b/project06_1/src/main/resources/application.properties new file mode 100644 index 0000000..dd10575 --- /dev/null +++ b/project06_1/src/main/resources/application.properties @@ -0,0 +1,18 @@ +server.port=8081 +spring.datasource.url=jdbc:mysql://localhost:3306/orange?useUnicode=true&characterEncoding=UTF-8&useSSL=false +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.username=root +spring.datasource.password=123456 +#շԶת +mybatis.configuration.map-underscore-to-camel-case=true +mybatis.mapper-locations=classpath:mapper/*Mapper.xml +mybatis.type-aliases-package= com.test.vue.entity + +spring.jackson.date-format=yyyy-MM-dd HH:mm:ss +spring.jackson.time-zone=GMT+8 + +#ϴͼƬ· +uploadFilePath=D:\\images\\ + +spring.servlet.multipart.max-file-size=10MB +spring.servlet.multipart.max-request-size=200MB \ No newline at end of file diff --git a/project06_1/src/main/resources/mapper/MessageMapper.xml b/project06_1/src/main/resources/mapper/MessageMapper.xml new file mode 100644 index 0000000..f690a6e --- /dev/null +++ b/project06_1/src/main/resources/mapper/MessageMapper.xml @@ -0,0 +1,16 @@ + + + + + + insert into orange_message(content) values (#{content}) + + + + update orange_message set used='YES' + + + \ No newline at end of file diff --git a/project06_1/src/main/resources/mapper/ProductMapper.xml b/project06_1/src/main/resources/mapper/ProductMapper.xml new file mode 100644 index 0000000..1a1fae0 --- /dev/null +++ b/project06_1/src/main/resources/mapper/ProductMapper.xml @@ -0,0 +1,26 @@ + + + + + + + update orange_product set + + name =#{name}, + img_url=#{imgUrl}, + price=#{price} + + where id=#{id} + + + insert into orange_product(name,img_url,price,add_time) values (#{name},#{imgUrl},#{price},#{addTime}) + + + delete from orange_product where id=#{id} + + \ No newline at end of file diff --git a/project06_1/src/main/resources/mapper/SaleMapper.xml b/project06_1/src/main/resources/mapper/SaleMapper.xml new file mode 100644 index 0000000..a8b7f7e --- /dev/null +++ b/project06_1/src/main/resources/mapper/SaleMapper.xml @@ -0,0 +1,17 @@ + + + + + + + update orange_sale sales_num=#{salesNum} where product_id=#{productId} + + + insert into orange_sale(product_id,sales_num) values (#{productId},#{salesNum}) + + \ No newline at end of file diff --git a/project06_1/src/main/resources/mapper/UserMapper.xml b/project06_1/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..094abd2 --- /dev/null +++ b/project06_1/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,11 @@ + + + + + + insert into orange_user(username,password,sex,city) values(#{username},#{password},#{sex},#{city}) + + \ No newline at end of file diff --git a/project06_1/src/main/resources/static/back.jpeg b/project06_1/src/main/resources/static/back.jpeg new file mode 100644 index 0000000..d1c6d34 Binary files /dev/null and b/project06_1/src/main/resources/static/back.jpeg differ diff --git a/project06_1/src/main/resources/static/images/apple.png b/project06_1/src/main/resources/static/images/apple.png new file mode 100644 index 0000000..0810381 Binary files /dev/null and b/project06_1/src/main/resources/static/images/apple.png differ diff --git a/project06_1/src/main/resources/static/images/juzi.png b/project06_1/src/main/resources/static/images/juzi.png new file mode 100644 index 0000000..106df92 Binary files /dev/null and b/project06_1/src/main/resources/static/images/juzi.png differ diff --git a/project06_1/src/main/resources/static/images/lemon.png b/project06_1/src/main/resources/static/images/lemon.png new file mode 100644 index 0000000..39f12cc Binary files /dev/null and b/project06_1/src/main/resources/static/images/lemon.png differ diff --git a/project06_1/src/main/resources/static/images/li.png b/project06_1/src/main/resources/static/images/li.png new file mode 100644 index 0000000..0834592 Binary files /dev/null and b/project06_1/src/main/resources/static/images/li.png differ diff --git a/project06_1/src/main/resources/static/images/orange.png b/project06_1/src/main/resources/static/images/orange.png new file mode 100644 index 0000000..70e8db8 Binary files /dev/null and b/project06_1/src/main/resources/static/images/orange.png differ diff --git a/project06_1/src/main/resources/static/images/youzi.png b/project06_1/src/main/resources/static/images/youzi.png new file mode 100644 index 0000000..53df959 Binary files /dev/null and b/project06_1/src/main/resources/static/images/youzi.png differ diff --git a/project06_2/.gitignore b/project06_2/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/project06_2/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/project06_2/.idea/.gitignore b/project06_2/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/project06_2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/project06_2/.idea/codeStyles/Project.xml b/project06_2/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/project06_2/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/project06_2/.idea/compiler.xml b/project06_2/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/project06_2/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/project06_2/.idea/gradle.xml b/project06_2/.idea/gradle.xml new file mode 100644 index 0000000..aeafadd --- /dev/null +++ b/project06_2/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/project06_2/.idea/jarRepositories.xml b/project06_2/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/project06_2/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/.idea/misc.xml b/project06_2/.idea/misc.xml new file mode 100644 index 0000000..d5d35ec --- /dev/null +++ b/project06_2/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/.gitignore b/project06_2/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/project06_2/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/project06_2/app/build.gradle b/project06_2/app/build.gradle new file mode 100644 index 0000000..8080a2d --- /dev/null +++ b/project06_2/app/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + defaultConfig { + applicationId "com.example.orangesale_end" + minSdkVersion 26 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + implementation 'liji.library.dev:citypickerview:1.1.0' + implementation "com.squareup.okhttp3:okhttp:4.2.2" + implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.12' +} diff --git a/project06_2/app/proguard-rules.pro b/project06_2/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/project06_2/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/project06_2/app/src/androidTest/java/com/example/orangesale_end/ExampleInstrumentedTest.java b/project06_2/app/src/androidTest/java/com/example/orangesale_end/ExampleInstrumentedTest.java new file mode 100644 index 0000000..0ef57ae --- /dev/null +++ b/project06_2/app/src/androidTest/java/com/example/orangesale_end/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.example.orangesale_end; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.example.orangesale_end", appContext.getPackageName()); + } +} diff --git a/project06_2/app/src/main/AndroidManifest.xml b/project06_2/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..138b087 --- /dev/null +++ b/project06_2/app/src/main/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/MainActivity.java b/project06_2/app/src/main/java/com/example/orangesale_end/MainActivity.java new file mode 100644 index 0000000..5ad8815 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/MainActivity.java @@ -0,0 +1,92 @@ +package com.example.orangesale_end; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Looper; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +import com.example.orangesale_end.activity.IndexActivity; +import com.example.orangesale_end.activity.RegisterActivity; +import com.example.orangesale_end.entity.OrangeUser; +import com.example.orangesale_end.netrequest.OkHttpUser; + +import java.io.IOException; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + private Button registerButton, loginButton; + private EditText usernameText, paswdEdit; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.user_login); + init(); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.register: + Intent intent = new Intent(MainActivity.this, RegisterActivity.class); + startActivity(intent); + break; + case R.id.login: + //注册时,我们引入了数据库,登录这里可以通过数据库进行验证,验证跳转到首页,不通过进行提示 + Thread thread = new Thread(runnable); + thread.start(); + break; + } + + } + + //界面组件初始化 + private void init() { + usernameText = findViewById(R.id.username); + paswdEdit = findViewById(R.id.password); + loginButton = findViewById(R.id.login); + loginButton.setOnClickListener(this); + registerButton = findViewById(R.id.register); + registerButton.setOnClickListener(this); + } + + /** + * 登录验证 + */ + Runnable runnable = new Runnable() { + @Override + public void run() { + String username = usernameText.getText().toString(); + String password = paswdEdit.getText().toString(); + OrangeUser orangeUser = new OrangeUser(); + orangeUser.setUsername(username); + orangeUser.setPassword(password); + OkHttpUser okHttpUser = new OkHttpUser(); + OrangeUser orangeUser1 = null; + try { + orangeUser1 = okHttpUser.userLogin(orangeUser); + if (orangeUser1 != null) { + Intent intent1 = new Intent(MainActivity.this, IndexActivity.class); + Bundle bundle = new Bundle(); + bundle.putString("username", usernameText.getText().toString()); + bundle.putString("password", orangeUser1.getPassword()); + bundle.putString("city", orangeUser1.getCity()); + bundle.putString("sex", orangeUser1.getSex()); + intent1.putExtras(bundle); + startActivity(intent1); + } else { + //解决在子线程中调用Toast的异常情况处理 + Looper.prepare(); + Toast.makeText(MainActivity.this, "账号或者密码错误", Toast.LENGTH_SHORT).show(); + Looper.loop(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + }; +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/activity/CategoryActivity.java b/project06_2/app/src/main/java/com/example/orangesale_end/activity/CategoryActivity.java new file mode 100644 index 0000000..278743a --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/activity/CategoryActivity.java @@ -0,0 +1,90 @@ +package com.example.orangesale_end.activity; + +import android.app.Activity; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.widget.ListView; + +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.adapter.Adapter; +import com.example.orangesale_end.entity.Product; +import com.example.orangesale_end.fragment.SetDetailFragment; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + + +public class CategoryActivity extends Activity { + public OnChangeListener onchangedListener; + private List productList; + private List productCategory = new ArrayList<>(); + private ListView titleList; + private Adapter adapter; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.content_category); + initData(); + init(); + SetDetailFragment fragment = new SetDetailFragment(); + FragmentManager fragmentManager = getFragmentManager(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + transaction.replace(R.id.category_detail, fragment); + transaction.commit(); + titleList.setOnItemClickListener((parent, view, position, id) -> { + adapter.setSelectedPosition(position); + adapter.notifyDataSetInvalidated(); + if (onchangedListener != null) { + onchangedListener.changeText(productList.get(position)); + } + }); + + } + + public void setOnChangeListener(OnChangeListener onChangeListener) { + this.onchangedListener = onChangeListener; + } + + public interface OnChangeListener { + void changeText(Product product); + } + + /** + * 初始化数据 + */ + private void initData() { + productList = new ArrayList<>(); + productCategory.add("橘子"); + productCategory.add("橙子"); + productCategory.add("柚子"); + Product product = new Product(); + product.setImageUrlId(R.drawable.arrow_down); + product.setProductName("橘子"); + product.setProductPrice(new BigDecimal("9.9")); + Product product1 = new Product(); + product1.setImageUrlId(R.drawable.orange); + product1.setProductName("橙子"); + product1.setProductPrice(new BigDecimal("29.9")); + Product product2 = new Product(); + product2.setImageUrlId(R.drawable.arrow_left); + product2.setProductName("柚子"); + product2.setProductPrice(new BigDecimal("19.9")); + productList.add(product); + productList.add(product1); + productList.add(product2); + } + + /** + * 初始化组件 + */ + private void init() { + titleList = findViewById(R.id.category_title_list); + adapter = new Adapter(productCategory, CategoryActivity.this); + titleList.setAdapter(adapter); + } +} \ No newline at end of file diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/activity/IndexActivity.java b/project06_2/app/src/main/java/com/example/orangesale_end/activity/IndexActivity.java new file mode 100644 index 0000000..e399cfb --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/activity/IndexActivity.java @@ -0,0 +1,128 @@ +package com.example.orangesale_end.activity; + +import android.app.Activity; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; + +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.fragment.IndexFragment; +import com.example.orangesale_end.fragment.PearsonFragment; +import com.example.orangesale_end.fragment.ProductFragment; +import com.example.orangesale_end.fragment.ShoppingCartFragment; +import com.example.orangesale_end.service.TimeService; + +public class IndexActivity extends Activity implements View.OnClickListener { + private IndexFragment indexFragment; + private ProductFragment productFragment; + private ShoppingCartFragment shoppingCartFragment; + private PearsonFragment pearsonFragment; + private LinearLayout indexLine, productLine, shoppingCartLine, pearsonLine; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + init(); + initIndexFragment(); + Thread thread = new Thread(runnable); + thread.start(); + } + + /** + * 组件初始化 + */ + private void init() { + indexLine = findViewById(R.id.content_index); + indexLine.setOnClickListener(this); + productLine = findViewById(R.id.content_product); + productLine.setOnClickListener(this); + shoppingCartLine = findViewById(R.id.content_cart); + shoppingCartLine.setOnClickListener(this); + pearsonLine = findViewById(R.id.content_pearson); + pearsonLine.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.content_index: + initIndexFragment(); + break; + case R.id.content_product: + initproductFragment(); + break; + case R.id.content_cart: + initshoppingCartFragment(); + break; + case R.id.content_pearson: + initpearsonFragment(); + break; + } + } + + /** + * 初始化首页Fragment + */ + private void initIndexFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (indexFragment == null) { + indexFragment = new IndexFragment(); + } + transaction.replace(R.id.main_content0, indexFragment); + transaction.commit(); + } + + /** + * 初始化产品Fragment + */ + private void initproductFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (productFragment == null) { + productFragment = new ProductFragment(); + } + transaction.replace(R.id.main_content0, productFragment); + transaction.commit(); + } + + /** + * 初始化购物车Fragment + */ + private void initshoppingCartFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (shoppingCartFragment == null) { + shoppingCartFragment = new ShoppingCartFragment(); + } + transaction.replace(R.id.main_content0, shoppingCartFragment); + transaction.commit(); + } + + /** + * 初始化个人Fragment + */ + private void initpearsonFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (pearsonFragment == null) { + Intent intent = IndexActivity.this.getIntent(); + Bundle bundle = intent.getExtras(); + pearsonFragment = new PearsonFragment(); + pearsonFragment.setArguments(bundle); + } + transaction.replace(R.id.main_content0, pearsonFragment); + transaction.commit(); + } + + Runnable runnable = () -> { + Intent intent = new Intent(IndexActivity.this, TimeService.class); + startService(intent); + }; + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/activity/RegisterActivity.java b/project06_2/app/src/main/java/com/example/orangesale_end/activity/RegisterActivity.java new file mode 100644 index 0000000..6601d99 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/activity/RegisterActivity.java @@ -0,0 +1,176 @@ +package com.example.orangesale_end.activity; + +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.os.Looper; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioGroup; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.lljjcoder.citypickerview.widget.CityPicker; +import com.example.orangesale_end.R; +import com.example.orangesale_end.entity.OrangeUser; +import com.example.orangesale_end.netrequest.OkHttpUser; + +import java.io.IOException; + +public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { + private EditText usernameEdit, passwordEdit, surePasswordEdit; + private TextView cityText; + private CityPicker cityPicker; + private Button regButton; + private RadioGroup sexGroup; + private String sexStr = "男"; + + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.user_register); + init(); + } + + /** + * 界面组件初始化 + */ + private void init() { + cityText = findViewById(R.id.reg_province); + cityText.setOnClickListener(this); + usernameEdit = findViewById(R.id.reg_username); + passwordEdit = findViewById(R.id.reg_password); + surePasswordEdit = findViewById(R.id.reg_sure_password); + regButton = findViewById(R.id.reg_register); + regButton.setOnClickListener(this); + sexGroup = findViewById(R.id.sex); + sexGroup.setOnCheckedChangeListener(this); + + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.reg_province: + initCityPicker(); + cityPicker.show(); + break; + case R.id.reg_register: + //注册验证方法 + //validateRegister(); + Thread thread = new Thread(runnable); + thread.start(); + break; + + } + } + + /** + * 初始化城市选择器 + */ + public void initCityPicker() { + cityPicker = new CityPicker.Builder(RegisterActivity.this) + .textSize(16) + .title("地址选择") + .backgroundPop(0xa0000000) + .titleBackgroundColor("#EFB81C") + .titleTextColor("#000000") + .backgroundPop(0xa0000000) + .confirTextColor("#000000") + .cancelTextColor("#000000") + .province("江西省") + .city("赣州市") + .district("章贡区") + .textColor(Color.parseColor("#000000")) + .provinceCyclic(true) + .cityCyclic(false) + .districtCyclic(false) + .visibleItemsCount(7) + .itemPadding(10) + .onlyShowProvinceAndCity(false) + .build(); + cityPicker.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener() { + @Override + public void onSelected(String... strings) { + String province = strings[0]; + String city = strings[1]; + String district = strings[2]; + cityText.setText(String.format("%s %s %s", province, city, district)); + } + + @Override + public void onCancel() { + } + }); + + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + //根据用户选择来改变sex的值 + sexStr = checkedId == R.id.reg_man ? "男" : "女"; + } + + /** + * 注册验证 + */ + Runnable runnable = new Runnable() { + @Override + public void run() { + String username = usernameEdit.getText().toString(); + String password = passwordEdit.getText().toString(); + String surePassword = surePasswordEdit.getText().toString(); + String city = cityText.getText().toString(); + //判断两次密码是否输入一致 + if (password.equals(surePassword)) { + //这里也可以再进行其它的验证,如是否符合要求等,符合就进行插入数据库操作 + if (!username.equals("") || !password.equals("")) { + if (!city.equals("")) { + Bundle bundle = new Bundle(); + bundle.putString("username", username); + bundle.putString("password", password); + bundle.putString("sex", sexStr); + bundle.putString("city", city); + OrangeUser orangeUser = new OrangeUser(); + orangeUser.setUsername(username); + orangeUser.setPassword(password); + orangeUser.setCity(city); + orangeUser.setSex(sexStr); + //将使用安卓自身带的SQLite数据库换成调用okhttp的方式 + OkHttpUser okHttpUser = new OkHttpUser(); + try { + if (okHttpUser.userRegister(orangeUser)) { + Intent intent = new Intent(RegisterActivity.this, IndexActivity.class); + intent.putExtras(bundle); + startActivity(intent); + } else { + Looper.prepare(); + Toast.makeText(RegisterActivity.this, "注册失败!", Toast.LENGTH_SHORT).show(); + Looper.loop(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else { + Looper.prepare(); + Toast.makeText(RegisterActivity.this, "请选择地址", Toast.LENGTH_SHORT).show(); + Looper.loop(); + } + } else { + Looper.prepare(); + Toast.makeText(RegisterActivity.this, "账号或密码未填写", Toast.LENGTH_SHORT).show(); + Looper.loop(); + } + } else { + Looper.prepare(); + Toast.makeText(RegisterActivity.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show(); + Looper.loop(); + } + } + }; +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/activity/UserActivity.java b/project06_2/app/src/main/java/com/example/orangesale_end/activity/UserActivity.java new file mode 100644 index 0000000..f9ef766 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/activity/UserActivity.java @@ -0,0 +1,66 @@ +package com.example.orangesale_end.activity; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; + +public class UserActivity extends Activity implements View.OnClickListener { + private ImageView userIconImage; + private TextView usernameText, userSexText, userCityText; + private LinearLayout usernameLine, userSexline, userCityLine, userPayLine, userSettingLine, userGeneralLine, userSearchProductLine; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.content_user); + init(); + } + + /** + * 组件初始化 + */ + private void init() { + userIconImage = findViewById(R.id.user_icon); + usernameText = findViewById(R.id.user_username); + userSexText = findViewById(R.id.user_sex); + userCityText = findViewById(R.id.user_city); + usernameLine = findViewById(R.id.user_username_line); + userSexline = findViewById(R.id.user_sex_line); + userCityLine = findViewById(R.id.user_city_line); + userPayLine = findViewById(R.id.user_pay); + userSettingLine = findViewById(R.id.user_setting); + userGeneralLine = findViewById(R.id.user_general); +// userSearchProductLine = findViewById(R.id.user_searchProduct); + userSearchProductLine.setOnClickListener(this); + setData(); + } + + /** + * 组件赋值 + */ + private void setData() { + Intent intent = UserActivity.this.getIntent(); + Bundle bundle = intent.getExtras(); + usernameText.setText(String.format("用户名:%s", bundle.getString("username"))); + userSexText.setText(String.format("性别:%s", bundle.getString("sex"))); + userCityText.setText(String.format("城市:%s", bundle.getString("city"))); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + /*case R.id.user_searchProduct: + Intent intent1 = new Intent(UserActivity.this, CategoryActivity.class); + startActivity(intent1); + break;*/ + } + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/adapter/Adapter.java b/project06_2/app/src/main/java/com/example/orangesale_end/adapter/Adapter.java new file mode 100644 index 0000000..7b5b02e --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/adapter/Adapter.java @@ -0,0 +1,69 @@ +package com.example.orangesale_end.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.example.orangesale_end.R; + +import java.util.List; + +public class Adapter extends BaseAdapter { + private List productCategory; + private LayoutInflater layoutInflater; + private int selectionPosition = -1; + + public Adapter(List productCategory, Context context) { + this.productCategory = productCategory; + this.layoutInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return productCategory.size(); + } + + @Override + public Object getItem(int position) { + return productCategory.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder = null; + if (convertView == null) { + viewHolder = new ViewHolder(); + convertView = layoutInflater.inflate(R.layout.category_list_item, null); + Log.i("adapts", "getView: " + convertView); + viewHolder.tv = convertView.findViewById(R.id.categor_titles); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + viewHolder.tv.setText(productCategory.get(position)); + if (selectionPosition == position) { + viewHolder.tv.setBackgroundColor(Color.YELLOW); + } else { + viewHolder.tv.setBackgroundColor(Color.WHITE); + } + return convertView; + } + + public void setSelectedPosition(int position) { + this.selectionPosition = position; + } + + class ViewHolder { + TextView tv; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/adapter/ListViewAdapter.java b/project06_2/app/src/main/java/com/example/orangesale_end/adapter/ListViewAdapter.java new file mode 100644 index 0000000..39c0e88 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/adapter/ListViewAdapter.java @@ -0,0 +1,78 @@ +package com.example.orangesale_end.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.entity.Condition; + +import java.util.List; + +public class ListViewAdapter extends BaseAdapter { + private List conditionList; + private LayoutInflater layoutInflater; + private int selectedPosition = -1; + private int selectColor = Color.GRAY; + + public ListViewAdapter(Context context, List conditionList) { + this.conditionList = conditionList; + this.layoutInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return conditionList.size(); + } + + @Override + public Object getItem(int position) { + return conditionList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = layoutInflater.inflate(R.layout.product_condition_item, null); + viewHolder = new ViewHolder(); + viewHolder.imageView = convertView.findViewById(R.id.condition_icon); + viewHolder.jiange = convertView.findViewById(R.id.image_jiange); + viewHolder.textView = convertView.findViewById(R.id.condition_name); + viewHolder.linearLayout = convertView.findViewById(R.id.item_bg); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + Condition condition = conditionList.get(position); + if (condition != null) { + viewHolder.imageView.setBackgroundResource(condition.getConditionIcon()); + viewHolder.textView.setText(condition.getConditionName()); + viewHolder.jiange.setBackgroundColor(Color.rgb(207, 207, 207)); + if (selectedPosition == position) { + viewHolder.linearLayout.setBackgroundColor(selectColor); + } + + } + return convertView; + } + + class ViewHolder { + ImageView imageView, jiange; + TextView textView; + LinearLayout linearLayout; + } + + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/adapter/ProductAdapter.java b/project06_2/app/src/main/java/com/example/orangesale_end/adapter/ProductAdapter.java new file mode 100644 index 0000000..72c6f20 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/adapter/ProductAdapter.java @@ -0,0 +1,68 @@ +package com.example.orangesale_end.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.entity.OrangeProductPack; + +import java.util.List; + +public class ProductAdapter extends BaseAdapter { + //private List productList; + private List orangeProductList; + private LayoutInflater layoutInflater; + + public ProductAdapter(Context context, List orangeProductList) { + this.orangeProductList = orangeProductList; + this.layoutInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return orangeProductList.size(); + } + + @Override + public Object getItem(int position) { + return orangeProductList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = layoutInflater.inflate(R.layout.categoty_detail_content, null); + viewHolder = new ViewHolder(); + viewHolder.productImage = convertView.findViewById(R.id.category_product_image); + viewHolder.productName = convertView.findViewById(R.id.category_product_name); + viewHolder.productPrice = convertView.findViewById(R.id.category_product_price); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + OrangeProductPack product = orangeProductList.get(position); + if (product != null) { + viewHolder.productImage.setImageBitmap(product.getImgBitmap()); + viewHolder.productName.setText(product.getName()); + viewHolder.productPrice.setText(String.format("%s元", String.valueOf(product.getPrice()))); + } + return convertView; + } + + class ViewHolder { + ImageView productImage; + TextView productName, productPrice; + } + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/Condition.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/Condition.java new file mode 100644 index 0000000..960bf61 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/Condition.java @@ -0,0 +1,30 @@ +package com.example.orangesale_end.entity; + +public class Condition { + private Integer conditionIcon; + private String conditionName; + + public Integer getConditionIcon() { + return conditionIcon; + } + + public void setConditionIcon(Integer conditionIcon) { + this.conditionIcon = conditionIcon; + } + + public String getConditionName() { + return conditionName; + } + + public void setConditionName(String conditionName) { + this.conditionName = conditionName; + } + + @Override + public String toString() { + return "Condition{" + + "conditionIcon=" + conditionIcon + + ", conditionName='" + conditionName + '\'' + + '}'; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeMessage.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeMessage.java new file mode 100644 index 0000000..eb7a058 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeMessage.java @@ -0,0 +1,52 @@ +package com.example.orangesale_end.entity; + +import java.sql.Timestamp; + +public class OrangeMessage { + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Timestamp getSendTime() { + return sendTime; + } + + public void setSendTime(Timestamp sendTime) { + this.sendTime = sendTime; + } + + public String getUsed() { + return used; + } + + public void setUsed(String used) { + this.used = used; + } + + private Integer id; + private String content; + private Timestamp sendTime; + private String used; + + @Override + public String toString() { + return "OrangeMessage{" + + "id=" + id + + ", content='" + content + '\'' + + ", sendTime=" + sendTime + + ", used='" + used + '\'' + + '}'; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeProduct.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeProduct.java new file mode 100644 index 0000000..6ce06d9 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeProduct.java @@ -0,0 +1,64 @@ +package com.example.orangesale_end.entity; + +import java.math.BigDecimal; +import java.sql.Timestamp; + +public class OrangeProduct { + private Integer id; + private String name; + private BigDecimal price; + private String imgUrl; + + @Override + public String toString() { + return "OrangeProduct{" + + "id=" + id + + ", name='" + name + '\'' + + ", price=" + price + + ", imgUrl='" + imgUrl + '\'' + + ", addTime=" + addTime + + '}'; + } + + public Timestamp getAddTime() { + return addTime; + } + + public void setAddTime(Timestamp addTime) { + this.addTime = addTime; + } + + private Timestamp addTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public String getImgUrl() { + return imgUrl; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeProductPack.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeProductPack.java new file mode 100644 index 0000000..0acf008 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeProductPack.java @@ -0,0 +1,66 @@ +package com.example.orangesale_end.entity; + +import android.graphics.Bitmap; + +import java.math.BigDecimal; +import java.sql.Timestamp; + +public class OrangeProductPack { + private Integer id; + private String name; + private Timestamp addTime; + private Bitmap imgBitmap; + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + private BigDecimal price; + + @Override + public String toString() { + return "OrangeProductPack{" + + "id=" + id + + ", name='" + name + '\'' + + ", addTime=" + addTime + + ", imgBitmap=" + imgBitmap + + ", price=" + price + + '}'; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Timestamp getAddTime() { + return addTime; + } + + public void setAddTime(Timestamp addTime) { + this.addTime = addTime; + } + + public Bitmap getImgBitmap() { + return imgBitmap; + } + + public void setImgBitmap(Bitmap imgBitmap) { + this.imgBitmap = imgBitmap; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeUser.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeUser.java new file mode 100644 index 0000000..91c6ffc --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/OrangeUser.java @@ -0,0 +1,59 @@ +package com.example.orangesale_end.entity; + +public class OrangeUser { + private Integer id; + private String username; + private String password; + private String sex; + private String city; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + @Override + public String toString() { + return "OrangeUser{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + ", sex='" + sex + '\'' + + ", city='" + city + '\'' + + '}'; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/Product.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/Product.java new file mode 100644 index 0000000..f762103 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/Product.java @@ -0,0 +1,43 @@ +package com.example.orangesale_end.entity; + +import java.math.BigDecimal; + +public class Product { + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public BigDecimal getProductPrice() { + return productPrice; + } + + public void setProductPrice(BigDecimal productPrice) { + this.productPrice = productPrice; + } + + public Integer getImageUrlId() { + return imageUrlId; + } + + public void setImageUrlId(Integer imageUrlId) { + this.imageUrlId = imageUrlId; + } + + private Integer imageUrlId; + private String productName; + private BigDecimal productPrice; + + @Override + public String toString() { + return "Product{" + + "imageUrlId=" + imageUrlId + + ", productName='" + productName + '\'' + + ", productPrice=" + productPrice + + '}'; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/entity/ShoppingCart.java b/project06_2/app/src/main/java/com/example/orangesale_end/entity/ShoppingCart.java new file mode 100644 index 0000000..fe38c7c --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/entity/ShoppingCart.java @@ -0,0 +1,44 @@ +package com.example.orangesale_end.entity; + +public class ShoppingCart { + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Integer getProductId() { + return ProductId; + } + + public void setProductId(Integer productId) { + ProductId = productId; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + private Integer id; + private Integer userId; + private Integer ProductId; + /** + * 购买数量 + */ + private Integer number; +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/fragment/IndexFragment.java b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/IndexFragment.java new file mode 100644 index 0000000..76a008d --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/IndexFragment.java @@ -0,0 +1,137 @@ +package com.example.orangesale_end.fragment; + +import android.app.Fragment; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.GridView; +import android.widget.LinearLayout; +import android.widget.SearchView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.adapter.ProductAdapter; +import com.example.orangesale_end.entity.OrangeProductPack; +import com.example.orangesale_end.entity.Product; +import com.example.orangesale_end.netrequest.OkHttpClientProduct; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + + +public class IndexFragment extends Fragment implements View.OnClickListener { + private SearchView searchView; + private LinearLayout orangeLine, youziLine, juziLine, xiguaLine, liLine, appleLine, lemonLine, mangguoLine; + private GridView gridView; + private ProductAdapter productAdapter; + private List productList; + private List list = new ArrayList<>(); + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index, container, false); + init(view); + return view; + } + + /** + * 初始化组件 + */ + private void init(View view) { + searchView = view.findViewById(R.id.searchView); + searchView.setOnClickListener(this); + orangeLine = view.findViewById(R.id.chengzi); + orangeLine.setOnClickListener(this); + youziLine = view.findViewById(R.id.youzi); + youziLine.setOnClickListener(this); + juziLine = view.findViewById(R.id.juzi); + juziLine.setOnClickListener(this); + xiguaLine = view.findViewById(R.id.xigua); + xiguaLine.setOnClickListener(this); + liLine = view.findViewById(R.id.li); + liLine.setOnClickListener(this); + lemonLine = view.findViewById(R.id.lemon); + lemonLine.setOnClickListener(this); + mangguoLine = view.findViewById(R.id.mangguo); + mangguoLine.setOnClickListener(this); + appleLine = view.findViewById(R.id.apple); + appleLine.setOnClickListener(this); + gridView = view.findViewById(R.id.index_famous_gridview); + //initData(); + new SearchProductTask().execute(); + } + + + @Override + public void onClick(View v) { + + } + + /** + * 初始化商品数据 + */ + private void initData() { + productList = new ArrayList<>(); + Product product = new Product(); + product.setImageUrlId(R.drawable.taocan1); + product.setProductName("熟食龙虾套餐一"); + product.setProductPrice(new BigDecimal("29.9")); + Product product1 = new Product(); + product1.setImageUrlId(R.drawable.taocan2); + product1.setProductName("熟食龙虾套餐二"); + product1.setProductPrice(new BigDecimal("19.9")); + Product product2 = new Product(); + product2.setImageUrlId(R.drawable.youzip); + product2.setProductName("柚子"); + product2.setProductPrice(new BigDecimal("19.9")); + Product product3 = new Product(); + product3.setImageUrlId(R.drawable.xiguap); + product3.setProductName("西瓜"); + product3.setProductPrice(new BigDecimal("19.9")); + Product product4 = new Product(); + product4.setImageUrlId(R.drawable.applep); + product4.setProductName("苹果"); + product4.setProductPrice(new BigDecimal("49.9")); + Product product5 = new Product(); + product5.setImageUrlId(R.drawable.lemonp); + product5.setProductName("柠檬"); + product5.setProductPrice(new BigDecimal("9.9")); + productList.add(product); + productList.add(product1); + productList.add(product2); + productList.add(product3); + productList.add(product4); + productList.add(product5); + + } + + /** + * 发送网络请求获取数据 + */ + class SearchProductTask extends AsyncTask> { + + @Override + protected List doInBackground(Void... voids) { + OkHttpClientProduct clientProduct = new OkHttpClientProduct(); + try { + list = clientProduct.getProductPack(); + } catch (IOException e) { + e.printStackTrace(); + } + return list; + } + + @Override + protected void onPostExecute(List orangeProducts) { + productAdapter = new ProductAdapter(getActivity(), list); + gridView.setAdapter(productAdapter); + } + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/fragment/PearsonFragment.java b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/PearsonFragment.java new file mode 100644 index 0000000..0f3e8de --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/PearsonFragment.java @@ -0,0 +1,64 @@ +package com.example.orangesale_end.fragment; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; + +public class PearsonFragment extends Fragment implements View.OnClickListener { + private ImageView userIconImage; + private TextView usernameText, userSexText, userCityText; + private LinearLayout usernameLine, userSexline, userCityLine, userPayLine, userSettingLine, userGeneralLine; + + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_user, container, false); + init(view); + return view; + } + + /** + * 组件初始化 + */ + private void init(View view) { + userIconImage = view.findViewById(R.id.user_icon); + usernameText = view.findViewById(R.id.user_username); + userSexText = view.findViewById(R.id.user_sex); + userCityText = view.findViewById(R.id.user_city); + usernameLine = view.findViewById(R.id.user_username_line); + userSexline = view.findViewById(R.id.user_sex_line); + userCityLine = view.findViewById(R.id.user_city_line); + userPayLine = view.findViewById(R.id.user_pay); + userSettingLine = view.findViewById(R.id.user_setting); + userGeneralLine = view.findViewById(R.id.user_general); + setData(); + } + + /** + * 组件赋值 + */ + private void setData() { + Bundle bundle = getArguments(); + usernameText.setText(String.format("用户名:%s", bundle.getString("username"))); + userSexText.setText(String.format("性别:%s", bundle.getString("sex"))); + userCityText.setText(String.format("城市:%s", bundle.getString("city"))); + } + + @Override + public void onClick(View v) { + + } + + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/fragment/ProductFragment.java b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/ProductFragment.java new file mode 100644 index 0000000..5d6fc86 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/ProductFragment.java @@ -0,0 +1,102 @@ +package com.example.orangesale_end.fragment; + +import android.app.Fragment; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.GridView; +import android.widget.Spinner; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.adapter.ListViewAdapter; +import com.example.orangesale_end.adapter.ProductAdapter; +import com.example.orangesale_end.entity.Condition; +import com.example.orangesale_end.entity.OrangeProductPack; +import com.example.orangesale_end.netrequest.OkHttpClientProduct; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ProductFragment extends Fragment { + private Spinner conditonListSpinner; + private ListViewAdapter listViewAdapter; + private List conditionList; + private GridView productGridView; + private List orangeProductList = new ArrayList<>(); + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false); + init(view); + return view; + } + + /** + * 组件初始化方法 + * + * @param view + */ + private void init(View view) { + conditonListSpinner = view.findViewById(R.id.product_select_condition); + initCondList(); + listViewAdapter = new ListViewAdapter(getActivity(), conditionList); + conditonListSpinner.setAdapter(listViewAdapter); + productGridView = view.findViewById(R.id.product_list); + new SearchProductTask().execute(); + } + + /** + * 初始化conditionList + */ + private void initCondList() { + conditionList = new ArrayList<>(); + Condition allCondition = new Condition(); + allCondition.setConditionIcon(R.drawable.all); + allCondition.setConditionName("全部"); + Condition saleCondition = new Condition(); + saleCondition.setConditionIcon(R.drawable.salenum); + saleCondition.setConditionName("按销量高低排序"); + Condition timeCondition = new Condition(); + timeCondition.setConditionIcon(R.drawable.time); + timeCondition.setConditionName("按上市时间排序"); + Condition priceCondition = new Condition(); + priceCondition.setConditionIcon(R.drawable.price); + priceCondition.setConditionName("按商品价格排序"); + conditionList.add(allCondition); + conditionList.add(saleCondition); + conditionList.add(timeCondition); + conditionList.add(priceCondition); + } + + /** + * 发送网络请求获取数据 + */ + class SearchProductTask extends AsyncTask> { + + @Override + protected List doInBackground(Void... voids) { + OkHttpClientProduct clientProduct = new OkHttpClientProduct(); + try { + orangeProductList = clientProduct.getProductPack(); + } catch (IOException e) { + e.printStackTrace(); + } + return orangeProductList; + } + + @Override + protected void onPostExecute(List orangeProducts) { + ProductAdapter productAdapter = new ProductAdapter(getActivity(), orangeProductList); + productGridView.setAdapter(productAdapter); + } + } + + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/fragment/SetDetailFragment.java b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/SetDetailFragment.java new file mode 100644 index 0000000..211082d --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/SetDetailFragment.java @@ -0,0 +1,53 @@ +package com.example.orangesale_end.fragment; + +import android.annotation.SuppressLint; +import android.app.Fragment; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.activity.CategoryActivity; + +import java.util.Objects; + +public class SetDetailFragment extends Fragment { + private View view; + private ImageView imageView; + private TextView nameText, priceText; + + @SuppressLint("SetTextI18n") + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + view = inflater.inflate(R.layout.categoty_detail_content, container, false); + if (view != null) { + init(); + } + CategoryActivity categoryActivity = (CategoryActivity) getActivity(); + Objects.requireNonNull(categoryActivity).setOnChangeListener(product -> { + Log.i("sss", "onCreateView: " + product.getProductName()); + imageView.setBackgroundResource(product.getImageUrlId()); + nameText.setText(product.getProductName()); + priceText.setText(product.getProductPrice().toString()); + }); + return view; + } + + /** + * 内容组件初始化 + */ + private void init() { + imageView = view.findViewById(R.id.category_product_image); + nameText = view.findViewById(R.id.category_product_name); + priceText = view.findViewById(R.id.category_product_price); + } + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/fragment/ShoppingCartFragment.java b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/ShoppingCartFragment.java new file mode 100644 index 0000000..f37faae --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/fragment/ShoppingCartFragment.java @@ -0,0 +1,61 @@ +package com.example.orangesale_end.fragment; + +import android.app.Fragment; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.entity.ShoppingCart; + +import java.util.ArrayList; +import java.util.List; + +public class ShoppingCartFragment extends Fragment implements View.OnClickListener { + private Button walkButton; + private List cartList = new ArrayList<>(); + private ProductFragment productFragment; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view; + if (cartList.size() > 0) { + //有商品 + view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_have_product, container, false); + } else { + view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_no_product, container, false); + } + init(view); + return view; + } + + /** + * 组件初始化 + */ + private void init(View view) { + walkButton = view.findViewById(R.id.random_search); + walkButton.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.random_search: + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (productFragment == null) { + productFragment = new ProductFragment(); + } + transaction.replace(R.id.main_content0, productFragment); + transaction.commit(); + break; + } + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpClientProduct.java b/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpClientProduct.java new file mode 100644 index 0000000..dcf1d7c --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpClientProduct.java @@ -0,0 +1,80 @@ +package com.example.orangesale_end.netrequest; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.example.orangesale_end.entity.OrangeProduct; +import com.example.orangesale_end.entity.OrangeProductPack; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class OkHttpClientProduct { + + /** + * 查询商品信息 + * + * @return + */ + public List getProduct() throws IOException { + OkHttpClient okHttpClient = new OkHttpClient(); + Request request = new Request.Builder() + .url("http://10.21.244.195:8081/orange/product/search") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(response.body()).string()); + List list = JSON.parseObject(jsonObject.getString("data"), new TypeReference>() { + }); + return list; + } + + /** + * 获取图片 + * + * @param imgUrl + * @return + * @throws IOException + */ + public Bitmap getImageBitMap(String imgUrl) throws IOException { + Bitmap bitmap; + OkHttpClient okHttpClient = new OkHttpClient(); + Request request = new Request.Builder() + .url(imgUrl) + .build(); + Response response = okHttpClient.newCall(request).execute(); + byte[] bytes = Objects.requireNonNull(response.body()).bytes(); + bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + return bitmap; + + } + + /** + * 封装信息 + * + * @return + * @throws IOException + */ + + public List getProductPack() throws IOException { + List packList = new ArrayList<>(); + List list = getProduct(); + for (OrangeProduct orangeProduct : list) { + OrangeProductPack orangeProductPack = new OrangeProductPack(); + orangeProductPack.setId(orangeProduct.getId()); + orangeProductPack.setImgBitmap(getImageBitMap(orangeProduct.getImgUrl())); + orangeProductPack.setAddTime(orangeProduct.getAddTime()); + orangeProductPack.setPrice(orangeProduct.getPrice()); + packList.add(orangeProductPack); + } + return packList; + } +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpMessage.java b/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpMessage.java new file mode 100644 index 0000000..47af199 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpMessage.java @@ -0,0 +1,39 @@ +package com.example.orangesale_end.netrequest; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.example.orangesale_end.entity.OrangeMessage; + +import java.io.IOException; +import java.util.Objects; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class OkHttpMessage { + + /** + * 消费消息 + * + * @return + */ + public OrangeMessage consumeMessage() throws IOException { + OkHttpClient okHttpClient = new OkHttpClient(); + Request request = new Request.Builder() + .url("http://10.21.244.195:8081/orange/message/consumeMessage") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(Objects.requireNonNull(response.body()).string()); + OrangeMessage orangeMessage = JSON.toJavaObject(jsonObject.getJSONObject("data"), OrangeMessage.class); + /** + * 消费完消息以后,设置消息为已读 + */ + Request request1 = new Request.Builder() + .url("http://10.21.244.195:8081/orange/message/updateMessage") + .build(); + okHttpClient.newCall(request1).execute(); + return orangeMessage; + } + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpUser.java b/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpUser.java new file mode 100644 index 0000000..8560764 --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/netrequest/OkHttpUser.java @@ -0,0 +1,71 @@ +package com.example.orangesale_end.netrequest; + +import android.util.Log; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.example.orangesale_end.entity.OrangeUser; + +import java.io.IOException; + +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class OkHttpUser { + /** + * 用户登录验证 + * + * @param orangeUser + */ + public OrangeUser userLogin(OrangeUser orangeUser) throws IOException { + OkHttpClient okHttpClient= new OkHttpClient(); + //数据类型为json格式 + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + //将对象转为JSON字符串 + String jsonStr = JSONObject.toJSONString(orangeUser); + + RequestBody requestBody = RequestBody.create(jsonStr, mediaType); + Request request = new Request.Builder() + .url("http://10.21.244.195:8081/orange/user/login") + .post(requestBody) + .build(); + + Response response = okHttpClient.newCall(request).execute(); + + String responseStr = response.body().string(); + System.out.println("responseStr = " + responseStr); + JSONObject jsonObject = JSON.parseObject(responseStr); + JSONObject jsonObject1 = jsonObject.getJSONObject("data"); + OrangeUser orangeUser1 = JSON.toJavaObject(jsonObject1, OrangeUser.class); + return orangeUser1; + } + + /** + * 用户注册 + * + * @param orangeUser + * @return + * @throws IOException + */ + public boolean userRegister(OrangeUser orangeUser) throws IOException { + OkHttpClient okHttpClient = new OkHttpClient(); + //数据类型为json格式 + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + //将对象转为JSON字符串 + String jsonStr = JSONObject.toJSONString(orangeUser); + RequestBody requestBody = RequestBody.create(jsonStr, mediaType); + Request request = new Request.Builder() + .url("http://10.21.244.195:8081/orange/user/register") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + Log.i("register", "userRegister: "+jsonObject); + return jsonObject.getBoolean("flag"); + } + + +} diff --git a/project06_2/app/src/main/java/com/example/orangesale_end/service/TimeService.java b/project06_2/app/src/main/java/com/example/orangesale_end/service/TimeService.java new file mode 100644 index 0000000..ceecacc --- /dev/null +++ b/project06_2/app/src/main/java/com/example/orangesale_end/service/TimeService.java @@ -0,0 +1,105 @@ +package com.example.orangesale_end.service; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; +import android.os.IBinder; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.core.app.NotificationCompat; + +import com.example.orangesale_end.R; +import com.example.orangesale_end.entity.OrangeMessage; +import com.example.orangesale_end.netrequest.OkHttpMessage; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Objects; +import java.util.Timer; +import java.util.TimerTask; + +public class TimeService extends Service { + private static Timer timer = null; + private NotificationManager manager; + private NotificationCompat.Builder builder; + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + /** + * 清除通知 + */ + private void cleanAllNotification() { + manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + manager.cancelAll(); + if (timer != null) { + timer.cancel(); + timer = null; + } + + } + + /** + * 添加通知 + */ + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + long period = 60 * 1000; //1分钟一个周期 + if (timer == null) { + timer = new Timer(); + } + timer.schedule(new TimerTask() { + @Override + public void run() { + new ConsumeMessageTask().execute(); + } + }, 0, period); + + return super.onStartCommand(intent, flags, startId); + } + + class ConsumeMessageTask extends AsyncTask { + @Override + protected Void doInBackground(Void... voids) { + /** + * NotificationChannel是android8.0新增的特性,如果App的targetSDKVersion>=26, + * 没有设置channel通知渠道的话,就会导致通知无法展示。 + * 报错内容:Failed to post notification on channel “null” + */ + OkHttpMessage okHttpMessage = new OkHttpMessage(); + OrangeMessage orangeMessage; + try { + orangeMessage = okHttpMessage.consumeMessage(); + if (!Objects.isNull(orangeMessage)) { + Log.i("orangeMessage", "run: " + orangeMessage.toString()); + NotificationChannel channel = new NotificationChannel("channel", "通知", NotificationManager.IMPORTANCE_DEFAULT); + manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + manager.createNotificationChannel(channel); + builder = new NotificationCompat.Builder(TimeService.this); + Date date = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + builder.setContentTitle("来自橙一色的系统通知消息" + " " + formatter.format(date)); + builder.setSmallIcon(R.drawable.chengzi); + builder.setChannelId("channel"); + builder.setContentText(orangeMessage.getContent()); + builder.setAutoCancel(true); + builder.setDefaults(Notification.DEFAULT_ALL); + Notification notification = builder.build(); + manager.notify(1, notification); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + } +} diff --git a/project06_2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/project06_2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/project06_2/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/project06_2/app/src/main/res/drawable/address.png b/project06_2/app/src/main/res/drawable/address.png new file mode 100644 index 0000000..7318be0 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/address.png differ diff --git a/project06_2/app/src/main/res/drawable/all.png b/project06_2/app/src/main/res/drawable/all.png new file mode 100644 index 0000000..131c4fd Binary files /dev/null and b/project06_2/app/src/main/res/drawable/all.png differ diff --git a/project06_2/app/src/main/res/drawable/apple.png b/project06_2/app/src/main/res/drawable/apple.png new file mode 100644 index 0000000..0810381 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/apple.png differ diff --git a/project06_2/app/src/main/res/drawable/applep.png b/project06_2/app/src/main/res/drawable/applep.png new file mode 100644 index 0000000..e26da47 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/applep.png differ diff --git a/project06_2/app/src/main/res/drawable/arrow_down.png b/project06_2/app/src/main/res/drawable/arrow_down.png new file mode 100644 index 0000000..6d95bb5 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/arrow_down.png differ diff --git a/project06_2/app/src/main/res/drawable/arrow_left.png b/project06_2/app/src/main/res/drawable/arrow_left.png new file mode 100644 index 0000000..365afe0 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/arrow_left.png differ diff --git a/project06_2/app/src/main/res/drawable/arrow_right.png b/project06_2/app/src/main/res/drawable/arrow_right.png new file mode 100644 index 0000000..84ded85 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/arrow_right.png differ diff --git a/project06_2/app/src/main/res/drawable/button_login.xml b/project06_2/app/src/main/res/drawable/button_login.xml new file mode 100644 index 0000000..d093f1b --- /dev/null +++ b/project06_2/app/src/main/res/drawable/button_login.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/drawable/button_register.xml b/project06_2/app/src/main/res/drawable/button_register.xml new file mode 100644 index 0000000..3eb0673 --- /dev/null +++ b/project06_2/app/src/main/res/drawable/button_register.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/drawable/cart.png b/project06_2/app/src/main/res/drawable/cart.png new file mode 100644 index 0000000..f2e1190 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/cart.png differ diff --git a/project06_2/app/src/main/res/drawable/chengzi.png b/project06_2/app/src/main/res/drawable/chengzi.png new file mode 100644 index 0000000..fff0306 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/chengzi.png differ diff --git a/project06_2/app/src/main/res/drawable/city.png b/project06_2/app/src/main/res/drawable/city.png new file mode 100644 index 0000000..790fb2b Binary files /dev/null and b/project06_2/app/src/main/res/drawable/city.png differ diff --git a/project06_2/app/src/main/res/drawable/hehuo.png b/project06_2/app/src/main/res/drawable/hehuo.png new file mode 100644 index 0000000..c5a1e75 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/hehuo.png differ diff --git a/project06_2/app/src/main/res/drawable/ic_launcher_background.xml b/project06_2/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/project06_2/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/project06_2/app/src/main/res/drawable/ic_launcher_foreground.xml b/project06_2/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/project06_2/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/project06_2/app/src/main/res/drawable/index.png b/project06_2/app/src/main/res/drawable/index.png new file mode 100644 index 0000000..cc1ec04 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/index.png differ diff --git a/project06_2/app/src/main/res/drawable/index_menu.xml b/project06_2/app/src/main/res/drawable/index_menu.xml new file mode 100644 index 0000000..14636dd --- /dev/null +++ b/project06_2/app/src/main/res/drawable/index_menu.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/drawable/juzi.png b/project06_2/app/src/main/res/drawable/juzi.png new file mode 100644 index 0000000..106df92 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/juzi.png differ diff --git a/project06_2/app/src/main/res/drawable/juzip.png b/project06_2/app/src/main/res/drawable/juzip.png new file mode 100644 index 0000000..4f10b72 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/juzip.png differ diff --git a/project06_2/app/src/main/res/drawable/lemon.png b/project06_2/app/src/main/res/drawable/lemon.png new file mode 100644 index 0000000..39f12cc Binary files /dev/null and b/project06_2/app/src/main/res/drawable/lemon.png differ diff --git a/project06_2/app/src/main/res/drawable/lemonp.png b/project06_2/app/src/main/res/drawable/lemonp.png new file mode 100644 index 0000000..ca5eca8 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/lemonp.png differ diff --git a/project06_2/app/src/main/res/drawable/li.png b/project06_2/app/src/main/res/drawable/li.png new file mode 100644 index 0000000..0834592 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/li.png differ diff --git a/project06_2/app/src/main/res/drawable/mala.png b/project06_2/app/src/main/res/drawable/mala.png new file mode 100644 index 0000000..60f56c2 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/mala.png differ diff --git a/project06_2/app/src/main/res/drawable/mangguo.png b/project06_2/app/src/main/res/drawable/mangguo.png new file mode 100644 index 0000000..2e9825c Binary files /dev/null and b/project06_2/app/src/main/res/drawable/mangguo.png differ diff --git a/project06_2/app/src/main/res/drawable/orange.png b/project06_2/app/src/main/res/drawable/orange.png new file mode 100644 index 0000000..70e8db8 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/orange.png differ diff --git a/project06_2/app/src/main/res/drawable/pangxie.png b/project06_2/app/src/main/res/drawable/pangxie.png new file mode 100644 index 0000000..279d440 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/pangxie.png differ diff --git a/project06_2/app/src/main/res/drawable/password.png b/project06_2/app/src/main/res/drawable/password.png new file mode 100644 index 0000000..1c6c4f5 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/password.png differ diff --git a/project06_2/app/src/main/res/drawable/pearson.png b/project06_2/app/src/main/res/drawable/pearson.png new file mode 100644 index 0000000..90cf0eb Binary files /dev/null and b/project06_2/app/src/main/res/drawable/pearson.png differ diff --git a/project06_2/app/src/main/res/drawable/price.png b/project06_2/app/src/main/res/drawable/price.png new file mode 100644 index 0000000..c7a125c Binary files /dev/null and b/project06_2/app/src/main/res/drawable/price.png differ diff --git a/project06_2/app/src/main/res/drawable/product.png b/project06_2/app/src/main/res/drawable/product.png new file mode 100644 index 0000000..8f5cb21 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/product.png differ diff --git a/project06_2/app/src/main/res/drawable/salenum.png b/project06_2/app/src/main/res/drawable/salenum.png new file mode 100644 index 0000000..87ed2c9 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/salenum.png differ diff --git a/project06_2/app/src/main/res/drawable/search.png b/project06_2/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..a8b5ac0 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/search.png differ diff --git a/project06_2/app/src/main/res/drawable/setting.png b/project06_2/app/src/main/res/drawable/setting.png new file mode 100644 index 0000000..34c2f2f Binary files /dev/null and b/project06_2/app/src/main/res/drawable/setting.png differ diff --git a/project06_2/app/src/main/res/drawable/sex.png b/project06_2/app/src/main/res/drawable/sex.png new file mode 100644 index 0000000..acb8197 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/sex.png differ diff --git a/project06_2/app/src/main/res/drawable/shoppingcart.png b/project06_2/app/src/main/res/drawable/shoppingcart.png new file mode 100644 index 0000000..76c06de Binary files /dev/null and b/project06_2/app/src/main/res/drawable/shoppingcart.png differ diff --git a/project06_2/app/src/main/res/drawable/shuiguo.png b/project06_2/app/src/main/res/drawable/shuiguo.png new file mode 100644 index 0000000..d316137 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/shuiguo.png differ diff --git a/project06_2/app/src/main/res/drawable/shushi.png b/project06_2/app/src/main/res/drawable/shushi.png new file mode 100644 index 0000000..7bcaadd Binary files /dev/null and b/project06_2/app/src/main/res/drawable/shushi.png differ diff --git a/project06_2/app/src/main/res/drawable/spinner_drop_down_shape.xml b/project06_2/app/src/main/res/drawable/spinner_drop_down_shape.xml new file mode 100644 index 0000000..64306b1 --- /dev/null +++ b/project06_2/app/src/main/res/drawable/spinner_drop_down_shape.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/drawable/sudong.png b/project06_2/app/src/main/res/drawable/sudong.png new file mode 100644 index 0000000..27f5fa5 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/sudong.png differ diff --git a/project06_2/app/src/main/res/drawable/sure_apssword.png b/project06_2/app/src/main/res/drawable/sure_apssword.png new file mode 100644 index 0000000..0e7cee9 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/sure_apssword.png differ diff --git a/project06_2/app/src/main/res/drawable/tab_menu_text.xml b/project06_2/app/src/main/res/drawable/tab_menu_text.xml new file mode 100644 index 0000000..fb06945 --- /dev/null +++ b/project06_2/app/src/main/res/drawable/tab_menu_text.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/drawable/taocan1.png b/project06_2/app/src/main/res/drawable/taocan1.png new file mode 100644 index 0000000..59ec919 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/taocan1.png differ diff --git a/project06_2/app/src/main/res/drawable/taocan2.png b/project06_2/app/src/main/res/drawable/taocan2.png new file mode 100644 index 0000000..0f721da Binary files /dev/null and b/project06_2/app/src/main/res/drawable/taocan2.png differ diff --git a/project06_2/app/src/main/res/drawable/tiaoliao.png b/project06_2/app/src/main/res/drawable/tiaoliao.png new file mode 100644 index 0000000..2092c92 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/tiaoliao.png differ diff --git a/project06_2/app/src/main/res/drawable/time.png b/project06_2/app/src/main/res/drawable/time.png new file mode 100644 index 0000000..8a672eb Binary files /dev/null and b/project06_2/app/src/main/res/drawable/time.png differ diff --git a/project06_2/app/src/main/res/drawable/user.png b/project06_2/app/src/main/res/drawable/user.png new file mode 100644 index 0000000..47d8362 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/user.png differ diff --git a/project06_2/app/src/main/res/drawable/user_account.png b/project06_2/app/src/main/res/drawable/user_account.png new file mode 100644 index 0000000..e70142a Binary files /dev/null and b/project06_2/app/src/main/res/drawable/user_account.png differ diff --git a/project06_2/app/src/main/res/drawable/user_general.png b/project06_2/app/src/main/res/drawable/user_general.png new file mode 100644 index 0000000..cf57947 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/user_general.png differ diff --git a/project06_2/app/src/main/res/drawable/user_icon.png b/project06_2/app/src/main/res/drawable/user_icon.png new file mode 100644 index 0000000..d5309b1 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/user_icon.png differ diff --git a/project06_2/app/src/main/res/drawable/user_pay.png b/project06_2/app/src/main/res/drawable/user_pay.png new file mode 100644 index 0000000..3fd6f50 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/user_pay.png differ diff --git a/project06_2/app/src/main/res/drawable/user_sex.png b/project06_2/app/src/main/res/drawable/user_sex.png new file mode 100644 index 0000000..da0e318 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/user_sex.png differ diff --git a/project06_2/app/src/main/res/drawable/xianhuo.png b/project06_2/app/src/main/res/drawable/xianhuo.png new file mode 100644 index 0000000..d1c77ef Binary files /dev/null and b/project06_2/app/src/main/res/drawable/xianhuo.png differ diff --git a/project06_2/app/src/main/res/drawable/xigua.png b/project06_2/app/src/main/res/drawable/xigua.png new file mode 100644 index 0000000..20275c1 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/xigua.png differ diff --git a/project06_2/app/src/main/res/drawable/xiguap.png b/project06_2/app/src/main/res/drawable/xiguap.png new file mode 100644 index 0000000..b760712 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/xiguap.png differ diff --git a/project06_2/app/src/main/res/drawable/yangzhi.png b/project06_2/app/src/main/res/drawable/yangzhi.png new file mode 100644 index 0000000..055a8df Binary files /dev/null and b/project06_2/app/src/main/res/drawable/yangzhi.png differ diff --git a/project06_2/app/src/main/res/drawable/youzi.png b/project06_2/app/src/main/res/drawable/youzi.png new file mode 100644 index 0000000..53df959 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/youzi.png differ diff --git a/project06_2/app/src/main/res/drawable/youzip.png b/project06_2/app/src/main/res/drawable/youzip.png new file mode 100644 index 0000000..5a7d966 Binary files /dev/null and b/project06_2/app/src/main/res/drawable/youzip.png differ diff --git a/project06_2/app/src/main/res/layout/activity_main.xml b/project06_2/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..0352b13 --- /dev/null +++ b/project06_2/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/layout/cart_have_product.xml b/project06_2/app/src/main/res/layout/cart_have_product.xml new file mode 100644 index 0000000..b7362e4 --- /dev/null +++ b/project06_2/app/src/main/res/layout/cart_have_product.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/project06_2/app/src/main/res/layout/cart_no_product.xml b/project06_2/app/src/main/res/layout/cart_no_product.xml new file mode 100644 index 0000000..8781e18 --- /dev/null +++ b/project06_2/app/src/main/res/layout/cart_no_product.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + +