| | |
| | | import com.ruoyi.common.enums.ApplyTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.tax.VatTaxUtils; |
| | | import com.ruoyi.common.utils.HttpClientKit; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.DtoConversionUtils; |
| | |
| | | FlowLevel = 0; |
| | | } |
| | | } |
| | | |
| | | SysUser sysUser = sysUserService.selectUserByUserName(serviceFund.getUserno()); |
| | | //审批未通过:单据信息 + 审批人/审批时间/意见(意见 = "审批未通过。" + 驳回意见) |
| | | List<ConcurrentHashMap<String, Object>> contentList = FundNotifyMessageBuilder.newRows(); |
| | | FundNotifyMessageBuilder.addBillInfo(contentList, serviceFund.getApplytype(), |
| | | serviceFund.getUsername(), serviceFund.getPretaxcost(), serviceFund.getDonorname(), |
| | | FundNotifyMessageBuilder.billNo(serviceFund.getBh(), serviceFund.getId())); |
| | | FundNotifyMessageBuilder.addAuditResult(contentList, loginUser.getUser().getNickName(), new Date(), |
| | | FundNotifyMessageBuilder.opinion(FundNotifyMessageBuilder.CONCLUSION_REJECT, |
| | | checkFundVO.getFlowcontent())); |
| | | try { |
| | | DingTalkReqVo dingTalkReqVo = new DingTalkReqVo(); |
| | | dingTalkReqVo.setTitle(FundNotifyMessageBuilder.TITLE); |
| | | dingTalkReqVo.setNumber(sysUser.getPhonenumber()); |
| | | dingTalkReqVo.setContents(contentList); |
| | | dingTalkService.sendNotification(dingTalkReqVo); |
| | | } catch (Exception e) { |
| | | log.error("费用---审批未通过钉钉通知失败,fundId={}", serviceFund.getId(), e); |
| | | } |
| | | } |
| | | |
| | | SysUser sysUser = sysUserService.selectUserByUserName(serviceFund.getUserno()); |
| | | //审批未通过:单据信息 + 审批人/审批时间/意见(意见 = "审批未通过。" + 驳回意见) |
| | | List<ConcurrentHashMap<String, Object>> contentList = FundNotifyMessageBuilder.newRows(); |
| | | FundNotifyMessageBuilder.addBillInfo(contentList, serviceFund.getApplytype(), |
| | | serviceFund.getUsername(), serviceFund.getPretaxcost(), serviceFund.getDonorname(), |
| | | FundNotifyMessageBuilder.billNo(serviceFund.getBh(), serviceFund.getId())); |
| | | FundNotifyMessageBuilder.addAuditResult(contentList, loginUser.getUser().getNickName(), new Date(), |
| | | FundNotifyMessageBuilder.opinion(checkFundVO.getFlowconclusion()+"", |
| | | checkFundVO.getFlowcontent())); |
| | | try { |
| | | DingTalkReqVo dingTalkReqVo = new DingTalkReqVo(); |
| | | dingTalkReqVo.setTitle(FundNotifyMessageBuilder.TITLE); |
| | | dingTalkReqVo.setNumber(sysUser.getPhonenumber()); |
| | | dingTalkReqVo.setContents(contentList); |
| | | dingTalkService.sendNotification(dingTalkReqVo); |
| | | } catch (Exception e) { |
| | | log.error("费用---审批未通过钉钉通知失败,fundId={}", serviceFund.getId(), e); |
| | | } |
| | | serviceFund.setRecordstatus(RecordStatus); |
| | | serviceFund.setFlowlevel(FlowLevel.longValue()); |
| | | // serviceFund.setBackflowlevel(serviceFund.getFlowlevel()); |
| | |
| | | } |
| | | map.put("发票识别", null); |
| | | map.put("识别人", null); |
| | | map.put("税额", serviceFunddetailShared.getTaxamount()); |
| | | // 明细“税额”按“扣税合计”口径:劳务个税 + 增值税 + 城建税, |
| | | // 与主表“税额合计”(PretaxCost − TaxedCost)对齐;v1 历史数据增值税/城建税为 0,取值与改造前一致。 |
| | | map.put("税额", totalTaxOf(serviceFunddetailShared)); |
| | | long qtuuid = IdGeneratorUtils.nextId(); |
| | | map.put("其他附件", ""); |
| | | if (StringUtils.isNotEmpty(annexfiles)) { |
| | |
| | | allMap.put("formson_0832", list); |
| | | allMap.put("annexfilesList", annexfilesList); |
| | | return allMap; |
| | | } |
| | | |
| | | /** |
| | | * 明细上传协友的“税额” = 劳务个税 + 增值税 + 城建税(扣税合计口径)。 |
| | | * <p> |
| | | * 背景:2026-11 新增增值税、城建税后,主表“税额合计”取 `PretaxCost − TaxedCost`, |
| | | * 天然包含这两项;若明细仍只发劳务个税,致远里“税额合计 ≠ 明细税额之和”(差增值税+城建税)。 |
| | | * v1 历史数据的增值税/城建税均为 0,取值与改造前完全一致。 |
| | | */ |
| | | private static BigDecimal totalTaxOf(ServiceFunddetailShared detail) { |
| | | if (detail == null) { |
| | | return BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_HALF_UP); |
| | | } |
| | | BigDecimal tax = detail.getTaxamount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getTaxamount()); |
| | | BigDecimal vat = detail.getVatAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getVatAmount()); |
| | | BigDecimal city = detail.getCityTaxAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getCityTaxAmount()); |
| | | return tax.add(vat).add(city).setScale(2, BigDecimal.ROUND_HALF_UP); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // 保存详情数据 |
| | | for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetails) { |
| | | // 2026-10-15:附件文件名规范二次校验(与前端 fileNameCheck 同口径;只校验本次变更的附件,历史附件放行) |
| | | java.util.Set<String> existingNames = new java.util.HashSet<>(); |
| | | if (serviceFunddetailVO.getId() != null) { |
| | | ServiceFunddetail oldDetail = serviceFunddetailMapper.selectById(serviceFunddetailVO.getId()); |
| | | if (oldDetail != null) { |
| | | existingNames.addAll(com.ruoyi.project.common.AttachmentNameValidator |
| | | .collectNames(oldDetail.getInvoicefiles())); |
| | | existingNames.addAll(com.ruoyi.project.common.AttachmentNameValidator |
| | | .collectNames(oldDetail.getAnnexfiles())); |
| | | } |
| | | } |
| | | String invoiceJson = CollectionUtils.isEmpty(serviceFunddetailVO.getInvoicefilesList()) |
| | | ? serviceFunddetailVO.getInvoicefiles() |
| | | : JSON.toJSONString(serviceFunddetailVO.getInvoicefilesList()); |
| | | String annexJson = CollectionUtils.isEmpty(serviceFunddetailVO.getAnnexfilesList()) |
| | | ? serviceFunddetailVO.getAnnexfiles() |
| | | : JSON.toJSONString(serviceFunddetailVO.getAnnexfilesList()); |
| | | String nameError = com.ruoyi.project.common.AttachmentNameValidator |
| | | .checkJsonListForUpdate(existingNames, invoiceJson, annexJson); |
| | | if (nameError != null) { |
| | | throw new BaseException("附件文件名不符合要求,无法保存:" + nameError); |
| | | } |
| | | //去掉身份证的首尾空格 |
| | | if (StringUtils.isNotEmpty(serviceFunddetailVO.getIdcardno())) { |
| | | serviceFunddetailVO.setIdcardno(serviceFunddetailVO.getIdcardno().trim()); |
| | |
| | | //通过受益人名称,将税前、税后的值相加 |
| | | Map<String, Double> sumAmount = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, Collectors.summingDouble(ServiceFunddetail::getAmount))); |
| | | Map<String, Double> sumTaxdAmount = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, Collectors.summingDouble(ServiceFunddetail::getTaxedamount))); |
| | | // 新增口径:增值税、城建税、劳务税前、劳务个税按受益人合计 |
| | | Map<String, Double> sumVat = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, |
| | | Collectors.summingDouble(d -> d.getVatAmount() == null ? 0.0 : d.getVatAmount()))); |
| | | Map<String, Double> sumCityTax = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, |
| | | Collectors.summingDouble(d -> d.getCityTaxAmount() == null ? 0.0 : d.getCityTaxAmount()))); |
| | | Map<String, Double> sumLaborPretax = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, |
| | | Collectors.summingDouble(d -> d.getLaborPretaxAmount() == null ? 0.0 : d.getLaborPretaxAmount()))); |
| | | Map<String, Double> sumTax = serviceFunddetails.stream().collect(Collectors.groupingBy(ServiceFunddetail::getBeneficiaryname, |
| | | Collectors.summingDouble(d -> d.getTaxamount() == null ? 0.0 : d.getTaxamount()))); |
| | | |
| | | for (String key : sumAmount.keySet()) { |
| | | ServiceFunddetailExcel serviceFunddetailExcel = new ServiceFunddetailExcel(); |
| | | serviceFunddetailExcel.setAmount(sumAmount.getOrDefault(key, 0.0)); |
| | | serviceFunddetailExcel.setVatAmount(sumVat.getOrDefault(key, 0.0)); |
| | | serviceFunddetailExcel.setCityTaxAmount(sumCityTax.getOrDefault(key, 0.0)); |
| | | serviceFunddetailExcel.setLaborPretaxAmount(sumLaborPretax.getOrDefault(key, 0.0)); |
| | | serviceFunddetailExcel.setTaxamount(sumTax.getOrDefault(key, 0.0)); |
| | | serviceFunddetailExcel.setTaxedamount(sumTaxdAmount.getOrDefault(key, 0.0)); |
| | | for (ServiceFunddetail serviceFunddetail2 : serviceFunddetails) { |
| | | if (serviceFunddetail2.getBeneficiaryname().equals(key)) { |
| | |
| | | String filePath = RuoYiConfig.getDownloadPath() + ajaxResult.get("msg"); |
| | | |
| | | List<VExpertfeeDonor> list2 = vExpertfeeDonorMapper.selectVExpertfeeDonorList2(faxId); |
| | | // 打印模板视图不含“增值税 / 城建税 / 劳务税前”,按 fund_tax_id 从明细表汇总后回填 |
| | | fillDonorTaxAmounts(list2); |
| | | ExcelUtil<VExpertfeeDonor> util2 = new ExcelUtil<VExpertfeeDonor>(VExpertfeeDonor.class); |
| | | AjaxResult ajaxResult2 = util2.exportExcel(list2, "VExpertfeeDonor"); |
| | | |
| | | List<VExpertfeeExpert> list3 = vExpertfeeExpertMapper.selectVExpertfeeExpertListByFaxId(faxId); |
| | | fillExpertTaxAmounts(list3); |
| | | ExcelUtil<VExpertfeeExpert> util3 = new ExcelUtil<VExpertfeeExpert>(VExpertfeeExpert.class); |
| | | AjaxResult ajaxResult3 = util3.exportExcel(list3, "vExpertfeeExpert"); |
| | | |
| | |
| | | |
| | | |
| | | String name = "专家费汇总单" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".xlsx"; |
| | | // mergeExcel 内部会写文件、校验结果,并在 finally 里清理 3 个临时 sheet 文件 |
| | | mergeExcel(list1, RuoYiConfig.getDownloadPath() + name); |
| | | for (String path : list1) { |
| | | new File(RuoYiConfig.getDownloadPath() + path).delete(); |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("downloadUrl", "/profile/download/" + name); |
| | | map.put("downloadName", name); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 专家费汇总单打印(专家明细 sheet):增值税、城建税直接取视图列,劳务税前按差额计算。 |
| | | * <p> |
| | | * 2026-11-18:视图 {@code v_expertfee_expert} 已独立提供 {@code vat_amount}、{@code city_tax_amount}, |
| | | * 且 {@code TaxAmount} 恢复为<b>纯劳务个税</b>,因此: |
| | | * <ul> |
| | | * <li>增值税 / 城建税 / 劳务税后 直接用视图值,不再从明细表二次汇总;</li> |
| | | * <li>劳务税前 = 税前金额 − 增值税 − 城建税;</li> |
| | | * <li>「合计」行按各行累加。</li> |
| | | * </ul> |
| | | */ |
| | | private void fillExpertTaxAmounts(List<VExpertfeeExpert> rows) { |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return; |
| | | } |
| | | BigDecimal vatTotal = BigDecimal.ZERO; |
| | | BigDecimal cityTotal = BigDecimal.ZERO; |
| | | BigDecimal laborTotal = BigDecimal.ZERO; |
| | | for (VExpertfeeExpert row : rows) { |
| | | if (isTotalRow(row.getBeneficiaryname())) { |
| | | continue; |
| | | } |
| | | BigDecimal vat = nvl(row.getVatAmount()); |
| | | BigDecimal city = nvl(row.getCityTaxAmount()); |
| | | BigDecimal labor = VatTaxUtils.roundMoney( |
| | | nvl(row.getPretaxamount()).subtract(vat).subtract(city)); |
| | | row.setVatAmount(vat); |
| | | row.setCityTaxAmount(city); |
| | | row.setLaborPretaxAmount(labor); |
| | | vatTotal = vatTotal.add(vat); |
| | | cityTotal = cityTotal.add(city); |
| | | laborTotal = laborTotal.add(labor); |
| | | } |
| | | for (VExpertfeeExpert row : rows) { |
| | | if (isTotalRow(row.getBeneficiaryname())) { |
| | | row.setVatAmount(vatTotal); |
| | | row.setCityTaxAmount(cityTotal); |
| | | row.setLaborPretaxAmount(laborTotal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 专家费汇总单打印(捐献者 sheet):口径同 {@link #fillExpertTaxAmounts},合计行按「捐献者」行的值累加。 |
| | | */ |
| | | private void fillDonorTaxAmounts(List<VExpertfeeDonor> rows) { |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return; |
| | | } |
| | | BigDecimal vatTotal = BigDecimal.ZERO; |
| | | BigDecimal cityTotal = BigDecimal.ZERO; |
| | | BigDecimal laborTotal = BigDecimal.ZERO; |
| | | for (VExpertfeeDonor row : rows) { |
| | | if (isTotalRow(row.getDonorname())) { |
| | | continue; |
| | | } |
| | | BigDecimal vat = nvl(row.getVatAmount()); |
| | | BigDecimal city = nvl(row.getCityTaxAmount()); |
| | | BigDecimal labor = VatTaxUtils.roundMoney( |
| | | nvl(row.getPretaxamount()).subtract(vat).subtract(city)); |
| | | row.setVatAmount(vat); |
| | | row.setCityTaxAmount(city); |
| | | row.setLaborPretaxAmount(labor); |
| | | vatTotal = vatTotal.add(vat); |
| | | cityTotal = cityTotal.add(city); |
| | | laborTotal = laborTotal.add(labor); |
| | | } |
| | | for (VExpertfeeDonor row : rows) { |
| | | if (isTotalRow(row.getDonorname())) { |
| | | row.setVatAmount(vatTotal); |
| | | row.setCityTaxAmount(cityTotal); |
| | | row.setLaborPretaxAmount(laborTotal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 打印里的「合计」行 |
| | | */ |
| | | private static boolean isTotalRow(String name) { |
| | | return name != null && "合计".equals(name.trim()); |
| | | } |
| | | |
| | | private static BigDecimal nvl(BigDecimal value) { |
| | | return value == null ? BigDecimal.ZERO : value; |
| | | } |
| | | |
| | | |
| | |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("userName", "opo"); |
| | | map.put("password", "4126407a-9821-4874-be41-6568abd6dbe5"); |
| | | map.put("loginName", "OPO系统审批"); |
| | | map.put("loginName", "OPO系统"); |
| | | |
| | | JSONObject jsonObj = new JSONObject(map); |
| | | |
| | |
| | | return id; |
| | | } |
| | | |
| | | /** |
| | | * 把 3 个 sheet 的临时导出文件合并成一个「专家费汇总单」。 |
| | | * <p> |
| | | * 修复点(2026-11-12): |
| | | * <ol> |
| | | * <li>原实现用 {@code cell.getStringCellValue()} 复制单元格,遇到数字单元格会抛 |
| | | * {@code IllegalStateException: Cannot get a STRING value from a NUMERIC cell}, |
| | | * 而外层 catch 把异常吞掉 → 接口仍返回下载地址,但合并文件没生成,前端下载 404;</li> |
| | | * <li>原实现没有关闭输入/输出流,Windows 上临时文件被锁定,删不掉(残留 *_vExpertfee*.xlsx);</li> |
| | | * <li>失败时不再静默,抛业务异常让前端看到真实原因。</li> |
| | | * </ol> |
| | | */ |
| | | public void mergeExcel(List<String> files, String outputFile) { |
| | | try { |
| | | Workbook resultWorkbook = new XSSFWorkbook(); |
| | | File outFile = new File(outputFile); |
| | | try (Workbook resultWorkbook = new XSSFWorkbook()) { |
| | | // 表头与数据两种样式,避免每个单元格都新建样式(原实现每格一个样式,文件会变大) |
| | | CellStyle headerStyle = createMergeCellStyle(resultWorkbook, true); |
| | | CellStyle bodyStyle = createMergeCellStyle(resultWorkbook, false); |
| | | for (String file : files) { |
| | | InputStream is1 = new FileInputStream(RuoYiConfig.getDownloadPath() + file); |
| | | Workbook workbook1 = new XSSFWorkbook(is1); |
| | | Sheet sheet1 = workbook1.getSheetAt(0); |
| | | // 复制第一个文件的Sheet |
| | | Sheet newSheet1 = resultWorkbook.createSheet(file.substring(0, file.indexOf("."))); |
| | | for (Row row : sheet1) { |
| | | Row newRow = newSheet1.createRow(row.getRowNum()); |
| | | int columns = row.getLastCellNum(); |
| | | for (int i = 0; i < columns; i++) { |
| | | newSheet1.setColumnWidth(i, 5000); |
| | | Cell cell = row.getCell(i); |
| | | Cell newCell = newRow.createCell(cell.getColumnIndex()); |
| | | newCell.setCellValue(cell.getStringCellValue()); |
| | | // 创建单元格样式 |
| | | CellStyle style = resultWorkbook.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); // 水平居中 |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中 |
| | | if (row.getRowNum() == 0) { |
| | | // 设置第一行背景色 |
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | File srcFile = new File(RuoYiConfig.getDownloadPath() + file); |
| | | try (InputStream is1 = new FileInputStream(srcFile); |
| | | Workbook workbook1 = new XSSFWorkbook(is1)) { |
| | | Sheet sheet1 = workbook1.getSheetAt(0); |
| | | String sheetName = file.contains(".") ? file.substring(0, file.indexOf(".")) : file; |
| | | Sheet newSheet = resultWorkbook.createSheet(sheetName); |
| | | for (Row row : sheet1) { |
| | | Row newRow = newSheet.createRow(row.getRowNum()); |
| | | short columns = row.getLastCellNum(); |
| | | for (int i = 0; i < columns; i++) { |
| | | newSheet.setColumnWidth(i, 5000); |
| | | Cell newCell = newRow.createCell(i); |
| | | copyCellValue(row.getCell(i), newCell); |
| | | newCell.setCellStyle(row.getRowNum() == 0 ? headerStyle : bodyStyle); |
| | | } |
| | | |
| | | newCell.setCellStyle(style); |
| | | } |
| | | } |
| | | } |
| | | FileOutputStream out = new FileOutputStream(outputFile); |
| | | resultWorkbook.write(out); |
| | | // 先写临时文件再改名,避免下载到写了一半的文件 |
| | | File tmpFile = new File(outputFile + ".tmp"); |
| | | try (FileOutputStream out = new FileOutputStream(tmpFile)) { |
| | | resultWorkbook.write(out); |
| | | } |
| | | if (!tmpFile.renameTo(outFile) && !tmpFile.equals(outFile)) { |
| | | // rename 失败(目标被占用等)时退化为直接写目标文件 |
| | | try (FileOutputStream out = new FileOutputStream(outFile)) { |
| | | resultWorkbook.write(out); |
| | | } |
| | | tmpFile.delete(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("生成专家费汇总单失败,outputFile={}", outputFile, e); |
| | | throw new ServiceException("生成专家费汇总单失败:" + e.getMessage()); |
| | | } finally { |
| | | // 合并完成后清理临时 sheet 文件(失败时也尝试清理,避免残留) |
| | | for (String file : files) { |
| | | File tmp = new File(RuoYiConfig.getDownloadPath() + file); |
| | | if (tmp.exists() && !tmp.delete()) { |
| | | log.warn("临时导出文件未能删除:{}", tmp.getAbsolutePath()); |
| | | } |
| | | } |
| | | } |
| | | if (!outFile.exists() || outFile.length() == 0) { |
| | | throw new ServiceException("生成专家费汇总单失败:文件未生成"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 合并用的单元格样式(表头灰底、正文白底),统一居中 |
| | | */ |
| | | private static CellStyle createMergeCellStyle(Workbook workbook, boolean header) { |
| | | CellStyle style = workbook.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | if (header) { |
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | } |
| | | return style; |
| | | } |
| | | |
| | | /** |
| | | * 按单元格实际类型复制值:数字按数字、日期按日期、公式按公式,空单元格保持为空。 |
| | | * 原实现只支持字符串单元格,遇到金额(数字)就抛异常。 |
| | | */ |
| | | private static void copyCellValue(Cell source, Cell target) { |
| | | if (source == null) { |
| | | target.setBlank(); |
| | | return; |
| | | } |
| | | switch (source.getCellType()) { |
| | | case STRING: |
| | | target.setCellValue(source.getStringCellValue()); |
| | | break; |
| | | case NUMERIC: |
| | | if (DateUtil.isCellDateFormatted(source)) { |
| | | target.setCellValue(source.getDateCellValue()); |
| | | } else { |
| | | target.setCellValue(source.getNumericCellValue()); |
| | | } |
| | | break; |
| | | case BOOLEAN: |
| | | target.setCellValue(source.getBooleanCellValue()); |
| | | break; |
| | | case FORMULA: |
| | | target.setCellFormula(source.getCellFormula()); |
| | | break; |
| | | default: |
| | | target.setBlank(); |
| | | break; |
| | | } |
| | | } |
| | | |