| | |
| | | import com.estate.expert.admin.stat.report.render.AbstractInfoTablePolicy; |
| | | import com.estate.expert.admin.stat.report.render.CheckInfoTablePolicy; |
| | | import com.estate.expert.admin.stat.report.render.CustomPictureRenderPolicy; |
| | | import lombok.AllArgsConstructor; |
| | | import com.estate.expert.admin.stat.report.render.DeviceGroupTablePolicy; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | /** |
| | | * 第三方评估报告构建器 |
| | | */ |
| | | @AllArgsConstructor |
| | | public class SystemReportBuilder implements ReportBuilderBase { |
| | | |
| | | private static final String DEFAULT_TEMPLATE_FILE = "第三方评估报告.docx"; |
| | | |
| | | protected UserFileService userFileService; |
| | | |
| | | private final String templateFile; |
| | | |
| | | public SystemReportBuilder(UserFileService userFileService) { |
| | | this(userFileService, DEFAULT_TEMPLATE_FILE); |
| | | } |
| | | |
| | | public SystemReportBuilder(UserFileService userFileService, String templateFile) { |
| | | this.userFileService = userFileService; |
| | | this.templateFile = templateFile; |
| | | } |
| | | |
| | | /** |
| | | * 构建第三方评估报告 |
| | |
| | | */ |
| | | @Override |
| | | public XWPFTemplate buildReport(JSONObject data, Map<String, Integer> templateConfig) { |
| | | var res = new ClassPathResource("templates/第三方评估报告.docx"); |
| | | var res = new ClassPathResource("templates/" + templateFile); |
| | | |
| | | var viewConfig = templateConfig != null ? toViewConfig(templateConfig) : null; |
| | | var builder = initConfig(viewConfig); |
| | |
| | | */ |
| | | private ConfigureBuilder initConfig(Map<String, Boolean> viewConfig){ |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.bind("data.设备信息", new LoopRowTableRenderPolicy()); |
| | | builder.bind("data.设备分组信息", new DeviceGroupTablePolicy()); |
| | | builder.bind("data.评估结果.隐患等级分布.分项", new LoopRowTableRenderPolicy()); |
| | | builder.bind("分项评估", new CheckInfoTablePolicy()); |
| | | |
| | |
| | | * @param dataMap 数据映射 |
| | | */ |
| | | private void initChart(JSONObject data, Map<String, Object> dataMap){ |
| | | var checkCategories = data.getJSONObject("评估结果").getJSONArray("检查项"); |
| | | var evalResult = data.getJSONObject("评估结果"); |
| | | var checkCategories = evalResult.getJSONArray("检查项"); |
| | | if(checkCategories == null) return; |
| | | var safetyCategories = new JSONArray(); |
| | | for (var c : checkCategories){ |
| | | var co = (JSONObject)c; |
| | | var name = co.getString("名称"); |
| | | if(name != null && name.contains("安全")) |
| | | safetyCategories.add(co); |
| | | var pieChart = buildPieChart(co); |
| | | if(pieChart!=null) |
| | | co.put("问题分布饼图", pieChart); |
| | |
| | | if(barChart!=null) |
| | | co.put("问题分布直方图", barChart); |
| | | } |
| | | if(safetyCategories.isEmpty() && !checkCategories.isEmpty()) |
| | | safetyCategories.add(checkCategories.get(0)); |
| | | evalResult.put("安全检查项", safetyCategories); |
| | | } |
| | | |
| | | /** |