From edbfa6b1a3a45e79cb17b06f3798535c3b1ba395 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期三, 18 十一月 2026 09:12:39 +0800
Subject: [PATCH] 修改了增值税城建税
---
ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java | 336 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 304 insertions(+), 32 deletions(-)
diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
index 17d1ed3..b488cf0 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
@@ -853,7 +853,9 @@
}
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)) {
@@ -896,6 +898,23 @@
allMap.put("formson_0832", list);
allMap.put("annexfilesList", annexfilesList);
return allMap;
+ }
+
+ /**
+ * 鏄庣粏涓婁紶鍗忓弸鐨勨�滅◣棰濃�� = 鍔冲姟涓◣ + 澧炲�肩◣ + 鍩庡缓绋庯紙鎵g◣鍚堣鍙e緞锛夈��
+ * <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);
}
@@ -1583,6 +1602,28 @@
// 淇濆瓨璇︽儏鏁版嵁
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());
@@ -1683,10 +1724,23 @@
//閫氳繃鍙楃泭浜哄悕绉帮紝灏嗙◣鍓嶃�佺◣鍚庣殑鍊肩浉鍔�
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)));
+ // 鏂板鍙e緞锛氬鍊肩◣銆佸煄寤虹◣銆佸姵鍔$◣鍓嶃�佸姵鍔′釜绋庢寜鍙楃泭浜哄悎璁�
+ 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)) {
@@ -1782,10 +1836,13 @@
String filePath = RuoYiConfig.getDownloadPath() + ajaxResult.get("msg");
List<VExpertfeeDonor> list2 = vExpertfeeDonorMapper.selectVExpertfeeDonorList2(faxId);
+ // 鎵撳嵃妯℃澘瑙嗗浘涓嶅惈鈥滃鍊肩◣ / 鍩庡缓绋� / 鍔冲姟绋庡墠鈥濓紝鎸� fund_tax_id 浠庢槑缁嗚〃姹囨�诲悗鍥炲~
+ fillDonorTaxAmounts(list2, faxId);
ExcelUtil<VExpertfeeDonor> util2 = new ExcelUtil<VExpertfeeDonor>(VExpertfeeDonor.class);
AjaxResult ajaxResult2 = util2.exportExcel(list2, "VExpertfeeDonor");
List<VExpertfeeExpert> list3 = vExpertfeeExpertMapper.selectVExpertfeeExpertListByFaxId(faxId);
+ fillExpertTaxAmounts(list3, faxId);
ExcelUtil<VExpertfeeExpert> util3 = new ExcelUtil<VExpertfeeExpert>(VExpertfeeExpert.class);
AjaxResult ajaxResult3 = util3.exportExcel(list3, "vExpertfeeExpert");
@@ -1796,14 +1853,155 @@
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>
+ * 鍙e緞璇存槑锛�
+ * <ul>
+ * <li>瑙嗗浘 {@code v_expertfee_expert} 鐨� {@code TaxAmount} 宸叉敼涓�
+ * <b>澧炲�肩◣ + 鍩庡缓绋� + 鍔冲姟涓◣</b>锛�2026-11-12 涓氬姟鏂逛慨鏀癸級锛岃�屾墦鍗拌鍒嗗埆灞曠ず锛�
+ * 鍥犳 {@code 鍔冲姟涓◣ = TaxAmount 鈭� 澧炲�肩◣ 鈭� 鍩庡缓绋巬锛�</li>
+ * <li>澧炲�肩◣/鍩庡缓绋�/鍔冲姟绋庡墠 瑙嗗浘鏈崟鐙彁渚涳紝鎸� <b>涓庤鍥剧浉鍚岀殑鍒嗙粍</b>
+ * 锛堝彈鐩婁汉 + 璇佷欢鍙� + 鍗″彿 + 寮�鎴疯 + 鍗曚綅锛変粠 {@code service_funddetail} 姹囨�诲悗鍖归厤鍥炲~锛�</li>
+ * <li>銆屽悎璁°�嶈鎸夊悇琛岀殑鍊肩疮鍔狅紙涓嶄緷璧栬鍥� UNION 鐨勫悎璁″垪锛夈��</li>
+ * </ul>
+ */
+ private void fillExpertTaxAmounts(List<VExpertfeeExpert> rows, Integer fundTaxId) {
+ if (CollectionUtils.isEmpty(rows)) {
+ return;
+ }
+ Map<String, FundTaxAmountSum> sumMap = toSumMap(serviceFundMapper.selectTaxSumByBeneficiary(fundTaxId.longValue()));
+ BigDecimal vatTotal = BigDecimal.ZERO;
+ BigDecimal cityTotal = BigDecimal.ZERO;
+ BigDecimal laborTotal = BigDecimal.ZERO;
+ BigDecimal laborTaxTotal = BigDecimal.ZERO;
+ for (VExpertfeeExpert row : rows) {
+ if (isTotalRow(row.getBeneficiaryname())) {
+ continue;
+ }
+ FundTaxAmountSum s = sumMap.get(expertGroupKey(row));
+ BigDecimal vat = s == null ? BigDecimal.ZERO : nvl(s.getVatAmount());
+ BigDecimal city = s == null ? BigDecimal.ZERO : nvl(s.getCityTaxAmount());
+ BigDecimal labor = s == null ? BigDecimal.ZERO : nvl(s.getLaborPretaxAmount());
+ // 瑙嗗浘鐨勬墸绋庨噾棰濆惈澧炲�肩◣銆佸煄寤虹◣锛岃繖閲屾媶鍥炲姵鍔′釜绋�
+ BigDecimal laborTax = nvl(row.getTaxamount()).subtract(vat).subtract(city);
+ row.setVatAmount(vat);
+ row.setCityTaxAmount(city);
+ row.setLaborPretaxAmount(labor);
+ row.setTaxamount(laborTax);
+ vatTotal = vatTotal.add(vat);
+ cityTotal = cityTotal.add(city);
+ laborTotal = laborTotal.add(labor);
+ laborTaxTotal = laborTaxTotal.add(laborTax);
+ }
+ for (VExpertfeeExpert row : rows) {
+ if (isTotalRow(row.getBeneficiaryname())) {
+ row.setVatAmount(vatTotal);
+ row.setCityTaxAmount(cityTotal);
+ row.setLaborPretaxAmount(laborTotal);
+ row.setTaxamount(laborTaxTotal);
+ }
+ }
+ }
+
+ /**
+ * 涓撳璐规眹鎬诲崟鎵撳嵃锛堟崘鐚�� sheet锛夛細鍚� {@link #fillExpertTaxAmounts}锛屽垎缁勪负銆屾崘鐚�� + 妗堜緥ID銆嶃��
+ */
+ private void fillDonorTaxAmounts(List<VExpertfeeDonor> rows, Integer fundTaxId) {
+ if (CollectionUtils.isEmpty(rows)) {
+ return;
+ }
+ Map<String, FundTaxAmountSum> sumMap = toSumMap(serviceFundMapper.selectTaxSumByDonor(fundTaxId.longValue()));
+ BigDecimal vatTotal = BigDecimal.ZERO;
+ BigDecimal cityTotal = BigDecimal.ZERO;
+ BigDecimal laborTotal = BigDecimal.ZERO;
+ BigDecimal laborTaxTotal = BigDecimal.ZERO;
+ for (VExpertfeeDonor row : rows) {
+ if (isTotalRow(row.getDonorname())) {
+ continue;
+ }
+ FundTaxAmountSum s = sumMap.get(donorGroupKey(row.getDonorname(), row.getInfoid()));
+ BigDecimal vat = s == null ? BigDecimal.ZERO : nvl(s.getVatAmount());
+ BigDecimal city = s == null ? BigDecimal.ZERO : nvl(s.getCityTaxAmount());
+ BigDecimal labor = s == null ? BigDecimal.ZERO : nvl(s.getLaborPretaxAmount());
+ BigDecimal laborTax = nvl(row.getTaxamount()).subtract(vat).subtract(city);
+ row.setVatAmount(vat);
+ row.setCityTaxAmount(city);
+ row.setLaborPretaxAmount(labor);
+ row.setTaxamount(laborTax);
+ vatTotal = vatTotal.add(vat);
+ cityTotal = cityTotal.add(city);
+ laborTotal = laborTotal.add(labor);
+ laborTaxTotal = laborTaxTotal.add(laborTax);
+ }
+ for (VExpertfeeDonor row : rows) {
+ if (isTotalRow(row.getDonorname())) {
+ row.setVatAmount(vatTotal);
+ row.setCityTaxAmount(cityTotal);
+ row.setLaborPretaxAmount(laborTotal);
+ row.setTaxamount(laborTaxTotal);
+ }
+ }
+ }
+
+ private static Map<String, FundTaxAmountSum> toSumMap(List<FundTaxAmountSum> sums) {
+ Map<String, FundTaxAmountSum> map = new HashMap<>();
+ if (!CollectionUtils.isEmpty(sums)) {
+ for (FundTaxAmountSum s : sums) {
+ map.put(s.getGroupKey(), s);
+ }
+ }
+ return map;
+ }
+
+ /**
+ * 涓撳鏄庣粏鍒嗙粍閿紝蹇呴』涓庤鍥� {@code v_expertfee_expert} 鐨� GROUP BY 瀹屽叏涓�鑷达細
+ * BeneficiaryName + IDCardNo + BankCardNo + DepositBank + UnitName銆�
+ */
+ private static String expertGroupKey(VExpertfeeExpert row) {
+ return joinKey(row.getBeneficiaryname(), row.getIdcardno(), row.getBankcardno(),
+ row.getDepositbank(), row.getUnitname());
+ }
+
+ /**
+ * 鎹愮尞鑰呭垎缁勯敭锛屼笌瑙嗗浘 {@code v_expertfee_donor} 鐨� GROUP BY 涓�鑷达細DonorName + InfoID銆�
+ */
+ private static String donorGroupKey(String donorname, Long infoid) {
+ return joinKey(donorname, infoid == null ? "" : String.valueOf(infoid));
+ }
+
+ /**
+ * 鐢� "|" 鎷兼帴鍒嗙粍閿紱null 缁熶竴鎸夌┖涓插鐞嗭紙涓� SQL 鐨� IFNULL(x,'') 瀵归綈锛�
+ */
+ private static String joinKey(Object... parts) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < parts.length; i++) {
+ if (i > 0) {
+ sb.append('|');
+ }
+ Object p = parts[i];
+ sb.append(p == null ? "" : String.valueOf(p).trim());
+ }
+ return sb.toString();
+ }
+
+ /**
+ * 鎵撳嵃閲岀殑銆屽悎璁°�嶈
+ */
+ private static boolean isTotalRow(String name) {
+ return name != null && "鍚堣".equals(name.trim());
+ }
+
+ private static BigDecimal nvl(BigDecimal value) {
+ return value == null ? BigDecimal.ZERO : value;
}
@@ -1928,41 +2126,115 @@
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("鐢熸垚涓撳璐规眹鎬诲崟澶辫触锛宱utputFile={}", 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;
}
}
--
Gitblit v1.9.3