|
|
|
@ -27,37 +27,24 @@ import com.biutag.supervision.pojo.dto.NegativeDto; |
|
|
|
import com.biutag.supervision.pojo.dto.flow.FirstDistributeData; |
|
|
|
import com.biutag.supervision.pojo.dto.flow.FirstDistributeData; |
|
|
|
import com.biutag.supervision.pojo.dto.flow.VerifyData; |
|
|
|
import com.biutag.supervision.pojo.dto.flow.VerifyData; |
|
|
|
import com.biutag.supervision.pojo.dto.jwdc.NegativeApiDto; |
|
|
|
import com.biutag.supervision.pojo.dto.jwdc.NegativeApiDto; |
|
|
|
import com.biutag.supervision.pojo.dto.report.ReportViewModel; |
|
|
|
|
|
|
|
import com.biutag.supervision.pojo.entity.*; |
|
|
|
import com.biutag.supervision.pojo.entity.*; |
|
|
|
import com.biutag.supervision.pojo.model.UserAuth; |
|
|
|
import com.biutag.supervision.pojo.model.UserAuth; |
|
|
|
import com.biutag.supervision.pojo.request.negative.ReportGenerationRequest; |
|
|
|
|
|
|
|
import com.biutag.supervision.pojo.vo.NegativeFileVo; |
|
|
|
import com.biutag.supervision.pojo.vo.NegativeFileVo; |
|
|
|
import com.biutag.supervision.service.report.ReportDataService; |
|
|
|
|
|
|
|
import com.biutag.supervision.util.ChartRenderUtil; |
|
|
|
|
|
|
|
import com.biutag.supervision.util.SpringUtil; |
|
|
|
import com.biutag.supervision.util.SpringUtil; |
|
|
|
import com.biutag.supervision.util.TimeUtil; |
|
|
|
import com.biutag.supervision.util.TimeUtil; |
|
|
|
import com.deepoove.poi.XWPFTemplate; |
|
|
|
|
|
|
|
import com.deepoove.poi.data.Pictures; |
|
|
|
|
|
|
|
import jakarta.servlet.ServletOutputStream; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.StreamUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import static com.biutag.supervision.constants.AppConstants.*; |
|
|
|
import static com.biutag.supervision.constants.AppConstants.JWPY_DEPARTID; |
|
|
|
|
|
|
|
import static com.biutag.supervision.constants.AppConstants.JWPY_DEPART_NAME; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
@RequiredArgsConstructor |
|
|
|
@RequiredArgsConstructor |
|
|
|
@ -94,7 +81,6 @@ public class NegativeService extends ServiceImpl<NegativeMapper, Negative> { |
|
|
|
|
|
|
|
|
|
|
|
private final NegativeCountersignApplyService countersignApplyService; |
|
|
|
private final NegativeCountersignApplyService countersignApplyService; |
|
|
|
|
|
|
|
|
|
|
|
private final ReportDataService reportDataService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public NegativeDetail get(String id, Integer workId) { |
|
|
|
public NegativeDetail get(String id, Integer workId) { |
|
|
|
Negative negative = getById(id); |
|
|
|
Negative negative = getById(id); |
|
|
|
@ -494,48 +480,4 @@ public class NegativeService extends ServiceImpl<NegativeMapper, Negative> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void generateReport(ReportGenerationRequest request, HttpServletResponse response) { |
|
|
|
|
|
|
|
// 你要返回的模板路径
|
|
|
|
|
|
|
|
String templatePath = "static/templates/督审一体化平台研判分析报告.docx"; |
|
|
|
|
|
|
|
ClassPathResource resource = new ClassPathResource(templatePath); |
|
|
|
|
|
|
|
if (!resource.exists()) { |
|
|
|
|
|
|
|
// 资源不存在,返回 404
|
|
|
|
|
|
|
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND); |
|
|
|
|
|
|
|
response.setContentType("application/json;charset=UTF-8"); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
response.getWriter().write("{\"message\":\"模板文件不存在: " + templatePath + "\"}"); |
|
|
|
|
|
|
|
} catch (IOException ignored) {} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 1) 准备模板变量(含图表)
|
|
|
|
|
|
|
|
ReportViewModel vm = reportDataService.buildViewModel(request); |
|
|
|
|
|
|
|
// 2) 响应头(docx 正确类型)
|
|
|
|
|
|
|
|
String downloadName = "督审一体化平台研判分析报告.docx"; |
|
|
|
|
|
|
|
String encoded = URLEncoder.encode(downloadName, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); |
|
|
|
|
|
|
|
String contentDisposition = "attachment; filename=\"" + encoded + "\"; filename*=UTF-8''" + encoded; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.reset(); |
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
response.setHeader("Content-Disposition", contentDisposition); |
|
|
|
|
|
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
|
|
|
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
|
|
|
|
|
|
|
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); |
|
|
|
|
|
|
|
response.setHeader("Pragma", "no-cache"); |
|
|
|
|
|
|
|
response.setDateHeader("Expires", 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3) 关键:compile + render + write(不要 StreamUtils.copy)
|
|
|
|
|
|
|
|
try (InputStream in = resource.getInputStream(); |
|
|
|
|
|
|
|
XWPFTemplate template = XWPFTemplate.compile(in).render(vm); |
|
|
|
|
|
|
|
ServletOutputStream out = response.getOutputStream()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template.write(out); |
|
|
|
|
|
|
|
out.flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("生成/下载报告失败", e); |
|
|
|
|
|
|
|
// 如果你们有统一异常处理,可以直接抛出去
|
|
|
|
|
|
|
|
// throw new RuntimeException("生成报告失败", e);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|