修复部分sonar问题
This commit is contained in:
+27
-13
@@ -369,7 +369,7 @@ public class ReportManageConroller {
|
|||||||
@ApiOperation(value = "上传图片")
|
@ApiOperation(value = "上传图片")
|
||||||
@PostMapping("/uploadPicFile")
|
@PostMapping("/uploadPicFile")
|
||||||
public ResponseMessage<Map<String, Object>> uploadPicFile(MultipartFile file, HttpServletRequest request) throws IOException {
|
public ResponseMessage<Map<String, Object>> uploadPicFile(MultipartFile file, HttpServletRequest request) throws IOException {
|
||||||
|
Random r = new Random();
|
||||||
try (InputStream input = file.getInputStream()) {
|
try (InputStream input = file.getInputStream()) {
|
||||||
Map<String, Object> resultMap = new HashMap();
|
Map<String, Object> resultMap = new HashMap();
|
||||||
String path = uploadFile;//此路径映射到localhost
|
String path = uploadFile;//此路径映射到localhost
|
||||||
@@ -381,13 +381,12 @@ public class ReportManageConroller {
|
|||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
String date = dateFormat.format(now);
|
String date = dateFormat.format(now);
|
||||||
Random r = new Random();
|
|
||||||
String num = "";
|
String num = "";
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
int s = r.nextInt(10);
|
int s = r.nextInt(10);
|
||||||
num += String.valueOf(s);
|
num += String.valueOf(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取上传文件名
|
//获取上传文件名
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String contentType = file.getContentType();
|
String contentType = file.getContentType();
|
||||||
@@ -500,6 +499,7 @@ public class ReportManageConroller {
|
|||||||
//如果只下载一个文件,则不压缩
|
//如果只下载一个文件,则不压缩
|
||||||
if (downLoadFileIds.size() == 1) {
|
if (downLoadFileIds.size() == 1) {
|
||||||
String fileId = downLoadFileIds.get(0);
|
String fileId = downLoadFileIds.get(0);
|
||||||
|
FileOutputStream outputStream = null;
|
||||||
try {
|
try {
|
||||||
FileEntity entity = fileService.getFile(fileId);
|
FileEntity entity = fileService.getFile(fileId);
|
||||||
String fileName = entity.getFileName();
|
String fileName = entity.getFileName();
|
||||||
@@ -510,7 +510,7 @@ public class ReportManageConroller {
|
|||||||
//PDF文件需要加水印
|
//PDF文件需要加水印
|
||||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||||
String path = uploadFile + entity.getSavePath();
|
String path = uploadFile + entity.getSavePath();
|
||||||
FileOutputStream outputStream = new FileOutputStream(path);
|
outputStream = new FileOutputStream(path);
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||||
if ("hwobs".equals(uploadType)) {
|
if ("hwobs".equals(uploadType)) {
|
||||||
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
||||||
@@ -521,7 +521,7 @@ public class ReportManageConroller {
|
|||||||
}
|
}
|
||||||
//给文件添加水印
|
//给文件添加水印
|
||||||
waterMarkUtil.addWatermarkToPdfAndWriteToResponse(new FileInputStream(path), response);
|
waterMarkUtil.addWatermarkToPdfAndWriteToResponse(new FileInputStream(path), response);
|
||||||
outputStream.close();
|
|
||||||
} else {
|
} else {
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local
|
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local
|
||||||
if ("hwobs".equals(uploadType)){
|
if ("hwobs".equals(uploadType)){
|
||||||
@@ -535,6 +535,10 @@ public class ReportManageConroller {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.info(ex.getMessage(),ex);
|
log.info(ex.getMessage(),ex);
|
||||||
|
} finally {
|
||||||
|
if (outputStream != null){
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<String> filePaths = new ArrayList<>();
|
List<String> filePaths = new ArrayList<>();
|
||||||
@@ -545,14 +549,14 @@ public class ReportManageConroller {
|
|||||||
response.setHeader("Pragma", "public");
|
response.setHeader("Pragma", "public");
|
||||||
response.setHeader("Cache-Control", "no-store");
|
response.setHeader("Cache-Control", "no-store");
|
||||||
response.setHeader("Expires", "0");
|
response.setHeader("Expires", "0");
|
||||||
|
FileOutputStream outputStream = null;
|
||||||
for (String fileId : downLoadFileIds) {
|
for (String fileId : downLoadFileIds) {
|
||||||
try {
|
try {
|
||||||
FileEntity entity = fileService.getFile(fileId);
|
FileEntity entity = fileService.getFile(fileId);
|
||||||
String fileName = entity.getFileName();
|
String fileName = entity.getFileName();
|
||||||
|
|
||||||
String path = uploadFile + entity.getSavePath();
|
String path = uploadFile + entity.getSavePath();
|
||||||
FileOutputStream outputStream = new FileOutputStream(path);
|
outputStream = new FileOutputStream(path);
|
||||||
filePaths.add(path);
|
filePaths.add(path);
|
||||||
|
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||||
@@ -567,9 +571,12 @@ public class ReportManageConroller {
|
|||||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||||
waterMarkUtil.savePdfToFile(new FileInputStream(path), path);
|
waterMarkUtil.savePdfToFile(new FileInputStream(path), path);
|
||||||
}
|
}
|
||||||
outputStream.close();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.info(ex.getMessage(),ex);
|
log.info(ex.getMessage(),ex);
|
||||||
|
} finally {
|
||||||
|
if (outputStream != null){
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//将文件压缩 写入Response
|
//将文件压缩 写入Response
|
||||||
@@ -656,6 +663,7 @@ public class ReportManageConroller {
|
|||||||
//如果只下载一个文件,则不压缩
|
//如果只下载一个文件,则不压缩
|
||||||
if (downLoadFileIds.size() == 1) {
|
if (downLoadFileIds.size() == 1) {
|
||||||
String fileId = downLoadFileIds.get(0);
|
String fileId = downLoadFileIds.get(0);
|
||||||
|
FileOutputStream outputStream = null;
|
||||||
try {
|
try {
|
||||||
FileEntity entity = fileService.getFile(fileId);
|
FileEntity entity = fileService.getFile(fileId);
|
||||||
String fileName = entity.getFileName();
|
String fileName = entity.getFileName();
|
||||||
@@ -666,7 +674,7 @@ public class ReportManageConroller {
|
|||||||
//PDF文件需要加水印
|
//PDF文件需要加水印
|
||||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||||
String path = uploadFile + entity.getSavePath();
|
String path = uploadFile + entity.getSavePath();
|
||||||
FileOutputStream outputStream = new FileOutputStream(path);
|
outputStream = new FileOutputStream(path);
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||||
if ("hwobs".equals(uploadType)) {
|
if ("hwobs".equals(uploadType)) {
|
||||||
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
||||||
@@ -677,7 +685,6 @@ public class ReportManageConroller {
|
|||||||
}
|
}
|
||||||
//给文件添加水印
|
//给文件添加水印
|
||||||
waterMarkUtil.addWatermarkToPdfAndWriteToResponse(new FileInputStream(path), response);
|
waterMarkUtil.addWatermarkToPdfAndWriteToResponse(new FileInputStream(path), response);
|
||||||
outputStream.close();
|
|
||||||
} else {
|
} else {
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local
|
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local
|
||||||
if ("hwobs".equals(uploadType)){
|
if ("hwobs".equals(uploadType)){
|
||||||
@@ -691,6 +698,10 @@ public class ReportManageConroller {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.info(ex.getMessage(),ex);
|
log.info(ex.getMessage(),ex);
|
||||||
|
} finally {
|
||||||
|
if (outputStream != null){
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<String> filePaths = new ArrayList<>();
|
List<String> filePaths = new ArrayList<>();
|
||||||
@@ -701,14 +712,14 @@ public class ReportManageConroller {
|
|||||||
response.setHeader("Pragma", "public");
|
response.setHeader("Pragma", "public");
|
||||||
response.setHeader("Cache-Control", "no-store");
|
response.setHeader("Cache-Control", "no-store");
|
||||||
response.setHeader("Expires", "0");
|
response.setHeader("Expires", "0");
|
||||||
|
FileOutputStream outputStream = null;
|
||||||
for (String fileId : downLoadFileIds) {
|
for (String fileId : downLoadFileIds) {
|
||||||
try {
|
try {
|
||||||
FileEntity entity = fileService.getFile(fileId);
|
FileEntity entity = fileService.getFile(fileId);
|
||||||
String fileName = entity.getFileName();
|
String fileName = entity.getFileName();
|
||||||
|
|
||||||
String path = uploadFile + entity.getSavePath();
|
String path = uploadFile + entity.getSavePath();
|
||||||
FileOutputStream outputStream = new FileOutputStream(path);
|
outputStream = new FileOutputStream(path);
|
||||||
filePaths.add(path);
|
filePaths.add(path);
|
||||||
|
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||||
@@ -723,9 +734,12 @@ public class ReportManageConroller {
|
|||||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||||
waterMarkUtil.savePdfToFile(new FileInputStream(path), path);
|
waterMarkUtil.savePdfToFile(new FileInputStream(path), path);
|
||||||
}
|
}
|
||||||
outputStream.close();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.info(ex.getMessage(),ex);
|
log.info(ex.getMessage(),ex);
|
||||||
|
} finally {
|
||||||
|
if (outputStream != null){
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//将文件压缩 写入Response
|
//将文件压缩 写入Response
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -49,6 +50,12 @@ public class IFileServiceImpl implements IFileService {
|
|||||||
@Resource
|
@Resource
|
||||||
private OSSClientUtil ossClientUtil;
|
private OSSClientUtil ossClientUtil;
|
||||||
|
|
||||||
|
private static Random r;
|
||||||
|
|
||||||
|
static {
|
||||||
|
r = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加文件
|
* 添加文件
|
||||||
* @param entity
|
* @param entity
|
||||||
@@ -82,7 +89,7 @@ public class IFileServiceImpl implements IFileService {
|
|||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
String date = dateFormat.format(now);
|
String date = dateFormat.format(now);
|
||||||
Random r = new Random();
|
|
||||||
String num = "";
|
String num = "";
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
int s = r.nextInt(10);
|
int s = r.nextInt(10);
|
||||||
@@ -137,7 +144,6 @@ public class IFileServiceImpl implements IFileService {
|
|||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
String date = dateFormat.format(now);
|
String date = dateFormat.format(now);
|
||||||
Random r = new Random();
|
|
||||||
String num = "";
|
String num = "";
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
int s = r.nextInt(10);
|
int s = r.nextInt(10);
|
||||||
|
|||||||
@@ -950,14 +950,23 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
|||||||
public String createHtmlString(String fileId) throws Exception {
|
public String createHtmlString(String fileId) throws Exception {
|
||||||
FileEntity fileEntity = fileDao.selectById(fileId);
|
FileEntity fileEntity = fileDao.selectById(fileId);
|
||||||
String path = uploadFile + fileEntity.getSavePath();
|
String path = uploadFile + fileEntity.getSavePath();
|
||||||
FileOutputStream outputStream = new FileOutputStream(path);
|
FileOutputStream outputStream = null;
|
||||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
try {
|
||||||
if ("hwobs".equals(uploadType)) {
|
outputStream = new FileOutputStream(path);
|
||||||
obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream);
|
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||||
} else if ("alioss".equals(uploadType)) {
|
if ("hwobs".equals(uploadType)) {
|
||||||
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream);
|
obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream);
|
||||||
} else if ("local".equals(uploadType)) {
|
} else if ("alioss".equals(uploadType)) {
|
||||||
localFileUtil.getFileFromLocal(fileEntity.getSavePath(), outputStream);
|
ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream);
|
||||||
|
} else if ("local".equals(uploadType)) {
|
||||||
|
localFileUtil.getFileFromLocal(fileEntity.getSavePath(), outputStream);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (outputStream != null){
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String html = null;
|
String html = null;
|
||||||
|
|||||||
@@ -91,9 +91,13 @@ public class FileContentUtil {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
} catch (NotOfficeXmlFileException e) {
|
} catch (NotOfficeXmlFileException e) {
|
||||||
fis.close();
|
|
||||||
log.info("文件内容抽取失败,原因可能是上传的文件为空文件");
|
log.info("文件内容抽取失败,原因可能是上传的文件为空文件");
|
||||||
|
} finally {
|
||||||
|
if (fis != null){
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanInvalidCharacters(content.toString());
|
return cleanInvalidCharacters(content.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,15 +40,24 @@ public class LocalFileUtil {
|
|||||||
|
|
||||||
ZipEntry zipEntry = new ZipEntry(sourceFile.getName());
|
ZipEntry zipEntry = new ZipEntry(sourceFile.getName());
|
||||||
zipOutputStream.putNextEntry(zipEntry);
|
zipOutputStream.putNextEntry(zipEntry);
|
||||||
|
FileInputStream fileInputStream = null;
|
||||||
|
try {
|
||||||
|
fileInputStream = new FileInputStream(sourceFile);
|
||||||
|
|
||||||
FileInputStream fileInputStream = new FileInputStream(sourceFile);
|
int len;
|
||||||
|
while ((len = fileInputStream.read(buffer)) > 0) {
|
||||||
|
zipOutputStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
|
||||||
int len;
|
fileInputStream.close();
|
||||||
while ((len = fileInputStream.read(buffer)) > 0) {
|
} catch (Exception e){
|
||||||
zipOutputStream.write(buffer, 0, len);
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (fileInputStream != null){
|
||||||
|
fileInputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileInputStream.close();
|
|
||||||
zipOutputStream.closeEntry();
|
zipOutputStream.closeEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +71,28 @@ public class LocalFileUtil {
|
|||||||
|
|
||||||
public void saveFile(InputStream fileInputStream, String fileName) throws IOException {
|
public void saveFile(InputStream fileInputStream, String fileName) throws IOException {
|
||||||
String path = localFilePath + fileName;
|
String path = localFilePath + fileName;
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(path);
|
|
||||||
byte[] buffer = new byte[1024];
|
FileOutputStream fileOutputStream= null;
|
||||||
int length;
|
try {
|
||||||
while ((length = fileInputStream.read(buffer)) > 0) {
|
fileOutputStream = new FileOutputStream(path);
|
||||||
fileOutputStream.write(buffer, 0, length);
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = fileInputStream.read(buffer)) > 0) {
|
||||||
|
fileOutputStream.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
fileInputStream.close();
|
||||||
|
fileOutputStream.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (fileOutputStream != null){
|
||||||
|
fileOutputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileInputStream != null){
|
||||||
|
fileInputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileInputStream.close();
|
|
||||||
fileOutputStream.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getFileFromLocal(String savePath, FileOutputStream outputStream) throws IOException {
|
public void getFileFromLocal(String savePath, FileOutputStream outputStream) throws IOException {
|
||||||
@@ -80,22 +103,30 @@ public class LocalFileUtil {
|
|||||||
if (!sourceFile.exists()) {
|
if (!sourceFile.exists()) {
|
||||||
throw new IOException("Source file does not exist.");
|
throw new IOException("Source file does not exist.");
|
||||||
}
|
}
|
||||||
|
FileInputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
// 创建输入流
|
||||||
|
inputStream = new FileInputStream(sourceFile);
|
||||||
|
|
||||||
// 创建输入流
|
// 创建缓冲区
|
||||||
FileInputStream inputStream = new FileInputStream(sourceFile);
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
|
||||||
// 创建缓冲区
|
// 从输入流读取数据,并写入输出流
|
||||||
byte[] buffer = new byte[1024];
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
int bytesRead;
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null){
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
// 从输入流读取数据,并写入输出流
|
if (outputStream != null){
|
||||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
outputStream.close();
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭输入流和输出流
|
|
||||||
inputStream.close();
|
|
||||||
outputStream.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downFile(String savePath, HttpServletResponse response) throws IOException {
|
public void downFile(String savePath, HttpServletResponse response) throws IOException {
|
||||||
|
|||||||
@@ -89,7 +89,9 @@ public class ObsBootUtil {
|
|||||||
throw new AdcDaBaseException("OBS下载文件失败");
|
throw new AdcDaBaseException("OBS下载文件失败");
|
||||||
}finally {
|
}finally {
|
||||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||||
objectContent.close();
|
if (objectContent != null) {
|
||||||
|
objectContent.close();
|
||||||
|
}
|
||||||
response.getOutputStream().close();
|
response.getOutputStream().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +114,13 @@ public class ObsBootUtil {
|
|||||||
throw new AdcDaBaseException("OBS下载文件失败");
|
throw new AdcDaBaseException("OBS下载文件失败");
|
||||||
}finally {
|
}finally {
|
||||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||||
objectContent.close();
|
if (objectContent != null){
|
||||||
outputStream.close();
|
objectContent.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputStream != null){
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,10 +179,11 @@ public class UserEOController extends BaseController<UserEO> {
|
|||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
is.close();
|
if (is != null){
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,17 +193,18 @@ public class UserEOController extends BaseController<UserEO> {
|
|||||||
@ApiOperation("下载模板")
|
@ApiOperation("下载模板")
|
||||||
@GetMapping("/template")
|
@GetMapping("/template")
|
||||||
public ResponseMessage download(HttpServletResponse response) {
|
public ResponseMessage download(HttpServletResponse response) {
|
||||||
|
InputStream fis = null;
|
||||||
|
OutputStream toClient = null;
|
||||||
try {
|
try {
|
||||||
InputStream fis = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/用户导入模板.xlsx");
|
fis = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/用户导入模板.xlsx");
|
||||||
byte[] buffer = new byte[fis.available()];
|
byte[] buffer = new byte[fis.available()];
|
||||||
fis.read(buffer);
|
fis.read(buffer);
|
||||||
fis.close();
|
|
||||||
response.reset();
|
response.reset();
|
||||||
response.setContentType("application/vnd.ms-excel");
|
response.setContentType("application/vnd.ms-excel");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("用户导入模板.xlsx","UTF-8"));
|
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("用户导入模板.xlsx","UTF-8"));
|
||||||
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
|
toClient = new BufferedOutputStream(response.getOutputStream());
|
||||||
|
|
||||||
toClient.write(buffer);
|
toClient.write(buffer);
|
||||||
|
|
||||||
@@ -211,9 +213,23 @@ public class UserEOController extends BaseController<UserEO> {
|
|||||||
toClient.close();
|
toClient.close();
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (fis != null){
|
||||||
|
try {
|
||||||
|
fis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toClient != null){
|
||||||
|
try {
|
||||||
|
toClient.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Result.success();
|
return Result.success();
|
||||||
|
|
||||||
|
|||||||
@@ -61,19 +61,25 @@ public class CompressUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else { // 当前是文件
|
} else { // 当前是文件
|
||||||
|
FileInputStream inputStream = null;
|
||||||
// 输入流
|
try {
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
// 输入流
|
||||||
// 标记要打包的条目
|
inputStream = new FileInputStream(file);
|
||||||
out.putNextEntry(new ZipEntry(file.getName()));
|
// 标记要打包的条目
|
||||||
// 进行写操作
|
out.putNextEntry(new ZipEntry(file.getName()));
|
||||||
int len = 0;
|
// 进行写操作
|
||||||
byte[] bytes = new byte[1024];
|
int len = 0;
|
||||||
while ((len = inputStream.read(bytes)) > 0) {
|
byte[] bytes = new byte[1024];
|
||||||
out.write(bytes, 0, len);
|
while ((len = inputStream.read(bytes)) > 0) {
|
||||||
}
|
out.write(bytes, 0, len);
|
||||||
// 关闭输入流
|
}
|
||||||
inputStream.close();
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null){
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.adc.da.sys.util;
|
package com.adc.da.sys.util;
|
||||||
|
|
||||||
|
import com.adc.da.util.exception.AdcDaBaseException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import sun.misc.BASE64Decoder;
|
import sun.misc.BASE64Decoder;
|
||||||
@@ -41,6 +42,11 @@ public class EncryptUtil {
|
|||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (encrypt == null){
|
||||||
|
throw new AdcDaBaseException("秘钥生成错误");
|
||||||
|
}
|
||||||
|
|
||||||
// 取MD5Hash码,并组合加密数组
|
// 取MD5Hash码,并组合加密数组
|
||||||
byte[] md5Hasn = null;
|
byte[] md5Hasn = null;
|
||||||
try {
|
try {
|
||||||
@@ -48,6 +54,11 @@ public class EncryptUtil {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (md5Hasn == null){
|
||||||
|
throw new AdcDaBaseException("MD5生成错误");
|
||||||
|
}
|
||||||
|
|
||||||
// 组合消息体
|
// 组合消息体
|
||||||
byte[] totalByte = EncryptUtil.addMD5(md5Hasn, encrypt);
|
byte[] totalByte = EncryptUtil.addMD5(md5Hasn, encrypt);
|
||||||
|
|
||||||
@@ -112,6 +123,10 @@ public class EncryptUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (temp == null){
|
||||||
|
throw new AdcDaBaseException("秘钥生成错误");
|
||||||
|
}
|
||||||
|
|
||||||
// 进行解密后的md5Hash校验
|
// 进行解密后的md5Hash校验
|
||||||
byte[] md5Hash = null;
|
byte[] md5Hash = null;
|
||||||
try {
|
try {
|
||||||
@@ -120,6 +135,10 @@ public class EncryptUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (md5Hash == null){
|
||||||
|
throw new AdcDaBaseException("MD5生成错误");
|
||||||
|
}
|
||||||
|
|
||||||
// 进行解密校检
|
// 进行解密校检
|
||||||
for (int i = 0; i < md5Hash.length; i++) {
|
for (int i = 0; i < md5Hash.length; i++) {
|
||||||
if (md5Hash[i] != temp[i]) {
|
if (md5Hash[i] != temp[i]) {
|
||||||
|
|||||||
+19
-10
@@ -1,5 +1,6 @@
|
|||||||
package com.adc.da.wkflow.business_activiti.instance.service;
|
package com.adc.da.wkflow.business_activiti.instance.service;
|
||||||
|
|
||||||
|
import com.adc.da.util.exception.AdcDaBaseException;
|
||||||
import org.activiti.bpmn.model.BpmnModel;
|
import org.activiti.bpmn.model.BpmnModel;
|
||||||
import org.activiti.engine.HistoryService;
|
import org.activiti.engine.HistoryService;
|
||||||
import org.activiti.engine.RepositoryService;
|
import org.activiti.engine.RepositoryService;
|
||||||
@@ -57,16 +58,24 @@ public class InstanceService {
|
|||||||
|
|
||||||
// 得到高亮线
|
// 得到高亮线
|
||||||
List<String> highLightedFlowsList = getHighLightedFlows(processDefinition, historicActivityInstanceList);
|
List<String> highLightedFlowsList = getHighLightedFlows(processDefinition, historicActivityInstanceList);
|
||||||
|
InputStream imageStream = null;
|
||||||
// 获取流程图图像字符流
|
try {
|
||||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
|
// 获取流程图图像字符流
|
||||||
DefaultProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
|
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
|
||||||
InputStream imageStream = generator.generateDiagram(bpmnModel, "png", executedActivityIdList,
|
DefaultProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
|
||||||
highLightedFlowsList, "宋体", "宋体", "宋体", null, 1.0);
|
imageStream = generator.generateDiagram(bpmnModel, "png", executedActivityIdList,
|
||||||
byte[] buffer = new byte[imageStream.available()];
|
highLightedFlowsList, "宋体", "宋体", "宋体", null, 1.0);
|
||||||
imageStream.read(buffer);
|
byte[] buffer = new byte[imageStream.available()];
|
||||||
imageStream.close();
|
imageStream.read(buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
} catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new AdcDaBaseException("流程图生成错误,请检查");
|
||||||
|
} finally {
|
||||||
|
if (imageStream != null){
|
||||||
|
imageStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-60
@@ -277,10 +277,6 @@ public class TodoTaskController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 转办
|
* 转办
|
||||||
* @param taskId
|
|
||||||
* @param assignee
|
|
||||||
* @param userId
|
|
||||||
* @param pId
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = "新改派任务")
|
@ApiOperation(value = "新改派任务")
|
||||||
@@ -387,7 +383,14 @@ public class TodoTaskController {
|
|||||||
}
|
}
|
||||||
iBusProcessNameService.updateById(one);
|
iBusProcessNameService.updateById(one);
|
||||||
}
|
}
|
||||||
return WrapMapper.ok(task.getProcessInstanceId());
|
|
||||||
|
if (task == null){
|
||||||
|
throw new AdcDaBaseException("缺少任务信息,无法完成任务");
|
||||||
|
} else {
|
||||||
|
return WrapMapper.ok(task.getProcessInstanceId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new AdcDaBaseException("缺少任务id,无法完成任务");
|
throw new AdcDaBaseException("缺少任务id,无法完成任务");
|
||||||
}
|
}
|
||||||
@@ -1077,23 +1080,15 @@ public class TodoTaskController {
|
|||||||
.processInstanceId(busProcessName.getPrcId())
|
.processInstanceId(busProcessName.getPrcId())
|
||||||
.finished().orderByHistoricActivityInstanceEndTime().desc().list();
|
.finished().orderByHistoricActivityInstanceEndTime().desc().list();
|
||||||
if (userTask.size() > 0) {
|
if (userTask.size() > 0) {
|
||||||
if (end.equals("1")) {
|
|
||||||
if(CollectionUtils.isNotEmpty(userVOList)){
|
if(CollectionUtils.isNotEmpty(userVOList)){
|
||||||
for (UserVO userVO : userVOList) {
|
for (UserVO userVO : userVOList) {
|
||||||
if(StringUtils.equals(userVO.getUsid(),userTask.get(0).getAssignee())){
|
if(StringUtils.equals(userVO.getUsid(),userTask.get(0).getAssignee())){
|
||||||
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(CollectionUtils.isNotEmpty(userVOList)){
|
|
||||||
for (UserVO userVO : userVOList) {
|
|
||||||
if(StringUtils.equals(userVO.getUsid(),userTask.get(0).getAssignee())){
|
|
||||||
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
busProcessName.setTaskBackAssignee("");
|
busProcessName.setTaskBackAssignee("");
|
||||||
}
|
}
|
||||||
@@ -1118,6 +1113,7 @@ public class TodoTaskController {
|
|||||||
Date createTime = null;
|
Date createTime = null;
|
||||||
Date endTime = null;
|
Date endTime = null;
|
||||||
try {
|
try {
|
||||||
|
SimpleDateFormat SimpleDateFormat_YMD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
createTime = SimpleDateFormat_YMD_HMS.parse(busProcessName.getCreatTime());
|
createTime = SimpleDateFormat_YMD_HMS.parse(busProcessName.getCreatTime());
|
||||||
if(StringUtils.isNotEmpty(busProcessName.getEndTime())){
|
if(StringUtils.isNotEmpty(busProcessName.getEndTime())){
|
||||||
endTime = SimpleDateFormat_YMD_HMS.parse(busProcessName.getEndTime());
|
endTime = SimpleDateFormat_YMD_HMS.parse(busProcessName.getEndTime());
|
||||||
@@ -1255,23 +1251,11 @@ public class TodoTaskController {
|
|||||||
.processInstanceId(busProcessName.getPrcId())
|
.processInstanceId(busProcessName.getPrcId())
|
||||||
.finished().orderByHistoricActivityInstanceEndTime().desc().list();
|
.finished().orderByHistoricActivityInstanceEndTime().desc().list();
|
||||||
if (userTask.size() > 0) {
|
if (userTask.size() > 0) {
|
||||||
if (end.equals("1")) {
|
for (UserVO userVO : userVOList) {
|
||||||
if(CollectionUtils.isNotEmpty(userVOList)) {
|
if (StringUtils.equals(userTask.get(0).getAssignee(), userVO.getUsid())) {
|
||||||
for (UserVO userVO : userVOList) {
|
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
||||||
if (StringUtils.equals(userTask.get(0).getAssignee(), userVO.getUsid())) {
|
|
||||||
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if(CollectionUtils.isNotEmpty(userVOList)) {
|
|
||||||
for (UserVO userVO : userVOList) {
|
|
||||||
if (StringUtils.equals(userTask.get(0).getAssignee(), userVO.getUsid())) {
|
|
||||||
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
busProcessName.setTaskBackAssignee("");
|
busProcessName.setTaskBackAssignee("");
|
||||||
}
|
}
|
||||||
@@ -1295,6 +1279,7 @@ public class TodoTaskController {
|
|||||||
Date createTime = null;
|
Date createTime = null;
|
||||||
Date endTime = null;
|
Date endTime = null;
|
||||||
try {
|
try {
|
||||||
|
SimpleDateFormat SimpleDateFormat_YMD = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
createTime = SimpleDateFormat_YMD.parse(busProcessName.getCreatTime());
|
createTime = SimpleDateFormat_YMD.parse(busProcessName.getCreatTime());
|
||||||
if(StringUtils.isNotEmpty(busProcessName.getEndTime())){
|
if(StringUtils.isNotEmpty(busProcessName.getEndTime())){
|
||||||
endTime = SimpleDateFormat_YMD.parse(busProcessName.getEndTime());
|
endTime = SimpleDateFormat_YMD.parse(busProcessName.getEndTime());
|
||||||
@@ -1436,40 +1421,21 @@ public class TodoTaskController {
|
|||||||
.processInstanceId(busProcessName.getPrcId())
|
.processInstanceId(busProcessName.getPrcId())
|
||||||
.finished().orderByHistoricActivityInstanceEndTime().desc().list();
|
.finished().orderByHistoricActivityInstanceEndTime().desc().list();
|
||||||
if (userTask.size() > 0) {
|
if (userTask.size() > 0) {
|
||||||
if (end.equals("1")) {
|
if(CollectionUtils.isNotEmpty(userVOList)){
|
||||||
if(CollectionUtils.isNotEmpty(userVOList)){
|
for (UserVO userVO : userVOList) {
|
||||||
for (UserVO userVO : userVOList) {
|
if(StringUtils.equals(userVO.getUsid(),userTask.get(0).getAssignee())){
|
||||||
if(StringUtils.equals(userVO.getUsid(),userTask.get(0).getAssignee())){
|
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
||||||
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(CollectionUtils.isNotEmpty(userVOList)){
|
|
||||||
for (UserVO userVO : userVOList) {
|
|
||||||
if(StringUtils.equals(userVO.getUsid(),userTask.get(0).getAssignee())){
|
|
||||||
busProcessName.setTaskBackAssignee(userVO.getUsname() + "(" + userVO.getAccount() + ")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
busProcessName.setTaskBackAssignee("");
|
busProcessName.setTaskBackAssignee("");
|
||||||
}
|
}
|
||||||
//获取 审批结果
|
|
||||||
// if (StringUtils.isNotEmpty(busProcessName.getPrcId())) {
|
|
||||||
// List<BusProcessApprove> busProcessApproves = iBusProcessApproveService.selectEoByPrcIdAndTask(busProcessName.getPrcId());
|
|
||||||
// if(busProcessApproves.size() != 0){
|
|
||||||
// BusProcessApprove busProcessApprove = busProcessApproves.get(0);
|
|
||||||
// JSONObject dataJson = JSONObject.parseObject(busProcessApprove.getFromValsJson());
|
|
||||||
// if (StringUtils.isNotEmpty(dataJson.getString("flag"))) {
|
|
||||||
// busProcessName.setStatus(dataJson.getString("flag"));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
Date createTime = null;
|
Date createTime = null;
|
||||||
Date endTime = null;
|
Date endTime = null;
|
||||||
try {
|
try {
|
||||||
|
SimpleDateFormat SimpleDateFormat_YMD = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
createTime = SimpleDateFormat_YMD.parse(busProcessName.getCreatTime());
|
createTime = SimpleDateFormat_YMD.parse(busProcessName.getCreatTime());
|
||||||
if(StringUtils.isNotEmpty(busProcessName.getEndTime())){
|
if(StringUtils.isNotEmpty(busProcessName.getEndTime())){
|
||||||
endTime = SimpleDateFormat_YMD.parse(busProcessName.getEndTime());
|
endTime = SimpleDateFormat_YMD.parse(busProcessName.getEndTime());
|
||||||
@@ -1530,7 +1496,7 @@ public class TodoTaskController {
|
|||||||
int fromIndex = 0; // 开始索引
|
int fromIndex = 0; // 开始索引
|
||||||
int toIndex = 0; // 结束索引
|
int toIndex = 0; // 结束索引
|
||||||
|
|
||||||
if (pageNum != pageCount) {
|
if (!pageNum.equals(pageCount)) {
|
||||||
fromIndex = (pageNum - 1) * pageSize;
|
fromIndex = (pageNum - 1) * pageSize;
|
||||||
toIndex = fromIndex + pageSize;
|
toIndex = fromIndex + pageSize;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class CreatedTools {
|
public class CreatedTools {
|
||||||
|
|
||||||
private final static DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
||||||
|
|
||||||
// 返回long型的创建时间
|
// 返回long型的创建时间
|
||||||
public static long getCreated() {
|
public static long getCreated() {
|
||||||
Date d = new Date();
|
Date d = new Date();
|
||||||
|
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
long l = Long.parseLong(df.format(d));
|
long l = Long.parseLong(df.format(d));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@@ -19,6 +18,7 @@ public class CreatedTools {
|
|||||||
public static long getCreated(int add) {
|
public static long getCreated(int add) {
|
||||||
long t = System.currentTimeMillis() + add;
|
long t = System.currentTimeMillis() + add;
|
||||||
Timestamp time = new Timestamp(t);
|
Timestamp time = new Timestamp(t);
|
||||||
|
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
long l = Long.parseLong(df.format(time));
|
long l = Long.parseLong(df.format(time));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class DateTools {
|
public class DateTools {
|
||||||
|
|
||||||
public static SimpleDateFormat SimpleDateFormat_YMD = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
public static SimpleDateFormat SimpleDateFormat_YMD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
// 增加对应天数
|
// 增加对应天数
|
||||||
public static Timestamp addDay(Timestamp end, int day) {
|
public static Timestamp addDay(Timestamp end, int day) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
@@ -369,9 +366,14 @@ public class DateTools {
|
|||||||
public static int getDayOfMonth(String yearMonth) {
|
public static int getDayOfMonth(String yearMonth) {
|
||||||
java.sql.Date date = getYearMonth(yearMonth);
|
java.sql.Date date = getYearMonth(yearMonth);
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTimeInMillis(date.getTime());
|
|
||||||
int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
|
if (date != null){
|
||||||
return dateOfMonth;
|
cal.setTimeInMillis(date.getTime());
|
||||||
|
int dateOfMonth = cal.getActualMaximum(Calendar.DATE);
|
||||||
|
return dateOfMonth;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取每月最大天数
|
// 获取每月最大天数
|
||||||
@@ -461,24 +463,12 @@ public class DateTools {
|
|||||||
|
|
||||||
String str = getstrDate1(20181113110947L);
|
String str = getstrDate1(20181113110947L);
|
||||||
System.out.println(str);
|
System.out.println(str);
|
||||||
// System.err.println(getDayOfMonth(2000, 2));
|
|
||||||
// System.err.println(getDayOfMonth("2000-02"));
|
|
||||||
/*
|
|
||||||
* System.err.println(getYearToLong(2016));
|
|
||||||
* System.err.println(getYearToLong(2017));
|
|
||||||
* System.err.println(getYearToLong(2018));
|
|
||||||
*/
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
long a = sdf.parse(str).getTime();
|
long a = sdf.parse(str).getTime();
|
||||||
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
System.out.println(sdf1.format(new Date(a)));
|
System.out.println(sdf1.format(new Date(a)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getYearToLong(int year) {
|
|
||||||
java.sql.Date date = strToDate(year + "-01-01");
|
|
||||||
return date.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getCreated() {
|
public static long getCreated() {
|
||||||
Date d = new Date();
|
Date d = new Date();
|
||||||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
|
|||||||
@@ -78,16 +78,16 @@ public class FileTools {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (null != fin) {
|
if (fin != null) {
|
||||||
fin.close();
|
fin.close();
|
||||||
}
|
}
|
||||||
if (null != fout) {
|
if (fout != null) {
|
||||||
fout.close();
|
fout.close();
|
||||||
}
|
}
|
||||||
if (null != fcin) {
|
if (fcin != null) {
|
||||||
fcin.close();
|
fcin.close();
|
||||||
}
|
}
|
||||||
if (null != fcout) {
|
if (fcout != null) {
|
||||||
fcout.close();
|
fcout.close();
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@@ -99,8 +99,7 @@ public class FileTools {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断文件夹中所有文件的名字是否含有.bid
|
* 判断文件夹中所有文件的名字是否含有.bid
|
||||||
*
|
*
|
||||||
* @param file 想要读取的文件对象
|
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean checkFileName(String filePath, String exclusive_name) {
|
public static boolean checkFileName(String filePath, String exclusive_name) {
|
||||||
@@ -208,70 +207,4 @@ public class FileTools {
|
|||||||
return foldResult;
|
return foldResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件写入数据
|
|
||||||
*
|
|
||||||
* @param content
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean writeFile(String content, String url) {
|
|
||||||
if (StrUtil.isEmpty(url)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BufferedWriter writer = null;
|
|
||||||
try {
|
|
||||||
|
|
||||||
File file = new File(url);
|
|
||||||
if (file.exists()) {
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
FileOutputStream writerStream = new FileOutputStream(file);
|
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8"));
|
|
||||||
writer.write(content);
|
|
||||||
writer.flush();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (writer != null) {
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFileToString(String file) {
|
|
||||||
String content = "";
|
|
||||||
// 2、建立数据通道
|
|
||||||
FileInputStream fis = null;
|
|
||||||
try {
|
|
||||||
fis = new FileInputStream(file);
|
|
||||||
byte[] buf = new byte[1024];
|
|
||||||
int length = 0;
|
|
||||||
// 循环读取文件内容,输入流中将最多buf.length个字节的数据读入一个buf数组中,返回类型是读取到的字节数。
|
|
||||||
// 当文件读取到结尾时返回 -1,循环结束。
|
|
||||||
while ((length = fis.read(buf)) != -1) {
|
|
||||||
content += new String(buf, 0, length);
|
|
||||||
}
|
|
||||||
// 最后记得,关闭流
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (fis != null) {
|
|
||||||
try {
|
|
||||||
fis.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user