Commit fed92d32 authored by 霍传世's avatar 霍传世

pdfGe

parents
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/
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
#!/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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Apache Maven Wrapper startup batch script, version 3.2.0
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# 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 /usr/local/etc/mavenrc ] ; then
. /usr/local/etc/mavenrc
fi
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
JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
else
JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=$(java-config --jre-home)
fi
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -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 "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); 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="$(\unset -f command 2>/dev/null; \command -v 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
# 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/.." || exit 1; pwd)
fi
# end of workaround
done
printf '%s' "$(cd "$basedir" || exit 1; pwd)"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
# Remove \r in case we run on Windows within Git Bash
# and check out the repository with auto CRLF management
# enabled. Otherwise, we may read lines that are delimited with
# \r\n and produce $'-Xarg\r' rather than -Xarg due to word
# splitting rules.
tr -s '\r\n' ' ' < "$1"
fi
}
log() {
if [ "$MVNW_VERBOSE" = true ]; then
printf '%s\n' "$1"
fi
}
BASE_DIR=$(find_maven_basedir "$(dirname "$0")")
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
log "$MAVEN_PROJECTBASEDIR"
##########################################################################################
# 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.
##########################################################################################
wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar"
if [ -r "$wrapperJarPath" ]; then
log "Found $wrapperJarPath"
else
log "Couldn't find $wrapperJarPath, downloading it ..."
if [ -n "$MVNW_REPOURL" ]; then
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
else
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
fi
while IFS="=" read -r key value; do
# Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
safeValue=$(echo "$value" | tr -d '\r')
case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;;
esac
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
log "Downloading from: $wrapperUrl"
if $cygwin; then
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
fi
if command -v wget > /dev/null; then
log "Found wget ... using wget"
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
else
wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
log "Found curl ... using curl"
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
else
curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
fi
else
log "Falling back to using Java to download"
javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaSource=$(cygpath --path --windows "$javaSource")
javaClass=$(cygpath --path --windows "$javaClass")
fi
if [ -e "$javaSource" ]; then
if [ ! -e "$javaClass" ]; then
log " - Compiling MavenWrapperDownloader.java ..."
("$JAVA_HOME/bin/javac" "$javaSource")
fi
if [ -e "$javaClass" ]; then
log " - Running MavenWrapperDownloader.java ..."
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
# If specified, validate the SHA-256 sum of the Maven wrapper jar file
wrapperSha256Sum=""
while IFS="=" read -r key value; do
case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;;
esac
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
if [ -n "$wrapperSha256Sum" ]; then
wrapperSha256Result=false
if command -v sha256sum > /dev/null; then
if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then
wrapperSha256Result=true
fi
elif command -v shasum > /dev/null; then
if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then
wrapperSha256Result=true
fi
else
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available."
echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties."
exit 1
fi
if [ $wrapperSha256Result = false ]; then
echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2
echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2
echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2
exit 1
fi
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 "$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
# shellcheck disable=SC2086 # safe args
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@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 Apache Maven Wrapper startup batch script, version 3.2.0
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\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 WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET WRAPPER_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 WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %WRAPPER_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('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file
SET WRAPPER_SHA_256_SUM=""
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B
)
IF NOT %WRAPPER_SHA_256_SUM%=="" (
powershell -Command "&{"^
"$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^
"If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^
" Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^
" Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^
" Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^
" exit 1;"^
"}"^
"}"
if ERRORLEVEL 1 goto error
)
@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 "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\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%
cmd /C exit /B %ERROR_CODE%
<?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>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>PDFGenerator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PDFGenerator</name>
<description>PDFGenerator</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.32</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.133</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.example.pdfgenerator.Dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BasicReportParameters {
private String school;
private String province;
private String region;
private String examId;
private String subSubject;
private String command;
}
package com.example.pdfgenerator.Dto;
import lombok.Data;
@Data
public class ClassBasicReportParameters {
private String className;
private String school;
private String examId;
private String province;
private String region;
private String subSubject;
private String command;
}
package com.example.pdfgenerator.Dto;
import lombok.Data;
@Data
public class ClassDtoArgs {
private String region;
private String school;
private String className;
}
package com.example.pdfgenerator.Dto;
public class Dto {
private String school;
private String region;
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
}
package com.example.pdfgenerator.Dto;
public class DtoArgs {
private String quesType;
private Double stuQtScoreRate;
private String subSubject;
private String stuId;
public String getQuesType() {
return quesType;
}
public void setQuesType(String quesType) {
this.quesType = quesType;
}
public Double getStuQtScoreRate() {
return stuQtScoreRate;
}
public void setStuQtScoreRate(Double stuQtScoreRate) {
this.stuQtScoreRate = stuQtScoreRate;
}
public String getSubSubject() {
return subSubject;
}
public void setSubSubject(String subSubject) {
this.subSubject = subSubject;
}
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
}
package com.example.pdfgenerator.Dto;
public class DtoAsw {
private String quesNo;
private String stuId;
private Double stuQuesAswTime;
private String subSubject;
public String getQuesNo() {
return quesNo;
}
public void setQuesNo(String quesNo) {
this.quesNo = quesNo;
}
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
public Double getStuQuesAswTime() {
return stuQuesAswTime;
}
public void setStuQuesAswTime(Double stuQuesAswTime) {
this.stuQuesAswTime = stuQuesAswTime;
}
public String getSubSubject() {
return subSubject;
}
public void setSubSubject(String subSubject) {
this.subSubject = subSubject;
}
}
package com.example.pdfgenerator.Dto;
public class Params {
private String province;
private String region;
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
}
package com.example.pdfgenerator.Dto;
import lombok.Data;
import java.util.List;
@Data
public class ProvinceAllTypeClass {
private List<BasicReportParameters> synthesisSchoolSubjectReportParameters;
private List<BasicReportParameters> synthesisSchoolReportParameters;
private List<ClassBasicReportParameters> synthesisClassSubjectReportParameters;
private List<ClassBasicReportParameters> synthesisClassReportParameters;
private String provinceName;
}
package com.example.pdfgenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PdfGeneratorApplication {
public static void main(String[] args) {
SpringApplication.run(PdfGeneratorApplication.class, args);
}
}
package com.example.pdfgenerator.config;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CommonConfig {
@Bean(name = "cosClient")
public COSClient cosClient() {
COSCredentials cred = new BasicCOSCredentials("AKID61zliQDpBOgqALHvLl25sRmvnV9cohPt", "TkqtgCUaYJhx1rTpztY2LQRO9h2pPmun");
Region region = new Region("ap-beijing");
ClientConfig clientConfig = new ClientConfig(region);
clientConfig.setHttpProtocol(HttpProtocol.https);
// 3 生成 cos 客户端。
return new COSClient(cred, clientConfig);
}
}
package com.example.pdfgenerator.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
/**
* @author yn
* @version 1.0
* @date 2020/9/15 15:30
*/
@Configuration
public class MyDataSourceConfig {
private static JdbcTemplate reportJdbcTemplate;
private static JdbcTemplate mkReportJdbcTemplate;
private static JdbcTemplate campsiteJdbcTemplate;
@PostConstruct
private void init() {
initReport();
initMkReport();
// initCampCenter();
}
public static JdbcTemplate getReportJdbcTemplate(){
return reportJdbcTemplate;
}
public static JdbcTemplate getMkReportJdbcTemplate() { return mkReportJdbcTemplate; }
public static JdbcTemplate getCampsiteJdbcTemplate(){
return campsiteJdbcTemplate;
}
public DataSource initReport(){
System.err.println("print init reportSource...");
//外网
String url = "jdbc:mysql://192.168.0.46:3306/tempnew?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8";
DruidDataSource dataSource = getDataSource(url);
dataSource.setUsername("jiru");
dataSource.setPassword("Jiru@20231026");
reportJdbcTemplate = new JdbcTemplate(dataSource);
return dataSource;
}
public DataSource initMkReport(){
System.err.println("print init mkSource...");
//外网
String url = "jdbc:mysql://192.168.0.11:3306/boye_20240911?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8";
DruidDataSource dataSource = getDataSource(url);
dataSource.setUsername("root");
dataSource.setPassword("Thu#DSS#0419");
mkReportJdbcTemplate = new JdbcTemplate(dataSource);
return dataSource;
}
// public DataSource initCampCenter(){
// System.err.println("print init campsiteSource...");
// //外网
// String url = "jdbc:mysql://10.0.0.8:3306/yingdi?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8";
// DruidDataSource dataSource = getDataSource(url);
// dataSource.setUsername("root");
// dataSource.setPassword("sunny@campcenter1017");
// reportJdbcTemplate = new JdbcTemplate(dataSource);
// return dataSource;
// }
private DruidDataSource getDataSource(String url) {
DruidDataSource dataSource = new DruidDataSource();
//设置连接池里面的连接连接池的必要参数
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl(url);
dataSource.setUsername("thussat");
dataSource.setPassword("Thussat@2020");
dataSource.setInitialSize(8);
dataSource.setMaxActive(20);
dataSource.setMinIdle(5);
dataSource.setMaxWait(60000);
dataSource.setDefaultAutoCommit(true);
dataSource.setValidationQuery("SELECT 1 FROM DUAL");
dataSource.setValidationQueryTimeout(60000);
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setTestWhileIdle(true);
dataSource.setTimeBetweenEvictionRunsMillis(60000);
dataSource.setMinEvictableIdleTimeMillis(300000);
dataSource.setBreakAfterAcquireFailure(false);//出错时不把正在提交的数据抛弃
return dataSource;
}
}
package com.example.pdfgenerator.controller;
import com.example.pdfgenerator.Dto.ClassBasicReportParameters;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("/classController")
public class ClassController {
@Autowired
private COSClient cosClient;
private static final String bucketName = "schoolreportpdf-1317275686";
private JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
@GetMapping("/generatorClassBasic")
public void GeneratorClassBasicController(@RequestParam(value = "examId",required = false) String examId) throws IOException, InterruptedException {
HashMap<String,ClassBasicReportParameters> fileToCosPath = new HashMap<>();
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
String sqlStatement = "SELECT\n" +
"\tclass AS class_name,\n" +
"\tschool,\n" +
"\texam_id,\n" +
"\tprovince,\n" +
"\tregion \n" +
"FROM\n" +
"\tbase_class_total_score_tda"+suffix+"\n" +
"WHERE\n" +
"\tsubject_type = '常规'\n" +
"and province = '山东省'\n" +
"GROUP BY\n" +
"\tclass,\n" +
"\tschool,\n" +
"\texam_id,\n" +
"\tprovince,\n" +
"\tregion\n";
List<ClassBasicReportParameters> parametersList = this.reportJdbcTemplate.query(sqlStatement,new Object[]{},new BeanPropertyRowMapper<>(ClassBasicReportParameters.class));
Runtime runtime = Runtime.getRuntime();
List<String> basicReportCommands = new ArrayList<>();
List<String> files = new ArrayList<>();
String reformCommand = "node D:\\myWorkSpace\\pdfOfClassBasicGen.js \"http://localhost:8080/pdf/classBasic?province=condition5&school=condition1&examId=condition4&region=conditionC&subjectType=常规&className=conditionA\" pdf ";
String unReformCommand = "node D:\\myWorkSpace\\pdfOfClassBasicGen.js \"http://localhost:8080/pdf/classBasic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规&className=conditionA\" pdf ";
for (ClassBasicReportParameters basicReportParameters : parametersList) {
String command = "";
String fileName = "";
if(basicReportParameters.getRegion().equals("改革")||basicReportParameters.getRegion().equals("改革A")){
fileName = "D:\\Class\\Basic\\"+basicReportParameters.getRegion()+basicReportParameters.getProvince()+basicReportParameters.getSchool()+ basicReportParameters.getClassName()+basicReportParameters.getExamId()+".pdf";
command = reformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("conditionC",basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("conditionA",basicReportParameters.getClassName())
.concat(" ").concat(fileName);
} else {
fileName = "D:\\Class\\Basic\\"+basicReportParameters.getRegion()+basicReportParameters.getProvince()+basicReportParameters.getSchool()+basicReportParameters.getClassName()+basicReportParameters.getExamId()+".pdf";
command = unReformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3",basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("conditionA",basicReportParameters.getClassName())
.concat(" ").concat(fileName);
}
basicReportCommands.add(command);
fileToCosPath.put(fileName,basicReportParameters);
files.add(fileName);
}
int i = 0;
for (String command : basicReportCommands) {
System.out.println("班级综合报告总共需生成:"+basicReportCommands.size());
System.out.println("正在生成第"+(++i)+"报告");
System.out.println("执行命令是:");
System.out.println(command);
runtime.exec(command);
Thread.sleep(12000);
//上传到cos当中去
File file = new File("D:\\Class\\Basic");
File[] files1 = file.listFiles();
assert files1 != null;
for (File file1 : files1) {
ClassBasicReportParameters parameters = fileToCosPath.get(file1.getAbsolutePath());
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, "class/"+parameters.getExamId()+"/"+parameters.getProvince()+"/"+parameters.getSchool()+"/班级综合报告/"+parameters.getClassName()+"/"+file1.getName(), file1);
try {
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println(putObjectResult.getRequestId());
file1.delete();
} catch (CosServiceException e) {
System.out.println("cos服务出现问题");
e.printStackTrace();
} catch (CosClientException e) {
System.out.println("cos客户端出现问题出现问题的文件是"+file1.getName());
e.printStackTrace();
}
}
}
}
//待完成 ---- > subject of class
@RequestMapping("/generatorClassSubject")
public ResponseEntity BatchSubjectPdfGenerator(@RequestParam(value = "examId",required = false)String examId) throws IOException, InterruptedException {
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
HashMap<String,ClassBasicReportParameters> fileToCosPath = new HashMap<>();
String sqlStatement = "SELECT\n" +
"\tclass as class_name,\n" +
"\tsub_subject,\n" +
"\tschool,\n" +
"\tprovince,\n" +
"\tregion,\n" +
"\texam_id\n" +
"FROM\n" +
"\tbase_student_subject_tda"+suffix+"\n" +
"where\n" +
"subject_type = '常规'\n" +
"\tGROUP BY\n" +
"\tclass,\n" +
"\tsub_subject,\n" +
"\tschool,\n" +
"\tprovince,\n" +
"\tregion,\n" +
"\texam_id";
List<ClassBasicReportParameters> parametersList = this.reportJdbcTemplate.query(sqlStatement, new Object[]{}, new BeanPropertyRowMapper<>(ClassBasicReportParameters.class));
Runtime runtime = Runtime.getRuntime();
List<String> basicReportCommands = new ArrayList<>();
List<String> files = new ArrayList<>();
String reformCommand = "node D:\\myWorkSpace\\pdfOfClassSubjectGen.js \"http://localhost:8080/pdf/classSubject?province=condition5&school=condition1&examId=condition4&region=conditionC&subSubject=condition6&subjectType=常规&className=conditionA\" pdf";
String unReformCommand = "node D:\\myWorkSpace\\pdfOfClassSubjectGen.js \"http://localhost:8080/pdf/classSubject?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subSubject=condition6&subjectType=常规&className=conditionA\" pdf";
for (int i = 0; i < parametersList.size(); i++) {
String command = "";
String fileName = "";
ClassBasicReportParameters basicReportParameters = parametersList.get(i);
if (basicReportParameters.getRegion().equals("改革")||basicReportParameters.getRegion().equals("改革A")) {
fileName = "D:\\Class\\Subject\\" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + basicReportParameters.getSubSubject() + basicReportParameters.getClassName().replace(" ","")+ ".pdf";
command = reformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("conditionC", basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("condition6", basicReportParameters.getSubSubject()).replace("conditionA",basicReportParameters.getClassName())
.concat(" ").concat(fileName);
} else {
fileName = "D:\\Class\\Subject\\" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + basicReportParameters.getSubSubject() + basicReportParameters.getClassName().replace(" ","")+".pdf";
command = unReformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3", basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("condition6", basicReportParameters.getSubSubject()).replace("conditionA",basicReportParameters.getClassName())
.concat(" ").concat(fileName);
;
}
basicReportCommands.add(command);
fileToCosPath.put(fileName,basicReportParameters);
files.add(fileName);
}
// for (ClassBasicReportParameters basicReportParameters : parametersList) {
//
// String command = "";
//
// String fileName = "";
//
// if (basicReportParameters.getRegion().equals("改革")||basicReportParameters.getRegion().equals("改革A")) {
// fileName = "D:\\Class\\Subject\\" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + basicReportParameters.getSubSubject() + basicReportParameters.getClassName().replace(" ","")+ ".pdf";
// command = reformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("conditionC", basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("condition6", basicReportParameters.getSubSubject()).replace("conditionA",basicReportParameters.getClassName())
// .concat(" ").concat(fileName);
// } else {
// fileName = "D:\\Class\\Subject\\" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + basicReportParameters.getSubSubject() + basicReportParameters.getClassName().replace(" ","")+".pdf";
// command = unReformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3", basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("condition6", basicReportParameters.getSubSubject()).replace("conditionA",basicReportParameters.getClassName())
// .concat(" ").concat(fileName);
// ;
// }
// basicReportCommands.add(command);
// fileToCosPath.put(fileName,basicReportParameters);
// files.add(fileName);
// }
int i = 0;
//偶有出现 遗留两个文件的情况
for (String command : basicReportCommands) {
Thread.sleep(6125);
System.err.println("学科报告总共需生成:" + parametersList.size());
System.err.println("正在生成第" + (++i) + "报告");
System.err.println("执行命令是:");
System.err.println(command);
runtime.exec(command);
// 执行完 上传文件 cos
File file = new File("D:/Class/Subject");
File[] files1 = file.listFiles();
assert files1 != null;
for (File file1 : files1) {
ClassBasicReportParameters parameters = fileToCosPath.get(file1.getAbsolutePath());
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, "class/"+parameters.getExamId()+"/"+parameters.getProvince()+"/"+parameters.getSchool()+"/班级学科报告/"+parameters.getClassName()+"/"+parameters.getSubSubject()+"/"+file1.getName(),file1);
try {
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println(putObjectResult.getRequestId());
file1.delete();
} catch (CosServiceException e ) {
System.out.println("cos服务出现问题");
e.printStackTrace();
} catch (CosClientException e ) {
System.out.println("cos客户端出现问题出现问题的文件是" + files.get(i));
e.printStackTrace();
}
}
}
return ResponseEntity.ok("done");
}
}
package com.example.pdfgenerator.controller;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.*;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@RestController
public class CosController {
@Autowired
private COSClient cosClient;
private static final String BUCKET_NAME = "schoolreportpdf-1317275686";
@GetMapping("/download-folder")
public ResponseEntity<InputStreamResource> downloadFolder(@RequestParam(required = false ,defaultValue = "class/basic/改革/山东省/东平县高级中学") String folderPath) throws IOException {
//删除目录下面的服务器本地上面的zip文件
// List objects in the folder
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(BUCKET_NAME)
.withPrefix(folderPath);
ObjectListing listObjectsResponse = cosClient.listObjects(listObjectsRequest);
List<COSObjectSummary> objectSummaries = listObjectsResponse.getObjectSummaries();
// Create a temporary file for ZIP
File tempZipFile = File.createTempFile("zipFile", ".zip");
// Create ZIP file
try (FileOutputStream fos = new FileOutputStream(tempZipFile);
ZipOutputStream zos = new ZipOutputStream(fos)) {
for (COSObjectSummary objectSummary : objectSummaries) {
String key = objectSummary.getKey();
String fileName = key.substring(key.lastIndexOf('/') + 1);
COSObject s3Object = cosClient.getObject(BUCKET_NAME, key);
try (COSObjectInputStream inputStream = s3Object.getObjectContent()) {
ZipEntry zipEntry = new ZipEntry(fileName);
zos.putNextEntry(zipEntry);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
}
}
var resource = new InputStreamResource(new ByteArrayInputStream(java.nio.file.Files.readAllBytes(tempZipFile.toPath())));
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"zipFile.zip\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
}finally {
if(tempZipFile!=null&&tempZipFile.exists()){
tempZipFile.delete();
}
}
}
}
package com.example.pdfgenerator.controller;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.COSObjectSummary;
import com.qcloud.cos.model.GetObjectRequest;
import com.qcloud.cos.model.ListObjectsRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.*;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@Controller
public class CosDownloadZipFileController {
@Autowired
private COSClient cosClient;
@GetMapping("/getClassReportPdfZipFile")
public ResponseEntity<FileSystemResource> CosClientGen(@RequestParam("region")String region,@RequestParam("province")String province,@RequestParam("school")String school) throws IOException {
String bucketName = "schoolreportpdf-1317275686";
String folderName = "class/"+region+"/"+province+"/"+school;
String localPath = "";
String finishPath = "";
String osName = System.getProperty("os.name").toLowerCase();
// 根据操作系统设置目录
if (osName.contains("win")) {
// Windows系统
localPath = "D:/classZipInit/"+school;
finishPath = "D:/classZipFinish/"+school+".zip";
} else if (osName.contains("nix") || osName.contains("nux")) {
// Linux 系统
localPath = "/customDir/classZipInit/"+school;
finishPath = "/customDir/classZipFinish/"+school+".zip";
}
try {
downloadFolder(cosClient, bucketName, folderName, localPath);
zipDirectory(localPath,finishPath);
} catch (Exception e){
e.printStackTrace();
}finally {
deleteDirectory(Paths.get(localPath));
return downloadZip(finishPath);
}
}
private static void downloadFolder(COSClient cosClient, String bucketName, String folderName, String localPath) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(folderName);
for (COSObjectSummary objectSummary : cosClient.listObjects(listObjectsRequest).getObjectSummaries()) {
String key = objectSummary.getKey();
String localFilePath = localPath +"/"+key.substring(folderName.length());
downloadFile(cosClient, bucketName, key, localFilePath);
}
}
private static void downloadFile(COSClient cosClient, String bucketName, String key, String localFilePath) {
try {
File localFile = new File(localFilePath);
localFile.getParentFile().mkdirs(); // 创建目录
InputStream inputStream = cosClient.getObject(new GetObjectRequest(bucketName, key)).getObjectContent();
try (FileOutputStream fos = new FileOutputStream(localFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
}
System.out.println("Downloaded: " + key);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void zipDirectory(String sourceFolder, String zipFilePath) throws IOException {
Path zipFile = Paths.get(zipFilePath);
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile.toFile()))) {
Path srcPath = Paths.get(sourceFolder);
Files.walk(srcPath)
.filter(path -> !Files.isDirectory(path))
.forEach(path -> {
ZipEntry zipEntry = new ZipEntry(srcPath.relativize(path).toString());
try {
zos.putNextEntry(zipEntry);
Files.copy(path,zos);
zos.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
public static void deleteZipFile(String filePath) throws IOException {
Path path = Paths.get(filePath);
Files.delete(path);
}
public static void deleteDirectory(Path path) throws IOException {
// 使用Files.walkFileTree来遍历文件夹
Files.walk(path)
.sorted((p1, p2) -> p2.compareTo(p1)) // 反向排序以确保从子文件夹到父文件夹删除
.forEach(p -> {
try {
Files.delete(p);
} catch (IOException e) {
System.err.println("无法删除文件: " + p + " " + e.getMessage());
}
});
}
public ResponseEntity<FileSystemResource> downloadZip(String zipPath) throws UnsupportedEncodingException {
File zipFile = new File(zipPath); // 你的ZIP文件路径
if (!zipFile.exists()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
FileSystemResource resource = new FileSystemResource(zipFile);
HttpHeaders headers = new HttpHeaders();
System.out.println(zipFile.getName());
headers.add("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFile.getName(), "UTF-8")+"\"");
new Thread(() -> {
try {
// 等待响应发送后再删除文件
Thread.sleep(2000); // 可根据需要调整延迟
if (zipFile.exists()) {
zipFile.delete();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}).start();
return ResponseEntity.ok()
.headers(headers)
.contentLength(zipFile.length())
.contentType(org.springframework.http.MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
}
}
package com.example.pdfgenerator.controller;
import com.example.pdfgenerator.Dto.BasicReportParameters;
import com.example.pdfgenerator.Dto.ClassBasicReportParameters;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import com.qcloud.cos.COSClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Controller
public class GeneratorAllTypePdfByProvinceController {
private static final Logger logger = LoggerFactory.getLogger(GeneratorAllTypePdfByProvinceController.class);
@Autowired
private COSClient coscLient;
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
private static final String bucketName = "schoolreportpdf-1317275686";
@RequestMapping("/GeneratorByProvinceName")
public ResponseEntity generatorName(@RequestParam("examId")String examId,@RequestParam(value = "provinceName",required = false)String provinceName) throws IOException, InterruptedException {
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
String synthesisSchoolSubjectReportSql = "select \n" +
"school,exam_id,province,region,sub_subject\n" +
"from \n" +
"base_school_subject_tda"+suffix+" \n" +
" where subject_type = '常规'\n";
String synthesisSchoolReportSql = "select \n" +
"school,exam_id,province,region\n" +
"from \n" +
"base_school_total_score_tda"+suffix+" where subject_type = '常规'\n";
String synthesisClassSubjectReportSql = "SELECT\n" +
"\tclass as class_name,\n" +
"\tsub_subject,\n" +
"\tschool,\n" +
"\tprovince,\n" +
"\tregion,\n" +
"\texam_id\n" +
"FROM\n" +
"\tbase_student_subject_tda"+suffix+"\n" +
"where\n" +
"subject_type = '常规'\n" ;
String synthesisClassReportSql = "SELECT\n" +
"\tclass AS class_name,\n" +
"\tschool,\n" +
"\texam_id,\n" +
"\tprovince,\n" +
"\tregion \n" +
"FROM\n" +
"\tbase_class_total_score_tda"+suffix+"\n" +
"WHERE\n" +
"\tsubject_type = '常规'\n" ;
if(provinceName!=null){
List<String> provinceList = Arrays.asList(provinceName.split("#"));
String appendStatement = "and province in (" ;
for (String s : provinceList) {
appendStatement = appendStatement +"'"+s+"',";
}
appendStatement = appendStatement.substring(0,appendStatement.length()-1)+") ";
synthesisSchoolSubjectReportSql = synthesisSchoolSubjectReportSql + " " + appendStatement;
synthesisSchoolReportSql = synthesisSchoolReportSql + " " + appendStatement ;
synthesisClassSubjectReportSql = synthesisClassSubjectReportSql + " " + appendStatement;
synthesisClassReportSql = synthesisClassReportSql + " " + appendStatement;
}
synthesisSchoolSubjectReportSql = synthesisSchoolSubjectReportSql + "group by school,exam_id,province,region,sub_subject";
synthesisSchoolReportSql = synthesisSchoolReportSql + " " + "group by school,exam_id,province,region";
synthesisClassSubjectReportSql = synthesisClassSubjectReportSql + " " + "\tGROUP BY\n" +"\tclass,\n" + "\tsub_subject,\n" + "\tschool,\n" + "\tprovince,\n" + "\tregion,\n" + "\texam_id";
synthesisClassReportSql = synthesisClassReportSql + " " + "GROUP BY\n" + "\tclass,\n" + "\tschool,\n" + "\texam_id,\n" + "\tprovince,\n" + "\tregion\n";
List<BasicReportParameters> synthesisSchoolSubjectReportParameters = this.reportJdbcTemplate.query(synthesisSchoolSubjectReportSql, new Object[]{}, new BeanPropertyRowMapper<>(BasicReportParameters.class));
for (BasicReportParameters parameter : synthesisSchoolSubjectReportParameters) {
if(parameter.getRegion().equals("改革")||parameter.getRegion().equals("改革A")){
String command = "node /myworkSpace/puppeteer2.js \"http://localhost:8080/pdf/subject?province=condition5&school=condition1&examId=condition4&region=conditionC&subSubject=condition6&subjectType=常规\" pdf";
command = command.replace("condition1", parameter.getSchool()).replace("condition5", parameter.getProvince()).replace("conditionC", parameter.getRegion()).replace("condition4", parameter.getExamId()).replace("condition6", parameter.getSubSubject())
.concat(" ").concat("/myworkSpace/subject/" + parameter.getRegion() + parameter.getProvince() + parameter.getSchool() + parameter.getSubSubject() + parameter.getExamId() + ".pdf");
parameter.setCommand(command);
}else{
String command = "node /myworkSpace/puppeteer2.js \"http://localhost:8080/pdf/subject?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subSubject=condition6&subjectType=常规\" pdf";
command = command.replace("condition1", parameter.getSchool()).replace("condition5", parameter.getProvince()).replace("condition3", parameter.getRegion()).replace("condition4", parameter.getExamId()).replace("condition6", parameter.getSubSubject())
.concat(" ").concat("/myworkSpace/subject/" + parameter.getRegion() + parameter.getProvince() + parameter.getSchool() + parameter.getSubSubject() + parameter.getExamId() + ".pdf");
parameter.setCommand(command);
}
}
List<BasicReportParameters> synthesisSchoolReportParameters = this.reportJdbcTemplate.query(synthesisSchoolReportSql, new Object[]{}, new BeanPropertyRowMapper<>(BasicReportParameters.class));
for (BasicReportParameters synthesisSchoolReportParameter : synthesisSchoolReportParameters) {
if(synthesisSchoolReportParameter.getRegion().equals("改革")||synthesisSchoolReportParameter.getRegion().equals("改革A")){
String command = "node /myworkSpace/puppeteer.js \"http://localhost:8080/pdf/basic?province=condition5&school=condition1&examId=condition4&region=conditionC&subjectType=常规\" pdf ";
command = command.replace("condition1", synthesisSchoolReportParameter.getSchool()).replace("condition5", synthesisSchoolReportParameter.getProvince()).replace("conditionC",synthesisSchoolReportParameter.getRegion()).replace("condition4", synthesisSchoolReportParameter.getExamId())
.concat(" ").concat("/myworkSpace/basic/"+synthesisSchoolReportParameter.getRegion()+synthesisSchoolReportParameter.getProvince()+synthesisSchoolReportParameter.getSchool()+synthesisSchoolReportParameter.getExamId()+".pdf");
synthesisSchoolReportParameter.setCommand(command);
}else{
String command = "node /myworkSpace/puppeteer.js \"http://localhost:8080/pdf/basic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规\" pdf ";
command = command.replace("condition1", synthesisSchoolReportParameter.getSchool()).replace("condition5", synthesisSchoolReportParameter.getProvince()).replace("condition3",synthesisSchoolReportParameter.getRegion()).replace("condition4", synthesisSchoolReportParameter.getExamId())
.concat(" ").concat("/myworkSpace/basic/"+synthesisSchoolReportParameter.getRegion()+synthesisSchoolReportParameter.getProvince()+synthesisSchoolReportParameter.getSchool()+synthesisSchoolReportParameter.getExamId()+".pdf");
synthesisSchoolReportParameter.setCommand(command);
}
}
List<ClassBasicReportParameters> synthesisClassSubjectReportParameters = this.reportJdbcTemplate.query(synthesisClassSubjectReportSql,new Object[]{},new BeanPropertyRowMapper<>(ClassBasicReportParameters.class));
for (ClassBasicReportParameters synthesisClassSubjectReportParameter : synthesisClassSubjectReportParameters) {
if (synthesisClassSubjectReportParameter.getRegion().equals("改革")||synthesisClassSubjectReportParameter.getRegion().equals("改革A")) {
String command = "node /myworkSpace/pdfOfClassSubjectGen.js \"http://localhost:8080/pdf/classSubject?province=condition5&school=condition1&examId=condition4&region=conditionC&subSubject=condition6&subjectType=常规&className=conditionA\" pdf";
String fileName = "/myworkSpace/Class/subject/" + synthesisClassSubjectReportParameter.getRegion() + synthesisClassSubjectReportParameter.getProvince() + synthesisClassSubjectReportParameter.getSchool() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getExamId() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getClassName().replace(" ","")+ ".pdf";
command = command.replace("condition1", synthesisClassSubjectReportParameter.getSchool()).replace("condition5", synthesisClassSubjectReportParameter.getProvince()).replace("conditionC", synthesisClassSubjectReportParameter.getRegion()).replace("condition4", synthesisClassSubjectReportParameter.getExamId()).replace("condition6", synthesisClassSubjectReportParameter.getSubSubject()).replace("conditionA",synthesisClassSubjectReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassSubjectReportParameter.setCommand(command);
} else {
String command = "node /myworkSpace/pdfOfClassSubjectGen.js \"http://localhost:8080/pdf/classSubject?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subSubject=condition6&subjectType=常规&className=conditionA\" pdf";
String fileName = "/myworkSpace/Class/subject/" + synthesisClassSubjectReportParameter.getRegion() + synthesisClassSubjectReportParameter.getProvince() + synthesisClassSubjectReportParameter.getSchool() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getExamId() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getClassName().replace(" ","")+".pdf";
command = command.replace("condition1", synthesisClassSubjectReportParameter.getSchool()).replace("condition5", synthesisClassSubjectReportParameter.getProvince()).replace("condition3", synthesisClassSubjectReportParameter.getRegion()).replace("condition4", synthesisClassSubjectReportParameter.getExamId()).replace("condition6", synthesisClassSubjectReportParameter.getSubSubject()).replace("conditionA",synthesisClassSubjectReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassSubjectReportParameter.setCommand(command);
}
}
List<ClassBasicReportParameters> synthesisClassReportParameters = this.reportJdbcTemplate.query(synthesisClassReportSql,new Object[]{},new BeanPropertyRowMapper<>(ClassBasicReportParameters.class));
for (ClassBasicReportParameters synthesisClassReportParameter : synthesisClassReportParameters) {
if(synthesisClassReportParameter.getRegion().equals("改革")||synthesisClassReportParameter.getRegion().equals("改革A")){
String command = "node /myworkSpace/pdfOfClassBasicGen.js \"http://localhost:8080/pdf/classBasic?province=condition5&school=condition1&examId=condition4&region=conditionC&subjectType=常规&className=conditionA\" pdf ";
String fileName = "/myworkSpace/Class/Basic/"+synthesisClassReportParameter.getRegion()+synthesisClassReportParameter.getProvince()+synthesisClassReportParameter.getSchool()+ synthesisClassReportParameter.getClassName()+synthesisClassReportParameter.getExamId()+".pdf";
command = command.replace("condition1", synthesisClassReportParameter.getSchool()).replace("condition5", synthesisClassReportParameter.getProvince()).replace("conditionC",synthesisClassReportParameter.getRegion()).replace("condition4", synthesisClassReportParameter.getExamId()).replace("conditionA",synthesisClassReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassReportParameter.setCommand(command);
} else {
String command = "node/myworkSpace/pdfOfClassBasicGen.js \"http://localhost:8080/pdf/classBasic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规&className=conditionA\" pdf ";
String fileName = "/myworkSpace/Class/Basic/"+synthesisClassReportParameter.getRegion()+synthesisClassReportParameter.getProvince()+synthesisClassReportParameter.getSchool()+synthesisClassReportParameter.getClassName()+synthesisClassReportParameter.getExamId()+".pdf";
command = command.replace("condition1", synthesisClassReportParameter.getSchool()).replace("condition5", synthesisClassReportParameter.getProvince()).replace("condition3",synthesisClassReportParameter.getRegion()).replace("condition4", synthesisClassReportParameter.getExamId()).replace("conditionA",synthesisClassReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassReportParameter.setCommand(command);
}
}
Map<String, List<BasicReportParameters>> schoolReport = synthesisSchoolReportParameters.stream().collect(Collectors.groupingBy(BasicReportParameters::getProvince));
Map<String, List<BasicReportParameters>> schoolSubjectReport = synthesisSchoolSubjectReportParameters.stream().collect(Collectors.groupingBy(BasicReportParameters::getProvince));
Map<String, List<ClassBasicReportParameters>> classReport = synthesisClassReportParameters.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getProvince));
Map<String, List<ClassBasicReportParameters>> classSubjectReport = synthesisClassSubjectReportParameters.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getProvince));
//分组开始执行记录
for (String key : schoolReport.keySet()) {
logger.info("province:"+key+ "Gen...............................................................");
List<BasicReportParameters> schoolBasicReport = schoolReport.get(key);
List<BasicReportParameters> schoolSubject = schoolSubjectReport.get(key);
List<ClassBasicReportParameters> classBasicReport = classReport.get(key);
List<ClassBasicReportParameters> classSubject = classSubjectReport.get(key);
for (BasicReportParameters schoolLevel : schoolBasicReport) {
logger.info("school:"+schoolLevel.getSchool()+"loading---------------------------------------------------------------");
Map<String, List<BasicReportParameters>> schoolMap= schoolSubject.stream().collect(Collectors.groupingBy(BasicReportParameters::getSchool));
Map<String, List<ClassBasicReportParameters>> classBasic = classBasicReport.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getSchool));
final Map<String, List<ClassBasicReportParameters>> subjectClass = classSubject.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getSchool));
List<BasicReportParameters> schoolSelf = schoolMap.get(schoolLevel.getSchool());
logger.info("basicReport:loading******************************************");
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", schoolLevel.getCommand());
processBuilder.redirectErrorStream(true); // 合并标准输出和错误输出
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
}
int exitCode = process.waitFor();
logger.info("exitCode:"+schoolLevel.getSchool());
for (BasicReportParameters parameters : schoolSelf) {
logger.info("subjectReport:loading***************************************************************");
ProcessBuilder processBuilderSubject = new ProcessBuilder();
processBuilderSubject.command("bash", "-c", parameters.getCommand());
processBuilderSubject.redirectErrorStream(true); // 合并标准输出和错误输出
Process processSubject = processBuilderSubject.start();
BufferedReader readerSubject = new BufferedReader(new InputStreamReader(processSubject.getInputStream()));
String lineSubject;
while ((lineSubject = readerSubject.readLine()) != null) {
}
int exitCodeSubject = processSubject.waitFor();
logger.info("exitCode:"+parameters.getSubSubject());
}
List<ClassBasicReportParameters> args = classBasic.get(schoolLevel.getSchool());
List<ClassBasicReportParameters> params = subjectClass.get(schoolLevel.getSchool());
for (ClassBasicReportParameters arg : args) {
logger.info("classBasic:loading++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
ProcessBuilder processBuilderClass = new ProcessBuilder();
processBuilderClass.command("bash", "-c", arg.getCommand());
processBuilderClass.redirectErrorStream(true); // 合并标准输出和错误输出
Process processClass = processBuilderClass.start();
BufferedReader readerClass = new BufferedReader(new InputStreamReader(processClass.getInputStream()));
String lineClass;
while ((lineClass = readerClass.readLine()) != null) {
}
int exitCodeSubject = processClass.waitFor();
logger.info("exitCode:"+arg.getClassName());
final Map<String, List<ClassBasicReportParameters>> collect = params.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getClassName));
List<ClassBasicReportParameters> list = collect.get(arg.getClassName());
for (ClassBasicReportParameters classBasicReportParameters : list) {
logger.info("classSubject:loading++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
ProcessBuilder processBuilderClassSubject = new ProcessBuilder();
processBuilderClassSubject.command("bash", "-c", classBasicReportParameters.getCommand());
processBuilderClassSubject.redirectErrorStream(true); // 合并标准输出和错误输出
Process processClassSubject = processBuilderClassSubject.start();
BufferedReader readerClassSubject = new BufferedReader(new InputStreamReader(processClassSubject.getInputStream()));
String lineClassSubject;
while ((lineClassSubject = readerClassSubject.readLine()) != null) {
}
int exitCodeSubjectClass = processClassSubject.waitFor();
logger.info("exitCode:"+classBasicReportParameters.getSubSubject());
}
}
}
}
return null;
}
}
package com.example.pdfgenerator.controller;
import com.example.pdfgenerator.Dto.BasicReportParameters;
import com.example.pdfgenerator.Dto.ClassBasicReportParameters;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import com.qcloud.cos.COSClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
@RestController
public class PDFGeByProvinceBatchController {
private static final Logger logger = LoggerFactory.getLogger(GeneratorAllTypePdfByProvinceController.class);
@Autowired
private COSClient coscLient;
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
private static final String bucketName = "schoolreportpdf-1317275686";
@RequestMapping("/BatchGeByProvinceName")
public ResponseEntity generatorName(@RequestParam("examId")String examId, @RequestParam(value = "provinceName",required = false)String provinceName) throws IOException, InterruptedException {
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
String synthesisSchoolSubjectReportSql = "select \n" +
"school,exam_id,province,region,sub_subject\n" +
"from \n" +
"base_school_subject_tda"+suffix+" \n" +
" where subject_type = '常规'\n";
String synthesisSchoolReportSql = "select \n" +
"school,exam_id,province,region\n" +
"from \n" +
"base_school_total_score_tda"+suffix+" where subject_type = '常规'\n";
String synthesisClassSubjectReportSql = "SELECT\n" +
"\tclass as class_name,\n" +
"\tsub_subject,\n" +
"\tschool,\n" +
"\tprovince,\n" +
"\tregion,\n" +
"\texam_id\n" +
"FROM\n" +
"\tbase_student_subject_tda"+suffix+"\n" +
"where\n" +
"subject_type = '常规'\n" ;
String synthesisClassReportSql = "SELECT\n" +
"\tclass AS class_name,\n" +
"\tschool,\n" +
"\texam_id,\n" +
"\tprovince,\n" +
"\tregion \n" +
"FROM\n" +
"\tbase_class_total_score_tda"+suffix+"\n" +
"WHERE\n" +
"\tsubject_type = '常规'\n" ;
if(provinceName!=null){
List<String> provinceList = Arrays.asList(provinceName.split("#"));
String appendStatement = "and province in (" ;
for (String s : provinceList) {
appendStatement = appendStatement +"'"+s+"',";
}
appendStatement = appendStatement.substring(0,appendStatement.length()-1)+") ";
synthesisSchoolSubjectReportSql = synthesisSchoolSubjectReportSql + " " + appendStatement;
synthesisSchoolReportSql = synthesisSchoolReportSql + " " + appendStatement ;
synthesisClassSubjectReportSql = synthesisClassSubjectReportSql + " " + appendStatement;
synthesisClassReportSql = synthesisClassReportSql + " " + appendStatement;
}
synthesisSchoolSubjectReportSql = synthesisSchoolSubjectReportSql + "group by school,exam_id,province,region,sub_subject";
synthesisSchoolReportSql = synthesisSchoolReportSql + " " + "group by school,exam_id,province,region";
synthesisClassSubjectReportSql = synthesisClassSubjectReportSql + " " + "\tGROUP BY\n" +"\tclass,\n" + "\tsub_subject,\n" + "\tschool,\n" + "\tprovince,\n" + "\tregion,\n" + "\texam_id";
synthesisClassReportSql = synthesisClassReportSql + " " + "GROUP BY\n" + "\tclass,\n" + "\tschool,\n" + "\texam_id,\n" + "\tprovince,\n" + "\tregion\n";
List<BasicReportParameters> synthesisSchoolSubjectReportParameters = this.reportJdbcTemplate.query(synthesisSchoolSubjectReportSql, new Object[]{}, new BeanPropertyRowMapper<>(BasicReportParameters.class));
for (BasicReportParameters parameter : synthesisSchoolSubjectReportParameters) {
if(parameter.getRegion().equals("改革")||parameter.getRegion().equals("改革A")){
String command = "node /myworkSpace/puppeteer2.js \"https://schoolreport.cssatest.com/pdf/subject?province=condition5&school=condition1&examId=condition4&region=conditionC&subSubject=condition6&subjectType=常规\" pdf";
command = command.replace("condition1", parameter.getSchool()).replace("condition5", parameter.getProvince()).replace("conditionC", parameter.getRegion()).replace("condition4", parameter.getExamId()).replace("condition6", parameter.getSubSubject())
.concat(" ").concat("/myworkSpace/subject/" + parameter.getRegion() + parameter.getProvince() + parameter.getSchool() + parameter.getSubSubject() + parameter.getExamId() + ".pdf");
parameter.setCommand(command);
}else{
String command = "node /myworkSpace/puppeteer2.js \"https://schoolreport.cssatest.com/pdf/subject?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subSubject=condition6&subjectType=常规\" pdf";
command = command.replace("condition1", parameter.getSchool()).replace("condition5", parameter.getProvince()).replace("condition3", parameter.getRegion()).replace("condition4", parameter.getExamId()).replace("condition6", parameter.getSubSubject())
.concat(" ").concat("/myworkSpace/subject/" + parameter.getRegion() + parameter.getProvince() + parameter.getSchool() + parameter.getSubSubject() + parameter.getExamId() + ".pdf");
parameter.setCommand(command);
}
}
List<BasicReportParameters> synthesisSchoolReportParameters = this.reportJdbcTemplate.query(synthesisSchoolReportSql, new Object[]{}, new BeanPropertyRowMapper<>(BasicReportParameters.class));
for (BasicReportParameters synthesisSchoolReportParameter : synthesisSchoolReportParameters) {
if(synthesisSchoolReportParameter.getRegion().equals("改革")||synthesisSchoolReportParameter.getRegion().equals("改革A")){
String command = "node /myworkSpace/puppeteer.js \"https://schoolreport.cssatest.com/pdf/basic?province=condition5&school=condition1&examId=condition4&region=conditionC&subjectType=常规\" pdf ";
command = command.replace("condition1", synthesisSchoolReportParameter.getSchool()).replace("condition5", synthesisSchoolReportParameter.getProvince()).replace("conditionC",synthesisSchoolReportParameter.getRegion()).replace("condition4", synthesisSchoolReportParameter.getExamId())
.concat(" ").concat("/myworkSpace/basic/"+synthesisSchoolReportParameter.getRegion()+synthesisSchoolReportParameter.getProvince()+synthesisSchoolReportParameter.getSchool()+synthesisSchoolReportParameter.getExamId()+".pdf");
synthesisSchoolReportParameter.setCommand(command);
}else{
String command = "node /myworkSpace/puppeteer.js \"https://schoolreport.cssatest.com/pdf/basic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规\" pdf ";
command = command.replace("condition1", synthesisSchoolReportParameter.getSchool()).replace("condition5", synthesisSchoolReportParameter.getProvince()).replace("condition3",synthesisSchoolReportParameter.getRegion()).replace("condition4", synthesisSchoolReportParameter.getExamId())
.concat(" ").concat("/myworkSpace/basic/"+synthesisSchoolReportParameter.getRegion()+synthesisSchoolReportParameter.getProvince()+synthesisSchoolReportParameter.getSchool()+synthesisSchoolReportParameter.getExamId()+".pdf");
synthesisSchoolReportParameter.setCommand(command);
}
}
List<ClassBasicReportParameters> synthesisClassSubjectReportParameters = this.reportJdbcTemplate.query(synthesisClassSubjectReportSql,new Object[]{},new BeanPropertyRowMapper<>(ClassBasicReportParameters.class));
for (ClassBasicReportParameters synthesisClassSubjectReportParameter : synthesisClassSubjectReportParameters) {
if (synthesisClassSubjectReportParameter.getRegion().equals("改革")||synthesisClassSubjectReportParameter.getRegion().equals("改革A")) {
String command = "node /myworkSpace/pdfOfClassSubjectGen.js \"https://schoolreport.cssatest.com/pdf/classSubject?province=condition5&school=condition1&examId=condition4&region=conditionC&subSubject=condition6&subjectType=常规&className=conditionA\" pdf";
String fileName = "/myworkSpace/Class/subject/" + synthesisClassSubjectReportParameter.getRegion() + synthesisClassSubjectReportParameter.getProvince() + synthesisClassSubjectReportParameter.getSchool() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getExamId() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getClassName().replace(" ","")+ ".pdf";
command = command.replace("condition1", synthesisClassSubjectReportParameter.getSchool()).replace("condition5", synthesisClassSubjectReportParameter.getProvince()).replace("conditionC", synthesisClassSubjectReportParameter.getRegion()).replace("condition4", synthesisClassSubjectReportParameter.getExamId()).replace("condition6", synthesisClassSubjectReportParameter.getSubSubject()).replace("conditionA",synthesisClassSubjectReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassSubjectReportParameter.setCommand(command);
} else {
String command = "node /myworkSpace/pdfOfClassSubjectGen.js \"https://schoolreport.cssatest.com/pdf/classSubject?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subSubject=condition6&subjectType=常规&className=conditionA\" pdf";
String fileName = "/myworkSpace/Class/subject/" + synthesisClassSubjectReportParameter.getRegion() + synthesisClassSubjectReportParameter.getProvince() + synthesisClassSubjectReportParameter.getSchool() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getExamId() + synthesisClassSubjectReportParameter.getSubSubject() + synthesisClassSubjectReportParameter.getClassName().replace(" ","")+".pdf";
command = command.replace("condition1", synthesisClassSubjectReportParameter.getSchool()).replace("condition5", synthesisClassSubjectReportParameter.getProvince()).replace("condition3", synthesisClassSubjectReportParameter.getRegion()).replace("condition4", synthesisClassSubjectReportParameter.getExamId()).replace("condition6", synthesisClassSubjectReportParameter.getSubSubject()).replace("conditionA",synthesisClassSubjectReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassSubjectReportParameter.setCommand(command);
}
}
List<ClassBasicReportParameters> synthesisClassReportParameters = this.reportJdbcTemplate.query(synthesisClassReportSql,new Object[]{},new BeanPropertyRowMapper<>(ClassBasicReportParameters.class));
for (ClassBasicReportParameters synthesisClassReportParameter : synthesisClassReportParameters) {
if(synthesisClassReportParameter.getRegion().equals("改革")||synthesisClassReportParameter.getRegion().equals("改革A")){
String command = "node /myworkSpace/pdfOfClassBasicGen.js \"https://schoolreport.cssatest.com/pdf/classBasic?province=condition5&school=condition1&examId=condition4&region=conditionC&subjectType=常规&className=conditionA\" pdf ";
String fileName = "/myworkSpace/Class/Basic/"+synthesisClassReportParameter.getRegion()+synthesisClassReportParameter.getProvince()+synthesisClassReportParameter.getSchool()+ synthesisClassReportParameter.getClassName()+synthesisClassReportParameter.getExamId()+".pdf";
command = command.replace("condition1", synthesisClassReportParameter.getSchool()).replace("condition5", synthesisClassReportParameter.getProvince()).replace("conditionC",synthesisClassReportParameter.getRegion()).replace("condition4", synthesisClassReportParameter.getExamId()).replace("conditionA",synthesisClassReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassReportParameter.setCommand(command);
} else {
String command = "node/myworkSpace/pdfOfClassBasicGen.js \"https://schoolreport.cssatest.com/pdf/classBasic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规&className=conditionA\" pdf ";
String fileName = "/myworkSpace/Class/Basic/"+synthesisClassReportParameter.getRegion()+synthesisClassReportParameter.getProvince()+synthesisClassReportParameter.getSchool()+synthesisClassReportParameter.getClassName()+synthesisClassReportParameter.getExamId()+".pdf";
command = command.replace("condition1", synthesisClassReportParameter.getSchool()).replace("condition5", synthesisClassReportParameter.getProvince()).replace("condition3",synthesisClassReportParameter.getRegion()).replace("condition4", synthesisClassReportParameter.getExamId()).replace("conditionA",synthesisClassReportParameter.getClassName())
.concat(" ").concat(fileName);
synthesisClassReportParameter.setCommand(command);
}
}
Map<String, List<BasicReportParameters>> schoolReport = synthesisSchoolReportParameters.stream().collect(Collectors.groupingBy(BasicReportParameters::getProvince));
Map<String, List<BasicReportParameters>> schoolSubjectReport = synthesisSchoolSubjectReportParameters.stream().collect(Collectors.groupingBy(BasicReportParameters::getProvince));
Map<String, List<ClassBasicReportParameters>> classReport = synthesisClassReportParameters.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getProvince));
Map<String, List<ClassBasicReportParameters>> classSubjectReport = synthesisClassSubjectReportParameters.stream().collect(Collectors.groupingBy(ClassBasicReportParameters::getProvince));
//分组开始执行记录
for (String key : schoolReport.keySet()) {
logger.info("province:"+key+ "Gen...............................................................");
List<BasicReportParameters> schoolBasicReport = schoolReport.get(key);
List<BasicReportParameters> schoolSubject = schoolSubjectReport.get(key);
for (BasicReportParameters schoolLevel : schoolBasicReport) {
logger.info("school:"+schoolLevel.getSchool()+"loading---------------------------------------------------------------");
Map<String, List<BasicReportParameters>> schoolMap= schoolSubject.stream().collect(Collectors.groupingBy(BasicReportParameters::getSchool));
logger.info("basicReport:loading******************************************");
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", schoolLevel.getCommand());
processBuilder.redirectErrorStream(true); // 合并标准输出和错误输出
Process process = processBuilder.start();
// BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
// String line;
// while ((line = reader.readLine()) != null) {
// }
Thread.sleep(1000);
int exitCode = process.waitFor();
logger.info("exitCode:"+schoolLevel.getSchool());
}
}
return null;
}
}
package com.example.pdfgenerator.controller;
import com.example.pdfgenerator.Dto.BasicReportParameters;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/logHandle")
public class SchoolReportGenUploadController {
@Autowired
private COSClient cosClient;
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
private static final String bucketName = "schoolreportpdf-1317275686";
@PostMapping("/GeneratorBatchUrls")
public ResponseEntity GeneratorBatchUrls(@RequestParam("examId")String examId) throws IOException, InterruptedException {
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
String sqlStatement = "select \n" +
"school,exam_id,province,region\n" +
"from \n" +
"base_school_total_score_tda"+suffix+" where subject_type = '常规'\n" +
"group by school,exam_id,province,region";
List<BasicReportParameters> parametersList = this.reportJdbcTemplate.query(sqlStatement,new Object[]{},new BeanPropertyRowMapper<>(BasicReportParameters.class));
Runtime runtime = Runtime.getRuntime();
List<String> basicReportCommands = new ArrayList<>();
List<String> files = new ArrayList<>();
String reformCommand = "http://localhost:8080/pdf/basic?province=condition5&school=condition1&examId=condition4&region=改革&subjectType=常规";
String unReformCommand = "http://localhost:8080/pdf/basic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规";
for (BasicReportParameters basicReportParameters : parametersList) {
String command = "";
String fileName = "";
if(basicReportParameters.getRegion().equals("改革")){
command = reformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3",basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId());
}else{
command = unReformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3",basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId());
}
basicReportCommands.add(command);
files.add(fileName);
}
int i = 0;
for (String command : basicReportCommands) {
System.out.println("\""+command+"\""+",");
}
return ResponseEntity.ok("done");
}
@PostMapping("/BatchBasicPdfGenerator")
public ResponseEntity batchPdfGenerator(@RequestParam("examId")String examId) throws IOException, InterruptedException {
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
String sqlStatement = "select \n" +
"school,exam_id,province,region\n" +
"from \n" +
"base_school_total_score_tda"+suffix+" where subject_type = '常规'\n" +
"group by school,exam_id,province,region";
List<BasicReportParameters> parametersList = this.reportJdbcTemplate.query(sqlStatement,new Object[]{},new BeanPropertyRowMapper<>(BasicReportParameters.class));
Runtime runtime = Runtime.getRuntime();
List<String> basicReportCommands = new ArrayList<>();
List<String> files = new ArrayList<>();
String reformCommand = "node D:\\myWorkSpace\\puppeteer.js \"http://localhost:8080/pdf/basic?province=condition5&school=condition1&examId=condition4&region=conditionC&subjectType=常规\" pdf ";
String unReformCommand = "node D:\\myWorkSpace\\puppeteer.js \"http://localhost:8080/pdf/basic?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subjectType=常规\" pdf ";
for (BasicReportParameters basicReportParameters : parametersList) {
String command = "";
String fileName = "";
if(basicReportParameters.getRegion().equals("改革")||basicReportParameters.getRegion().equals("改革A")){
fileName = "PdfDir\\"+basicReportParameters.getRegion()+basicReportParameters.getProvince()+basicReportParameters.getSchool()+basicReportParameters.getExamId()+".pdf";
command = reformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("conditionC",basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId())
.concat(" ").concat("D:\\PdfDir\\"+basicReportParameters.getRegion()+basicReportParameters.getProvince()+basicReportParameters.getSchool()+basicReportParameters.getExamId()+".pdf");
}else{
fileName = "PdfDir\\"+basicReportParameters.getRegion()+basicReportParameters.getProvince()+basicReportParameters.getSchool()+basicReportParameters.getExamId()+".pdf";
command = unReformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3",basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId())
.concat(" ").concat("D:\\PdfDir\\"+basicReportParameters.getRegion()+basicReportParameters.getProvince()+basicReportParameters.getSchool()+basicReportParameters.getExamId()+".pdf");;
}
basicReportCommands.add(command);
files.add(fileName);
}
int i = 0;
for (String command : basicReportCommands) {
System.out.println("基础报告总共需生成:"+basicReportCommands.size());
System.out.println("正在生成第"+(++i)+"报告");
System.out.println("执行命令是:");
System.out.println(command);
runtime.exec(command);
Thread.sleep(15000);
//上传到cos当中去
File file = new File("D:\\PdfDir");
File[] files1 = file.listFiles();
assert files1 != null;
for (File file1 : files1) {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, "PdfDir/"+file1.getName(), file1);
try {
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
System.out.println(putObjectResult.getRequestId());
file1.delete();
} catch (CosServiceException e) {
System.out.println("cos服务出现问题");
e.printStackTrace();
} catch (CosClientException e) {
System.out.println("cos客户端出现问题出现问题的文件是"+files.get(i));
e.printStackTrace();
}
}
}
return ResponseEntity.ok("done");
}
@PostMapping("/BatchSubjectPdfGenerator")
public ResponseEntity BatchSubjectPdfGenerator(@RequestParam(value = "examId",defaultValue = "TDA20240919G2")String examId) throws IOException, InterruptedException {
String suffix = examId.trim().replace("TDA","").replace("G3","").replace("G2","").trim();
String sqlStatement = "select \n" +
"school,exam_id,province,region,sub_subject\n" +
"from \n" +
"base_school_subject_tda"+suffix+" \n" +
" where subject_type = '常规'\n"+
"group by school,exam_id,province,region,sub_subject";
List<BasicReportParameters> parametersList = this.reportJdbcTemplate.query(sqlStatement, new Object[]{}, new BeanPropertyRowMapper<>(BasicReportParameters.class));
Runtime runtime = Runtime.getRuntime();
List<String> basicReportCommands = new ArrayList<>();
List<String> files = new ArrayList<>();
String reformCommand = "node /myworkSpace/puppeteer2.js \"https://schoolreport.cssatest.com/pdf/subject?province=condition5&school=condition1&examId=condition4&region=conditionC&subSubject=condition6&subjectType=常规\" pdf";
String unReformCommand = "node /myworkSpace/puppeteer2.js \"https://schoolreport.cssatest.com/pdf/subject?province=condition5&school=condition1&examId=condition4&region=非改革&branch=condition3&subSubject=condition6&subjectType=常规\" pdf";
for (BasicReportParameters basicReportParameters : parametersList) {
String command = "";
String fileName = "";
if (basicReportParameters.getRegion().equals("改革")||basicReportParameters.getRegion().equals("改革A")) {
// fileName = "PdfSubject\\" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + ".pdf";
fileName = "/myworkSpace/" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + ".pdf";
command = reformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("conditionC", basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("condition6", basicReportParameters.getSubSubject())
// .concat(" ").concat("D:\\PdfSubject\\" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + ".pdf");
.concat(" ").concat("/myworkSpace/subject/" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + ".pdf");
} else {
fileName = "/myworkSpace/" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + ".pdf";
command = unReformCommand.replace("condition1", basicReportParameters.getSchool()).replace("condition5", basicReportParameters.getProvince()).replace("condition3", basicReportParameters.getRegion()).replace("condition4", basicReportParameters.getExamId()).replace("condition6", basicReportParameters.getSubSubject())
.concat(" ").concat("/myworkSpace/subject/" + basicReportParameters.getRegion() + basicReportParameters.getProvince() + basicReportParameters.getSchool() + basicReportParameters.getSubSubject() + basicReportParameters.getExamId() + ".pdf");
;
}
basicReportCommands.add(command);
files.add(fileName);
}
int i = 0;
for (String basicReportCommand : basicReportCommands) {
try {
System.err.println("学科报告总共需生成:" + basicReportCommands.size());
System.err.println("正在生成第" + (++i) + "报告");
System.err.println("执行命令是:");
System.err.println(basicReportCommand);
// 使用 ProcessBuilder 创建进程
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", basicReportCommand);
processBuilder.redirectErrorStream(true); // 合并标准输出和错误输出
// 启动进程
Process process = processBuilder.start();
// 获取输出流并读取命令输出
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// 等待进程结束并获取退出值
int exitCode = process.waitFor();
System.out.println("\nExited with error code : " + exitCode);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
//偶有出现 遗留两个文件的情况
// for (String command : basicReportCommands) {
// Thread.sleep(6000);
// System.err.println("学科报告总共需生成:" + basicReportCommands.size());
// System.err.println("正在生成第" + (++i) + "报告");
// System.err.println("执行命令是:");
// System.err.println(command);
// runtime.exec(command);
// 执行完 上传文件 cos
// File file = new File("D:\\PdfSubject");
// File[] files1 = file.listFiles();
// assert files1 != null;
// for (File file1 : files1) {
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, "PdfSubject/" + file1.getName(), file1);
// try {
// PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
// System.out.println(putObjectResult.getRequestId());
// file1.delete();
// } catch (CosServiceException e) {
// System.out.println("cos服务出现问题");
// e.printStackTrace();
// } catch (CosClientException e) {
// System.out.println("cos客户端出现问题出现问题的文件是" + files.get(i));
// e.printStackTrace();
// }
// }
// }
return ResponseEntity.ok("done");
}
}
server:
port: 8059
spring:
datasource:
url: jdbc:mysql://192.168.0.46:3306/temp_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
username: jiru
password: Jiru@20231026
druid:
initial-size: 5
max-active: 200
min-idle: 5
max-wait: 6000
redis:
host: 192.168.0.4
port: 6379
password: Thussat@2023
database: 101
lettuce:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
token :
prefix: authentication
redis: "user_name:"
verification :
prefix: "login_verification:"
package com.example.pdfgenerator.CampsitePackages;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SpringBootTest
public class CampsiteTestClass {
@Test
public void ExcelExport(){
String code = "1A027422328";
// 定义正则表达式
String regex = "^\\d[A-Z]\\d{9}$";
// 编译正则表达式
Pattern pattern = Pattern.compile(regex);
// 创建匹配器
Matcher matcher = pattern.matcher(code);
// 检查是否匹配
if (matcher.matches()) {
System.out.println("1");
} else {
System.out.println("2");
}
}
}
package com.example.pdfgenerator;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.COSObjectSummary;
import com.qcloud.cos.model.GetObjectRequest;
import com.qcloud.cos.model.ListObjectsRequest;
import com.qcloud.cos.model.ciModel.common.MediaOutputObject;
import com.qcloud.cos.model.ciModel.job.FileCompressConfig;
import com.qcloud.cos.model.ciModel.job.FileProcessJobResponse;
import com.qcloud.cos.model.ciModel.job.FileProcessJobType;
import com.qcloud.cos.model.ciModel.job.FileProcessRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@SpringBootTest
public class CosClientDownloadZipFile {
@Autowired
private COSClient cosClient;
@Test
public void CosClientGen() throws IOException {
String bucketName = "schoolreportpdf-1317275686";
String folderName = "class/basic/改革/山东省/东平县高级中学";
String localPath = "D:/classZipInit/东平县高级中学/";
String finishPath = "D:/classZipFinish/东平县高级中学.zip";
try {
downloadFolder(cosClient, bucketName, folderName, localPath);
zipDirectory(localPath,finishPath);
} finally {
cosClient.shutdown();
}
}
private static void downloadFolder(COSClient cosClient, String bucketName, String folderName, String localPath) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(folderName);
for (COSObjectSummary objectSummary : cosClient.listObjects(listObjectsRequest).getObjectSummaries()) {
String key = objectSummary.getKey();
String localFilePath = localPath + key.substring(folderName.length());
downloadFile(cosClient, bucketName, key, localFilePath);
}
}
private static void downloadFile(COSClient cosClient, String bucketName, String key, String localFilePath) {
try {
File localFile = new File(localFilePath);
localFile.getParentFile().mkdirs(); // 创建目录
InputStream inputStream = cosClient.getObject(new GetObjectRequest(bucketName, key)).getObjectContent();
try (FileOutputStream fos = new FileOutputStream(localFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
}
System.out.println("Downloaded: " + key);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void zipDirectory(String sourceFolder, String zipFilePath) throws IOException {
Path zipFile = Paths.get(zipFilePath);
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile.toFile()))) {
Path srcPath = Paths.get(sourceFolder);
Files.walk(srcPath)
.filter(path -> !Files.isDirectory(path))
.forEach(path -> {
ZipEntry zipEntry = new ZipEntry(srcPath.relativize(path).toString());
try {
zos.putNextEntry(zipEntry);
Files.copy(path, zos);
zos.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
@Test
public void delDirectory(){
String directoryPath = "D:/classZipInit/东平县高级中学"; // 替换为你的文件夹路径
try {
deleteDirectory(Paths.get(directoryPath));
System.out.println("文件夹已成功删除");
} catch (IOException e) {
System.err.println("删除文件夹时出错: " + e.getMessage());
}
}
public static void deleteDirectory(Path path) throws IOException {
// 使用Files.walkFileTree来遍历文件夹
Files.walk(path)
.sorted((p1, p2) -> p2.compareTo(p1)) // 反向排序以确保从子文件夹到父文件夹删除
.forEach(p -> {
try {
Files.delete(p);
} catch (IOException e) {
System.err.println("无法删除文件: " + p + " " + e.getMessage());
}
});
}
@Test
public void delZipFile() {
String zipFilePath = "D:/classZipFinish/东平县高级中学.zip"; // 替换为你的ZIP文件路径
try {
deleteZipFile(zipFilePath);
System.out.println("ZIP文件已成功删除");
} catch (IOException e) {
System.err.println("删除ZIP文件时出错: " + e.getMessage());
}
}
public static void deleteZipFile(String filePath) throws IOException {
Path path = Paths.get(filePath);
Files.delete(path);
}
@Test
public void DownloadZipFile(){
//1.创建任务请求对象
FileProcessRequest request=new FileProcessRequest();
//2.添加请求参数 参数详情请见 API 接口文档
request.setBucketName("schoolreportpdf-1317275686");
request.setTag(FileProcessJobType.FileCompress);
FileCompressConfig fileCompressConfig=request.getOperation().getFileCompressConfig();
fileCompressConfig.setFormat("zip");
fileCompressConfig.setFlatten("0");
fileCompressConfig.setPrefix("class/basic/改革/山东省/东平县高级中学/");
// List<String> keyList=fileCompressConfig.getKey();
// keyList.add("mark/pic-1.jpg");
// keyList.add("mark/pic-1.pdf");
MediaOutputObject output=request.getOperation().getOutput();
output.setBucket("schoolreportpdf-1317275686");
output.setRegion("ap-beijing");
output.setObject("output/demo.zip");
//3.调用接口,获取任务响应对象
FileProcessJobResponse response= cosClient.createFileProcessJob(request);
response.getJobDetail().getJobId();
FileProcessRequest queryRequest = new FileProcessRequest();
queryRequest.setBucketName("schoolreportpdf-1317275686");
queryRequest.setJobId(response.getJobDetail().getJobId());
FileProcessJobResponse queryResponse = null;
do{
queryResponse = cosClient.describeFileProcessJob(queryRequest);
}while(!queryResponse.getJobDetail().getState().equals("SUCCESS"));
System.out.println(response.getJobDetail().getMessage());
}
}
package com.example.pdfgenerator.DataProcessing;
import com.example.pdfgenerator.DeFenLu;
import com.example.pdfgenerator.Dto.DtoArgs;
import com.example.pdfgenerator.Dto.Params;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@SpringBootTest
public class ClassIncrement {
// @Test
public void GeProvinceQuesTypeSituation(){
String sql = "select region,province from base_province_subject_tda20240919 where subject_type = '常规' group by region,province";
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
List<Params> params = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(Params.class));
for (Params param : params) {
ProcessProvinceExcellentQuesTypeSituation(param.getProvince(),param.getRegion(),jdbcTemplate);
}
}
private void ProcessProvinceExcellentQuesTypeSituation(String province, String region, JdbcTemplate jdbcTemplate) {
String sql = "select\n" +
"ques_type,\n" +
"stu_qt_score_rate,\n" +
"sub_subject,\n" +
"stu_id\n" +
"from\n" +
"base_student_ques_type_tda20240919\n" +
"where\n" +
"region = '"+region+"'\n" +
"AND province = '"+province+"'\n" +
"\t\t\tAND subject_type = '常规' \n" +
"\t\t\tAND exam_id = 'TDA20240919G2'\n";
List<DtoArgs> list = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(DtoArgs.class));
Map<String, List<DtoArgs>> collect = list.stream().collect(Collectors.groupingBy(DtoArgs::getSubSubject));
for(String subject : collect.keySet()){
String sql2 = "SELECT\n" +
"\tstu_id \n" +
"FROM\n" +
"\tbase_student_subject_tda20240919 \n" +
"WHERE\n" +
"\tstu_subject_score_rate_province_pct_rank >= ( 1-0.27 ) \n" +
"\tAND region = '"+region+"' \n" +
"\tAND province = '"+province+"' \n" +
"\tAND subject_type = '常规' \n" +
"\tAND exam_id = 'TDA20240919G2' \n" +
"\tAND sub_subject = '"+subject+"'";
List<String> excellentIds = jdbcTemplate.queryForList(sql2,String.class);
//单科
List<DtoArgs> quesTypeList = collect.get(subject);
//本省优生 各种题型的得分率数据
List<DtoArgs> excellentStuList = quesTypeList.stream().filter(x->excellentIds.contains(x.getStuId())).collect(Collectors.toList());
Map<String, List<DtoArgs>> excellentGroupByQuesType = excellentStuList.stream().collect(Collectors.groupingBy(DtoArgs::getQuesType));
for (String ques_type : excellentGroupByQuesType.keySet()) {
//进行插入数据
List<DtoArgs> finalList = excellentGroupByQuesType.get(ques_type);
Double typeRateMean = finalList.stream().mapToDouble(DtoArgs::getStuQtScoreRate).sum();
Double resultMean = typeRateMean/finalList.size();
if(Double.isNaN(resultMean)||Double.isInfinite(resultMean)){
resultMean = 0.0;
}
System.out.println(resultMean);
HashMap params = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("region",region);
put("quesType",ques_type);
}};
params.put("Mean",resultMean);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
namedParameterJdbcTemplate.update("insert into province_ques_type_excellent20240919(region,province,sub_subject,mean,ques_type) value (:region,:province,:subSubject,:Mean,:quesType)",new MapSqlParameterSource(params));
}
}
}
// @Test
public void GeProvinceExcellentDifficultySituations(){
String sql = "select region,province from base_province_subject_tda20240919 where subject_type = '常规' group by region,province";
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
List<Params> params = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(Params.class));
for (Params param : params) {
ProcessProvinceExcellentQuestTypeDifficultyLevel(param.getProvince(),param.getRegion(),jdbcTemplate);
}
}
private void ProcessProvinceExcellentQuestTypeDifficultyLevel(String province, String region, JdbcTemplate jdbcTemplate) {
String sql = "SELECT\n" +
"\ta.region,\n" +
"\ta.sub_subject,\n" +
"\ta.subject_type,\n" +
"\ta.exam_id,\n" +
"\ta.ques_no,\n" +
"\ta.region_ques_standard_difficulty,\n" +
"\tb.stu_ques_score,\n" +
"\tb.`ques_max_score`,\n" +
"\tb.`stu_id`\n" +
"\tFROM\n" +
"\tbase_area_question_tda20240919 a\n" +
"\tleft join base_student_question_tda20240919 b on a.ques_no = b.ques_no and a.sub_subject = b.`sub_subject` and a.region = b.region and a.subject_type = b.subject_type\n" +
"\twhere a.subject_type = '常规' and a.region = '"+region+"' and b.province = '"+province+"'";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
System.out.println("emoj--->"+sql);
List<DeFenLu> list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DeFenLu.class));
//化学 --》list 物理 ----》list
Map<String, List<DeFenLu>> collect = list.stream().collect(Collectors.groupingBy(DeFenLu::getSubSubject));
for (String subject : collect.keySet()) {
String sql2 = "select stu_id from base_student_subject_tda20240919 where sub_subject = '"+subject+"' and region = '"+region+"' and province = '"+province +"' and stu_subject_score_rate_province_pct_rank >= 0.73 and subject_type = '常规'";
List<String> excellentIds = namedParameterJdbcTemplate.queryForList(sql2,new HashMap<>(),String.class);
System.out.println("处理"+subject+"学科");
List<DeFenLu> deFenLus = collect.get(subject);
//本省优生的难度情况
deFenLus = deFenLus.stream().filter(x->excellentIds.contains(x.getStuId())).collect(Collectors.toList());
List<DeFenLu> yi = new ArrayList<>();
List<DeFenLu> jiaoyi = new ArrayList<>();
List<DeFenLu> zhong = new ArrayList<>();
List<DeFenLu> jiaonan = new ArrayList<>();
List<DeFenLu> nan = new ArrayList<>();
//单个科目答题记录:记录体型难度情况
for (DeFenLu fenLus : deFenLus) {
if(fenLus.getRegionQuesStandardDifficulty()>=0&&fenLus.getRegionQuesStandardDifficulty()<5){
yi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=5&&fenLus.getRegionQuesStandardDifficulty()<10){
jiaoyi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=10&&fenLus.getRegionQuesStandardDifficulty()<15){
zhong.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=15&&fenLus.getRegionQuesStandardDifficulty()<20){
jiaonan.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=20&&fenLus.getRegionQuesStandardDifficulty()<=25){
nan.add(fenLus);
}
}
//处理难易程度的得分率
double yiStuSum = yi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double yiSum = yi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaoyiStuSum = jiaoyi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaoyiyiSum = jiaoyi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double zhongStuSum = zhong.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double zhongSum = zhong.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaonanStuSum = jiaonan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaonanSum = jiaonan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double nanStuSum = nan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double nanSum = nan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
System.out.println(yiStuSum/yiSum);
double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
System.out.println(jiaoyiStuSum/jiaoyiyiSum);
double jiaoyiResult = (Double.isNaN(jiaoyiStuSum/jiaoyiyiSum)||Double.isInfinite(jiaoyiStuSum/jiaoyiyiSum))?0.0:(jiaoyiStuSum/jiaoyiyiSum);
System.out.println(zhongStuSum/zhongSum);
double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
System.out.println(jiaonanStuSum/jiaonanSum);
double jiaonanResult = (Double.isNaN(jiaonanStuSum/jiaonanSum)||Double.isInfinite(jiaonanStuSum/jiaonanSum))?0.0:(jiaonanStuSum/jiaonanSum);
System.out.println(nanStuSum/nanSum);
double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
HashMap paramsYi = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","易");
put("region",region);
put("scoreMean", yiResult);
}};
HashMap paramsJiaoYi = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","较易");
put("region",region);
put("scoreMean", jiaoyiResult);
}};
HashMap paramsZhong = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","中");
put("region",region);
put("scoreMean", zhongResult);
}};
HashMap paramsJiaoNan = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","较难");
put("region",region);
put("scoreMean", jiaonanResult);
}};
HashMap paramsNan= new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","难");
put("region",region);
put("scoreMean", nanResult);
}};
namedParameterJdbcTemplate.update("insert into province_excellent_difficult20240919(sub_subject,difficult,region,province,score_mean) value(:subSubject,:difficult,:region,:province,:scoreMean)",new MapSqlParameterSource(paramsYi));
namedParameterJdbcTemplate.update("insert into province_excellent_difficult20240919(sub_subject,difficult,region,province,score_mean) value(:subSubject,:difficult,:region,:province,:scoreMean)",new MapSqlParameterSource(paramsJiaoYi));
namedParameterJdbcTemplate.update("insert into province_excellent_difficult20240919(sub_subject,difficult,region,province,score_mean) value(:subSubject,:difficult,:region,:province,:scoreMean)",new MapSqlParameterSource(paramsZhong));
namedParameterJdbcTemplate.update("insert into province_excellent_difficult20240919(sub_subject,difficult,region,province,score_mean) value(:subSubject,:difficult,:region,:province,:scoreMean)",new MapSqlParameterSource(paramsJiaoNan));
namedParameterJdbcTemplate.update("insert into province_excellent_difficult20240919(sub_subject,difficult,region,province,score_mean) value(:subSubject,:difficult,:region,:province,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
}
}
package com.example.pdfgenerator.DataProcessing;
import com.example.pdfgenerator.DtoKn;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@SpringBootTest
public class Garbge {
// @Test
public void meanRegion(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "select region from base_school_subject_tda20240919 where subject_type = '常规' group by region";
List<String> regions = jdbcTemplate.queryForList(sql, String.class);
for (String region : regions) {
meanRegionTest(region,namedParameterJdbcTemplate);
}
}
public void meanRegionTest(String region, NamedParameterJdbcTemplate reportJdbcTemplate){
String sql = "select \n" +
"knowledge,\n" +
"stu_kn_score_rate,\n" +
"sub_subject,\n" +
"stu_id\n" +
"from\n" +
"base_student_knowledge_tda20240919\n" +
"where\n" +
"region = '"+region+"' and subject_type = '常规'";
List<DtoKn> list = reportJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DtoKn.class));
Map<String, List<DtoKn>> collect = list.stream().collect(Collectors.groupingBy(DtoKn::getSubSubject));
for (String subject : collect.keySet()) {
List<DtoKn> subjectLis =collect.get(subject);
String sql2 = "select \n" +
"stu_id\n" +
"from \n" +
"base_student_subject_tda20240919\n" +
"where\n" +
"sub_subject = '"+subject+"'\n" +
"and\n" +
"subject_type = '常规'\n" +
"and\n" +
"region = '"+region+"'\n" +
"and \n" +
"stu_subject_score_rate_region_pct_rank >= 0.73";
List<String> ids = reportJdbcTemplate.queryForList(sql2,new HashMap<>(),String.class);
List<DtoKn> collect1 = subjectLis.stream().filter(x -> ids.contains(x.getStuId())).collect(Collectors.toList());
Map<String, List<DtoKn>> collect2 = collect1.stream().collect(Collectors.groupingBy(DtoKn::getKnowledge));
for (String knowledge : collect2.keySet()) {
//优生知识点层级
List<DtoKn> dataList = collect2.get(knowledge);
Double sumRate = dataList.stream().mapToDouble(DtoKn::getStuKnScoreRate).sum();
Double resultRate = sumRate/dataList.size();
if(Double.isNaN(resultRate)||Double.isInfinite(resultRate)){
resultRate = 0.0;
}
HashMap paramsYi = new HashMap(){{
put("subSubject",subject);
put("knowledge",knowledge);
put("region",region);
}};
paramsYi.put("rate",resultRate);
reportJdbcTemplate.update("insert into knowledge_region_excellent20240919(sub_subject,knowledge,region,rate) value (:subSubject,:knowledge,:region,:rate)",new MapSqlParameterSource(paramsYi));
}
}
}
}
package com.example.pdfgenerator.DataProcessing;
import com.example.pdfgenerator.Dto.Params;
import com.example.pdfgenerator.DtoKn;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@SpringBootTest
public class NumberTwo {
// @Test
public void ProvinceExKnow(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "select region,province from base_school_subject_tda20240919 where subject_type = '常规' group by region,province";
List<Params> paramsList = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Params.class));
for (Params param : paramsList) {
provinceExe(param.getRegion(),param.getProvince(),namedParameterJdbcTemplate);
}
}
public void provinceExe(String region,String province,NamedParameterJdbcTemplate reportTemplate){
String sql = "select \n" +
"knowledge,\n" +
"stu_kn_score_rate,\n" +
"sub_subject,\n" +
"stu_id\n" +
"from\n" +
"base_student_knowledge_tda20240919\n" +
"where\n" +
"region = '"+region+"' and subject_type = '常规' and province = '"+province+"'";
List<DtoKn> list = reportTemplate.query(sql,new HashMap<>(),new BeanPropertyRowMapper<>(DtoKn.class));
Map<String, List<DtoKn>> collect = list.stream().collect(Collectors.groupingBy(DtoKn::getSubSubject));
for (String subject : collect.keySet()) {
//单个科目
List<DtoKn> data = collect.get(subject);
String sql3 = "\t\t\t\tSELECT\n" +
"\t\t\tstu_id \n" +
"\t\tFROM\n" +
"\t\t\tbase_student_subject_tda20240919 \n" +
"\t\tWHERE\n" +
"\t\t\tprovince = '"+province+"' \n" +
"\t\t\tAND region = '"+region+"' \n" +
"\t\t\tAND subject_type = '常规' \n" +
"\t\t\tAND exam_id = 'TDA20240919G2' \n" +
"\t\t\tAND sub_subject = '"+subject+"' \n" +
"\t\t\tAND stu_subject_score_rate_province_pct_rank >= (1-0.27) ";
List<String> ids = reportTemplate.queryForList(sql3,new HashMap<>(),String.class);
List<DtoKn> collect1 = data.stream().filter(x -> ids.contains(x.getStuId())).collect(Collectors.toList());
Map<String, List<DtoKn>> collect2 = collect1.stream().collect(Collectors.groupingBy(DtoKn::getKnowledge));
for (String knowledge : collect2.keySet()) {
List<DtoKn> goods = collect2.get(knowledge);
Double sumRate = goods.stream().mapToDouble(DtoKn::getStuKnScoreRate).sum();
Double result = sumRate/goods.size();
if(Double.isNaN(result)||Double.isInfinite(result)){
result = 0.0;
}
HashMap paramsYi = new HashMap(){{
put("subSubject",subject);
put("knowledge",knowledge);
put("region",region);
put("province",province);
}};
paramsYi.put("rate",result);
reportTemplate.update("insert into knowledge_province_excellent20240919(sub_subject,knowledge,region,rate,province) value (:subSubject,:knowledge,:region,:rate,:province)",new MapSqlParameterSource(paramsYi));
}
}
}
}
package com.example.pdfgenerator.DataProcessing;
import com.example.pdfgenerator.DeFenLu;
import com.example.pdfgenerator.Dto.*;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import java.util.*;
import java.util.stream.Collectors;
@SpringBootTest
class PdfGeneratorApplicationTests {
@Test
void contextLoads() {
}
// @Test
public void TestInsertSchoolClass(){
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
String sql = "SELECT\n" +
"\tregion,\n" +
"\tschool,\n" +
"\tclass as className\n" +
"FROM\n" +
"\tbase_class_subject_tda20240919 \n" +
"WHERE\n" +
"\tsubject_type = '常规' \n" +
"GROUP BY\n" +
"\tschool,\n" +
"\tregion,\n" +
"\tclass\n" +
"order by region,school,class";
List<ClassDtoArgs> paramsList = reportJdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(ClassDtoArgs.class));
for(ClassDtoArgs param : paramsList){
System.out.println("运行"+param.getSchool()+param.getClassName()+"难度解析");
TestInsertClassName(param.getSchool(), param.getRegion(), param.getClassName(), reportJdbcTemplate);
}
}
public void TestInsertClassName(String school,String region,String className,JdbcTemplate jdbcTemplate){
//学校的
String sql = "SELECT\n" +
"\ta.region,\n" +
"\ta.sub_subject,\n" +
"\ta.subject_type,\n" +
"\ta.exam_id,\n" +
"\ta.ques_no,\n" +
"\ta.region_ques_standard_difficulty,\n" +
"\tb.stu_ques_score,\n" +
"\tb.`ques_max_score`,b.stu_ques_score\n" +
"\tFROM\n" +
"\tbase_area_question_tda20240919 a\n" +
"\tleft join base_student_question_tda20240919 b on a.ques_no = b.ques_no and a.sub_subject = b.`sub_subject`\n" +"and a.region = b.region "+
"\twhere b.school = '"+school+"' and b.subject_type = '常规' and a.region = '"+region+"'"+"and class = '"+className+"'";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DeFenLu> list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DeFenLu.class));
//化学 --》list 物理 ----》list
Map<String, List<DeFenLu>> collect = list.stream().collect(Collectors.groupingBy(DeFenLu::getSubSubject));
//学科粒度
for (String subject : collect.keySet()) {
System.out.println("处理"+subject+"学科");
List<DeFenLu> deFenLus = collect.get(subject);
List<DeFenLu> yi = new ArrayList<>();
List<DeFenLu> jiaoyi = new ArrayList<>();
List<DeFenLu> zhong = new ArrayList<>();
List<DeFenLu> jiaonan = new ArrayList<>();
List<DeFenLu> nan = new ArrayList<>();
//单个科目答题记录:记录体型难度情况
for (DeFenLu fenLus : deFenLus) {
if(fenLus.getRegionQuesStandardDifficulty()>=0&&fenLus.getRegionQuesStandardDifficulty()<5){
yi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=5&&fenLus.getRegionQuesStandardDifficulty()<10){
jiaoyi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=10&&fenLus.getRegionQuesStandardDifficulty()<15){
zhong.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=15&&fenLus.getRegionQuesStandardDifficulty()<20){
jiaonan.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=20&&fenLus.getRegionQuesStandardDifficulty()<=25){
nan.add(fenLus);
}
}
//处理难易程度的得分率
double yiStuSum = yi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double yiSum = yi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaoyiStuSum = jiaoyi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaoyiyiSum = jiaoyi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double zhongStuSum = zhong.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double zhongSum = zhong.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaonanStuSum = jiaonan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaonanSum = jiaonan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double nanStuSum = nan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double nanSum = nan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
// System.out.println(yiStuSum/yiSum);
double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
// System.out.println(jiaoyiStuSum/jiaoyiyiSum);
double jiaoyiResult = (Double.isNaN(jiaoyiStuSum/jiaoyiyiSum)||Double.isInfinite(jiaoyiStuSum/jiaoyiyiSum))?0.0:(jiaoyiStuSum/jiaoyiyiSum);
// System.out.println(zhongStuSum/zhongSum);
double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
// System.out.println(jiaonanStuSum/jiaonanSum);
double jiaonanResult = (Double.isNaN(jiaonanStuSum/jiaonanSum)||Double.isInfinite(jiaonanStuSum/jiaonanSum))?0.0:(jiaonanStuSum/jiaonanSum);
// System.out.println(nanStuSum/nanSum);
double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
HashMap paramsYi = new HashMap(){{
put("class",className);
put("school",school);
put("subSubject",subject);
put("difficult","易");
put("region",region);
put("scoreMean", yiResult);
}};
HashMap paramsJiaoYi = new HashMap(){{
put("class",className);
put("school",school);
put("subSubject",subject);
put("difficult","较易");
put("region",region);
put("scoreMean", jiaoyiResult);
}};
HashMap paramsZhong = new HashMap(){{
put("class",className);
put("school",school);
put("subSubject",subject);
put("difficult","中");
put("region",region);
put("scoreMean", zhongResult);
}};
HashMap paramsJiaoNan = new HashMap(){{
put("class",className);
put("school",school);
put("subSubject",subject);
put("difficult","较难");
put("region",region);
put("scoreMean", jiaonanResult);
}};
HashMap paramsNan= new HashMap(){{
put("class",className);
put("school",school);
put("subSubject",subject);
put("difficult","难");
put("region",region);
put("scoreMean", nanResult);
}};
namedParameterJdbcTemplate.update("insert into class_diffficult20240919(class,school,sub_subject,difficult,region,score_mean) value(:class,:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsYi));
namedParameterJdbcTemplate.update("insert into class_diffficult20240919(class,school,sub_subject,difficult,region,score_mean) value(:class,:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoYi));
namedParameterJdbcTemplate.update("insert into class_diffficult20240919(class,school,sub_subject,difficult,region,score_mean) value(:class,:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsZhong));
namedParameterJdbcTemplate.update("insert into class_diffficult20240919(class,school,sub_subject,difficult,region,score_mean) value(:class,:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoNan));
namedParameterJdbcTemplate.update("insert into class_diffficult20240919(class,school,sub_subject,difficult,region,score_mean) value(:class,:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
}
// @Test
public void TestInsertSchool(){
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
String sql = "select school,region from base_school_subject_tda20240919 where subject_type = '常规' group by school,region";
List<Dto> listParams = reportJdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(Dto.class));
for (Dto listParam : listParams) {
System.out.println("运行"+listParam.getSchool()+listParam.getRegion());
test(listParam.getSchool(), listParam.getRegion(),reportJdbcTemplate);
}
}
public void test(String school,String region,JdbcTemplate jdbcTemplate) {
//学校的
String sql = "SELECT\n" +
"\ta.region,\n" +
"\ta.sub_subject,\n" +
"\ta.subject_type,\n" +
"\ta.exam_id,\n" +
"\ta.ques_no,\n" +
"\ta.region_ques_standard_difficulty,\n" +
"\tb.stu_ques_score,\n" +
"\tb.`ques_max_score`\n" +
"\tFROM\n" +
"\tbase_area_question_tda20240919 a\n" +
"\tleft join base_student_question_tda20240919 b on a.ques_no = b.ques_no and a.sub_subject = b.`sub_subject`\n" +"and a.region = b.region "+
"\twhere b.school = '"+school+"' and b.subject_type = '常规' and a.region = '"+region+"'";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DeFenLu> list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DeFenLu.class));
//化学 --》list 物理 ----》list
Map<String, List<DeFenLu>> collect = list.stream().collect(Collectors.groupingBy(DeFenLu::getSubSubject));
//学科粒度
for (String subject : collect.keySet()) {
System.out.println("处理"+subject+"学科");
List<DeFenLu> deFenLus = collect.get(subject);
List<DeFenLu> yi = new ArrayList<>();
List<DeFenLu> jiaoyi = new ArrayList<>();
List<DeFenLu> zhong = new ArrayList<>();
List<DeFenLu> jiaonan = new ArrayList<>();
List<DeFenLu> nan = new ArrayList<>();
//单个科目答题记录:记录体型难度情况
for (DeFenLu fenLus : deFenLus) {
if(fenLus.getRegionQuesStandardDifficulty()>=0&&fenLus.getRegionQuesStandardDifficulty()<5){
yi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=5&&fenLus.getRegionQuesStandardDifficulty()<10){
jiaoyi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=10&&fenLus.getRegionQuesStandardDifficulty()<15){
zhong.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=15&&fenLus.getRegionQuesStandardDifficulty()<20){
jiaonan.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=20&&fenLus.getRegionQuesStandardDifficulty()<=25){
nan.add(fenLus);
}
}
//处理难易程度的得分率
double yiStuSum = yi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double yiSum = yi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaoyiStuSum = jiaoyi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaoyiyiSum = jiaoyi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double zhongStuSum = zhong.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double zhongSum = zhong.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaonanStuSum = jiaonan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaonanSum = jiaonan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double nanStuSum = nan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double nanSum = nan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
// System.out.println(yiStuSum/yiSum);
double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
// System.out.println(jiaoyiStuSum/jiaoyiyiSum);
double jiaoyiResult = (Double.isNaN(jiaoyiStuSum/jiaoyiyiSum)||Double.isInfinite(jiaoyiStuSum/jiaoyiyiSum))?0.0:(jiaoyiStuSum/jiaoyiyiSum);
// System.out.println(zhongStuSum/zhongSum);
double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
// System.out.println(jiaonanStuSum/jiaonanSum);
double jiaonanResult = (Double.isNaN(jiaonanStuSum/jiaonanSum)||Double.isInfinite(jiaonanStuSum/jiaonanSum))?0.0:(jiaonanStuSum/jiaonanSum);
// System.out.println(nanStuSum/nanSum);
double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
HashMap paramsYi = new HashMap(){{
put("school",school);
put("subSubject",subject);
put("difficult","易");
put("region",region);
put("scoreMean", yiResult);
}};
HashMap paramsJiaoYi = new HashMap(){{
put("school",school);
put("subSubject",subject);
put("difficult","较易");
put("region",region);
put("scoreMean", jiaoyiResult);
}};
HashMap paramsZhong = new HashMap(){{
put("school",school);
put("subSubject",subject);
put("difficult","中");
put("region",region);
put("scoreMean", zhongResult);
}};
HashMap paramsJiaoNan = new HashMap(){{
put("school",school);
put("subSubject",subject);
put("difficult","较难");
put("region",region);
put("scoreMean", jiaonanResult);
}};
HashMap paramsNan= new HashMap(){{
put("school",school);
put("subSubject",subject);
put("difficult","难");
put("region",region);
put("scoreMean", nanResult);
}};
namedParameterJdbcTemplate.update("insert into school_diffficult20240919(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsYi));
namedParameterJdbcTemplate.update("insert into school_diffficult20240919(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoYi));
namedParameterJdbcTemplate.update("insert into school_diffficult20240919(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsZhong));
namedParameterJdbcTemplate.update("insert into school_diffficult20240919(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoNan));
namedParameterJdbcTemplate.update("insert into school_diffficult20240919(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
// DeFenLu deFenLu = yi.get(0);
}
// @Test
public void TestInsertRegion(){
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
String sql = "select region from base_school_subject_tda20240919 where subject_type = '常规' group by region";
List<String> listParams = reportJdbcTemplate.queryForList(sql,String.class);
for (String region : listParams) {
System.out.println("运行"+region);
TestRegion(region,reportJdbcTemplate);
}
}
public void TestRegion(String region,JdbcTemplate jdbcTemplate){
String sql = "SELECT\n" +
"\ta.region,\n" +
"\ta.sub_subject,\n" +
"\ta.subject_type,\n" +
"\ta.exam_id,\n" +
"\ta.ques_no,\n" +
"\ta.region_ques_standard_difficulty,\n" +
"\tb.stu_ques_score,\n" +
"\tb.`ques_max_score`\n" +
"\tFROM\n" +
"\tbase_area_question_tda20240919 a\n" +
"\tleft join base_student_question_tda20240919 b on a.ques_no = b.ques_no and a.sub_subject = b.`sub_subject` and a.region = b.region and a.subject_type = b.subject_type\n" +
"\twhere a.subject_type = '常规' and a.region = '"+region+"'\n";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DeFenLu> list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DeFenLu.class));
//化学 --》list 物理 ----》list
Map<String, List<DeFenLu>> collect = list.stream().collect(Collectors.groupingBy(DeFenLu::getSubSubject));
//学科粒度
for (String subject : collect.keySet()) {
System.out.println("处理"+subject+"学科");
List<DeFenLu> deFenLus = collect.get(subject);
List<DeFenLu> yi = new ArrayList<>();
List<DeFenLu> jiaoyi = new ArrayList<>();
List<DeFenLu> zhong = new ArrayList<>();
List<DeFenLu> jiaonan = new ArrayList<>();
List<DeFenLu> nan = new ArrayList<>();
//单个科目答题记录:记录体型难度情况
for (DeFenLu fenLus : deFenLus) {
if(fenLus.getRegionQuesStandardDifficulty()>=0&&fenLus.getRegionQuesStandardDifficulty()<5){
yi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=5&&fenLus.getRegionQuesStandardDifficulty()<10){
jiaoyi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=10&&fenLus.getRegionQuesStandardDifficulty()<15){
zhong.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=15&&fenLus.getRegionQuesStandardDifficulty()<20){
jiaonan.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=20&&fenLus.getRegionQuesStandardDifficulty()<=25){
nan.add(fenLus);
}
}
//处理难易程度的得分率
double yiStuSum = yi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double yiSum = yi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaoyiStuSum = jiaoyi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaoyiyiSum = jiaoyi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double zhongStuSum = zhong.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double zhongSum = zhong.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaonanStuSum = jiaonan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaonanSum = jiaonan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double nanStuSum = nan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double nanSum = nan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
System.out.println(yiStuSum/yiSum);
double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
System.out.println(jiaoyiStuSum/jiaoyiyiSum);
double jiaoyiResult = (Double.isNaN(jiaoyiStuSum/jiaoyiyiSum)||Double.isInfinite(jiaoyiStuSum/jiaoyiyiSum))?0.0:(jiaoyiStuSum/jiaoyiyiSum);
System.out.println(zhongStuSum/zhongSum);
double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
System.out.println(jiaonanStuSum/jiaonanSum);
double jiaonanResult = (Double.isNaN(jiaonanStuSum/jiaonanSum)||Double.isInfinite(jiaonanStuSum/jiaonanSum))?0.0:(jiaonanStuSum/jiaonanSum);
System.out.println(nanStuSum/nanSum);
double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
HashMap paramsYi = new HashMap(){{
put("subSubject",subject);
put("difficult","易");
put("region",region);
put("scoreMean", yiResult);
}};
HashMap paramsJiaoYi = new HashMap(){{
put("subSubject",subject);
put("difficult","较易");
put("region",region);
put("scoreMean", jiaoyiResult);
}};
HashMap paramsZhong = new HashMap(){{
put("subSubject",subject);
put("difficult","中");
put("region",region);
put("scoreMean", zhongResult);
}};
HashMap paramsJiaoNan = new HashMap(){{
put("subSubject",subject);
put("difficult","较难");
put("region",region);
put("scoreMean", jiaonanResult);
}};
HashMap paramsNan= new HashMap(){{
put("subSubject",subject);
put("difficult","难");
put("region",region);
put("scoreMean", nanResult);
}};
namedParameterJdbcTemplate.update("insert into region_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsYi));
namedParameterJdbcTemplate.update("insert into region_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoYi));
namedParameterJdbcTemplate.update("insert into region_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsZhong));
namedParameterJdbcTemplate.update("insert into region_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoNan));
namedParameterJdbcTemplate.update("insert into region_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
}
// @Test
public void TestProvinceInsert(){
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
String sql = "select region,province from base_school_subject_tda20240919 where subject_type = '常规' group by region,province";
List<Params> paramsList = reportJdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(Params.class));
for (Params param : paramsList) {
System.out.println("运行"+param.getProvince()+param.getRegion());
TestProvince(param.getProvince(),param.getRegion(),reportJdbcTemplate);
}
// TestProvince("江西省","改革",reportJdbcTemplate);
}
public void TestProvince(String province,String region,JdbcTemplate jdbcTemplate){
String sql = "SELECT\n" +
"\ta.region,\n" +
"\ta.sub_subject,\n" +
"\ta.subject_type,\n" +
"\ta.exam_id,\n" +
"\ta.ques_no,\n" +
"\ta.region_ques_standard_difficulty,\n" +
"\tb.stu_ques_score,\n" +
"\tb.`ques_max_score`\n" +
"\tFROM\n" +
"\tbase_area_question_tda20240919 a\n" +
"\tleft join base_student_question_tda20240919 b on a.ques_no = b.ques_no and a.sub_subject = b.`sub_subject` and a.region = b.region and a.subject_type = b.subject_type\n" +
"\twhere a.subject_type = '常规' and a.region = '"+region+"' and b.province = '"+province+"'";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DeFenLu> list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DeFenLu.class));
//化学 --》list 物理 ----》list
Map<String, List<DeFenLu>> collect = list.stream().collect(Collectors.groupingBy(DeFenLu::getSubSubject));
//学科粒度
for (String subject : collect.keySet()) {
System.out.println("处理"+subject+"学科");
List<DeFenLu> deFenLus = collect.get(subject);
List<DeFenLu> yi = new ArrayList<>();
List<DeFenLu> jiaoyi = new ArrayList<>();
List<DeFenLu> zhong = new ArrayList<>();
List<DeFenLu> jiaonan = new ArrayList<>();
List<DeFenLu> nan = new ArrayList<>();
//单个科目答题记录:记录体型难度情况
for (DeFenLu fenLus : deFenLus) {
if(fenLus.getRegionQuesStandardDifficulty()>=0&&fenLus.getRegionQuesStandardDifficulty()<5){
yi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=5&&fenLus.getRegionQuesStandardDifficulty()<10){
jiaoyi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=10&&fenLus.getRegionQuesStandardDifficulty()<15){
zhong.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=15&&fenLus.getRegionQuesStandardDifficulty()<20){
jiaonan.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=20&&fenLus.getRegionQuesStandardDifficulty()<=25){
nan.add(fenLus);
}
}
//处理难易程度的得分率
double yiStuSum = yi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double yiSum = yi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaoyiStuSum = jiaoyi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaoyiyiSum = jiaoyi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double zhongStuSum = zhong.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double zhongSum = zhong.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaonanStuSum = jiaonan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaonanSum = jiaonan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double nanStuSum = nan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double nanSum = nan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
System.out.println(yiStuSum/yiSum);
double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
System.out.println(jiaoyiStuSum/jiaoyiyiSum);
double jiaoyiResult = (Double.isNaN(jiaoyiStuSum/jiaoyiyiSum)||Double.isInfinite(jiaoyiStuSum/jiaoyiyiSum))?0.0:(jiaoyiStuSum/jiaoyiyiSum);
System.out.println(zhongStuSum/zhongSum);
double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
System.out.println(jiaonanStuSum/jiaonanSum);
double jiaonanResult = (Double.isNaN(jiaonanStuSum/jiaonanSum)||Double.isInfinite(jiaonanStuSum/jiaonanSum))?0.0:(jiaonanStuSum/jiaonanSum);
System.out.println(nanStuSum/nanSum);
double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
HashMap paramsYi = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","易");
put("region",region);
put("scoreMean", yiResult);
}};
HashMap paramsJiaoYi = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","较易");
put("region",region);
put("scoreMean", jiaoyiResult);
}};
HashMap paramsZhong = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","中");
put("region",region);
put("scoreMean", zhongResult);
}};
HashMap paramsJiaoNan = new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","较难");
put("region",region);
put("scoreMean", jiaonanResult);
}};
HashMap paramsNan= new HashMap(){{
put("province",province);
put("subSubject",subject);
put("difficult","难");
put("region",region);
put("scoreMean", nanResult);
}};
namedParameterJdbcTemplate.update("insert into province_difficult20240919(province,sub_subject,difficult,region,score_mean) value(:province,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsYi));
namedParameterJdbcTemplate.update("insert into province_difficult20240919(province,sub_subject,difficult,region,score_mean) value(:province,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoYi));
namedParameterJdbcTemplate.update("insert into province_difficult20240919(province,sub_subject,difficult,region,score_mean) value(:province,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsZhong));
namedParameterJdbcTemplate.update("insert into province_difficult20240919(province,sub_subject,difficult,region,score_mean) value(:province,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoNan));
namedParameterJdbcTemplate.update("insert into province_difficult20240919(province,sub_subject,difficult,region,score_mean) value(:province,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
}
// @Test
public void excellentRegion(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
String sql = "select region from base_school_subject_tda20240919 where subject_type ='常规' group by region";
List<String> regions = jdbcTemplate.queryForList(sql,new Object[]{},String.class);
for (String region : regions) {
testExcellent(region,jdbcTemplate);
}
}
public void testExcellent(String region,JdbcTemplate jdbcTemplate){
String sql = "SELECT\n" +
" a.region,\n" +
" a.sub_subject,\n" +
" a.subject_type,\n" +
" a.exam_id,\n" +
" a.ques_no,\n" +
" a.region_ques_standard_difficulty,\n" +
" b.stu_ques_score,\n" +
" b.`ques_max_score`,\n" +
" b.`stu_id`\n" +
" FROM\n" +
" base_area_question_tda20240919 a\n" +
" left join base_student_question_tda20240919 b on a.ques_no = b.ques_no and a.sub_subject = b.`sub_subject` and a.region = b.region and a.subject_type = b.subject_type\n" +
" where a.subject_type = '常规' and a.region = '"+region+"'";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DeFenLu> list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DeFenLu.class));
//化学 --》list 物理 ----》list
Map<String, List<DeFenLu>> collect = list.stream().collect(Collectors.groupingBy(DeFenLu::getSubSubject));
//学科粒度
for (String subject : collect.keySet()) {
//这个级别开始晒数据
String sql2 = "select stu_id from base_student_subject_tda20240919 where sub_subject = '"+subject+"' and region = '"+region+"' and stu_subject_score_rate_region_pct_rank >= 0.73 and subject_type = '常规'";
List<String> excellent = namedParameterJdbcTemplate.queryForList(sql2,new HashMap<>(),String.class);
System.out.println("处理"+subject+"学科");
List<DeFenLu> deFenLus = collect.get(subject);
deFenLus = deFenLus.stream().filter(x->excellent.contains(x.getStuId())).collect(Collectors.toList());
List<DeFenLu> yi = new ArrayList<>();
List<DeFenLu> jiaoyi = new ArrayList<>();
List<DeFenLu> zhong = new ArrayList<>();
List<DeFenLu> jiaonan = new ArrayList<>();
List<DeFenLu> nan = new ArrayList<>();
//单个科目答题记录:记录体型难度情况
for (DeFenLu fenLus : deFenLus) {
if(fenLus.getRegionQuesStandardDifficulty()>=0&&fenLus.getRegionQuesStandardDifficulty()<5){
yi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=5&&fenLus.getRegionQuesStandardDifficulty()<10){
jiaoyi.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=10&&fenLus.getRegionQuesStandardDifficulty()<15){
zhong.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=15&&fenLus.getRegionQuesStandardDifficulty()<20){
jiaonan.add(fenLus);
}else if(fenLus.getRegionQuesStandardDifficulty()>=20&&fenLus.getRegionQuesStandardDifficulty()<=25){
nan.add(fenLus);
}
}
//处理难易程度的得分率
double yiStuSum = yi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double yiSum = yi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaoyiStuSum = jiaoyi.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaoyiyiSum = jiaoyi.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double zhongStuSum = zhong.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double zhongSum = zhong.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double jiaonanStuSum = jiaonan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double jiaonanSum = jiaonan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
double nanStuSum = nan.stream().mapToDouble(DeFenLu::getStuQuesScore).sum();
double nanSum = nan.stream().mapToDouble(DeFenLu::getQuesMaxScore).sum();
System.out.println(yiStuSum/yiSum);
double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
System.out.println(jiaoyiStuSum/jiaoyiyiSum);
double jiaoyiResult = (Double.isNaN(jiaoyiStuSum/jiaoyiyiSum)||Double.isInfinite(jiaoyiStuSum/jiaoyiyiSum))?0.0:(jiaoyiStuSum/jiaoyiyiSum);
System.out.println(zhongStuSum/zhongSum);
double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
System.out.println(jiaonanStuSum/jiaonanSum);
double jiaonanResult = (Double.isNaN(jiaonanStuSum/jiaonanSum)||Double.isInfinite(jiaonanStuSum/jiaonanSum))?0.0:(jiaonanStuSum/jiaonanSum);
System.out.println(nanStuSum/nanSum);
double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
HashMap paramsYi = new HashMap(){{
put("subSubject",subject);
put("difficult","易");
put("region",region);
put("scoreMean", yiResult);
}};
HashMap paramsJiaoYi = new HashMap(){{
put("subSubject",subject);
put("difficult","较易");
put("region",region);
put("scoreMean", jiaoyiResult);
}};
HashMap paramsZhong = new HashMap(){{
put("subSubject",subject);
put("difficult","中");
put("region",region);
put("scoreMean", zhongResult);
}};
HashMap paramsJiaoNan = new HashMap(){{
put("subSubject",subject);
put("difficult","较难");
put("region",region);
put("scoreMean", jiaonanResult);
}};
HashMap paramsNan= new HashMap(){{
put("subSubject",subject);
put("difficult","难");
put("region",region);
put("scoreMean", nanResult);
}};
namedParameterJdbcTemplate.update("insert into region_excellent_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsYi));
namedParameterJdbcTemplate.update("insert into region_excellent_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoYi));
namedParameterJdbcTemplate.update("insert into region_excellent_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsZhong));
namedParameterJdbcTemplate.update("insert into region_excellent_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsJiaoNan));
namedParameterJdbcTemplate.update("insert into region_excellent_difficult20240919(sub_subject,difficult,region,score_mean) value(:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
}
// @Test
public void ExcellentAswTimeProvince(){
String sql = "select region,province from base_province_subject_tda20240919 where subject_type = '常规' group by region,province";
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
List<Params> params = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(Params.class));
for (Params param : params) {
ExcellentAswTime(param.getProvince(),param.getRegion(),jdbcTemplate);
}
}
public void ExcellentAswTime(String province,String region,JdbcTemplate jdbcTemplate){
String sql = "select\n" +
"ques_no,\n" +
"stu_id ,\n" +
"stu_ques_asw_time,\n" +
"sub_subject\n" +
"from \n" +
"base_student_question_log_time_tda20240919\n" +
"where\n" +
// "region = '"+region+"'\n" +
// "and \n" +
"province = '"+province+"'\n" +
"and \n" +
"subject_type='常规'\n" +
"and \n" +
"exam_id = 'TDA20240919G2'\n" ;
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DtoAsw> listDtoAsw = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(DtoAsw.class));
Map<String,List<DtoAsw>> collect = listDtoAsw.stream().collect(Collectors.groupingBy(DtoAsw::getSubSubject));
//科目粒度
for (String subject : collect.keySet()) {
System.out.println("operator"+subject+"科目");
String sql2 = "select stu_id from base_student_subject_tda20240919 where " +
// "region = '"+region+"'\n" +
// "and \n" +
"sub_subject = '"+subject+"'\n" +
"and \n" +
"province = '"+province+"' \n" +
"and \n" +
"subject_type= '常规'\n" +
"and \n" +
"exam_id = 'TDA20240919G2'\n" +
"and \n" +
"stu_subject_score_rate_province_pct_rank >= (1-0.27)";
List<String> excellent = jdbcTemplate.queryForList(sql2,String.class);
List<DtoAsw> list = collect.get(subject);
List<DtoAsw> exCollect = list.stream().filter(x->excellent.contains(x.getStuId())).collect(Collectors.toList());
Map<String, List<DtoAsw>> collect1 = exCollect.stream().collect(Collectors.groupingBy(DtoAsw::getQuesNo));
for (String ques_no : collect1.keySet()) {
System.out.println("计算题目编号:"+ques_no);
List<DtoAsw> aswList = collect1.get(ques_no);
Double sumTime = aswList.stream().mapToDouble(DtoAsw::getStuQuesAswTime).sum();
Double avgTime = sumTime/aswList.size();
System.out.println(avgTime);
HashMap params = new HashMap(){{
put("subSubject",subject);
put("province",province);
put("region","改革");
put("quesNo",ques_no);
put("time",avgTime);
}};
namedParameterJdbcTemplate.update("insert into province_excellent_asw_time20240919(sub_subject,province,region,ques_no,time) value (:subSubject,:province,:region,:quesNo,:time)",new MapSqlParameterSource(params));
}
}
}
// @Test
public void ExcellentRegionAswTime(){
String sql = "select region from base_province_subject_tda20240919 where subject_type = '常规' group by region\n";
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
List<String> regions = reportJdbcTemplate.queryForList(sql,String.class);
// for (String region : regions) {
// ExcellentRegionAsw(region,reportJdbcTemplate);
// }
ExcellentRegionAsw("",reportJdbcTemplate);
}
public void ExcellentRegionAsw(String region,JdbcTemplate jdbcTemplate){
String sql = "select\n" +
"ques_no,\n" +
"sub_subject,\n" +
"stu_id,\n" +
"stu_ques_asw_time\n" +
"from \n" +
"base_student_question_log_time_tda20240919\n" +
"where\n" +
// "region = '"+region+"'\n" +
// "and \n" +
"subject_type= '常规'\n" +
"and \n" +
"exam_id = 'TDA20240919G2'\n";
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<DtoAsw> list = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(DtoAsw.class));
Map<String, List<DtoAsw>> collect = list.stream().collect(Collectors.groupingBy(DtoAsw::getSubSubject));
for (String subject : collect.keySet()) {
String sql2 = "select stu_id from base_student_subject_tda20240919 where " +
// "region = '"+region+"'\n" +
// "and \n" +
"sub_subject = '"+subject+"'\n" +
"and \n" +
"subject_type= '常规'\n" +
"and \n" +
"exam_id = 'TDA20240919G2'\n" +
"and \n" +
"stu_subject_score_rate_region_pct_rank >= (1-0.27)";
List<String> yousheng = jdbcTemplate.queryForList(sql2,String.class);
List<DtoAsw> col = collect.get(subject);
List<DtoAsw> youshengList = col.stream().filter(x->yousheng.contains(x.getStuId())).collect(Collectors.toList());
Map<String, List<DtoAsw>> collect1 = youshengList.stream().collect(Collectors.groupingBy(DtoAsw::getQuesNo));
for (String ques_no : collect1.keySet()) {
System.out.println("计算编号为:"+ques_no);
Double sumTime = collect1.get(ques_no).stream().mapToDouble(DtoAsw::getStuQuesAswTime).sum();
Double avgTime = sumTime/collect1.get(ques_no).size();
HashMap params = new HashMap(){{
put("subSubject",subject);
put("region","改革");
put("quesNo",ques_no);
put("time",avgTime);
}};
namedParameterJdbcTemplate.update("insert into region_excellent_asw_time20240919(sub_subject,region,ques_no,time) value (:subSubject,:region,:quesNo,:time)",new MapSqlParameterSource(params));
}
}
}
// @Test
public void testQuesType(){
String sql = "select region from base_province_subject_tda20240919 where subject_type = '常规' group by region\n";
JdbcTemplate reportJdbcTemplate = MyDataSourceConfig.getReportJdbcTemplate();
List<String> regions = reportJdbcTemplate.queryForList(sql,String.class);
for (String region : regions) {
testQuesTypeScoreMean(region,reportJdbcTemplate);
}
}
public void testQuesTypeScoreMean(String region,JdbcTemplate jdbcTemplate){
String sql = "select\n" +
"ques_type,\n" +
"stu_qt_score_rate,\n" +
"sub_subject,\n" +
"stu_id\n" +
"from\n" +
"base_student_ques_type_tda20240919\n" +
"where\n" +
"region = '"+region+"'\n" +
"\t\t\tAND subject_type = '常规' \n" +
"\t\t\tAND exam_id = 'TDA20240919G2'\n";
List<DtoArgs> list = jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<>(DtoArgs.class));
Map<String, List<DtoArgs>> collect = list.stream().collect(Collectors.groupingBy(DtoArgs::getSubSubject));
for (String subject : collect.keySet()) {
String sql2 = "SELECT\n" +
"\tstu_id \n" +
"FROM\n" +
"\tbase_student_subject_tda20240919 \n" +
"WHERE\n" +
"\tstu_subject_score_rate_region_pct_rank >= ( 1-0.27 ) \n" +
"\tAND region = '"+region+"' \n" +
"\tAND subject_type = '常规' \n" +
"\tAND exam_id = 'TDA20240919G2' \n" +
"\tAND sub_subject = '"+subject+"'";
List<String> youshengIds = jdbcTemplate.queryForList(sql2, String.class);
//单科
List<DtoArgs> subejectList = collect.get(subject);
List<DtoArgs> collect1 = subejectList.stream().filter(x -> youshengIds.contains(x.getStuId())).collect(Collectors.toList());
//优生
Map<String, List<DtoArgs>> collect2 = collect1.stream().collect(Collectors.groupingBy(DtoArgs::getQuesType));
for (String ques_type : collect2.keySet()) {
//进行插入数据
List<DtoArgs> finalList = collect2.get(ques_type);
Double typeRateMean = finalList.stream().mapToDouble(DtoArgs::getStuQtScoreRate).sum();
Double resultMean = typeRateMean/finalList.size();
if(Double.isNaN(resultMean)||Double.isInfinite(resultMean)){
resultMean = 0.0;
}
System.out.println(resultMean);
HashMap params = new HashMap(){{
put("subSubject",subject);
put("region",region);
put("quesType",ques_type);
}};
params.put("Mean",resultMean);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
namedParameterJdbcTemplate.update("insert into region_ques_type_excellent20240919(region,sub_subject,mean,ques_type) value (:region,:subSubject,:Mean,:quesType)",new MapSqlParameterSource(params));
}
}
}
}
package com.example.pdfgenerator;
public class DeFenLu {
private String region;
private String subSubject;
private String subjectType;
private String examId;
private String quesNo;
private Double regionQuesStandardDifficulty;
private Double stuQuesScore;
private Double quesMaxScore;
private String stuId;
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getSubSubject() {
return subSubject;
}
public void setSubSubject(String subSubject) {
this.subSubject = subSubject;
}
public String getSubjectType() {
return subjectType;
}
public void setSubjectType(String subjectType) {
this.subjectType = subjectType;
}
public String getExamId() {
return examId;
}
public void setExamId(String examId) {
this.examId = examId;
}
public String getQuesNo() {
return quesNo;
}
public void setQuesNo(String quesNo) {
this.quesNo = quesNo;
}
public Double getRegionQuesStandardDifficulty() {
return regionQuesStandardDifficulty;
}
public void setRegionQuesStandardDifficulty(Double regionQuesStandardDifficulty) {
this.regionQuesStandardDifficulty = regionQuesStandardDifficulty;
}
public Double getStuQuesScore() {
return stuQuesScore;
}
public void setStuQuesScore(Double stuQuesScore) {
this.stuQuesScore = stuQuesScore;
}
public Double getQuesMaxScore() {
return quesMaxScore;
}
public void setQuesMaxScore(Double quesMaxScore) {
this.quesMaxScore = quesMaxScore;
}
}
package com.example.pdfgenerator;
public class DtoKn {
private String knowledge;
private Double stuKnScoreRate;
private String subSubject;
private String stuId;
public String getKnowledge() {
return knowledge;
}
public void setKnowledge(String knowledge) {
this.knowledge = knowledge;
}
public Double getStuKnScoreRate() {
return stuKnScoreRate;
}
public void setStuKnScoreRate(Double stuKnScoreRate) {
this.stuKnScoreRate = stuKnScoreRate;
}
public String getSubSubject() {
return subSubject;
}
public void setSubSubject(String subSubject) {
this.subSubject = subSubject;
}
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class DimensionDto {
private String sortNum;
private String dimensionName;
private String questionIndex;
private Double kcpl;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class ProvinceDifficultyAvgScoreMean {
private String province;
private String region;
private Double scoreMean;
private String difficulty;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class ProvinceExcellentDifficulty {
private String zkzNum;
private String score;
private String percentG;
private String difficulty;
private Double scoreMean;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class QuesTypeDto {
private String zkzNum;
private String quesIndex;
private Double score;
private Double fullScore;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class SchoolDifficultyPreview {
private String region;
private String school;
private String zkzNum;
private String name;
private String subSubject;
private String quesId;
private String quesIndex;
private Double score;
private Double fullScore;
private String nandu;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class SchoolQuesTypeScoreMean {
private String quesType;
private String school;
private String region;
private String province;
private String quesTypeScoreMeanAvg;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class StudentDifficultyAvgScoreMean {
private String name;
private String difficulty;
private Double scoreMean;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class StudentDimension {
private String zkzNum;
private String quesIndex;
private Double score;
private Double fullScore;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class StudentDimensionScoreMean {
private String zkzNum;
private String sortNum;
private String dimensionName;
private Double scoreMean;
private Double fullScore;
private Double kcpl;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class StudentHistogram {
private String zkzNum;
private String studentName;
private String type;
private String score;
private String provincePercent;
private String countryPercent;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class StudentQuesTypeScoreMean {
private String zkzNum;
private String quesType;
private Double quesScoreMean;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class TempStudentScoreMean {
private String quesType;
private String ZkzNum;
private Double ScoreMean;
}
package com.example.pdfgenerator.MKReport.BeanProject;
import lombok.Data;
@Data
public class thQuesTypeAnalysis {
private String subSubject;
private String quesTypeName;
private String quesIndex;
}
package com.example.pdfgenerator.MKReport;
import com.example.pdfgenerator.MKReport.BeanProject.*;
import com.example.pdfgenerator.config.MyDataSourceConfig;
import com.mysql.cj.xdevapi.SchemaImpl;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@SpringBootTest
public class MkReportTestClass {
@Test
public void TestInsertSchool(){
JdbcTemplate mkReportJdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(mkReportJdbcTemplate);
String sql = "SELECT\n" +
"\t'改革' AS region,\n" +
"\t'博野中学' AS school,\n" +
"CASE\n" +
"\t\t\n" +
"\t\tWHEN a.subject_id = 3002 THEN\n" +
"\t\t'数学' \n" +
"\tEND AS sub_subject,\n" +
"\ta.ques_id,\n" +
"\ta.ques_index,\n" +
"\ta.zkz_num,\n" +
"c.student_name as name,\n" +
"\ta.score,\n" +
"\ta.full_score,\n" +
"\tb.qujian_index as nandu\n" +
"FROM\n" +
"\tdp_ques_score a\n" +
"\tLEFT JOIN tx_nandu_20240314 b ON a.ques_id = b.ques_id \n" +
"\tAND a.subject_id = b.subject_id \n" +
"\tJOIN excel_student c on a.zkz_num = c.zkz_num\n" +
"WHERE\n" +
"\ta.subject_id = 3002";
List<SchoolDifficultyPreview> schoolDifficultyPreviewList = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(SchoolDifficultyPreview.class));
Map<String, List<SchoolDifficultyPreview>> collect = schoolDifficultyPreviewList.stream().collect(Collectors.groupingBy(SchoolDifficultyPreview::getSubSubject));
List<StudentDifficultyAvgScoreMean> avgScoreMeans = new ArrayList<>();
for (String subject : collect.keySet()) {
System.out.println("正在处理"+subject+"学科");
List<SchoolDifficultyPreview> list = collect.get(subject);
Map<String, List<SchoolDifficultyPreview>> collect1 = list.stream().collect(Collectors.groupingBy(SchoolDifficultyPreview::getNandu));
for (String nandu : collect1.keySet()) {
System.out.println("正在处理"+nandu+"难易数据");
List<SchoolDifficultyPreview> list1 = collect1.get(nandu);
Map<String, List<SchoolDifficultyPreview>> collect2 = list1.stream().collect(Collectors.groupingBy(SchoolDifficultyPreview::getName));
for (String name : collect2.keySet()) {
List<SchoolDifficultyPreview> list2 = collect2.get(name);
double scoreSum = list2.stream().mapToDouble(SchoolDifficultyPreview::getScore).sum();
double fullScoreSum = list2.stream().mapToDouble(SchoolDifficultyPreview::getFullScore).sum();
double result = (Double.isNaN(scoreSum/fullScoreSum)||Double.isInfinite(scoreSum/fullScoreSum))?0.0:(scoreSum/fullScoreSum);
System.out.println("正在处理"+name+"学生的"+nandu+"难度系数的数据---->结果为:"+result);
StudentDifficultyAvgScoreMean studentDifficultyAvgScoreMean = new StudentDifficultyAvgScoreMean();
studentDifficultyAvgScoreMean.setDifficulty(nandu.equals("1")?"易":(nandu.equals("2")?"中":"难"));
studentDifficultyAvgScoreMean.setName(name);
studentDifficultyAvgScoreMean.setScoreMean(result);
avgScoreMeans.add(studentDifficultyAvgScoreMean);
}
}
Map<String, List<StudentDifficultyAvgScoreMean>> collections = avgScoreMeans.stream().collect(Collectors.groupingBy(StudentDifficultyAvgScoreMean::getDifficulty));
for (String difficulty : collections.keySet()) {
List<StudentDifficultyAvgScoreMean> listCollections = collections.get(difficulty);
double schoolStudentDifficultyScoreMean = listCollections.stream().mapToDouble(StudentDifficultyAvgScoreMean::getScoreMean).average().getAsDouble();
HashMap params= new HashMap(){{
put("school","博野中学");
put("subSubject",subject);
put("difficult",difficulty);
put("region","改革");
put("scoreMean", schoolStudentDifficultyScoreMean);
}};
namedParameterJdbcTemplate.update("insert into school_diffficult20240314(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(params));
}
// List<SchoolDifficultyPreview> schoolDifficultyPreviews = collect.get(subject);
//
// List<SchoolDifficultyPreview> yi = new ArrayList<>();
// List<SchoolDifficultyPreview> zhong = new ArrayList<>();
// List<SchoolDifficultyPreview> nan = new ArrayList<>();
//
// for (SchoolDifficultyPreview schoolDifficultyPreview : schoolDifficultyPreviews) {
//
// if(schoolDifficultyPreview.getNandu()>=0&&schoolDifficultyPreview.getNandu()<0.3){
// yi.add(schoolDifficultyPreview);
// } else if(schoolDifficultyPreview.getNandu()>=0.3&&schoolDifficultyPreview.getNandu()<0.7){
// zhong.add(schoolDifficultyPreview);
// }else if(schoolDifficultyPreview.getNandu()>=0.7&&schoolDifficultyPreview.getNandu()<=1){
// nan.add(schoolDifficultyPreview);
// }
//
// }
//
// //处理难易程度的得分率
// double yiStuSum = yi.stream().mapToDouble(SchoolDifficultyPreview::getScore).sum();
// double yiSum = yi.stream().mapToDouble(SchoolDifficultyPreview::getFullScore).sum();
//
// double zhongStuSum = zhong.stream().mapToDouble(SchoolDifficultyPreview::getScore).sum();
// double zhongSum = zhong.stream().mapToDouble(SchoolDifficultyPreview::getFullScore).sum();
//
// double nanStuSum = nan.stream().mapToDouble(SchoolDifficultyPreview::getScore).sum();
// double nanSum = nan.stream().mapToDouble(SchoolDifficultyPreview::getFullScore).sum();
//
// System.out.println(yiStuSum/yiSum);
// double yiResult = (Double.isNaN(yiStuSum/yiSum)||Double.isInfinite(yiStuSum/yiSum))?0.0:(yiStuSum/yiSum);
// System.out.println(zhongStuSum/zhongSum);
// double zhongResult = (Double.isNaN(zhongStuSum/zhongSum)||Double.isInfinite(zhongStuSum/zhongSum))?0.0:(zhongStuSum/zhongSum);
// System.out.println(nanStuSum/nanSum);
// double nanResult = (Double.isNaN(nanStuSum/nanSum)||Double.isInfinite(nanStuSum/nanSum))?0.0:(nanStuSum/nanSum);
//
// HashMap paramsYi = new HashMap(){{
// put("school",schoolDifficultyPreviews.get(0).getSchool());
// put("subSubject",subject);
// put("difficult","易");
// put("region",schoolDifficultyPreviews.get(0).getRegion());
// put("scoreMean", yiResult);
// }};
//
// HashMap paramsZhong = new HashMap(){{
// put("school",schoolDifficultyPreviews.get(0).getSchool());
// put("subSubject",subject);
// put("difficult","中");
// put("region",schoolDifficultyPreviews.get(0).getRegion());
// put("scoreMean", zhongResult);
// }};
//
// HashMap paramsNan= new HashMap(){{
// put("school",schoolDifficultyPreviews.get(0).getSchool());
// put("subSubject",subject);
// put("difficult","难");
// put("region",schoolDifficultyPreviews.get(0).getRegion());
// put("scoreMean", nanResult);
// }};
//
// namedParameterJdbcTemplate.update("insert into school_diffficult20240314(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsYi));
// namedParameterJdbcTemplate.update("insert into school_diffficult20240314(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsZhong));
// namedParameterJdbcTemplate.update("insert into school_diffficult20240314(school,sub_subject,difficult,region,score_mean) value(:school,:subSubject,:difficult,:region,:scoreMean)",new MapSqlParameterSource(paramsNan));
}
}
@Test
public void TestInsertSchoolScoreMeanQuesType(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = " select\n" +
" ques_type_name,\n" +
" ques_index,\n" +
" subject_name as sub_subject\n" +
" from \n" +
" th_ques_type_analysis\n" +
" where\n" +
" subject_name = '数学' ";
List<thQuesTypeAnalysis> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(thQuesTypeAnalysis.class));
List<StudentQuesTypeScoreMean> collection = new ArrayList<>();
for (thQuesTypeAnalysis thQuesTypeAnalysis : list) {
System.out.println("正在处理题型是"+thQuesTypeAnalysis.getQuesTypeName()+"的平均得分率");
String queryForObject = " select \n" +
" zkz_num,\n" +
" ques_index,\n" +
" score,\n" +
" full_score\n" +
" from \n" +
" dp_ques_score\n" +
" where\n" +
" ques_index in (replacement)\n" +
" ";
queryForObject = queryForObject.replace("replacement",thQuesTypeAnalysis.getQuesIndex());
List<QuesTypeDto> quesTypeCollects = jdbcTemplate.query(queryForObject,new BeanPropertyRowMapper<>(QuesTypeDto.class));
Map<String, List<QuesTypeDto>> collect = quesTypeCollects.stream().collect(Collectors.groupingBy(QuesTypeDto::getZkzNum));
//处理每个学生的对应该种题型的平均得分率
for (String zkzNum : collect.keySet()) {
System.out.println("处理"+zkzNum+"同学的数据");
List<QuesTypeDto> collectList = collect.get(zkzNum);
Double scoreSum = collectList.stream().mapToDouble(QuesTypeDto::getScore).sum();
Double fullScoreSum = collectList.stream().mapToDouble(QuesTypeDto::getFullScore).sum();
double scoreMeanQuesType = (Double.isNaN(scoreSum/fullScoreSum)||Double.isInfinite(scoreSum/fullScoreSum))?0.0:(scoreSum/fullScoreSum);
StudentQuesTypeScoreMean studentQuesTypeScoreMean = new StudentQuesTypeScoreMean();
studentQuesTypeScoreMean.setQuesScoreMean(scoreMeanQuesType);
studentQuesTypeScoreMean.setZkzNum(zkzNum);
studentQuesTypeScoreMean.setQuesType(thQuesTypeAnalysis.getQuesTypeName());
collection.add(studentQuesTypeScoreMean);
}
}
Map<String, List<StudentQuesTypeScoreMean>> collect = collection.stream().collect(Collectors.groupingBy(StudentQuesTypeScoreMean::getQuesType));
for (String quesType : collect.keySet()) {
List<StudentQuesTypeScoreMean> quesTypeScoreMeanList = collect.get(quesType);
Double result = quesTypeScoreMeanList.stream().mapToDouble(StudentQuesTypeScoreMean::getQuesScoreMean).average().getAsDouble();
HashMap params = new HashMap(){{
put("subSubject","数学");
put("quesType",quesType);
put("school","博野中学");
put("province","山东省");
put("scoreMean",result);
put("region","改革");
}};
namedParameterJdbcTemplate.update("insert into school_quesType_score_mean20240314(sub_subject,ques_type,school,province,score_mean,region) value(:subSubject,:quesType,:school,:province,:scoreMean,:region)",new MapSqlParameterSource(params));
}
}
@Test
public void GeDimensionScoreMean(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = " select \n" +
" sort_num,\n" +
" dimension_name,\n" +
" question_index,\n" +
" kcpl\n" +
" from \n" +
" th_dimension_question\n";
List<DimensionDto> dimensionList = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DimensionDto.class));
List<StudentDimensionScoreMean> collection = new ArrayList<>();
for (DimensionDto dimensionDto : dimensionList) {
String queryForDimensionQues = "select\n" +
"zkz_num,\n" +
"ques_index, \n" +
"score,\n" +
"full_score\n" +
"from\n" +
"dp_ques_score\n" +
"where\n" +
"ques_index in ( replacement )";
queryForDimensionQues = queryForDimensionQues.replace("replacement",dimensionDto.getQuestionIndex());
List<StudentDimension> dimensionDtoS = namedParameterJdbcTemplate.query(queryForDimensionQues,new BeanPropertyRowMapper<>(StudentDimension.class));
Map<String, List<StudentDimension>> collect = dimensionDtoS.stream().collect(Collectors.groupingBy(StudentDimension::getZkzNum));
for (String zkzNum : collect.keySet()) {
List<StudentDimension> studentDimensionList = collect.get(zkzNum);
Double scoreSum = studentDimensionList.stream().mapToDouble(StudentDimension::getScore).sum();
Double fullScoreSum = studentDimensionList.stream().mapToDouble(StudentDimension::getFullScore).sum();
double scoreMeanDimension = (Double.isNaN(scoreSum/fullScoreSum)||Double.isInfinite(scoreSum/fullScoreSum))?0.0:(scoreSum/fullScoreSum);
StudentDimensionScoreMean studentDimensionScoreMean = new StudentDimensionScoreMean();
studentDimensionScoreMean.setDimensionName(dimensionDto.getDimensionName());
studentDimensionScoreMean.setScoreMean(scoreMeanDimension);
studentDimensionScoreMean.setSortNum(dimensionDto.getSortNum());
studentDimensionScoreMean.setZkzNum(zkzNum);
studentDimensionScoreMean.setFullScore(fullScoreSum);
studentDimensionScoreMean.setKcpl(dimensionDto.getKcpl());
collection.add(studentDimensionScoreMean);
}
}
Map<String, List<StudentDimensionScoreMean>> collect = collection.stream().collect(Collectors.groupingBy(StudentDimensionScoreMean::getSortNum));
for (String sortNum : collect.keySet()) {
List<StudentDimensionScoreMean> studentDimensions = collect.get(sortNum);
Double result = studentDimensions.stream().mapToDouble(StudentDimensionScoreMean::getScoreMean).average().getAsDouble();
HashMap params = new HashMap(){{
put("scoreMean",result);
put("kcpl",studentDimensions.get(0).getKcpl());
put("sortNum",sortNum);
put("dimensionName",studentDimensions.get(0).getDimensionName());
put("fullScore",studentDimensions.get(0).getFullScore());
put("school","博野中学");
}};
namedParameterJdbcTemplate.update("insert into school_dimesion_score_mean20240314(score_mean,sort_num,dimension_name,school,full_score,kcpl) value(:scoreMean,:sortNum,:dimensionName,:school,:fullScore,:kcpl)",new MapSqlParameterSource(params));
}
}
@Test
public void percentHistogram(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "SELECT\n" +
" a.zkz_num,\n" +
"\tb.student_name,\n" +
" b.type,\n" +
"\ta.score,\n" +
"\tc.percent_g as province_percent,\n" +
"\td.percent_g as country_percent\n" +
"FROM\n" +
"\t ( select\n" +
" zkz_num,\n" +
" sum(score) as score \n" +
" from \n" +
" dp_ques_score\n" +
" group by zkz_num ) a \n" +
"left join\n" +
" `excel_student` b on a.zkz_num = b.zkz_num\n" +
"left join \n" +
" total_subject_score_perent_mapping c on a.score = c.score \n" +
"left join\n" +
" total_subject_score_perent_mapping_guo d on a.score = d.score\n" +
" ";
List<StudentHistogram> histogramList = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(StudentHistogram.class));
for (StudentHistogram studentHistogram : histogramList) {
HashMap params = new HashMap(){{
put("school","博野中学");
put("zkzNum",studentHistogram.getZkzNum());
put("studentName",studentHistogram.getStudentName());
put("type",studentHistogram.getType());
put("score",studentHistogram.getScore());
put("provincePercent",studentHistogram.getProvincePercent());
put("countryPercent",studentHistogram.getCountryPercent());
}};
namedParameterJdbcTemplate.update("insert into school_histrogram20240314(school,zkz_num,student_name,type,score,province_percent,country_percent) value(:school,:zkzNum,:studentName,:type,:score,:provincePercent,:countryPercent)",new MapSqlParameterSource(params));
}
}
@Test
public void insertProvinceQuesType(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "select\n" +
"tx_name as ques_type,\n" +
"zkz_num as zkz_num,\n" +
"defenlu as score_mean\n" +
"from\n" +
"tx_defenlu_20240314\n" +
"where\n" +
"province_id in (13,37) \n" +
"and subject_id = 3002 ";
List<TempStudentScoreMean> list = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(TempStudentScoreMean.class));
Map<String, List<TempStudentScoreMean>> collect = list.stream().collect(Collectors.groupingBy(TempStudentScoreMean::getQuesType));
//省份 题型
for (String quesType : collect.keySet()) {
System.out.println("正在处理"+quesType+"题型的关于"+"山东省和博野中学的数据");
List<TempStudentScoreMean> tempStudentScoreMeanList = collect.get(quesType);
//计算数据的平均得分率
double provinceAverage = tempStudentScoreMeanList.stream().mapToDouble(TempStudentScoreMean::getScoreMean).average().getAsDouble();
HashMap params = new HashMap(){{
put("province","山东省");
put("scoreMean",provinceAverage);
put("quesType",quesType);
put("region","改革");
put("subSubject","数学");
}};
namedParameterJdbcTemplate.update("insert into province_ques_type_score_mean20240314(province,score_mean,ques_type,region,sub_subject) value(:province,:scoreMean,:quesType,:region,:subSubject)",new MapSqlParameterSource(params));
}
}
@Test
public void insertQuesTypeProvinceExcellent(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "select\n" +
"a.zkz_num as zkz_num,\n" +
"a.score,\n" +
"a.percent_g ,\n" +
"b.tx_name as ques_type,\n" +
"b.defenlu as score_mean\n" +
"from\n" +
"(select \n" +
"a.zkz_num,\n" +
"a.score,\n" +
"a.subject_id,\n" +
"a.province_id,\n" +
"b.percent_g\n" +
"from\n" +
"dp_subject_score a \n" +
"left join total_subject_score_perent_mapping b on a.score = b.score \n" +
"where \n" +
"a.subject_id = 3002 \n" +
"and \n" +
"a.province_id in(37,13)\n" +
"and b.percent_g > 73) a\n" +
"join \n" +
"tx_defenlu_20240314 b on a.zkz_num = b.zkz_num and a.subject_id = b.subject_id \n" +
"order by a.province_id";
List<TempStudentScoreMean> list = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(TempStudentScoreMean.class));
Map<String, List<TempStudentScoreMean>> collect = list.stream().collect(Collectors.groupingBy(TempStudentScoreMean::getQuesType));
//省份 题型
for (String quesType : collect.keySet()) {
System.out.println("正在处理"+quesType+"题型的关于"+"山东省和博野中学的数据");
List<TempStudentScoreMean> tempStudentScoreMeanList = collect.get(quesType);
//计算数据的平均得分率
double provinceAverage = tempStudentScoreMeanList.stream().mapToDouble(TempStudentScoreMean::getScoreMean).average().getAsDouble();
HashMap params = new HashMap(){{
put("province","山东省");
put("scoreMean",provinceAverage);
put("quesType",quesType);
put("region","改革");
put("subSubject","数学");
}};
namedParameterJdbcTemplate.update("insert into province_excellent_ques_type_score_mean20240314(province,score_mean,ques_type,region,sub_subject) value(:province,:scoreMean,:quesType,:region,:subSubject)",new MapSqlParameterSource(params));
}
}
@Test
public void insertProvinceExcellentDifficulty(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "SELECT\n" +
"\ta.zkz_num AS zkz_num,\n" +
"\ta.score,\n" +
"\ta.percent_g,\n" +
"\tcase\n" +
"\twhen\n" +
"\tb.qujian_index = 1 then '易' \n" +
"\twhen b.qujian_index = 2 then '中' \n" +
" when b.qujian_index = 3 then '难'\n" +
"\tend as difficulty,\n" +
"\tb.defenlu AS score_mean \n" +
"FROM\n" +
"\t(\n" +
"\tSELECT\n" +
"\t\ta.zkz_num,\n" +
"\t\ta.score,\n" +
"\t\ta.subject_id,\n" +
"\t\ta.province_id,\n" +
"\t\tb.percent_g \n" +
"\tFROM\n" +
"\t\tdp_subject_score a\n" +
"\t\tLEFT JOIN total_subject_score_perent_mapping b ON a.score = b.score \n" +
"\tWHERE\n" +
"\t\ta.subject_id = 3002 \n" +
"\t\tAND a.province_id IN ( 37, 13 ) \n" +
"\t\tAND b.percent_g > 73 \n" +
"\t) a\n" +
"\tJOIN tx_nandu_defenlu_20240314 b ON a.zkz_num = b.zkz_num \n" +
"\tAND a.subject_id = b.subject_id \n" +
"ORDER BY\n" +
"\ta.province_id";
List<ProvinceExcellentDifficulty> list = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ProvinceExcellentDifficulty.class));
Map<String, List<ProvinceExcellentDifficulty>> collect = list.stream().collect(Collectors.groupingBy(ProvinceExcellentDifficulty::getDifficulty));
for (String difficulty : collect.keySet()) {
System.out.println("处理"+difficulty+"难度题型系数");
List<ProvinceExcellentDifficulty> collections = collect.get(difficulty);
double result = collections.stream().mapToDouble(ProvinceExcellentDifficulty::getScoreMean).average().getAsDouble();
HashMap params = new HashMap(){{
put("province","山东省");
put("scoreMean",result);
put("difficulty",difficulty);
put("region","改革");
put("subSubject","数学");
}};
namedParameterJdbcTemplate.update("insert into province_excellent_difficulty_score_mean20240314(province,score_mean,difficulty,region,sub_subject) value(:province,:scoreMean,:difficulty,:region,:subSubject)",new MapSqlParameterSource(params));
}
}
@Test
public void insertProvinceDifficulty(){
JdbcTemplate jdbcTemplate = MyDataSourceConfig.getMkReportJdbcTemplate();
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
String sql = "select\n" +
"'山东省' as province,\n" +
"'改革' as region,\n" +
"AVG(defenlu) as score_mean,\n" +
"Case\n" +
"when \n" +
"qujian_index = 1 then '易'\n" +
"when \n" +
"qujian_index = 2 then '中'\n" +
"when\n" +
"qujian_index = 3 then '难'\n" +
"end as difficulty\n" +
"from \n" +
"tx_nandu_defenlu_20240314 \n" +
"where \n" +
"province_id in (13,37)\n" +
"group by qujian_index ";
List<ProvinceDifficultyAvgScoreMean> list = namedParameterJdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ProvinceDifficultyAvgScoreMean.class));
for (ProvinceDifficultyAvgScoreMean provinceDifficultyAvgScoreMean : list) {
HashMap params = new HashMap(){{
put("province",provinceDifficultyAvgScoreMean.getProvince());
put("scoreMean",provinceDifficultyAvgScoreMean.getScoreMean());
put("difficulty",provinceDifficultyAvgScoreMean.getDifficulty());
put("region",provinceDifficultyAvgScoreMean.getRegion());
put("subSubject","数学");
}};
namedParameterJdbcTemplate.update("insert into province_difficulty_score_mean20240314(province,score_mean,difficulty,region,sub_subject) value(:province,:scoreMean,:difficulty,:region,:subSubject)",new MapSqlParameterSource(params));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment