Browse Source

生成文档

licailing 4 years ago
parent
commit
64586f66d1

+ 10 - 0
src/main/java/com/izouma/wenlvju/domain/regulation/Report.java

@@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
 import org.hibernate.annotations.Where;
 
 import javax.persistence.*;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -40,6 +41,15 @@ public class Report extends BaseEntity {
     @Column(columnDefinition = "TEXT")
     private String file;
 
+    @ApiModelProperty(value = "开始时间")
+    private LocalDateTime start;
+
+    @ApiModelProperty(value = "结束时间")
+    private LocalDateTime end;
+
+    @ApiModelProperty(value = "生成时间")
+    private LocalDateTime generatedAt;
+
     @Column(columnDefinition = "TEXT")
     @Convert(converter = NumOfReportListConverter.class)
     private List<NumOfReport> total;

+ 3 - 0
src/main/java/com/izouma/wenlvju/repo/regulation/ReportStatisticRepo.java

@@ -7,10 +7,13 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.util.List;
 
 public interface ReportStatisticRepo extends JpaRepository<ReportStatistic, Long>, JpaSpecificationExecutor<ReportStatistic> {
     @Query("update ReportStatistic t set t.del = true where t.id = ?1")
     @Modifying
     @Transactional
     void softDelete(Long id);
+
+    List<ReportStatistic> findAllByReportId(Long reportId);
 }

+ 8 - 7
src/main/java/com/izouma/wenlvju/service/performance/ParticipantService.java

@@ -87,8 +87,9 @@ public class ParticipantService {
         });
     }
 
-    public String createAward(Participant participant, String programmeName) throws IOException, WriterException {
-        BufferedImage shareImg = ImageIO.read(this.getClass().getResourceAsStream("/static/certificate.jpeg"));
+    public String createAward(Participant participant, String programmeName, Long awardId) throws IOException, WriterException {
+        BufferedImage shareImg = ImageIO.read(this.getClass()
+                .getResourceAsStream("/static/certificate" + awardId + ".jpeg"));
         BufferedImage result = new BufferedImage(2480, 1748, BufferedImage.TYPE_INT_RGB);
         Graphics2D g = result.createGraphics();
         g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
@@ -137,8 +138,8 @@ public class ParticipantService {
 
         // 节目名称
         if (programmeName.length() > 8) {
-            String body1 = programmeName.substring(0, 7);
-            String body2 = programmeName.substring(7);
+            String body1 = programmeName.substring(0, 8);
+            String body2 = programmeName.substring(8);
             Font title = new Font("黑体", Font.PLAIN, 40);
             g.setFont(title);
             g.drawString(body1, 1200, 795);
@@ -156,7 +157,7 @@ public class ParticipantService {
                 .toOutputStream(out);
         ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
 
-        return storageService.uploadFromInputStream(in, "award/" + participant.getId() + ".jpg");
+        return storageService.uploadFromInputStream(in, "award/" + awardId + "-" + programmeId + "-" + participant.getId() + ".jpg");
     }
 
     public void awardByProgrammeId(Long programmeId) {
@@ -171,7 +172,7 @@ public class ParticipantService {
         participants.forEach(participant -> {
             if (ObjectUtil.isNull(participant.getAwardImg())) {
                 try {
-                    participant.setAwardImg(this.createAward(participant, programme.getName()));
+                    participant.setAwardImg(this.createAward(participant, programme.getName(), programme.getAwardId()));
                 } catch (IOException e) {
                     log.error("文件找不到", e);
                 } catch (WriterException e) {
@@ -201,7 +202,7 @@ public class ParticipantService {
         participants.forEach(participant -> {
             if (ObjectUtil.isNull(participant.getAwardImg())) {
                 try {
-                    participant.setAwardImg(this.createAward(participant, programmeMap.get(participant.getProgrammeId())));
+                    participant.setAwardImg(this.createAward(participant, programmeMap.get(participant.getProgrammeId()), awardId));
                 } catch (IOException e) {
                     log.error("文件找不到", e);
                 } catch (WriterException e) {

+ 309 - 37
src/main/java/com/izouma/wenlvju/service/regulation/ReportService.java

@@ -1,5 +1,6 @@
 package com.izouma.wenlvju.service.regulation;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
@@ -26,6 +27,7 @@ import com.izouma.wenlvju.service.poi.PoiWordTable;
 import com.izouma.wenlvju.service.storage.StorageService;
 import com.izouma.wenlvju.utils.ChartUtils;
 import com.izouma.wenlvju.utils.JpaUtils;
+import com.izouma.wenlvju.utils.ObjUtils;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
 import freemarker.template.TemplateException;
@@ -138,6 +140,71 @@ public class ReportService {
         return map;
     }
 
+    public void getDate1(Report report) {
+        //开始结束时间
+        int year = report.getYear();
+        LocalDateTime start = LocalDateTime.of(year, 1, 1, 0, 0);
+        LocalDate endDate = LocalDate.of(year, 12, 31);
+        //名称
+        String time = year + "年";
+
+        switch (report.getType()) {
+            case ANNUAL:
+                Report result = reportRepo.findByTypeAndYear(ReportType.ANNUAL, year);
+                if (ObjectUtil.isNotNull(result)) {
+                    BeanUtil.copyProperties(result, report);
+                    return;
+                }
+                break;
+            case QUARTERLY:
+                int quarterly = report.getQuarterly();
+                Report result1 = reportRepo.findByYearAndQuarterly(year, quarterly);
+                if (ObjectUtil.isNotNull(result1)) {
+                    BeanUtil.copyProperties(result1, report);
+                    return;
+                }
+
+                switch (quarterly) {
+                    case 1:
+                        endDate = LocalDate.of(year, 3, 31);
+                        time += "一季度";
+                        break;
+                    case 2:
+                        start = LocalDateTime.of(year, 4, 1, 0, 0);
+                        endDate = LocalDate.of(year, 6, 30);
+                        time += "二季度";
+                        break;
+                    case 3:
+                        start = LocalDateTime.of(year, 7, 1, 0, 0);
+                        endDate = LocalDate.of(year, 9, 30);
+                        time += "三季度";
+                        break;
+                    case 4:
+                        start = LocalDateTime.of(year, 10, 1, 0, 0, 0);
+                        time += "四季度";
+                        break;
+                }
+                break;
+            case MONTHLY:
+                Report result2 = reportRepo.findByYearAndMonth(year, report.getMonth());
+                if (ObjectUtil.isNotNull(result2)) {
+                    BeanUtil.copyProperties(result2, report);
+                    return;
+                }
+
+                LocalDate startDate = LocalDate.of(year, report.getMonth(), 1);
+                start = LocalDateTime.of(startDate, LocalTime.MIN);
+                endDate = startDate.plusMonths(1).minusDays(1);
+                time += report.getMonth() + "月";
+                break;
+        }
+        // 结束日期
+        LocalDateTime end = LocalDateTime.of(endDate, LocalTime.MAX);
+        report.setStart(start);
+        report.setEnd(end);
+        report.setTime(time);
+    }
+
     /**
      * 生成报告
      */
@@ -338,13 +405,13 @@ public class ReportService {
     }
 
     /**
-     * 生成word
+     * 生成freemarkerWord
      *
      * @param report
      * @throws IOException
      * @throws TemplateException
      */
-    public void word(Report report) throws IOException, TemplateException {
+    public void freemarkerWord(Report report) throws IOException, TemplateException {
         // 开始结束时间
         Map<String, Object> date = this.getDate(report);
         if (ObjectUtil.isNull(date)) {
@@ -386,9 +453,6 @@ public class ReportService {
         //各专业统计
         List<NumOfReport> specialty = this.getSpecialty(recordSpecialties);
         specialty.forEach(num -> dataMap.put(num.getName(), num.getNum()));
-        //画图
-        Map<String, Integer> specialtyMap = specialty.stream()
-                .collect(Collectors.toMap(NumOfReport::getName, NumOfReport::getNum));
 
         //考级机构/承办单位统计
         List<ReportStatistic> reportDTOS = this.generate(records, complains);
@@ -409,9 +473,9 @@ public class ReportService {
         dataMap.put("list", listMapGo);
 
         //承办单位
-        List<ReportStatistic> reportStatistics = unitTypeListMap.get(UnitType.ORGANIZATION);
+        List<ReportStatistic> reportOr = unitTypeListMap.get(UnitType.ORGANIZATION);
         List<Map<String, Object>> listMap = new ArrayList<>();
-        reportStatistics.forEach(dto -> {
+        reportOr.forEach(dto -> {
             Map<String, Object> orMap = new HashMap<>();
             orMap.put("name", dto.getName());
             orMap.put("examCenterQuantity", dto.getExamCenterQuantity());
@@ -442,7 +506,7 @@ public class ReportService {
         report.setTime(String.valueOf(date.get("time")));
         report.setTitle("南京市社会艺术水平考级监管报告");
         Long id = reportRepo.save(report).getId();
-        List<ReportStatistic> statistics = reportStatistics.stream()
+        List<ReportStatistic> statistics = reportDTOS.stream()
                 .peek(statistic -> statistic.setReportId(id))
                 .collect(Collectors.toList());
         reportStatisticRepo.saveAll(statistics);
@@ -469,10 +533,9 @@ public class ReportService {
 
         //标题
         String time = String.valueOf(date.get("time"));
-        final String returnurl = "/Users/qiufangchao/Desktop/result.docx";  // 结果文件
-        final String templateurl = "/Users/qiufangchao/Desktop/poiTemp.docx";  // 模板文件
 
-        InputStream is = new FileInputStream(templateurl);
+        InputStream is = this.getClass()
+                .getResourceAsStream("/templates/chart/poiTemp.docx");
         XWPFDocument doc = new XWPFDocument(is);
 
         Map<String, String> textMap = new HashMap<>();
@@ -593,33 +656,23 @@ public class ReportService {
         PoiWordTable.doParagraphs(doc, textMap, tableList);
         PoiWordTable.doCharts(doc, items);
 
-        try {
-            File file = new File(returnurl);
-            if (file.exists()) {
-                file.delete();
-            }
-            FileOutputStream fos = new FileOutputStream(returnurl);
-            doc.write(fos);
-            fos.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        ByteArrayOutputStream fos = new ByteArrayOutputStream();
+        doc.write(fos);
+        fos.close();
 
-//        InputStream is = IOUtils.toInputStream(writer.toString(), "UTF-8");
-//
-//        String url = storageService.uploadFromInputStream(is, "word" + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
-//                + RandomStringUtils.randomAlphabetic(8) + ".docx");
-//
-//        report.setSpecialty(specialty);
-//        report.setTotal(total);
-//        report.setFile(url);
-//        report.setTime(time);
-//        report.setTitle("南京市社会艺术水平考级监管报告");
-//        Long id = reportRepo.save(report).getId();
-//        List<ReportStatistic> statistics = reportsOr.stream()
-//                .peek(statistic -> statistic.setReportId(id))
-//                .collect(Collectors.toList());
-//        reportStatisticRepo.saveAll(statistics);
+        String url = storageService.uploadFromInputStream(new ByteArrayInputStream(fos.toByteArray()), "word" + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
+                + RandomStringUtils.randomAlphabetic(8) + ".docx");
+
+        report.setSpecialty(specialty);
+        report.setTotal(total);
+        report.setFile(url);
+        report.setTime(time);
+        report.setTitle("南京市社会艺术水平考级监管报告");
+        Long id = reportRepo.save(report).getId();
+        List<ReportStatistic> statistics = reportsOr.stream()
+                .peek(statistic -> statistic.setReportId(id))
+                .collect(Collectors.toList());
+        reportStatisticRepo.saveAll(statistics);
     }
 
     /*
@@ -647,4 +700,223 @@ public class ReportService {
 //        }
         return doc;
     }
+
+    /**
+     * 存数据
+     *
+     * @param report
+     */
+    public void saveStatistic(Report report) {
+        // 开始结束时间
+        this.getDate1(report);
+        List<ReportStatistic> reportStatistics = null;
+        if (ObjectUtil.isNotNull(report.getId())) {
+            if (report.getGeneratedAt().isAfter(report.getEnd())) {
+                return;
+            }
+
+            reportStatistics = reportStatisticRepo.findAllByReportId(report.getId());
+        }
+
+        LocalDateTime start = report.getStart();
+        LocalDateTime end = report.getEnd();
+        //备案
+        List<Record> records = recordRepo.findAllByExaminationStartTimeBetween(start.toLocalDate(), end.toLocalDate());
+        //投诉
+        List<Complain> complains = complainRepo.findAllByFinishIsTrueAndComplainAtBetween(start, end);
+        //备案专业
+        List<Long> recordIds = records.stream().map(Record::getId).collect(Collectors.toList());
+        List<RecordSpecialty> recordSpecialties = recordSpecialtyRepo.findAllByRecordIdIn(recordIds);
+        //备案检查
+        List<RecordExpertAudit> recordAudits = recordExpertAuditRepo.findAllByRecordIdIn(recordIds);
+
+        //总统计
+        List<NumOfReport> total = this.getTotal(records, complains, recordAudits);
+
+        //各专业统计
+        List<NumOfReport> specialty = this.getSpecialty(recordSpecialties);
+
+        //考级机构/承办单位统计
+        List<ReportStatistic> reportDTOS = this.generate(records, complains);
+
+        report.setSpecialty(specialty);
+        report.setTotal(total);
+        report.setTitle("南京市社会艺术水平考级监管报告");
+        //生成时间
+        report.setGeneratedAt(LocalDateTime.now());
+        Long id = reportRepo.save(report).getId();
+        List<ReportStatistic> statistics = reportDTOS.stream()
+                .peek(statistic -> statistic.setReportId(id))
+                .collect(Collectors.toList());
+        if (CollUtil.isNotEmpty(reportStatistics)) {
+            Map<UnitType, List<ReportStatistic>> unitTypeListMap = reportDTOS.stream()
+                    .collect(Collectors.groupingBy(ReportStatistic::getUnitType));
+            //考级机构
+            Map<String, ReportStatistic> reportGo = unitTypeListMap.get(UnitType.GRADING_ORGANIZATION)
+                    .stream()
+                    .collect(Collectors.toMap(ReportStatistic::getName, rs -> rs));
+            Map<String, ReportStatistic> reportsOr = unitTypeListMap.get(UnitType.ORGANIZATION).stream()
+                    .collect(Collectors.toMap(ReportStatistic::getName, rs -> rs));
+            statistics.forEach(st -> {
+                if (UnitType.GRADING_ORGANIZATION.equals(st.getUnitType())) {
+                    ReportStatistic rs = reportGo.get(st.getName());
+                    if (ObjectUtil.isNotNull(rs)) {
+                        st.setId(rs.getId());
+                    }
+                } else if (UnitType.ORGANIZATION.equals(st.getUnitType())) {
+                    ReportStatistic rs = reportsOr.get(st.getName());
+                    if (ObjectUtil.isNotNull(rs)) {
+                        st.setId(rs.getId());
+                    }
+                }
+            });
+        }
+        reportStatisticRepo.saveAll(statistics);
+    }
+
+    /**
+     * 生成文档
+     *
+     * @param report
+     * @throws IOException
+     * @throws InvalidFormatException
+     */
+    public String generateWord(Report report) throws IOException, InvalidFormatException {
+        if (StrUtil.isNotEmpty(report.getFile())) {
+            return report.getFile();
+        }
+
+        InputStream is = this.getClass()
+                .getResourceAsStream("/templates/chart/poiTemp.docx");
+        XWPFDocument doc = new XWPFDocument(is);
+
+        Map<String, String> textMap = new HashMap<>();
+        List<List<String[]>> tableList = new ArrayList<>();
+        List<ChartItem> items = new ArrayList<>();
+
+        textMap.put("Title", report.getTime() + "南京市社会艺术水平考级监管报告");
+
+        //总统计
+        List<NumOfReport> total = report.getTotal();
+        List<String[]> tableTotal = new ArrayList<>();
+        tableTotal.add(new String[]{"备案条数", "报考人数", "投诉数量", "检查数量"});
+        Map<String, Integer> totalMap = total.stream()
+                .collect(Collectors.toMap(NumOfReport::getName, NumOfReport::getNum));
+        tableTotal.add(new String[]{String.valueOf(totalMap.get("record")), String.valueOf(totalMap.get("totalExamQuantity")),
+                String.valueOf(totalMap.get("totalComplain")), String.valueOf(totalMap.get("totalAudit"))});
+        tableList.add(tableTotal);
+
+        //各专业统计
+        List<NumOfReport> specialty = report.getSpecialty();
+        List<String[]> tableSpecialty = new ArrayList<>();
+        Map<String, Integer> specialtyMap = specialty.stream()
+                .collect(Collectors.toMap(NumOfReport::getName, NumOfReport::getNum));
+        tableSpecialty.add(new String[]{"音乐", "舞蹈", "美术", "戏曲戏剧", "曲艺"});
+        tableSpecialty.add(new String[]{String.valueOf(specialtyMap.get("音乐")), String.valueOf(specialtyMap.get("舞蹈")),
+                String.valueOf(specialtyMap.get("美术")), String.valueOf(specialtyMap.get("戏曲戏剧")), String.valueOf(specialtyMap.get("曲艺"))});
+        tableList.add(tableSpecialty);
+
+        //画图
+        List<String> titleArr = new ArrayList<>();// 标题
+        titleArr.add("title");
+        titleArr.add("各专业报考场数");
+
+        List<String> fldNameArr = new ArrayList<>();// 字段名
+        fldNameArr.add("key");
+        fldNameArr.add("value");
+
+        List<Map<String, String>> listItemsByType = new ArrayList<>();
+        specialty.forEach(sp -> {
+            Map<String, String> con = new HashMap<>();
+            con.put("key", sp.getName());
+            con.put("value", String.valueOf(sp.getNum()));
+            listItemsByType.add(con);
+        });
+
+        items.add(ChartItem.builder()
+                .fldNameArr(fldNameArr)
+                .type("pie")
+                .titleArr(titleArr)
+                .listItemsByType(listItemsByType)
+                .build());
+
+        //考级机构/承办单位统计
+        List<ReportStatistic> reportDTOS = reportStatisticRepo.findAllByReportId(report.getId());
+        Map<UnitType, List<ReportStatistic>> unitTypeListMap = reportDTOS.stream()
+                .collect(Collectors.groupingBy(ReportStatistic::getUnitType));
+        //考级机构
+        List<ReportStatistic> reportsGo = unitTypeListMap.get(UnitType.GRADING_ORGANIZATION);
+        String[] goTile = {"机构名称", "考级数量", "报考人数", "投诉条数", "投诉内容"};
+        List<String[]> tableGo = new ArrayList<>();
+        tableGo.add(goTile);
+        reportsGo.forEach(dto -> tableGo.add(new String[]{dto.getName(), String.valueOf(dto.getExamCenterQuantity()), String.valueOf(dto.getExamQuantity()),
+                String.valueOf(dto.getComplain()), dto.getComplainContent()}));
+        tableList.add(tableGo);
+
+        //承办单位
+        List<ReportStatistic> reportsOr = unitTypeListMap.get(UnitType.ORGANIZATION);
+        List<String[]> tableOr = new ArrayList<>();
+        tableOr.add(goTile);
+        reportsOr.forEach(dto -> tableOr.add(new String[]{dto.getName(), String.valueOf(dto.getExamCenterQuantity()), String.valueOf(dto.getExamQuantity()),
+                String.valueOf(dto.getComplain()), dto.getComplainContent()}));
+        tableList.add(tableOr);
+
+        //投诉饼图
+        //画图
+        List<String> titleCom = new ArrayList<>();// 标题
+        titleCom.add("title");
+        titleCom.add("考级机构投诉统计");
+
+        List<Map<String, String>> comItemsByType = new ArrayList<>();
+        reportsGo.forEach(sp -> {
+            Map<String, String> con = new HashMap<>();
+            con.put("key", sp.getName());
+            con.put("value", String.valueOf(sp.getComplain()));
+            comItemsByType.add(con);
+        });
+
+        items.add(ChartItem.builder()
+                .fldNameArr(fldNameArr)
+                .type("pie")
+                .titleArr(titleCom)
+                .listItemsByType(comItemsByType)
+                .build());
+
+        //备案柱状图
+        List<String> titleRecord = new ArrayList<>();// 标题
+        titleRecord.add("title");
+        titleRecord.add("承办单位报考人数统计");
+
+        List<Map<String, String>> recordItemsByType = new ArrayList<>();
+        reportsOr.forEach(sp -> {
+            Map<String, String> con = new HashMap<>();
+            con.put("key", sp.getName());
+            con.put("value", String.valueOf(sp.getExamQuantity()));
+            recordItemsByType.add(con);
+        });
+
+        items.add(ChartItem.builder()
+                .fldNameArr(fldNameArr)
+                .type("bar")
+                .titleArr(titleRecord)
+                .listItemsByType(recordItemsByType)
+                .build());
+
+        // 生成文档
+        PoiWordTable.doParagraphs(doc, textMap, tableList);
+        PoiWordTable.doCharts(doc, items);
+
+        ByteArrayOutputStream fos = new ByteArrayOutputStream();
+        doc.write(fos);
+        fos.close();
+
+        String url = storageService.uploadFromInputStream(new ByteArrayInputStream(fos.toByteArray()), "word" + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
+                + RandomStringUtils.randomAlphabetic(8) + ".docx");
+
+        report.setFile(url);
+        reportRepo.save(report);
+
+        return url;
+    }
+
 }

+ 15 - 0
src/main/java/com/izouma/wenlvju/web/RateController.java

@@ -14,6 +14,7 @@ import com.izouma.wenlvju.utils.SecurityUtils;
 import com.izouma.wenlvju.utils.excel.ExcelUtils;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.domain.Page;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -29,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+@Slf4j
 @RestController
 @RequestMapping("/rate")
 @AllArgsConstructor
@@ -146,6 +148,19 @@ public class RateController extends BaseController {
         return null;
     }
 
+    @GetMapping("/mergePdf")
+    public void mergePdf() {
+        List<Rate> rates = rateRepo.findAllByStatusAndYearOrderByScoreDesc(RateStatus.SUBMIT_PAPER_MATERIALS,
+                String.valueOf(LocalDate.now().getYear()));
+        rates.forEach(rate -> {
+            try {
+                rateService.mergePdf(rate);
+            } catch (IOException e) {
+                log.error(e.getMessage());
+            }
+        });
+    }
+
     @OperLog(value = "等级评定", type = "修改", desc = "对等级评定申请进行操作")
     @ApiOperation("设置审查时间")
     @GetMapping("/saveReviewTime")

+ 13 - 2
src/main/java/com/izouma/wenlvju/web/regulation/ReportController.java

@@ -62,14 +62,25 @@ public class ReportController extends BaseController {
         ExcelUtils.export(response, data);
     }
 
-    @PostMapping("/word")
+    @PostMapping("/freemarkerWord")
     public void word(@RequestBody Report report) throws TemplateException, IOException {
-        reportService.word(report);
+        reportService.freemarkerWord(report);
     }
 
     @PostMapping("/poiWord")
     public void poiWord(@RequestBody Report report) throws IOException, InvalidFormatException {
         reportService.poiWord(report);
     }
+
+    @PostMapping("/saveStatistic")
+    public void saveStatistic(@RequestBody Report report) {
+        reportService.saveStatistic(report);
+    }
+
+    @PostMapping("/generateWord/{id}")
+    public String generateWord(@PathVariable Long id) throws IOException, InvalidFormatException {
+        Report report = reportRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        return reportService.generateWord(report);
+    }
 }
 

+ 0 - 0
src/main/resources/static/certificate.jpeg → src/main/resources/static/certificate28202.jpeg


BIN
src/main/resources/templates/chart/poiTemp.docx


+ 17 - 6
src/main/vue/src/views/record/ReportList.vue

@@ -67,7 +67,7 @@
             <el-table-column label="操作" align="center" fixed="right" min-width="150">
                 <template slot-scope="{ row }">
                     <el-button type="primary" size="mini" plain @click="statisticRow(row)">查看</el-button>
-                    <el-button type="primary" size="mini" plain @click="downloadRow(row.file)">下载</el-button>
+                    <el-button type="primary" size="mini" plain @click="downloadRow(row)">下载</el-button>
                     <!-- <el-button @click="deleteRow(row)" type="danger" size="mini" plain>删除</el-button> -->
                 </template>
             </el-table-column>
@@ -267,9 +267,7 @@ export default {
             this.loading = true;
             this.$alert('确认生成吗?', '警告', { type: 'error' })
                 .then(() => {
-                    return this.$http.post('/report/word', this.form, { body: 'json' })(() => {
-                        this.getData();
-                    });
+                    return this.$http.post('/report/saveStatistic', this.form, { body: 'json' });
                 })
                 .then(() => {
                     this.$message.success('生成成功');
@@ -283,8 +281,21 @@ export default {
                     this.loading = false;
                 });
         },
-        downloadRow(file) {
-            window.open(file, '_blank');
+        downloadRow(row) {
+            if (row.file != '' && typeof row.file != 'undefined') {
+                window.open(row.file, '_blank');
+            } else {
+                this.$http
+                    .post('report/generateWord/' + row.id)
+                    .then(res => {
+                        window.open(res, '_blank');
+                        this.getData();
+                    })
+                    .catch(e => {
+                        console.log(e);
+                        this.$message.error(e.error);
+                    });
+            }
         },
         statisticRow(row) {
             this.$router.push({

+ 1 - 11
src/main/vue/src/widgets/ExamWidegt.vue

@@ -46,16 +46,6 @@ export default {
             let data = [];
             let res = [...this.types];
 
-            // let total = this.allData[year].baokao;
-
-            // res.forEach((item, index) => {
-            //     let _val = this.getRandomMoney(res.length - index, total);
-            //     total -= _val;
-            //     data.push({
-            //         name: item.name,
-            //         value: _val
-            //     });
-            // });
             res.forEach(item => {
                 // let name = '音乐';
                 // if (item.name == 'dance') {
@@ -68,7 +58,7 @@ export default {
                 //     name = '曲艺';
                 // }
                 data.push({
-                    name: name,
+                    name: item.name,
                     value: item.num
                 });
             });

+ 19 - 1
src/test/java/com/izouma/wenlvju/service/performance/ParticipantServiceTest.java

@@ -1,6 +1,7 @@
 package com.izouma.wenlvju.service.performance;
 
 
+import cn.hutool.core.collection.CollUtil;
 import com.google.zxing.BarcodeFormat;
 import com.google.zxing.EncodeHintType;
 import com.google.zxing.MultiFormatWriter;
@@ -9,6 +10,7 @@ import com.google.zxing.client.j2se.MatrixToImageWriter;
 import com.google.zxing.common.BitMatrix;
 import com.izouma.wenlvju.ApplicationTests;
 import com.izouma.wenlvju.domain.performance.Participant;
+import com.izouma.wenlvju.domain.regulation.Report;
 import com.izouma.wenlvju.exception.BusinessException;
 import com.izouma.wenlvju.repo.performance.ParticipantRepo;
 import net.coobird.thumbnailator.Thumbnails;
@@ -20,7 +22,9 @@ import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.*;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.List;
 
 public class ParticipantServiceTest extends ApplicationTests {
 
@@ -127,7 +131,21 @@ public class ParticipantServiceTest extends ApplicationTests {
     @Test
     public void test3() throws IOException, WriterException {
         Participant participant = participantRepo.findById(3048L).orElseThrow(new BusinessException("无记录"));
-        System.out.println(participantService.createAward(participant, "多声部手风琴原创作品《最美的风景》"));
+        System.out.println(participantService.createAward(participant, "多声部手风琴原创作品《最美的风景》", 123L));
     }
 
+    @Test
+    public void test4() {
+        List<Report> reports = new ArrayList<>();
+        reports.add(Report.builder()
+                .year(2021)
+                .build());
+        reports.add(Report.builder()
+                .year(2022)
+                .build());
+        System.out.println(reports);
+        reports.forEach(report -> report.setQuarterly(1));
+        System.out.println(reports);
+
+    }
 }