修改启动报错

newBigdata
yz 1 year ago
parent 43d5147cf5
commit 3be6c249eb

@ -2,7 +2,9 @@ package com.sztzjy.financial_bigdata;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication @SpringBootApplication
public class FinancialBigDataApplication { public class FinancialBigDataApplication {

@ -1,7 +1,7 @@
package com.sztzjy.financial_bigdata.config.security; package com.sztzjy.financial_bigdata.config.security;
import com.sztzjy.financial_bigdata.util.file.IFileUtil; //import com.sztzjy.financial_bigdata.util.file.IFileUtil;
import com.sztzjy.financial_bigdata.util.file.LocalFileUtil; //import com.sztzjy.financial_bigdata.util.file.LocalFileUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -67,12 +67,12 @@ public class WebConfigurerAdapter implements WebMvcConfigurer {
} }
} }
@Bean // @Bean
public IFileUtil getFileUtil() { // public IFileUtil getFileUtil() {
if (fileType.equals("local")) { // if (fileType.equals("local")) {
return new LocalFileUtil(filePath); // return new LocalFileUtil(filePath);
} else { // } else {
throw new IllegalArgumentException("未知文件工具类注入类型"); // throw new IllegalArgumentException("未知文件工具类注入类型");
} // }
} // }
} }

@ -1,65 +1,65 @@
package com.sztzjy.financial_bigdata.util; //package com.sztzjy.financial_bigdata.util;
//
import cn.hutool.core.util.IdUtil; //import cn.hutool.core.util.IdUtil;
import com.sztzjy.financial_bigdata.util.file.LocalFileUtil; //import com.sztzjy.financial_bigdata.util.file.LocalFileUtil;
import com.sztzjy.financial_bigdata.util.seal.SealCircle; //import com.sztzjy.financial_bigdata.util.seal.SealCircle;
import com.sztzjy.financial_bigdata.util.seal.SealFont; //import com.sztzjy.financial_bigdata.util.seal.SealFont;
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import javax.annotation.Resource; //import javax.annotation.Resource;
import java.io.File; //import java.io.File;
//
/** ///**
* @author 17803 // * @author 17803
* @date 2023-12-05 15:11 // * @date 2023-12-05 15:11
*/ // */
//
@Component //@Component
public class SealUtil { //public class SealUtil {
//
@Resource // @Resource
LocalFileUtil localFileUtil; // LocalFileUtil localFileUtil;
//
@Value("${file.path}") // @Value("${file.path}")
private String filePath; // private String filePath;
//
public String genertSealB(String name) throws Exception{ // public String genertSealB(String name) throws Exception{
String file = filePath+"/seal/"; // String file = filePath+"/seal/";
// 创建 File 对象 // // 创建 File 对象
File infoFile = new File(file); // File infoFile = new File(file);
if (!infoFile.exists()) { // if (!infoFile.exists()) {
infoFile.mkdir(); // infoFile.mkdir();
} // }
String s = IdUtil.fastSimpleUUID(); // String s = IdUtil.fastSimpleUUID();
com.sztzjy.financial_bigdata.util.seal.SealUtil.builder() // com.sztzjy.financial_bigdata.util.seal.SealUtil.builder()
.size(200) // .size(200)
.borderCircle(SealCircle.builder().line(4).width(95).height(95).build()) // .borderCircle(SealCircle.builder().line(4).width(95).height(95).build())
.mainFont(SealFont.builder().text(name+"有限公司").size(22).space(30.0).margin(4).build()) // .mainFont(SealFont.builder().text(name+"有限公司").size(22).space(30.0).margin(4).build())
.centerFont(SealFont.builder().text("★").size(60).build()) // .centerFont(SealFont.builder().text("★").size(60).build())
.titleFont(SealFont.builder().text("电子签章").size(16).space(8.0).margin(54).build()) // .titleFont(SealFont.builder().text("电子签章").size(16).space(8.0).margin(54).build())
.build() // .build()
.draw(filePath+"/seal/"+ s +".png"); // .draw(filePath+"/seal/"+ s +".png");
System.out.println(name+"公章已生成"); // System.out.println(name+"公章已生成");
return s; // return s;
} // }
public String genertSealA(String name) throws Exception{ // public String genertSealA(String name) throws Exception{
String file = filePath+"/seal/"; // String file = filePath+"/seal/";
// 创建 File 对象 // // 创建 File 对象
File infoFile = new File(file); // File infoFile = new File(file);
if (!infoFile.exists()) { // if (!infoFile.exists()) {
infoFile.mkdir(); // infoFile.mkdir();
} // }
String s = IdUtil.fastSimpleUUID(); // String s = IdUtil.fastSimpleUUID();
com.sztzjy.financial_bigdata.util.seal.SealUtil.builder() // com.sztzjy.financial_bigdata.util.seal.SealUtil.builder()
.size(200) // .size(200)
.borderCircle(SealCircle.builder().line(4).width(95).height(95).build()) // .borderCircle(SealCircle.builder().line(4).width(95).height(95).build())
.mainFont(SealFont.builder().text(name).size(22).space(30.0).margin(4).build()) // .mainFont(SealFont.builder().text(name).size(22).space(30.0).margin(4).build())
.centerFont(SealFont.builder().text("★").size(60).build()) // .centerFont(SealFont.builder().text("★").size(60).build())
.titleFont(SealFont.builder().text("电子签章").size(16).space(8.0).margin(54).build()) // .titleFont(SealFont.builder().text("电子签章").size(16).space(8.0).margin(54).build())
.build() // .build()
.draw(filePath+"/seal/"+ s +".png"); // .draw(filePath+"/seal/"+ s +".png");
System.out.println(name+"公章已生成"); // System.out.println(name+"公章已生成");
return s; // return s;
} // }
} //}

@ -1,87 +1,87 @@
package com.sztzjy.financial_bigdata.util.file; //package com.sztzjy.financial_bigdata.util.file;
//
//
import org.springframework.web.multipart.MultipartFile; //import org.springframework.web.multipart.MultipartFile;
//
import javax.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; //import java.io.InputStream;
//
/** ///**
* // * 文件上传下载接口定义
* // *
* @author // * @author 陈沅
*/ // */
public interface IFileUtil { //public interface IFileUtil {
//
//
//
/** // /**
* http // * 从http请求上传文件
* // *
* @param file formhttp // * @param file form传参http文件对象
* @return // * @return 返回文件在服务器上保存的相对路径
*/ // */
String upload(MultipartFile file); // String upload(MultipartFile file);
//
/** // /**
* // * 根据文件流上传文件
* // *
* @param objectName // * @param objectName 指定文件名(带扩展名)
* @param fileIn // * @param fileIn 文件流
* @return // * @return 返回文件在服务器上保存的相对路径
*/ // */
String upload(String objectName, InputStream fileIn); // String upload(String objectName, InputStream fileIn);
//
/** // /**
* // * 删除服务器上的一个文件
* // *
* @param path // * @param path 文件在服务器上保存的相对路径
* @return true // * @return 返回true则表示删除成功
*/ // */
boolean remove(String path); // boolean remove(String path);
//
/** // /**
* // * 下载文件流,指定文件名
* // *
* @param response // * @param response
* @param fileName // * @param fileName 指定下载文件名称
* @param filePath // * @param filePath 文件保存的相对路径
*/ // */
void download(HttpServletResponse response, String fileName, String filePath); // void download(HttpServletResponse response, String fileName, String filePath);
//
/** // /**
* // * 下载文件流,不指定文件名
* // *
* @param response // * @param response
* @param filePath // * @param filePath 文件保存的相对路径
*/ // */
void download(HttpServletResponse response, String filePath); // void download(HttpServletResponse response, String filePath);
//
/** // /**
* // * 相对路径
* // *
* @param relativePath // * @param relativePath 文件保存的相对路径
* @return // * @return 文件保存的绝对路径
*/ // */
String getFullPath(String relativePath); // String getFullPath(String relativePath);
//
//
/** // /**
* // * 获取文件后缀名
* // *
* @param fileName // * @param fileName 文件名称
* @return suffix // * @return suffix
*/ // */
String getSuffix(String fileName); // String getSuffix(String fileName);
//
//
/** // /**
* // * 获取文件存储至磁盘的相对路径
* // *
* @param fileName // * @param fileName 文件名
* @param suffix // * @param suffix 动态拼接的文件后缀,若该值为空则不拼接
* @return // * @return 相对路径
*/ // */
String getDiskRelativePath(String fileName, String suffix); // String getDiskRelativePath(String fileName, String suffix);
//
} //}

@ -1,175 +1,175 @@
package com.sztzjy.financial_bigdata.util.file; //package com.sztzjy.financial_bigdata.util.file;
//
import cn.hutool.core.util.CharsetUtil; //import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.IdUtil; //import cn.hutool.core.util.IdUtil;
import org.springframework.util.Assert; //import org.springframework.util.Assert;
import org.springframework.util.StringUtils; //import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; //import org.springframework.web.multipart.MultipartFile;
//
import javax.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletResponse;
import java.io.*; //import java.io.*;
import java.net.URLEncoder; //import java.net.URLEncoder;
import java.nio.file.Files; //import java.nio.file.Files;
import java.util.Arrays; //import java.util.Arrays;
import java.util.Calendar; //import java.util.Calendar;
import java.util.Date; //import java.util.Date;
import java.util.List; //import java.util.List;
//
public class LocalFileUtil implements IFileUtil{ //public class LocalFileUtil implements IFileUtil{
//
private final static List<String> excludeSp = Arrays.asList("exe", "bin", "sh"); // private final static List<String> excludeSp = Arrays.asList("exe", "bin", "sh");
//
private final String localPath; // private final String localPath;
//
public LocalFileUtil(String localPath) { // public LocalFileUtil(String localPath) {
this.localPath = localPath; // this.localPath = localPath;
} // }
//
@Override // @Override
public String upload(MultipartFile file) { // public String upload(MultipartFile file) {
return upload(null, file); // return upload(null, file);
} // }
//
@Override // @Override
public String upload(String objectName, InputStream fileIn) { // public String upload(String objectName, InputStream fileIn) {
Assert.notNull(fileIn, "文件不能为空"); // Assert.notNull(fileIn, "文件不能为空");
Assert.hasText(objectName, "文件名为空"); // Assert.hasText(objectName, "文件名为空");
Assert.isTrue(objectName.lastIndexOf(".") > 0, "文件名称需携带扩展后缀"); // Assert.isTrue(objectName.lastIndexOf(".") > 0, "文件名称需携带扩展后缀");
FileOutputStream out = null; // FileOutputStream out = null;
try { // try {
String relativePath = getDiskRelativePath(objectName, null); // String relativePath = getDiskRelativePath(objectName, null);
File file = new File(getFullPath(relativePath)); // File file = new File(getFullPath(relativePath));
file.getParentFile().mkdirs(); // file.getParentFile().mkdirs();
out = new FileOutputStream(file); // out = new FileOutputStream(file);
byte[] buff = new byte[4096]; // byte[] buff = new byte[4096];
int len; // int len;
while ((len = fileIn.read(buff)) != -1) { // while ((len = fileIn.read(buff)) != -1) {
out.write(buff, 0, len); // out.write(buff, 0, len);
} // }
out.flush(); // out.flush();
return relativePath; // return relativePath;
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
throw new IllegalArgumentException("上传文件失败,IO错误"); // throw new IllegalArgumentException("上传文件失败,IO错误");
} finally { // } finally {
try { // try {
fileIn.close(); // fileIn.close();
if (out != null) out.close(); // if (out != null) out.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
} // }
//
@Override // @Override
public boolean remove(String path) { // public boolean remove(String path) {
if (!StringUtils.hasText(path)) return false; // if (!StringUtils.hasText(path)) return false;
File file = new File(getFullPath(path)); // File file = new File(getFullPath(path));
if (!file.exists()) return false; // if (!file.exists()) return false;
return file.delete(); // return file.delete();
} // }
//
@Override // @Override
public void download(HttpServletResponse response, String fileName, String relativePath) { // public void download(HttpServletResponse response, String fileName, String relativePath) {
Assert.hasText(relativePath, "路径为空"); // Assert.hasText(relativePath, "路径为空");
System.out.println("------------------------------------" + getFullPath(relativePath)); // System.out.println("------------------------------------" + getFullPath(relativePath));
File file = new File(getFullPath(relativePath)); // File file = new File(getFullPath(relativePath));
Assert.isTrue(file.exists(), "附件不存在"); // Assert.isTrue(file.exists(), "附件不存在");
String sp = relativePath.substring(relativePath.lastIndexOf(".") + 1); // String sp = relativePath.substring(relativePath.lastIndexOf(".") + 1);
Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误"); // Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误");
if (!StringUtils.hasText(fileName)) { // if (!StringUtils.hasText(fileName)) {
fileName = file.getName().substring(0, file.getName().lastIndexOf(".")); // fileName = file.getName().substring(0, file.getName().lastIndexOf("."));
} // }
InputStream fis = null; // InputStream fis = null;
try { // try {
response.setContentType("application/octet-stream"); // response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode((fileName + "." + sp), CharsetUtil.UTF_8)); // response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode((fileName + "." + sp), CharsetUtil.UTF_8));
fis = new BufferedInputStream(Files.newInputStream(file.toPath())); // fis = new BufferedInputStream(Files.newInputStream(file.toPath()));
response.addHeader("Content-Length", String.valueOf(fis.available())); // response.addHeader("Content-Length", String.valueOf(fis.available()));
byte[] buff = new byte[4096]; // byte[] buff = new byte[4096];
int len; // int len;
while ((len = fis.read(buff)) != -1) { // while ((len = fis.read(buff)) != -1) {
response.getOutputStream().write(buff, 0, len); // response.getOutputStream().write(buff, 0, len);
} // }
} catch (Exception e) { // } catch (Exception e) {
throw new IllegalArgumentException("下载文件失败: " + e.getMessage()); // throw new IllegalArgumentException("下载文件失败: " + e.getMessage());
} finally { // } finally {
try { // try {
if (fis != null) fis.close(); // if (fis != null) fis.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
} // }
//
@Override // @Override
public void download(HttpServletResponse response, String relativePath) { // public void download(HttpServletResponse response, String relativePath) {
download(response, null, relativePath); // download(response, null, relativePath);
} // }
//
@Override // @Override
public String getFullPath(String relativePath) { // public String getFullPath(String relativePath) {
if (!relativePath.startsWith("/")) { // if (!relativePath.startsWith("/")) {
relativePath = "/" + relativePath; // relativePath = "/" + relativePath;
} // }
return localPath + relativePath; // return localPath + relativePath;
} // }
//
@Override // @Override
public String getSuffix(String fileName) { // public String getSuffix(String fileName) {
Assert.hasText(fileName, "文件名不存在!"); // Assert.hasText(fileName, "文件名不存在!");
if (fileName.lastIndexOf(".") < 0) { // if (fileName.lastIndexOf(".") < 0) {
return null; // return null;
} // }
return fileName.substring(fileName.lastIndexOf(".") + 1); // return fileName.substring(fileName.lastIndexOf(".") + 1);
} // }
//
public String upload(String fileName, MultipartFile file) { // public String upload(String fileName, MultipartFile file) {
return upload(fileName, file, null); // return upload(fileName, file, null);
} // }
//
//
@Override // @Override
public String getDiskRelativePath(String fileName, String suffix) { // public String getDiskRelativePath(String fileName, String suffix) {
Calendar c = Calendar.getInstance(); // Calendar c = Calendar.getInstance();
Date d = new Date(); // Date d = new Date();
c.setTime(d); // c.setTime(d);
String year = Integer.toString(c.get(Calendar.YEAR)); // String year = Integer.toString(c.get(Calendar.YEAR));
String month = Integer.toString(c.get(Calendar.MONTH) + 1); // String month = Integer.toString(c.get(Calendar.MONTH) + 1);
String day = Integer.toString(c.get(Calendar.DATE)); // String day = Integer.toString(c.get(Calendar.DATE));
StringBuilder path = new StringBuilder(); // StringBuilder path = new StringBuilder();
path.append("/").append(year) // path.append("/").append(year)
.append("/").append(month) // .append("/").append(month)
.append("/").append(day) // .append("/").append(day)
.append("/").append(fileName); // .append("/").append(fileName);
if (StringUtils.hasText(suffix)) path.append(".").append(suffix); // if (StringUtils.hasText(suffix)) path.append(".").append(suffix);
return path.toString(); // return path.toString();
} // }
//
private String upload(String fileName, MultipartFile file, String relativePath) { // private String upload(String fileName, MultipartFile file, String relativePath) {
Assert.isTrue(!file.isEmpty(), "文件不存在"); // Assert.isTrue(!file.isEmpty(), "文件不存在");
String originalFilename = file.getOriginalFilename(); // String originalFilename = file.getOriginalFilename();
if (fileName == null) fileName = IdUtil.simpleUUID(); // if (fileName == null) fileName = IdUtil.simpleUUID();
String sp = getSuffix(originalFilename); // String sp = getSuffix(originalFilename);
Assert.notNull(sp, "文件类型错误"); // Assert.notNull(sp, "文件类型错误");
Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误"); // Assert.isTrue(!excludeSp.contains(sp.toLowerCase()), "文件类型错误");
try { // try {
String filePath; // String filePath;
if (relativePath == null) { // if (relativePath == null) {
filePath = getDiskRelativePath(fileName, sp); // filePath = getDiskRelativePath(fileName, sp);
} else { // } else {
relativePath = relativePath.endsWith("/") ? relativePath : relativePath + "/"; // relativePath = relativePath.endsWith("/") ? relativePath : relativePath + "/";
filePath = relativePath + fileName + "." + sp; // filePath = relativePath + fileName + "." + sp;
} // }
//
File destFile = new File(getFullPath(filePath)); // File destFile = new File(getFullPath(filePath));
destFile.getParentFile().mkdirs(); // destFile.getParentFile().mkdirs();
file.transferTo(destFile); // file.transferTo(destFile);
return filePath; // return filePath;
} catch (FileNotFoundException e) { // } catch (FileNotFoundException e) {
throw new IllegalArgumentException("上传文件失败,FileNotFound错误"); // throw new IllegalArgumentException("上传文件失败,FileNotFound错误");
} catch (IOException e) { // } catch (IOException e) {
throw new IllegalArgumentException("上传文件失败,IO错误"); // throw new IllegalArgumentException("上传文件失败,IO错误");
} // }
} // }
} //}

Loading…
Cancel
Save