From be3b4fc7e141bca05beff2164510c59f894fc4b5 Mon Sep 17 00:00:00 2001 From: Harryxzy Date: Fri, 4 Jul 2025 15:13:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E7=A8=8E=E7=89=88=E6=9C=AC=20?= =?UTF-8?q?=E4=B8=AA=E7=A8=8E=E7=94=B3=E6=8A=A5bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/TaxDeclareRecordServiceImpl.java | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java b/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java index 13ae9c1a8..2c78fa48e 100644 --- a/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java +++ b/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java @@ -48,6 +48,7 @@ import com.engine.salary.enums.sicategory.DeleteTypeEnum; import com.engine.salary.enums.taxagent.TaxAgentTaxReturnStatusEnum; import com.engine.salary.enums.taxdeclaration.*; import com.engine.salary.exception.SalaryRunTimeException; +import com.engine.salary.mapper.salaryacct.SalaryAcctRecordMapper; import com.engine.salary.mapper.taxdeclaration.TaxDeclareRecordMapper; import com.engine.salary.mapper.taxdeclaration.TaxDeclareStatusMapper; import com.engine.salary.remote.tax.client.DeclareClient; @@ -55,6 +56,8 @@ import com.engine.salary.remote.tax.response.declare.GetCompanyIncomesResponse; import com.engine.salary.remote.tax.response.declare.GetDeclareTaxResultFeedbackResponse; import com.engine.salary.service.*; import com.engine.salary.service.factory.TaxPaymentServiceFactory; +import com.engine.salary.sys.service.SalarySysConfService; +import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl; import com.engine.salary.util.*; import com.engine.salary.util.db.IdGenerator; import com.engine.salary.util.db.MapperProxyFactory; @@ -77,6 +80,7 @@ import java.util.*; import java.util.stream.Collectors; import static com.engine.salary.enums.taxdeclaration.TaxDeclareStatusEnum.NOT_DECLARE; +import static com.engine.salary.sys.constant.SalarySysConstant.TAX_DECLARATION_DATE_TYPE; /** * 个税申报 @@ -182,9 +186,20 @@ public class TaxDeclareRecordServiceImpl extends Service implements TaxDeclareRe return ServiceUtil.getService(OtherDeductionServiceImpl.class, user); } + private SalaryAcctRecordMapper getSalaryAcctRecordMapper() { + return MapperProxyFactory.getProxy(SalaryAcctRecordMapper.class); + } + private TaxPaymentServiceFactory taxPaymentServiceFactory = new TaxPaymentServiceFactory(user); + private SalarySysConfService getSalarySysConfService(User user) { + return ServiceUtil.getService(SalarySysConfServiceImpl.class, user); + } + + //是否根据税款所属期进行申报 + private final boolean isTaxDeclarationByTaxCycle = "1".equals(getSalarySysConfService(user).getValueByCode(TAX_DECLARATION_DATE_TYPE)); + // private TaxPaymentRequestMapper taxPaymentRequestMapper; @@ -274,9 +289,44 @@ public class TaxDeclareRecordServiceImpl extends Service implements TaxDeclareRe // 根据个税扣缴义务人范围查询个税扣缴义务人 Collection taxAgents = queryByTaxAgentRange(saveParam); Map taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getId, TaxAgentPO::getName); + + Date taxCycle; + List salaryAcctRecords = new ArrayList<>(); + //根据税款所属期申报 + if (isTaxDeclarationByTaxCycle) { + taxCycle = saveParam.getTaxCycle(); + if (Objects.isNull(taxCycle)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "税款所属期参数错误")); + } + + // 查询薪资所属月的薪资核算记录 + salaryAcctRecords = listByTaxCycle(SalaryAcctRecordPO.builder().taxCycle(taxCycle).build()); + // 无薪资核算记录,不允许生成个税申报表 + if (CollectionUtils.isEmpty(salaryAcctRecords)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据").replace("{0}", SalaryDateUtil.getFormatYearMonth(taxCycle))); + } + } else { + //根据薪资所属月申报 + // 薪资所属月的日期范围 + LocalDateRange salaryMonthDateRange = SalaryDateUtil.localDate2Range(saveParam.getSalaryMonth()); + if (Objects.isNull(salaryMonthDateRange)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "薪资所属月参数错误")); + } + // 查询薪资所属月的薪资核算记录 + salaryAcctRecords = listBySalaryMonth(SalaryAcctRecordPO.builder().salaryMonths(salaryMonthDateRange).build()); + // 如果当前薪资所属月下存在不同的税款所属期,属于异常业务场景,不允许生成个税申报表 + taxCycle = salaryAcctRecords.get(0).getTaxCycle(); + boolean differentTaxCycle = salaryAcctRecords.stream().anyMatch(salaryAcctRecordPO -> salaryAcctRecordPO.getTaxCycle().compareTo(taxCycle) != 0); + if (differentTaxCycle) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98876, "{0}存在不同的税款所属期,无法正常生成个税申报表,请调整账套设置,重新核算后再生成个税申报表") + .replace("{0}", SalaryDateUtil.getFormatYearMonth(saveParam.getSalaryMonth()))); + } + } // 查询薪资所属月下的薪资核算记录,并按照权限过滤 - LocalDateRange salaryMonthRange = new LocalDateRange().setFromDate(saveParam.getSalaryMonth()).setEndDate(saveParam.getSalaryMonth()); - List salaryAcctRecords = getSalaryAcctRecordService(user).listBySalaryMonth(salaryMonthRange); + // LocalDateRange salaryMonthRange = new LocalDateRange().setFromDate(saveParam.getSalaryMonth()).setEndDate(saveParam.getSalaryMonth()); + // List salaryAcctRecords = getSalaryAcctRecordService(user).listBySalaryMonth(salaryMonthRange); + + // 查询薪资核算记录关联的个税扣缴义务人 List salaryAcctTaxAgents = getSalaryAcctRecordService(user).listBySalaryAcctRecordIds(SalaryEntityUtil.properties(salaryAcctRecords, SalaryAcctRecordPO::getId)); // 按照saveParam中的个税扣缴义务人范围过滤 @@ -362,6 +412,14 @@ public class TaxDeclareRecordServiceImpl extends Service implements TaxDeclareRe } } + public List listBySalaryMonth(SalaryAcctRecordPO po) { + return getSalaryAcctRecordMapper().listSome(po); + } + + public List listByTaxCycle(SalaryAcctRecordPO po) { + return getSalaryAcctRecordMapper().listSome(po); + } + @Override public void refreshData(Long id) { // 查询个税申报记录