| | |
| | | package com.estate.expert.admin.controller.admin; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.estate.expert.admin.domain.business.client.ClientDto; |
| | | import com.estate.expert.admin.domain.business.client.clientparam.ClientParam; |
| | | import com.estate.expert.admin.domain.report.ReportTemplate; |
| | |
| | | return Result.success(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "委托方获取参数",response = ClientParam.class) |
| | | @GetMapping("/getParam") |
| | | public Result getParam(@RequestParam Integer clientId) { |
| | | ClientParam clientParam = clientParamService.getOne(new LambdaQueryWrapper<ClientParam>().eq(ClientParam::getClientId, clientId).last("limit 1")); |
| | | return Result.success(clientParam); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "委托方获取模板",response = ReportTemplate.class) |
| | | @PostMapping("/getTemplate") |
| | | public Result getTemplate(@ApiParam(value = "模板类型0安全 1设备") @RequestParam(value = "type") Integer type) { |
| | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * @TableName device 设备管理 |
| | | * |
| | | * 编号(对应name) |
| | | * 出厂编号(对应name) |
| | | */ |
| | | @Getter |
| | | @Setter |
| | |
| | | private DeviceType type; |
| | | |
| | | /** |
| | | * 出厂编号 |
| | | * 设备编号 |
| | | */ |
| | | @Column(nullable = false) |
| | | private String manufacturerNumber; |
| | |
| | | @Override |
| | | public String getOptionName() { |
| | | // return String.format("%s - %s", getName(), type.getDesc()); |
| | | return getName(); |
| | | return getManufacturerNumber(); |
| | | } |
| | | } |
| | |
| | | @NotNull(message = "设备类型不能为空") |
| | | DeviceType type; |
| | | |
| | | @ApiModelProperty("设备编号") |
| | | @NotBlank(message = "设备编号不能为空") |
| | | String name; |
| | | |
| | | @ApiModelProperty("出厂编号") |
| | | @NotBlank(message = "出厂编号不能为空") |
| | | String name; |
| | | |
| | | @ApiModelProperty("设备编号") |
| | | @NotBlank(message = "设备编号不能为空") |
| | | String manufacturerNumber; |
| | | |
| | | @ApiModelProperty("设备是否正在使用中") |
| | |
| | | var data = result.root().getData(); |
| | | |
| | | var map = new HashMap<String, Object>(); |
| | | map.put("设备编号", device.getName()); |
| | | map.put("设备编号", device.getManufacturerNumber()); |
| | | map.put("设备类型", device.getType().getDesc()); |
| | | |
| | | map.put("风险等级", data.getRiskLevel().getDesc()); |
| | |
| | | |
| | | var detailData = new FuzzyResultFormatter().format(result); |
| | | map.put("详情", detailData); |
| | | map.put("path", "__DEVICE__"+device.getName()); |
| | | map.put("path", "__DEVICE__"+device.getManufacturerNumber()); |
| | | return map; |
| | | } |
| | | } |
| | |
| | | var data = result.root().getData(); |
| | | |
| | | var map = new HashMap<String, Object>(); |
| | | map.put("设备编号", device.getName()); |
| | | map.put("设备编号", device.getManufacturerNumber()); |
| | | map.put("单台设备评分", formatFloat(data.getScore())); |
| | | |
| | | // 展示特定的层级 |
| | |
| | | node.setPath(device.getId() + node.getPath()); |
| | | }); |
| | | map.put("children", newTree.getChildren()); |
| | | map.put("path", "__DEVICE__"+device.getName()); |
| | | map.put("path", "__DEVICE__"+device.getManufacturerNumber()); |
| | | return map; |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 设备处理器 |
| | | * |
| | | * |
| | | * 用于处理设备信息的读取和写入 |
| | | */ |
| | | public class DeviceProcessor extends RowDataProcessorBase<Device> { |
| | | |
| | | /** |
| | | * 获取表头 |
| | | * |
| | | * |
| | | * @return 表头 |
| | | */ |
| | | protected final String[] getHeaders() { |
| | |
| | | protected List<String> buildRowData(Device data) { |
| | | return List.of( |
| | | data.getType().getDesc(), |
| | | data.getName(), |
| | | data.getManufacturerNumber(), |
| | | getProp(data, "设备型号"), |
| | | getProp(data, "设备出厂日期"), |
| | | data.getManufacturerNumber(), |
| | | data.getName(), |
| | | getProp(data, "报废年限"), |
| | | getProp(data, "使用单位"), |
| | | getProp(data, "工程起重机械生产单位"), |
| | |
| | | protected Device parseRowData(int rowIndex, List<String> rowData) { |
| | | var index = 0; |
| | | var device = new Device(); |
| | | |
| | | |
| | | // 初始化 properties Map |
| | | device.setProperties(new HashMap<>()); |
| | | |
| | |
| | | if(model != null) { |
| | | device.getProperties().put("设备型号", model); |
| | | } |
| | | |
| | | |
| | | String manufactureDate = ExcelParseUtils.parseString(rowData.get(index++)); |
| | | if(manufactureDate != null) { |
| | | device.getProperties().put("设备出厂日期", manufactureDate); |
| | | } |
| | | |
| | | |
| | | device.setManufacturerNumber(ExcelParseUtils.parseString(rowData.get(index++))); |
| | | |
| | | var headers = getHeaders(); |
| | |
| | | BizResultCode.TASK_ALREADY_EXIST.check(task != null); |
| | | BizResultCode.DRIVER_CAR_NOT_MATCH.check( |
| | | entity.getDrivers() != null && entity.getCars() != null |
| | | && entity.getDrivers().size() != entity.getCars().size()); |
| | | && entity.getDrivers().size() != entity.getCars().size()); |
| | | entity.setState(CheckTaskState.Published); |
| | | entity.setName(UUID.randomUUID().toString()); |
| | | return super.add(creator, entity); |
| | |
| | | @Override |
| | | public CheckTask edit(CheckTask entity) { |
| | | BizResultCode.TASK_STATUS_ERROR.check(entity.getState() != CheckTaskState.Init |
| | | && entity.getState() != CheckTaskState.Rejected |
| | | && entity.getState() != CheckTaskState.EXECUTING |
| | | && entity.getState() != CheckTaskState.Published); |
| | | && entity.getState() != CheckTaskState.Rejected |
| | | && entity.getState() != CheckTaskState.EXECUTING |
| | | && entity.getState() != CheckTaskState.Published); |
| | | return super.edit(entity); |
| | | } |
| | | |
| | |
| | | var device = deviceUsage.getDevice(); |
| | | var dt = buildDeviceHierarchyTree(modelTree, records, device); |
| | | dt.setId(device.getId()); |
| | | dt.setName(device.getName()); |
| | | dt.setName(device.getManufacturerNumber()); |
| | | treeRoot.addChild(dt); |
| | | }); |
| | | return treeRoot; |
| | |
| | | builder.bind("data.评估结果.隐患等级分布汇总.分项", new LoopRowTableRenderPolicy()); |
| | | builder.bind("分项隐患", new LoopRowTableRenderPolicy()); |
| | | builder.bind("分项问题", new DeviceTablePolicy()); |
| | | // builder.bind("data.设备信息", new DeviceInfoTablePolicy()); |
| | | |
| | | builder.addPlugin('%', new CustomPictureRenderPolicy(userFileService)); |
| | | |
| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | |
| | | List<Object> result = new ArrayList<>(); |
| | | |
| | | JSONObject info = new JSONObject(); |
| | | info.put("设备编号", device.getName()); |
| | | info.put("设备编号", device.getManufacturerNumber()); |
| | | |
| | | var errorCounts = deviceRes.root().getData().getTotalErrorCounts(); |
| | | info.put("一级隐患", errorCounts[0]); |
| | |
| | | List<Object> result = new ArrayList<>(); |
| | | |
| | | JSONObject info = new JSONObject(); |
| | | info.put("设备编号", device.getName()); |
| | | info.put("设备编号", device.getManufacturerNumber()); |
| | | |
| | | info.put("问题", buildDeviceErrorInfo(device)); |
| | | result.add(info); |
| | |
| | | * @return 设备记录 |
| | | */ |
| | | private List<ErrorRecord> buildDeviceRecords(Device device){ |
| | | return records.stream().filter(r -> r.getDevice().getId().equals(device.getId())).toList(); |
| | | return records.stream() |
| | | .filter(r -> r.getDevice().getId().equals(device.getId())) |
| | | .sorted(Comparator.comparing(r -> r.getLevel() != null ? r.getLevel().ordinal() : ErrorLevel.P4.ordinal())) |
| | | .toList(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | protected List<Object> buildDeviceInfo() { |
| | | List<Object> deviceInfos = new ArrayList<>(); |
| | | for (var device : devices) { |
| | | // 按照设备类型排序 |
| | | var sortedDevices = devices.stream() |
| | | .sorted(Comparator.comparing(device -> device.getType() != null ? device.getType().ordinal() : Integer.MAX_VALUE)) |
| | | .collect(Collectors.toList()); |
| | | for (var device : sortedDevices) { |
| | | JSONObject deviceInfo = new JSONObject(); |
| | | deviceInfo.put("设备类型", device.getType().getDesc()); |
| | | deviceInfo.put("设备编号", device.getName()); |
| | | deviceInfo.put("设备编号", device.getManufacturerNumber()); |
| | | deviceInfo.put("设备租赁单位", device.getProperties().get("工程起重机械租赁单位")); |
| | | deviceInfo.put("设备使用单位", device.getProperties().get("使用单位")); |
| | | deviceInfo.put("安拆单位", device.getProperties().get("工程起重机械安拆单位")); |
| | |
| | | int totalErrors = Arrays.stream(node.getData().getTotalErrorCounts()).sum(); |
| | | result.put("隐患数量", totalErrors); |
| | | List<Object> errorInfos = new ArrayList<>(); |
| | | for (int i = 3; i>=0 ; i--) { |
| | | for (int i = 0; i<4 ; i++) { |
| | | var level = ErrorLevel.values()[i]; |
| | | var count = node.getData().getTotalErrorCounts()[i]; |
| | | var info = new JSONObject(); |
| | |
| | | var problem = record.getProblem(); |
| | | JSONObject subItem = new JSONObject(); |
| | | if(record.getDevice() != null) |
| | | subItem.put("设备编号", record.getDevice().getName()); |
| | | subItem.put("设备编号", record.getDevice().getManufacturerNumber()); |
| | | subItem.put("隐患等级", record.getLevel().getDesc()); |
| | | subItem.put("问题部位", record.getProblemPart()); |
| | | subItem.put("问题备注", trimText(StringUtils.hasText(record.getRemark()) ? record.getRemark() : problem.getDescription())); |
| | |
| | | |
| | | if(!CollectionUtils.isEmpty(problem.getSpecificTerms())){ |
| | | StringBuilder sb = new StringBuilder(); |
| | | var terms = CollectionUtils.isEmpty(record.getSpecificTermIndexes()) |
| | | ? problem.getSpecificTerms() |
| | | : record.getSpecificTermIndexes().stream() |
| | | var terms = CollectionUtils.isEmpty(record.getSpecificTermIndexes()) |
| | | ? problem.getSpecificTerms() |
| | | : record.getSpecificTermIndexes().stream() |
| | | .filter(idx -> idx < problem.getSpecificTerms().size()) |
| | | .map(problem.getSpecificTerms()::get) |
| | | .collect(Collectors.toList()); |
| | | |
| | | |
| | | for(int i = 0; i < terms.size(); i++) { |
| | | sb.append(terms.get(i)); |
| | | if(i < terms.size() - 1) { |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | |
| | | info.put("类别", n.getName()); |
| | | info.put("序号", index.getAndIncrement() + 1); |
| | | buildNode(info, n); |
| | | |
| | | |
| | | // 从fuzzyNode中获取评价 |
| | | var fuzzyNode = getFuzzyNodeByPath(n.getPath()); |
| | | if(fuzzyNode != null && fuzzyNode.getData() != null && fuzzyNode.getData().getRiskLevel() != null) { |
| | |
| | | var errors = new ArrayList<>(); |
| | | // 按 problem.id 去重,相同问题只保留第一个记录 |
| | | var nodeRecords = records.stream() |
| | | .filter(record -> record.getProblem() != null && |
| | | .filter(record -> record.getProblem() != null && |
| | | record.getProblem().getHierarchyPath() != null && |
| | | record.getProblem().getHierarchyPath().startsWith(suffix)) |
| | | .collect(java.util.stream.Collectors.toMap( |
| | |
| | | record -> record, |
| | | (existing, replacement) -> existing // 保留第一个遇到的记录 |
| | | )) |
| | | .values(); |
| | | |
| | | .values() |
| | | .stream() |
| | | // 按照record.errorLevel排序 |
| | | .sorted(Comparator.comparing(ErrorRecord::getLevel, Comparator.nullsLast(Comparator.naturalOrder()))) |
| | | .toList(); |
| | | |
| | | for(var record : nodeRecords){ |
| | | var subItem = buildRecordDetail(record); |
| | | subItem.put("项目级别", errorNodeName(record)); |
| | |
| | | package com.estate.expert.admin.stat.report.render; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.deepoove.poi.policy.DynamicTableRenderPolicy; |
| | | import com.estate.expert.admin.domain.exam.record.error.ErrorLevel; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | * 这里循环渲染表格 |
| | | * */ |
| | | public class CheckInfoTablePolicy extends DynamicTableRenderPolicy { |
| | | |
| | | private String colorCommon = "000000"; |
| | | private String colorP1 = "FF0000"; |
| | | |
| | | // 橙色 |
| | | private String colorP2 = "FF8000"; |
| | | |
| | | /** |
| | | * 渲染检查信息表格 |
| | |
| | | var errors = info.getJSONArray("问题"); |
| | | if(!CollectionUtils.isEmpty(errors)){ |
| | | |
| | | var highLevelColor = highLevelColor(errors); |
| | | var highLevelColor = RenderHelper.highLevelColor(errors); |
| | | for(var error : errors){ |
| | | var e = (JSONObject) error; |
| | | var row = table.insertNewTableRow(table.getRows().size()); |
| | | var textColor = colorCommon; |
| | | var errorLevel = e.getString("隐患等级"); |
| | | if(errorLevel.equals("一级隐患")){ |
| | | textColor = colorP1; |
| | | }else if(errorLevel.equals("二级隐患")){ |
| | | textColor = colorP2; |
| | | } |
| | | var textColor = RenderHelper.getErrorLevelColor(errorLevel); |
| | | RenderHelper.renderCell(row, info.getString("类别"), highLevelColor); |
| | | RenderHelper.renderCell(row, e.getString("问题部位"), textColor); |
| | | RenderHelper.renderCell(row, e.getString("问题备注"), textColor); |
| | |
| | | int endRow = table.getRows().size() - 1; |
| | | if(isErrorSummary && endRow > 3){ |
| | | RenderHelper.mergeCellsVertically(table, 2, 0); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取最高隐患等级颜色 |
| | | * @param errorRecords 错误记录 |
| | | * @return 最高隐患等级颜色 |
| | | */ |
| | | private String highLevelColor(JSONArray errorRecords){ |
| | | var minLevel = ErrorLevel.P4; |
| | | |
| | | for(var errorRecord : errorRecords){ |
| | | var e = (JSONObject) errorRecord; |
| | | var levelStr = e.getString("隐患等级"); |
| | | var level = ErrorLevel.getByDesc(levelStr); |
| | | if(level != null && level.ordinal() < minLevel.ordinal()){ |
| | | minLevel = level; |
| | | } |
| | | } |
| | | |
| | | switch (minLevel){ |
| | | case P1: |
| | | return colorP1; |
| | | case P2: |
| | | return colorP2; |
| | | default: |
| | | return colorCommon; |
| | | } |
| | | } |
| | | |
| New file |
| | |
| | | package com.estate.expert.admin.stat.report.render; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.deepoove.poi.policy.DynamicTableRenderPolicy; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 设备信息表格渲染策略 |
| | | */ |
| | | public class DeviceInfoTablePolicy extends DynamicTableRenderPolicy { |
| | | |
| | | /** |
| | | * 渲染设备信息表格 |
| | | * @param table 表格 |
| | | * @param data 数据 |
| | | * @throws Exception 异常 |
| | | */ |
| | | @Override |
| | | public void render(XWPFTable table, Object data) throws Exception { |
| | | if (data == null) { |
| | | return; |
| | | } |
| | | |
| | | var deviceInfoList = (List<Object>) data; |
| | | if (CollectionUtils.isEmpty(deviceInfoList)) { |
| | | return; |
| | | } |
| | | |
| | | for (var deviceInfo : deviceInfoList) { |
| | | var info = (JSONObject) deviceInfo; |
| | | var row = table.insertNewTableRow(table.getRows().size() - 3); |
| | | |
| | | RenderHelper.renderCell(row, ""); |
| | | RenderHelper.renderCell(row, info.getString("设备类型")); |
| | | RenderHelper.renderCell(row, "1"); |
| | | RenderHelper.renderCell(row, info.getString("设备编号")); |
| | | RenderHelper.renderCell(row, info.getString("设备租赁单位")); |
| | | RenderHelper.renderCell(row, info.getString("设备使用单位")); |
| | | RenderHelper.renderCell(row, info.getString("安拆单位")); |
| | | RenderHelper.renderCell(row, info.getString("检测单位")); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.deepoove.poi.policy.DynamicTableRenderPolicy; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | /** |
| | | * 设备表格渲染策略 |
| | |
| | | var deviceInfo = (JSONObject) d; |
| | | var records = deviceInfo.getJSONArray("问题"); |
| | | var name = deviceInfo.getString("设备编号"); |
| | | for (var record : records) { |
| | | var info = (JSONObject) record; |
| | | var row = table.insertNewTableRow(table.getRows().size() ); |
| | | RenderHelper.renderCell(row, name); |
| | | RenderHelper.renderCell(row, info.getString("检查问题")); |
| | | RenderHelper.renderCell(row, info.getString("隐患等级")); |
| | | if (!CollectionUtils.isEmpty(records)) { |
| | | var highLevelColor = RenderHelper.highLevelColor(records); |
| | | for (var record : records) { |
| | | var info = (JSONObject) record; |
| | | var row = table.insertNewTableRow(table.getRows().size()); |
| | | var errorLevel = info.getString("隐患等级"); |
| | | var textColor = RenderHelper.getErrorLevelColor(errorLevel); |
| | | RenderHelper.renderCell(row, name, highLevelColor); |
| | | RenderHelper.renderCell(row, info.getString("检查问题"), textColor); |
| | | RenderHelper.renderCell(row, info.getString("隐患等级"), textColor); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | package com.estate.expert.admin.stat.report.render; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.deepoove.poi.util.TableTools; |
| | | import com.estate.expert.admin.domain.exam.record.error.ErrorLevel; |
| | | import lombok.extern.log4j.Log4j2; |
| | | import org.apache.poi.xwpf.usermodel.ParagraphAlignment; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | |
| | | */ |
| | | @Log4j2 |
| | | public class RenderHelper { |
| | | |
| | | // 颜色常量 |
| | | private static final String COLOR_COMMON = "000000"; |
| | | private static final String COLOR_P1 = "FF0000"; |
| | | private static final String COLOR_P2 = "FF8000"; |
| | | |
| | | /** |
| | | * 渲染单元格 |
| | |
| | | TableTools.mergeCellsVertically(table, col, start, size - 1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取最高隐患等级颜色 |
| | | * @param errorRecords 错误记录 |
| | | * @return 最高隐患等级颜色 |
| | | */ |
| | | public static String highLevelColor(JSONArray errorRecords) { |
| | | var minLevel = ErrorLevel.P4; |
| | | |
| | | for (var errorRecord : errorRecords) { |
| | | var e = (JSONObject) errorRecord; |
| | | var levelStr = e.getString("隐患等级"); |
| | | var level = ErrorLevel.getByDesc(levelStr); |
| | | if (level != null && level.ordinal() < minLevel.ordinal()) { |
| | | minLevel = level; |
| | | } |
| | | } |
| | | |
| | | switch (minLevel) { |
| | | case P1: |
| | | return COLOR_P1; |
| | | case P2: |
| | | return COLOR_P2; |
| | | default: |
| | | return COLOR_COMMON; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据隐患等级获取颜色 |
| | | * @param errorLevel 隐患等级字符串 |
| | | * @return 对应的颜色 |
| | | */ |
| | | public static String getErrorLevelColor(String errorLevel) { |
| | | if (errorLevel == null) { |
| | | return COLOR_COMMON; |
| | | } |
| | | if (errorLevel.equals("一级隐患")) { |
| | | return COLOR_P1; |
| | | } else if (errorLevel.equals("二级隐患")) { |
| | | return COLOR_P2; |
| | | } |
| | | return COLOR_COMMON; |
| | | } |
| | | } |
| | |
| | | |
| | | @Test |
| | | public void testDeviceReportData() throws IOException { |
| | | var reportData = reportService.fuzzyReportData(1256, 2); |
| | | var reportData = reportService.fuzzyReportData(203, 2); |
| | | var string = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(reportData); |
| | | |
| | | // write to file |
| | |
| | | |
| | | @Test |
| | | public void testBuildSystemScoreReport() throws IOException { |
| | | var template = reportService.scoreReport(1256, 1); |
| | | var template = reportService.scoreReport(1435, 1); |
| | | template.writeToFile("/Volumes/Works/tmp/system_score_report.docx"); |
| | | } |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testBuildDeviceScoreReport() throws IOException { |
| | | var template = reportService.scoreReport(1, 2); |
| | | var template = reportService.scoreReport(1403, 2); |
| | | template.writeToFile("/Volumes/Works/tmp/device_score_report.docx"); |
| | | } |
| | | |