|
@@ -2,6 +2,7 @@ package com.jeeplus.modules.ruralprojectrecords.web;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.jeeplus.common.config.Global;
|
|
import com.jeeplus.common.config.Global;
|
|
|
|
+import com.jeeplus.common.oss.OSSClientUtil;
|
|
import com.jeeplus.common.utils.JedisUtils;
|
|
import com.jeeplus.common.utils.JedisUtils;
|
|
import com.jeeplus.common.utils.SpringContextHolder;
|
|
import com.jeeplus.common.utils.SpringContextHolder;
|
|
import com.jeeplus.common.utils.StringUtils;
|
|
import com.jeeplus.common.utils.StringUtils;
|
|
@@ -15,6 +16,7 @@ import com.jeeplus.modules.ruralprojectrecords.enums.ProjectStatusEnum;
|
|
import com.jeeplus.modules.ruralprojectrecords.service.RuralProjectMessageElectronicSealService;
|
|
import com.jeeplus.modules.ruralprojectrecords.service.RuralProjectMessageElectronicSealService;
|
|
import com.jeeplus.modules.ruralprojectrecords.service.RuralProjectRecordsService;
|
|
import com.jeeplus.modules.ruralprojectrecords.service.RuralProjectRecordsService;
|
|
import com.jeeplus.modules.sys.entity.User;
|
|
import com.jeeplus.modules.sys.entity.User;
|
|
|
|
+import com.jeeplus.modules.sys.entity.Workattachment;
|
|
import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
import com.jeeplus.modules.sys.utils.UserUtils;
|
|
import com.jeeplus.modules.sys.utils.UserUtils;
|
|
import com.jeeplus.modules.tools.utils.SignaturePostUtil;
|
|
import com.jeeplus.modules.tools.utils.SignaturePostUtil;
|
|
@@ -25,12 +27,16 @@ import com.jeeplus.modules.workprojectnotify.service.WorkProjectNotifyService;
|
|
import com.jeeplus.modules.workprojectnotify.util.UtilNotify;
|
|
import com.jeeplus.modules.workprojectnotify.util.UtilNotify;
|
|
import org.activiti.engine.HistoryService;
|
|
import org.activiti.engine.HistoryService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
import redis.clients.jedis.Jedis;
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -41,6 +47,7 @@ import java.util.*;
|
|
@Controller
|
|
@Controller
|
|
@RequestMapping(value = "${adminPath}/ruralProject/signatureCallBack")
|
|
@RequestMapping(value = "${adminPath}/ruralProject/signatureCallBack")
|
|
public class RuralProjectSignatureCallBackController extends BaseController {
|
|
public class RuralProjectSignatureCallBackController extends BaseController {
|
|
|
|
+ private final static String directory = Global.getConfig("remoteServer.directory");
|
|
@Autowired
|
|
@Autowired
|
|
private RuralProjectRecordsService projectRecordsService;
|
|
private RuralProjectRecordsService projectRecordsService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -163,7 +170,127 @@ public class RuralProjectSignatureCallBackController extends BaseController {
|
|
String signatureUrl = null;
|
|
String signatureUrl = null;
|
|
if(StringUtils.isNotBlank(presignCallBack.getStoragePath())){
|
|
if(StringUtils.isNotBlank(presignCallBack.getStoragePath())){
|
|
signatureUrl = presignCallBack.getStoragePath().replace("oss:/","");
|
|
signatureUrl = presignCallBack.getStoragePath().replace("oss:/","");
|
|
- projectReportData.setSignatureUrl(signatureUrl);
|
|
|
|
|
|
+ if(StringUtils.isBlank(projectReportData.getSignatureUrl())){
|
|
|
|
+ projectReportData.setSignatureUrl(signatureUrl);
|
|
|
|
+
|
|
|
|
+ //将源文件下载下来进行解压并解析,保留有效的文件
|
|
|
|
+ signatureUrl = signatureUrl.replace("/xg-qz","");
|
|
|
|
+ OSSClientUtil ossClientUtil = new OSSClientUtil();
|
|
|
|
+ //将文件下载并对原有文件地址进行替换
|
|
|
|
+ String deleteFile = null;
|
|
|
|
+ String unzipFileStr = null;
|
|
|
|
+ try {
|
|
|
|
+ String path = null;
|
|
|
|
+ if (System.getProperty("os.name").toLowerCase().contains("win")) {
|
|
|
|
+ path = "D:/attachment-file/";
|
|
|
|
+ } else {
|
|
|
|
+ path = "/attachment-file/";
|
|
|
|
+ }
|
|
|
|
+ String aliyunUrl = "http://cdn.gangwaninfo.com";
|
|
|
|
+ String aliDownloadUrl = "http://oss.gangwaninfo.com";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String file = aliyunUrl + signatureUrl;
|
|
|
|
+ file = file.replace("amp;", "");
|
|
|
|
+ String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
|
|
|
|
+ String cons = "";
|
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
|
+ cons = aliyunUrl;
|
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
|
+ } else {
|
|
|
|
+ cons = aliDownloadUrl;
|
|
|
|
+ }
|
|
|
|
+ String ossKey = file.split(cons + "/")[1];
|
|
|
|
+ ossClientUtil.downQzByStreamSaveLocal(ossKey,fileName,path+fileName);
|
|
|
|
+ //将下载下来的文件转换为file文件
|
|
|
|
+ File srcFile = new File(path + fileName);
|
|
|
|
+ deleteFile = path + fileName;
|
|
|
|
+
|
|
|
|
+ //截取文件名称
|
|
|
|
+ String srcFileName = srcFile.getName().substring(0, srcFile.getName().lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ //解压后文件地址
|
|
|
|
+ unzipFileStr = path + srcFileName;
|
|
|
|
+
|
|
|
|
+ //将下载后的文件进行解压
|
|
|
|
+ SignaturePostUtil.unZipFile(srcFile, unzipFileStr);
|
|
|
|
+
|
|
|
|
+ //遍历解压后文件夹中的所有文件信息
|
|
|
|
+ File unZipFile = new File(unzipFileStr);
|
|
|
|
+
|
|
|
|
+ File[] unZipFileList = unZipFile.listFiles();
|
|
|
|
+
|
|
|
|
+ if (null != unZipFileList && unZipFileList.length > 0) {
|
|
|
|
+ for (File f : unZipFileList) {
|
|
|
|
+ String signatureFileName = f.getName();
|
|
|
|
+ //判定文件是否是以(1).pdf结尾的,如果是,则表示是正确得文件,保存到oss文件库,并提供下载连接
|
|
|
|
+ if (signatureFileName.endsWith("(1).pdf")) {
|
|
|
|
+ System.out.println("字符串以 (1).pdf 结尾");
|
|
|
|
+ String filepath = "";
|
|
|
|
+ //取得上传文件
|
|
|
|
+ //将文件上传到oss云盘中
|
|
|
|
+ MultipartFile cMultiFile = new MockMultipartFile("file", f.getName(), null, new FileInputStream(f));
|
|
|
|
+ if (!cMultiFile.isEmpty()) {
|
|
|
|
+ // 文件保存路径
|
|
|
|
+ String realPath =directory.replaceFirst("/","")+"/projectRecords" + datePath()+"/"+ System.currentTimeMillis();
|
|
|
|
+ //文件原名称
|
|
|
|
+ String newName = cMultiFile.getOriginalFilename();
|
|
|
|
+ if(StringUtils.isNotBlank(newName)){
|
|
|
|
+ newName = newName.substring(13, newName.length());
|
|
|
|
+ //SpringUtil.getBean ( IWorkAttachmentApi.class ).uploadFile2OSS(cMultiFile.getInputStream(),realPath,newName);
|
|
|
|
+ ossClientUtil.uploadFileSignatureOSS(f.getPath(),realPath,newName);
|
|
|
|
+ filepath = "/" + realPath + newName;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println(f.getName());
|
|
|
|
+ //截取文件后缀名
|
|
|
|
+ String substring = f.getName().substring(f.getName().lastIndexOf(".") + 1, f.getName().length());
|
|
|
|
+
|
|
|
|
+ String newFileName = f.getName().substring(13, f.getName().length());
|
|
|
|
+
|
|
|
|
+ //将签章完成的附件进行保存到附件表中
|
|
|
|
+ Workattachment workattachment = new Workattachment();
|
|
|
|
+ workattachment.setDelFlag("0");
|
|
|
|
+ workattachment.setUrl(filepath);
|
|
|
|
+ workattachment.setType(substring);
|
|
|
|
+ workattachment.setAttachmentName(newFileName);
|
|
|
|
+ workattachment.setAttachmentFlag("project_report_approval_file_signature");
|
|
|
|
+ workattachment.setFileSize(String.valueOf(f.length()));
|
|
|
|
+ workattachment.setAttachmentId(projectReportData.getId());
|
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
+ workattachment.setId(id);
|
|
|
|
+ workattachment.setCreateDate(new Date());
|
|
|
|
+ workattachment.setUpdateDate(new Date());
|
|
|
|
+ //先查询数据库中是否已经对数据进行保存
|
|
|
|
+ //若未保存,则进行保存,否则直接跳过
|
|
|
|
+ List<Workattachment> byAttachmentIdAndUrl = workattachmentService.getByAttachmentIdAndUrlAndAttachmentFlag(workattachment);
|
|
|
|
+ if(byAttachmentIdAndUrl.size() == 0){
|
|
|
|
+ workattachmentService.insert(workattachment);
|
|
|
|
+
|
|
|
|
+ //将附件信息添加到签章附件信息表中
|
|
|
|
+ projectReportData.setSignatureUrl(filepath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ if(StringUtils.isNotBlank(deleteFile)){
|
|
|
|
+ //根据路径创建文件对象
|
|
|
|
+ File file = new File(deleteFile);
|
|
|
|
+ //路径是个文件且不为空时删除文件
|
|
|
|
+ if(file.isFile()&&file.exists()){
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ File file = new File(unzipFileStr);
|
|
|
|
+ deleteFile(file);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
//修改签章对应信息文件
|
|
//修改签章对应信息文件
|
|
projectReportDataService.updateSignatureInfo(projectReportData);
|
|
projectReportDataService.updateSignatureInfo(projectReportData);
|
|
@@ -453,7 +580,123 @@ public class RuralProjectSignatureCallBackController extends BaseController {
|
|
String signatureUrl = null;
|
|
String signatureUrl = null;
|
|
if(StringUtils.isNotBlank(presignCallBack.getStoragePath())){
|
|
if(StringUtils.isNotBlank(presignCallBack.getStoragePath())){
|
|
signatureUrl = presignCallBack.getStoragePath().replace("oss:/","");
|
|
signatureUrl = presignCallBack.getStoragePath().replace("oss:/","");
|
|
- records.setReportSignatureUrl(signatureUrl);
|
|
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isBlank(records.getReportSignatureUrl())){
|
|
|
|
+ records.setReportSignatureUrl(signatureUrl);
|
|
|
|
+
|
|
|
|
+ //将源文件下载下来进行解压并解析,保留有效的文件
|
|
|
|
+ signatureUrl = signatureUrl.replace("/xg-qz","");
|
|
|
|
+ OSSClientUtil ossClientUtil = new OSSClientUtil();
|
|
|
|
+ //将文件下载并对原有文件地址进行替换
|
|
|
|
+ String deleteFile = null;
|
|
|
|
+ String unzipFileStr = null;
|
|
|
|
+ try {
|
|
|
|
+ String path = null;
|
|
|
|
+ if (System.getProperty("os.name").toLowerCase().contains("win")) {
|
|
|
|
+ path = "D:/attachment-file/";
|
|
|
|
+ } else {
|
|
|
|
+ path = "/attachment-file/";
|
|
|
|
+ }
|
|
|
|
+ String aliyunUrl = "http://cdn.gangwaninfo.com";
|
|
|
|
+ String aliDownloadUrl = "http://oss.gangwaninfo.com";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String file = aliyunUrl + signatureUrl;
|
|
|
|
+ file = file.replace("amp;", "");
|
|
|
|
+ String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
|
|
|
|
+ String cons = "";
|
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
|
+ cons = aliyunUrl;
|
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
|
+ } else {
|
|
|
|
+ cons = aliDownloadUrl;
|
|
|
|
+ }
|
|
|
|
+ String ossKey = file.split(cons + "/")[1];
|
|
|
|
+ ossClientUtil.downQzByStreamSaveLocal(ossKey,fileName,path+fileName);
|
|
|
|
+ //将下载下来的文件转换为file文件
|
|
|
|
+ File srcFile = new File(path + fileName);
|
|
|
|
+ deleteFile = path + fileName;
|
|
|
|
+
|
|
|
|
+ //截取文件名称
|
|
|
|
+ String srcFileName = srcFile.getName().substring(0, srcFile.getName().lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ //解压后文件地址
|
|
|
|
+ unzipFileStr = path + srcFileName;
|
|
|
|
+
|
|
|
|
+ //将下载后的文件进行解压
|
|
|
|
+ SignaturePostUtil.unZipFile(srcFile, unzipFileStr);
|
|
|
|
+
|
|
|
|
+ //遍历解压后文件夹中的所有文件信息
|
|
|
|
+ File unZipFile = new File(unzipFileStr);
|
|
|
|
+
|
|
|
|
+ File[] unZipFileList = unZipFile.listFiles();
|
|
|
|
+
|
|
|
|
+ if (null != unZipFileList && unZipFileList.length > 0) {
|
|
|
|
+ for (File f : unZipFileList) {
|
|
|
|
+ String filepath = "";
|
|
|
|
+ //取得上传文件
|
|
|
|
+ //将文件上传到oss云盘中
|
|
|
|
+ MultipartFile cMultiFile = new MockMultipartFile("file", f.getName(), null, new FileInputStream(f));
|
|
|
|
+ if (!cMultiFile.isEmpty()) {
|
|
|
|
+ // 文件保存路径
|
|
|
|
+ String realPath =directory.replaceFirst("/","")+"/projectRecords" + datePath()+"/"+ System.currentTimeMillis();
|
|
|
|
+ //文件原名称
|
|
|
|
+ String newName = cMultiFile.getOriginalFilename();
|
|
|
|
+ if(StringUtils.isNotBlank(newName)){
|
|
|
|
+ newName = newName.substring(13, newName.length());
|
|
|
|
+ //SpringUtil.getBean ( IWorkAttachmentApi.class ).uploadFile2OSS(cMultiFile.getInputStream(),realPath,newName);
|
|
|
|
+ ossClientUtil.uploadFileSignatureOSS(f.getPath(),realPath,newName);
|
|
|
|
+ filepath = "/" + realPath + newName;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println(f.getName());
|
|
|
|
+ //截取文件后缀名
|
|
|
|
+ String substring = f.getName().substring(f.getName().lastIndexOf(".") + 1, f.getName().length());
|
|
|
|
+
|
|
|
|
+ String newFileName = f.getName().substring(13, f.getName().length());
|
|
|
|
+
|
|
|
|
+ //将签章完成的附件进行保存到附件表中
|
|
|
|
+ Workattachment workattachment = new Workattachment();
|
|
|
|
+ workattachment.setDelFlag("0");
|
|
|
|
+ workattachment.setUrl(filepath);
|
|
|
|
+ workattachment.setType(substring);
|
|
|
|
+ workattachment.setAttachmentName(newFileName);
|
|
|
|
+ workattachment.setAttachmentFlag("project_report_file_signature");
|
|
|
|
+ workattachment.setFileSize(String.valueOf(f.length()));
|
|
|
|
+ workattachment.setAttachmentId(projectReportData.getId());
|
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
+ workattachment.setId(id);
|
|
|
|
+ workattachment.setCreateDate(new Date());
|
|
|
|
+ workattachment.setUpdateDate(new Date());
|
|
|
|
+ //先查询数据库中是否已经对数据进行保存
|
|
|
|
+ //若未保存,则进行保存,否则直接跳过
|
|
|
|
+ List<Workattachment> byAttachmentIdAndUrl = workattachmentService.getByAttachmentIdAndUrlAndAttachmentFlag(workattachment);
|
|
|
|
+ if(byAttachmentIdAndUrl.size() == 0){
|
|
|
|
+ workattachmentService.insert(workattachment);
|
|
|
|
+
|
|
|
|
+ //将附件信息添加到签章附件信息表中
|
|
|
|
+ records.setReportSignatureUrl(filepath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ if(StringUtils.isNotBlank(deleteFile)){
|
|
|
|
+ //根据路径创建文件对象
|
|
|
|
+ File file = new File(deleteFile);
|
|
|
|
+ //路径是个文件且不为空时删除文件
|
|
|
|
+ if(file.isFile()&&file.exists()){
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ File file = new File(unzipFileStr);
|
|
|
|
+ deleteFile(file);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
//修改签章对应信息文件
|
|
//修改签章对应信息文件
|
|
projectReportDataService.updateReportSignatureInfo(records);
|
|
projectReportDataService.updateReportSignatureInfo(records);
|
|
@@ -1390,4 +1633,41 @@ public class RuralProjectSignatureCallBackController extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ public static Boolean deleteFile(File file) {
|
|
|
|
+ //判断文件不为null或文件目录存在
|
|
|
|
+ if (file == null || !file.exists()) {
|
|
|
|
+ System.out.println("文件删除失败,请检查文件是否存在以及文件路径是否正确");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //获取目录下子文件
|
|
|
|
+ File[] files = file.listFiles();
|
|
|
|
+ //遍历该目录下的文件对象
|
|
|
|
+ for (File f : files) {
|
|
|
|
+ //判断子目录是否存在子目录,如果是文件则删除
|
|
|
|
+ if (f.isDirectory()) {
|
|
|
|
+ //递归删除目录下的文件
|
|
|
|
+ deleteFile(f);
|
|
|
|
+ } else {
|
|
|
|
+ //文件删除
|
|
|
|
+ f.delete();
|
|
|
|
+ //打印文件名
|
|
|
|
+ System.out.println("文件名:" + f.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //文件夹删除
|
|
|
|
+ file.delete();
|
|
|
|
+ System.out.println("目录名:" + file.getName());
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static String datePath(){
|
|
|
|
+
|
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
|
+ String year = String.valueOf(date.get(Calendar.YEAR));
|
|
|
|
+ String month = String.valueOf(date.get(Calendar.MONTH)+1);
|
|
|
|
+ String day = String.valueOf(date.get(Calendar.DAY_OF_MONTH));
|
|
|
|
+ String path = "/"+year+"/"+month+"/"+day;
|
|
|
|
+ return path;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|