commit 823ef3f8707ca917605fa003eb83c56c5a7d3490 Author: linjj <850658129@qq.com> Date: Thu Mar 27 17:48:22 2025 +0800 湛江重耗材采集器 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..90f6aaf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 potter fu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f2c46d --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# springboot-mybatis2datasource-demo +[![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu) + +Spring Boot整合MyBatis双数据源Demo diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..5551fde --- /dev/null +++ b/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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# 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 "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..e5cfb0a --- /dev/null +++ b/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 http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM 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% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e95f529 --- /dev/null +++ b/pom.xml @@ -0,0 +1,131 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.1.RELEASE + + com.example + consumables_zj + 0.0.1-SNAPSHOT + jar + springbootDemo + springbootDemo + + 1.8 + + + + + net.java.dev.jna + jna + 5.13.0 + + + net.java.dev.jna + jna-platform + 5.13.0 + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.9 + + + + mysql + mysql-connector-java + 8.0.23 + + + + org.apache.pdfbox + pdfbox + 2.0.27 + + + org.apache.commons + commons-collections4 + 4.4 + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.plugin + spring-plugin-core + 2.0.0.RELEASE + + + org.springframework.plugin + spring-plugin-metadata + 2.0.0.RELEASE + + + com.baomidou + mybatis-plus-boot-starter + 3.3.1 + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-quartz + + + + com.microsoft.sqlserver + sqljdbc4 + 4.0 + + + junit + junit + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-test + + + commons-io + commons-io + 2.6 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/src/main/java/com/example/MainApplication.java b/src/main/java/com/example/MainApplication.java new file mode 100644 index 0000000..244a6b2 --- /dev/null +++ b/src/main/java/com/example/MainApplication.java @@ -0,0 +1,16 @@ +package com.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author potter.fu + * @date 2018-12-07 15:40 + */ +@SpringBootApplication +public class MainApplication { + public static void main(String[] args) { + + SpringApplication.run(MainApplication.class, args); + } +} diff --git a/src/main/java/com/example/config/DataSource1Config.java b/src/main/java/com/example/config/DataSource1Config.java new file mode 100644 index 0000000..28eee31 --- /dev/null +++ b/src/main/java/com/example/config/DataSource1Config.java @@ -0,0 +1,58 @@ +package com.example.config; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; + + +@Configuration +@MapperScan(basePackages = "com.example.db1.dao", sqlSessionTemplateRef = "db1SqlSessionTemplate") +public class DataSource1Config { + /** + * 生成数据源. @Primary 注解声明为默认数据源 + */ + @Bean(name = "db1DataSource") + @ConfigurationProperties(prefix = "spring.datasource.hikari.db1") + @Primary + public DataSource testDataSource() { + return DataSourceBuilder.create().build(); + } + + /** + * 创建 SqlSessionFactory + */ + @Bean(name = "db1SqlSessionFactory") + @Primary + public SqlSessionFactory testSqlSessionFactory(@Qualifier("db1DataSource") DataSource dataSource) throws Exception { + SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); + bean.setDataSource(dataSource); + bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db1/*.xml")); + return bean.getObject(); + } + + /** + * 配置事务管理 + */ + @Bean(name = "db1TransactionManager") + @Primary + public DataSourceTransactionManager testTransactionManager(@Qualifier("db1DataSource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + + @Bean(name = "db1SqlSessionTemplate") + @Primary + public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("db1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { + return new SqlSessionTemplate(sqlSessionFactory); + } +} diff --git a/src/main/java/com/example/config/DataSource2Config.java b/src/main/java/com/example/config/DataSource2Config.java new file mode 100644 index 0000000..5c4120e --- /dev/null +++ b/src/main/java/com/example/config/DataSource2Config.java @@ -0,0 +1,45 @@ +package com.example.config; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; + + +@Configuration +@MapperScan(basePackages = "com.example.db2.dao", sqlSessionTemplateRef = "db2SqlSessionTemplate") +public class DataSource2Config { + + @Bean(name = "db2DataSource") + @ConfigurationProperties(prefix = "spring.datasource.hikari.db2") + public DataSource testDataSource() { + return DataSourceBuilder.create().build(); + } + + @Bean(name = "db2SqlSessionFactory") + public SqlSessionFactory testSqlSessionFactory(@Qualifier("db2DataSource") DataSource dataSource) throws Exception { + SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); + bean.setDataSource(dataSource); + bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db2/*.xml")); + return bean.getObject(); + } + + @Bean(name = "db2TransactionManager") + public DataSourceTransactionManager testTransactionManager(@Qualifier("db2DataSource") DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + + @Bean(name = "db2SqlSessionTemplate") + public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("db2SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { + return new SqlSessionTemplate(sqlSessionFactory); + } +} diff --git a/src/main/java/com/example/config/Knife4jConfiguration.java b/src/main/java/com/example/config/Knife4jConfiguration.java new file mode 100644 index 0000000..5037cb6 --- /dev/null +++ b/src/main/java/com/example/config/Knife4jConfiguration.java @@ -0,0 +1,57 @@ +package com.example.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +import java.util.ArrayList; +import java.util.List; + + +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfiguration { + /** + * 需要配置controller层包名 + */ + String controllerPackagePath = "com.example"; + @Bean(value = "defaultApi2") + public Docket defaultApi2() { + List pars = new ArrayList<>(); + ParameterBuilder tokenPar = new ParameterBuilder(); + tokenPar.name("token") + .description("用户token") + .defaultValue("") + .modelRef(new ModelRef("string")) + .parameterType("header") + .required(false) + .build(); + pars.add(tokenPar.build()); + //添加head参数end + + Docket docket=new Docket(DocumentationType.SWAGGER_2) + .apiInfo(new ApiInfoBuilder() + //.title("swagger-bootstrap-ui-demo RESTful APIs") + .description("# swagger-bootstrap-ui-demo RESTful APIs") + .termsOfServiceUrl("www.codeleader.top") + .version("1.0") + .build()) + .globalOperationParameters(pars) + //分组名称 + .groupName("2.X版本") + .select() + //这里指定Controller扫描包路径 + .apis(RequestHandlerSelectors.basePackage(controllerPackagePath)) + .paths(PathSelectors.any()) + .build(); + return docket; + } +} diff --git a/src/main/java/com/example/controller/MedRecordController.java b/src/main/java/com/example/controller/MedRecordController.java new file mode 100644 index 0000000..4f08114 --- /dev/null +++ b/src/main/java/com/example/controller/MedRecordController.java @@ -0,0 +1,35 @@ +package com.example.controller; + +import com.example.service.MedicaRecordService; +import com.example.util.CommonResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @ClassName MedRecordController + * @Description 重耗材采集器接口 + * @Author linjj + * @Date 2025/3/25 16:45 + * @Version 1.0 + */ +@RestController +@RequestMapping("/task") +@Api(value = "重耗材任务接口", tags = "重耗材任务对外接口") +@Slf4j +public class MedRecordController { + + @Autowired + private MedicaRecordService medicaRecordService; + @PostMapping("/getTask") + @ApiOperation("获取任务接口") + @ResponseBody + public CommonResult GetTask() { + medicaRecordService.gatherMedicaRecord(); + return CommonResult.success("完成"); + } + +} diff --git a/src/main/java/com/example/db1/dao/ArchiveDetailDao.java b/src/main/java/com/example/db1/dao/ArchiveDetailDao.java new file mode 100644 index 0000000..76b4111 --- /dev/null +++ b/src/main/java/com/example/db1/dao/ArchiveDetailDao.java @@ -0,0 +1,55 @@ +package com.example.db1.dao; + +import com.example.dto.ArchiveDetailDto; +import com.example.vo.ArchiveDetailVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @InterfaceName ArchiveDetailDao + * @Description 操作文件表接口 + * @Author linjj + * @Date 2024/1/19 9:01 + * @Version 1.0 + */ +@Mapper +public interface ArchiveDetailDao { + /** + * @Author: linjj + * @Description: 批量插入文件表数据 + * @DateTime: 2025/3/25 14:56 + * @Params: [archiveDetailDto] + * @Return boolean + */ + boolean addArchiveDetailParam(@Param("list") List list); + + /** + * @Author: linjj + * @Description: 插入文件表数据 + * @DateTime: 2025/3/25 14:56 + * @Params: [archiveDetailDto] + * @Return boolean + */ + boolean addArchiveDetail(ArchiveDetailDto archiveDetailDto); + /** + * @Author: linjj + * @Description: 查询文件地址 + * @DateTime: 2025/3/26 16:34 + * @Params: [C2] + * @Return java.util.List + */ + List getPdfPath(String C1); + /** + * @Author: linjj + * @Description: 删除记录 + * @DateTime: 2025/3/26 16:37 + * @Params: [C1] + * @Return boolean + */ + boolean delPdfPath(String C1); + + + +} diff --git a/src/main/java/com/example/db1/dao/ArchiveMasterDao.java b/src/main/java/com/example/db1/dao/ArchiveMasterDao.java new file mode 100644 index 0000000..f08ad1b --- /dev/null +++ b/src/main/java/com/example/db1/dao/ArchiveMasterDao.java @@ -0,0 +1,27 @@ +package com.example.db1.dao; + +import com.example.vo.ArchiveDetailVo; +import com.example.vo.ArchiveMasterVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @InterfaceName ArchiveMasterDao + * @Description 患者基础信息查询sql + * @Author linjj + * @Date 2024/1/18 9:47 + * @Version 1.0 + */ +@Mapper +public interface ArchiveMasterDao { + /** + * @Author: linjj + * @Description: 根据记帐号住院次数查询患者是否存在归档数据库中 + * @DateTime: 2025/3/27 17:03 + * @Params: 、 + * @Return java.util.List + */ + List getMasterId(@Param("patientId")String patientId, @Param("visitId")String visitId); +} diff --git a/src/main/java/com/example/db1/dao/ArchiveOtherDao.java b/src/main/java/com/example/db1/dao/ArchiveOtherDao.java new file mode 100644 index 0000000..1f4760c --- /dev/null +++ b/src/main/java/com/example/db1/dao/ArchiveOtherDao.java @@ -0,0 +1,52 @@ +package com.example.db1.dao; + +import com.example.dto.ArchiveOtherExtDto; +import com.example.dto.UpdateOtherDao; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +/** + * @ClassName ArchiveOtherDao + * @Description 任务表接口 + * @Author linjj + * @Date 2025/3/26 15:13 + * @Version 1.0 + */ +@Mapper +public interface ArchiveOtherDao { + /** + * @Author: linjj + * @Description: 根据c2任务平台唯一判断是否存在 + * @DateTime: 2025/3/26 15:15 + * @Params: [C2] + * @Return java.util.List + */ + List getArchiveOtherExt(String C2); + /** + * @Author: linjj + * @Description: //查询任务表中C2字段跟时间是否都一致,一致不需要重新采集 + * @DateTime: 2025/3/27 17:29 + * @Params: [C2] + * @Return java.util.List + */ + List getArchiveOtherExtAndTime(@Param("C2")String C2, @Param("SycTime") Date SycTime); + /** + * @Author: linjj + * @Description: 新增任务表记录 + * @DateTime: 2025/3/26 15:29 + * @Params: [archiveOtherExtDto] + * @Return java.lang.Boolean + */ + Boolean addArchiveOtherExt(ArchiveOtherExtDto archiveOtherExtDto); + /** + * @Author: linjj + * @Description: 更新任务表 + * @DateTime: 2025/3/26 15:44 + * @Params: [updateOtherDao] + * @Return java.lang.Boolean + */ + Boolean updateArchiveOtherExt(UpdateOtherDao updateOtherDao); +} diff --git a/src/main/java/com/example/db2/dao/MedicaRecordDao.java b/src/main/java/com/example/db2/dao/MedicaRecordDao.java new file mode 100644 index 0000000..f05a8dc --- /dev/null +++ b/src/main/java/com/example/db2/dao/MedicaRecordDao.java @@ -0,0 +1,24 @@ +package com.example.db2.dao; + +import com.example.vo.MedicaRecordVo; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @ClassName MedicaRecordDao + * @Description 查询重耗材信息接口 + * @Author linjj + * @Date 2025/3/25 12:34 + * @Version 1.0 + */ +@Mapper +public interface MedicaRecordDao { + /** + * @Author: linjj + * @Description: 查询当天患者信息接口 + * @DateTime: 2025/3/25 12:36 + * @Return java.util.List + */ + List getMedicaRecord(); +} diff --git a/src/main/java/com/example/dto/ArchiveDetailDto.java b/src/main/java/com/example/dto/ArchiveDetailDto.java new file mode 100644 index 0000000..f65e7c1 --- /dev/null +++ b/src/main/java/com/example/dto/ArchiveDetailDto.java @@ -0,0 +1,34 @@ +package com.example.dto; + +import lombok.Data; + +import java.util.Date; + +/** + * @ClassName ArchiveDetailDto + * @Description 保存文件表记录dto + * @Author linjj + * @Date 2024/1/18 17:29 + * @Version 1.0 + */ +@Data +public class ArchiveDetailDto { + //文件id + private String id; + //文件路径 + private String pdfPath; + //病案id + private String masterId; + //生成时间 + private Date upLoadDateTime; + //分段id + private String assortId; + //来源 + private String source; + //文件名 + private String title; + private String flag; + private String sys; + //扩展字段存储平台唯一id + private String C1; +} diff --git a/src/main/java/com/example/dto/ArchiveMasterDto.java b/src/main/java/com/example/dto/ArchiveMasterDto.java new file mode 100644 index 0000000..2ba0e3a --- /dev/null +++ b/src/main/java/com/example/dto/ArchiveMasterDto.java @@ -0,0 +1,26 @@ +package com.example.dto; + +import lombok.Data; + +/** + * @ClassName ArchiveMasterVo + * @Description + * @Author linjj + * @Date 2024/1/18 9:33 + * @Version 1.0 + */ +@Data +public class ArchiveMasterDto { + //病案id + private String id; + //患者姓名 + private String name; + //住院次数 + private String visitId; + //住院号 + private String inpNo; + //入院时间 + private String admissionDateTime; + //出院时间 + private String dischargeDateTime; +} diff --git a/src/main/java/com/example/dto/ArchiveOtherExtDto.java b/src/main/java/com/example/dto/ArchiveOtherExtDto.java new file mode 100644 index 0000000..32b788b --- /dev/null +++ b/src/main/java/com/example/dto/ArchiveOtherExtDto.java @@ -0,0 +1,49 @@ +package com.example.dto; + +import lombok.Data; + +import java.math.BigInteger; +import java.util.Date; + +/** + * @ClassName ArchiveOtherExtDto + * @Description 任务表实体类 + * @Author linjj + * @Date 2025/3/26 15:07 + * @Version 1.0 + */ +@Data +public class ArchiveOtherExtDto { + //任务id + private String id; + //创建时间 + private Date SycTime; + //下载地址 + private String SycObj; + //默认0 + private BigInteger otherID; + //采集器标识重耗材21 + private BigInteger sysFlag; + //更新时间 + private Date sysUpdateTime; + //住院号 + private String jzh; + //开始时间 + private Date stime; + //结束时间 + private Date eTime; + //任务状态0为开始、2采集失败、3成功 + private BigInteger statusFlag; + //任务状态说明 + private String pResult; + //主键id + private String MID; + //文件id + private String DID; + //文件名 + private String C1; + //平台唯一id + private String C2; + + +} diff --git a/src/main/java/com/example/dto/UpdateOtherDao.java b/src/main/java/com/example/dto/UpdateOtherDao.java new file mode 100644 index 0000000..7d675a0 --- /dev/null +++ b/src/main/java/com/example/dto/UpdateOtherDao.java @@ -0,0 +1,34 @@ +package com.example.dto; + +import lombok.Data; + +import java.math.BigInteger; +import java.util.Date; + +/** + * @ClassName updateOtherDao + * @Description 更新任务表实体 + * @Author linjj + * @Date 2025/3/26 15:42 + * @Version 1.0 + */ +@Data +public class UpdateOtherDao { + //更新时间 + private Date sysUpdateTime; + //开始时间 + private Date stime; + //结束时间 + private Date eTime; + //任务状态0为开始、2采集失败、3成功 + private BigInteger statusFlag; + //任务状态说明 + private String pResult; + //文件名 + private String C1; + //平台唯一id + private String C2; + //文件id + private String DID; + +} diff --git a/src/main/java/com/example/quartz/ConsumablesQuartz.java b/src/main/java/com/example/quartz/ConsumablesQuartz.java new file mode 100644 index 0000000..41fe324 --- /dev/null +++ b/src/main/java/com/example/quartz/ConsumablesQuartz.java @@ -0,0 +1,25 @@ +package com.example.quartz; + +import com.example.service.MedicaRecordService; +import org.quartz.JobExecutionContext; +import org.springframework.scheduling.quartz.QuartzJobBean; + +import javax.annotation.Resource; + +/** + * @description: 高耗材定时任务采集 + * @author linjj + * @date: 2025/3/18 9:22 + */ +public class ConsumablesQuartz extends QuartzJobBean { + + + @Resource + private MedicaRecordService medicaRecordService; + + @Override + protected void executeInternal(JobExecutionContext jobExecutionContext) { + //根据试图中时间采集患者高耗材数据 + medicaRecordService.gatherMedicaRecord(); + } +} diff --git a/src/main/java/com/example/quartz/QuartzConfig.java b/src/main/java/com/example/quartz/QuartzConfig.java new file mode 100644 index 0000000..8e43fb5 --- /dev/null +++ b/src/main/java/com/example/quartz/QuartzConfig.java @@ -0,0 +1,46 @@ +package com.example.quartz; + +import org.quartz.*; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @ClassName QuartzConfig + * @Description + * @Author linjj + * @Date 2025/3/14 15:47 + * @Version 1.0 + */ +@Configuration +public class QuartzConfig { + + @Value("${quartzTime}") + private String quartzTime; + + + @Bean + public JobDetail teatQuartzDetail() { + + return JobBuilder.newJob(ConsumablesQuartz.class).withIdentity("ConsumablesQuartz").storeDurably().build(); + + } + + + + @Bean + public Trigger testQuartzTrigger() { + + return TriggerBuilder.newTrigger().forJob(teatQuartzDetail()) + + .withIdentity("ConsumablesQuartz") + .withSchedule(CronScheduleBuilder.cronSchedule(quartzTime)) + .build(); + + } + + + + + +} diff --git a/src/main/java/com/example/service/MedicaRecordService.java b/src/main/java/com/example/service/MedicaRecordService.java new file mode 100644 index 0000000..ca643e8 --- /dev/null +++ b/src/main/java/com/example/service/MedicaRecordService.java @@ -0,0 +1,18 @@ +package com.example.service; + +/** + * @ClassName MedicaRecordService + * @Description 重耗材采集接口 + * @Author linjj + * @Date 2025/3/25 12:55 + * @Version 1.0 + */ +public interface MedicaRecordService { + + /** + * @Author: linjj + * @Description: 轮询采集 + * @DateTime: 2025/3/25 12:58 + */ + void gatherMedicaRecord(); +} diff --git a/src/main/java/com/example/service/serviceImpl/MedicaRecordServiceImpl.java b/src/main/java/com/example/service/serviceImpl/MedicaRecordServiceImpl.java new file mode 100644 index 0000000..b2ffa96 --- /dev/null +++ b/src/main/java/com/example/service/serviceImpl/MedicaRecordServiceImpl.java @@ -0,0 +1,267 @@ +package com.example.service.serviceImpl; + + +import com.example.db1.dao.ArchiveDetailDao; +import com.example.db1.dao.ArchiveMasterDao; +import com.example.db1.dao.ArchiveOtherDao; +import com.example.db2.dao.MedicaRecordDao; +import com.example.dto.ArchiveDetailDto; +import com.example.dto.ArchiveOtherExtDto; +import com.example.dto.UpdateOtherDao; +import com.example.service.MedicaRecordService; +import com.example.vo.MedicaRecordVo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +/** + * @ClassName MedicaRecordServiceImpl + * @Description 重耗材采集实体类 + * @Author linjj + * @Date 2025/3/25 12:55 + * @Version 1.0 + */ +@Service +@Slf4j +public class MedicaRecordServiceImpl implements MedicaRecordService { + + @Autowired + private MedicaRecordDao medicaRecordDao; + @Autowired + private ArchiveMasterDao archiveMasterDao; + @Value("${savePath}") + private String savePath; + @Autowired + private ArchiveDetailDao archiveDetailDao; + @Autowired + private ArchiveOtherDao archiveOtherDao; + + @Override + public void gatherMedicaRecord() { + //根据时间段查询当前时间需要采集的患者信息 + List patientInfos = medicaRecordDao.getMedicaRecord(); + if (CollectionUtils.isEmpty(patientInfos)) { + log.info("当前时间段内无需要采集的数据"); + return; + } + log.info("当前时间需要采集:" + patientInfos.size() + "份重耗材"); + PollingGather(patientInfos); + } + /** + * @Author: linjj + * @Description: 轮询采集 + * @DateTime: 2025/3/25 14:45 + * @Params: [patientInfos] + * @Return void + */ + private void PollingGather(List patientInfos) { + //更新任务表 + UpdateOtherDao updateOtherDao=new UpdateOtherDao(); + //轮询采集 + for (MedicaRecordVo patientInfo : patientInfos) { + try { + //记帐号 + String medicaRecord = patientInfo.getMedicaRecord(); + //住院次数 + String visitId = patientInfo.getVisitId(); + //http下载地址 + String pdfPath = patientInfo.getPdfPath(); + //文件表 + ArchiveDetailDto archiveDetailDto = new ArchiveDetailDto(); + //任务表 + ArchiveOtherExtDto archiveOtherExtDto = new ArchiveOtherExtDto(); + //使用yyyyMMddHHmmssSSS格式作为文件名,文件id + Date date = new Date(); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String newDate = format.format(date); + //生成保存地址路径 + String newSavePath = GenerateSavePath(medicaRecord, visitId,newDate); + log.info("当前采集患者记帐号为:"+medicaRecord+",住院次数为:"+visitId); + //根据记帐号住院次数查询患者是否存在归档数据库中 + List masterIds = archiveMasterDao.getMasterId(medicaRecord, visitId); + if (CollectionUtils.isEmpty(masterIds)) { + log.info("当前采集患者基础信息不存在归档数据库中采集失败记帐号为:"+medicaRecord+",住院次数为:"+visitId); + continue; + } + //查询任务表中C2字段跟时间是否都一致,一致不需要重新采集 + List archiveOtherExtAndTime = archiveOtherDao.getArchiveOtherExtAndTime(patientInfo.getId(), patientInfo.getExportTime()); + if (!CollectionUtils.isEmpty(archiveOtherExtAndTime)){ + log.info("已经存在文件表跳过采集:"+medicaRecord+",住院次数为:"+visitId); + continue; + } + //查询任务表中c2字段是否已经存在,存在直接下载文件,不存在新增任务 + List archiveOtherExt = archiveOtherDao.getArchiveOtherExt(patientInfo.getId()); + if (CollectionUtils.isEmpty(archiveOtherExt)) { + archiveOtherExtDto.setId(newDate); + archiveOtherExtDto.setSycTime(patientInfo.getExportTime()); + archiveOtherExtDto.setSycObj(patientInfo.getPdfPath()); + archiveOtherExtDto.setOtherID(BigInteger.valueOf(0)); + archiveOtherExtDto.setSysFlag(BigInteger.valueOf(21)); + archiveOtherExtDto.setSysUpdateTime(new Date()); + archiveOtherExtDto.setJzh(medicaRecord); + archiveOtherExtDto.setStime(new Date()); + archiveOtherExtDto.setETime(new Date()); + archiveOtherExtDto.setStatusFlag(BigInteger.valueOf(0)); + archiveOtherExtDto.setPResult("未开始"); + archiveOtherExtDto.setMID(masterIds.get(0)); + archiveOtherExtDto.setC2(patientInfo.getId()); + archiveOtherDao.addArchiveOtherExt(archiveOtherExtDto); + } + updateDetail(patientInfo); + //下载图像 + if (!DownloadFile(pdfPath, newSavePath)){ + log.info("当前文件下载失败记帐号为:"+medicaRecord+",住院次数为:"+visitId); + failOther(updateOtherDao, patientInfo); + continue; + } + //下载成功保存文件表信息 + archiveDetailDto.setId(newDate); + archiveDetailDto.setPdfPath(newSavePath); + archiveDetailDto.setMasterId(masterIds.get(0)); + archiveDetailDto.setUpLoadDateTime(new Date()); + archiveDetailDto.setAssortId("61"); + archiveDetailDto.setSource("重耗材采集服务"); + archiveDetailDto.setFlag("0"); + archiveDetailDto.setSys("1"); + archiveDetailDto.setTitle("高价值耗材清单"); + archiveDetailDto.setC1(patientInfo.getId()); + //插入到文件表中 + if (!archiveDetailDao.addArchiveDetail(archiveDetailDto)){ + log.info("插入文件表失败,采集失败记帐号为:"+medicaRecord+",住院次数为:"+visitId); + } + log.info("插入文件表成功,采集成功记帐号为:"+medicaRecord+",住院次数为:"+visitId); + succeedOther(updateOtherDao, patientInfo, newDate); + } catch (Exception e) { + //下载失败更新任务表中任务状态 + failOther(updateOtherDao, patientInfo); + log.error("系统异常,下载失败记帐号为:"+patientInfo.getMedicaRecord()+",住院次数为:"+patientInfo.getVisitId()+"异常信息为:"+e.getMessage(),e); + } + } + } + + private void updateDetail(MedicaRecordVo patientInfo) { + //判断文件表是否有记录,有记录先删除后更新 + List pdfPathS = archiveDetailDao.getPdfPath(patientInfo.getId()); + if (!CollectionUtils.isEmpty(pdfPathS)) { + //不为空删除对应记录 + if (archiveDetailDao.delPdfPath(patientInfo.getId())){ + //删除对应文件 + for (String path:pdfPathS){ + File file1 = new File(path); + try { + file1.delete(); // 删除照片 + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + + /** + * @Author: linjj + * @Description: 成功任务更新任务表方法 + * @DateTime: 2025/3/26 16:07 + * @Params: [updateOtherDao, patientInfo, newDate] + * @Return void + */ + private void succeedOther(UpdateOtherDao updateOtherDao, MedicaRecordVo patientInfo, String newDate) { + //下载成功更新任务表中任务状态 + updateOtherDao.setSysUpdateTime(new Date()); + updateOtherDao.setStime(new Date()); + updateOtherDao.setETime(new Date()); + updateOtherDao.setStatusFlag(BigInteger.valueOf(3)); + updateOtherDao.setPResult("Done"); + updateOtherDao.setDID(newDate); + updateOtherDao.setC1(newDate +".pdf"); + updateOtherDao.setC2(patientInfo.getId()); + archiveOtherDao.updateArchiveOtherExt(updateOtherDao); + } + + /** + * @Author: linjj + * @Description: 失败任务更新任务表方法 + * @DateTime: 2025/3/26 16:07 + * @Params: [updateOtherDao, patientInfo] + * @Return void + */ + private void failOther(UpdateOtherDao updateOtherDao, MedicaRecordVo patientInfo) { + //下载失败更新任务表中任务状态 + updateOtherDao.setSysUpdateTime(new Date()); + updateOtherDao.setStime(new Date()); + updateOtherDao.setETime(new Date()); + updateOtherDao.setStatusFlag(BigInteger.valueOf(2)); + updateOtherDao.setPResult("文件下载失败"); + updateOtherDao.setC2(patientInfo.getId()); + archiveOtherDao.updateArchiveOtherExt(updateOtherDao); + } + + /** + * @Author: linjj + * @Description: 生成新的保存路径 + * @DateTime: 2025/3/25 13:58 + * @Params: [inpNo, visitId] + * @Return java.lang.String + */ + private String GenerateSavePath(String inpNo,String visitId,String newDate){ + //保存目录 + String saveDirectory=savePath+ File.separatorChar+inpNo+ File.separatorChar+visitId; + //保存地址 + String newSavePath=saveDirectory+File.separatorChar + newDate + ".pdf"; + // 检查目录是否存在,不存在则创建目录 + File directory = new File(saveDirectory); + if (!directory.exists()) { + boolean isCreated = directory.mkdirs(); // 创建所有必需的父目录 + if (!isCreated) { + // 处理创建目录失败的情况 + log.info("目录创建失败,下载失败记帐号为:"+inpNo+",住院次数为:"+visitId); + } + } + return newSavePath; + } + /** + * @Author: linjj + * @Description: 文件下载 + * @DateTime: 2025/3/25 14:50 + * @Params: [fileURL, savePath] + * @Return java.lang.Boolean + */ + private Boolean DownloadFile(String fileURL,String savePath) { + try { + CloseableHttpClient httpClient = HttpClients.createDefault(); + try (CloseableHttpResponse response = httpClient.execute(new HttpGet(fileURL))) { + HttpEntity entity = response.getEntity(); + try (InputStream in = entity.getContent(); + FileOutputStream fileOutputStream = new FileOutputStream(savePath)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + fileOutputStream.write(buffer, 0, bytesRead); + } + return true; + } + } + } catch (Exception e) { + log.error("文件下载失败"+e.getMessage(),e); + return false; + } + } +} diff --git a/src/main/java/com/example/text/test.java b/src/main/java/com/example/text/test.java new file mode 100644 index 0000000..143f90c --- /dev/null +++ b/src/main/java/com/example/text/test.java @@ -0,0 +1,42 @@ +package com.example.text; + +import com.example.MainApplication; +import com.example.service.MedicaRecordService; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +/** + * @ClassName test + * @Description 测试类 + * @Author linjj + * @Date 2024/1/18 9:54 + * @Version 1.0 + */ +@SpringBootTest(classes = MainApplication.class) +@RunWith(SpringRunner.class) +@Slf4j +public class test { + @Resource + private MedicaRecordService medicaRecordService; + @Value("${savePath}") + private String savePath; + + private final static Logger logger = LoggerFactory.getLogger(test.class); + + + @Test + public void testDemo() { + medicaRecordService.gatherMedicaRecord(); + + } +} diff --git a/src/main/java/com/example/util/BusinessException.java b/src/main/java/com/example/util/BusinessException.java new file mode 100644 index 0000000..b5dc39e --- /dev/null +++ b/src/main/java/com/example/util/BusinessException.java @@ -0,0 +1,26 @@ +package com.example.util; + + + +/** + * @description: 自定义的异常类 + * @author: ChenJ + * @date: 2022/5/9 17:29 + * @param: + * @return: + **/ +public class BusinessException extends Exception { + /** + * 枚举类型,内含状态码code和信息msg + */ + private final ExceptionCode exceptionCode; + + public ExceptionCode getExceptionCode() { + return exceptionCode; + } + + public BusinessException(ExceptionCode exceptionCode) { + super(exceptionCode.getMessage()); + this.exceptionCode = exceptionCode; + } +} diff --git a/src/main/java/com/example/util/CommonResult.java b/src/main/java/com/example/util/CommonResult.java new file mode 100644 index 0000000..c1cb0aa --- /dev/null +++ b/src/main/java/com/example/util/CommonResult.java @@ -0,0 +1,152 @@ +package com.example.util; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * + * @author docus + * @date 2020/3/28 16:23 + */ +@Data +@ApiModel("响应") +@AllArgsConstructor +@NoArgsConstructor +public class CommonResult { + @ApiModelProperty("响应码") + private Integer code; + @ApiModelProperty("响应消息") + private String msg; + @ApiModelProperty("响应实体") + private T data; + + public CommonResult(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult success(T data) { + return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult success(T data, String message) { + return new CommonResult(ResultCode.SUCCESS.getCode(), message, data); + } + + /** + * 失败返回结果 + * + * @param errorCode 错误码 + * @param + * @return + */ + public static CommonResult failed(IErrorCode errorCode) { + return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null); + } + + /** + * 失败返回结果 + * + * @param errorCode 错误码 + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult failed(IErrorCode errorCode, String message) { + return new CommonResult(errorCode.getCode(), message, null); + } + + /** + * 失败返回结果 + * + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult failed(String message) { + return new CommonResult(ResultCode.FAILED.getCode(), message, null); + } + + + /** + * 失败返回结果 + * + * @param + * @return + */ + public static CommonResult failed() { + return failed(ResultCode.FAILED); + } + + /** + * 参数验证失败返回结果 + * + * @param + * @return + */ + public static CommonResult validateFailed() { + return failed(ResultCode.VALIDATE_FAILED); + } + + /** + * 提示信息 + * + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult validateFailed(String message) { + return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null); + } + + /** + * 未登录返回结果 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult unauthorized(T data) { + return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); + } + + /** + * 重防及重复请求 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult preventreplay(T data) { + return new CommonResult(ResultCode.PREVENT_REPLAY.getCode(), ResultCode.PREVENT_REPLAY.getMessage(), data); + } + + /** + * 未授权返回结果 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult forbidden(T data) { + return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); + } +} diff --git a/src/main/java/com/example/util/ExceptionCode.java b/src/main/java/com/example/util/ExceptionCode.java new file mode 100644 index 0000000..343a4ab --- /dev/null +++ b/src/main/java/com/example/util/ExceptionCode.java @@ -0,0 +1,26 @@ +package com.example.util; + + +public enum ExceptionCode { + /** + * 服务器开小差了,请稍后再试 + */ + WRONG_PARAMS("参数不对", 1001); + + + private final String message; + private final Integer code; + + ExceptionCode(String message, int code) { + this.message = message; + this.code = code; + } + + public String getMessage() { + return message; + } + + public Integer getCode() { + return code; + } +} diff --git a/src/main/java/com/example/util/IErrorCode.java b/src/main/java/com/example/util/IErrorCode.java new file mode 100644 index 0000000..62543f7 --- /dev/null +++ b/src/main/java/com/example/util/IErrorCode.java @@ -0,0 +1,12 @@ +package com.example.util; + +/** + * @Description 封装API的错误码 + * @Author JacksonTu + * @Date 2020/3/28 16:26 + */ +public interface IErrorCode { + Integer getCode(); + + String getMessage(); +} diff --git a/src/main/java/com/example/util/JsonResult.java b/src/main/java/com/example/util/JsonResult.java new file mode 100644 index 0000000..2f1223b --- /dev/null +++ b/src/main/java/com/example/util/JsonResult.java @@ -0,0 +1,51 @@ +package com.example.util; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * 这是一个给fastJSON/jackson准备的一个对象 + */ +public class JsonResult implements Serializable { + private Map dataMap = new HashMap<>(3); + + public JsonResult() { + } + + public String getCode() { + return dataMap.get("code").toString(); + } + + public void setCode(String code) { + this.dataMap.put("code", code); + } + + public String getMsg() { + return dataMap.get("msg").toString(); + } + + public void setMsg(String msg) { + this.dataMap.put("msg", msg); + } + + public Object getData() { + return dataMap.get("data"); + } + + public void setData(Object data) { + this.dataMap.put("data", data); + } + + public Map getDataMap() { + return dataMap; + } + + public void setDataMap(Map dataMap) { + this.dataMap = dataMap; + } + + public void put(String name, Object value) { + this.dataMap.put(name, value); + } +} diff --git a/src/main/java/com/example/util/Msg.java b/src/main/java/com/example/util/Msg.java new file mode 100644 index 0000000..6f898fc --- /dev/null +++ b/src/main/java/com/example/util/Msg.java @@ -0,0 +1,71 @@ +/** + * + */ +package com.example.util; + +import java.util.HashMap; +import java.util.Map; + +/** + *

Title:Msg

+ *

Description:common return class

+ *

Company:

+ * @author hu + * @date + */ +public class Msg { + //state:100-success 200-fail + private int code; + //提示信息 + private String msg; + //用户要返回给浏览器的数据 + private Map extend=new HashMap(); + + + + public static Msg fail(String msg){ + Msg result=new Msg(); + result.setCode(100); + result.setMsg(msg); + return result; + } + + + public static Msg success(String msg){ + Msg result=new Msg(); + result.setCode(200); + result.setMsg(msg); + return result; + } + + public Msg add(String key, Object value){ + this.getExtend().put(key, value); + return this; + } + + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public Map getExtend() { + return extend; + } + + public void setExtend(Map extend) { + this.extend = extend; + } + +} diff --git a/src/main/java/com/example/util/ResultCode.java b/src/main/java/com/example/util/ResultCode.java new file mode 100644 index 0000000..f12a66a --- /dev/null +++ b/src/main/java/com/example/util/ResultCode.java @@ -0,0 +1,42 @@ +package com.example.util; + + +/** + * @Description 枚举一些常用API操作码 + * @Author JacksonTu + * @Date 2020/3/28 16:26 + */ +public enum ResultCode implements IErrorCode { + + SUCCESS(0, "操作成功"), + FAILED(500, "操作失败"), + VALIDATE_FAILED(404, "参数检验失败"), + UNAUTHORIZED(401, "暂未登录或token已经过期"), + FORBIDDEN(403, "没有相关权限"), + PREVENT_REPLAY(405,"重复请求"), + NOT_EXIST(601,"数据不存在"), + NOT_ENABLE(600,"数据未启用"); + + + + + private Integer code; + private String message; + + private ResultCode(Integer code, String message) { + this.code = code; + this.message = message; + } + + @Override + public Integer getCode() { + return code; + } + + @Override + public String getMessage() { + return message; + } + + +} diff --git a/src/main/java/com/example/vo/ArchiveDetailVo.java b/src/main/java/com/example/vo/ArchiveDetailVo.java new file mode 100644 index 0000000..d2d03b0 --- /dev/null +++ b/src/main/java/com/example/vo/ArchiveDetailVo.java @@ -0,0 +1,18 @@ +package com.example.vo; + +import lombok.Data; + +/** + * @ClassName Archive_detail + * @Author linjj + * @Date 2024/3/10 20:59 + * @Version 1.0 + */ +@Data +public class ArchiveDetailVo { + + private String id; + + private String pdfPath; + +} diff --git a/src/main/java/com/example/vo/ArchiveMasterVo.java b/src/main/java/com/example/vo/ArchiveMasterVo.java new file mode 100644 index 0000000..a97ff29 --- /dev/null +++ b/src/main/java/com/example/vo/ArchiveMasterVo.java @@ -0,0 +1,30 @@ +package com.example.vo; + +import lombok.Data; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @ClassName ArchiveMasterVo + * @Description + * @Author linjj + * @Date 2024/1/18 9:33 + * @Version 1.0 + */ +@Data +public class ArchiveMasterVo { + + //病案id + private String id; + //患者姓名 + private String name; + //住院次数 + private String visitId; + //住院号 + private String inpNo; + //入院时间 + private String admissionDateTime; + //出院时间 + private String dischargeDateTime; + //记帐号 + private String patientId; +} diff --git a/src/main/java/com/example/vo/MedicaRecordVo.java b/src/main/java/com/example/vo/MedicaRecordVo.java new file mode 100644 index 0000000..3d73eb7 --- /dev/null +++ b/src/main/java/com/example/vo/MedicaRecordVo.java @@ -0,0 +1,30 @@ +package com.example.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +/** + * @ClassName MedicaRecordVo + * @Author linjj + * @Date 2025/3/25 12:03 + * @Version 1.0 + */ +@Data +@TableName("v_select_medica_record") +public class MedicaRecordVo { + private String id; + //记帐号 + private String medicaRecord; + //住院次数 + private String visitId; + //患者姓名 + private String patientName; + //导出时间 + private Date exportTime; + //pdf下载地址 + private String pdfPath; + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..da19d9b --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,17 @@ +server.port=3397 + +# SQL Server ????? +spring.datasource.hikari.db1.jdbc-url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=DB_PrivilegeManagement_GYFY +spring.datasource.hikari.db1.username=sa +spring.datasource.hikari.db1.password=docus@702 +spring.datasource.hikari.db1.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver + +# MySQL?? +spring.datasource.hikari.db2.jdbc-url=jdbc:mysql://10.6.3.80:3306/gzykd_spd +spring.datasource.hikari.db2.username=baxt +spring.datasource.hikari.db2.password=123456 +spring.datasource.hikari.db2.driver-class-name=com.mysql.cj.jdbc.Driver + +# MyBatis-Plus ?? +mybatis-plus.mapper-locations=classpath:mapper/db1/*.xml,classpath:mapper/db2/*.xml +mybatis-plus.type-aliases-package=com.example.vo \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..6b69383 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,4 @@ +#文件保存路径 +savePath: Z:\Consumables\reload +#定时补偿任务时间 +quartzTime: 0 0/30 * * * ? diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..f162fd5 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,42 @@ + + + logback + + + + + %d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + true + + + consumables_zj/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log + + + + + %d{yyyy-MM-dd HH:mm:ss} -%msg%n + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/db1/ArchiveDetailrMapper.xml b/src/main/resources/mapper/db1/ArchiveDetailrMapper.xml new file mode 100644 index 0000000..a8d2b3d --- /dev/null +++ b/src/main/resources/mapper/db1/ArchiveDetailrMapper.xml @@ -0,0 +1,31 @@ + + + + + + + insert into archive_detail(ID, PDF_PATH, MasterID, UpLoadDateTime, AssortID, Source, Title, flag, Sys,C1) + values (#{id}, #{pdfPath}, #{masterId}, #{upLoadDateTime}, #{assortId}, + #{source}, + #{title}, #{flag}, #{sys}, #{C1}) + + + insert into + archive_detail(id,PDF_PATH,MasterID,UpLoadDateTime,AssortID,Source,Title,flag,Sys,C1 + ) + values + + (replace(newid(), '-', ''),#{item.pdfPath},#{item.masterId},#{item.uploadDateTime},#{item.assortId},#{item.source}, + #{item.title},#{item.flag},#{item.sys}) + + + + delete from archive_detail + where c1 = #{C1} AND AssortID='61' + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/db1/ArchiveMasterMapper.xml b/src/main/resources/mapper/db1/ArchiveMasterMapper.xml new file mode 100644 index 0000000..36e2510 --- /dev/null +++ b/src/main/resources/mapper/db1/ArchiveMasterMapper.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/db1/ArchiveOtherDao.xml b/src/main/resources/mapper/db1/ArchiveOtherDao.xml new file mode 100644 index 0000000..24d839e --- /dev/null +++ b/src/main/resources/mapper/db1/ArchiveOtherDao.xml @@ -0,0 +1,46 @@ + + + + + + insert into archive_other_ext(ID, SycTime, SycObj, otherID, sysFlag, sysUpdateTime, jzh, stime, eTime,statusFlag,pResult,MID,C2) + values (#{id}, #{SycTime}, #{SycObj}, #{otherID}, #{sysFlag}, + #{sysUpdateTime},#{jzh}, #{stime}, #{eTime}, #{statusFlag}, #{pResult}, #{MID}, #{C2}) + + + update archive_other_ext + + + sysUpdateTime = #{sysUpdateTime}, + + + stime = #{stime}, + + + eTime = #{eTime}, + + + statusFlag = #{statusFlag}, + + + pResult = #{pResult}, + + + C1 = #{C1}, + + + DID = #{DID}, + + + where C2 = #{C2} + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/db2/MedicaRecordDao.xml b/src/main/resources/mapper/db2/MedicaRecordDao.xml new file mode 100644 index 0000000..a0e4d63 --- /dev/null +++ b/src/main/resources/mapper/db2/MedicaRecordDao.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file