|
@@ -1,17 +1,47 @@
|
|
|
package com.jeeplus.test.cw.projectReport.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
+import com.jeeplus.common.redis.RedisUtils;
|
|
|
+import com.jeeplus.flowable.model.Flow;
|
|
|
+import com.jeeplus.flowable.service.FlowTaskService;
|
|
|
import com.jeeplus.sys.utils.Global;
|
|
|
import com.jeeplus.sys.utils.SpringContextHolder;
|
|
|
+import com.jeeplus.test.cw.common.flowable.dto.CommitParamDTO;
|
|
|
+import com.jeeplus.test.cw.projectRecords.domain.CwProjectRecords;
|
|
|
+import com.jeeplus.test.cw.projectRecords.service.dto.CwProjectRecordsDTO;
|
|
|
+import com.jeeplus.test.cw.projectReport.domain.CwProjectReport;
|
|
|
import com.jeeplus.test.cw.projectReport.domain.CwProjectReportData;
|
|
|
+import com.jeeplus.test.cw.projectReport.domain.CwProjectReportSignature;
|
|
|
+import com.jeeplus.test.cw.projectReport.mapper.CwProjectReportSignatureMapper;
|
|
|
+import com.jeeplus.test.cw.projectReport.mapper.ProjectReportWorkAttachmentMapper;
|
|
|
import com.jeeplus.test.cw.projectReport.service.CwProjectReportService;
|
|
|
+import com.jeeplus.test.oss.domain.WorkAttachment;
|
|
|
+import com.jeeplus.test.oss.service.OSSClientService;
|
|
|
import com.jeeplus.test.signature.domain.PresignCallBack;
|
|
|
+import com.jeeplus.test.signature.utils.SignaturePostUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.flowable.engine.TaskService;
|
|
|
+import org.flowable.task.api.Task;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.connection.jedis.JedisUtils;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.core.userdetails.User;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -25,8 +55,14 @@ import java.util.*;
|
|
|
public class CwProjectReportSignatureCallBackController {
|
|
|
|
|
|
|
|
|
- private CwProjectReportService cwProjectReportService = SpringContextHolder.getBean(CwProjectReportService.class);
|
|
|
+ private static final String DIRECTORY = "/attachment-file";
|
|
|
+
|
|
|
+ private static final String ALIYUNURL = "http://oss.gangwaninfo.com";
|
|
|
|
|
|
+ private CwProjectReportService cwProjectReportService = SpringContextHolder.getBean(CwProjectReportService.class);
|
|
|
+ private OSSClientService ossClientService = SpringContextHolder.getBean(OSSClientService.class);
|
|
|
+ private CwProjectReportSignatureMapper cwProjectReportSignatureMapper = SpringContextHolder.getBean(CwProjectReportSignatureMapper.class);
|
|
|
+ private ProjectReportWorkAttachmentMapper attachmentMapper = SpringContextHolder.getBean(ProjectReportWorkAttachmentMapper.class);
|
|
|
|
|
|
private static final String HTTPTOP = Global.getConfig("signature_http_top");
|
|
|
|
|
@@ -34,6 +70,13 @@ public class CwProjectReportSignatureCallBackController {
|
|
|
private final static String appsecret = Global.getConfig("appsecret");
|
|
|
private final static String signature = Global.getConfig("signature");
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+ @Autowired
|
|
|
+ private FlowTaskService flowTaskService;
|
|
|
+ @Autowired
|
|
|
+ private TaskService taskService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 审定单签章回调操作(个人职业章盖章)
|
|
@@ -41,25 +84,88 @@ public class CwProjectReportSignatureCallBackController {
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getApprovalCallBackCoordinates", method= RequestMethod.POST)
|
|
|
- public String getApprovalCallBackCoordinates(PresignCallBack presignCallBack) throws Exception {
|
|
|
+ public String getApprovalCallBackCoordinates(PresignCallBack presignCallBack, HttpServletResponse response) throws Exception {
|
|
|
+ // 在redis中取回流程审核所需的参数
|
|
|
+ CommitParamDTO<CwProjectReportData> commitParamDTO = (CommitParamDTO<CwProjectReportData>)redisUtils.get("cw_report_signature_" + presignCallBack.getContractId());
|
|
|
+ // 将取回的数据转换为审核通过所需要的参数
|
|
|
+ Map<String, Object> vars = Maps.newHashMap();
|
|
|
+ Flow flow = new Flow();
|
|
|
+ flow.setTaskId(commitParamDTO.getTaskId());
|
|
|
+ flow.setTaskDefKey(commitParamDTO.getTaskDefKey());
|
|
|
+ flow.setProcInsId(commitParamDTO.getProcInsId());
|
|
|
+ flow.setProcDefId(commitParamDTO.getProcDefId());
|
|
|
+ flow.setAssignee(commitParamDTO.getAssignee());
|
|
|
+ flow.setComment(commitParamDTO.getComment());
|
|
|
+ Map<String, String> stringObjectMap = JSON.parseObject(JSON.toJSONString(commitParamDTO.getVars()), new TypeReference<Map<String, String>>() {});
|
|
|
+ for (Map.Entry<String, String> entry : stringObjectMap.entrySet()) {
|
|
|
+ String value = entry.getValue();
|
|
|
+ if("true".equals(value) || "false".equals(value)){
|
|
|
+ vars.put(entry.getKey(), Boolean.valueOf(value).booleanValue());
|
|
|
+ }else{
|
|
|
+ vars.put(entry.getKey(), value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 流程节点审核通过
|
|
|
+ flowTaskService.auditSave(flow, vars);
|
|
|
+ CwProjectReport cwProjectReport = cwProjectReportService.list(new QueryWrapper<CwProjectReport>().lambda().eq(CwProjectReport::getSignatureContractId, presignCallBack.getContractId())).get(0);
|
|
|
+ // 指定下一步处理人
|
|
|
+ Task task = taskService.createTaskQuery().processInstanceId(flow.getProcInsId()).active().singleResult();
|
|
|
+ // task为null时,则当前节点为最后一个审核节点
|
|
|
+ if(task != null){
|
|
|
+ if(StringUtils.isNotBlank(flow.getAssignee ())){
|
|
|
+ taskService.setAssignee(task.getId(), flow.getAssignee ());
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(cwProjectReport)) {
|
|
|
+ CwProjectReportSignature cwProjectReportSignature = cwProjectReportSignatureMapper.selectOne(new QueryWrapper<CwProjectReportSignature>().lambda()
|
|
|
+ .eq(CwProjectReportSignature::getReportId, cwProjectReport.getId())
|
|
|
+ .eq(CwProjectReportSignature::getType, cwProjectReport.getSignatureType())
|
|
|
+ );
|
|
|
+ if ("2".equals(cwProjectReportSignature.getStatus())){
|
|
|
+ cwProjectReportSignature.setStatus("6");
|
|
|
+ cwProjectReportSignatureMapper.updateById(cwProjectReportSignature);
|
|
|
+ }else if ("6".equals(cwProjectReportSignature.getStatus())){
|
|
|
+ cwProjectReportSignature.setStatus("7");
|
|
|
+ cwProjectReportSignatureMapper.updateById(cwProjectReportSignature);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 修改数据流程状态为->审核通过
|
|
|
+ if(ObjectUtil.isNotEmpty(cwProjectReport)) {
|
|
|
+ CwProjectReportSignature cwProjectReportSignature = cwProjectReportSignatureMapper.selectOne(new QueryWrapper<CwProjectReportSignature>().lambda()
|
|
|
+ .eq(CwProjectReportSignature::getReportId, cwProjectReport.getId())
|
|
|
+ .eq(CwProjectReportSignature::getType, cwProjectReport.getSignatureType())
|
|
|
+ );
|
|
|
+ cwProjectReportSignature.setStatus("5");
|
|
|
+ cwProjectReportSignatureMapper.updateById(cwProjectReportSignature);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除redis中的数据
|
|
|
+ redisUtils.delete("cw_report_signature_" + presignCallBack.getContractId());
|
|
|
|
|
|
- /*Jedis jedis = JedisUtils.getResource();
|
|
|
- String contractIdRedis = jedis.get("qiyuesuo" + presignCallBack.getContractId());
|
|
|
- String auditUsersStr = jedis.get("qiyuesuoAuditUserList" + presignCallBack.getContractId());
|
|
|
- Gson gson = new Gson();
|
|
|
- ProjectApprovalSignature projectApprovalSignature1 = gson.fromJson(contractIdRedis, ProjectApprovalSignature.class);
|
|
|
|
|
|
- Type listType = new TypeToken<ArrayList<User>>(){}.getType();
|
|
|
- List<User> auditUserList = new Gson().fromJson(auditUsersStr, listType);
|
|
|
|
|
|
- //根据contractId查询对应的报告信息
|
|
|
- CwProjectReportData projectReportData = cwProjectReportService.queryById(projectApprovalSignature1.getId());
|
|
|
|
|
|
- if(null == projectReportData){
|
|
|
- return null;
|
|
|
- }
|
|
|
- //根据项目id查询对应的审定单数据状态是否是已经被送审
|
|
|
- ProjectApprovalSignature projectApprovalSignature = cwProjectReportService.getProjectApprovalSignature(projectReportData.getId());*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// Jedis jedis = JedisUtils.getResource();
|
|
|
+// String contractIdRedis = jedis.get("qiyuesuo" + presignCallBack.getContractId());
|
|
|
+// String auditUsersStr = jedis.get("qiyuesuoAuditUserList" + presignCallBack.getContractId());
|
|
|
+// Gson gson = new Gson();
|
|
|
+// ProjectApprovalSignature projectApprovalSignature1 = gson.fromJson(contractIdRedis, ProjectApprovalSignature.class);
|
|
|
+//
|
|
|
+// Type listType = new TypeToken<ArrayList<User>>(){}.getType();
|
|
|
+// List<User> auditUserList = new Gson().fromJson(auditUsersStr, listType);
|
|
|
+//
|
|
|
+// //根据contractId查询对应的报告信息
|
|
|
+// CwProjectReportData projectReportData = cwProjectReportService.queryById(projectApprovalSignature1.getId());
|
|
|
+//
|
|
|
+// if(null == projectReportData){
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// //根据项目id查询对应的审定单数据状态是否是已经被送审
|
|
|
+// ProjectApprovalSignature projectApprovalSignature = cwProjectReportService.getProjectApprovalSignature(projectReportData.getId());
|
|
|
|
|
|
//对数据进以及流程行处理
|
|
|
//approvalSaveAudit(projectApprovalSignature1,auditUserList);
|
|
@@ -68,4 +174,253 @@ public class CwProjectReportSignatureCallBackController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @RequestMapping(value = "/getApprovalCallBackAccomplish", method= RequestMethod.POST)
|
|
|
+ public String getApprovalCallBackAccomplish(PresignCallBack presignCallBack, HttpServletResponse response) {
|
|
|
+// //根据contractId查询对应的报告信息
|
|
|
+ CwProjectReportData projectReportData = cwProjectReportService.queryByContractId(presignCallBack.getContractId());
|
|
|
+ //对文件回调路径进行处理并保存
|
|
|
+ String signatureUrl = null;
|
|
|
+ if(StringUtils.isNotBlank(presignCallBack.getStoragePath())){
|
|
|
+ signatureUrl = presignCallBack.getStoragePath().replace("oss:/","");
|
|
|
+ signatureUrl = signatureUrl.replace("/xg-qz","");
|
|
|
+ projectReportData.setSignatureUrl(signatureUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ //将签章完成地址保存到数据库对应报告信息中
|
|
|
+ cwProjectReportService.updateSignatureUrl(projectReportData);
|
|
|
+
|
|
|
+
|
|
|
+ //将文件下载并对原有文件地址进行替换
|
|
|
+ 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 = Global.getAliyunUrl();
|
|
|
+ String aliDownloadUrl = Global.getAliDownloadUrl();
|
|
|
+
|
|
|
+
|
|
|
+ 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];
|
|
|
+ ossClientService.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();
|
|
|
+
|
|
|
+ for (File f : unZipFileList) {
|
|
|
+ String filepath = "";
|
|
|
+ //取得上传文件
|
|
|
+ //将文件上传到oss云盘中
|
|
|
+ MultipartFile cMultiFile = new MockMultipartFile("file", f.getName(), null, new FileInputStream(f));
|
|
|
+ if (cMultiFile != null && !cMultiFile.isEmpty()) {
|
|
|
+ // 文件保存路径
|
|
|
+ String realPath =DIRECTORY.replace("/","")+"/cw_project_report_file"+ossClientService.datePath()+"/"+ System.currentTimeMillis();
|
|
|
+ //文件原名称
|
|
|
+ String newName = cMultiFile.getOriginalFilename();
|
|
|
+ newName = newName.substring(13, newName.length());
|
|
|
+ ossClientService.uploadFile2OSS(cMultiFile.getInputStream(),realPath,newName);
|
|
|
+ filepath = "/" + realPath + newName;
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println(f.getName());
|
|
|
+ //截取文件后缀名
|
|
|
+ String substring = f.getName().substring(f.getName().lastIndexOf(".")+1, f.getName().length());
|
|
|
+ //遍历该contractId对应的报告信息,将报告信息中的附件地址进行替换
|
|
|
+
|
|
|
+ //查询报告文件信息(电子章)
|
|
|
+ List<WorkAttachment> fileList = attachmentMapper.selectWorkAttachmentByReportId(projectReportData.getId());
|
|
|
+ if(fileList.size()>0){
|
|
|
+ for (WorkAttachment workattachment : fileList) {
|
|
|
+ //根据url截取文件名成
|
|
|
+ String workattachmentName = workattachment.getUrl().substring(workattachment.getUrl().lastIndexOf("/")+1, workattachment.getUrl().length());
|
|
|
+
|
|
|
+ if(f.getName().contains(workattachmentName)){
|
|
|
+ workattachment.setUrl(filepath);
|
|
|
+ workattachment.setType(substring);
|
|
|
+ workattachment.setAttachmentName(f.getName());
|
|
|
+ attachmentMapper.updateByIdOnSignature(workattachment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping(value = "/download", method= RequestMethod.POST)
|
|
|
+ public String download(String signatureUrl) {
|
|
|
+// //根据contractId查询对应的报告信息
|
|
|
+ CwProjectReportData projectReportData = cwProjectReportService.queryByContractId("3032604994397941821");
|
|
|
+
|
|
|
+ //将文件下载并对原有文件地址进行替换
|
|
|
+ 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 = Global.getAliyunUrl();
|
|
|
+ String aliDownloadUrl = Global.getAliDownloadUrl();
|
|
|
+
|
|
|
+
|
|
|
+ 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];
|
|
|
+ ossClientService.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();
|
|
|
+
|
|
|
+ for (File f : unZipFileList) {
|
|
|
+ String filepath = "";
|
|
|
+ //取得上传文件
|
|
|
+ //将文件上传到oss云盘中
|
|
|
+ MultipartFile cMultiFile = new MockMultipartFile("file", f.getName(), null, new FileInputStream(f));
|
|
|
+ if (cMultiFile != null && !cMultiFile.isEmpty()) {
|
|
|
+ // 文件保存路径
|
|
|
+ String realPath =DIRECTORY.replace("/","")+"/cw_project_report_file"+ossClientService.datePath()+"/"+ System.currentTimeMillis();
|
|
|
+ //文件原名称
|
|
|
+ String newName = cMultiFile.getOriginalFilename();
|
|
|
+ newName = newName.substring(13, newName.length());
|
|
|
+ ossClientService.uploadFile2OSS(cMultiFile.getInputStream(),realPath,newName);
|
|
|
+ filepath = "/" + realPath + newName;
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println(f.getName());
|
|
|
+ //截取文件后缀名
|
|
|
+ String substring = f.getName().substring(f.getName().lastIndexOf(".")+1, f.getName().length());
|
|
|
+ //遍历该contractId对应的报告信息,将报告信息中的附件地址进行替换
|
|
|
+
|
|
|
+ //查询报告文件信息(电子章)
|
|
|
+ List<WorkAttachment> fileList = attachmentMapper.selectWorkAttachmentByReportId(projectReportData.getId());
|
|
|
+ if(fileList.size()>0){
|
|
|
+ for (WorkAttachment workattachment : fileList) {
|
|
|
+ //根据url截取文件名成
|
|
|
+ String workattachmentName = workattachment.getUrl().substring(workattachment.getUrl().lastIndexOf("/")+1, workattachment.getUrl().length());
|
|
|
+
|
|
|
+ if(f.getName().contains(workattachmentName)){
|
|
|
+ workattachment.setUrl(filepath);
|
|
|
+ workattachment.setType(substring);
|
|
|
+ workattachment.setAttachmentName(f.getName());
|
|
|
+ attachmentMapper.updateByIdOnSignature(workattachment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|