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 {
private String fdAttaSrc;
// 非扣税使用的金额,授权失败记录金额
private String fdMoney;
// 汇款用途,如果是非扣税,就是转账,如果是报销,就是报销
private String fdPayType;
}
......@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* 聚富通代发工资相关
......@@ -163,10 +165,18 @@ public class IcbcTransactionFlowIssueController {
// 工资
icbcTransactionFlowIssueService.getPdfFile();
// 非扣税
icbcTransactionFlowIssueService.getPdfFileByNoTax(null);
icbcTransactionFlowIssueService.getPdfFileByNoTax(addDay(-2));
icbcTransactionFlowIssueService.getPdfFileByNoTax(addDay(-1));
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 = "定时任务获取回单文件")
@PostMapping("/getTestPdfFile")
public R getPdfFileTest() throws IOException {
......
......@@ -78,7 +78,7 @@ public interface EkpBankGrantDetailMapper extends BaseMapper<EkpBankGrantDetail>
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表的 银企出纳
void updateGongZiZhiChuMain(@Param("fdId") String fdId, @Param("chuNaName") String chuNaName);
......
......@@ -40,4 +40,10 @@ public interface EkpBankPayTaskMapper extends BaseMapper<EkpBankPayTask> {
// 获取发放中的明细表,查询结果
List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(@Param("typeName") String typeName);
// 获取发放中的主表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultMainByOther();
// 获取发放中的明细表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultDetailByOther();
}
......@@ -77,7 +77,7 @@ public interface EkpBankGrantDetailService extends IService<EkpBankGrantDetail>
* @Date: 2024/12/26 11:41
* @return: void
**/
void updateGongZiZhiChuTable(String fdId, String chuNaName);
void updateGongZiZhiChuTable(String tableName, String fdId, String chuNaName);
/**
* @param fdId 工资支出 表id
* @param chuNaName 银企出纳名字
......
......@@ -47,4 +47,10 @@ public interface EkpBankPayTaskService extends IService<EkpBankPayTask> {
**/
List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(String typeName);
// 获取发放中的主表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultMainByOther();
// 获取发放中的明细表,查询结果——其他(非扣税、报销等)
List<EkpBankResultVo> getEkpBankMainByNeedResultDetailByOther();
}
......@@ -129,8 +129,8 @@ public class EkpBankGrantDetailServiceImpl extends ServiceImpl<EkpBankGrantDetai
}
@Override
public void updateGongZiZhiChuTable(String fdId, String chuNaName) {
baseMapper.updateGongZiZhiChuTable(fdId, chuNaName);
public void updateGongZiZhiChuTable(String tableName, String fdId, String chuNaName) {
baseMapper.updateGongZiZhiChuTable(tableName,fdId, chuNaName);
}
@Override
......
......@@ -57,4 +57,25 @@ public class EkpBankPayTaskServiceImpl extends ServiceImpl<EkpBankPayTaskMapper,
public List<EkpBankResultVo> getEkpBankMainByNeedResultDetail(String 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();
}
}
......@@ -798,6 +798,8 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
@Transactional
public R<String> submitBankTask(String fdId, String type, String submitUser) {
if (Common.isNotNull(fdId) && Common.isNotNull(type)) {
// 工资支出表名称
String tableName = "ekp_fd9be224c214ad0992aa";
String redisKey = "SUBMIT_BANK_" + fdId;
if (Common.isNotNull(redisUtil.get(redisKey))) {
return R.failed("数据锁定中,请耐心等待!");
......@@ -840,7 +842,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
// 同步更新明细的发放时间、发放状态
ekpBankGrantDetailService.updateStatusByGrant(fdId);
// 更新 工资支出 的 银企出纳名字
ekpBankGrantDetailService.updateGongZiZhiChuTable(fdId, submitUser);
ekpBankGrantDetailService.updateGongZiZhiChuTable(tableName, fdId, submitUser);
ekpBankGrantDetailService.updateGongZiZhiChuMain(fdId, submitUser);
}
redisUtil.remove(redisKey);
......@@ -911,6 +913,9 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
@Transactional
public synchronized R<String> submitNoTaxTask(String fdId, String type, String submitUser) {
if (Common.isNotNull(fdId) && Common.isNotNull(type)) {
// 非扣税表名称
String tableName = "ekp_75edcee9b5e4b198035a";
String wxNoPre = "FKS";
String redisKey = "SUBMIT_NO_TAX_BANK_" + fdId;
if (Common.isNotNull(redisUtil.get(redisKey))) {
return R.failed("数据锁定中,请耐心等待!");
......@@ -936,6 +941,21 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
redisUtil.remove(redisKey);
return R.failed("数据错误,无金额!");
}
if (Common.isNotNull(main.getFdPayType()) && "报销".equals(main.getFdPayType())) {
if ("行政报销".equals(main.getFdCustomerName())) {
wxNoPre = "XZBX";
tableName = "ekp_6f55b508bcf492cae93d";
} else if ("业务报销".equals(main.getFdCustomerName())) {
wxNoPre = "YWBX";
tableName = "ekp_a2b51052cb1324b5f92f";
} else if ("项目报销".equals(main.getFdCustomerName())) {
wxNoPre = "XMBX";
tableName = "ekp_a185e090a77a14211ab0";
} else if ("差旅费报销".equals(main.getFdCustomerName())) {
wxNoPre = "CLFBX";
tableName = "ekp_af0fda0b28888440fa17";
}
}
int count = ekpBankGrantDetailService.getCountByIdAndMain(fdId);
String totalAmt = String.valueOf(BigDecimalUtils.safeMultiply(main.getFdMoney(), new BigDecimal("100"), 0));
String totalCount = String.valueOf(count);
......@@ -943,10 +963,10 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
// 为空或者失败数=-1,则生成新的wxNo
if (Common.isEmpty(wxNo) ||
(Common.isNotNull(main.getFdFailNum()) && main.getFdFailNum() == CommonConstants.ONE_INT_NEGATE)) {
wxNo = "FKS" + new Date().getTime();
wxNo = wxNoPre + new Date().getTime();
String cur = ekpBankGrantDetailService.getWxNoByWxNo(wxNo);
if (Common.isNotNull(cur)) {
wxNo = "FKS" + new Date().getTime();
wxNo = wxNoPre + new Date().getTime();
}
main.setFdWxNo(wxNo);
main.setFdFailNum(CommonConstants.ZERO_INT);
......@@ -980,12 +1000,13 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
// 同步更新明细的发放时间、发放状态
ekpBankGrantDetailService.updateStatusByGrant(fdId);
// 更新 工资支出 的 银企出纳名字
ekpBankGrantDetailService.updateGongZiZhiChuTable(fdId, submitUser);
ekpBankGrantDetailService.updateGongZiZhiChuTable(tableName, fdId, submitUser);
ekpBankGrantDetailService.updateGongZiZhiChuMain(fdId, submitUser);
}
redisUtil.remove(redisKey);
return returnR;
} else {
wxNoPre = "FKSMX";
// 2明细表
EkpBankGrantDetail detail = ekpBankGrantDetailService.getById(fdId);
if (detail == null) {
......@@ -1000,6 +1021,24 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
redisUtil.remove(redisKey);
return R.failed("数据错误,无金额!");
}
if (Common.isNotNull(detail.getFdParentId())) {
EkpBankPayTask main = ekpBankPayTaskService.getById(detail.getFdParentId());
if (main == null) {
redisUtil.remove(redisKey);
return R.failed("未找到主表数据!");
}
if (Common.isNotNull(main.getFdPayType()) && "报销".equals(main.getFdPayType())) {
if ("行政报销".equals(main.getFdCustomerName())) {
wxNoPre = "XZBXMX";
} else if ("业务报销".equals(main.getFdCustomerName())) {
wxNoPre = "YWBXMX";
} else if ("项目报销".equals(main.getFdCustomerName())) {
wxNoPre = "XMBXMX";
} else if ("差旅费报销".equals(main.getFdCustomerName())) {
wxNoPre = "CLFBXMX";
}
}
}
String totalAmt = String.valueOf(BigDecimalUtils.safeMultiply(detail.getFdMoney(), new BigDecimal("100"), 0));
String totalCount = "1";
String wxNo = detail.getFdWxNo();
......@@ -1007,10 +1046,10 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
if (Common.isEmpty(wxNo) ||
(Common.isNotNull(detail.getFdFailNum()) && detail.getFdFailNum() > CommonConstants.ZERO_INT
&& Common.isNotNull(detail.getFdGrantNum()) && detail.getFdFailNum() >= detail.getFdGrantNum())) {
wxNo = "FKSMX" + new Date().getTime();
wxNo = wxNoPre + new Date().getTime();
String cur = ekpBankGrantDetailService.getWxNoByWxNo(wxNo);
if (Common.isNotNull(cur)) {
wxNo = "FKSMX" + new Date().getTime();
wxNo = wxNoPre + new Date().getTime();
}
detail.setFdWxNo(wxNo);
ekpBankGrantDetailService.updateById(detail);
......@@ -1327,7 +1366,6 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
MybankEnterprisePayQpayentResponseV1 responseV1;
String title = "转账";
String typeName = "非扣税";
String seqNoPre = "AHWX";
String seqNo;
......@@ -1347,7 +1385,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
List<EkpBankGrantDetail> detailDataList;
EkpBankGrantDetail detailData;
// 1:获取需要查询结果的非扣税支付任务(发放中的任务)——主表
List<EkpBankResultVo> mainList = ekpBankPayTaskService.getEkpBankMainByNeedResultMain(typeName);
List<EkpBankResultVo> mainList = ekpBankPayTaskService.getEkpBankMainByNeedResultMainByOther();
String statusRemark;
// 终结态:失败6/8/41或成功7
String failStatus = "41";
......@@ -1361,6 +1399,10 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
// 是否经过了检查,经过检查后则不继续检查结果
boolean isShouQuanCheck = true;
for (EkpBankResultVo vo : mainList) {
if (Common.isNotNull(vo.getFdPayType()) && "报销".equals(vo.getFdPayType())) {
title = vo.getFdPayType();
}
seqNo = seqNoPre + System.currentTimeMillis() + (i++);
responseV1 = icbcTransactionFlowQueryService.getResultNoTax(vo, tranDate, tranTime, seqNo, client);
if (Common.isNotNull(responseV1)) {
......@@ -1427,7 +1469,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
moneyAll = BigDecimalUtils.safeAdd(moneyAll, money);
// 初始化日志明细
logDetail = new EkpBankGrantLogDetail();
setLogDetailBaseInfoNoTax(logs, money, logDetail, data);
setLogDetailBaseInfoNoTax(logs, money, logDetail, data, title);
if (Common.isNotNull(data.getUniBusiId())) {
detailData = oldMap.get(data.getUniBusiId());
......@@ -1498,7 +1540,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
}
// 2:获取主表已发放且明细表发放中的明细表数据,查询工行接口
List<EkpBankResultVo> detailList = ekpBankPayTaskService.getEkpBankMainByNeedResultDetail(typeName);
List<EkpBankResultVo> detailList = ekpBankPayTaskService.getEkpBankMainByNeedResultDetailByOther();
// 明细表
if (detailList != null && !detailList.isEmpty()) {
detailDataList = new ArrayList<>();
......@@ -1507,6 +1549,9 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
// 初始化
i = 0;
for (EkpBankResultVo vo : detailList) {
if (Common.isNotNull(vo.getFdPayType()) && "报销".equals(vo.getFdPayType())) {
title = vo.getFdPayType();
}
seqNo = seqNoPre + System.currentTimeMillis() + (i++);
responseV1 = icbcTransactionFlowQueryService.getResultNoTax(vo, tranDate, tranTime, seqNo, client);
......@@ -1564,7 +1609,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
saveNewEkpBankGrantLog(responseV1.getPackageName(), vo, vo.getFdParentId(), logs, title);
// 初始化日志明细
logDetail = new EkpBankGrantLogDetail();
setLogDetailBaseInfoNoTax(logs, money, logDetail, data);
setLogDetailBaseInfoNoTax(logs, money, logDetail, data, title);
// 收款人名称
logDetail.setFdPayee(vo.getFdPayeeName());
logDetail.setFdRecipientBank(vo.getFdRecipientBank());
......@@ -1602,7 +1647,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
saveNewEkpBankGrantLog(responseV1.getPackageName(), vo, vo.getFdParentId(), logs, title);
// 初始化日志明细
logDetail = new EkpBankGrantLogDetail();
setLogDetailBaseInfoNoTax(logs, money, logDetail, null);
setLogDetailBaseInfoNoTax(logs, money, logDetail, null, title);
// 收款人名称
logDetail.setFdPayee(vo.getFdPayeeName());
logDetail.setFdRecipientBank(vo.getFdRecipientBank());
......@@ -2156,7 +2201,7 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
}
private void setLogDetailBaseInfoNoTax(EkpBankGrantLog logs, BigDecimal money, EkpBankGrantLogDetail logDetail
, MybankEnterprisePayQpayentResponseV1.MybankEnterprisePayQpayentResponseRdV1 data) {
, MybankEnterprisePayQpayentResponseV1.MybankEnterprisePayQpayentResponseRdV1 data, String title) {
logDetail.setFdParentId(logs.getFdId());
logDetail.setFdMoney(money);
......@@ -2167,8 +2212,8 @@ public class IcbcTransactionFlowIssueServiceImpl extends ServiceImpl<EkpSocialIn
logDetail.setFdPayeeAccount(data.getRecAccNo());
logDetail.setFdRemark(data.getSummary());
}
// 汇款用途
logDetail.setFdRemittancePurpose("转账");
// 汇款用途:工资、转账、报销
logDetail.setFdRemittancePurpose(title);
}
/**
......
......@@ -364,6 +364,7 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn
String fSeqNo;
MybankEnterpriseTradeQhisdResponseV1 response;
// int i=1;
for(Map<String,String> accountInfo: accountList) {
bizContent = new MybankEnterpriseTradeQhisdRequestV1.MybankEnterpriseTradeQhisdRequestBizV1();
......@@ -384,6 +385,8 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn
request.setServiceUrl(icbcConfigProperties.getServerUrl());
request.setBizContent(bizContent);
response = client.execute(request);
// 如果工行人要传参,把这个打出来,复制给他
//System.out.println("传参" + (i++) + ":" + JSON.toJSONString(request));
if (response.isSuccess()) {
getInfoListByNoTax(request, mainMap, returnMap, detailMap, client, bizContent);
}
......@@ -422,6 +425,7 @@ public class IcbcTransactionFlowQueryServiceImpl extends ServiceImpl<EkpSocialIn
if (no.contains("-")) {
no = no.split("-")[0];
}
// no 的值将是 "HQP923041354291"
infoOldVo = mainMap.get(no);
if (infoOldVo != null) {
......
......@@ -231,7 +231,7 @@
<!-- 更新工资支出 的 银企出纳 -->
<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>
<!-- 更新工资支出Main表的 银企出纳 -->
<update id="updateGongZiZhiChuMain" >
......
......@@ -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}
</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>
......@@ -134,7 +134,7 @@
<!--查询所有需要查询的单号-主表-->
<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
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 not EXISTS (
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 @@
<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
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 not EXISTS (
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
errorMessageList.add(new ErrorMessage(-1, "超过500条,不存储数据,请处理导入表格"));
cachedDataList.clear();
// 中断读取
context.interrupt();
return;
throw new RuntimeException("超过500条,请减少数据条数!");
}
ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex();
......@@ -395,8 +394,13 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala
}).sheet().doRead();
} catch (Exception e) {
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e);
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
// 判断 为RuntimeException
if (e instanceof RuntimeException) {
return R.failed(e.getMessage());
}
String errorInfo = "数据导入解析失败,请将单元格设为文本!" + e.getMessage();
log.error(errorInfo, e);
return R.failed(errorInfo);
}
boolean isTrue = true;
for (ErrorMessage message : errorMessageList) {
......@@ -482,6 +486,10 @@ public class TSalaryZeroServiceImpl extends ServiceImpl<TSalaryZeroMapper, TSala
continue;
}
if (judgeTaxMonth(excel.getTaxMonth())) {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), "计税月份格式不正确!", excel));
continue;
}
insert = new TSalaryZero();
BeanUtil.copyProperties(excel, insert);
insert.setSettleMonth(settleMonth);
......@@ -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申报
public void saveBatchWithTableName(List<TSalaryZero> insertList, String tableName) {
if (insertList == null || insertList.isEmpty()) {
......
......@@ -190,6 +190,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
}
} finally {
atomicPushFriend.decrementAndGet();
cleanSpireTempFiles();
}
return R.ok();
} else {
......@@ -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() {
Map<String, Integer> map = new HashMap<>();
......@@ -332,7 +368,8 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
if (rosterAutoFlagYgs && !huaListVo.isEmpty()) {
urlR = doExportRosterNew(vo, type, huaListVo, zhangMap, templateSrcMap);
// 新增:强制垃圾回收以清理 Spire.XLS 的临时字体文件
//System.gc();
// 房工接口,获取 企业职工基本医疗保险参保登记表 url
//urlR = doExportRoster(vo.getSocialId(), String.valueOf(type), vo.getUnitCreditCode(), listVo)
if (urlR != null && urlR.getCode() == 200 && Common.isNotNull(urlR.getData())) {
......@@ -1292,7 +1329,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
String filePath = projectRoot + CommonConstants.DOUBLE_LINE + fileName;
//获取要导出的列表
List<TDispatchSocialPersionExportVo> list = new ArrayList<>();
ExcelWriter excelWriter = null;
//ExcelWriter excelWriter = null;
File createFile = null;
try {
......@@ -1346,13 +1383,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
throw new RuntimeException("填充Excel模板失败", e);
}
File inputFile = null;
FileInputStream inputStream = null;
InputStream inStream = null;
try {
//读取文件 生成电子章
inputFile = new File(filePath);
inputStream = new FileInputStream(inputFile);
createFile = new File(filePath);
inputStream = new FileInputStream(createFile);
if (Common.isEmpty(url)) {
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取URL异常");
......@@ -1376,12 +1412,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
return R.failed("税友附件生成异常:" + e.getMessage());
} finally {
// 清理文件
finallyClose(inputFile, null, null, inputStream, null, inStream, null);
finallyClose(null, null, null, inputStream, null, inStream, null);
}
} catch (Exception e) {
if (excelWriter != null) {
/*if (excelWriter != null) {
excelWriter.finish();
}
}*/
log.error("税友附件生成异常", e);
return R.failed("税友附件生成异常:" + e.getMessage());
} finally {
......
......@@ -53,26 +53,28 @@ public class ExcelToImage {
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError);
}
String projectRoot = System.getProperty(CommonConstants.USER_DIR);
File tempFile = null;
File compressedTempFile = null;
//加载Excel工作表
Workbook wb = new Workbook();
wb.loadFromHtml(inputStream);
//获取工作表
Worksheet sheet = wb.getWorksheets().get(0);
//调用方法将Excel工作表保存为图片
sheet.saveToImage(projectRoot+toImag);
File file = null;
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 (file.exists()){
if (tempFile.exists()){
// file 压缩到1M以内
backLog.setLogInfo("压缩大小前");
// 压缩并加章
file = compressImage(file, projectRoot, zhangStream);
tempFile = compressImage(tempFile, projectRoot, zhangStream, compressedTempFile);
backLog.setLogInfo("压缩大小后");
String key = System.currentTimeMillis() + file.getName();
byte[] fileContent = Files.readAllBytes(file.toPath());
String key = System.currentTimeMillis() + tempFile.getName();
byte[] fileContent = Files.readAllBytes(tempFile.toPath());
String base64String = Base64.getEncoder().encodeToString(fileContent);
backLog.setLogInfo("转化为base64String");
String url = socialFriendConfig.uploadPng(restTemplate, key, base64String, backLog);
......@@ -80,15 +82,21 @@ public class ExcelToImage {
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);
}
} catch (Exception e) {
e.printStackTrace();
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagConvertError+e.getMessage());
} finally {
if (file.exists()){
file.delete();
if (wb != null) {
wb.dispose(); // 重要:释放资源并删除临时文件
}
if (tempFile != null && tempFile.exists()){
tempFile.delete();
}
if (compressedTempFile != null && compressedTempFile.exists()){
compressedTempFile.delete();
}
if (null != inputStream){
try {
......@@ -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 sealedImage = addSealToImage(image, zhangStream);
ImageIO.write(sealedImage, "png", originalFile);
int quality = 100; // 从100%开始
File compressedFile = new File(projectRoot, TO_IMAGE_TEMP);
int maxSize = 1024 * 1024;
try {
while (originalFile.length() > maxSize && quality > 10) {
quality -= 5;
ImageIO.write(sealedImage, "png", compressedFile);
if (compressedFile.length() < maxSize) {
ImageIO.write(sealedImage, "png", compressedTempFile);
if (compressedTempFile.length() < maxSize) {
originalFile.delete();
compressedFile.renameTo(originalFile);
compressedTempFile.renameTo(originalFile);
break;
}
compressedFile.delete();
compressedTempFile.delete();
}
} catch (Exception e) {
if (compressedFile != null && compressedFile.exists()) {
compressedFile.delete();
}
} finally {
if (compressedFile != null && compressedFile.exists()) {
compressedFile.delete();
}
throw e;
}
return originalFile;
}
......
......@@ -142,7 +142,6 @@ public class WordToImageUtil {
if (imgFile != null) {
imgFile.delete();
}
}
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