[init]
This commit is contained in:
commit
5462e706fd
|
|
@ -0,0 +1,2 @@
|
|||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### 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/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# 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
|
||||
#
|
||||
# http://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.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
#!/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
|
||||
#
|
||||
# http://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.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
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"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||
|
||||
exec_maven() {
|
||||
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||
}
|
||||
|
||||
if [ -d "$MAVEN_HOME" ]; then
|
||||
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
exec_maven "$@"
|
||||
fi
|
||||
|
||||
case "${distributionUrl-}" in
|
||||
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||
esac
|
||||
|
||||
# prepare tmp dir
|
||||
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||
trap clean HUP INT TERM EXIT
|
||||
else
|
||||
die "cannot create temp dir"
|
||||
fi
|
||||
|
||||
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||
|
||||
# Download and Install Apache Maven
|
||||
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
verbose "Downloading from: $distributionUrl"
|
||||
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
# select .zip or .tar.gz
|
||||
if ! command -v unzip >/dev/null; then
|
||||
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
fi
|
||||
|
||||
# verbose opt
|
||||
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||
|
||||
# normalize http auth
|
||||
case "${MVNW_PASSWORD:+has-password}" in
|
||||
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
esac
|
||||
|
||||
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||
verbose "Found wget ... using wget"
|
||||
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||
verbose "Found curl ... using curl"
|
||||
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||
elif set_java_home; then
|
||||
verbose "Falling back to use Java to download"
|
||||
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
cat >"$javaSource" <<-END
|
||||
public class Downloader extends java.net.Authenticator
|
||||
{
|
||||
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||
}
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
setDefault( new Downloader() );
|
||||
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||
}
|
||||
}
|
||||
END
|
||||
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||
verbose " - Compiling Downloader.java ..."
|
||||
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||
verbose " - Running Downloader.java ..."
|
||||
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||
fi
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
if [ -n "${distributionSha256Sum-}" ]; then
|
||||
distributionSha256Result=false
|
||||
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
elif command -v sha256sum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
elif command -v shasum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $distributionSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# unzip and move
|
||||
if command -v unzip >/dev/null; then
|
||||
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||
else
|
||||
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||
fi
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
<# : batch portion
|
||||
@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 http://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 Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||
}
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.3</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.waterquality</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>project</name>
|
||||
<description>project</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// WaterQualityApi.java
|
||||
package com.waterquality.api;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication()
|
||||
public class WaterQualityApi {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WaterQualityApi.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
// RiverController.java
|
||||
package com.waterquality.api.controller;
|
||||
|
||||
import com.waterquality.api.entity.River;
|
||||
import com.waterquality.api.service.RiverService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/rivers")
|
||||
public class RiverController {
|
||||
|
||||
private final RiverService riverService;
|
||||
|
||||
@Autowired
|
||||
public RiverController(RiverService riverService) {
|
||||
this.riverService = riverService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<River>> getAllRivers() {
|
||||
return ResponseEntity.ok(riverService.getAllRivers());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<River> getRiverById(@PathVariable Integer id) {
|
||||
return riverService.getRiverById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<River> createRiver(@RequestBody River river) {
|
||||
return new ResponseEntity<>(riverService.saveRiver(river), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<River> updateRiver(@PathVariable Integer id, @RequestBody River river) {
|
||||
return riverService.getRiverById(id)
|
||||
.map(existingRiver -> {
|
||||
river.setRiverId(id);
|
||||
return ResponseEntity.ok(riverService.saveRiver(river));
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteRiver(@PathVariable Integer id) {
|
||||
return riverService.getRiverById(id)
|
||||
.map(river -> {
|
||||
riverService.deleteRiver(id);
|
||||
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// SectionController.java
|
||||
package com.waterquality.api.controller;
|
||||
|
||||
import com.waterquality.api.entity.Section;
|
||||
import com.waterquality.api.service.SectionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/sections")
|
||||
public class SectionController {
|
||||
|
||||
private final SectionService sectionService;
|
||||
|
||||
@Autowired
|
||||
public SectionController(SectionService sectionService) {
|
||||
this.sectionService = sectionService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Section>> getAllSections() {
|
||||
return ResponseEntity.ok(sectionService.getAllSections());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Section> getSectionById(@PathVariable Integer id) {
|
||||
return sectionService.getSectionById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@GetMapping("/river/{riverId}")
|
||||
public ResponseEntity<List<Section>> getSectionsByRiverId(@PathVariable Integer riverId) {
|
||||
return ResponseEntity.ok(sectionService.getSectionsByRiverId(riverId));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Section> createSection(@RequestBody Section section) {
|
||||
return new ResponseEntity<>(sectionService.saveSection(section), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Section> updateSection(@PathVariable Integer id, @RequestBody Section section) {
|
||||
return sectionService.getSectionById(id)
|
||||
.map(existingSection -> {
|
||||
section.setSectionId(id);
|
||||
return ResponseEntity.ok(sectionService.saveSection(section));
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteSection(@PathVariable Integer id) {
|
||||
return sectionService.getSectionById(id)
|
||||
.map(section -> {
|
||||
sectionService.deleteSection(id);
|
||||
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
// WaterQualityDataController.java
|
||||
package com.waterquality.api.controller;
|
||||
|
||||
import com.waterquality.api.dto.WaterQualityStatisticsDTO;
|
||||
import com.waterquality.api.entity.WaterQualityData;
|
||||
import com.waterquality.api.service.WaterQualityDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/water-quality")
|
||||
public class WaterQualityDataController {
|
||||
|
||||
private final WaterQualityDataService waterQualityDataService;
|
||||
|
||||
@Autowired
|
||||
public WaterQualityDataController(WaterQualityDataService waterQualityDataService) {
|
||||
this.waterQualityDataService = waterQualityDataService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<WaterQualityData>> getAllWaterQualityData() {
|
||||
return ResponseEntity.ok(waterQualityDataService.getAllWaterQualityData());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<WaterQualityData> getWaterQualityDataById(@PathVariable Integer id) {
|
||||
return waterQualityDataService.getWaterQualityDataById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@GetMapping("/section/{sectionId}")
|
||||
public ResponseEntity<List<WaterQualityData>> getWaterQualityDataBySectionId(
|
||||
@PathVariable Integer sectionId) {
|
||||
return ResponseEntity.ok(waterQualityDataService.getWaterQualityDataBySectionId(sectionId));
|
||||
}
|
||||
|
||||
@GetMapping("/section/{sectionId}/date-range")
|
||||
public ResponseEntity<List<WaterQualityData>> getWaterQualityDataBySectionIdAndDateRange(
|
||||
@PathVariable Integer sectionId,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
|
||||
return ResponseEntity.ok(
|
||||
waterQualityDataService.getWaterQualityDataBySectionIdAndDateRange(
|
||||
sectionId, startDate, endDate));
|
||||
}
|
||||
|
||||
@GetMapping("/river/{riverId}")
|
||||
public ResponseEntity<List<WaterQualityData>> getWaterQualityDataByRiverId(
|
||||
@PathVariable Integer riverId) {
|
||||
return ResponseEntity.ok(waterQualityDataService.getWaterQualityDataByRiverId(riverId));
|
||||
}
|
||||
|
||||
@GetMapping("/river/{riverId}/date-range")
|
||||
public ResponseEntity<List<WaterQualityData>> getWaterQualityDataByRiverIdAndDateRange(
|
||||
@PathVariable Integer riverId,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
|
||||
return ResponseEntity.ok(
|
||||
waterQualityDataService.getWaterQualityDataByRiverIdAndDateRange(
|
||||
riverId, startDate, endDate));
|
||||
}
|
||||
|
||||
@GetMapping("/section/{sectionId}/statistics")
|
||||
public ResponseEntity<List<WaterQualityStatisticsDTO>> getStatisticsBySectionId(
|
||||
@PathVariable Integer sectionId) {
|
||||
return ResponseEntity.ok(waterQualityDataService.getStatisticsBySectionId(sectionId));
|
||||
}
|
||||
|
||||
@GetMapping("/river/{riverId}/statistics")
|
||||
public ResponseEntity<List<WaterQualityStatisticsDTO>> getStatisticsByRiverId(
|
||||
@PathVariable Integer riverId) {
|
||||
return ResponseEntity.ok(waterQualityDataService.getStatisticsByRiverId(riverId));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<WaterQualityData> createWaterQualityData(
|
||||
@RequestBody WaterQualityData waterQualityData) {
|
||||
return new ResponseEntity<>(
|
||||
waterQualityDataService.saveWaterQualityData(waterQualityData),
|
||||
HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<WaterQualityData> updateWaterQualityData(
|
||||
@PathVariable Integer id,
|
||||
@RequestBody WaterQualityData waterQualityData) {
|
||||
return waterQualityDataService.getWaterQualityDataById(id)
|
||||
.map(existingData -> {
|
||||
waterQualityData.setDataId(id);
|
||||
return ResponseEntity.ok(
|
||||
waterQualityDataService.saveWaterQualityData(waterQualityData));
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteWaterQualityData(@PathVariable Integer id) {
|
||||
return waterQualityDataService.getWaterQualityDataById(id)
|
||||
.map(data -> {
|
||||
waterQualityDataService.deleteWaterQualityData(id);
|
||||
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
|
||||
})
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.waterquality.api.dto;
|
||||
|
||||
// WaterQualityStatisticsDTO.java
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class WaterQualityStatisticsDTO {
|
||||
private String parameter;
|
||||
private BigDecimal average;
|
||||
private BigDecimal min;
|
||||
private BigDecimal max;
|
||||
|
||||
public WaterQualityStatisticsDTO(String parameter, BigDecimal average, BigDecimal min, BigDecimal max) {
|
||||
this.parameter = parameter;
|
||||
this.average = average;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
public void setParameter(String parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public BigDecimal getAverage() {
|
||||
return average;
|
||||
}
|
||||
|
||||
public void setAverage(BigDecimal average) {
|
||||
this.average = average;
|
||||
}
|
||||
|
||||
public BigDecimal getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public void setMin(BigDecimal min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
public BigDecimal getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public void setMax(BigDecimal max) {
|
||||
this.max = max;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.waterquality.api.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Rivers")
|
||||
public class River {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "river_id")
|
||||
private Integer riverId;
|
||||
|
||||
@Column(name = "river_name", nullable = false)
|
||||
private String riverName;
|
||||
|
||||
@OneToMany(mappedBy = "river")
|
||||
private List<Section> sections;
|
||||
|
||||
// Getters and Setters
|
||||
public Integer getRiverId() {
|
||||
return riverId;
|
||||
}
|
||||
|
||||
public void setRiverId(Integer riverId) {
|
||||
this.riverId = riverId;
|
||||
}
|
||||
|
||||
public String getRiverName() {
|
||||
return riverName;
|
||||
}
|
||||
|
||||
public void setRiverName(String riverName) {
|
||||
this.riverName = riverName;
|
||||
}
|
||||
|
||||
public List<Section> getSections() {
|
||||
return sections;
|
||||
}
|
||||
|
||||
public void setSections(List<Section> sections) {
|
||||
this.sections = sections;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.waterquality.api.entity;
|
||||
|
||||
// Section.java
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Sections")
|
||||
public class Section {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "section_id")
|
||||
private Integer sectionId;
|
||||
|
||||
@Column(name = "section_name", nullable = false)
|
||||
private String sectionName;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "river_id")
|
||||
@JsonIgnore
|
||||
private River river;
|
||||
|
||||
@OneToMany(mappedBy = "section")
|
||||
private List<WaterQualityData> waterQualityDataList;
|
||||
|
||||
// Getters and Setters
|
||||
public Integer getSectionId() {
|
||||
return sectionId;
|
||||
}
|
||||
|
||||
public void setSectionId(Integer sectionId) {
|
||||
this.sectionId = sectionId;
|
||||
}
|
||||
|
||||
public String getSectionName() {
|
||||
return sectionName;
|
||||
}
|
||||
|
||||
public void setSectionName(String sectionName) {
|
||||
this.sectionName = sectionName;
|
||||
}
|
||||
|
||||
public River getRiver() {
|
||||
return river;
|
||||
}
|
||||
|
||||
public void setRiver(River river) {
|
||||
this.river = river;
|
||||
}
|
||||
|
||||
public List<WaterQualityData> getWaterQualityDataList() {
|
||||
return waterQualityDataList;
|
||||
}
|
||||
|
||||
public void setWaterQualityDataList(List<WaterQualityData> waterQualityDataList) {
|
||||
this.waterQualityDataList = waterQualityDataList;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
// WaterQualityData.java
|
||||
package com.waterquality.api.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
@Entity
|
||||
@Table(name = "WaterQualityData")
|
||||
public class WaterQualityData {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "data_id")
|
||||
private Integer dataId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "section_id")
|
||||
@JsonIgnore
|
||||
private Section section;
|
||||
|
||||
@Column(name = "data_date")
|
||||
private LocalDate dataDate;
|
||||
|
||||
@Column(name = "temperature")
|
||||
private BigDecimal temperature;
|
||||
|
||||
@Column(name = "ph")
|
||||
private BigDecimal ph;
|
||||
|
||||
@Column(name = "dissolved_oxygen")
|
||||
private BigDecimal dissolvedOxygen;
|
||||
|
||||
@Column(name = "conductivity")
|
||||
private BigDecimal conductivity;
|
||||
|
||||
@Column(name = "NTU")
|
||||
private BigDecimal ntu;
|
||||
|
||||
@Column(name = "permanganate_index")
|
||||
private BigDecimal permanganateIndex;
|
||||
|
||||
@Column(name = "ammonia_nitrogen")
|
||||
private BigDecimal ammoniaNitrogen;
|
||||
|
||||
@Column(name = "total_phosphorus")
|
||||
private BigDecimal totalPhosphorus;
|
||||
|
||||
@Column(name = "total_nitrogen")
|
||||
private BigDecimal totalNitrogen;
|
||||
|
||||
// Getters and Setters
|
||||
public Integer getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(Integer dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public Section getSection() {
|
||||
return section;
|
||||
}
|
||||
|
||||
public void setSection(Section section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
public LocalDate getDataDate() {
|
||||
return dataDate;
|
||||
}
|
||||
|
||||
public void setDataDate(LocalDate dataDate) {
|
||||
this.dataDate = dataDate;
|
||||
}
|
||||
|
||||
public BigDecimal getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(BigDecimal temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public BigDecimal getPh() {
|
||||
return ph;
|
||||
}
|
||||
|
||||
public void setPh(BigDecimal ph) {
|
||||
this.ph = ph;
|
||||
}
|
||||
|
||||
public BigDecimal getDissolvedOxygen() {
|
||||
return dissolvedOxygen;
|
||||
}
|
||||
|
||||
public void setDissolvedOxygen(BigDecimal dissolvedOxygen) {
|
||||
this.dissolvedOxygen = dissolvedOxygen;
|
||||
}
|
||||
|
||||
public BigDecimal getConductivity() {
|
||||
return conductivity;
|
||||
}
|
||||
|
||||
public void setConductivity(BigDecimal conductivity) {
|
||||
this.conductivity = conductivity;
|
||||
}
|
||||
|
||||
public BigDecimal getNtu() {
|
||||
return ntu;
|
||||
}
|
||||
|
||||
public void setNtu(BigDecimal ntu) {
|
||||
this.ntu = ntu;
|
||||
}
|
||||
|
||||
public BigDecimal getPermanganateIndex() {
|
||||
return permanganateIndex;
|
||||
}
|
||||
|
||||
public void setPermanganateIndex(BigDecimal permanganateIndex) {
|
||||
this.permanganateIndex = permanganateIndex;
|
||||
}
|
||||
|
||||
public BigDecimal getAmmoniaNitrogen() {
|
||||
return ammoniaNitrogen;
|
||||
}
|
||||
|
||||
public void setAmmoniaNitrogen(BigDecimal ammoniaNitrogen) {
|
||||
this.ammoniaNitrogen = ammoniaNitrogen;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalPhosphorus() {
|
||||
return totalPhosphorus;
|
||||
}
|
||||
|
||||
public void setTotalPhosphorus(BigDecimal totalPhosphorus) {
|
||||
this.totalPhosphorus = totalPhosphorus;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalNitrogen() {
|
||||
return totalNitrogen;
|
||||
}
|
||||
|
||||
public void setTotalNitrogen(BigDecimal totalNitrogen) {
|
||||
this.totalNitrogen = totalNitrogen;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.waterquality.api.repository;
|
||||
|
||||
// RiverRepository.java
|
||||
|
||||
import com.waterquality.api.entity.River;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface RiverRepository extends JpaRepository<River, Integer> {
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// SectionRepository.java
|
||||
package com.waterquality.api.repository;
|
||||
|
||||
import com.waterquality.api.entity.Section;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface SectionRepository extends JpaRepository<Section, Integer> {
|
||||
List<Section> findByRiverRiverId(Integer riverId);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// WaterQualityDataRepository.java
|
||||
package com.waterquality.api.repository;
|
||||
|
||||
import com.waterquality.api.entity.WaterQualityData;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface WaterQualityDataRepository extends JpaRepository<WaterQualityData, Integer> {
|
||||
List<WaterQualityData> findBySectionSectionId(Integer sectionId);
|
||||
|
||||
List<WaterQualityData> findBySectionSectionIdAndDataDateBetween(
|
||||
Integer sectionId, LocalDate startDate, LocalDate endDate);
|
||||
|
||||
@Query("SELECT w FROM WaterQualityData w WHERE w.section.river.riverId = :riverId")
|
||||
List<WaterQualityData> findByRiverId(Integer riverId);
|
||||
|
||||
@Query("SELECT w FROM WaterQualityData w WHERE w.section.river.riverId = :riverId AND w.dataDate BETWEEN :startDate AND :endDate")
|
||||
List<WaterQualityData> findByRiverIdAndDateRange(
|
||||
Integer riverId, LocalDate startDate, LocalDate endDate);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// RiverService.java
|
||||
package com.waterquality.api.service;
|
||||
|
||||
import com.waterquality.api.entity.River;
|
||||
import com.waterquality.api.repository.RiverRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class RiverService {
|
||||
|
||||
private final RiverRepository riverRepository;
|
||||
|
||||
@Autowired
|
||||
public RiverService(RiverRepository riverRepository) {
|
||||
this.riverRepository = riverRepository;
|
||||
}
|
||||
|
||||
public List<River> getAllRivers() {
|
||||
return riverRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<River> getRiverById(Integer id) {
|
||||
return riverRepository.findById(id);
|
||||
}
|
||||
|
||||
public River saveRiver(River river) {
|
||||
return riverRepository.save(river);
|
||||
}
|
||||
|
||||
public void deleteRiver(Integer id) {
|
||||
riverRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// SectionService.java
|
||||
package com.waterquality.api.service;
|
||||
|
||||
import com.waterquality.api.entity.Section;
|
||||
import com.waterquality.api.repository.SectionRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class SectionService {
|
||||
|
||||
private final SectionRepository sectionRepository;
|
||||
|
||||
@Autowired
|
||||
public SectionService(SectionRepository sectionRepository) {
|
||||
this.sectionRepository = sectionRepository;
|
||||
}
|
||||
|
||||
public List<Section> getAllSections() {
|
||||
return sectionRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<Section> getSectionById(Integer id) {
|
||||
return sectionRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<Section> getSectionsByRiverId(Integer riverId) {
|
||||
return sectionRepository.findByRiverRiverId(riverId);
|
||||
}
|
||||
|
||||
public Section saveSection(Section section) {
|
||||
return sectionRepository.save(section);
|
||||
}
|
||||
|
||||
public void deleteSection(Integer id) {
|
||||
sectionRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
// WaterQualityDataService.java
|
||||
package com.waterquality.api.service;
|
||||
|
||||
import com.waterquality.api.dto.WaterQualityStatisticsDTO;
|
||||
import com.waterquality.api.entity.WaterQualityData;
|
||||
import com.waterquality.api.repository.WaterQualityDataRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class WaterQualityDataService {
|
||||
|
||||
private final WaterQualityDataRepository waterQualityDataRepository;
|
||||
|
||||
@Autowired
|
||||
public WaterQualityDataService(WaterQualityDataRepository waterQualityDataRepository) {
|
||||
this.waterQualityDataRepository = waterQualityDataRepository;
|
||||
}
|
||||
|
||||
public List<WaterQualityData> getAllWaterQualityData() {
|
||||
return waterQualityDataRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<WaterQualityData> getWaterQualityDataById(Integer id) {
|
||||
return waterQualityDataRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<WaterQualityData> getWaterQualityDataBySectionId(Integer sectionId) {
|
||||
return waterQualityDataRepository.findBySectionSectionId(sectionId);
|
||||
}
|
||||
|
||||
public List<WaterQualityData> getWaterQualityDataBySectionIdAndDateRange(
|
||||
Integer sectionId, LocalDate startDate, LocalDate endDate) {
|
||||
return waterQualityDataRepository.findBySectionSectionIdAndDataDateBetween(
|
||||
sectionId, startDate, endDate);
|
||||
}
|
||||
|
||||
public List<WaterQualityData> getWaterQualityDataByRiverId(Integer riverId) {
|
||||
return waterQualityDataRepository.findByRiverId(riverId);
|
||||
}
|
||||
|
||||
public List<WaterQualityData> getWaterQualityDataByRiverIdAndDateRange(
|
||||
Integer riverId, LocalDate startDate, LocalDate endDate) {
|
||||
return waterQualityDataRepository.findByRiverIdAndDateRange(riverId, startDate, endDate);
|
||||
}
|
||||
|
||||
public WaterQualityData saveWaterQualityData(WaterQualityData waterQualityData) {
|
||||
return waterQualityDataRepository.save(waterQualityData);
|
||||
}
|
||||
|
||||
public void deleteWaterQualityData(Integer id) {
|
||||
waterQualityDataRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public List<WaterQualityStatisticsDTO> getStatisticsBySectionId(Integer sectionId) {
|
||||
List<WaterQualityData> dataList = waterQualityDataRepository.findBySectionSectionId(sectionId);
|
||||
return calculateStatistics(dataList);
|
||||
}
|
||||
|
||||
public List<WaterQualityStatisticsDTO> getStatisticsByRiverId(Integer riverId) {
|
||||
List<WaterQualityData> dataList = waterQualityDataRepository.findByRiverId(riverId);
|
||||
return calculateStatistics(dataList);
|
||||
}
|
||||
|
||||
private List<WaterQualityStatisticsDTO> calculateStatistics(List<WaterQualityData> dataList) {
|
||||
List<WaterQualityStatisticsDTO> statisticsList = new ArrayList<>();
|
||||
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
return statisticsList;
|
||||
}
|
||||
|
||||
statisticsList.add(calculateParameterStatistics("Temperature", dataList, WaterQualityData::getTemperature));
|
||||
statisticsList.add(calculateParameterStatistics("PH", dataList, WaterQualityData::getPh));
|
||||
statisticsList.add(calculateParameterStatistics("Dissolved Oxygen", dataList, WaterQualityData::getDissolvedOxygen));
|
||||
statisticsList.add(calculateParameterStatistics("Conductivity", dataList, WaterQualityData::getConductivity));
|
||||
statisticsList.add(calculateParameterStatistics("NTU", dataList, WaterQualityData::getNtu));
|
||||
statisticsList.add(calculateParameterStatistics("Permanganate Index", dataList, WaterQualityData::getPermanganateIndex));
|
||||
statisticsList.add(calculateParameterStatistics("Ammonia Nitrogen", dataList, WaterQualityData::getAmmoniaNitrogen));
|
||||
statisticsList.add(calculateParameterStatistics("Total Phosphorus", dataList, WaterQualityData::getTotalPhosphorus));
|
||||
statisticsList.add(calculateParameterStatistics("Total Nitrogen", dataList, WaterQualityData::getTotalNitrogen));
|
||||
|
||||
return statisticsList;
|
||||
}
|
||||
|
||||
private WaterQualityStatisticsDTO calculateParameterStatistics(
|
||||
String parameterName,
|
||||
List<WaterQualityData> dataList,
|
||||
Function<WaterQualityData, BigDecimal> parameterGetter) {
|
||||
|
||||
BigDecimal sum = BigDecimal.ZERO;
|
||||
BigDecimal min = null;
|
||||
BigDecimal max = null;
|
||||
int count = 0;
|
||||
|
||||
for (WaterQualityData data : dataList) {
|
||||
BigDecimal value = parameterGetter.apply(data);
|
||||
if (value != null) {
|
||||
count++;
|
||||
sum = sum.add(value);
|
||||
|
||||
if (min == null || value.compareTo(min) < 0) {
|
||||
min = value;
|
||||
}
|
||||
|
||||
if (max == null || value.compareTo(max) > 0) {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal average = count > 0
|
||||
? sum.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP)
|
||||
: null;
|
||||
|
||||
return new WaterQualityStatisticsDTO(parameterName, average, min, max);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: com.waterquality.api.WaterQualityApi
|
||||
Class-Path: jackson-annotations-2.18.2.jar jaxb-core-4.0.5.jar spring-as
|
||||
pects-6.2.3.jar jboss-logging-3.6.1.Final.jar spring-boot-starter-jdbc-
|
||||
3.4.3.jar spring-web-6.2.3.jar micrometer-commons-1.14.4.jar slf4j-api-
|
||||
2.0.16.jar spring-boot-starter-3.4.3.jar spring-expression-6.2.3.jar hi
|
||||
bernate-core-6.6.8.Final.jar snakeyaml-2.3.jar angus-activation-2.0.2.j
|
||||
ar spring-core-6.2.3.jar jakarta.xml.bind-api-4.0.2.jar classmate-1.7.0
|
||||
.jar spring-jdbc-6.2.3.jar spring-boot-starter-logging-3.4.3.jar txw2-4
|
||||
.0.5.jar jackson-core-2.18.2.jar hibernate-commons-annotations-7.0.3.Fi
|
||||
nal.jar spring-boot-autoconfigure-3.4.3.jar jakarta.persistence-api-3.1
|
||||
.0.jar mysql-connector-j-9.1.0.jar istack-commons-runtime-4.1.2.jar spr
|
||||
ing-boot-3.4.3.jar tomcat-embed-websocket-10.1.36.jar spring-aop-6.2.3.
|
||||
jar logback-core-1.5.16.jar jakarta.activation-api-2.1.3.jar tomcat-emb
|
||||
ed-core-10.1.36.jar byte-buddy-1.15.11.jar spring-tx-6.2.3.jar spring-b
|
||||
oot-starter-json-3.4.3.jar jul-to-slf4j-2.0.16.jar spring-orm-6.2.3.jar
|
||||
HikariCP-5.1.0.jar jandex-3.2.0.jar spring-beans-6.2.3.jar jaxb-runtim
|
||||
e-4.0.5.jar log4j-api-2.24.3.jar jakarta.annotation-api-2.1.1.jar jacks
|
||||
on-databind-2.18.2.jar logback-classic-1.5.16.jar spring-jcl-6.2.3.jar
|
||||
jackson-module-parameter-names-2.18.2.jar jakarta.inject-api-2.0.1.jar
|
||||
spring-boot-starter-tomcat-3.4.3.jar spring-data-commons-3.4.3.jar log4
|
||||
j-to-slf4j-2.24.3.jar spring-boot-starter-data-jpa-3.4.3.jar micrometer
|
||||
-observation-1.14.4.jar spring-webmvc-6.2.3.jar jackson-datatype-jdk8-2
|
||||
.18.2.jar jackson-datatype-jsr310-2.18.2.jar tomcat-embed-el-10.1.36.ja
|
||||
r spring-boot-starter-web-3.4.3.jar jakarta.transaction-api-2.0.1.jar a
|
||||
spectjweaver-1.9.22.1.jar antlr4-runtime-4.13.0.jar spring-context-6.2.
|
||||
3.jar spring-data-jpa-3.4.3.jar
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
spring.application.name=WaterQuality
|
||||
|
||||
spring.datasource.url=jdbc:mysql://8.130.82.85:33306/RiversQuality?useSSL=false&serverTimezone=UTC
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=tju1895
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
|
||||
spring.jpa.properties.hibernate.format_sql=true
|
||||
|
||||
|
||||
server.port=8080
|
||||
|
|
@ -0,0 +1,614 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>水质数据查询系统</title>
|
||||
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.0/dist/echarts.min.js"></script> -->
|
||||
<script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<script src="https://unpkg.com/echarts@5.4.0/dist/echarts.min.js"></script>
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: #1e88e5;
|
||||
--secondary-color: #e3f2fd;
|
||||
--text-color: #333;
|
||||
--light-gray: #f5f5f5;
|
||||
--border-color: #ddd;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f9f9f9;
|
||||
color: var(--text-color);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
header {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
padding: 20px 0;
|
||||
margin-bottom: 30px;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
header h1 {
|
||||
text-align: center;
|
||||
font-weight: 300;
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.query-panel {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
select, input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 20px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0d47a1;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
padding: 10px 20px;
|
||||
cursor: pointer;
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
border-bottom: 2px solid var(--primary-color);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
th, td {
|
||||
padding: 12px 15px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: var(--secondary-color);
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: var(--light-gray);
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 400px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.statistics-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background-color: white;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
margin-bottom: 10px;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 30px;
|
||||
font-size: 18px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #d32f2f;
|
||||
padding: 10px;
|
||||
background-color: #ffebee;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.query-panel {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.statistics-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<h1>水质数据查询系统</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container" id="app">
|
||||
<div class="card">
|
||||
<div class="query-panel">
|
||||
<div class="form-group">
|
||||
<label for="queryType">查询类型</label>
|
||||
<select id="queryType" v-model="queryType">
|
||||
<option value="river">按河道查询</option>
|
||||
<option value="section">按断面查询</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group" v-if="queryType === 'river'">
|
||||
<label for="river">选择河道</label>
|
||||
<select id="river" v-model="selectedRiverId">
|
||||
<option value="">请选择河道</option>
|
||||
<option v-for="river in rivers" :key="river.riverId" :value="river.riverId">
|
||||
{{ river.riverName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group" v-if="queryType === 'section'">
|
||||
<label for="section">选择断面</label>
|
||||
<select id="section" v-model="selectedSectionId">
|
||||
<option value="">请选择断面</option>
|
||||
<option v-for="section in sections" :key="section.sectionId" :value="section.sectionId">
|
||||
{{ section.sectionName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="startDate">开始日期</label>
|
||||
<input type="date" id="startDate" v-model="startDate">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="endDate">结束日期</label>
|
||||
<input type="date" id="endDate" v-model="endDate">
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="align-self: flex-end;">
|
||||
<button @click="queryData">查询数据</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="error">
|
||||
{{ error }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" v-if="loading">
|
||||
<div class="loading">数据加载中...</div>
|
||||
</div>
|
||||
|
||||
<div class="card" v-if="!loading && waterQualityData.length > 0">
|
||||
<div class="tabs">
|
||||
<div class="tab" :class="{ active: activeTab === 'table' }" @click="activeTab = 'table'">
|
||||
表格数据
|
||||
</div>
|
||||
<div class="tab" :class="{ active: activeTab === 'chart' }" @click="activeTab = 'chart'">
|
||||
图表分析
|
||||
</div>
|
||||
<div class="tab" :class="{ active: activeTab === 'statistics' }" @click="activeTab = 'statistics'; fetchStatistics()">
|
||||
统计分析
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" :class="{ active: activeTab === 'table' }">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日期</th>
|
||||
<th>水温 (°C)</th>
|
||||
<th>pH值</th>
|
||||
<th>溶解氧 (mg/L)</th>
|
||||
<th>电导率 (μS/cm)</th>
|
||||
<th>浊度 (NTU)</th>
|
||||
<th>高锰酸盐指数 (mg/L)</th>
|
||||
<th>氨氮 (mg/L)</th>
|
||||
<th>总磷 (mg/L)</th>
|
||||
<th>总氮 (mg/L)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in waterQualityData" :key="item.dataId">
|
||||
<td>{{ formatDate(item.dataDate) }}</td>
|
||||
<td>{{ item.temperature }}</td>
|
||||
<td>{{ item.ph }}</td>
|
||||
<td>{{ item.dissolvedOxygen }}</td>
|
||||
<td>{{ item.conductivity }}</td>
|
||||
<td>{{ item.ntu }}</td>
|
||||
<td>{{ item.permanganateIndex }}</td>
|
||||
<td>{{ item.ammoniaNitrogen }}</td>
|
||||
<td>{{ item.totalPhosphorus }}</td>
|
||||
<td>{{ item.totalNitrogen }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" :class="{ active: activeTab === 'chart' }">
|
||||
<select v-model="selectedParameter" @change="updateChart">
|
||||
<option value="temperature">水温</option>
|
||||
<option value="ph">pH值</option>
|
||||
<option value="dissolvedOxygen">溶解氧</option>
|
||||
<option value="conductivity">电导率</option>
|
||||
<option value="ntu">浊度</option>
|
||||
<option value="permanganateIndex">高锰酸盐指数</option>
|
||||
<option value="ammoniaNitrogen">氨氮</option>
|
||||
<option value="totalPhosphorus">总磷</option>
|
||||
<option value="totalNitrogen">总氮</option>
|
||||
</select>
|
||||
<div id="chart" class="chart-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" :class="{ active: activeTab === 'statistics' }">
|
||||
<div v-if="loadingStatistics" class="loading">统计数据加载中...</div>
|
||||
<div v-else class="statistics-grid">
|
||||
<div class="stat-card" v-for="stat in statistics" :key="stat.parameter">
|
||||
<h3>{{ getParameterDisplayName(stat.parameter) }}</h3>
|
||||
<div class="stat-value">
|
||||
<span class="stat-label">平均值:</span>
|
||||
<span>{{ stat.average }}</span>
|
||||
</div>
|
||||
<div class="stat-value">
|
||||
<span class="stat-label">最小值:</span>
|
||||
<span>{{ stat.min }}</span>
|
||||
</div>
|
||||
<div class="stat-value">
|
||||
<span class="stat-label">最大值:</span>
|
||||
<span>{{ stat.max }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" v-if="!loading && waterQualityData.length === 0 && !error">
|
||||
<p>暂无数据。请调整查询条件后重试。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
queryType: 'river',
|
||||
rivers: [],
|
||||
sections: [],
|
||||
selectedRiverId: '',
|
||||
selectedSectionId: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
waterQualityData: [],
|
||||
statistics: [],
|
||||
loading: false,
|
||||
loadingStatistics: false,
|
||||
error: '',
|
||||
activeTab: 'table',
|
||||
selectedParameter: 'temperature',
|
||||
chart: null
|
||||
},
|
||||
created() {
|
||||
this.fetchRivers();
|
||||
this.fetchSections();
|
||||
|
||||
// 设置默认日期范围为过去30天
|
||||
const today = new Date();
|
||||
const thirtyDaysAgo = new Date();
|
||||
thirtyDaysAgo.setDate(today.getDate() - 30);
|
||||
|
||||
this.endDate = this.formatDateForInput(today);
|
||||
this.startDate = this.formatDateForInput(thirtyDaysAgo);
|
||||
},
|
||||
methods: {
|
||||
fetchRivers() {
|
||||
axios.get('/api/rivers')
|
||||
.then(response => {
|
||||
this.rivers = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取河道数据失败:', error);
|
||||
this.error = '获取河道数据失败,请稍后重试';
|
||||
});
|
||||
},
|
||||
fetchSections() {
|
||||
axios.get('/api/sections')
|
||||
.then(response => {
|
||||
this.sections = response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取断面数据失败:', error);
|
||||
this.error = '获取断面数据失败,请稍后重试';
|
||||
});
|
||||
},
|
||||
queryData() {
|
||||
this.error = '';
|
||||
|
||||
if (this.queryType === 'river' && !this.selectedRiverId) {
|
||||
this.error = '请选择一个河道';
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.queryType === 'section' && !this.selectedSectionId) {
|
||||
this.error = '请选择一个断面';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.startDate || !this.endDate) {
|
||||
this.error = '请选择开始和结束日期';
|
||||
return;
|
||||
}
|
||||
|
||||
const startDateObj = new Date(this.startDate);
|
||||
const endDateObj = new Date(this.endDate);
|
||||
|
||||
if (startDateObj > endDateObj) {
|
||||
this.error = '开始日期不能晚于结束日期';
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
let url;
|
||||
|
||||
if (this.queryType === 'river') {
|
||||
url = `/api/water-quality/river/${this.selectedRiverId}/date-range?startDate=${this.startDate}&endDate=${this.endDate}`;
|
||||
} else {
|
||||
url = `/api/water-quality/section/${this.selectedSectionId}/date-range?startDate=${this.startDate}&endDate=${this.endDate}`;
|
||||
}
|
||||
|
||||
axios.get(url)
|
||||
.then(response => {
|
||||
this.waterQualityData = response.data;
|
||||
this.loading = false;
|
||||
|
||||
if (this.waterQualityData.length > 0) {
|
||||
// 按日期排序
|
||||
this.waterQualityData.sort((a, b) => new Date(a.dataDate) - new Date(b.dataDate));
|
||||
|
||||
// 如果在图表选项卡,更新图表
|
||||
if (this.activeTab === 'chart') {
|
||||
this.$nextTick(() => {
|
||||
this.initChart();
|
||||
this.updateChart();
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('查询数据失败:', error);
|
||||
this.error = '查询数据失败,请稍后重试';
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
fetchStatistics() {
|
||||
if (this.statistics.length > 0 || this.loadingStatistics) {
|
||||
return; // 已有数据或正在加载中,不重复请求
|
||||
}
|
||||
|
||||
this.loadingStatistics = true;
|
||||
let url;
|
||||
|
||||
if (this.queryType === 'river') {
|
||||
url = `/api/water-quality/river/${this.selectedRiverId}/statistics`;
|
||||
} else {
|
||||
url = `/api/water-quality/section/${this.selectedSectionId}/statistics`;
|
||||
}
|
||||
|
||||
axios.get(url)
|
||||
.then(response => {
|
||||
this.statistics = response.data;
|
||||
this.loadingStatistics = false;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取统计数据失败:', error);
|
||||
this.error = '获取统计数据失败,请稍后重试';
|
||||
this.loadingStatistics = false;
|
||||
});
|
||||
},
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return '';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('zh-CN');
|
||||
},
|
||||
formatDateForInput(date) {
|
||||
if (!date) return '';
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
},
|
||||
initChart() {
|
||||
if (!this.chart) {
|
||||
this.chart = echarts.init(document.getElementById('chart'));
|
||||
}
|
||||
},
|
||||
updateChart() {
|
||||
if (!this.chart || this.waterQualityData.length === 0) return;
|
||||
|
||||
const dates = this.waterQualityData.map(item => this.formatDate(item.dataDate));
|
||||
const values = this.waterQualityData.map(item => item[this.selectedParameter]);
|
||||
|
||||
const option = {
|
||||
title: {
|
||||
text: this.getParameterDisplayName(this.selectedParameter) + '变化趋势',
|
||||
left: 'center'
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLabel: {
|
||||
rotate: 45
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
name: this.getParameterUnit(this.selectedParameter)
|
||||
},
|
||||
series: [{
|
||||
name: this.getParameterDisplayName(this.selectedParameter),
|
||||
type: 'line',
|
||||
data: values,
|
||||
smooth: true,
|
||||
markPoint: {
|
||||
data: [
|
||||
{ type: 'max', name: '最大值' },
|
||||
{ type: 'min', name: '最小值' }
|
||||
]
|
||||
},
|
||||
markLine: {
|
||||
data: [
|
||||
{ type: 'average', name: '平均值' }
|
||||
]
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
this.chart.setOption(option);
|
||||
},
|
||||
getParameterDisplayName(parameter) {
|
||||
const nameMap = {
|
||||
'temperature': '水温',
|
||||
'ph': 'pH值',
|
||||
'dissolvedOxygen': '溶解氧',
|
||||
'conductivity': '电导率',
|
||||
'ntu': '浊度',
|
||||
'permanganateIndex': '高锰酸盐指数',
|
||||
'ammoniaNitrogen': '氨氮',
|
||||
'totalPhosphorus': '总磷',
|
||||
'totalNitrogen': '总氮',
|
||||
'Temperature': '水温',
|
||||
'PH': 'pH值',
|
||||
'Dissolved Oxygen': '溶解氧',
|
||||
'Conductivity': '电导率',
|
||||
'NTU': '浊度',
|
||||
'Permanganate Index': '高锰酸盐指数',
|
||||
'Ammonia Nitrogen': '氨氮',
|
||||
'Total Phosphorus': '总磷',
|
||||
'Total Nitrogen': '总氮'
|
||||
};
|
||||
return nameMap[parameter] || parameter;
|
||||
},
|
||||
getParameterUnit(parameter) {
|
||||
const unitMap = {
|
||||
'temperature': '°C',
|
||||
'ph': '',
|
||||
'dissolvedOxygen': 'mg/L',
|
||||
'conductivity': 'μS/cm',
|
||||
'ntu': 'NTU',
|
||||
'permanganateIndex': 'mg/L',
|
||||
'ammoniaNitrogen': 'mg/L',
|
||||
'totalPhosphorus': 'mg/L',
|
||||
'totalNitrogen': 'mg/L'
|
||||
};
|
||||
return unitMap[parameter] || '';
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
activeTab(newTab) {
|
||||
if (newTab === 'chart' && this.waterQualityData.length > 0) {
|
||||
this.$nextTick(() => {
|
||||
this.initChart();
|
||||
this.updateChart();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.waterquality.api;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ProjectApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue