Bläddra i källkod

项目新增报告页面修改和批量下载项目相关文件功能修改

user5 4 år sedan
förälder
incheckning
6442c88b5a

+ 34 - 0
src/main/java/com/jeeplus/common/oss/OSSClientUtil.java

@@ -649,6 +649,40 @@ public class OSSClientUtil {
             e.printStackTrace();
         }
     }
+    /**
+     * 附件下载到本地指定文件夹
+     * @param key
+     * @param fileName
+     */
+    public void downByStreamSaveLocal(String key, String fileName,String downFileStr){
+        try {
+            // 创建OSSClient实例
+            OSSObject ossObject = ossClient.getObject(bucketName, key);
+            BufferedInputStream in = new BufferedInputStream(ossObject.getObjectContent());
+
+
+            //写入到文件(注意文件保存路径的后面一定要加上文件的名称)
+            FileOutputStream fileOut = new FileOutputStream(downFileStr);
+            BufferedOutputStream bos = new BufferedOutputStream(fileOut);
+            byte[] buf = new byte[4096];
+            int length = in.read(buf);
+            //保存文件
+            while(length != -1)
+            {
+                bos.write(buf, 0, length);
+                length = in.read(buf);
+            }
+            if(bos!=null){
+                bos.flush();
+                bos.close();
+            }
+            if(in!=null){
+                in.close();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
     /**
      * 文件下载

+ 1 - 1
src/main/java/com/jeeplus/modules/projectAccessory/service/ProjectTemplateService.java

@@ -302,7 +302,7 @@ public class ProjectTemplateService extends TreeService<ProjectTemplateDao, Proj
             workattachmentService.clientAttachmentManageOnUrl(attachments);
             info.setWorkAttachments(attachments);
             //判断是否为必填项,若为必填项则添加必填判定字段
-            if(projectTemplateInfo.getRequiredStageList().indexOf(info.getRequiredStage()) != -1){
+            if(info.getRequiredStage() == projectTemplateInfo.getRequiredStage()){
                 info.setMustFlag(1);
                 //判定必填项的下的是否有附件信息
                 if (attachments.size()!=0){

+ 26 - 1
src/main/java/com/jeeplus/modules/ruralprojectrecords/service/RuralProjectRecordsService.java

@@ -91,6 +91,14 @@ import java.util.*;
 @Service
 @Transactional(readOnly = true)
 public class RuralProjectRecordsService extends CrudService<RuralProjectRecordsDao, RuralProjectRecords> {
+	/**
+	 * 阿里云文件服务器前缀
+	 */
+	private final static String aliyunUrl = Global.getConfig("aliyunUrl");
+	/**
+	 * 百度云文件服务器前缀
+	 */
+	private final static String bosUrl = Global.getConfig("bosUrl");
 
 	@Autowired
 	private RuralWorkProjectUserDao workProjectUserDao;
@@ -1541,7 +1549,14 @@ public class RuralProjectRecordsService extends CrudService<RuralProjectRecordsD
 
 			//查看送审金额是否为500w以上金额
 			//Integer approvalMoney = projectAccessoryRelationService.decideAttachmentProjectApprovalMoney(projectReportData.getReviewFee());
-			Integer approvalMoney = 2;
+			//Integer approvalMoney = 2;
+			String money=records.getSubmitMoney();
+			Integer approvalMoney=null;
+			if(com.jeeplus.common.utils.StringUtils.isBlank(money)){
+				approvalMoney=1;
+			}else{
+				approvalMoney=Integer.parseInt(money);
+			}
 			switch (approvalMoney){
 				case 0:
 					//金额为0
@@ -1642,6 +1657,16 @@ public class RuralProjectRecordsService extends CrudService<RuralProjectRecordsD
 		SftpClientUtil sftpClientUtil = new SftpClientUtil();
 		for (ProjectTemplateInfo info: projectTemplateList) {
 			List<WorkClientAttachment> workAttachments = info.getWorkAttachments();
+			/*for (WorkClientAttachment attachment: workAttachments) {
+				switch (uploadMode){
+					case "1":
+						attachment.setUrl(bosUrl + attachment.getUrl());
+						break;
+					case "2":
+						attachment.setUrl(aliyunUrl + attachment.getUrl());
+						break;
+				}
+			}*/
 			for (WorkClientAttachment attachment:workAttachments) {
 				sftpClientUtil.downloadRuralProject(attachment.getUrl().substring(0,attachment.getUrl().lastIndexOf("/")),attachment.getUrl().substring(attachment.getUrl().lastIndexOf("/") + 1, attachment.getUrl().length()),downloadPath,attachment.getAttachmentName());
 			}

+ 25 - 1
src/main/java/com/jeeplus/modules/utils/SftpClientUtil.java

@@ -8,12 +8,15 @@ import java.util.*;
 import com.jcraft.jsch.*;
 import com.jeeplus.common.bos.BOSClientUtil;
 import com.jeeplus.common.config.Global;
+import com.jeeplus.common.oss.OSSClientUtil;
 import com.jeeplus.common.utils.StringUtils;
 import org.apache.commons.fileupload.util.Streams;
 import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.io.FileUtils;
 
@@ -36,6 +39,10 @@ public class SftpClientUtil {
     private final static String directory = Global.getConfig("remoteServer.directory");
     /** 文件存储方式(0:本地服务器存储。1:云端存储) */
     private final static String uploadMode = Global.getConfig("remoteServer.uploadMode");
+    @Autowired
+    private HttpServletRequest request;
+    @Autowired
+    private HttpServletResponse response;
 
 
     /**
@@ -355,6 +362,24 @@ public class SftpClientUtil {
                     in.close();
                 }
             }
+        }else if("2".equals(uploadMode)){
+            String fileNamePath = directory +"/" + downloadFile;
+            try {
+                fileNamePath = URLDecoder.decode(fileNamePath,"UTF-8");
+                String fileName = URLEncoder.encode(fileNamePath.substring(fileNamePath.lastIndexOf("/") + 1, fileNamePath.length()),"UTF-8");
+                String key = fileNamePath.substring(1,fileNamePath.length());
+
+                //判断文件的保存路径后面是否以/结尾
+                if (!downLoadFilePath.endsWith("/")) {
+                    downLoadFilePath += "/";
+                }
+                //写入文件路径字符串
+                String downFileStr = downLoadFilePath + downloadFile;
+                new OSSClientUtil().downByStreamSaveLocal(key,fileName,downFileStr);
+
+            }catch (IOException e){
+                e.printStackTrace();
+            }
         }else{
             try{
                 String path = directory.substring(directory.indexOf("=")+1, directory.length());
@@ -400,7 +425,6 @@ public class SftpClientUtil {
         return null;
     }
 
-
     /**
      * File转MultipartFile
      * @param file

+ 2 - 2
src/main/java/com/jeeplus/modules/workprojectnotify/web/WorkProjectNotifyController.java

@@ -2922,7 +2922,7 @@ public class WorkProjectNotifyController extends BaseController {
 							relateInfo.setAttachType(mainDict.getValue());
 							switch (mainDict.getValue()) {
 								case "11":
-									List<ProjectTemplateInfo> fileAttachmentList = projectTemplateService.getProjectTemplateList(relateInfo);
+									List<ProjectTemplateInfo> fileAttachmentList = projectTemplateService.getProjectTemplateListByArchive(relateInfo);
 									for (ProjectTemplateInfo info: fileAttachmentList) {
 										info.setAttachTypes(info.getAttachTypes().toLowerCase());
 										if(engineeringId.equals(ruralProjectRecords.getEngineeringType())){
@@ -2939,7 +2939,7 @@ public class WorkProjectNotifyController extends BaseController {
 									projectReportRecord.setFileAttachmentList(fileAttachmentList);
 									break;
 								case "12":
-									List<ProjectTemplateInfo> projectTemplateList = projectTemplateService.getProjectTemplateList(relateInfo);
+									List<ProjectTemplateInfo> projectTemplateList = projectTemplateService.getProjectTemplateListByArchive(relateInfo);
 									for (ProjectTemplateInfo info: projectTemplateList) {
 										info.setAttachTypes(info.getAttachTypes().toLowerCase());
 										if(engineeringId.equals(ruralProjectRecords.getEngineeringType())){