From 9bb1937982f5578d619c77486212efd145e0c0be Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Thu, 6 Jun 2024 17:53:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=B8=AD=E5=BF=83=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 58 +++++ pom.xml | 245 ++++++++++++++++++ .../ResourceCenterApplication.java | 15 ++ .../resource_center/util/file/IFileUtil.java | 87 +++++++ .../util/file/LocalFileUtil.java | 176 +++++++++++++ src/main/resources/application-dev.yml | 26 ++ src/main/resources/application-pro.yml | 28 ++ src/main/resources/application.yml | 85 ++++++ src/main/resources/generatorConfig.xml | 47 ++++ src/main/resources/logback-spring.xml | 79 ++++++ 10 files changed, 846 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/sztzjy/resource_center/ResourceCenterApplication.java create mode 100644 src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java create mode 100644 src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-pro.yml create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/generatorConfig.xml create mode 100644 src/main/resources/logback-spring.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2371a3b --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +# ignore these folders +target/ +.idea/ +.settings/ +.vscode/ +bin/ +out/ + +# ignore these files +.classpath +.project +.settings +.idea + +# filter databfile、sln file +*.mdb +*.ldb +*.sln + +# class file +*.com +*.class +*.dll +*.exe +*.o +*.so + +# compression file +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip +*.via +*.tmp +*.err +*.log +*.iml + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +Icon? +ehthumbs.db +Thumbs.db +.factorypath +.mvn/ +mvnw.cmd +mvnw + +# Files or folders need to be retained +# ... \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f115ca6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,245 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.12 + + + + org.sztzjy + resource_center + 1.0-SNAPSHOT + resource_center + resource_center + + + 1.8 + 0.10.8 + UTF-8 + UTF-8 + + + + org.apache.poi + poi + 3.15-beta2 + + + org.apache.poi + poi-ooxml + 3.15-beta2 + + + com.itextpdf + itextpdf + 5.5.13 + + + com.itextpdf + itext-asian + 5.2.0 + + + org.springframework.boot + spring-boot-starter + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.0.0 + + + + org.springframework.boot + spring-boot-starter-data-redis + 2.7.12 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + + org.mybatis.generator + mybatis-generator-core + 1.4.0 + + + + org.springframework.boot + spring-boot-starter-test + test + + + cn.hutool + hutool-all + 5.8.10 + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.security + spring-security-jwt + 1.1.1.RELEASE + + + + org.springframework.boot + spring-boot-starter-security + + + + com.nimbusds + nimbus-jose-jwt + 9.26 + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.alibaba + druid-spring-boot-starter + 1.2.18 + + + + com.github.xiaoymin + knife4j-spring-boot-starter + 3.0.3 + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.security.oauth + spring-security-oauth2 + 2.3.8.RELEASE + + + org.projectlombok + lombok + + + org.hibernate + hibernate-spatial + 5.4.29.Final + + + mysql-connector-java + mysql + + + + + + mysql + mysql-connector-java + 8.0.32 + + + + io.jsonwebtoken + jjwt-api + ${jjwt.version} + + + io.jsonwebtoken + jjwt-impl + ${jjwt.version} + runtime + + + io.jsonwebtoken + jjwt-jackson + ${jjwt.version} + runtime + + + com.alibaba + fastjson + 1.2.47 + + + org.apache.httpcomponents + httpclient + 4.5.14 + + + com.github.ben-manes.caffeine + caffeine + 2.9.3 + + + org.springframework + spring-test + 5.3.14 + + + + com.alibaba + easyexcel + 3.2.1 + + + + org.python + jython-standalone + 2.7.2 + + + + + org.xhtmlrenderer + flying-saucer-pdf + 9.1.22 + + + + org.xhtmlrenderer + flying-saucer-pdf-itext5 + 9.1.22 + + + + + org.lionsoul + ip2region + 2.6.5 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + diff --git a/src/main/java/com/sztzjy/resource_center/ResourceCenterApplication.java b/src/main/java/com/sztzjy/resource_center/ResourceCenterApplication.java new file mode 100644 index 0000000..89b955a --- /dev/null +++ b/src/main/java/com/sztzjy/resource_center/ResourceCenterApplication.java @@ -0,0 +1,15 @@ +package com.sztzjy.resource_center; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@EnableScheduling +public class ResourceCenterApplication { + + public static void main(String[] args) { + SpringApplication.run(ResourceCenterApplication.class, args); + } + +} diff --git a/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java b/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java new file mode 100644 index 0000000..afe9aae --- /dev/null +++ b/src/main/java/com/sztzjy/resource_center/util/file/IFileUtil.java @@ -0,0 +1,87 @@ +package com.sztzjy.resource_center.util.file; + + +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; + +/** + * 文件上传下载接口定义 + * + * @author 陈沅 + */ +public interface IFileUtil { + + + + /** + * 从http请求上传文件 + * + * @param file form传参http文件对象 + * @return 返回文件在服务器上保存的相对路径 + */ + String upload(MultipartFile file); + + /** + * 根据文件流上传文件 + * + * @param objectName 指定文件名(带扩展名) + * @param fileIn 文件流 + * @return 返回文件在服务器上保存的相对路径 + */ + String upload(String objectName, InputStream fileIn); + + /** + * 删除服务器上的一个文件 + * + * @param path 文件在服务器上保存的相对路径 + * @return 返回true则表示删除成功 + */ + boolean remove(String path); + + /** + * 下载文件流,指定文件名 + * + * @param response + * @param fileName 指定下载文件名称 + * @param filePath 文件保存的相对路径 + */ + void download(HttpServletResponse response, String fileName, String filePath); + + /** + * 下载文件流,不指定文件名 + * + * @param response + * @param filePath 文件保存的相对路径 + */ + void download(HttpServletResponse response, String filePath); + + /** + * 相对路径 + * + * @param relativePath 文件保存的相对路径 + * @return 文件保存的绝对路径 + */ + String getFullPath(String relativePath); + + + /** + * 获取文件后缀名 + * + * @param fileName 文件名称 + * @return suffix + */ + String getSuffix(String fileName); + + + /** + * 获取文件存储至磁盘的相对路径 + * + * @param fileName 文件名 + * @param suffix 动态拼接的文件后缀,若该值为空则不拼接 + * @return 相对路径 + */ + String getDiskRelativePath(String fileName, String suffix); + +} diff --git a/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java b/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java new file mode 100644 index 0000000..65af9cd --- /dev/null +++ b/src/main/java/com/sztzjy/resource_center/util/file/LocalFileUtil.java @@ -0,0 +1,176 @@ +package com.sztzjy.resource_center.util.file; + +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.IdUtil; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +public class LocalFileUtil implements IFileUtil{ + + private final static List excludeSp = Arrays.asList("exe", "bin", "sh"); + + private final String localPath; + + public LocalFileUtil(String localPath) { + this.localPath = localPath; + } + + @Override + public String upload(MultipartFile file) { + return upload(null, file); + } + + @Override + public String upload(String objectName, InputStream fileIn) { + Assert.notNull(fileIn, "文件不能为空"); + Assert.hasText(objectName, "文件名为空"); + Assert.isTrue(objectName.lastIndexOf(".") > 0, "文件名称需携带扩展后缀"); + FileOutputStream out = null; + try { + String relativePath = getDiskRelativePath(objectName, null); + File file = new File(getFullPath(relativePath)); + file.getParentFile().mkdirs(); + out = new FileOutputStream(file); + byte[] buff = new byte[4096]; + int len; + while ((len = fileIn.read(buff)) != -1) { + out.write(buff, 0, len); + } + out.flush(); + return relativePath; + } catch (IOException e) { + e.printStackTrace(); + throw new IllegalArgumentException("上传文件失败,IO错误"); + } finally { + try { + fileIn.close(); + if (out != null) out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + public boolean remove(String path) { + if (!StringUtils.hasText(path)) return false; + File file = new File(getFullPath(path)); + if (!file.exists()) return false; + return file.delete(); + } + + @Override + public void download(HttpServletResponse response, String fileName, String relativePath) { + Assert.hasText(relativePath, "路径为空"); + System.out.println("------------------------------------" + getFullPath(relativePath)); + File file = new File(getFullPath(relativePath)); + Assert.isTrue(file.exists(), "附件不存在"); + String sp = relativePath.substring(relativePath.lastIndexOf(".") + 1); + Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误"); + if (!StringUtils.hasText(fileName)) { + fileName = file.getName().substring(0, file.getName().lastIndexOf(".")); + } + InputStream fis = null; + try { + response.setContentType("application/octet-stream"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode((fileName + "." + sp), CharsetUtil.UTF_8)); + fis = new BufferedInputStream(Files.newInputStream(file.toPath())); + response.addHeader("Content-Length", String.valueOf(fis.available())); + byte[] buff = new byte[4096]; + int len; + while ((len = fis.read(buff)) != -1) { + response.getOutputStream().write(buff, 0, len); + } + } catch (Exception e) { + throw new IllegalArgumentException("下载文件失败: " + e.getMessage()); + } finally { + try { + if (fis != null) fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + public void download(HttpServletResponse response, String relativePath) { + download(response, null, relativePath); + } + + @Override + public String getFullPath(String relativePath) { + if (!relativePath.startsWith("/")) { + relativePath = "/" + relativePath; + } + return localPath + relativePath; + } + + @Override + public String getSuffix(String fileName) { + Assert.hasText(fileName, "文件名不存在!"); + if (fileName.lastIndexOf(".") < 0) { + return null; + } + return fileName.substring(fileName.lastIndexOf(".") + 1); + } + + public String upload(String fileName, MultipartFile file) { + return upload(fileName, file, null); + } + + + @Override + public String getDiskRelativePath(String fileName, String suffix) { + Calendar c = Calendar.getInstance(); + Date d = new Date(); + c.setTime(d); + String year = Integer.toString(c.get(Calendar.YEAR)); + String month = Integer.toString(c.get(Calendar.MONTH) + 1); + String day = Integer.toString(c.get(Calendar.DATE)); + StringBuilder path = new StringBuilder(); + path.append("/").append(year) + .append("/").append(month) + .append("/").append(day) + .append("/").append(fileName); + if (StringUtils.hasText(suffix)) path.append(".").append(suffix); + return path.toString(); + } + + + private String upload(String fileName, MultipartFile file, String relativePath) { + Assert.isTrue(!file.isEmpty(), "文件不存在"); + String originalFilename = file.getOriginalFilename(); + if (fileName == null) fileName = IdUtil.simpleUUID(); + String sp = getSuffix(originalFilename); + Assert.notNull(sp, "文件类型错误"); + Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误"); + try { + String filePath; + if (relativePath == null) { + filePath = getDiskRelativePath(fileName, sp); + } else { + relativePath = relativePath.endsWith("/") ? relativePath : relativePath + "/"; + filePath = relativePath + fileName + "." + sp; + } + + File destFile = new File(getFullPath(filePath)); + destFile.getParentFile().mkdirs(); + file.transferTo(destFile); + return filePath; + } catch (FileNotFoundException e) { + throw new IllegalArgumentException("上传文件失败,FileNotFound错误"); + } catch (IOException e) { + throw new IllegalArgumentException("上传文件失败,IO错误"); + } + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..c1f1a9c --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,26 @@ +spring: + datasource: + druid: + db-type: mysql + url: jdbc:mysql://${DB_HOST:118.31.7.2}:${DB_PORT:3306}/${DB_NAME:resource_center}?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true + username: ${DB_USER:root} + password: ${DB_PWD:sztzjy2017} + driver-class-name: com.mysql.cj.jdbc.Driver + + +# 文件存储 +file: + type: local +# path: /usr/local/tianzeProject/financial_bigdata/uploadFile + path: D:/home +timer: + enable: false + +swagger: + enable: true + tokenHeader: Authorization + title: 天择外汇模拟交易 • 接口文档 + description: 天择外汇模拟交易WebAPI接口文档 + contactName: 深圳天择教育科技有限公司 + contactAddress: www.sztzjy.com + version: @project.version@ \ No newline at end of file diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml new file mode 100644 index 0000000..a7b13f5 --- /dev/null +++ b/src/main/resources/application-pro.yml @@ -0,0 +1,28 @@ +#天金融大数据 +spring: + datasource: + druid: + db-type: mysql + url: jdbc:mysql://${DB_HOST:120.78.220.29}:${DB_PORT:3307}/${DB_NAME:financial_bigdata}?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true + username: ${DB_USER:root} + password: ${DB_PWD:sztzjy2017} + driver-class-name: com.mysql.cj.jdbc.Driver + + +# 文件存储 +file: + type: local + path: /usr/local/tianzeProject/financial_bigdata/uploadFile + + +timer: + enable: false + +swagger: + enable: true + tokenHeader: Authorization + title: 天择外汇模拟交易 • 接口文档 + description: 天择外汇模拟交易WebAPI接口文档 + contactName: 深圳天择教育科技有限公司 + contactAddress: www.sztzjy.com + version: @project.version@ \ 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..cf7cba8 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,85 @@ +server: + port: 8889 + servlet: + context-path: / + tomcat: + relaxedQueryChars: <,>, [,],^,`,{,|,} + +spring: + servlet: + multipart: + max-file-size: 50MB + max-request-size: 50MB + application: + name: trading_system + profiles: + active: dev + mvc: + pathmatch: + matching-strategy: ant_path_matcher + jackson: + time-zone: GMT+8 + redis: + host: localhost + port: 6379 + database: 0 +# spring.redis.pool.max-active=8 +# # 连接池最大阻塞等待时间(使用负值表示没有限制) +# spring.redis.pool.max-wait=-1 +# # 连接池中的最大空闲连接 +# spring.redis.pool.max-idle=8 +# # 连接池中的最小空闲连接 +# spring.redis.pool.min-idle=0 +# # 连接超时时间(毫秒) +# spring.redis.timeout=0 + datasource: + druid: + # 初始连接数 + initial-size: 5 + # 最小连接数 + min-idle: 15 + # 最大连接数 + max-active: 500 + # 获取连接超时时间 + max-wait: 5000 + # 连接有效性检测时间 + time-between-eviction-runs-millis: 60000 + # 连接在池中最小生存的时间 + min-evictable-idle-time-millis: 300000 + # 连接在池中最大生存的时间 + max-evictable-idle-time-millis: 900000 + # 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除 + test-while-idle: true + # 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个 + test-on-borrow: false + # 是否在归还到池中前进行检验 + test-on-return: false + # 检测连接是否有效 + validation-query: select 'X' + # 配置监控统计 + webStatFilter: + enabled: true + stat-view-servlet: + allow: + enabled: true + # 控制台管理用户名和密码 + url-pattern: /druid/* + reset-enable: false + login-username: admin + login-password: 2023 + filter: + stat: + enabled: true + # 记录慢SQL + log-slow-sql: false + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true + +mybatis: + type-aliases-package: com.sztzjy.financial_bigdata.entity + mapper-locations: classpath*:/mapper/*.xml + + diff --git a/src/main/resources/generatorConfig.xml b/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..6445391 --- /dev/null +++ b/src/main/resources/generatorConfig.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..8dca66a --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,79 @@ + + + + + + + + + + ${SERVER_NAME} + + + + + + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + + + ERROR + + DENY + + ACCEPT + + + + ${log.pattern} + UTF-8 + + + + ${LOG_HOME}/info/%d{yyyy年MM月dd日} - info.log + 90 + + + + + + + ERROR + + + + ${log.pattern} + UTF-8 + + + + ${LOG_HOME}/error/%d{yyyy年MM月dd日} - error.log + 90 + + + + + + + + + +