Переглянути джерело

专家评审表导出多个

master
WendyYang 1 рік тому
джерело
коміт
26407509d1
6 змінених файлів з 134 додано та 26 видалено
  1. +22
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/model/FreemarkerBatchExportDTO.java
  2. +42
    -11
      pmapi/src/main/java/com/ningdatech/pmapi/common/util/FreemarkerWordUtil.java
  3. +7
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ExpertReviewManage.java
  4. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java
  5. +5
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertReviewTableDTO.java
  6. +57
    -13
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java

+ 22
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/model/FreemarkerBatchExportDTO.java Переглянути файл

@@ -0,0 +1,22 @@
package com.ningdatech.pmapi.common.model;

import lombok.Data;

/**
* <p>
* FreemarkerBatchExportDTO
* </p>
*
* @author WendyYang
* @since 2023/8/1
**/
@Data
public class FreemarkerBatchExportDTO {

private String fileName;

private String template;

private Object data;

}

+ 42
- 11
pmapi/src/main/java/com/ningdatech/pmapi/common/util/FreemarkerWordUtil.java Переглянути файл

@@ -2,6 +2,7 @@ package com.ningdatech.pmapi.common.util;

import cn.hutool.core.io.IoUtil;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.pmapi.common.model.FreemarkerBatchExportDTO;
import com.ningdatech.pmapi.meeting.entity.dto.ExpertFeeExportDTO;
import com.ningdatech.pmapi.meeting.entity.dto.ExpertInfoDTO;
import freemarker.template.Configuration;
@@ -19,6 +20,9 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
* <p>
@@ -69,22 +73,49 @@ public class FreemarkerWordUtil {

public static void export(String fileName, Object data, HttpServletResponse response, String templateName) throws TemplateException, IOException {
Template template = CONFIGURATION.getTemplate(templateName);
StringWriter out = new StringWriter();
Writer writer = new BufferedWriter(out, 4096);
template.process(data, writer);
response.setCharacterEncoding(StandardCharsets.UTF_8.displayName());
response.setContentType(ContentType.APPLICATION_JSON.getMimeType());
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8"));
try (InputStream is = new ByteArrayResource(out.toString().getBytes(StandardCharsets.UTF_8)).getInputStream();
ServletOutputStream outputStream = response.getOutputStream()) {
// 缓冲区
byte[] buffer = new byte[1024];
int bytesToRead;
// 通过循环将读入的Word文件的内容输出到浏览器中
while ((bytesToRead = is.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesToRead);
try (StringWriter out = new StringWriter();
Writer writer = new BufferedWriter(out, 4096)) {
template.process(data, writer);
try (InputStream is = new ByteArrayResource(out.toString().getBytes(StandardCharsets.UTF_8)).getInputStream();
ServletOutputStream outputStream = response.getOutputStream()) {
// 缓冲区
byte[] buffer = new byte[1024];
int bytesToRead;
// 通过循环将读入的Word文件的内容输出到浏览器中
while ((bytesToRead = is.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesToRead);
}
}
}


}

public static void exportBatch(HttpServletResponse response, List<FreemarkerBatchExportDTO> fbeList, String fileName) throws IOException, TemplateException {
response.setCharacterEncoding(StandardCharsets.UTF_8.displayName());
response.setContentType("application/zip");
String encode = URLEncoder.encode(fileName, "UTF-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + encode);

try (ServletOutputStream os = response.getOutputStream();
ZipOutputStream zos = new ZipOutputStream(os)) {
for (FreemarkerBatchExportDTO param : fbeList) {
Template template = CONFIGURATION.getTemplate(param.getTemplate());
StringWriter out = new StringWriter();
try (Writer writer = new BufferedWriter(out, 4096)) {
template.process(param.getData(), writer);
}
ZipEntry zipEntry = new ZipEntry(param.getFileName());
zos.putNextEntry(zipEntry);
zos.write(out.toString().getBytes(StandardCharsets.UTF_8));
zos.closeEntry();
}
} finally {
response.flushBuffer();
}
}

public static void main(String[] args) {


+ 7
- 0
pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ExpertReviewManage.java Переглянути файл

@@ -199,4 +199,11 @@ public class ExpertReviewManage {
return detail;
}

public List<ExpertReview> listFinalExpertReviews(Long meetingId) {
LambdaQueryWrapper<ExpertReview> query = Wrappers.lambdaQuery(ExpertReview.class)
.eq(ExpertReview::getIsFinal, Boolean.TRUE)
.eq(ExpertReview::getMeetingId, meetingId);
return expertReviewService.list(query);
}

}

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/meeting/controller/MeetingExportController.java Переглянути файл

@@ -48,7 +48,7 @@ public class MeetingExportController {
}

@GetMapping("/expertInviteTable/{meetingId}")
@ApiOperation("专家评审单导出")
@ApiOperation("专家抽取表导出")
public void exportExpertInviteTable(@PathVariable Long meetingId, HttpServletResponse response) {
expertExportManage.expertInviteTable(meetingId, response);
}


+ 5
- 1
pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/ExpertReviewTableDTO.java Переглянути файл

@@ -2,6 +2,8 @@ package com.ningdatech.pmapi.meeting.entity.dto;

import lombok.Data;

import java.io.Serializable;

/**
* <p>
* ExpertReviewTableDTO
@@ -11,7 +13,9 @@ import lombok.Data;
* @since 2023/7/24
**/
@Data
public class ExpertReviewTableDTO {
public class ExpertReviewTableDTO implements Serializable {

private static final long serialVersionUID = 3383159744182234397L;

private String projectName;



+ 57
- 13
pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertExportManage.java Переглянути файл

@@ -3,16 +3,20 @@ package com.ningdatech.pmapi.meeting.manage;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.util.CollUtils;
import com.ningdatech.pmapi.common.model.FreemarkerBatchExportDTO;
import com.ningdatech.pmapi.common.util.FreemarkerWordUtil;
import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo;
import com.ningdatech.pmapi.expert.manage.ExpertReviewManage;
import com.ningdatech.pmapi.expert.service.IExpertUserFullInfoService;
import com.ningdatech.pmapi.meeting.entity.domain.Meeting;
import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert;
import com.ningdatech.pmapi.meeting.entity.domain.MeetingInnerProject;
import com.ningdatech.pmapi.meeting.entity.domain.MeetingOuterProject;
import com.ningdatech.pmapi.meeting.entity.dto.*;
import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertAttendStatusEnum;
import com.ningdatech.pmapi.meeting.service.IMeetingExpertService;
import com.ningdatech.pmapi.meeting.service.IMeetingInnerProjectService;
import com.ningdatech.pmapi.meeting.service.IMeetingOuterProjectService;
@@ -29,11 +33,13 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* <p>
@@ -54,6 +60,7 @@ public class ExpertExportManage {
private final IMeetingOuterProjectService meetingOuterProjectService;
private final IExpertUserFullInfoService expertUserInfoService;
private final IProjectService projectService;
private final ExpertReviewManage expertReviewManage;

//==================================================================================================================

@@ -78,6 +85,16 @@ public class ExpertExportManage {

static Supplier<String> wordName = () -> UUID.randomUUID().toString(true) + ".doc";

private List<MeetingExpert> listExpertsByAgreeOrLeave(Long meetingId) {
Page<MeetingExpert> page = Page.of(1, 20);
meetingExpertService.pageExpertByStatusAndMeetingId(page, meetingId, null, null);
if (page.getTotal() == 0) {
return Collections.emptyList();
}
page.getRecords().removeIf(w -> !(ExpertAttendStatusEnum.AGREED.eq(w.getStatus()) || ExpertAttendStatusEnum.ON_LEAVE.eq(w.getStatus())));
return page.getRecords();
}

//==================================================================================================================

public void exportFeeForExpert(Long meetingId, HttpServletResponse response) {
@@ -130,22 +147,41 @@ public class ExpertExportManage {
public void expertReviewTable(Long meetingId, HttpServletResponse response) {
try {
Meeting meeting = meetingService.getById(meetingId);
ExpertReviewTableDTO data = new ExpertReviewTableDTO();
data.setMeetingTime(DateUtil.localDateTimeFormat(meeting.getStartTime(), "yyyy年M月d日"));
data.setMeetingAddress(meeting.getMeetingAddress());
data.setHoldOrg(meeting.getHoldOrg());
List<String> projectNames = new ArrayList<>();
String startTime = DateUtil.localDateTimeFormat(meeting.getStartTime(), "yyyy年M月d日");
List<FreemarkerBatchExportDTO> fbeList;
if (meeting.getIsInnerProject()) {
List<MeetingInnerProject> inners = meetingInnerProjectService.listByMeetingId(meetingId);
List<Long> projectIds = CollUtils.fieldList(inners, MeetingInnerProject::getProjectId);
List<Project> projects = projectService.listByIds(projectIds);
projects.forEach(w -> projectNames.add(w.getProjectName()));
fbeList = projects.stream().map(w -> {
FreemarkerBatchExportDTO fbe = new FreemarkerBatchExportDTO();
ExpertReviewTableDTO currData = new ExpertReviewTableDTO();
currData.setHoldOrg(meeting.getHoldOrg());
currData.setMeetingTime(startTime);
currData.setMeetingAddress(meeting.getMeetingAddress());
currData.setProjectName(w.getProjectName());
fbe.setData(currData);
fbe.setTemplate(EXPERT_REVIEW);
fbe.setFileName(w.getProjectName() + ".doc");
return fbe;
}).collect(Collectors.toList());
} else {
List<MeetingOuterProject> inners = meetingOuterProjectService.listByMeetingId(meetingId);
inners.forEach(w -> projectNames.add(w.getProjectName()));
fbeList = inners.stream().map(w -> {
FreemarkerBatchExportDTO fbe = new FreemarkerBatchExportDTO();
ExpertReviewTableDTO currData = new ExpertReviewTableDTO();
currData.setHoldOrg(meeting.getHoldOrg());
currData.setMeetingTime(startTime);
currData.setMeetingAddress(meeting.getMeetingAddress());
currData.setProjectName(w.getProjectName());
fbe.setData(currData);
fbe.setTemplate(EXPERT_REVIEW);
fbe.setFileName(w.getProjectName() + ".doc");
return fbe;
}).collect(Collectors.toList());
}
data.setProjectName(StrUtil.join("、", projectNames));
FreemarkerWordUtil.export(wordName.get(), data, response, EXPERT_REVIEW);
String exportFileName = meeting.getName() + "专家评审表.zip";
FreemarkerWordUtil.exportBatch(response, fbeList, exportFileName);
} catch (TemplateException | IOException e) {
log.error("专家评审单导出异常:{}", meetingId, e);
throw BizException.wrap("专家评审单导出失败");
@@ -171,13 +207,17 @@ public class ExpertExportManage {
data.setProjectName(StrUtil.join("、", projectNames));
data.setExperts(new ArrayList<>());
// 设置专家信息
List<MeetingExpert> experts = meetingExpertService.listAgreedExperts(meetingId);
List<MeetingExpert> experts = listExpertsByAgreeOrLeave(meetingId);
List<Long> expertIds = CollUtils.fieldList(experts, MeetingExpert::getExpertId);
List<ExpertUserFullInfo> expertInfos = expertUserInfoService.listByUserId(expertIds);
Map<Long, ExpertUserFullInfo> expertMap = CollUtils.listToMap(expertInfos, ExpertUserFullInfo::getUserId);
experts.forEach(w -> {
ExpertInfoDTO expert = new ExpertInfoDTO();
expert.setName(w.getExpertName());
if (ExpertAttendStatusEnum.ON_LEAVE.eq(w.getStatus())) {
expert.setBank(w.getExpertName() + "(请假)");
} else {
expert.setName(w.getExpertName());
}
ExpertUserFullInfo expertUser = expertMap.get(w.getExpertId());
if (expertUser != null) {
expert.setCompany(expertUser.getCompany());
@@ -217,7 +257,7 @@ public class ExpertExportManage {
}
data.setExperts(new ArrayList<>());
// 设置专家信息
List<MeetingExpert> experts = meetingExpertService.listAgreedExperts(meetingId);
List<MeetingExpert> experts = listExpertsByAgreeOrLeave(meetingId);
List<Long> expertIds = CollUtils.fieldList(experts, MeetingExpert::getExpertId);
List<ExpertUserFullInfo> expertInfos = expertUserInfoService.listByUserId(expertIds);
Map<Long, ExpertUserFullInfo> expertMap = CollUtils.listToMap(expertInfos, ExpertUserFullInfo::getUserId);
@@ -225,7 +265,11 @@ public class ExpertExportManage {
experts.forEach(w -> {
ExpertInfoDTO expert = new ExpertInfoDTO();
expert.setNo(integer.incrementAndGet());
expert.setName(w.getExpertName());
if (ExpertAttendStatusEnum.ON_LEAVE.eq(w.getStatus())) {
expert.setBank(w.getExpertName() + "(请假)");
} else {
expert.setName(w.getExpertName());
}
expert.setMobile(w.getMobile());
ExpertUserFullInfo expertUser = expertMap.get(w.getExpertId());
if (expertUser != null) {


Завантаження…
Відмінити
Зберегти