zhoulisky 7 months ago
parent
commit
5e0b89df8b

+ 5 - 0
kd-service-api/kd-scientific-api/src/main/java/org/sky/scientific/pojo/entity/DownloadTask.java

@@ -36,6 +36,11 @@ public class DownloadTask extends TenantEntity {
 	@Size(min = 4, max = 4, message = "参数yearAndMonth格式错误,YYYY")
 	private String yearAndMonth;
 
+	@Schema(description = "完成时间")
+	@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
+	@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
+	private Date doneTime;
+
 	@Schema(description = "过期时间")
 	@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
 	@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)

+ 2 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/ScientificApplication.java

@@ -4,11 +4,13 @@ package org.sky.scientific;
 import org.sky.core.cloud.client.KdCloudApplication;
 import org.sky.core.launch.KdApplication;
 import org.sky.core.launch.constant.AppConstant;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * 科研模块启动器
  */
 @KdCloudApplication
+@EnableScheduling
 public class ScientificApplication {
 
 	public static void main(String[] args) {

+ 25 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/ArchiveCenterController.java

@@ -2,6 +2,8 @@
 package org.sky.scientific.controller;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -17,12 +19,14 @@ import org.apache.commons.compress.utils.IOUtils;
 import org.sky.core.boot.ctrl.KdController;
 import org.sky.core.secure.utils.SecureUtil;
 import org.sky.core.tool.api.R;
+import org.sky.core.tool.utils.DateUtil;
 import org.sky.scientific.mapper.DownloadTaskMapper;
 import org.sky.scientific.pojo.entity.ArchiveAttachEntity;
 import org.sky.scientific.pojo.entity.DownloadTask;
 import org.sky.scientific.service.IArchiveService;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -31,6 +35,8 @@ import java.io.*;
 import java.net.URLEncoder;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Date;
+import java.util.List;
 import java.util.zip.Deflater;
 
 /**
@@ -97,7 +103,7 @@ public class ArchiveCenterController extends KdController {
 			if (result == 1) {
 				new Thread(() -> {
 					RequestContextHolder.setRequestAttributes(requestAttributes);
-					service.downloadCenterZipFiles(task.getYearAndMonth(), task);
+					service.downloadCenterZipFiles(task);
 				}).start();
 				return R.data(task);
 			}
@@ -105,6 +111,22 @@ public class ArchiveCenterController extends KdController {
 		return R.success();
 	}
 
+	@Scheduled(cron = "0 0/5 * * * ?")
+	public void dealWithDownloadTask() {
+		//处理下载任务,主要针对未完成的任务
+		LambdaQueryWrapper<DownloadTask> wrapper = Wrappers.<DownloadTask>lambdaQuery()
+			.eq(DownloadTask::getStatus, 0)
+			.le(DownloadTask::getCreateTime, DateUtil.minusMinutes(new Date(), 5));
+		List<DownloadTask> list = downloadTaskMapper.selectList(wrapper);
+		RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+		for (DownloadTask task : list) {
+			new Thread(() -> {
+				RequestContextHolder.setRequestAttributes(requestAttributes);
+				service.downloadCenterZipFiles(task);
+			}).start();
+		}
+	}
+
 	@SneakyThrows
 	@GetMapping("center/download")
 	@ApiOperationSupport(order = 6)
@@ -138,7 +160,9 @@ public class ArchiveCenterController extends KdController {
 				zos.setEncoding("UTF-8"); // 支持中文文件名
 				zos.setLevel(Deflater.BEST_SPEED);
 
+				Date date = new Date();
 				compressFolderWithApache(folder, folder.getName(), zos);
+				log.info("压缩耗时:{}秒", (new Date().getTime() - date.getTime()) / 1000);
 
 				zos.finish();
 				response.flushBuffer();

+ 1 - 3
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/IArchiveService.java

@@ -23,9 +23,7 @@ public interface IArchiveService {
 
 	void downloadFjbczlZipFiles(HttpServletRequest request, HttpServletResponse response, String year);
 
-	void downloadCenterZipFiles(String year, DownloadTask task);
+	void downloadCenterZipFiles(DownloadTask task);
 
-	void downloadHighTechZipFiles(HttpServletRequest request, HttpServletResponse response, String year);
 
-	void downloadDeductionZipFiles(HttpServletRequest request, HttpServletResponse response, String year);
 }

+ 85 - 64
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/ArchiveServiceImpl.java

@@ -278,17 +278,22 @@ public class ArchiveServiceImpl implements IArchiveService {
 	}
 
 	@Override
-	public void downloadCenterZipFiles(String year, DownloadTask task) {
+	public void downloadCenterZipFiles(DownloadTask task) {
+		String year = task.getYearAndMonth();
 		if (Func.isBlank(year)) {
 			throw new ServiceException("参数year不能为空");
 		}
 		String dir;
+		List<Integer> types = null;
 		if (task.getType() == 0) {
 			dir = "全部档案资料";
+			types = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
 		} else if (task.getType() == 1) {
 			dir = "高新备查资料";
+ 			types = Arrays.asList(1, 2, 4, 5, 7, 9, 11, 14, 21, 22, 23, 25, 27);
 		} else {
 			dir = "加计扣除备查资料";
+ 			types = Arrays.asList(3, 4, 6, 8, 10, 13, 15, 19, 20, 26, 28);
 		}
 		Date date = new Date();
 
@@ -304,63 +309,80 @@ public class ArchiveServiceImpl implements IArchiveService {
 		List<CompletableFuture<Void>> futureList = new ArrayList<>();
 
 		ArchiveAttachEntity finalArchiveAttach = archiveAttach;
+		List<Integer> finalTypes = types;
 		futureList.add(CompletableFuture.runAsync(() -> {
 			RequestContextHolder.setRequestAttributes(requestAttributes);
-			//1 高新技术企业资格证书:基础资源管理-企业基本信息-高企证书上传(按年度)。未上传则为空
-			generateD1(Paths.get(basePath.toString(), "1.高新技术企业资格证书"), year);
-			//2 高新技术企业认定资料:附件补充
-			Path path2 = FileUtil.mkdir(Paths.get(basePath.toString(), "2.高新技术企业认定资料"));
-			this.downloadAttachFiles(path2, Collections.singletonList(finalArchiveAttach.getD3()));
-			//3 加计扣除情况说明:附件补充
-			Path path3 = FileUtil.mkdir(Paths.get(basePath.toString(), "3.加计扣除情况说明"));
-			this.downloadAttachFiles(path3, Collections.singletonList(finalArchiveAttach.getD10()));
-			//4 研发立项决议文件:附件补充
-			Path path4 = FileUtil.mkdir(Paths.get(basePath.toString(), "4.研发立项决议文件"));
-			this.downloadAttachFiles(path4, Collections.singletonList(finalArchiveAttach.getD13()));
-
-			//5 高新研发项目汇总表:对外报表-高新口径研发费用报表-高新-研发项目清单表
-			generateD5(Paths.get(basePath.toString(), "5.高新研发项目汇总表"), year, 2);
-			//6 加计扣除研发项目汇总表:对外报表-加计扣除口径研发费用报表-加计扣除-研发项目清单表
-			generateD5(Paths.get(basePath.toString(), "6.加计扣除研发项目汇总表"), year, 3);
+			if(finalTypes.contains(1)){
+				//1 高新技术企业资格证书:基础资源管理-企业基本信息-高企证书上传(按年度)。未上传则为空
+				generateD1(Paths.get(basePath.toString(), "1.高新技术企业资格证书"), year);
+			}
+			if(finalTypes.contains(2)) {
+				//2 高新技术企业认定资料:附件补充
+				Path path2 = FileUtil.mkdir(Paths.get(basePath.toString(), "2.高新技术企业认定资料"));
+				this.downloadAttachFiles(path2, Collections.singletonList(finalArchiveAttach.getD3()));
+			}
+			if(finalTypes.contains(2)){
+				//3 加计扣除情况说明:附件补充
+				Path path3 = FileUtil.mkdir(Paths.get(basePath.toString(), "3.加计扣除情况说明"));
+				this.downloadAttachFiles(path3, Collections.singletonList(finalArchiveAttach.getD10()));
+			}
+			if(finalTypes.contains(2)){
+				//4 研发立项决议文件:附件补充
+				Path path4 = FileUtil.mkdir(Paths.get(basePath.toString(), "4.研发立项决议文件"));
+				this.downloadAttachFiles(path4, Collections.singletonList(finalArchiveAttach.getD13()));
+			}
+			if(finalTypes.contains(2)){
+				//5 高新研发项目汇总表:对外报表-高新口径研发费用报表-高新-研发项目清单表
+				generateD5(Paths.get(basePath.toString(), "5.高新研发项目汇总表"), year, 2);
+			}
+			if(finalTypes.contains(2)){
+				//6 加计扣除研发项目汇总表:对外报表-加计扣除口径研发费用报表-加计扣除-研发项目清单表
+				generateD5(Paths.get(basePath.toString(), "6.加计扣除研发项目汇总表"), year, 3);
+			}
 		}));
 
-		Path path7 = FileUtil.mkdir(Paths.get(basePath.toString(), "7.高新研发项目全套技术资料"));
-		XmFinanceEntity dto = new XmFinanceEntity();
-		dto.setYearAndMonth(year);
-		dto.setType(2);
-		List<XmFinanceEntity> list = xmFinanceService.selectXmFinanceList(dto);
-		AtomicInteger index = new AtomicInteger(1);
-		for (XmFinanceEntity xm : list) {
-			AtomicInteger finalIndex = index;
-			futureList.add(CompletableFuture.runAsync(() -> {
-				RequestContextHolder.setRequestAttributes(requestAttributes);
-				generateD7(path7, finalIndex.get(), xm);
-				finalIndex.incrementAndGet();
-			}));
+		if(types.contains(7)){
+			Path path7 = FileUtil.mkdir(Paths.get(basePath.toString(), "7.高新研发项目全套技术资料"));
+			XmFinanceEntity dto = new XmFinanceEntity();
+			dto.setYearAndMonth(year);
+			dto.setType(2);
+			List<XmFinanceEntity> list = xmFinanceService.selectXmFinanceList(dto);
+			AtomicInteger index = new AtomicInteger(1);
+			for (XmFinanceEntity xm : list) {
+				futureList.add(CompletableFuture.runAsync(() -> {
+					RequestContextHolder.setRequestAttributes(requestAttributes);
+					generateD7(path7, index.get(), xm);
+					index.incrementAndGet();
+				}));
+			}
 		}
-
-		Path path8 = FileUtil.mkdir(Paths.get(basePath.toString(), "8.加计扣除研发项目全套技术资料"));
-		dto = new XmFinanceEntity();
-		dto.setYearAndMonth(year);
-		dto.setType(3);
-		list = xmFinanceService.selectXmFinanceList(dto);
-		index = new AtomicInteger(1);
-		for (XmFinanceEntity xm : list) {
-			AtomicInteger finalIndex = index;
-			futureList.add(CompletableFuture.runAsync(() -> {
-				RequestContextHolder.setRequestAttributes(requestAttributes);
-				generateD7(path8, finalIndex.get(), xm);
-				finalIndex.incrementAndGet();
-			}));
-			index.incrementAndGet();
+		if(types.contains(8)){
+			Path path8 = FileUtil.mkdir(Paths.get(basePath.toString(), "8.加计扣除研发项目全套技术资料"));
+			XmFinanceEntity dto = new XmFinanceEntity();
+			dto.setYearAndMonth(year);
+			dto.setType(3);
+			List<XmFinanceEntity> list = xmFinanceService.selectXmFinanceList(dto);
+			AtomicInteger index = new AtomicInteger(1);
+			for (XmFinanceEntity xm : list) {
+				futureList.add(CompletableFuture.runAsync(() -> {
+					RequestContextHolder.setRequestAttributes(requestAttributes);
+					generateD7(path8, index.get(), xm);
+					index.incrementAndGet();
+				}));
+				index.incrementAndGet();
+			}
 		}
 
 		futureList.add(CompletableFuture.runAsync(() -> {
 			RequestContextHolder.setRequestAttributes(requestAttributes);
-			//9 高新研发人员与科技人员资料:改成高新科技人员资料:即科技人员管理-年高新科技人员汇总表资料表,选出:对外报表-高新口径研发费用报表-高新-研发项目清单中项目人员汇总
-			generateD9(Paths.get(basePath.toString(), "9.高新科技人员资料"), year, finalArchiveAttach.getD6());
-			//10 加计扣除研发人员与科技人员资料:改成加计扣除项目科研人员资料:即科技人员管理-项目人员汇总表,选出:对外报表-加计扣除口径研发费用报表-加计扣除-研发项目清单中项目人员汇总
-			generateD10(Paths.get(basePath.toString(), "10.加计扣除项目科研人员资料"), year);
+			if(finalTypes.contains(9)){
+				//9 高新研发人员与科技人员资料:改成高新科技人员资料:即科技人员管理-年高新科技人员汇总表资料表,选出:对外报表-高新口径研发费用报表-高新-研发项目清单中项目人员汇总
+				generateD9(Paths.get(basePath.toString(), "9.高新科技人员资料"), year, finalArchiveAttach.getD6());
+			}
+			if(finalTypes.contains(10)){
+				//10 加计扣除研发人员与科技人员资料:改成加计扣除项目科研人员资料:即科技人员管理-项目人员汇总表,选出:对外报表-加计扣除口径研发费用报表-加计扣除-研发项目清单中项目人员汇总
+				generateD10(Paths.get(basePath.toString(), "10.加计扣除项目科研人员资料"), year);
+			}
 		}));
 
 		futureList.add(CompletableFuture.runAsync(() -> {
@@ -406,7 +428,7 @@ public class ArchiveServiceImpl implements IArchiveService {
 
 		//18.高新研发费用附件凭证资料及相关说明:对外报表-高新口径研发费用报表-高新-研发项目(见列表详细)
 		Path path18 = FileUtil.mkdir(Paths.get(basePath.toString(), "18.高新研发费用附件支持资料及相关说明"));
- 		try {
+		try {
 			XmFinanceEntity dto2 = new XmFinanceEntity();
 			dto2.setYearAndMonth(year);
 			dto2.setType(2);
@@ -417,7 +439,7 @@ public class ArchiveServiceImpl implements IArchiveService {
 
 		//19.加计扣除研发费用附件凭证资料及相关说明:对外报表-加计扣除口径研发费用报表-加计扣除-研发项目(见列表详细)
 		Path path19 = FileUtil.mkdir(Paths.get(basePath.toString(), "19.加计扣除研发费用附件支撑资料及相关说明"));
-  		try {
+		try {
 			XmFinanceEntity dto2 = new XmFinanceEntity();
 			dto2.setYearAndMonth(year);
 			dto2.setType(3);
@@ -457,12 +479,21 @@ public class ArchiveServiceImpl implements IArchiveService {
 			Path path28 = FileUtil.mkdir(Paths.get(basePath.toString(), "28.其他加计扣除备查资料"));
 			this.downloadAttachFiles(path28, Collections.singletonList(finalArchiveAttach.getD12()));
 		}));
- 		CompletableFuture.allOf(futureList.toArray(new CompletableFuture[futureList.size()])).join();
+		CompletableFuture.allOf(futureList.toArray(new CompletableFuture[futureList.size()])).join();
+		log.info("一键导出耗时:{}", (new Date().getTime() - date.getTime()) / 1000 + "秒");
 		//设置任务状态为 已完成
 		task.setStatus(2);
+		task.setDoneTime(new Date());
 		task.setExpireTime(DateUtil.plusDays(new Date(), 1));
 		downloadTaskMapper.updateById(task);
-		System.out.println("一键导出耗时:" + (new Date().getTime() - date.getTime()) / 1000 + "秒");
+	}
+
+	private void downloadHighTechZipFiles(DownloadTask task) {
+
+	}
+
+	private void downloadDeductionZipFiles(DownloadTask task) {
+
 	}
 
 	private void generateD17(Path path, List<XmFinanceEntity> list, String year, List<CompletableFuture<Void>> futureList) {
@@ -514,7 +545,7 @@ public class ArchiveServiceImpl implements IArchiveService {
 			Path path17_2_1_2 = FileUtil.mkdir(Paths.get(path17_2_1.toString(), "2.研发领料单"));
 			futureList.add(CompletableFuture.runAsync(() -> {
 				RequestContextHolder.setRequestAttributes(requestAttributes);
- 				generateD17_2_1_2(year, path17_2_1_2, xm.getXmId(), "材料");
+				generateD17_2_1_2(year, path17_2_1_2, xm.getXmId(), "材料");
 			}));
 
 			//2-1-3.研发燃料耗用单
@@ -1377,14 +1408,4 @@ public class ArchiveServiceImpl implements IArchiveService {
 		return true;
 	}
 
-	@Override
-	public void downloadHighTechZipFiles(HttpServletRequest request, HttpServletResponse response, String year) {
-
-	}
-
-	@Override
-	public void downloadDeductionZipFiles(HttpServletRequest request, HttpServletResponse response, String year) {
-
-	}
-
 }

BIN
kd-service/kd-scientific/src/main/resources/export-template/每月考勤信息.xls