| | |
| | | import com.ruoyi.common.constant.InsOrderTypeConstants; |
| | | import com.ruoyi.common.constant.MenuJumpPathConstants; |
| | | import com.ruoyi.common.core.domain.Result; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.InformationNotification; |
| | | import com.ruoyi.common.utils.DateImageUtil; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | |
| | | import com.ruoyi.inspect.util.ReportSealLayoutUtil; |
| | | import com.ruoyi.inspect.util.ReportSignaturePictureUtils; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import com.ruoyi.system.service.InformationNotificationService; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | |
| | | private InsProductMapper insProductMapper; |
| | | @Resource |
| | | private InformationNotificationService informationNotificationService; |
| | | @Resource |
| | | private ISysMenuService menuService; |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | @Value("${file.path}") |
| | |
| | | if (userId == null) { |
| | | throw new ErrorException("缺少审核人"); |
| | | } |
| | | ensureReportPreparationPermission(userId, "审核人"); |
| | | insReport.setExamineUserId(userId);//审核人 |
| | | insReport.setWriteTime(LocalDateTime.now());//提交时间 |
| | | //获取提交人的签名地址 |
| | |
| | | info.setViewStatus(false); |
| | | info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION); |
| | | informationNotificationService.addInformationNotification(info); |
| | | String primaryReportUrl = getPrimaryReportUrl(insReport); |
| | | |
| | | // 判断是否是原材料 需要替换****成供应商 |
| | | IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>() |
| | | .eq(IfsInventoryQuantity::getId, order.getIfsInventoryId())); |
| | |
| | | }}; |
| | | writeMarksToReportFiles(insReport, writeMarks); |
| | | |
| | | // 修改临时pdf |
| | | String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl)); |
| | | insReport.setTempUrlPdf("/word/" + tempUrlPdf); |
| | | refreshTemporaryPreviews(insReport); |
| | | |
| | | insReportMapper.updateById(insReport); |
| | | |
| | |
| | | .set(InsReport::getIsExamine, null)); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 指定审核人/批准人时,确认对方登录后能看到「报告编制」页面, |
| | | * 避免指定后登录只剩首页、无法继续审批。 |
| | | */ |
| | | private void ensureReportPreparationPermission(Integer userId, String userLabel) { |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId.longValue()); |
| | | if (!containsReportPreparation(menus)) { |
| | | throw new ErrorException("所选" + userLabel + "没有「业务管理 → 报告编制」页面权限,请先在「系统管理 → 用户管理」为其分配对应角色"); |
| | | } |
| | | } |
| | | |
| | | private boolean containsReportPreparation(List<SysMenu> menus) { |
| | | if (CollectionUtils.isEmpty(menus)) { |
| | | return false; |
| | | } |
| | | for (SysMenu menu : menus) { |
| | | if (Long.valueOf(1129L).equals(menu.getMenuId()) |
| | | || "reportPreparation".equals(menu.getPath())) { |
| | | return true; |
| | | } |
| | | if (containsReportPreparation(menu.getChildren())) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | //审核 |
| | |
| | | if (userId == null) { |
| | | throw new ErrorException("缺少批准人"); |
| | | } |
| | | ensureReportPreparationPermission(userId, "批准人"); |
| | | if (Objects.equals(insReport.getExamineUserId(), userId)) { |
| | | throw new ErrorException("审核人和批准人不能为同一人,请重新选择批准人"); |
| | | } |
| | |
| | | info.setViewStatus(false); |
| | | info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION); |
| | | informationNotificationService.addInformationNotification(info); |
| | | String primaryReportUrl = getPrimaryReportUrl(insReport); |
| | | Map<String, Object> examineMarks = new HashMap<String, Object>() {{ |
| | | put("examineUrl", ReportSignaturePictureUtils.create(imgUrl, signatureUrl)); |
| | | put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create()); |
| | | }}; |
| | | writeMarksToReportFiles(insReport, examineMarks); |
| | | |
| | | // 修改临时pdf |
| | | String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl)); |
| | | insReport.setTempUrlPdf("/word/" + tempUrlPdf); |
| | | refreshTemporaryPreviews(insReport); |
| | | |
| | | // 发送企业微信通知(通知批准人审批) |
| | | threadPoolTaskExecutor.execute(() -> { |
| | |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private void refreshTemporaryPreviews(InsReport report) { |
| | | String primaryPdf = wordToPdfTemp(getPrimaryReportUrl(report).replace("/word", wordUrl)); |
| | | if (StringUtils.isBlank(primaryPdf)) { |
| | | throw new ErrorException("检测报告预览生成失败"); |
| | | } |
| | | report.setTempUrlPdf("/word/" + primaryPdf); |
| | | if (StringUtils.isNotBlank(report.getInspectionUrl())) { |
| | | String inspectionPdf = wordToPdfTemp(report.getInspectionUrl().replace("/word", wordUrl)); |
| | | if (StringUtils.isBlank(inspectionPdf)) { |
| | | throw new ErrorException("检验报告预览生成失败"); |
| | | } |
| | | report.setInspectionTempUrlPdf("/word/" + inspectionPdf); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String prepareEditedReportPreview(String absoluteDocxPath) { |
| | | String pdfName = wordToPdfTemp(absoluteDocxPath); |
| | | if (StringUtils.isBlank(pdfName)) { |
| | | throw new ErrorException("报告预览生成失败"); |
| | | } |
| | | return "/word/" + pdfName; |
| | | } |
| | | |
| | | private void writeMarksToReportFiles(InsReport report, Map<String, Object> marks) { |
| | | for (String reportUrl : getApprovalReportUrls(report)) { |
| | | wordInsertUrl(marks, reportUrl.replace("/word", wordUrl)); |
| | |
| | | throw new ErrorException("报告文件不存在,请联系管理员"); |
| | | } |
| | | try { |
| | | String filename = file.getFileName().toString(); |
| | | // 物理文件可能是 reviewed/edited UUID;对用户始终使用业务报告编号。 |
| | | String reportNumber = StringUtils.isBlank(report.getCode()) ? "报告" : report.getCode(); |
| | | reportNumber = reportNumber.replaceAll("[\\\\/:*?\"<>|\\p{Cntrl}]", "-").trim(); |
| | | String suffix = StringUtils.isNotBlank(report.getInspectionUrl()) |
| | | ? (Objects.equals(reportType, INSPECTION_REPORT) ? "-检验报告" : "-检测报告") : ""; |
| | | String filename = reportNumber + suffix + ".docx"; |
| | | String encodedName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20"); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
| | | response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedName); |