14 changed files with 388 additions and 32 deletions
@ -0,0 +1,36 @@ |
|||||
|
package com.research.web.controller.client; |
||||
|
|
||||
|
import com.research.system.service.ExportService; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
/** |
||||
|
* @Author zzc |
||||
|
* @Package com.research.web.controller.client |
||||
|
* @Date 2025/11/28 14:57 |
||||
|
* @description: |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/export") |
||||
|
@Api(tags = "任务相关") |
||||
|
@Slf4j |
||||
|
public class ExportController { |
||||
|
|
||||
|
@Resource |
||||
|
private ExportService exportService; |
||||
|
|
||||
|
@ApiOperation(value = "导出项目运行报告") |
||||
|
@RequestMapping(value = "/all", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
||||
|
public void export(HttpServletResponse response){ |
||||
|
exportService.export( response); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
package com.research.system.service; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
/** |
||||
|
* @Author zzc |
||||
|
* @Package com.research.system.service |
||||
|
* @Date 2025/11/28 12:37 |
||||
|
* @description: |
||||
|
*/ |
||||
|
public interface ExportService { |
||||
|
void export(HttpServletResponse response); |
||||
|
} |
||||
@ -0,0 +1,204 @@ |
|||||
|
package com.research.system.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import cn.hutool.core.date.DateUtil; |
||||
|
import cn.hutool.core.io.FileUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.deepoove.poi.XWPFTemplate; |
||||
|
import com.deepoove.poi.data.*; |
||||
|
import com.research.common.utils.DateUtils; |
||||
|
import com.research.common.utils.file.FileUtils; |
||||
|
import com.research.system.domain.dto.ClientPrjProOrgDto; |
||||
|
import com.research.system.domain.dto.GroupDto; |
||||
|
import com.research.system.domain.dto.OutcomeDto; |
||||
|
import com.research.system.domain.vo.ClientPrjProjInfoVo; |
||||
|
import com.research.system.domain.vo.GroupVO; |
||||
|
import com.research.system.domain.vo.OutcomeVo; |
||||
|
import com.research.system.service.CooperatorService; |
||||
|
import com.research.system.service.ExportService; |
||||
|
import com.research.system.service.KtsGroupService; |
||||
|
import com.research.system.service.OutcomeService; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.FileOutputStream; |
||||
|
import java.nio.file.Files; |
||||
|
import java.nio.file.Paths; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @Author zzc |
||||
|
* @Package com.research.system.service.impl |
||||
|
* @Date 2025/11/28 12:37 |
||||
|
* @description: |
||||
|
*/ |
||||
|
@Service |
||||
|
public class ExportServiceImpl implements ExportService { |
||||
|
|
||||
|
|
||||
|
@Resource |
||||
|
private CooperatorService cooperatorService; |
||||
|
@Value(value = "${research.reportTemplate}") |
||||
|
private String reportTemplate; |
||||
|
@Resource |
||||
|
private KtsGroupService ktsGroupService; |
||||
|
@Resource |
||||
|
private OutcomeService outcomeService; |
||||
|
|
||||
|
@Override |
||||
|
public void export(HttpServletResponse response) { |
||||
|
XWPFTemplate template = XWPFTemplate.compile(reportTemplate); |
||||
|
HashMap<String, Object> map = new HashMap<>(); |
||||
|
List<ClientPrjProjInfoVo.OrgVo> query = cooperatorService.query(new ClientPrjProOrgDto.Query()); |
||||
|
|
||||
|
//合作单位
|
||||
|
if (CollUtil.isNotEmpty(query)) { |
||||
|
TextRenderData text1 = Texts.of("单位名称").bold().fontSize(12).create(); |
||||
|
TextRenderData text2 = Texts.of("单位类型").bold().fontSize(12).create(); |
||||
|
TextRenderData text3 = Texts.of("负责人").bold().fontSize(12).create(); |
||||
|
RowRenderData headerRow = Rows.of(text1, text2, text3).center().create(); |
||||
|
Tables.TableBuilder of = Tables.of(headerRow); |
||||
|
for (ClientPrjProjInfoVo.OrgVo orgVo : query) { |
||||
|
RowRenderData rowRenderData = Rows.of( |
||||
|
orgVo.getOrgName(), |
||||
|
orgVo.getCategory() == null ? null : orgVo.getCategory() == 0 ? "申报单位" : "合作单位", |
||||
|
orgVo.getOrgLeader() |
||||
|
).center().create(); |
||||
|
of.addRow(rowRenderData).center(); |
||||
|
} |
||||
|
TableRenderData tableData = of |
||||
|
.create(); |
||||
|
map.put("table0", tableData); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//项目课题
|
||||
|
List<GroupVO.Result> groupList = ktsGroupService.queryGroupList(new GroupDto.Query()); |
||||
|
if (CollUtil.isNotEmpty(groupList)) { |
||||
|
TextRenderData text1 = Texts.of("单位名称").bold().fontSize(12).create(); |
||||
|
TextRenderData text2 = Texts.of("课题").bold().fontSize(12).create(); |
||||
|
TextRenderData text3 = Texts.of("负责人").bold().fontSize(12).create(); |
||||
|
RowRenderData headerRow = Rows.of(text1, text2, text3).center().create(); |
||||
|
Tables.TableBuilder of = Tables.of(headerRow); |
||||
|
for (GroupVO.Result result : groupList) { |
||||
|
RowRenderData rowRenderData = Rows.of( |
||||
|
result.getProjOrgName(), |
||||
|
result.getKtGroupName(), |
||||
|
result.getName() |
||||
|
).center().create(); |
||||
|
of.addRow(rowRenderData).center(); |
||||
|
} |
||||
|
TableRenderData tableData = of |
||||
|
.create(); |
||||
|
map.put("table1", tableData); |
||||
|
} |
||||
|
//项目成果
|
||||
|
List<OutcomeVo.Result> outcomeList = outcomeService.queryList(new OutcomeDto.Query()); |
||||
|
if (CollUtil.isNotEmpty(outcomeList)) { |
||||
|
//学术论文
|
||||
|
Map<Long, List<OutcomeVo.Result>> outcomeMap = outcomeList.stream().collect(Collectors.groupingBy(OutcomeVo.Result::getCategoryId1)); |
||||
|
List<OutcomeVo.Result> results = outcomeMap.get(1L); |
||||
|
|
||||
|
if (CollUtil.isNotEmpty(results)) { |
||||
|
TextRenderData text1 = Texts.of("单位名称").bold().fontSize(12).create(); |
||||
|
TextRenderData text2 = Texts.of("标题").bold().fontSize(12).create(); |
||||
|
TextRenderData text3 = Texts.of("作者").bold().fontSize(12).create(); |
||||
|
TextRenderData text4 = Texts.of("类型").bold().fontSize(12).create(); |
||||
|
TextRenderData text5 = Texts.of("刊物").bold().fontSize(12).create(); |
||||
|
TextRenderData text6 = Texts.of("收录类别").bold().fontSize(12).create(); |
||||
|
RowRenderData headerRow = Rows.of(text1, text2, text3, text4, text5, text6).center().create(); |
||||
|
Tables.TableBuilder of = Tables.of(headerRow); |
||||
|
for (OutcomeVo.Result result : results) { |
||||
|
RowRenderData rowRenderData = Rows.of( |
||||
|
result.getProjOrgName(), |
||||
|
result.getTitle(), |
||||
|
result.getAuthors(), |
||||
|
result.getAchType() == null ? null : result.getAchType() == 0 ? "期刊论文" : result.getAchType() == 1 ? "会议论文" : result.getAchType() == 2 ? "报刊文章" : result.getAchType() == 3 ? "报纸文章" : "学位论文", |
||||
|
result.getSource(), |
||||
|
result.getCategoryId2() == null ? null : result.getCategoryId2() == 2 ? "SCI" : result.getCategoryId2() == 3 ? "中文期刊" : "其他" |
||||
|
).center().create(); |
||||
|
of.addRow(rowRenderData).center(); |
||||
|
} |
||||
|
TableRenderData tableData = of |
||||
|
.create(); |
||||
|
map.put("table2", tableData); |
||||
|
} |
||||
|
List<OutcomeVo.Result> results1 = outcomeMap.get(11L); |
||||
|
if (CollUtil.isNotEmpty(results1)) { |
||||
|
TextRenderData text1 = Texts.of("单位名称").bold().fontSize(12).create(); |
||||
|
TextRenderData text2 = Texts.of("专利名称").bold().fontSize(12).create(); |
||||
|
TextRenderData text3 = Texts.of("专利号").bold().fontSize(12).create(); |
||||
|
TextRenderData text4 = Texts.of("专利类型").bold().fontSize(12).create(); |
||||
|
TextRenderData text5 = Texts.of("专利权人").bold().fontSize(12).create(); |
||||
|
TextRenderData text6 = Texts.of("专利内容").bold().fontSize(12).create(); |
||||
|
RowRenderData headerRow = Rows.of(text1, text2, text3, text4, text5, text6).center().create(); |
||||
|
Tables.TableBuilder of = Tables.of(headerRow); |
||||
|
for (OutcomeVo.Result result : results1) { |
||||
|
RowRenderData rowRenderData = Rows.of( |
||||
|
result.getProjOrgName(), |
||||
|
result.getTitle(), |
||||
|
result.getNo(), |
||||
|
result.getAchType() == null ? null : result.getAchType() == 0 ? "发明专利" : result.getAchType() == 1 ? "实用新型专利" : "外观设计专利", |
||||
|
result.getAuthors(), |
||||
|
result.getRemark() |
||||
|
).center().create(); |
||||
|
of.addRow(rowRenderData).center(); |
||||
|
} |
||||
|
TableRenderData tableData = of |
||||
|
.create(); |
||||
|
map.put("table3", tableData); |
||||
|
} |
||||
|
|
||||
|
List<OutcomeVo.Result> results2 = outcomeMap.get(71L); |
||||
|
if (CollUtil.isNotEmpty(results2)) { |
||||
|
TextRenderData text1 = Texts.of("标题").bold().fontSize(12).create(); |
||||
|
TextRenderData text2 = Texts.of("时间").bold().fontSize(12).create(); |
||||
|
TextRenderData text3 = Texts.of("地点").bold().fontSize(12).create(); |
||||
|
TextRenderData text4 = Texts.of("参与人").bold().fontSize(12).create(); |
||||
|
TextRenderData text5 = Texts.of("类型").bold().fontSize(12).create(); |
||||
|
TextRenderData text6 = Texts.of("内容").bold().fontSize(12).create(); |
||||
|
RowRenderData headerRow = Rows.of(text1, text2, text3, text4, text5, text6).center().create(); |
||||
|
Tables.TableBuilder of = Tables.of(headerRow); |
||||
|
for (OutcomeVo.Result result : results2) { |
||||
|
RowRenderData rowRenderData = Rows.of( |
||||
|
result.getTitle(), |
||||
|
DateUtil.format(result.getPublishDate(), "yyyy-MM-dd"), |
||||
|
result.getPlace(), |
||||
|
result.getAuthors(), |
||||
|
result.getAchType() == null ? null : result.getAchType() == 0 ? "学术讲座" : result.getAchType() == 1 ? "学术会议" : "外出进修", |
||||
|
result.getRemark() |
||||
|
).center().create(); |
||||
|
of.addRow(rowRenderData).center(); |
||||
|
} |
||||
|
TableRenderData tableData = of |
||||
|
.create(); |
||||
|
map.put("table4", tableData); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
try { |
||||
|
|
||||
|
String fileName = "项目运行报告.docx"; |
||||
|
String path = "C:/Users/zzc16/Desktop/项目运行报告.docx"; |
||||
|
// String path = "D:/Projects/research/server/profile/项目运行报告.docx";
|
||||
|
template.render(map); |
||||
|
//以文件形式输出
|
||||
|
template.writeAndClose(Files.newOutputStream(Paths.get(path))); |
||||
|
|
||||
|
//3.写出到客户端
|
||||
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
||||
|
FileUtils.setAttachmentResponseHeader(response, fileName); |
||||
|
FileUtils.writeBytes(path, response.getOutputStream()); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); // 输出详细的异常信息
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue