Forráskód Böngészése

t push -u origin master

郭超 4 éve
commit
7d7d56648b

+ 34 - 0
.gitignore

@@ -0,0 +1,34 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**
+!**/src/test/**
+.mvn
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+*.xls
+
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+
+### VS Code ###
+.vscode/

+ 286 - 0
mvnw

@@ -0,0 +1,286 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#    https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+#   JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+#   M2_HOME - location of maven2's installed home dir
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
+#     e.g. to debug Maven itself, use
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+  if [ -f /etc/mavenrc ] ; then
+    . /etc/mavenrc
+  fi
+
+  if [ -f "$HOME/.mavenrc" ] ; then
+    . "$HOME/.mavenrc"
+  fi
+
+fi
+
+# OS specific support.  $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+  CYGWIN*) cygwin=true ;;
+  MINGW*) mingw=true;;
+  Darwin*) darwin=true
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+    if [ -z "$JAVA_HOME" ]; then
+      if [ -x "/usr/libexec/java_home" ]; then
+        export JAVA_HOME="`/usr/libexec/java_home`"
+      else
+        export JAVA_HOME="/Library/Java/Home"
+      fi
+    fi
+    ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+  if [ -r /etc/gentoo-release ] ; then
+    JAVA_HOME=`java-config --jre-home`
+  fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+  ## resolve links - $0 may be a link to maven's home
+  PRG="$0"
+
+  # need this for relative symlinks
+  while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+      PRG="$link"
+    else
+      PRG="`dirname "$PRG"`/$link"
+    fi
+  done
+
+  saveddir=`pwd`
+
+  M2_HOME=`dirname "$PRG"`/..
+
+  # make it fully qualified
+  M2_HOME=`cd "$M2_HOME" && pwd`
+
+  cd "$saveddir"
+  # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --unix "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+  # TODO classpath?
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+  javaExecutable="`which javac`"
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+    # readlink(1) is not available as standard on Solaris 10.
+    readLink=`which readlink`
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+      if $darwin ; then
+        javaHome="`dirname \"$javaExecutable\"`"
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+      else
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
+      fi
+      javaHome="`dirname \"$javaExecutable\"`"
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+      JAVA_HOME="$javaHome"
+      export JAVA_HOME
+    fi
+  fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+  if [ -n "$JAVA_HOME"  ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+      # IBM's JDK on AIX uses strange locations for the executables
+      JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+      JAVACMD="$JAVA_HOME/bin/java"
+    fi
+  else
+    JAVACMD="`which java`"
+  fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+  echo "Error: JAVA_HOME is not defined correctly." >&2
+  echo "  We cannot execute $JAVACMD" >&2
+  exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+  echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+  if [ -z "$1" ]
+  then
+    echo "Path not specified to find_maven_basedir"
+    return 1
+  fi
+
+  basedir="$1"
+  wdir="$1"
+  while [ "$wdir" != '/' ] ; do
+    if [ -d "$wdir"/.mvn ] ; then
+      basedir=$wdir
+      break
+    fi
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+    if [ -d "${wdir}" ]; then
+      wdir=`cd "$wdir/.."; pwd`
+    fi
+    # end of workaround
+  done
+  echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+  if [ -f "$1" ]; then
+    echo "$(tr -s '\n' ' ' < "$1")"
+  fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+  exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Found .mvn/wrapper/maven-wrapper.jar"
+    fi
+else
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+    fi
+    jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
+    while IFS="=" read key value; do
+      case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+      esac
+    done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Downloading from: $jarUrl"
+    fi
+    wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+
+    if command -v wget > /dev/null; then
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Found wget ... using wget"
+        fi
+        wget "$jarUrl" -O "$wrapperJarPath"
+    elif command -v curl > /dev/null; then
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Found curl ... using curl"
+        fi
+        curl -o "$wrapperJarPath" "$jarUrl"
+    else
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Falling back to using Java to download"
+        fi
+        javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+        if [ -e "$javaClass" ]; then
+            if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+                if [ "$MVNW_VERBOSE" = true ]; then
+                  echo " - Compiling MavenWrapperDownloader.java ..."
+                fi
+                # Compiling the Java class
+                ("$JAVA_HOME/bin/javac" "$javaClass")
+            fi
+            if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+                # Running the downloader
+                if [ "$MVNW_VERBOSE" = true ]; then
+                  echo " - Running MavenWrapperDownloader.java ..."
+                fi
+                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+            fi
+        fi
+    fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+  echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+  $MAVEN_OPTS \
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 161 - 0
mvnw.cmd

@@ -0,0 +1,161 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements.  See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership.  The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License.  You may obtain a copy of the License at
+@REM
+@REM    https://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied.  See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven2 Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM     e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
+FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
+	IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+    echo Found %WRAPPER_JAR%
+) else (
+    echo Couldn't find %WRAPPER_JAR%, downloading it ...
+	echo Downloading from: %DOWNLOAD_URL%
+    powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
+    echo Finished downloading %WRAPPER_JAR%
+)
+@REM End of extension
+
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
+
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+
+exit /B %ERROR_CODE%

+ 108 - 0
pom.xml

@@ -0,0 +1,108 @@
+<?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>1.5.3.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.mooctest</groupId>
+    <artifactId>export</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>export</name>
+    <description>Project for exporting reports in excel.</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <!-- 在docker运行时要用的,只是一个前缀而已,就像包名一样,可自己任意定义此名称 -->
+        <docker.image.prefix>crowd_review</docker.image.prefix>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!--apache工具类-->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.1</version>
+        </dependency>
+        <!--lombok-->
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.2</version>
+            <scope>provided</scope>
+        </dependency>
+
+
+        <!--处理JSON格式-->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.3</version>
+        </dependency>
+
+        <!-- 基本依赖,仅操作 xls 格式只需引入此依赖 -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>3.14</version>
+        </dependency>
+        <!-- 使用 xlsx 格式需要额外引入此依赖 -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>3.14</version>
+        </dependency>
+
+
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+            <!-- docker 插件 begin -->
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>docker-maven-plugin</artifactId>
+                <version>1.0.0</version>
+                <configuration>
+                    <!--ray/springboot-docker-->
+                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
+                    <dockerDirectory>.</dockerDirectory>
+                    <resources>
+                        <resource>
+                            <targetPath>/</targetPath>
+                            <directory>${project.build.directory}</directory>
+                            <include>${project.build.finalName}.jar</include>
+                        </resource>
+                    </resources>
+                </configuration>
+            </plugin>
+            <!-- docker 插件 end -->
+        </plugins>
+        <!--打包后文件名称-->
+        <finalName>export-excel</finalName>
+    </build>
+
+</project>

+ 19 - 0
src/main/java/com/mooctest/export/DoExportRunner.java

@@ -0,0 +1,19 @@
+package com.mooctest.export;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+public class DoExportRunner implements Callable<Integer> {
+
+    private List<FinalReportDTO> data ;
+    public DoExportRunner(List<FinalReportDTO> datas){
+        this.data = datas;
+    }
+
+
+    @Override
+    public Integer call() throws Exception {
+        Report2xls.report2excel(data);
+        return data.size();
+    }
+}

+ 13 - 0
src/main/java/com/mooctest/export/ExportApplication.java

@@ -0,0 +1,13 @@
+package com.mooctest.export;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ExportApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(ExportApplication.class, args);
+    }
+
+}

+ 76 - 0
src/main/java/com/mooctest/export/ExportController.java

@@ -0,0 +1,76 @@
+package com.mooctest.export;
+
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+
+@Controller
+public class ExportController {
+    @Autowired
+    ExportService exportService;
+
+    @Value("${export.path}")
+    private String exportPath;
+
+    @Value("${crowd.frontend}")
+    private String crowdFrontend;
+
+    @PostMapping("/generateReport")
+    @ResponseBody
+    public String getReport(@RequestBody JSONObject jsonParam) {
+//        String res = exportService.getData(examId,caseId);
+        List<Object> projects = (List<Object>) jsonParam.get("projects");
+        Map<String,Object> data = (Map<String, Object>) projects.get(0);
+        System.out.println("data "+ data.toString());
+        List<Object> repports = (List<Object>) data.get("reports");
+        List<FinalReportDTO>datas = toReportDto(repports);
+        System.out.println("exportPath " + exportPath + "/excel-"+datas.get(0).getExamId()+"-"+datas.get(0).getCaseId()+".xls");
+        File file=new File(exportPath + "/excel-"+datas.get(0).getExamId()+"-"+datas.get(0).getCaseId()+".xls");
+        DoExportRunner ctt = new DoExportRunner(datas);
+        FutureTask<Integer> ft = new FutureTask<>(ctt);
+        ExecutorService executorService = Executors.newFixedThreadPool(1);
+        executorService.execute(ft);
+        String result = "wait";
+        if (file.exists()){
+            //todo 上传到oss 再返回oss
+            //文件存在。
+            result = crowdFrontend + exportPath + "/excel-" + datas.get(0).getExamId() + "-" + datas.get(0).getCaseId() + ".xls";
+        }
+        System.out.println(result);
+        return result;
+    }
+
+
+    private List<FinalReportDTO> toReportDto(List<Object> data ){
+        List<FinalReportDTO> res = new ArrayList<>();
+        FinalReportDTO temp;
+        data.forEach(s->{
+            res.add(new FinalReportDTO((LinkedHashMap<String,Object>) s ));
+        });
+        return res;
+    }
+
+
+
+
+//    @GetMapping("/generateReport")
+//    public String getReport(@RequestParam("projects") String projects,
+//                            @RequestParam("menus") String menus,
+//                            @RequestParam("projectStatistics")String projectStatistics) {
+//
+//        return "";
+//    }
+
+
+}

+ 25 - 0
src/main/java/com/mooctest/export/ExportService.java

@@ -0,0 +1,25 @@
+package com.mooctest.export;
+
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+@Service
+public class ExportService {
+
+
+    public String getData (String examId,String caseId){
+        JSONObject params = new JSONObject();
+        params.put("examId",examId);
+        params.put("caseId",caseId);
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+        HttpEntity<String> request = new HttpEntity<>(params.toJSONString(), headers);
+        RestTemplate rt = HttpUtil.getRestTemplate();
+        String url = rt.postForObject("127.0.0.1:8080/final_report/data", request, String.class);
+        return url;
+    }
+}

+ 59 - 0
src/main/java/com/mooctest/export/FinalReportDTO.java

@@ -0,0 +1,59 @@
+package com.mooctest.export;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Map;
+
+@Data
+public class FinalReportDTO {
+    private long id;
+
+    private String description;
+
+    private String[] imgUrls;
+
+    private int severity;
+
+    private int recurrent;
+
+    private int category;
+
+    private long writerId;
+
+    private String sourceId;
+
+    private Date createTime;
+
+    private long examId;
+
+    private long caseId;
+
+    public FinalReportDTO(Map<String , Object > data){
+        this.caseId =(Integer) data.get("caseId");
+        this.category=(Integer) data.get("category");
+        this.createTime = new Date((Long) data.get("createTime"));
+        this.description = (String) data.get("description");
+        this.examId = (Integer) data.get("examId");
+        this.id=(Integer) data.get("id");
+        String imsStr = (String)data.get("imgUrls");
+        if(imsStr!=null&&imsStr.length()!=0){
+            this.imgUrls = wrapImgStr(imsStr);
+        }
+        this.recurrent = (Integer) data.get("recurrent");
+        this.severity = (Integer) data.get("severity");
+        this.writerId = (Integer) data.get("writerId");
+    }
+
+    private String [] wrapImgStr(String imsStr){
+        String temp [] = imsStr.split(",");
+        ArrayList<String> res = new ArrayList<>();
+        for(int i =0;i<temp.length;i++){
+            if(temp[i]!=null&&temp[i].length()!=0){
+                res.add(temp[i]);
+            }
+        }
+        return (String[]) res.toArray( new String[res.size()]);
+    }
+}

+ 15 - 0
src/main/java/com/mooctest/export/HeartController.java

@@ -0,0 +1,15 @@
+package com.mooctest.export;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+public class HeartController {
+
+    @PostMapping("/hello")
+    @ResponseBody
+    public String getReport() {
+        return "hello";
+    }
+}

+ 11 - 0
src/main/java/com/mooctest/export/HttpUtil.java

@@ -0,0 +1,11 @@
+package com.mooctest.export;
+
+import org.springframework.web.client.RestTemplate;
+
+public class HttpUtil {
+    static RestTemplate rt = new RestTemplate();
+
+    public static RestTemplate getRestTemplate() {
+        return rt;
+    }
+}

+ 29 - 0
src/main/java/com/mooctest/export/MyWebAppConfig.java

@@ -0,0 +1,29 @@
+package com.mooctest.export;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+@Configuration
+public class MyWebAppConfig extends WebMvcConfigurerAdapter {
+    /**
+     * addResourceHandler() 添加请求路径方法
+     * 注意:/video/** 改为 /**会覆盖默认的映射(classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/)
+     *      这种情况下项目路径下的resources目录中的所有文件都不能访问,
+     *      解决办法:addResourceLocations(String... resourceLocations) 依次把映射路径加入进去
+     *      registry.addResourceHandler("/**").addResourceLocations("classpath:/resources/","classpath:/resources/","file:F:/迅雷下载/").;
+     * addResourceLocations() 添加映射路径方法
+     * 注意:必须要加 file:或classpath: 否则无法访问
+     *      file:绝对路径下的映射
+     *      classpath:相对路径下的映射
+     */
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        //迅雷下载文件夹下有a.mp4,访问路径:http:xxxx/video/a.mp4
+//        System.out.println(ClassUtils.getDefaultClassLoader().getResource("").getPath());
+//        String ddd = ClassUtils.getDefaultClassLoader().getResource("").getPath().split("target")[0];
+//        System.out.println(ddd);
+        registry.addResourceHandler("/data/**").addResourceLocations("file:"+"/data/");
+        super.addResourceHandlers(registry);
+    }
+}

+ 167 - 0
src/main/java/com/mooctest/export/Report2xls.java

@@ -0,0 +1,167 @@
+package com.mooctest.export;
+
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+
+@Configuration
+public class Report2xls {
+
+    private static String exportPath;
+
+    @Value("${export.path}")
+    public void setExportPath(String exportPathParam){
+        exportPath = exportPathParam;
+    }
+
+    private static String []  theads  = {"报告ID","bug分类","级别","复现程度","描述",
+            "图片1","图片2","图片3","图片4","图片5","图片6","图片7","图片8",
+            "图片9","图片10","图片11","图片12","图片13","图片14","图片15"
+            ,"图片16","图片17","图片18","图片19"};
+
+
+
+    public static void  report2excel (List<FinalReportDTO> data){
+        FileOutputStream fileOut = null; // 为了输出excel 文件
+        BufferedImage bufferImg = null;
+        HSSFCellStyle desCellStyle ;
+        HSSFCellStyle lineCellStyle ;
+//        System.out.println();
+        try {
+            ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
+
+            int maxImgLength = max(getMaxImgs(data),10); // 获得最大的图片列数
+            // 限定列数
+//            int cols = 6+maxImgLength;
+
+            HSSFWorkbook wb = new HSSFWorkbook();
+            HSSFSheet sheet1 = wb.createSheet("sheet1");
+            for (int i =5;i<maxImgLength;i++){
+                sheet1.setColumnWidth((short)i,(short)60*256);
+            }
+            sheet1.setColumnWidth((short)4,(short)30*256); // 设置描述列的宽度
+            desCellStyle = wb.createCellStyle();
+            desCellStyle.setWrapText(true);
+            desCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
+            lineCellStyle = wb.createCellStyle();
+            lineCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//设置文字居中,垂直居中
+            sheet1.setDefaultRowHeight((short)(30*256));
+            HSSFPatriarch patriarch = sheet1.createDrawingPatriarch(); // 创建的用来画图的
+            HSSFClientAnchor anchor;
+            Cell cell1,cell2,cell3,cell4,cell0;
+
+            int tempWidth;
+            int tempHeight;
+            int fitSize [] ;
+            Row thead = sheet1.createRow(0);
+            thead.setHeight((short)480);
+            for(int i =0;i<4+maxImgLength&&i<20;i++){
+                thead.createCell(i).setCellValue(theads[i]);
+            }
+            for (int rowNum = 0; rowNum < data.size(); rowNum++) {
+                Row row = sheet1.createRow(rowNum+1);
+//                System.out.println(rowNum);
+                FinalReportDTO dto = data.get(rowNum);
+                cell0 = row.createCell(0);
+                cell0.setCellValue(rowNum+1);
+                cell0.setCellStyle(lineCellStyle);
+                cell1 = row.createCell(1);
+                cell1.setCellValue(ReportUtil.category2String.get(dto.getCategory()));
+                cell1.setCellStyle(lineCellStyle);
+                cell2 =  row.createCell(2);
+                cell2.setCellValue(ReportUtil.severity2String.get(dto.getSeverity()));
+                cell2.setCellStyle(lineCellStyle);
+                cell3 = row.createCell(3);
+                cell3.setCellValue(ReportUtil.recurrent2String.get(dto.getRecurrent()));
+                cell3.setCellStyle(lineCellStyle);
+                cell4 = row.createCell(4);
+                cell4.setCellStyle(desCellStyle);
+                cell4.setCellValue(dto.getDescription());
+                if(dto.getImgUrls()!=null){
+                    row.setHeight((short)(30*256)); // 说明有图片,设置高度
+                    for(int photoIndex = 0;photoIndex<maxImgLength&&photoIndex<dto.getImgUrls().length;photoIndex++){
+                        //96报错
+                        URL url = new URL(dto.getImgUrls()[photoIndex]);
+                        URLConnection connection = url.openConnection();
+                        connection.setDoOutput(true);
+                        bufferImg = ImageIO.read(connection.getInputStream());
+                        tempWidth = bufferImg.getWidth();
+                        tempHeight = bufferImg.getHeight();
+                        fitSize = getFitHeightAndWidth(tempHeight,tempWidth);
+                        ImageIO.write(bufferImg, getPictureType(bufferImg.getType()), byteArrayOut);
+                        anchor = new HSSFClientAnchor(fitSize[1]*4, fitSize[0], 0, 0,(short) (5+photoIndex), (rowNum+1), (short) (6+photoIndex), rowNum+2);
+                        //插入图片 1
+                        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(),bufferImg.getType()));
+                        bufferImg = null;
+                        byteArrayOut = new ByteArrayOutputStream();
+                    }
+                }
+            }
+            fileOut = new FileOutputStream(exportPath+"/excel-"+data.get(0).getExamId()+"-"+data.get(0).getCaseId()+".xls");
+            wb.write(fileOut);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获得报告内的最大图片数量
+     * @param reports
+     * @return
+     */
+    private static int getMaxImgs (List<FinalReportDTO> reports ){
+        int res =0;
+        for (FinalReportDTO dto : reports){
+            if(dto.getImgUrls()!=null)
+                res = max(res,dto.getImgUrls().length);
+        }
+        return res;
+    }
+
+
+
+    private static int max(int a, int b) {
+        return a>b?a:b;
+    }
+
+    private static String getPictureType(int type){
+        if(type==6){
+            return "png";
+        }
+        return "jpg";
+    }
+
+    /**
+     * 0 is Height and 1 is width
+     * @param height
+     * @param width
+     * @return
+     */
+    private static int[] getFitHeightAndWidth(int height,int width){
+        //默认格子的大小是正方形的。
+        int [] res = new int[2];
+        int max = Math.max(height,width);
+        int min = Math.min(height,width);
+        min = (int)( (min*1.0/max)*255 );
+        if(height>width){
+            res[0] = 0;
+            res[1] = 255-min;
+        }else {
+            res[1] = 0;
+            res[0] = 255-min;
+        }
+        return res;
+    }
+
+
+}

+ 49 - 0
src/main/java/com/mooctest/export/ReportUtil.java

@@ -0,0 +1,49 @@
+package com.mooctest.export;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ReportUtil {
+    public static Map<Integer, String> severity2String = new HashMap<Integer, String>() {{
+            put(5, "紧急");
+            put(4, "严重");
+            put(3, "一般");
+            put(2, "较轻");
+            put(1, "待定");
+    }};
+
+    public static Map<Integer, String> category2String = new HashMap<Integer, String>() {{
+        put(5, "用户体验");
+        put(4, "页面布局缺陷");
+        put(3, "性能");
+        put(2, "功能不完整");
+        put(1, "安全");
+        put(6, "不正常退出");
+        put(7, "其他");
+    }};
+
+    public static Map<String, Integer> string2Category = new HashMap<String, Integer>() {{
+        put("用户体验", 5);
+        put("页面布局缺陷", 4);
+        put("性能", 3);
+        put("功能不完整", 2);
+        put("安全", 1);
+        put("不正常退出", 6);
+        put("其他", 7);
+    }};
+
+    public static Map<Integer, String> recurrent2String = new HashMap<Integer, String>() {{
+        put(5, "必现");
+        put(4, "大概率复现");
+        put(3, "小概率复现");
+        put(2, "无规律复现");
+        put(1, "其他");
+    }};
+
+    public static Map<Long, String> reviewerMap = new HashMap<Long, String>() {{
+       put(1l, "管理员");
+       put(2l, "周顺祥");
+       put(3l, "陈笑智");
+       put(4l, "韩鹏飞");
+    }};
+}

+ 3 - 0
src/main/resources/application.properties

@@ -0,0 +1,3 @@
+server.port=9003
+export.path=/Users/guochao/Desktop/corwd-file/xinchuang/excel
+crowd.frontend=http://127.0.0.1:5555

+ 16 - 0
src/test/java/com/mooctest/export/ExportApplicationTests.java

@@ -0,0 +1,16 @@
+package com.mooctest.export;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ExportApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}