|
|
@@ -3,13 +3,19 @@ package com.yccrc.kede.controller.ent;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
+import com.deepoove.poi.data.Pictures;
|
|
|
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
import com.mchange.io.FileUtils;
|
|
|
import com.yccrc.common.annotation.Log;
|
|
|
import com.yccrc.common.config.YccrcConfig;
|
|
|
+import com.yccrc.common.constant.Constants;
|
|
|
import com.yccrc.common.core.controller.BaseController;
|
|
|
import com.yccrc.common.core.domain.entity.SysUser;
|
|
|
import com.yccrc.common.enums.BusinessType;
|
|
|
@@ -22,6 +28,8 @@ import com.yccrc.kede.domain.Enterprise;
|
|
|
import com.yccrc.kede.domain.EnterpriseProject;
|
|
|
import com.yccrc.kede.domain.EnterpriseYearInfo;
|
|
|
import com.yccrc.kede.enums.AttachTypeEnum;
|
|
|
+import com.yccrc.kede.enums.EntIndustryTypeEnum;
|
|
|
+import com.yccrc.kede.enums.EntProjectTypeEnum;
|
|
|
import com.yccrc.kede.service.*;
|
|
|
import com.yccrc.kede.vo.ProjectHeadAddVO;
|
|
|
import com.yccrc.kede.vo.ProjectQueryVO;
|
|
|
@@ -29,18 +37,17 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.zip.ZipEntry;
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
@@ -197,6 +204,11 @@ public class EntProjectController extends BaseController {
|
|
|
for (Integer projectId : projectIds) {
|
|
|
EnterpriseProject pro = enterpriseProjectService.getById(projectId);
|
|
|
if (pro != null) {
|
|
|
+ // 生成doc模版
|
|
|
+ uploadBasicInfo(projectId, pro.getEntId(), pro.getProjectYear());
|
|
|
+ uploadProjectInfo(projectId);
|
|
|
+
|
|
|
+
|
|
|
downloadFileName += pro.getProjectName() + "_";
|
|
|
// 企业项目申报上传文件
|
|
|
List<Attach> attachEntList = attachService.lambdaQuery()
|
|
|
@@ -205,8 +217,13 @@ public class EntProjectController extends BaseController {
|
|
|
.in(Attach::getFileType, "file1", "file2", "file3", "file4", "file5",
|
|
|
"file6", "file7", "file8", "file9", "file10", "file11")
|
|
|
.list();
|
|
|
-
|
|
|
- if (!CollectionUtil.isEmpty(attachEntList)) {
|
|
|
+ List<Attach> docList = attachService.lambdaQuery()
|
|
|
+ .eq(Attach::getAttachType, AttachTypeEnum.DOC)
|
|
|
+ .eq(Attach::getDataId, pro.getId())
|
|
|
+ .in(Attach::getFileType, "doc1", "doc2")
|
|
|
+ .list();
|
|
|
+ if (!CollectionUtil.isEmpty(attachEntList) || !CollectionUtil.isEmpty(docList)) {
|
|
|
+ attachEntList.addAll(docList);
|
|
|
logger.info("打包企业资料");
|
|
|
ArrayList<String> fileList = new ArrayList<>();
|
|
|
for (Attach attach : attachEntList) {
|
|
|
@@ -250,4 +267,118 @@ public class EntProjectController extends BaseController {
|
|
|
IOUtils.write(data, response.getOutputStream());
|
|
|
}
|
|
|
|
|
|
+ public void uploadBasicInfo(Integer projectId, Integer entId, String projectYear) throws IOException {
|
|
|
+ EnterpriseYearInfo one = enterpriseYearInfoService.getOne(new LambdaQueryWrapper<EnterpriseYearInfo>()
|
|
|
+ .eq(EnterpriseYearInfo::getProjectYear, projectYear)
|
|
|
+ .eq(EnterpriseYearInfo::getEntId, entId)
|
|
|
+ );
|
|
|
+ ProjectQueryVO project = new ProjectQueryVO();
|
|
|
+ project.setEntId(entId);
|
|
|
+ project.setYear(projectYear);
|
|
|
+ Page<EnterpriseProject> list = enterpriseProjectService.selectList(project);
|
|
|
+
|
|
|
+ // 封装数据
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("one", one);
|
|
|
+ params.put("list", list.getRecords());
|
|
|
+ // 单选按钮
|
|
|
+ params.put("innovateFlag", (one.getInnovateFlag() != null && one.getInnovateFlag()) ? "是" : "否");
|
|
|
+ params.put("smallFlag", (one.getSmallFlag() != null && one.getSmallFlag()) ? "是" : "否");
|
|
|
+ params.put("techFlag", (one.getTechFlag() != null && one.getTechFlag()) ? "是" : "否");
|
|
|
+ // 时间
|
|
|
+ params.put("techStartDate", StringUtils.isNotEmpty(one.getTechStartDate())
|
|
|
+ ? one.getTechStartDate().replaceAll("(\\d{4})-(\\d{2})-(\\d{2})", "$1年$2月$3日")
|
|
|
+ : "");
|
|
|
+ params.put("techEndDate", StringUtils.isNotEmpty(one.getTechEndDate())
|
|
|
+ ? one.getTechEndDate().replaceAll("(\\d{4})-(\\d{2})-(\\d{2})", "$1年$2月$3日")
|
|
|
+ : "");
|
|
|
+ // 图片
|
|
|
+ params.put("image", Pictures
|
|
|
+ .ofUrl(one.getTechLicense())
|
|
|
+ .size(300, 240)
|
|
|
+ .create());
|
|
|
+ try {
|
|
|
+ upload("加计扣除基本信息表.doc", "001.docx", projectId, "doc1", params);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void uploadProjectInfo(Integer projectId) {
|
|
|
+ EnterpriseProject one = enterpriseProjectService.getOne(new LambdaQueryWrapper<EnterpriseProject>()
|
|
|
+ .eq(EnterpriseProject::getId, projectId));
|
|
|
+ if (one.getProjectJson() == null || "".equals(one.getProjectJson()) || "[]".equals(one.getProjectJson())) {
|
|
|
+ one.setProjectJson(JSON.toJSONString(Collections.singletonList(new ProjectHeadAddVO())));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(one.getProjectJson())) {
|
|
|
+ one.setHeadAddVOList(JSON.parseArray(one.getProjectJson(), ProjectHeadAddVO.class));
|
|
|
+ }
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("one", one);
|
|
|
+ params.put("list", one.getHeadAddVOList());
|
|
|
+ // 单选按钮
|
|
|
+ params.put("innovateFlag", (one.getDevelopFlag() != null && one.getDevelopFlag()) ? "成功" : "失败");
|
|
|
+ params.put("industry", (one.getIndustry() != null && one.getIndustry()) ? "是" : "否");
|
|
|
+ // 时间
|
|
|
+ params.put("projectDate", StringUtils.isNotEmpty(one.getProjectDate())
|
|
|
+ ? one.getProjectDate().replaceAll("(\\d{4})-(\\d{2})-(\\d{2})", "$1年$2月$3日")
|
|
|
+ : "");
|
|
|
+ params.put("projectStartDate", StringUtils.isNotEmpty(one.getProjectStartDate())
|
|
|
+ ? one.getProjectStartDate().replaceAll("(\\d{4})-(\\d{2})-(\\d{2})", "$1年$2月$3日")
|
|
|
+ : "");
|
|
|
+ params.put("projectEndDate", StringUtils.isNotEmpty(one.getProjectEndDate())
|
|
|
+ ? one.getProjectEndDate().replaceAll("(\\d{4})-(\\d{2})-(\\d{2})", "$1年$2月$3日")
|
|
|
+ : "");
|
|
|
+ params.put("projectType", EntProjectTypeEnum.getParse(one.getProjectType()));
|
|
|
+ params.put("industryType", EntIndustryTypeEnum.getParse(one.getIndustryType()));
|
|
|
+ try {
|
|
|
+ upload("企业研发项目情况表.doc", "002.docx", projectId, "doc2", params);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result<Attach> upload(String fileName, String templateName, Integer dataId, String fileType, Map<String, Object> params) throws IOException {
|
|
|
+ String suffix = "doc";
|
|
|
+ String fileKey = IdUtil.fastSimpleUUID() + "." + suffix;
|
|
|
+ String uploadPath = YccrcConfig.getUploadPath();
|
|
|
+ FileUtil.mkdir(uploadPath);
|
|
|
+ String dest = uploadPath + fileKey;
|
|
|
+
|
|
|
+ Resource resource = new ClassPathResource("templates/" + templateName);
|
|
|
+ InputStream inputStream = resource.getInputStream();
|
|
|
+ // 动态表单插件设置
|
|
|
+ LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
+ Configure config = Configure.builder()
|
|
|
+ .bind("list", policy).build();
|
|
|
+ // 数据填充
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(inputStream, config).render(params);
|
|
|
+ OutputStream outputStream = Files.newOutputStream(Paths.get(dest));
|
|
|
+ template.write(outputStream);
|
|
|
+
|
|
|
+ // 先移除后添加
|
|
|
+ attachService.remove(new LambdaQueryWrapper<Attach>()
|
|
|
+ .eq(Attach::getDataId, dataId)
|
|
|
+ .eq(Attach::getFileType, fileType)
|
|
|
+ .eq(Attach::getAttachType, AttachTypeEnum.DOC)
|
|
|
+ );
|
|
|
+
|
|
|
+ Attach attach = new Attach();
|
|
|
+ //保存数据信息至数据库
|
|
|
+ attach.setFileName(fileName);
|
|
|
+ attach.setFileSize(0L);
|
|
|
+ attach.setFileKey(fileKey);
|
|
|
+ attach.setUrl(YccrcConfig.getDomain() + Constants.RESOURCE_PREFIX + "/upload/" + fileKey);
|
|
|
+ attach.setDataId(dataId);
|
|
|
+ attach.setFileType(fileType);
|
|
|
+ attach.setAttachType(AttachTypeEnum.DOC);
|
|
|
+ try {
|
|
|
+ attach.setCreateBy(super.getUsername());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ attachService.save(attach);
|
|
|
+ return new Result<Attach>().ok(attach);
|
|
|
+ }
|
|
|
+
|
|
|
}
|