Commit ef40c3fe authored by fangxinjiang's avatar fangxinjiang

Merge remote-tracking branch 'origin/MVP1.7.21' into MVP1.7.21

parents 54b2ac5e d207cdae
...@@ -38,4 +38,6 @@ public class EkpBankResultVo implements Serializable { ...@@ -38,4 +38,6 @@ public class EkpBankResultVo implements Serializable {
private String fdAttaSrc; private String fdAttaSrc;
// 非扣税使用的金额,授权失败记录金额 // 非扣税使用的金额,授权失败记录金额
private String fdMoney; private String fdMoney;
// 汇款用途,如果是非扣税,就是转账,如果是报销,就是报销
private String fdPayType;
} }
...@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*; ...@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/** /**
* 聚富通代发工资相关 * 聚富通代发工资相关
...@@ -163,10 +165,18 @@ public class IcbcTransactionFlowIssueController { ...@@ -163,10 +165,18 @@ public class IcbcTransactionFlowIssueController {
// 工资 // 工资
icbcTransactionFlowIssueService.getPdfFile(); icbcTransactionFlowIssueService.getPdfFile();
// 非扣税 // 非扣税
icbcTransactionFlowIssueService.getPdfFileByNoTax(null); icbcTransactionFlowIssueService.getPdfFileByNoTax(addDay(-2));
icbcTransactionFlowIssueService.getPdfFileByNoTax(addDay(-1));
return R.ok(); return R.ok();
} }
private String addDay(int day) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day); // 获取前一天日期
return sdf.format(cal.getTime());
}
@Operation(summary = "定时任务获取回单文件", description = "定时任务获取回单文件") @Operation(summary = "定时任务获取回单文件", description = "定时任务获取回单文件")
@PostMapping("/getTestPdfFile") @PostMapping("/getTestPdfFile")
public R getPdfFileTest() throws IOException { public R getPdfFileTest() throws IOException {
......
...@@ -78,7 +78,7 @@ public interface EkpBankGrantDetailMapper extends BaseMapper<EkpBankGrantDetail> ...@@ -78,7 +78,7 @@ public interface EkpBankGrantDetailMapper extends BaseMapper<EkpBankGrantDetail>
List<EkpBankCodeConfiglVo> getEkpBankCodeConfiglVo(); List<EkpBankCodeConfiglVo> getEkpBankCodeConfiglVo();
// 更新工资支出的 银企出纳 // 更新工资支出的 银企出纳
void updateGongZiZhiChuTable(@Param("fdId") String fdId, @Param("chuNaName") String chuNaName); void updateGongZiZhiChuTable(@Param("tableName") String tableName, @Param("fdId") String fdId, @Param("chuNaName") String chuNaName);
// 更新工资支出Main表的 银企出纳 // 更新工资支出Main表的 银企出纳
void updateGongZiZhiChuMain(@Param("fdId") String fdId, @Param("chuNaName") String chuNaName); void updateGongZiZhiChuMain(@Param("fdId") String fdId, @Param("chuNaName") String chuNaName);
......
...@@ -40,4 +40,10 @@ public interface EkpBankPayTaskMapper extends BaseMapper<EkpBankPayTask> { ...@@ -40,4 +40,10 @@ public interface EkpBankPayTaskMapper extends BaseMapper<EkpBankPayTask> {
// 获取发放中的明细表,查询结果 // 获取发放中的明细表,查询结果
List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(@Param("typeName") String typeName); List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(@Param("typeName") String typeName);
// 获取发放中的主表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultMainByOther();
// 获取发放中的明细表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultDetailByOther();
} }
...@@ -77,7 +77,7 @@ public interface EkpBankGrantDetailService extends IService<EkpBankGrantDetail> ...@@ -77,7 +77,7 @@ public interface EkpBankGrantDetailService extends IService<EkpBankGrantDetail>
* @Date: 2024/12/26 11:41 * @Date: 2024/12/26 11:41
* @return: void * @return: void
**/ **/
void updateGongZiZhiChuTable(String fdId, String chuNaName); void updateGongZiZhiChuTable(String tableName, String fdId, String chuNaName);
/** /**
* @param fdId 工资支出 表id * @param fdId 工资支出 表id
* @param chuNaName 银企出纳名字 * @param chuNaName 银企出纳名字
......
...@@ -47,4 +47,10 @@ public interface EkpBankPayTaskService extends IService<EkpBankPayTask> { ...@@ -47,4 +47,10 @@ public interface EkpBankPayTaskService extends IService<EkpBankPayTask> {
**/ **/
List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(String typeName); List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(String typeName);
// 获取发放中的主表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultMainByOther();
// 获取发放中的明细表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultDetailByOther();
} }
...@@ -129,8 +129,8 @@ public class EkpBankGrantDetailServiceImpl extends ServiceImpl<EkpBankGrantDetai ...@@ -129,8 +129,8 @@ public class EkpBankGrantDetailServiceImpl extends ServiceImpl<EkpBankGrantDetai
} }
@Override @Override
public void updateGongZiZhiChuTable(String fdId, String chuNaName) { public void updateGongZiZhiChuTable(String tableName, String fdId, String chuNaName) {
baseMapper.updateGongZiZhiChuTable(fdId, chuNaName); baseMapper.updateGongZiZhiChuTable(tableName,fdId, chuNaName);
} }
@Override @Override
......
...@@ -57,4 +57,25 @@ public class EkpBankPayTaskServiceImpl extends ServiceImpl<EkpBankPayTaskMapper, ...@@ -57,4 +57,25 @@ public class EkpBankPayTaskServiceImpl extends ServiceImpl<EkpBankPayTaskMapper,
public List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(String typeName) { public List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(String typeName) {
return baseMapper.getEkpBankMainByNeedResultDetail(typeName); return baseMapper.getEkpBankMainByNeedResultDetail(typeName);
} }
/**
* @Description: 获取发放中的主表,查询结果
* @Author: hgw
* @Date: 2024/11/25 10:26
* @return: java.util.List<com.yifu.cloud.plus.v1.ekp.entity.EkpBankPayTask>
**/
@Override
public List<EkpBankResultVo> getEkpBankMainByNeedResultMainByOther() {
return baseMapper.getEkpBankMainByNeedResultMainByOther();
}
/**
* @Description: 获取发放中的明细表,查询结果
* @Author: hgw
* @Date: 2024/11/25 10:39
* @return: java.util.List<com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo>
**/
@Override
public List<EkpBankResultVo> getEkpBankMainByNeedResultDetailByOther() {
return baseMapper.getEkpBankMainByNeedResultDetailByOther();
}
} }
...@@ -364,6 +364,7 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn ...@@ -364,6 +364,7 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn
String fSeqNo; String fSeqNo;
MybankEnterpriseTradeQhisdResponseV1 response; MybankEnterpriseTradeQhisdResponseV1 response;
// int i=1;
for(Map<String,String> accountInfo: accountList) { for(Map<String,String> accountInfo: accountList) {
bizContent = new MybankEnterpriseTradeQhisdRequestV1.MybankEnterpriseTradeQhisdRequestBizV1(); bizContent = new MybankEnterpriseTradeQhisdRequestV1.MybankEnterpriseTradeQhisdRequestBizV1();
...@@ -384,6 +385,8 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn ...@@ -384,6 +385,8 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn
request.setServiceUrl(icbcConfigProperties.getServerUrl()); request.setServiceUrl(icbcConfigProperties.getServerUrl());
request.setBizContent(bizContent); request.setBizContent(bizContent);
response = client.execute(request); response = client.execute(request);
// 如果工行人要传参,把这个打出来,复制给他
//System.out.println("传参" + (i++) + ":" + JSON.toJSONString(request));
if (response.isSuccess()) { if (response.isSuccess()) {
getInfoListByNoTax(request, mainMap, returnMap, detailMap, client, bizContent); getInfoListByNoTax(request, mainMap, returnMap, detailMap, client, bizContent);
} }
...@@ -422,6 +425,7 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn ...@@ -422,6 +425,7 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn
if (no.contains("-")) { if (no.contains("-")) {
no = no.split("-")[0]; no = no.split("-")[0];
} }
// no 的值将是 "HQP923041354291" // no 的值将是 "HQP923041354291"
infoOldVo = mainMap.get(no); infoOldVo = mainMap.get(no);
if (infoOldVo != null) { if (infoOldVo != null) {
......
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
<!-- 更新工资支出 的 银企出纳 --> <!-- 更新工资支出 的 银企出纳 -->
<update id="updateGongZiZhiChuTable" > <update id="updateGongZiZhiChuTable" >
UPDATE ekp_fd9be224c214ad0992aa SET fd_bank_pay_chu_na = #{chuNaName} WHERE fd_id = #{fdId}; UPDATE ${tableName} SET fd_bank_pay_chu_na = #{chuNaName} WHERE fd_id = #{fdId};
</update> </update>
<!-- 更新工资支出Main表的 银企出纳 --> <!-- 更新工资支出Main表的 银企出纳 -->
<update id="updateGongZiZhiChuMain" > <update id="updateGongZiZhiChuMain" >
......
...@@ -106,6 +106,25 @@ ...@@ -106,6 +106,25 @@
where a.fd_grant_status = '已发放' and d.fd_grant_status = '发放失败' and d.fd_handle_status = '发放中' and a.fd_pay_type = #{typeName} where a.fd_grant_status = '已发放' and d.fd_grant_status = '发放失败' and d.fd_handle_status = '发放中' and a.fd_pay_type = #{typeName}
</select> </select>
<!-- 获取发放中的主表,查询结果 -->
<select id="getEkpBankMainByNeedResultMainByOther" resultType="com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo">
select a.fd_id fdId,a.fd_wx_no fdWxNo
,count(d.fd_id) num,a.fd_bank_name fdBankName,a.fd_bank_no fdBankNo,a.fd_bank_account fdBankAccount
,a.fd_grant_num fdGrantNum,a.fd_atta_src fdAttaSrc,a.fd_pay_type fdPayType
from ekp_bank_pay_task a left join ekp_bank_grant_detail d on a.fd_id = d.fd_parent_id
where a.fd_grant_status = '发放中' and a.fd_pay_type in ("非扣税","报销")
GROUP BY a.fd_id
</select>
<!-- 获取发放中的明细表,查询结果 -->
<select id="getEkpBankMainByNeedResultDetailByOther" resultType="com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo">
select d.fd_id fdId,d.fd_wx_no fdWxNo,d.fd_parent_id fdParentId,d.fd_fail_num fdFailNum,d.fd_salary_id fdSalaryId
,'1' num,a.fd_bank_name fdBankName,a.fd_bank_no fdBankNo,a.fd_bank_account fdBankAccount,d.fd_payee_name fdPayeeName
,d.fd_grant_num fdGrantNum,d.fd_recipient_bank fdRecipientBank,d.fd_atta_src fdAttaSrc,d.fd_money fdMoney,a.fd_pay_type fdPayType
from ekp_bank_grant_detail d left join ekp_bank_pay_task a on a.fd_id = d.fd_parent_id
where a.fd_grant_status = '已发放' and d.fd_grant_status = '发放失败' and d.fd_handle_status = '发放中' and a.fd_pay_type in ("非扣税","报销")
</select>
</mapper> </mapper>
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
<!--查询所有需要查询的单号-主表--> <!--查询所有需要查询的单号-主表-->
<select id="getNoToQueryByMain" resultType="com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseIdNameNoVo"> <select id="getNoToQueryByMain" resultType="com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseIdNameNoVo">
SELECT a.fd_wx_no id,a.fd_atta_src no FROM ekp_bank_pay_task a SELECT a.fd_wx_no id,a.fd_atta_src no FROM ekp_bank_pay_task a
where a.fd_pay_type = '非扣税' and a.fd_atta_src is not null where a.fd_pay_type in ('非扣税','报销') and a.fd_atta_src is not null
and a.fd_create_time >= DATE_SUB(curdate(), INTERVAL 3 MONTH) and a.fd_create_time >= DATE_SUB(curdate(), INTERVAL 3 MONTH)
and not EXISTS ( and not EXISTS (
select 1 from ekp_bank_atta b where b.fd_link_type='4' and a.fd_wx_no=b.fd_link_id select 1 from ekp_bank_atta b where b.fd_link_type='4' and a.fd_wx_no=b.fd_link_id
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
<select id="getNoToQueryByDetail" resultType="com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseIdNameNoVo"> <select id="getNoToQueryByDetail" resultType="com.yifu.cloud.plus.v1.yifu.common.core.vo.BaseIdNameNoVo">
SELECT a.fd_wx_no id,a.fd_atta_src no FROM ekp_bank_grant_detail a SELECT a.fd_wx_no id,a.fd_atta_src no FROM ekp_bank_grant_detail a
left join ekp_bank_pay_task m on m.fd_id=a.fd_parent_id left join ekp_bank_pay_task m on m.fd_id=a.fd_parent_id
where m.fd_pay_type = '非扣税' and a.fd_atta_src is not null where m.fd_pay_type in ('非扣税','报销') and a.fd_atta_src is not null
and a.fd_create_time >= DATE_SUB(curdate(), INTERVAL 6 MONTH) and a.fd_create_time >= DATE_SUB(curdate(), INTERVAL 6 MONTH)
and not EXISTS ( and not EXISTS (
select 1 from ekp_bank_atta b where b.fd_link_type='4' and a.fd_wx_no=b.fd_link_id select 1 from ekp_bank_atta b where b.fd_link_type='4' and a.fd_wx_no=b.fd_link_id
......
...@@ -300,8 +300,7 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala ...@@ -300,8 +300,7 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala
errorMessageList.add(new ErrorMessage(-1, "超过500条,不存储数据,请处理导入表格")); errorMessageList.add(new ErrorMessage(-1, "超过500条,不存储数据,请处理导入表格"));
cachedDataList.clear(); cachedDataList.clear();
// 中断读取 // 中断读取
context.interrupt(); throw new RuntimeException("超过500条,请减少数据条数!");
return;
} }
ReadRowHolder readRowHolder = context.readRowHolder(); ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex(); Integer rowIndex = readRowHolder.getRowIndex();
...@@ -395,8 +394,13 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala ...@@ -395,8 +394,13 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala
}).sheet().doRead(); }).sheet().doRead();
} catch (Exception e) { } catch (Exception e) {
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e); // 判断 为RuntimeException
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR); if (e instanceof RuntimeException) {
return R.failed(e.getMessage());
}
String errorInfo = "数据导入解析失败,请将单元格设为文本!" + e.getMessage();
log.error(errorInfo, e);
return R.failed(errorInfo);
} }
boolean isTrue = true; boolean isTrue = true;
for (ErrorMessage message : errorMessageList) { for (ErrorMessage message : errorMessageList) {
...@@ -482,6 +486,10 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala ...@@ -482,6 +486,10 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala
continue; continue;
} }
if (judgeTaxMonth(excel.getTaxMonth())) {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "计税月份格式不正确!", excel));
continue;
}
insert = new TSalaryZero(); insert = new TSalaryZero();
BeanUtil.copyProperties(excel, insert); BeanUtil.copyProperties(excel, insert);
insert.setSettleMonth(settleMonth); insert.setSettleMonth(settleMonth);
...@@ -512,6 +520,21 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala ...@@ -512,6 +520,21 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala
} }
} }
// 返回false则对
private boolean judgeTaxMonth(String taxMonth) {
if (Common.isEmpty(taxMonth)) {
return true;
}
if (taxMonth.length() > CommonConstants.dingleDigitIntArray[6]) {
taxMonth = taxMonth.substring(0, 6);
} else if (taxMonth.length() < CommonConstants.dingleDigitIntArray[6]) {
return true;
}
if (DateUtil.compareYearMonth(taxMonth, DateUtil.addMonth(0))) {
return true;
}
return false;
}
// 批量新增0申报 // 批量新增0申报
public void saveBatchWithTableName(List<TSalaryZero> insertList, String tableName) { public void saveBatchWithTableName(List<TSalaryZero> insertList, String tableName) {
if (insertList == null || insertList.isEmpty()) { if (insertList == null || insertList.isEmpty()) {
......
...@@ -190,6 +190,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -190,6 +190,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
} }
} finally { } finally {
atomicPushFriend.decrementAndGet(); atomicPushFriend.decrementAndGet();
cleanSpireTempFiles();
} }
return R.ok(); return R.ok();
} else { } else {
...@@ -198,6 +199,41 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -198,6 +199,41 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
} }
} }
// 2026-03-26 hgw
// 不可以并发,会使花名册转图片的字体不正确
// 后续优化,考虑升级(spire.xls)的版本
// 此方法是:删除临时文件
public void cleanSpireTempFiles() {
try {
String tempDirPath = System.getProperty("java.io.tmpdir");
File tempDir = new File(tempDirPath);
if (tempDir.exists() && tempDir.isDirectory()) {
File[] spireTempFiles = tempDir.listFiles((dir, name) ->
name.startsWith("+~JF") && name.endsWith(".tmp")
);
if (spireTempFiles != null && spireTempFiles.length > 0) {
int count = 0;
long totalSize = 0;
for (File file : spireTempFiles) {
if (file.isFile() && file.canWrite()) {
long fileSize = file.length();
if (file.delete()) {
count++;
totalSize += fileSize;
}
}
}
log.info("清理 Spire.XLS 临时文件完成:删除 {} 个文件,释放 {} MB 空间",
count, totalSize / 1024 / 1024);
}
}
} catch (Exception e) {
log.error("清理 Spire.XLS 临时文件失败", e);
}
}
// 获取特殊的户名称,当前给 徽州区 使用,徽州区需要走不同的分支 // 获取特殊的户名称,当前给 徽州区 使用,徽州区需要走不同的分支
private Map<String, Integer> getSpecialHuNameMap() { private Map<String, Integer> getSpecialHuNameMap() {
Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
...@@ -332,7 +368,8 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -332,7 +368,8 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
if (rosterAutoFlagYgs && !huaListVo.isEmpty()) { if (rosterAutoFlagYgs && !huaListVo.isEmpty()) {
urlR = doExportRosterNew(vo, type, huaListVo, zhangMap, templateSrcMap); urlR = doExportRosterNew(vo, type, huaListVo, zhangMap, templateSrcMap);
// 新增:强制垃圾回收以清理 Spire.XLS 的临时字体文件
//System.gc();
// 房工接口,获取 企业职工基本医疗保险参保登记表 url // 房工接口,获取 企业职工基本医疗保险参保登记表 url
//urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode(), listVo) //urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode(), listVo)
if (urlR != null && urlR.getCode() == 200 && Common.isNotNull(urlR.getData())) { if (urlR != null && urlR.getCode() == 200 && Common.isNotNull(urlR.getData())) {
...@@ -1292,7 +1329,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1292,7 +1329,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
String filePath = projectRoot + CommonConstants.DOUBLE_LINE + fileName; String filePath = projectRoot + CommonConstants.DOUBLE_LINE + fileName;
//获取要导出的列表 //获取要导出的列表
List<TDispatchSocialPersionExportVo> list = new ArrayList<>(); List<TDispatchSocialPersionExportVo> list = new ArrayList<>();
ExcelWriter excelWriter = null; //ExcelWriter excelWriter = null;
File createFile = null; File createFile = null;
try { try {
...@@ -1346,13 +1383,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1346,13 +1383,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
throw new RuntimeException("填充Excel模板失败", e); throw new RuntimeException("填充Excel模板失败", e);
} }
File inputFile = null;
FileInputStream inputStream = null; FileInputStream inputStream = null;
InputStream inStream = null; InputStream inStream = null;
try { try {
//读取文件 生成电子章 //读取文件 生成电子章
inputFile = new File(filePath); createFile = new File(filePath);
inputStream = new FileInputStream(inputFile); inputStream = new FileInputStream(createFile);
if (Common.isEmpty(url)) { if (Common.isEmpty(url)) {
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取URL异常"); return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取URL异常");
...@@ -1376,12 +1412,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1376,12 +1412,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
return R.failed("税友附件生成异常:" + e.getMessage()); return R.failed("税友附件生成异常:" + e.getMessage());
} finally { } finally {
// 清理文件 // 清理文件
finallyClose(inputFile, null, null, inputStream, null, inStream, null); finallyClose(null, null, null, inputStream, null, inStream, null);
} }
} catch (Exception e) { } catch (Exception e) {
if (excelWriter != null) { /*if (excelWriter != null) {
excelWriter.finish(); excelWriter.finish();
} }*/
log.error("税友附件生成异常", e); log.error("税友附件生成异常", e);
return R.failed("税友附件生成异常:" + e.getMessage()); return R.failed("税友附件生成异常:" + e.getMessage());
} finally { } finally {
......
...@@ -53,26 +53,28 @@ public class ExcelToImage { ...@@ -53,26 +53,28 @@ public class ExcelToImage {
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError); return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError);
} }
String projectRoot = System.getProperty(CommonConstants.USER_DIR); String projectRoot = System.getProperty(CommonConstants.USER_DIR);
File tempFile = null;
File compressedTempFile = null;
//加载Excel工作表 //加载Excel工作表
Workbook wb = new Workbook(); Workbook wb = new Workbook();
wb.loadFromHtml(inputStream);
//获取工作表
Worksheet sheet = wb.getWorksheets().get(0);
//调用方法将Excel工作表保存为图片
sheet.saveToImage(projectRoot+toImag);
File file = null;
try { try {
wb.loadFromHtml(inputStream);
//获取工作表
Worksheet sheet = wb.getWorksheets().get(0);
String toImagePath = projectRoot + toImag;
sheet.saveToImage(toImagePath);
tempFile = new File(toImagePath);
// 上传税友文件服务器,返回文件路径 // 上传税友文件服务器,返回文件路径
file = new File(projectRoot+toImag); if (tempFile.exists()){
if (file.exists()){
// file 压缩到1M以内 // file 压缩到1M以内
backLog.setLogInfo("压缩大小前"); backLog.setLogInfo("压缩大小前");
// 压缩并加章 // 压缩并加章
file = compressImage(file, projectRoot, zhangStream); tempFile = compressImage(tempFile, projectRoot, zhangStream, compressedTempFile);
backLog.setLogInfo("压缩大小后"); backLog.setLogInfo("压缩大小后");
String key = System.currentTimeMillis() + file.getName(); String key = System.currentTimeMillis() + tempFile.getName();
byte[] fileContent = Files.readAllBytes(file.toPath()); byte[] fileContent = Files.readAllBytes(tempFile.toPath());
String base64String = Base64.getEncoder().encodeToString(fileContent); String base64String = Base64.getEncoder().encodeToString(fileContent);
backLog.setLogInfo("转化为base64String"); backLog.setLogInfo("转化为base64String");
String url = socialFriendConfig.uploadPng(restTemplate, key, base64String, backLog); String url = socialFriendConfig.uploadPng(restTemplate, key, base64String, backLog);
...@@ -80,15 +82,21 @@ public class ExcelToImage { ...@@ -80,15 +82,21 @@ public class ExcelToImage {
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagOSSError); return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagOSSError);
} }
// 上传花名册到阿里云 // 上传花名册到阿里云
this.uploadHuaMingCeToOss(ossUtil, tSocialFriendBackLogService, socialId, file.getName(), file); this.uploadHuaMingCeToOss(ossUtil, tSocialFriendBackLogService, socialId, tempFile.getName(), tempFile);
return R.ok(url); return R.ok(url);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagConvertError+e.getMessage()); return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagConvertError+e.getMessage());
} finally { } finally {
if (file.exists()){ if (wb != null) {
file.delete(); wb.dispose(); // 重要:释放资源并删除临时文件
}
if (tempFile != null && tempFile.exists()){
tempFile.delete();
}
if (compressedTempFile != null && compressedTempFile.exists()){
compressedTempFile.delete();
} }
if (null != inputStream){ if (null != inputStream){
try { try {
...@@ -133,33 +141,26 @@ public class ExcelToImage { ...@@ -133,33 +141,26 @@ public class ExcelToImage {
} }
//压缩文件到指定大小 //压缩文件到指定大小
private File compressImage(File originalFile, String projectRoot, InputStream zhangStream) throws IOException { private File compressImage(File originalFile, String projectRoot, InputStream zhangStream, File compressedTempFile) throws IOException {
BufferedImage image = ImageIO.read(originalFile); BufferedImage image = ImageIO.read(originalFile);
// 新: 加盖公章 // 新: 加盖公章
BufferedImage sealedImage = addSealToImage(image, zhangStream); BufferedImage sealedImage = addSealToImage(image, zhangStream);
ImageIO.write(sealedImage, "png", originalFile); ImageIO.write(sealedImage, "png", originalFile);
int quality = 100; // 从100%开始 int quality = 100; // 从100%开始
File compressedFile = new File(projectRoot, TO_IMAGE_TEMP);
int maxSize = 1024 * 1024; int maxSize = 1024 * 1024;
try { try {
while (originalFile.length() > maxSize && quality > 10) { while (originalFile.length() > maxSize && quality > 10) {
quality -= 5; quality -= 5;
ImageIO.write(sealedImage, "png", compressedFile); ImageIO.write(sealedImage, "png", compressedTempFile);
if (compressedFile.length() < maxSize) { if (compressedTempFile.length() < maxSize) {
originalFile.delete(); originalFile.delete();
compressedFile.renameTo(originalFile); compressedTempFile.renameTo(originalFile);
break; break;
} }
compressedFile.delete(); compressedTempFile.delete();
} }
} catch (Exception e) { } catch (Exception e) {
if (compressedFile != null && compressedFile.exists()) { throw e;
compressedFile.delete();
}
} finally {
if (compressedFile != null && compressedFile.exists()) {
compressedFile.delete();
}
} }
return originalFile; return originalFile;
} }
......
...@@ -142,7 +142,6 @@ public class WordToImageUtil { ...@@ -142,7 +142,6 @@ public class WordToImageUtil {
if (imgFile != null) { if (imgFile != null) {
imgFile.delete(); imgFile.delete();
} }
} }
return "---"; return "---";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment