diff --git a/resource/sqlupgrade/DM/sql202308090303.sql b/resource/sqlupgrade/DM/sql202308090303.sql new file mode 100644 index 000000000..3c9a6cee5 --- /dev/null +++ b/resource/sqlupgrade/DM/sql202308090303.sql @@ -0,0 +1,36 @@ +create table hrsa_tax_declare_record +( + id number primary key , + create_time date, + update_time date, + creator number, + delete_type int default 0, + tenant_key varchar2(10), + tax_agent_id number, + salary_month varchar2(10), + tax_cycle varchar2(10), + remark varchar2(1000), + request_id varchar2(100), + tax_declare_type number, + tax_declare_status number +); +/ + +alter table hrsa_tax_declare_record add display_update_icon number; +/ + +alter table hrsa_tax_declare_record add tax_pay_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add person_num int; +/ + +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar2(1000); +/ + +alter table hrsa_tax_declare_record add tax_paid_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar2(255); +/ + diff --git a/resource/sqlupgrade/GS/sql202308090303.sql b/resource/sqlupgrade/GS/sql202308090303.sql new file mode 100644 index 000000000..3c9a6cee5 --- /dev/null +++ b/resource/sqlupgrade/GS/sql202308090303.sql @@ -0,0 +1,36 @@ +create table hrsa_tax_declare_record +( + id number primary key , + create_time date, + update_time date, + creator number, + delete_type int default 0, + tenant_key varchar2(10), + tax_agent_id number, + salary_month varchar2(10), + tax_cycle varchar2(10), + remark varchar2(1000), + request_id varchar2(100), + tax_declare_type number, + tax_declare_status number +); +/ + +alter table hrsa_tax_declare_record add display_update_icon number; +/ + +alter table hrsa_tax_declare_record add tax_pay_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add person_num int; +/ + +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar2(1000); +/ + +alter table hrsa_tax_declare_record add tax_paid_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar2(255); +/ + diff --git a/resource/sqlupgrade/JC/sql202308090303.sql b/resource/sqlupgrade/JC/sql202308090303.sql new file mode 100644 index 000000000..3c9a6cee5 --- /dev/null +++ b/resource/sqlupgrade/JC/sql202308090303.sql @@ -0,0 +1,36 @@ +create table hrsa_tax_declare_record +( + id number primary key , + create_time date, + update_time date, + creator number, + delete_type int default 0, + tenant_key varchar2(10), + tax_agent_id number, + salary_month varchar2(10), + tax_cycle varchar2(10), + remark varchar2(1000), + request_id varchar2(100), + tax_declare_type number, + tax_declare_status number +); +/ + +alter table hrsa_tax_declare_record add display_update_icon number; +/ + +alter table hrsa_tax_declare_record add tax_pay_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add person_num int; +/ + +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar2(1000); +/ + +alter table hrsa_tax_declare_record add tax_paid_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar2(255); +/ + diff --git a/resource/sqlupgrade/Mysql/sql202308090303.sql b/resource/sqlupgrade/Mysql/sql202308090303.sql new file mode 100644 index 000000000..f7094b24b --- /dev/null +++ b/resource/sqlupgrade/Mysql/sql202308090303.sql @@ -0,0 +1,32 @@ +create table hrsa_tax_declare_record +( + id bigint primary key comment 'ID' , + create_time datetime comment '创建时间' , + update_time datetime comment '修改时间' , + creator bigint comment '创建人id' , + delete_type int default 0 comment '是否删除' , + tenant_key varchar(10) comment '租户KEY' , + tax_agent_id bigint comment '个税扣缴义务人id' , + salary_month varchar(10) comment '薪资所属月' , + tax_cycle varchar(10) comment '税款所属期' , + remark varchar(1000) comment '备注' , + request_id varchar(100) comment '供应商第三方系统返回的requestid' , + tax_declare_type tinyint comment '申报类型' , + tax_declare_status tinyint comment '申报状态' +) +; + +alter table hrsa_tax_declare_record add display_update_icon tinyint +; + +alter table hrsa_tax_declare_record add tax_pay_amount varchar(255) +; + +alter table hrsa_tax_declare_record add person_num int +; +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar(1000) +; +alter table hrsa_tax_declare_record add tax_paid_amount varchar(255) +; +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar(255) +; \ No newline at end of file diff --git a/resource/sqlupgrade/Oracle/sql202308090303.sql b/resource/sqlupgrade/Oracle/sql202308090303.sql new file mode 100644 index 000000000..e9a221fca --- /dev/null +++ b/resource/sqlupgrade/Oracle/sql202308090303.sql @@ -0,0 +1,31 @@ +create table hrsa_tax_declare_record +( + id number primary key , + create_time date, + update_time date, + creator number, + delete_type int default 0, + tenant_key varchar2(10), + tax_agent_id number, + salary_month varchar2(10), + tax_cycle varchar2(10), + remark varchar2(1000), + request_id varchar2(100), + tax_declare_type number, + tax_declare_status number +) +/ + +alter table hrsa_tax_declare_record add display_update_icon number +/ +alter table hrsa_tax_declare_record add tax_pay_amount varchar2(255) +/ + +alter table hrsa_tax_declare_record add person_num int +/ +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar2(1000) +/ +alter table hrsa_tax_declare_record add tax_paid_amount varchar2(255) +/ +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar2(255) +/ \ No newline at end of file diff --git a/resource/sqlupgrade/PG/sql202308090303.sql b/resource/sqlupgrade/PG/sql202308090303.sql new file mode 100644 index 000000000..33f4a8aea --- /dev/null +++ b/resource/sqlupgrade/PG/sql202308090303.sql @@ -0,0 +1,31 @@ +create table hrsa_tax_declare_record +( + id bigint primary key , + create_time timestamp, + update_time timestamp, + creator bigint, + delete_type int default 0, + tenant_key varchar(10), + tax_agent_id bigint, + salary_month varchar(10), + tax_cycle varchar(10), + remark varchar(1000), + request_id varchar(100), + tax_declare_type smallint, + tax_declare_status smallint +); +/ + +alter table hrsa_tax_declare_record add display_update_icon smallint; +/ +alter table hrsa_tax_declare_record add tax_pay_amount varchar(255); +/ + +alter table hrsa_tax_declare_record add person_num int; +/ +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar(1000); +/ +alter table hrsa_tax_declare_record add tax_paid_amount varchar(255); +/ +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar(255); +/ \ No newline at end of file diff --git a/resource/sqlupgrade/SQLServer/sql202308090303.sql b/resource/sqlupgrade/SQLServer/sql202308090303.sql new file mode 100644 index 000000000..e3ca10522 --- /dev/null +++ b/resource/sqlupgrade/SQLServer/sql202308090303.sql @@ -0,0 +1,32 @@ +create table hrsa_tax_declare_record +( + id bigint primary key , + create_time datetime, + update_time datetime, + creator bigint, + delete_type int default 0, + tenant_key nvarchar(10), + tax_agent_id bigint, + salary_month nvarchar(10), + tax_cycle nvarchar(10), + remark nvarchar(1000), + request_id nvarchar(100), + tax_declare_type tinyint, + tax_declare_status tinyint +) +GO + + +alter table hrsa_tax_declare_record add display_update_icon tinyint +GO +alter table hrsa_tax_declare_record add tax_pay_amount nvarchar(255) +GO + +alter table hrsa_tax_declare_record add person_num int +GO +alter table hrsa_tax_declare_record add tax_declare_error_msg nvarchar(1000) +GO +alter table hrsa_tax_declare_record add tax_paid_amount nvarchar(255) +GO +alter table hrsa_tax_declare_record add tax_pure_paid_amount nvarchar(255) +GO \ No newline at end of file diff --git a/resource/sqlupgrade/ST/sql202308090303.sql b/resource/sqlupgrade/ST/sql202308090303.sql new file mode 100644 index 000000000..3c9a6cee5 --- /dev/null +++ b/resource/sqlupgrade/ST/sql202308090303.sql @@ -0,0 +1,36 @@ +create table hrsa_tax_declare_record +( + id number primary key , + create_time date, + update_time date, + creator number, + delete_type int default 0, + tenant_key varchar2(10), + tax_agent_id number, + salary_month varchar2(10), + tax_cycle varchar2(10), + remark varchar2(1000), + request_id varchar2(100), + tax_declare_type number, + tax_declare_status number +); +/ + +alter table hrsa_tax_declare_record add display_update_icon number; +/ + +alter table hrsa_tax_declare_record add tax_pay_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add person_num int; +/ + +alter table hrsa_tax_declare_record add tax_declare_error_msg varchar2(1000); +/ + +alter table hrsa_tax_declare_record add tax_paid_amount varchar2(255); +/ + +alter table hrsa_tax_declare_record add tax_pure_paid_amount varchar2(255); +/ + diff --git a/src/com/engine/salary/mapper/taxagent/TaxDeclareRecordMapper.java b/src/com/engine/salary/mapper/taxagent/TaxDeclareRecordMapper.java new file mode 100644 index 000000000..6142d2c21 --- /dev/null +++ b/src/com/engine/salary/mapper/taxagent/TaxDeclareRecordMapper.java @@ -0,0 +1,11 @@ +package com.engine.salary.mapper.taxagent; + +/** + * @description: 涓◣鐢虫姤 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 2022/11/2 5:46 PM + * @version:v1.0 + */ +public interface TaxDeclareRecordMapper { +} diff --git a/src/com/engine/salary/service/TaxDeclareRecordService.java b/src/com/engine/salary/service/TaxDeclareRecordService.java new file mode 100644 index 000000000..4f64025d6 --- /dev/null +++ b/src/com/engine/salary/service/TaxDeclareRecordService.java @@ -0,0 +1,187 @@ +package com.engine.salary.service; + +import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationRateDTO; +import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO; +import com.engine.salary.entity.taxdeclaration.po.TaxDeclareRecordPO; + +import java.time.YearMonth; +import java.util.Collection; + +/** + * @description: 涓◣鐢虫姤 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 2022/11/2 5:48 PM + * @version:v1.0 + */ +public interface TaxDeclareRecordService { + + /** + * 鏌ヨ涓◣鐢虫姤璁板綍 + * + * @param id + * @return + */ + TaxDeclareRecordPO getById(Long id); + +// /** +// * 鏌ヨ涓◣鐢虫姤璁板綍 +// * +// * @param ids +// * @param tenantKey +// * @return +// */ +// List listByIds(Collection ids, String tenantKey); +// +// /** +// * 鏌ヨ涓◣鐢虫姤璁板綍 +// * +// * @param taxCycleRange +// * @param tenantKey +// * @return +// */ +// List listByTaxCycleRange(YearMonthRange taxCycleRange, String tenantKey); +// +// /** +// * 鏍规嵁涓◣鎵g即涔夊姟浜篿d銆佺◣娆炬墍灞炴湡鏌ヨ涓◣鐢虫姤璁板綍 +// * +// * @param taxAgentIds +// * @param taxCycle +// * @param tenantKey +// * @return +// */ +// List listByTaxCycleAndTaxAgentIds(YearMonth taxCycle, Collection taxAgentIds, String tenantKey); +// +// /** +// * 鏍规嵁涓◣鎵g即涔夊姟浜篿d銆佽柂璧勬墍灞炴湀鏌ヨ涓◣鐢虫姤璁板綍 +// * +// * @param salaryMonth +// * @param taxAgentIds +// * @param tenantKey +// * @return +// */ +// List listBySalaryMonthAndTaxAgentIds(YearMonth salaryMonth, Collection taxAgentIds, String tenantKey); +// +// /** +// * 鏌ヨ涓◣鐢虫姤璁板綍 +// * +// * @param queryParam +// * @param tenantKey +// * @return +// */ +// Page listPageByParam(TaxDeclarationListQueryParam queryParam, Long employeeId, String tenantKey); +// +// /** +// * 鐢熸垚鐢虫姤琛 +// * +// * @param saveParam +// * @param employeeId +// * @param tenantKey +// */ +// void save(TaxDeclarationSaveParam saveParam, Long employeeId, String tenantKey); + + + /** + * 鍒锋柊鏁版嵁 + * + * @param id + * @param employeeId + * @param tenantKey + */ + void refreshData(Long id, Long employeeId, String tenantKey); + + /** + * 鏇存柊涓◣鐢虫姤琛ㄧ殑寰呭埛鏂版暟鎹殑鏍囪瘑 + * + * @param id + * @param employeeId + * @param tenantKey + */ + void updateIcon(Long id, Integer displayIcon, Long employeeId, String tenantKey); + + /** + * 鍥犱负钖祫鏍哥畻缁撴灉鍙戠敓鍙樺姩锛屾墍浠ラ渶瑕佹洿鏂颁釜绋庣敵鎶ヨ〃鐨勫緟鍒锋柊鏁版嵁鐨勬爣璇 + * + * @param taxCycle + * @param taxAgentIds + * @param tenantKey + */ + void updateByTaxCycleAndTaxAgentIds(YearMonth taxCycle, Collection taxAgentIds, String tenantKey); + + /** + * 鍒ゆ柇鏄惁鏈夋潈闄愬彲鏌ョ湅涓◣鐢虫姤琛 + * + * @param taxDeclaration + * @param employeeId + * @param tenantKey + * @return + */ + boolean checkByAuthority(TaxDeclarationPO taxDeclaration, Long employeeId, String tenantKey); + + /** + * 鏍规嵁id鍒犻櫎 + * + * @param ids + * @param tenantKey + */ + void deleteByIds(Collection ids, String tenantKey); + + /** + * 涓◣鐢虫姤 + * + * @param id + * @param tenantKey + */ + void declare(Long id, Long employeeId, String tenantKey); + + /** + * 涓◣鐢虫姤鑾峰彇鍙嶉 + * + * @param id + * @param tenantKey + */ + void getDeclareFeedback(Long id, TaxDeclarationRateDTO taxDeclarationRate, Long employeeId, String tenantKey); + + /** + * 浣滃簾 + * + * @param id + * @param tenantKey + */ + void cancelDeclare(Long id, Long employeeId, String tenantKey); + + /** + * 鑾峰彇浣滃簾鍙嶉 + * + * @param id + * @param tenantKey + */ + void getCancelFeedback(Long id, TaxDeclarationRateDTO taxDeclarationRate, Long employeeId, String tenantKey); + + /** + * 鏇存鐢虫姤 + * + * @param id + * @param employeeId + * @param tenantKey + */ + void updateDeclare(Long id, Long employeeId, String tenantKey); + + /** + * 绋庡眬绔敵鎶ョ姸鎬佹煡璇 + * + * @param id + * @param employeeId + * @param tenantKey + */ + String queryDeclareStatus(Long id, Long employeeId, String tenantKey); + + /** + * 绋庡眬绔敵鎶ユ槑缁嗘煡璇 + * + * @param id + * @param employeeId + * @param tenantKey + */ + String queryCompanyIncomes(Long id, Long employeeId, String tenantKey); +} diff --git a/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java b/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java new file mode 100644 index 000000000..75c5d06b7 --- /dev/null +++ b/src/com/engine/salary/service/impl/TaxDeclareRecordServiceImpl.java @@ -0,0 +1,1129 @@ +package com.engine.salary.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; +import com.engine.core.impl.Service; +import com.engine.salary.entity.taxdeclaration.po.TaxDeclareRecordPO; +import com.engine.salary.mapper.taxagent.TaxDeclareRecordMapper; +import com.engine.salary.service.*; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.weaver.common.component.table.page.Page; +import com.weaver.common.distribution.genid.IdGenerator; +import com.weaver.common.elog.dto.LoggerContext; +import com.weaver.common.elog.util.LoggerTemplate; +import com.weaver.common.elog.util.Util; +import com.weaver.framework.util.JsonUtil; +import com.weaver.hrm.salary.common.YearMonthRange; +import com.weaver.hrm.salary.constant.SzyhApiConstant; +import com.weaver.hrm.salary.dao.TaxPaymentRequestMapper; +import com.weaver.hrm.salary.entity.datacollection.po.AddUpSituationPO; +import com.weaver.hrm.salary.entity.employeedeclare.bo.EmployeeDeclareRequest; +import com.weaver.hrm.salary.entity.employeedeclare.po.EmployeeDeclarePO; +import com.weaver.hrm.salary.entity.salaryacct.param.SalaryAcctEmployeeQueryParam; +import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctEmployeePO; +import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctRecordPO; +import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctResultValuePO; +import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctTaxAgentPO; +import com.weaver.hrm.salary.entity.salaryitem.po.SalaryItemPO; +import com.weaver.hrm.salary.entity.salarysob.po.SalarySobAddUpRulePO; +import com.weaver.hrm.salary.entity.salarysob.po.SalarySobTaxReportRulePO; +import com.weaver.hrm.salary.entity.taxagent.bo.TaxAgentTaxReturnBO; +import com.weaver.hrm.salary.entity.taxagent.po.TaxAgentPO; +import com.weaver.hrm.salary.entity.taxagent.po.TaxAgentTaxReturnPO; +import com.weaver.hrm.salary.entity.taxapiflow.bo.TaxApiFlowBO; +import com.weaver.hrm.salary.entity.taxapiflow.po.TaxDeclarationApiFlowRecordPO; +import com.weaver.hrm.salary.entity.taxdeclaration.bo.*; +import com.weaver.hrm.salary.entity.taxdeclaration.dto.TaxDeclarationRateDTO; +import com.weaver.hrm.salary.entity.taxdeclaration.param.AbnormalEmployeeListQueryParam; +import com.weaver.hrm.salary.entity.taxdeclaration.param.TaxDeclarationListQueryParam; +import com.weaver.hrm.salary.entity.taxdeclaration.param.TaxDeclarationSaveParam; +import com.weaver.hrm.salary.entity.taxdeclaration.po.*; +import com.weaver.hrm.salary.entity.taxdeclaration.response.CancelDeclareFeedbackResponse; +import com.weaver.hrm.salary.entity.taxdeclaration.response.DeclareTaxFeedbackResponse; +import com.weaver.hrm.salary.entity.taxdeclaration.response.DeclareTaxResponse; +import com.weaver.hrm.salary.entity.taxdeclaration.response.UpdateDeclareResponse; +import com.weaver.hrm.salary.enums.OperateTypeEnum; +import com.weaver.hrm.salary.enums.employeedeclare.DeclareStatusEnum; +import com.weaver.hrm.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum; +import com.weaver.hrm.salary.enums.sicategory.DeleteTypeEnum; +import com.weaver.hrm.salary.enums.taxagent.TaxAgentTaxReturnStatusEnum; +import com.weaver.hrm.salary.enums.taxdeclaration.*; +import com.weaver.hrm.salary.exception.SalaryRunTimeException; +import com.weaver.hrm.salary.service.*; +import com.weaver.hrm.salary.service.factory.TaxPaymentServiceFactory; +import com.weaver.hrm.salary.util.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @description: 涓◣鐢虫姤 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 2022/11/2 5:48 PM + * @version:v1.0 + */ +@Slf4j +public class TaxDeclareRecordServiceImpl extends Service implements TaxDeclareRecordService { + + + private TaxDeclareRecordMapper taxDeclareRecordMapper; + + private TaxDeclarationService taxDeclarationService; + + private TaxDeclarationValueService taxDeclarationValueService; + + private EmployeeDeclareService employeeDeclareService; + + private TaxAgentTaxReturnService taxAgentTaxReturnService; + + private TaxAgentService taxAgentService; + + private TaxDeclarationApiConfigService taxDeclarationApiConfigService; + + private AddUpSituationService addUpSituationService; + + private TaxDeclarationApiBillingService taxDeclarationApiBillingService; + @Resource(name = "taxDeclarationLoggerTemplate") + private LoggerTemplate taxDeclarationLoggerTemplate; + + private TaxDeclareEmployeeService taxDeclareEmployeeService; + + private TaxDeclareFailService taxDeclareFailService; + + private SalaryAcctRecordService salaryAcctRecordService; + + private SalaryAcctTaxAgentService salaryAcctTaxAgentService; + + private SalaryAcctEmployeeService salaryAcctEmployeeService; + + private SalaryAcctResultService salaryAcctResultValueService; + + private SalaryItemService salaryItemService; + + private SalarySobTaxReportRuleService salarySobTaxReportRuleService; + + private TaxReportColumnService taxReportColumnService; + + private SalarySobAddUpRuleService salarySobAddUpRuleService; + + private TaxPaymentServiceFactory taxPaymentServiceFactory; + + private TaxPaymentRequestMapper taxPaymentRequestMapper; + + @Override + public TaxDeclareRecordPO getById(Long id) { + return new LambdaQueryChainWrapper<>(taxDeclareRecordMapper) + .eq(TaxDeclareRecordPO::getTenantKey, tenantKey) + .eq(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue()) + .eq(TaxDeclareRecordPO::getId, id) + .one(); + } +// +// @Override +// public List listByIds(Collection ids, String tenantKey) { +// return new LambdaQueryChainWrapper<>(taxDeclareRecordMapper) +// .eq(TaxDeclareRecordPO::getTenantKey, tenantKey) +// .eq(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue()) +// .in(TaxDeclareRecordPO::getId, ids) +// .list(); +// } +// +// @Override +// public List listByTaxCycleRange(YearMonthRange taxCycleRange, String tenantKey) { +// LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); +// queryWrapper.eq(TaxDeclareRecordPO::getTenantKey, tenantKey); +// queryWrapper.eq(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue()); +// if (Objects.nonNull(taxCycleRange.getStartMonth())) { +// queryWrapper.ge(TaxDeclareRecordPO::getTaxCycle, taxCycleRange.getStartMonth().toString()); +// } +// if (Objects.nonNull(taxCycleRange.getEndMonth())) { +// queryWrapper.le(TaxDeclareRecordPO::getTaxCycle, taxCycleRange.getEndMonth().toString()); +// } +// return taxDeclareRecordMapper.selectList(queryWrapper); +// } +// +// @Override +// public List listByTaxCycleAndTaxAgentIds(YearMonth taxCycle, Collection taxAgentIds, String tenantKey) { +// if (Objects.isNull(taxCycle) || CollectionUtils.isEmpty(taxAgentIds)) { +// return Collections.emptyList(); +// } +// return new LambdaQueryChainWrapper<>(taxDeclareRecordMapper) +// .eq(TaxDeclareRecordPO::getTenantKey, tenantKey) +// .eq(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue()) +// .in(TaxDeclareRecordPO::getTaxAgentId, taxAgentIds) +// .eq(TaxDeclareRecordPO::getTaxCycle, taxCycle.toString()) +// .list(); +// } +// +// @Override +// public List listBySalaryMonthAndTaxAgentIds(YearMonth salaryMonth, Collection taxAgentIds, String tenantKey) { +// if (Objects.isNull(salaryMonth) || CollectionUtils.isEmpty(taxAgentIds)) { +// return Collections.emptyList(); +// } +// return new LambdaQueryChainWrapper<>(taxDeclareRecordMapper) +// .eq(TaxDeclareRecordPO::getTenantKey, tenantKey) +// .eq(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue()) +// .in(TaxDeclareRecordPO::getTaxAgentId, taxAgentIds) +// .eq(TaxDeclareRecordPO::getSalaryMonth, salaryMonth.toString()) +// .list(); +// } +// +// @Override +// public Page listPageByParam(TaxDeclarationListQueryParam queryParam, Long employeeId, String tenantKey) { +// Page page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true); +// // 鏋勫缓鏌ヨ鍙傛暟 +// LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); +// queryWrapper.eq(TaxDeclareRecordPO::getTenantKey, tenantKey); +// queryWrapper.eq(TaxDeclareRecordPO::getDeleteType, 0); +// if (SalaryEntityUtil.isNotNullOrEmpty(queryParam.getFromSalaryMonth())) { +// queryWrapper.ge(TaxDeclareRecordPO::getSalaryMonth, queryParam.getFromSalaryMonth()); +// } +// if (SalaryEntityUtil.isNotNullOrEmpty(queryParam.getEndSalaryMonth())) { +// queryWrapper.le(TaxDeclareRecordPO::getSalaryMonth, queryParam.getEndSalaryMonth()); +// } +// if (StringUtils.isNotEmpty(queryParam.getTaxAgentName())) { +// List taxAgents = taxAgentService.listByNameLike(queryParam.getTaxAgentName(), tenantKey); +// if (CollectionUtils.isEmpty(taxAgents)) { +// return page; +// } +// Set taxAgentIds = SalaryEntityUtil.properties(taxAgents, TaxAgentPO::getId); +// queryWrapper.in(TaxDeclareRecordPO::getTaxAgentId, taxAgentIds); +// } +// // 鍒ゆ柇鏄惁寮鍚簡鍒嗘潈 +// Boolean openDevolution = taxAgentService.isOpenDevolution(tenantKey); +// // 鍒ゆ柇鏄惁鏄荤鐞嗗憳 +// Boolean isChief = taxAgentService.isChief(employeeId, tenantKey); +// // 鍙鑼冨洿鍐呯殑涓◣鎵g即涔夊姟浜 +// List taxAgents = Lists.newArrayList(); +// if (openDevolution) { +// if (isChief) { +// taxAgents = taxAgentService.listAsChief(openDevolution, isChief, employeeId, tenantKey); +// } else { +// taxAgents = taxAgentService.listAllTaxAgentsAsAdmin(employeeId, tenantKey); +// } +// if (CollectionUtils.isEmpty(taxAgents)) { +// return page; +// } +// Set taxAgentIds = SalaryEntityUtil.properties(taxAgents, TaxAgentPO::getId); +// queryWrapper.in(TaxDeclareRecordPO::getTaxAgentId, taxAgentIds); +// } +// queryWrapper.orderByDesc(TaxDeclareRecordPO::getTaxCycle); +// queryWrapper.orderByDesc(TaxDeclareRecordPO::getId); +// return taxDeclareRecordMapper.selectPage(page, queryWrapper); +// } +// +// @Override +// public void save(TaxDeclarationSaveParam saveParam, Long employeeId, String tenantKey) { +// LocalDateTime now = LocalDateTime.now(); +// Set needDeleteTaxDeclareRecordIds = Sets.newHashSet(); +// List newTaxDeclareRecords = Lists.newArrayList(); +// List newTaxDeclarations = Lists.newArrayList(); +// List newTaxDeclarationValues = Lists.newArrayList(); +// List newAddUpSituations = Lists.newArrayList(); +// // 鏍规嵁涓◣鎵g即涔夊姟浜鸿寖鍥存煡璇釜绋庢墸缂翠箟鍔′汉 +// List taxAgents = queryByTaxAgentRange(saveParam, employeeId, tenantKey); +// Map taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getId, TaxAgentPO::getName); +// // 鏌ヨ钖祫鎵灞炴湀涓嬬殑钖祫鏍哥畻璁板綍锛屽苟鎸夌収鏉冮檺杩囨护 +// YearMonthRange salaryMonthRange = new YearMonthRange() +// .setStartMonth(saveParam.getSalaryMonth()) +// .setEndMonth(saveParam.getSalaryMonth()); +// List salaryAcctRecords = salaryAcctRecordService.filterByAuthority( +// salaryAcctRecordService.listBySalaryMonth(salaryMonthRange, tenantKey), employeeId, tenantKey); +// // 鏌ヨ钖祫鏍哥畻璁板綍鍏宠仈鐨勪釜绋庢墸缂翠箟鍔′汉 +// List salaryAcctTaxAgents = salaryAcctTaxAgentService.listBySalaryAcctRecordIds( +// SalaryEntityUtil.properties(salaryAcctRecords, SalaryAcctRecordPO::getId), tenantKey); +// // 鎸夌収saveParam涓殑涓◣鎵g即涔夊姟浜鸿寖鍥磋繃婊 +// Set taxAgentIds = SalaryEntityUtil.properties(taxAgents, TaxAgentPO::getId); +// salaryAcctTaxAgents = salaryAcctTaxAgents.stream() +// .filter(e -> taxAgentIds.contains(e.getTaxAgentId())) +// .collect(Collectors.toList()); +// Set salaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctTaxAgents, SalaryAcctTaxAgentPO::getSalaryAcctRecordId); +// salaryAcctRecords = salaryAcctRecords.stream() +// .filter(e -> salaryAcctRecordIds.contains(e.getId())) +// .collect(Collectors.toList()); +// // 鏍¢獙鏄惁鍙互鐢熸垚涓◣鐢虫姤琛 +// // 杩斿洖鐩墠宸茬粡鐢熸垚鐨勪釜绋庣敵鎶ヨ〃 +// List taxDeclareRecords = checkBeforeSave(saveParam, taxAgentNameMap, salaryAcctRecords, salaryAcctTaxAgents, employeeId, tenantKey); +// Map taxDeclareRecordMap = SalaryEntityUtil.convert2Map(taxDeclareRecords, e -> e.getTaxCycle() + "-" + e.getTaxAgentId()); +// // 鏌ヨ钖祫鏍哥畻浜哄憳 +// List salaryAcctEmployees = salaryAcctEmployeeService.listByRecordIdsAndTaxAgentIds(salaryAcctRecordIds, taxAgentIds, tenantKey); +// // 钖祫鏍哥畻浜哄憳鎸夌収绋庢鎵灞炴湡鑱氬悎鍒嗙被 +// Map> taxCycleKeyEmployeeMap = SalaryEntityUtil.group2Map( +// salaryAcctEmployees, SalaryAcctEmployeePO::getTaxCycle); +// for (Map.Entry> taxCycleEntry : taxCycleKeyEmployeeMap.entrySet()) { +// // 钖祫鏍哥畻浜哄憳鎸夌収涓◣鎵g即涔夊姟浜篿d鑱氬悎鍒嗙被 +// Map> taxAgentIdKeyEmployeeMap = SalaryEntityUtil.group2Map( +// taxCycleEntry.getValue(), SalaryAcctEmployeePO::getTaxAgentId); +// for (Map.Entry> taxAgentIdEntry : taxAgentIdKeyEmployeeMap.entrySet()) { +// TaxDeclareRecordPO oldTaxDeclareRecord = taxDeclareRecordMap.get(taxCycleEntry.getKey() + "-" + taxAgentIdEntry.getKey()); +// // 濡傛灉宸茬粡鐢熸垚浜嗕釜绋庣敵鎶ヨ〃锛屽苟涓斾釜绋庣敵鎶ヨ〃宸茬粡鐢虫姤杩囦簡锛屽氨璺宠繃 +// if (oldTaxDeclareRecord != null) { +// if (!(Objects.equals(oldTaxDeclareRecord.getTaxDeclareType(), TaxDeclareTypeEnum.NORMAL_DECLARE.getValue()) +// && Objects.equals(oldTaxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.NOT_DECLARE.getValue()))) { +// continue; +// } +// needDeleteTaxDeclareRecordIds.add(oldTaxDeclareRecord.getId()); +// } +// TaxDeclareRecordPO taxDeclareRecord = new TaxDeclareRecordPO() +// .setId(IdGenerator.generate()) +// .setTaxAgentId(taxAgentIdEntry.getKey()) +// .setSalaryMonth(saveParam.getSalaryMonth().toString()) +// .setTaxCycle(taxCycleEntry.getKey()) +// .setTaxDeclareType(TaxDeclareTypeEnum.NORMAL_DECLARE.getValue()) +// .setTaxDeclareStatus(TaxDeclareStatusEnum.NOT_DECLARE.getValue()) +// .setRemark(saveParam.getDescription()) +// .setCreator(employeeId) +// .setTenantKey(tenantKey) +// .setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()) +// .setCreateTime(now) +// .setUpdateTime(now); +// newTaxDeclareRecords.add(taxDeclareRecord); +// // 鐢熸垚涓◣鐢虫姤琛 +// TaxDeclarationResult taxDeclarationResult = generateReportPerRecord(taxDeclareRecord, taxAgentIdEntry.getValue(), employeeId, tenantKey); +// newTaxDeclarations.addAll(taxDeclarationResult.getTaxDeclarations()); +// newTaxDeclarationValues.addAll(taxDeclarationResult.getTaxDeclarationValues()); +// newAddUpSituations.addAll(taxDeclarationResult.getAddUpSituations()); +// } +// } +// +// // 鍒犻櫎鍘熸潵鐢熸垚鐨勪釜绋庣敵鎶ヨ褰曘佷釜绋庣敵鎶ヨ〃銆佷釜绋庣敵鎶ヨ〃鏄庣粏 +// deleteByIds(needDeleteTaxDeclareRecordIds, tenantKey); +// // 淇濆瓨涓◣鐢虫姤璁板綍 +// if (CollectionUtils.isNotEmpty(newTaxDeclareRecords)) { +// saveBatch(newTaxDeclareRecords); +// } +// // 淇濆瓨涓◣鐢虫姤琛 +// if (CollectionUtils.isNotEmpty(newTaxDeclarations)) { +// taxDeclarationService.saveBatch(newTaxDeclarations); +// } +// // 淇濆瓨涓◣鐢虫姤琛ㄦ槑缁 +// if (CollectionUtils.isNotEmpty(newTaxDeclarationValues)) { +// taxDeclarationValueService.batchSave(newTaxDeclarationValues, tenantKey); +// } +// // 淇濆瓨绱鎯呭喌 +// if (CollectionUtils.isNotEmpty(newAddUpSituations)) { +// Map> addUpSituationMap = SalaryEntityUtil.group2Map(newAddUpSituations, e -> SalaryDateUtil.getFormatYearMonth(e.getTaxYearMonth())); +// for (Map.Entry> entry : addUpSituationMap.entrySet()) { +// addUpSituationService.deleteByTaxYearMonthAndTaxAgentIds(YearMonth.parse(entry.getKey()), +// SalaryEntityUtil.properties(entry.getValue(), AddUpSituationPO::getTaxAgentId), tenantKey); +// addUpSituationService.saveBatch(entry.getValue(), tenantKey); +// } +// } +// // 璁板綍鏃ュ織 +// for (TaxDeclareRecordPO taxDeclareRecord : newTaxDeclareRecords) { +// LoggerContext loggerContext = new LoggerContext<>(); +// loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); +// loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") +// .replace("{0}", taxAgentNameMap.getOrDefault(taxDeclareRecord.getTaxAgentId(), StringUtils.EMPTY)) +// .replace("{1}", taxDeclareRecord.getTaxCycle())); +// loggerContext.setOperator(Util.null2String(employeeId)); +// loggerContext.setOperateType(OperateTypeEnum.ADD.getValue()); +// loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 99815, "鐢熸垚涓◣鐢虫姤琛")); +// loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 99815, "鐢熸垚涓◣鐢虫姤琛")); +// loggerContext.setNewValues(taxDeclareRecord); +// taxDeclarationLoggerTemplate.write(loggerContext); +// } +// } + + @Override + @Transactional(rollbackFor = Exception.class) + public void refreshData(Long id) { + // 鏌ヨ涓◣鐢虫姤璁板綍 + TaxDeclareRecordPO taxDeclareRecord = getById(id); + if (Objects.isNull(taxDeclareRecord)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156495, "鍙傛暟寮傚父锛屼釜绋庣敵鎶ヨ褰曚笉瀛樺湪鎴栧凡琚垹闄")); + } + if (!Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.NOT_DECLARE.getValue()) + && !Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARE_FAIL.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 182700, "瀵逛笉璧凤紝鍙湁鏈敵鎶ョ姸鎬佷笅鍙互鍒锋柊鏁版嵁")); + } + // 鏌ヨ绋庢鎵灞炴湡涓嬬殑钖祫鏍哥畻浜哄憳 + SalaryAcctEmployeeQueryParam salaryAcctEmployeeQueryParam = new SalaryAcctEmployeeQueryParam() + .setTaxAgentIds(Collections.singletonList(taxDeclareRecord.getTaxAgentId())) + .setTaxCycle(taxDeclareRecord.getTaxCycle()); + List salaryAcctEmployees = salaryAcctEmployeeService.listByParam(salaryAcctEmployeeQueryParam, tenantKey); + // 鏌ヨ钖祫鏍哥畻璁板綍 + Set salaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctEmployees, SalaryAcctEmployeePO::getSalaryAcctRecordId); + List salaryAcctRecords = salaryAcctRecordService.listByIds(salaryAcctRecordIds, tenantKey); + // 濡傛灉瀛樺湪鏈綊妗g殑钖祫鏍哥畻璁板綍锛屼笉鍏佽鐢熸垚涓◣鐢虫姤琛 + boolean notArchived = salaryAcctRecords.stream() + .anyMatch(salaryAcctRecordPO -> Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())); + if (notArchived) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 98875, "{0}鏈夋湭褰掓。鏁版嵁锛岃鍏ㄩ儴褰掓。鍚庡啀鐢虫姤") + .replace("{0}", taxDeclareRecord.getSalaryMonth())); + } + + TaxDeclarationResult taxDeclarationResult = generateReportPerRecord(taxDeclareRecord, salaryAcctEmployees, employeeId, tenantKey); + // 鏇存柊涓◣鐢虫姤璁板綍 + taxDeclareRecord.setDisplayUpdateIcon(0).setUpdateTime(LocalDateTime.now()); + updateById(taxDeclareRecord); + // 鍒犻櫎鍘熸潵鐨勭敵鎶ヨ〃锛屼繚瀛樻柊鐢熸垚鐨 + taxDeclarationService.deleteByTaxDeclareRecordIds(Collections.singleton(taxDeclareRecord.getId()), tenantKey); + if (CollectionUtils.isNotEmpty(taxDeclarationResult.getTaxDeclarations())) { + taxDeclarationService.saveBatch(taxDeclarationResult.getTaxDeclarations()); + } + // 鍒犻櫎鍘熸潵鐨勭敵鎶ヨ〃鏄庣粏锛屼繚瀛樻柊鐢熸垚鐨 + taxDeclarationValueService.deleteByTaxDeclareRecordIds(Collections.singleton(taxDeclareRecord.getId()), tenantKey); + if (CollectionUtils.isNotEmpty(taxDeclarationResult.getTaxDeclarationValues())) { + taxDeclarationValueService.batchSave(taxDeclarationResult.getTaxDeclarationValues(), tenantKey); + } + // 淇濆瓨绱鎯呭喌 + if (CollectionUtils.isNotEmpty(taxDeclarationResult.getAddUpSituations())) { + Map> addUpSituationMap = SalaryEntityUtil.group2Map(taxDeclarationResult.getAddUpSituations(), + e -> SalaryDateUtil.getFormatYearMonth(e.getTaxYearMonth())); + for (Map.Entry> entry : addUpSituationMap.entrySet()) { + addUpSituationService.deleteByTaxYearMonthAndTaxAgentIds(YearMonth.parse(entry.getKey()), + SalaryEntityUtil.properties(entry.getValue(), AddUpSituationPO::getTaxAgentId), tenantKey); + addUpSituationService.saveBatch(entry.getValue(), tenantKey); + } + } + } + + private TaxDeclarationResult generateReportPerRecord(TaxDeclareRecordPO taxDeclareRecord, + List salaryAcctEmployees, + Long employeeId, String tenantKey) { + LocalDateTime now = LocalDateTime.now(); + List taxDeclarations = Lists.newArrayList(); + List taxDeclarationValues = Lists.newArrayList(); + List addUpSituations = Lists.newArrayList(); + // 鏌ヨ钖祫椤圭洰 + List salaryItems = salaryItemService.listAll(employeeId, tenantKey); + // 鏌ヨ涓◣鐢虫姤琛ㄥ垪 + List taxReportColumns = taxReportColumnService.listAll(tenantKey); + Map> taxReportColumnMap = SalaryEntityUtil.group2Map(taxReportColumns, TaxReportColumnPO::getIncomeCategory); + // 鏌ヨ钖祫鏍哥畻璁板綍 + Set salaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctEmployees, SalaryAcctEmployeePO::getSalaryAcctRecordId); + List salaryAcctRecords = salaryAcctRecordService.listByIds(salaryAcctRecordIds, tenantKey); + Map salaryAcctRecordMap = SalaryEntityUtil.convert2Map(salaryAcctRecords, SalaryAcctRecordPO::getId); + // 鏌ヨ钖祫鏍哥畻缁撴灉 + Set salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployees, SalaryAcctEmployeePO::getId); + List salaryAcctResultValues = salaryAcctResultValueService.listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds, tenantKey); + // 鏌ヨ钖祫璐﹀鐨勭疮璁″瓧娈靛搴斿叧绯 + Set salarySobIds = SalaryEntityUtil.properties(salaryAcctEmployees, SalaryAcctEmployeePO::getSalarySobId); + List salarySobAddUpRules = salarySobAddUpRuleService.listBySalarySobIds(salarySobIds, tenantKey); + Map salarySobAddUpRuleMap = SalaryEntityUtil.convert2Map(salarySobAddUpRules, + e -> e.getSalarySobId() + "-" + e.getAddUpColumnDataIndex()); + // 鏌ヨ钖祫璐﹀鐨勪釜绋庣敵鎶ヨ〃瀵瑰簲瑙勫垯 + List salarySobTaxReportRules = salarySobTaxReportRuleService.listBySalarySobIds(salarySobIds, tenantKey); + Map salarySobTaxReportRuleMap = SalaryEntityUtil.convert2Map(salarySobTaxReportRules, e -> e.getSalarySobId() + "-" + e.getReportColumnDataIndex()); + // 钖祫鏍哥畻缁撴灉鎸夌収钖祫鏍哥畻浜哄憳id鑱氬悎鍒嗙被 + Map salaryAcctResultValueMap = SalaryEntityUtil.convert2Map( + salaryAcctResultValues, SalaryAcctResultValuePO::getSalaryAcctEmployeeId); + // 钖祫鏍哥畻浜哄憳鎸夌収鎵寰楅」鐩仛鍚堝垎绫 + Map> incomeCategoryKeyEmployeeMap = SalaryEntityUtil.group2Map( + salaryAcctEmployees, SalaryAcctEmployeePO::getIncomeCategory); + for (Map.Entry> incomeCategoryEntry : incomeCategoryKeyEmployeeMap.entrySet()) { + List controlViewSalaryAcctRecords = incomeCategoryEntry.getValue().stream() + .map(e -> salaryAcctRecordMap.get(e.getSalaryAcctRecordId())) + .distinct() + .filter(e -> Objects.equals(e.getControlView(), 1)) + .collect(Collectors.toList()); + TaxDeclarationPO taxDeclaration = TaxDeclarationPO.builder() + .id(IdGenerator.generate()) + .taxDeclareRecordId(taxDeclareRecord.getId()) + .incomeCategory(Util.getIntValue(incomeCategoryEntry.getKey())) + .taxAgentId(taxDeclareRecord.getTaxAgentId()) + .salaryMonth(taxDeclareRecord.getSalaryMonth()) + .taxCycle(taxDeclareRecord.getTaxCycle()) + .remark(taxDeclareRecord.getRemark()) + .controlView(CollectionUtils.isEmpty(controlViewSalaryAcctRecords) ? 0 : 1) + .creator(employeeId) + .createTime(now) + .updateTime(now) + .deleteType(DeleteTypeEnum.NOT_DELETED.getValue()) + .tenantKey(tenantKey) + .build(); + taxDeclarations.add(taxDeclaration); + // 钖祫鏍哥畻缁撴灉 + Set salaryAcctEmployeeIdSet = SalaryEntityUtil.properties(incomeCategoryEntry.getValue(), SalaryAcctEmployeePO::getId); + List resultValues = salaryAcctEmployeeIdSet.stream() + .map(salaryAcctResultValueMap::get) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + TaxDeclareContext taxDeclareContext = new TaxDeclareContext() + .setSalaryAcctRecordMap(salaryAcctRecordMap) + .setSalaryAcctEmployees(incomeCategoryEntry.getValue()) + .setSalaryAcctResultValues(resultValues) + .setTaxDeclaration(taxDeclaration) + .setSalarySobTaxReportRuleMap(salarySobTaxReportRuleMap) + .setSalarySobAddUpRuleMap(salarySobAddUpRuleMap) + .setTaxReportColumns(taxReportColumnMap.get(incomeCategoryEntry.getKey())) + .setSalaryItems(salaryItems); + TaxDeclarationStrategy taxDeclarationStrategy = new TaxDeclarationCommon(); + TaxDeclarationGenerateResult generateResult = taxDeclarationStrategy.generate(taxDeclareContext, employeeId, tenantKey); + taxDeclarationValues.addAll(generateResult.getTaxDeclarationValues()); + addUpSituations.addAll(generateResult.getAddUpSituations()); + } + return new TaxDeclarationResult() + .setTaxDeclarations(taxDeclarations) + .setTaxDeclarationValues(taxDeclarationValues) + .setAddUpSituations(addUpSituations); + } + + /** + * 鏍¢獙鏄惁鍙互鐢熸垚涓◣鐢虫姤琛 + * + * @param saveParam + * @param taxAgentNameMap + * @param salaryAcctRecords + * @param salaryAcctTaxAgents + * @param tenantKey + */ + private List checkBeforeSave(TaxDeclarationSaveParam saveParam, + Map taxAgentNameMap, + List salaryAcctRecords, + List salaryAcctTaxAgents, + Long employeeId, String tenantKey) { + List resultList = Lists.newArrayList(); + // 濡傛灉瀛樺湪鏈綊妗g殑钖祫鏍哥畻璁板綍锛屼笉鍏佽鐢熸垚涓◣鐢虫姤琛 + boolean notArchived = salaryAcctRecords.stream() + .anyMatch(salaryAcctRecordPO -> Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())); + if (notArchived) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 98875, "{0}鏈夋湭褰掓。鏁版嵁锛岃鍏ㄩ儴褰掓。鍚庡啀鐢虫姤") + .replace("{0}", saveParam.getSalaryMonth().toString())); + } + // 鏌ヨ宸插綊妗g殑钖祫鏍哥畻璁板綍 + List archivedSalaryAcctRecords = salaryAcctRecords.stream() + .filter(salaryAcctRecordPO -> Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.ARCHIVED.getValue())) + .collect(Collectors.toList()); + // 鏃犲凡褰掓。鐨勮柂璧勬牳绠楄褰曪紝涓嶅厑璁哥敓鎴愪釜绋庣敵鎶ヨ〃 + if (CollectionUtils.isEmpty(archivedSalaryAcctRecords)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 177860, "{0}鏃犲彲鐢虫姤鏁版嵁") + .replace("{0}", saveParam.getSalaryMonth().toString())); + } + // 鏌ヨ宸插綊妗g殑钖祫鏍哥畻璁板綍鏄惁宸茬粡鐢熸垚杩囦釜绋庣敵鎶ヨ〃 + Map> taxCycleKeySalaryAcctTaxAgentMap = SalaryEntityUtil.group2Map(salaryAcctTaxAgents, SalaryAcctTaxAgentPO::getTaxCycle); + for (Map.Entry> taxCycleEntry : taxCycleKeySalaryAcctTaxAgentMap.entrySet()) { + Set archivedTaxAgentIds = SalaryEntityUtil.properties(taxCycleEntry.getValue(), SalaryAcctTaxAgentPO::getTaxAgentId); + List taxDeclareRecords = listBySalaryMonthAndTaxAgentIds(saveParam.getSalaryMonth(), archivedTaxAgentIds, tenantKey); + TaxDeclareRecordPO declareSuccessTaxDeclareRecord = taxDeclareRecords.stream() + .filter(taxDeclareRecordPO -> archivedTaxAgentIds.contains(taxDeclareRecordPO.getTaxAgentId()) + && !(Objects.equals(taxDeclareRecordPO.getTaxDeclareStatus(), TaxDeclareStatusEnum.NOT_DECLARE.getValue()) + || Objects.equals(taxDeclareRecordPO.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARE_FAIL.getValue()))) + .findAny() + .orElse(null); + // 宸茬粡鐢虫姤鎴愬姛浜嗙殑涓◣鐢虫姤琛ㄧ殑涓◣鎵g即涔夊姟浜轰笉鍏佽閲嶆柊鐢熸垚 + if (Objects.nonNull(declareSuccessTaxDeclareRecord)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 160522, "宸插紑鍚櫤鑳界畻钖笟鍔★紝涓◣鎵g即涔夊姟浜簕0}鐨勭◣娆炬墍灞炴湡{1}鐨勪釜绋庣敵鎶ヨ〃姝e湪鐢虫姤涓垨鑰呭凡缁忕敵鎶ユ垚鍔燂紝涓嶅彲閲嶅鐢熸垚") + .replace("{0}", taxAgentNameMap.get(declareSuccessTaxDeclareRecord.getTaxAgentId())) + .replace("{1}", declareSuccessTaxDeclareRecord.getTaxCycle())); + } + resultList.addAll(taxDeclareRecords); + } + return resultList; + } + + /** + * 鏍规嵁涓◣鎵g即涔夊姟浜鸿寖鍥存煡璇釜绋庢墸缂翠箟鍔′汉 + * + * @param saveParam + * @param employeeId + * @param tenantKey + * @return + */ + private List queryByTaxAgentRange(TaxDeclarationSaveParam saveParam, Long employeeId, String tenantKey) { + List taxAgents; + if (saveParam.getTaxAgentRange() == TaxAgentRangeEnum.ALL_TAX_AGENT) { + // 鍒ゆ柇褰撳墠鏄惁寮鍚簡鍒嗘潈 + Boolean openDevolution = taxAgentService.isOpenDevolution(tenantKey); + // 鍒ゆ柇鏄惁鏄荤鐞嗗憳 + Boolean isChief = taxAgentService.isChief(employeeId, tenantKey); + if (openDevolution && !isChief) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 160523, "瀵逛笉璧凤紝鎮ㄤ笉鏄柂閰ā鍧楃殑鎬荤鐞嗗憳锛屼笉鍏峰鐢熸垚鎵鏈変釜绋庢墸缂翠箟鍔′汉鐨勬潈闄")); + } + taxAgents = taxAgentService.listAll(tenantKey); + } else if (saveParam.getTaxAgentRange() == TaxAgentRangeEnum.ADMIN_TAX_AGENT) { + taxAgents = taxAgentService.listAllTaxAgentsAsAdmin(employeeId, tenantKey); + } else { + taxAgents = taxAgentService.listByIds(saveParam.getTaxAgentIds(), tenantKey); + } + return taxAgents; + } + + @Override + public void updateIcon(Long id, Integer displayIcon, Long employeeId, String tenantKey) { + TaxDeclareRecordPO taxDeclareRecord = getById(id, tenantKey); + if (taxDeclareRecord == null) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 84026, "鍙傛暟閿欒")); + } + taxDeclareRecord.setDisplayUpdateIcon(displayIcon); + taxDeclareRecord.setUpdateTime(LocalDateTime.now()); + updateById(taxDeclareRecord); + } + + @Override + public void updateByTaxCycleAndTaxAgentIds(YearMonth taxCycle, Collection taxAgentIds, String tenantKey) { + if (Objects.isNull(taxCycle) || CollectionUtils.isEmpty(taxAgentIds)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "鍙傛暟閿欒")); + } + List taxDeclareRecords = listByTaxCycleAndTaxAgentIds(taxCycle, taxAgentIds, tenantKey); + if (CollectionUtils.isEmpty(taxDeclareRecords)) { + return; + } + LocalDateTime now = LocalDateTime.now(); + taxDeclareRecords.forEach(e -> e.setDisplayUpdateIcon(1).setUpdateTime(now)); + updateBatchById(taxDeclareRecords); + } + + @Override + public boolean checkByAuthority(TaxDeclarationPO taxDeclaration, Long employeeId, String tenantKey) { + // 鍒ゆ柇鏄惁浠呮湰浜哄彲瑙 + if (Objects.equals(taxDeclaration.getControlView(), 1) && !Objects.equals(taxDeclaration.getCreator(), employeeId)) { + return false; + } + // 鍒ゆ柇鏄惁寮鍚簡鍒嗘潈 + Boolean openDevolution = taxAgentService.isOpenDevolution(tenantKey); + // 鍒ゆ柇鏄惁鏄荤鐞嗗憳 + Boolean isChief = taxAgentService.isChief(employeeId, tenantKey); + // 鍙鑼冨洿鍐呯殑涓◣鎵g即涔夊姟浜 + List taxAgents = Lists.newArrayList(); + if (openDevolution) { + if (isChief) { + taxAgents = taxAgentService.listAsChief(true, true, employeeId, tenantKey); + } else { + taxAgents = taxAgentService.listAllTaxAgentsAsAdmin(employeeId, tenantKey); + } + if (CollectionUtils.isEmpty(taxAgents)) { + return false; + } + Set taxAgentIds = SalaryEntityUtil.properties(taxAgents, TaxAgentPO::getId); + return taxAgentIds.contains(taxDeclaration.getTaxAgentId()); + } + // 鏌ヨ涓◣鐢虫姤琛 + return true; + } + + @Override + public void deleteByIds(Collection ids, String tenantKey) { + if (CollectionUtils.isEmpty(ids)) { + return; + } + List taxDeclareRecords = listByIds(ids, tenantKey); + if (CollectionUtils.isEmpty(taxDeclareRecords)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(160524, "涓◣鐢虫姤琛ㄤ笉瀛樺湪鎴栧凡琚垹闄")); + } + List cantDeleteTaxDeclareRecords = taxDeclareRecords.stream() + .filter(e -> !(Objects.equals(e.getTaxDeclareType(), TaxDeclareTypeEnum.NORMAL_DECLARE.getValue()) + && Objects.equals(e.getTaxDeclareStatus(), TaxDeclareStatusEnum.NOT_DECLARE.getValue()))) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(cantDeleteTaxDeclareRecords)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(177854, "涓◣鐢虫姤琛ㄥ凡缁忕敵鎶ワ紝鏃犳硶鍒犻櫎")); + } + new LambdaUpdateChainWrapper<>(taxDeclareRecordMapper) + .eq(TaxDeclareRecordPO::getTenantKey, tenantKey) + .eq(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue()) + .in(TaxDeclareRecordPO::getId, ids) + .set(TaxDeclareRecordPO::getDeleteType, DeleteTypeEnum.DELETED.getValue()) + .update(); + // 鍒犻櫎涓◣鐢虫姤琛 + taxDeclarationService.deleteByTaxDeclareRecordIds(ids, tenantKey); + // 鍒犻櫎涓◣鐢虫姤琛ㄦ槑缁 + taxDeclarationValueService.deleteByTaxDeclareRecordIds(ids, tenantKey); + // 璁板綍鏃ュ織 + writeDeleteLog(taxDeclareRecords, tenantKey); + } + + private void writeDeleteLog(List taxDeclareRecords, String tenantKey) { + // 璁板綍鏃ュ織 + List taxAgents = taxAgentService.listByIds(SalaryEntityUtil.properties(taxDeclareRecords, TaxDeclareRecordPO::getTaxAgentId), tenantKey); + Map taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getId, TaxAgentPO::getName); + for (TaxDeclareRecordPO taxDeclareRecord : taxDeclareRecords) { + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); + loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") + .replace("{0}", taxAgentNameMap.getOrDefault(taxDeclareRecord.getTaxAgentId(), com.baomidou.mybatisplus.core.toolkit.StringUtils.EMPTY)) + .replace("{1}", taxDeclareRecord.getTaxCycle())); + loggerContext.setOperateType(OperateTypeEnum.DELETE.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(156453, "鍒犻櫎涓◣鐢虫姤琛")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(156453, "鍒犻櫎涓◣鐢虫姤琛")); + taxDeclarationLoggerTemplate.write(loggerContext); + } + } + + @Override + public void declare(Long id, Long employeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, employeeId, tenantKey); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + if (StringUtils.isNotEmpty(taxDeclareRecord.getRequestId()) && Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARING.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 160526, "鐩墠姝e浜庣敵鎶ヤ腑锛岃绋嶅悗鐗囧埢鍐嶇偣鍑汇岀敵鎶ュ弽棣堛嶈幏鍙栫粨鏋")); + } + if (StringUtils.isNotEmpty(taxDeclareRecord.getRequestId()) && Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARE_CANCELLING.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 160527, "鐩墠姝e浜庝綔搴熺敵鎶ヤ腑锛岃绋嶅悗鐗囧埢鍐嶇偣鍑汇屼綔搴熷弽棣堛嶈幏鍙栫粨鏋")); + } + + // 鏌ヨ涓◣鐢虫姤琛 + List taxDeclarations = taxDeclarationService.listByTaxCycleAndTaxAgentIds(YearMonth.parse(taxDeclareRecord.getTaxCycle()), + Collections.singleton(taxDeclareRecord.getTaxAgentId()), tenantKey); + if (CollectionUtils.isEmpty(taxDeclarations)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156494, "褰撳墠鏃犲彲鐢虫姤鐨勬暟鎹")); + } + AbnormalEmployeeListQueryParam queryParam = new AbnormalEmployeeListQueryParam() + .setTaxDeclareRecordId(taxDeclareRecord.getId()) + .setTaxAgentId(taxDeclareRecord.getTaxAgentId()) + .setTaxCycle(taxDeclareRecord.getTaxCycle()); + // 鏌ヨ鏄惁瀛樺湪鏈夋湭鎶ラ佺殑浜 + List notDeclareTaxDeclareEmployees = taxDeclareEmployeeService.list4NotDeclareByParam(queryParam, tenantKey); + if (CollectionUtils.isNotEmpty(notDeclareTaxDeclareEmployees)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 162125, "瀛樺湪鏈夋湭鎶ラ佺殑浜猴紝璇峰厛鎶ラ佺浉鍏充汉鍛樺悗鍐嶇敵鎶ヤ釜绋")); + } + // 鏌ヨ鏄惁瀛樺湪娌℃湁鐢虫姤鏁版嵁鐨勪汉 + List noValueTaxDeclareEmployees = taxDeclareEmployeeService.list4NoValueByParam(queryParam, tenantKey); + if (CollectionUtils.isNotEmpty(noValueTaxDeclareEmployees)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 160535, "瀛樺湪娌℃湁鐢虫姤鏁版嵁鐨勪汉锛岃閲嶆柊鏍哥畻杩欎簺浜虹殑钖祫鍚庡啀鏉ョ敵鎶ヤ釜绋")); + } + // 鏌ヨ涓◣鐢虫姤琛ㄧ殑鐢虫姤鏁版嵁 + Set taxDeclarationIds = SalaryEntityUtil.properties(taxDeclarations, TaxDeclarationPO::getId); + List taxDeclarationValues = taxDeclarationValueService.listByTaxDeclarationIds(taxDeclarationIds, tenantKey); + // 鏌ヨ鏈◣娆炬墍灞炴湡鍐呮姤閫佹垚鍔熺殑浜哄憳 + List employeeDeclares = employeeDeclareService.listByTaxCycleAndTaxAgentId(YearMonth.parse(taxDeclareRecord.getTaxCycle()), + taxDeclareRecord.getTaxAgentId(), tenantKey); + employeeDeclares = employeeDeclares.stream() + .filter(e -> Objects.equals(e.getDeclareStatus(), DeclareStatusEnum.DECLARE_SUCCESS.getValue())) + .collect(Collectors.toList()); + + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + // 鏌ヨ涓◣鐢虫姤琛ㄧ殑琛ㄥご + List taxReportColumns = taxReportColumnService.listAll(tenantKey); + // 娉ㄥ唽鐨勪紒涓氫俊鎭-->璇锋眰鍙傛暟 + Map requestParam = taxDeclareRequest.getRequestParam(); + // 绋庢鎵灞炴湡 + requestParam.put("skssq", taxDeclareRecord.getTaxCycle().replace("-", "")); + // 浜哄憳鍒楄〃 + List> employeeDeclareParam = EmployeeDeclareRequest.convert2RequestParam(employeeDeclares); + requestParam.put("rylb", employeeDeclareParam); + // 缁煎悎鎵寰 + Map taxDeclarationParam = TaxDeclarationRequest.convert2RequestParam(taxReportColumns, taxDeclarations, taxDeclarationValues, employeeDeclares); + requestParam.put("zhsd", taxDeclarationParam); + String reqJson = JsonUtil.toJsonString(requestParam); + String url = apiConfig.getHost() + SzyhApiConstant.DECLARE_TAX; + Map params = new HashMap<>(1); + Map header = SingnatureData.initHeader(params, apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.doPost(url, header, reqJson, HttpUtil.JSON_TYPE); + log.info("涓◣鐢虫姤杩斿洖鏁版嵁: {} , taxDeclareRecord: {}", res, taxDeclareRecord); + DeclareTaxResponse declareTaxResponse = JsonUtil.parseObject(res, DeclareTaxResponse.class); + if (Objects.isNull(declareTaxResponse) || Objects.isNull(declareTaxResponse.getHead())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156449, "鏈嶅姟寮傚父")); + } + if (!Objects.equals(declareTaxResponse.getHead().getCode(), SzyhApiConstant.SUCCESS_CODE)) { + throw new SalaryRunTimeException(declareTaxResponse.getHead().getMsg()); + } + // 鏇存柊涓◣鐢虫姤璁板綍 + taxDeclareRecord.setTaxDeclareStatus(TaxDeclareStatusEnum.DECLARING.getValue()); + taxDeclareRecord.setRequestId(declareTaxResponse.getBody().getRequestId()); + taxDeclareRecord.setUpdateTime(LocalDateTime.now()); + taxDeclareRecordMapper.updateById(taxDeclareRecord); + // 鍒犻櫎涓◣鐢虫姤鐢虫姤澶辫触鐨勬暟鎹 + taxDeclareFailService.deleteByTaxDeclareRecordIds(Collections.singleton(taxDeclareRecord.getId()), tenantKey); + + // 璁板綍鏃ュ織 + TaxAgentPO taxAgent = taxDeclareRequest.getTaxAgent(); + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); + loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") + .replace("{0}", taxAgent.getName()) + .replace("{1}", taxDeclareRecord.getTaxCycle())); + loggerContext.setOperator(Util.null2String(employeeId)); + loggerContext.setOperateType(OperateTypeEnum.ADD.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156454, "鍦ㄧ嚎鐢虫姤")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156454, "鍦ㄧ嚎鐢虫姤")); + taxDeclarationLoggerTemplate.write(loggerContext); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void getDeclareFeedback(Long id, TaxDeclarationRateDTO taxDeclarationRate, Long currentEmployeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, currentEmployeeId, tenantKey); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + if (StringUtils.isEmpty(taxDeclareRecord.getRequestId()) || !Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARING.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 156496, "璇峰厛鐐瑰嚮銆屽湪绾跨敵鎶ャ嶅悗鍐嶇偣鍑汇岀敵鎶ュ弽棣堛嶈幏鍙栫敵鎶ョ粨鏋")); + } + + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + String url = apiConfig.getHost() + SzyhApiConstant.DECLARE_TAX_FEEDBACK; + Map requestParam = ImmutableMap.of("requestId", taxDeclareRecord.getRequestId(), "reportType", "1"); + Map header = SingnatureData.initHeader(Collections.emptyMap(), apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.getRequest(url, header, requestParam); + log.info("鐢虫姤鍙嶉杩斿洖鏁版嵁: {}, taxDeclareRecord: {}", res, JsonUtil.toJsonString(taxDeclareRecord)); + DeclareTaxFeedbackResponse declareTaxFeedbackResponse = JsonUtil.parseObject(res, DeclareTaxFeedbackResponse.class); + if (Objects.isNull(declareTaxFeedbackResponse) || Objects.isNull(declareTaxFeedbackResponse.getHead())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 156449, "鏈嶅姟寮傚父")); + } + if (!Objects.equals(declareTaxFeedbackResponse.getHead().getCode(), SzyhApiConstant.SUCCESS_CODE)) { + throw new SalaryRunTimeException(declareTaxFeedbackResponse.getHead().getMsg()); + } + // 鐢虫姤鍙嶉鐘舵 + Integer declareFeedbackStatus = SalaryEntityUtil.getIntValue(declareTaxFeedbackResponse.getBody().get("fkztbj"), 0); + DeclareFeedBackStatusEnum declareFeedBackStatusEnum = SalaryEnumUtil.enumMatchByValue(declareFeedbackStatus, DeclareFeedBackStatusEnum.class); + if (declareFeedBackStatusEnum == null) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 156509, "鏈嶅姟寮傚父锛屾帴鍙h繑鍥炴暟鎹湁璇")); + } + // 鏌ヨ鎶ラ佺殑浜哄憳 + List employeeDeclares = employeeDeclareService.listByTaxCycleAndTaxAgentId(YearMonth.parse(taxDeclareRecord.getTaxCycle()), + taxDeclareRecord.getTaxAgentId(), tenantKey); + Map employeeInfoMap = SalaryEntityUtil.convert2Map(employeeDeclares, + e -> e.getEmployeeName() + "-" + e.getCardNum()); + // 娴侀噺缁熻 + TaxDeclarationApiBillingServiceImpl.ApiFlowUpdateWrapper apiFlowUpdateWrapper + = new TaxDeclarationApiBillingServiceImpl.ApiFlowUpdateWrapper(tenantKey, currentEmployeeId + , LocalDate.parse(taxDeclareRecord.getTaxCycle() + "-01", SalaryDateUtil.DATE_FORMATTER) + , apiConfig, EnumDeclareApiBusinessType.TAX_DECLARATION); + + LocalDateTime now = LocalDateTime.now(); + List errorMsg = Lists.newArrayList(); + List taxDeclareFails = Lists.newArrayList(); + if (declareFeedBackStatusEnum == DeclareFeedBackStatusEnum.DECLARE_FAIL) { + List failInfoList = JsonUtil.parseList(Util.null2String(declareTaxFeedbackResponse.getBody().getOrDefault("fknr", "")).replace("\\\"", "\""), Map.class); + for (Map map : failInfoList) { + String msg = Util.null2String(map.get("msg")); + if (StringUtils.isNotEmpty(msg)) { + errorMsg.add(msg); + } + List details = JsonUtil.parseList(map.get("details"), List.class); + for (List detail : CollectionUtils.emptyIfNull(details)) { + String employeeName = Util.null2String(detail.get(0)); + String cardNum = Util.null2String(detail.get(2)); + String incomeCategoryCode = Util.null2String(detail.get(4)); + TaxDeclareFailPO taxDeclareFailPO = new TaxDeclareFailPO() + .setId(IdGenerator.generate()) + .setTaxDeclareRecordId(taxDeclareRecord.getId()) + .setEmployeeName(employeeName) + .setCardNum(cardNum) + .setIncomeCategory(incomeCategoryCode) + .setErrorMsg(msg) + .setTenantKey(tenantKey) + .setCreator(currentEmployeeId) + .setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()) + .setCreateTime(now) + .setUpdateTime(now); + taxDeclareFails.add(taxDeclareFailPO); + // 娴侀噺浣跨敤璁板綍 + EmployeeDeclarePO employeeDeclarePO = employeeInfoMap.get(employeeName + "-" + cardNum); + if (Objects.isNull(employeeDeclarePO)) { + continue; + } + TaxDeclarationApiFlowRecordPO flowDetailPO = TaxApiFlowBO.buildTaxDeclarationApiFlowRecordPO(apiFlowUpdateWrapper, taxDeclareRecord.getTaxAgentId(), employeeDeclarePO.getEmployeeId()); + flowDetailPO.setResultStatus(TaxAgentTaxReturnStatusEnum.FAIL.getValue()); + apiFlowUpdateWrapper.getApiFlowDetailPOList().add(flowDetailPO); + employeeInfoMap.remove(employeeName + "-" + cardNum); + } + } + taxDeclareRecord.setTaxDeclareErrorMsg(String.join(",", errorMsg)); + } + // 鐢虫姤鐘舵 + Integer declareStatus = SalaryEntityUtil.getIntValue(declareTaxFeedbackResponse.getBody().get("sbztbj"), 0); + TaxDeclareStatusEnum taxDeclareStatusEnum = SalaryEnumUtil.enumMatchByValue(declareStatus, TaxDeclareStatusEnum.class); + if (taxDeclareStatusEnum == null) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 156509, "鏈嶅姟寮傚父锛屾帴鍙h繑鍥炴暟鎹湁璇")); + } + // 涓哄鐞嗗紓甯告儏鍐碉紝濡傛灉鍙嶉鐘舵佷负鐢虫姤澶辫触锛屽垯璁板綍鐢虫姤鐘舵佷篃涓虹敵鎶ュけ璐 + if (declareFeedBackStatusEnum == DeclareFeedBackStatusEnum.DECLARE_FAIL) { + taxDeclareStatusEnum = TaxDeclareStatusEnum.DECLARE_FAIL; + } + taxDeclareRecord.setTaxDeclareStatus(taxDeclareStatusEnum.getValue()); + // 鐢虫姤绫诲瀷 + taxDeclareRecord.setTaxPayAmount(Util.null2String(declareTaxFeedbackResponse.getBody().get("ykjse"))); + taxDeclareRecord.setPersonNum(Integer.parseInt(Optional.ofNullable(declareTaxFeedbackResponse.getBody().get("nsrc")).orElse("0").toString())); + taxDeclareRecord.setRequestId(""); + taxDeclareRecord.setUpdateTime(LocalDateTime.now()); + BigDecimal purePaidAmount = SalaryEntityUtil.empty2Zero(taxDeclareRecord.getTaxPurePaidAmount()); + BigDecimal payAmount = SalaryEntityUtil.empty2Zero(taxDeclareRecord.getTaxPayAmount()); + if (TaxDeclareStatusEnum.DECLARE_SUCCESS_PAID.equals(taxDeclareStatusEnum) + || TaxDeclareStatusEnum.DECLARE_SUCCESS_NO_PAY.equals(taxDeclareStatusEnum)) { + // 濡傛灉鏄凡缂寸撼鐘舵侊紝鍒欐洿鏂板凡缂寸撼閲戦锛屽垽鏂槸鍚﹂渶瑕佺嚎涓嬮绋 + if (purePaidAmount.compareTo(payAmount) > 0) { + taxDeclareRecord.setTaxPayAmount(payAmount.subtract(purePaidAmount).toString()); + BigDecimal paidAmount = SalaryEntityUtil.empty2Zero(taxDeclareRecord.getTaxPaidAmount()); + taxDeclarationRate.setMsg(String.format(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 183789, "搴旂即绋庨锛堜笉鍚粸绾抽噾绛夛級锛%s鍏冿紝宸茬即閲戦锛堝彲鑳藉惈婊炵撼閲戠瓑锛夛細%s鍏冿紝褰撳墠宸茬即娆鹃噾棰濆ぇ浜庡簲缂寸撼閲戦锛岃绾夸笅鍓嶅線鍔炵◣澶у巺鍔炵悊閫娆俱"), payAmount, paidAmount)); + taxDeclarationRate.setMsgPersist(true); + } else if (purePaidAmount.compareTo(payAmount) == 0) { + taxDeclareRecord.setTaxPayAmount(BigDecimal.ZERO.toString()); + } else { + throw new SalaryRunTimeException("缂存鏁版嵁寮傚父锛岃澶勭悊鍚庨噸璇"); + } + } else if (TaxDeclareStatusEnum.DECLARE_SUCCESS_UNPAID.equals(taxDeclareStatusEnum)) { + // 濡傛灉涓嶆槸宸茬即绾崇姸鎬侊紝鍒欏噺鎺変箣鍓嶇殑宸茬即绾抽噾棰濆幓鏇存柊搴旂即绾抽噾棰 + taxDeclareRecord.setTaxPayAmount(payAmount.subtract(purePaidAmount).toString()); + } + // 鏇存柊涓◣鐢虫姤璁板綍 + taxDeclareRecordMapper.updateById(taxDeclareRecord); + // 濡傛灉鐢虫姤澶辫触 + if (CollectionUtils.isNotEmpty(taxDeclareFails)) { + taxDeclareFailService.saveBatch(taxDeclareFails); + } + // 鏇存柊娴侀噺浣跨敤璁板綍 + employeeInfoMap.forEach((key, value) -> { + TaxDeclarationApiFlowRecordPO flowDetailPO = TaxApiFlowBO.buildTaxDeclarationApiFlowRecordPO(apiFlowUpdateWrapper, taxDeclareRecord.getTaxAgentId(), value.getEmployeeId()); + flowDetailPO.setResultStatus(TaxAgentTaxReturnStatusEnum.SUCCESS.getValue()); + apiFlowUpdateWrapper.getApiFlowDetailPOList().add(flowDetailPO); + }); + taxDeclarationApiBillingService.updateApiFlowInfo(apiFlowUpdateWrapper); + + // 璁板綍鏃ュ織 + TaxAgentPO taxAgent = taxDeclareRequest.getTaxAgent(); + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); + loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") + .replace("{0}", taxAgent.getName()) + .replace("{1}", taxDeclareRecord.getTaxCycle())); + loggerContext.setOperator(Util.null2String(currentEmployeeId)); + loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 156455, "鐢虫姤鍙嶉")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 156455, "鐢虫姤鍙嶉")); + taxDeclarationLoggerTemplate.write(loggerContext); + } + + @Override + public void cancelDeclare(Long id, Long employeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, employeeId, tenantKey); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + // 鏇存鐢虫姤鎴愬姛鍚庝笉鑳戒綔搴 + if (Objects.equals(taxDeclareRecord.getTaxDeclareType(), TaxDeclareTypeEnum.UPDATE_DECLARE.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 182701, "鏇存鐢虫姤鍚庝笉鍏佽浣滃簾")); + } + // 鍙湁鐢虫姤鎴愬姛锛屾棤闇缂存/鐢虫姤鎴愬姛锛屾湭缂存鐨勭姸鎬佹墠鑳戒綔搴 + if (!Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARE_SUCCESS_NO_PAY.getValue()) + && !Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARE_SUCCESS_UNPAID.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156497, "鍙湁鐢虫姤鎴愬姛锛屾棤闇缂存/鐢虫姤鎴愬姛锛屾湭缂存鐨勭姸鎬佹墠鑳戒綔搴")); + } + // 渚涘簲鍟嗕俊鎭 + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + // 娉ㄥ唽鐨勪紒涓氫俊鎭-->璇锋眰鍙傛暟 + Map requestParam = taxDeclareRequest.getRequestParam(); + // 绋庢鎵灞炴湡 + requestParam.put("skssq", taxDeclareRecord.getTaxCycle().replace("-", "")); + // 鐢虫姤绫诲瀷 + requestParam.put("sblx", "1"); + // 浣滃簾閾惰仈缂存鍑瘉 + taxPaymentServiceFactory.get(TaxPaymentServiceTypeEnum.WITHHOLDING_VOUCHER.getValue()).cancelWithholdingVoucher(employeeId, tenantKey, apiConfig, taxDeclareRecord, requestParam); + // 鏄惁娓呯┖鎵寰 + requestParam.put("sfqksd", "0"); + // 璇锋眰 + String reqJson = JsonUtil.toJsonString(requestParam); + String url = apiConfig.getHost() + SzyhApiConstant.CANCEL_DECLARE; + Map params = new HashMap<>(1); + Map header = SingnatureData.initHeader(params, apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.doPost(url, header, reqJson, HttpUtil.JSON_TYPE); + log.info("浣滃簾鐢虫姤杩斿洖鏁版嵁锛" + res); + DeclareTaxResponse declareTaxResponse = JsonUtil.parseObject(res, DeclareTaxResponse.class); + if (Objects.isNull(declareTaxResponse) || Objects.isNull(declareTaxResponse.getHead())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156449, "鏈嶅姟寮傚父")); + } + if (!Objects.equals(declareTaxResponse.getHead().getCode(), SzyhApiConstant.SUCCESS_CODE)) { + throw new SalaryRunTimeException(declareTaxResponse.getHead().getMsg()); + } + // 鏇存柊涓◣鐢虫姤璁板綍 + taxDeclareRecord.setTaxDeclareStatus(TaxDeclareStatusEnum.DECLARE_CANCELLING.getValue()); + taxDeclareRecord.setRequestId(declareTaxResponse.getBody().getRequestId()); + taxDeclareRecord.setUpdateTime(LocalDateTime.now()); + taxDeclareRecordMapper.updateById(taxDeclareRecord); + + // 璁板綍鏃ュ織 + TaxAgentPO taxAgent = taxDeclareRequest.getTaxAgent(); + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); + loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") + .replace("{0}", taxAgent.getName()) + .replace("{1}", taxDeclareRecord.getTaxCycle())); + loggerContext.setOperator(Util.null2String(employeeId)); + loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156456, "鐢虫姤浣滃簾")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156456, "鐢虫姤浣滃簾")); + taxDeclarationLoggerTemplate.write(loggerContext); + } + + @Override + public void getCancelFeedback(Long id, TaxDeclarationRateDTO taxDeclarationRate, Long employeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, employeeId, tenantKey); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + if (!Objects.equals(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.DECLARE_CANCELLING.getValue()) + || StringUtils.isEmpty(taxDeclareRecord.getRequestId())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156500, "璇峰厛鐐瑰嚮銆屼綔搴熺敵鎶ャ嶅悗鍐嶆潵鐐瑰嚮銆岀敵鎶ュ弽棣堛嶆寜閽幏鍙栫粨鏋")); + } + // 渚涘簲鍟嗕俊鎭 + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + String url = apiConfig.getHost() + SzyhApiConstant.CANCEL_DECLARE_FEEDBACK; + Map requestParam = ImmutableMap.of("requestId", taxDeclareRecord.getRequestId(), "reportType", "1"); + Map header = SingnatureData.initHeader(Collections.emptyMap(), apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.getRequest(url, header, requestParam); + log.info("浣滃簾鍙嶉杩斿洖鏁版嵁锛" + res); + CancelDeclareFeedbackResponse cancelDeclareFeedbackResponse = JsonUtil.parseObject(res, CancelDeclareFeedbackResponse.class); + if (Objects.isNull(cancelDeclareFeedbackResponse) || Objects.isNull(cancelDeclareFeedbackResponse.getHead())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156449, "鏈嶅姟寮傚父")); + } + if (!Objects.equals(cancelDeclareFeedbackResponse.getHead().getCode(), SzyhApiConstant.SUCCESS_CODE)) { + throw new SalaryRunTimeException(cancelDeclareFeedbackResponse.getHead().getMsg()); + } + // 浣滃簾鏄惁鎴愬姛 + CancelDeclareStatusEnum cancelDeclareStatusEnum = SalaryEnumUtil.enumMatchByValue( + SalaryEntityUtil.getIntValue(cancelDeclareFeedbackResponse.getBody().get("fkztbj"), 10), CancelDeclareStatusEnum.class); + if (cancelDeclareStatusEnum == CancelDeclareStatusEnum.CANCEL_FAIL) { + String feedbackBody = Util.null2String(cancelDeclareFeedbackResponse.getBody().get("fknr")).replace("\\", ""); + List errorMsgList = JsonUtil.parseList(feedbackBody, Map.class).stream() + .map(e -> Util.null2String(e.get("msg"))) + .collect(Collectors.toList()); + taxDeclarationRate.setStatus(false).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156508, "浣滃簾澶辫触锛") + StringUtils.join(errorMsgList, ",")); + } + TaxDeclareStatusEnum taxDeclareStatusEnum = SalaryEnumUtil.enumMatchByValue( + SalaryEntityUtil.getIntValue(cancelDeclareFeedbackResponse.getBody().get("sbztbj"), 1), TaxDeclareStatusEnum.class); + if (taxDeclareStatusEnum == null) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156509, "鏈嶅姟寮傚父锛屾帴鍙h繑鍥炴暟鎹湁璇")); + } + taxDeclareRecord.setTaxDeclareStatus(taxDeclareStatusEnum.getValue()); + taxDeclareRecord.setRequestId(""); + taxDeclareRecord.setUpdateTime(LocalDateTime.now()); + taxDeclareRecordMapper.updateById(taxDeclareRecord); + + // 璁板綍鏃ュ織 + TaxAgentPO taxAgent = taxDeclareRequest.getTaxAgent(); + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); + loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") + .replace("{0}", taxAgent.getName()) + .replace("{1}", taxDeclareRecord.getTaxCycle())); + loggerContext.setOperator(Util.null2String(employeeId)); + loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156457, "鑾峰彇鐢虫姤浣滃簾鐨勫弽棣")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156457, "鑾峰彇鐢虫姤浣滃簾鐨勫弽棣")); + taxDeclarationLoggerTemplate.write(loggerContext); + } + + @Override + public void updateDeclare(Long id, Long employeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, employeeId, tenantKey); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + List taxDeclareStatusEnumValueList = Lists.newArrayList( + TaxDeclareStatusEnum.DECLARE_SUCCESS_UNPAID.getValue(), + TaxDeclareStatusEnum.DECLARE_SUCCESS_NO_PAY.getValue(), + TaxDeclareStatusEnum.DECLARE_SUCCESS_PAID.getValue(), + TaxDeclareStatusEnum.DECLARE_SUCCESS_PAYING.getValue()); + if (!taxDeclareStatusEnumValueList.contains(taxDeclareRecord.getTaxDeclareStatus())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 182702, "瀵逛笉璧凤紝鍙湁鐢虫姤鎴愬姛鍚庢墠鍏佽鏇存鐢虫姤")); + } + // 渚涘簲鍟嗕俊鎭 + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + // 娉ㄥ唽鐨勪紒涓氫俊鎭-->璇锋眰鍙傛暟 + Map requestParam = taxDeclareRequest.getRequestParam(); + // 绋庢鎵灞炴湡 + requestParam.put("skssq", taxDeclareRecord.getTaxCycle().replace("-", "")); + // 鐢虫姤绫诲瀷 + requestParam.put("sblx", "1"); + // 璇锋眰 + String reqJson = JsonUtil.toJsonString(requestParam); + log.info("鏇存鐢虫姤璇锋眰鏁版嵁锛" + reqJson); + String url = apiConfig.getHost() + SzyhApiConstant.UPDATE_DECLARE; + Map params = new HashMap<>(1); + Map header = SingnatureData.initHeader(params, apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.doPost(url, header, reqJson, HttpUtil.JSON_TYPE); + log.info("鏇存鐢虫姤杩斿洖鏁版嵁锛" + res); + UpdateDeclareResponse updateDeclareResponse = JsonUtil.parseObject(res, UpdateDeclareResponse.class); + if (Objects.isNull(updateDeclareResponse) || Objects.isNull(updateDeclareResponse.getHead())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156449, "鏈嶅姟寮傚父")); + } + if (!Objects.equals(updateDeclareResponse.getHead().getCode(), SzyhApiConstant.SUCCESS_CODE)) { + throw new SalaryRunTimeException(updateDeclareResponse.getHead().getMsg()); + } + taxDeclareRecord.setTaxDeclareType(TaxDeclareTypeEnum.UPDATE_DECLARE.getValue()); + taxDeclareRecord.setTaxDeclareStatus(TaxDeclareStatusEnum.NOT_DECLARE.getValue()); + taxDeclareRecord.setRequestId(""); + taxDeclareRecord.setUpdateTime(LocalDateTime.now()); + updateById(taxDeclareRecord); + + // 璁板綍鏃ュ織 + TaxAgentPO taxAgent = taxDeclareRequest.getTaxAgent(); + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setTargetId(String.valueOf(taxDeclareRecord.getId())); + loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 203562, "涓◣鎵g即涔夊姟浜恒寋0}銆嶇◣娆炬墍灞炴湡銆寋1}銆") + .replace("{0}", taxAgent.getName()) + .replace("{1}", taxDeclareRecord.getTaxCycle())); + loggerContext.setOperator(Util.null2String(employeeId)); + loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 177637, "鏇存鐢虫姤")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 177637, "鏇存鐢虫姤")); + taxDeclarationLoggerTemplate.write(loggerContext); + } + + @Override + public String queryDeclareStatus(Long id, Long employeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, employeeId, tenantKey); + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + Map requestParam = taxDeclareRequest.getRequestParam(); + // 绋庢鎵灞炴湡 + requestParam.put("skssq", taxDeclareRecord.getTaxCycle().replace("-", "")); + // 鐢虫姤绫诲瀷 + requestParam.put("sblx", "1"); + // 璇锋眰 + String reqJson = JsonUtil.toJsonString(requestParam); + String url = apiConfig.getHost() + SzyhApiConstant.QUERY_DECLARE_STATUS; + Map params = new HashMap<>(1); + Map header = SingnatureData.initHeader(params, apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.doPost(url, header, reqJson, HttpUtil.JSON_TYPE); + log.info("绋庡眬绔敵鎶ョ姸鎬佹煡璇㈣繑鍥炴暟鎹細" + res); + return res; + } + + @Override + public String queryCompanyIncomes(Long id, Long employeeId, String tenantKey) { + TaxDeclareRequest taxDeclareRequest = buildTaxDeclareRequest(id, employeeId, tenantKey); + TaxDeclarationApiConfigPO apiConfig = taxDeclareRequest.getTaxDeclarationApiConfig(); + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRequest.getTaxDeclareRecord(); + Map requestParam = taxDeclareRequest.getRequestParam(); + // 绋庢鎵灞炴湡 + requestParam.put("skssq", taxDeclareRecord.getTaxCycle().replace("-", "")); + // 鎶ヨ〃绫诲瀷 + requestParam.put("reportType", "1"); + // 椤电爜 + requestParam.put("pageNo", "1"); + // 姣忛〉鏁伴噺 + requestParam.put("pageSize", "3000"); + // 璇锋眰 + String reqJson = JsonUtil.toJsonString(requestParam); + String url = apiConfig.getHost() + SzyhApiConstant.QUERY_COMPANY_INCOMES; + Map params = new HashMap<>(1); + Map header = SingnatureData.initHeader(params, apiConfig.getAppKey(), apiConfig.getAppSecret()); + String res = HttpUtil.doPost(url, header, reqJson, HttpUtil.JSON_TYPE); + log.info("绋庡眬绔敵鎶ユ槑缁嗘煡璇㈣繑鍥炴暟鎹細" + res); + return res; + } + + private TaxDeclareRequest buildTaxDeclareRequest(Long id, Long employeeId, String tenantKey) { + // 鏌ヨ渚涘簲鍟嗕俊鎭 + TaxDeclarationApiConfigPO apiConfig = taxDeclarationApiConfigService.getConfig(tenantKey, employeeId, true); + if (apiConfig == null) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 160525, "鎺ュ彛娴侀噺涓嶈冻锛屾殏鏃犳硶浣跨敤璇ュ姛鑳斤紝璇峰厛璐拱鏅鸿兘绠楄柂鎺ュ彛娴侀噺")); + } + // 鏌ヨ涓◣鐢虫姤璁板綍 + TaxDeclareRecordPO taxDeclareRecord = getById(id, tenantKey); + if (Objects.isNull(taxDeclareRecord)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156495, "鍙傛暟寮傚父锛屼釜绋庣敵鎶ヨ褰曚笉瀛樺湪鎴栧凡琚垹闄")); + } + // 鏌ヨ涓◣鎵g即涔夊姟浜 + TaxAgentPO taxAgent = taxAgentService.getById(taxDeclareRecord.getTaxAgentId(), tenantKey); + // 鏌ヨ涓◣鎵g即涔夊姟浜哄叧鑱旂殑浼佷笟淇℃伅 + TaxAgentTaxReturnPO taxAgentTaxReturn = taxAgentTaxReturnService.getByTaxAgentId(taxDeclareRecord.getTaxAgentId(), tenantKey); + if (Objects.isNull(taxAgentTaxReturn) || !Objects.equals(taxAgentTaxReturn.getCheckStatus(), TaxAgentTaxReturnStatusEnum.SUCCESS.getValue())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156469, "涓◣鎵g即涔夊姟浜虹殑鎶ョ◣淇℃伅楠岃瘉鏈氳繃锛岃鍏堢淮鎶ゅソ涓◣鎵g即涔夊姟浜虹殑鎶ョ◣淇℃伅")); + } + // 娉ㄥ唽鐨勪紒涓氫俊鎭-->璇锋眰鍙傛暟 + Map requestParam = TaxAgentTaxReturnBO.convert2RequestMap(taxAgent, taxAgentTaxReturn); + + return new TaxDeclareRequest().setTaxDeclarationApiConfig(apiConfig) + .setTaxAgent(taxAgent) + .setTaxDeclareRecord(taxDeclareRecord) + .setRequestParam(requestParam); + } +} diff --git a/src/com/engine/salary/web/TaxDeclarationController.java b/src/com/engine/salary/web/TaxDeclarationController.java index 6d2332dd4..4f1d319df 100644 --- a/src/com/engine/salary/web/TaxDeclarationController.java +++ b/src/com/engine/salary/web/TaxDeclarationController.java @@ -7,6 +7,7 @@ import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationListDTO; import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationDetailListQueryParam; import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationListQueryParam; import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationSaveParam; +import com.engine.salary.entity.taxdeclaration.param.TaxDeclareRecordParam; import com.engine.salary.service.TaxDeclarationExcelService; import com.engine.salary.service.TaxDeclarationService; import com.engine.salary.service.impl.TaxDeclarationExcelServiceImpl; @@ -16,9 +17,12 @@ import com.engine.salary.util.SalaryDateUtil; import com.engine.salary.util.page.PageInfo; import com.engine.salary.wrapper.TaxDeclarationDetailWrapper; import com.engine.salary.wrapper.TaxDeclarationWrapper; +import com.engine.salary.wrapper.TaxDeclareRecordWrapper; +import io.swagger.annotations.ApiOperation; import io.swagger.v3.oas.annotations.parameters.RequestBody; import lombok.extern.slf4j.Slf4j; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.web.bind.annotation.RequestParam; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; @@ -33,6 +37,9 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.ParseException; import java.time.LocalDate; +import java.util.Collection; +import java.util.List; +import java.util.Map; @Slf4j @@ -54,6 +61,11 @@ public class TaxDeclarationController { return ServiceUtil.getService(TaxDeclarationDetailWrapper.class, user); } + private TaxDeclareRecordWrapper getTaxDeclareRecordWrapper(User user) { + return ServiceUtil.getService(TaxDeclareRecordWrapper.class, user); + } + + //涓◣鐢虫姤琛ㄥ垪琛 @POST @Path("/list") @@ -139,4 +151,288 @@ public class TaxDeclarationController { throw e; } } + + + /** + * 鍒锋柊涓◣鐢虫姤琛ㄧ殑寰呭埛鏂版爣璇 + * + * @param param 鏇存柊鍙傛暟 + * @return + */ + @Path("/updateIcon") + @ApiOperation("鍒锋柊涓◣鐢虫姤琛ㄧ殑寰呭埛鏂版爣璇") + @Produces(MediaType.APPLICATION_JSON) + public String updateIcon(@Context HttpServletRequest request, @Context HttpServletResponse response,@RequestBody TaxDeclareRecordParam param) { + taxDeclareRecordWrapper.updateIcon(param.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(null); + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getTaxDeclarationWrapper(user)::getTaxDeclarationInfoById, taxDeclarationId); + } + + /** + * 涓◣鐢虫姤琛ㄧ敓鎴 + * + * @param ids 涓◣鐢虫姤璁板綍id + * @return + */ + @Path("/delete") + @ApiOperation("涓◣鐢虫姤琛ㄧ敓鎴") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult delete(@RequestBody Collection ids) { + taxDeclareRecordWrapper.delete(ids, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(null); + } + + /** + * 涓◣鐢虫姤琛ㄦ槸鍚﹀凡缁忕敓鎴 + * + * @param index 杩涘害缂撳瓨绱㈠紩 + * @return + */ + @GetMapping("/getRate") + @ApiOperation("涓◣鐢虫姤琛ㄦ槸鍚﹀凡缁忕敓鎴") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult getRate(@RequestParam(value = "index") String index) { + TaxDeclarationRateDTO rateDTO = taxDeclareRecordWrapper.getRate(index, TenantContext.getCurrentTenantKey()); + return WeaResult.success(rateDTO); + } + + /** + * 鑾峰彇涓◣鐢虫姤璁板綍涓嬬殑涓◣鐢虫姤琛═AB + * + * @param id 涓◣鐢虫姤璁板綍id + * @return + */ + @GetMapping("/getTaxDeclarationTab") + @ApiOperation("鑾峰彇涓◣鐢虫姤璁板綍涓嬬殑涓◣鐢虫姤琛═AB") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> getTaxDeclarationTab(@RequestParam(value = "id") Long id) { + List taxDeclarationTab = taxDeclareRecordWrapper.getTaxDeclarationTab(id, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(taxDeclarationTab); + } + + /** + * 鍦ㄧ嚎鐢虫姤 + * + * @param taxDeclareRecordParam 鍦ㄧ嚎鐢虫姤鍙傛暟 + * @return + */ + @Path("/declare") + @ApiOperation("鍦ㄧ嚎鐢虫姤") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult declare(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String cacheKey = taxDeclareRecordWrapper.declare(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(cacheKey); + } + + /** + * 鑾峰彇鍦ㄧ嚎鐢虫姤鍙嶉 + * + * @param taxDeclareRecordParam 鐢虫姤鍙嶉鍙傛暟 + * @return + */ + @Path("/getDeclareFeedback") + @ApiOperation("鑾峰彇鍦ㄧ嚎鐢虫姤鍙嶉") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult getDeclareFeedback(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String cacheKey = taxDeclareRecordWrapper.getDeclareFeedback(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(cacheKey); + } + + /** + * 浣滃簾 + * + * @param taxDeclareRecordParam 浣滃簾鍙傛暟 + * @return + */ + @Path("/cancel") + @ApiOperation("浣滃簾") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult cancel(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String cacheKey = taxDeclareRecordWrapper.cancelDeclare(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(cacheKey); + } + + /** + * 鑾峰彇浣滃簾鍙嶉 + * + * @param taxDeclareRecordParam 浣滃簾鍙嶉鍙傛暟 + * @return + */ + @Path("/getCancelFeedback") + @ApiOperation("鑾峰彇浣滃簾鍙嶉") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult getCancelFeedback(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String cacheKey = taxDeclareRecordWrapper.getCancelFeedback(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(cacheKey); + } + + /** + * 鏇存鐢虫姤 + * + * @param taxDeclareRecordParam 鏇存鐢虫姤鍙傛暟 + * @return + */ + @Path("/updateDeclare") + @ApiOperation("鏇存鐢虫姤") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult updateDeclare(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String cacheKey = taxDeclareRecordWrapper.updateDeclare(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(cacheKey); + } + + /** + * 绋庡眬绔敵鎶ョ姸鎬佹煡璇 + * + * @param taxDeclareRecordParam 鏌ヨ鍙傛暟 + * @return + */ + @Path("/queryDeclareStatus") + @ApiOperation("绋庡眬绔敵鎶ョ姸鎬佹煡璇") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult queryDeclareStatus(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String res = taxDeclareRecordWrapper.queryDeclareStatus(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(res); + } + + /** + * 绋庡眬绔敵鎶ユ槑缁嗘煡璇 + * + * @param taxDeclareRecordParam 鏌ヨ鐢虫姤鏄庣粏鍙傛暟 + * @return + */ + @Path("/queryCompanyIncomes") + @ApiOperation("绋庡眬绔敵鎶ユ槑缁嗘煡璇") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult queryCompanyIncomes(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String res = taxDeclareRecordWrapper.queryCompanyIncomes(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(res); + } + + /** + * 鍒锋柊鏁版嵁 + * + * @param taxDeclareRecordParam 鍒锋柊鏁版嵁鍙傛暟 + * @return + */ + @Path("/refreshData") + @ApiOperation("鍒锋柊鏁版嵁") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult refreshData(@RequestBody @Validated TaxDeclareRecordParam taxDeclareRecordParam) { + String cacheKey = taxDeclareRecordWrapper.refreshData(taxDeclareRecordParam.getTaxDeclareRecordId(), UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(cacheKey); + } + + /** + * 涓◣鐢虫姤琛ㄨ鎯呭垪琛 + * + * @param queryParam 鏌ヨ鏉′欢 + * @return + */ + @Path("/detail/list") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹垪琛") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> listTaxDeclarationValue(@RequestBody TaxDeclarationValueListQueryParam queryParam) { + WeaTable weaTable = taxDeclareRecordWrapper.listValuePage(queryParam, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); + return WeaResult.success(weaTable); + } + + /** + * 瀵煎嚭涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹 + * + * @param queryParam 瀵煎嚭鍙傛暟 + * @return + */ + @Path("/detail/export") + @ApiOperation("瀵煎嚭涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> exportTaxDeclaration(@RequestBody @Validated TaxDeclarationValueListQueryParam queryParam) { + Map map = taxDeclareRecordWrapper.exportTaxDeclarationValue(queryParam, UserContext.getCurrentUser()); + return WeaResult.success(map); + } + + /** + * 涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-浜哄憳鏈姤閫佸垪琛 + * + * @param queryParam 鏌ヨ鏉′欢 + * @return + */ + @Path("/employee/list4NotDeclare") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-浜哄憳鏈姤閫佸垪琛") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> listEmployee4NotDeclare(@RequestBody @Validated AbnormalEmployeeListQueryParam queryParam) { + WeaTable weaTable = taxDeclareRecordWrapper.listEmployeePage4NotDeclare(queryParam, TenantContext.getCurrentTenantKey()); + return WeaResult.success(weaTable); + } + + /** + * 涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-鎶ラ佷汉鍛樻棤鐢虫姤鏁版嵁鍒楄〃 + * + * @param queryParam 鏌ヨ鏉′欢 + * @return + */ + @Path("/employee/list4NoValue") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-鎶ラ佷汉鍛樻棤鐢虫姤鏁版嵁鍒楄〃") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> listEmployee4NoValue(@RequestBody @Validated AbnormalEmployeeListQueryParam queryParam) { + WeaTable weaTable = taxDeclareRecordWrapper.listEmployeePage4NoValue(queryParam, TenantContext.getCurrentTenantKey()); + return WeaResult.success(weaTable); + } + + /** + * 涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-鐢虫姤澶辫触鍒楄〃 + * + * @param queryParam 鏌ヨ鏉′欢 + * @return + */ + @Path("/employee/list4Fail") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-鐢虫姤澶辫触鍒楄〃") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> listEmployee4Fail(@RequestBody @Validated AbnormalEmployeeListQueryParam queryParam) { + WeaTable weaTable = taxDeclareRecordWrapper.listEmployeePage4Fail(queryParam, TenantContext.getCurrentTenantKey()); + return WeaResult.success(weaTable); + } + + /** + * 涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-瀵煎嚭浜哄憳鏈姤閫佸垪琛 + * + * @param queryParam 鏌ヨ鏉′欢 + * @return + */ + @Path("/employee/export4NotDeclare") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-瀵煎嚭浜哄憳鏈姤閫佸垪琛") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> exportEmployee4NotDeclare(@RequestBody @Validated AbnormalEmployeeListQueryParam queryParam) { + Map map = taxDeclareRecordWrapper.exportEmployee4NotDeclare(queryParam, UserContext.getCurrentUser()); + return WeaResult.success(map); + } + + /** + * 涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-瀵煎嚭鎶ラ佷汉鍛樻棤鐢虫姤鏁版嵁鍒楄〃 + * + * @param queryParam 鏌ヨ鏉′欢 + * @return + */ + @Path("/employee/export4NoValue") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-瀵煎嚭鎶ラ佷汉鍛樻棤鐢虫姤鏁版嵁鍒楄〃") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> exportEmployee4NoValue(@RequestBody @Validated AbnormalEmployeeListQueryParam queryParam) { + Map map = taxDeclareRecordWrapper.exportEmployee4NoValue(queryParam, UserContext.getCurrentUser()); + return WeaResult.success(map); + } + + /** + * 涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-瀵煎嚭鐢虫姤澶辫触鍒楄〃 + * + * @param queryParam 瀵煎嚭鍙傛暟 + * @return + */ + @Path("/employee/export4Fail") + @ApiOperation("涓◣鐢虫姤琛ㄧ敵鎶ユ暟鎹-瀵煎嚭鐢虫姤澶辫触鍒楄〃") + @Produces(MediaType.APPLICATION_JSON) + public WeaResult> exportEmployee4Fail(@RequestBody @Validated AbnormalEmployeeListQueryParam queryParam) { + Map map = taxDeclareRecordWrapper.exportEmployee4Fail(queryParam, UserContext.getCurrentUser()); + return WeaResult.success(map); + } + } diff --git a/src/com/engine/salary/wrapper/TaxDeclareRecordWrapper.java b/src/com/engine/salary/wrapper/TaxDeclareRecordWrapper.java new file mode 100644 index 000000000..ae77b1f61 --- /dev/null +++ b/src/com/engine/salary/wrapper/TaxDeclareRecordWrapper.java @@ -0,0 +1,753 @@ +package com.engine.salary.wrapper; + +import com.engine.core.impl.Service; +import com.engine.salary.service.SalaryCacheService; +import com.engine.salary.service.TaxAgentService; +import com.engine.salary.service.TaxDeclarationExcelService; +import com.engine.salary.service.TaxDeclarationService; +import com.weaver.common.component.form.WeaForm; +import com.weaver.common.component.table.WeaTable; +import com.weaver.common.component.table.page.Page; +import com.weaver.common.component.table.permission.Permission; +import com.weaver.common.distribution.genid.IdGenerator; +import com.weaver.common.hr.util.Util; +import com.weaver.common.hrm.service.HrmCommonEmployeeService; +import com.weaver.common.threadPool.ThreadPoolUtil; +import com.weaver.common.threadPool.constant.ModulePoolEnum; +import com.weaver.common.threadPool.entity.LocalRunnable; +import com.weaver.datasecurity.interceptor.DSTenantKeyThreadVar; +import com.weaver.framework.util.JsonUtil; +import com.weaver.hrm.salary.cache.SalaryCacheKey; +import com.weaver.hrm.salary.common.excel.ExcelExportParam; +import com.weaver.hrm.salary.constant.SalaryConstant; +import com.weaver.hrm.salary.entity.taxagent.po.TaxAgentPO; +import com.weaver.hrm.salary.entity.taxdeclaration.dto.*; +import com.weaver.hrm.salary.entity.taxdeclaration.param.AbnormalEmployeeListQueryParam; +import com.weaver.hrm.salary.entity.taxdeclaration.param.TaxDeclarationListQueryParam; +import com.weaver.hrm.salary.entity.taxdeclaration.param.TaxDeclarationSaveParam; +import com.weaver.hrm.salary.entity.taxdeclaration.param.TaxDeclarationValueListQueryParam; +import com.weaver.hrm.salary.entity.taxdeclaration.po.*; +import com.weaver.hrm.salary.enums.salarysob.IncomeCategoryEnum; +import com.weaver.hrm.salary.enums.taxdeclaration.TaxAgentRangeEnum; +import com.weaver.hrm.salary.enums.taxdeclaration.TaxDeclareStatusEnum; +import com.weaver.hrm.salary.enums.taxdeclaration.TaxDeclareTypeEnum; +import com.weaver.hrm.salary.exception.SalaryNullException; +import com.weaver.hrm.salary.exception.SalaryRunTimeException; +import com.weaver.hrm.salary.service.*; +import com.weaver.hrm.salary.util.*; +import com.weaver.teams.domain.EntityType; +import com.weaver.teams.domain.user.SimpleEmployee; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; +import org.springframework.stereotype.Component; + +import java.time.YearMonth; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @description: 涓◣鐢虫姤 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 2022/11/10 9:24 AM + * @version:v1.0 + */ +@Slf4j +@Component +public class TaxDeclareRecordWrapper extends Service { + + + private TaxDeclareRecordService taxDeclareRecordService; + + private TaxAgentService taxAgentService; + + private HrmCommonEmployeeService hrmCommonEmployeeService; + + private SalaryCacheService salaryCacheService; + + private TaxDeclarationService taxDeclarationService; + + private TaxDeclarationValueService taxDeclarationValueService; + + private TaxDeclarationExcelService taxDeclarationExcelService; + + private TaxDeclareEmployeeService taxDeclareEmployeeService; + + private TaxDeclareFailService taxDeclareFailService; + + /** + * 涓◣鐢虫姤璁板綍鍒楄〃 + * + * @param queryParam + * @param employeeId + * @param tenantKey + * @return + */ + public WeaTable listPage(TaxDeclarationListQueryParam queryParam, Long employeeId, String tenantKey) { + Page page = taxDeclareRecordService.listPageByParam(queryParam, employeeId, tenantKey); + Page dtoPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal(), page.isSearchCount()); + if (CollectionUtils.isNotEmpty(page.getRecords())) { + // 鏌ヨ涓◣鎵g即涔夊姟浜 + Set taxAgentIds = SalaryEntityUtil.properties(page.getRecords(), TaxDeclareRecordPO::getTaxAgentId); + List taxAgents = taxAgentService.listByIds(taxAgentIds, tenantKey); + // 鏌ヨ浜哄憳濮撳悕 + List employeeIds = SalaryEntityUtil.properties(page.getRecords(), TaxDeclareRecordPO::getCreator, Collectors.toList()); + List simpleEmployees = hrmCommonEmployeeService.getEmployeeByIds(employeeIds, tenantKey); + + List dtoList = Lists.newArrayList(); + Map taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getId, TaxAgentPO::getName); + Map simpleEmployeeNameMap = SalaryEntityUtil.convert2Map(simpleEmployees, SimpleEmployee::getEmployeeId, SimpleEmployee::getName); + for (TaxDeclareRecordPO taxDeclareRecord : page.getRecords()) { + TaxDeclareTypeEnum taxDeclareTypeEnum = SalaryEnumUtil.enumMatchByValue(taxDeclareRecord.getTaxDeclareType(), TaxDeclareTypeEnum.class); + TaxDeclareStatusEnum taxDeclareStatusEnum = SalaryEnumUtil.enumMatchByValue(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.class); + TaxDeclareRecordListDTO taxDeclareRecordListDTO = new TaxDeclareRecordListDTO() + .setId(taxDeclareRecord.getId()) + .setTaxAgentId(taxDeclareRecord.getTaxAgentId()) + .setTaxAgentName(taxAgentNameMap.get(taxDeclareRecord.getTaxAgentId())) + .setSalaryMonth(taxDeclareRecord.getSalaryMonth()) + .setTaxCycle(taxDeclareRecord.getTaxCycle()) + .setTaxDeclareType(taxDeclareTypeEnum) + .setTaxDeclareTypeDesc(taxDeclareTypeEnum == null ? "" : SalaryI18nUtil.getI18nLabel(taxDeclareTypeEnum.getLabelId(), taxDeclareTypeEnum.getDefaultLabel())) + .setTaxDeclareStatus(taxDeclareStatusEnum) + .setTaxDeclareStatusDesc(taxDeclareStatusEnum == null ? "" : SalaryI18nUtil.getI18nLabel(taxDeclareStatusEnum.getLabelId(), taxDeclareStatusEnum.getDefaultLabel())) + .setTaxPaidAmount(SalaryEntityUtil.thousandthConvert(taxDeclareRecord.getTaxPaidAmount())) + .setOperateEmployeeId(taxDeclareRecord.getCreator()) + .setOperateEmployeeName(simpleEmployeeNameMap.get(taxDeclareRecord.getCreator())) + .setOperateTime(SalaryDateUtil.getFormatLocalDateTime(taxDeclareRecord.getCreateTime())) + .setDescription(taxDeclareRecord.getRemark()) + .setDisplayIcon(Objects.equals(taxDeclareRecord.getDisplayUpdateIcon(), 1)); + dtoList.add(taxDeclareRecordListDTO); + } + dtoPage.setRecords(dtoList); + } + // 杞崲鎴愬墠绔墍闇鐨勬暟鎹牸寮 + WeaTable weaTable = SalaryFormatUtil.getInstance() + .buildTable(TaxDeclareRecordListDTO.class, dtoPage); + for (int i = 0; i < dtoPage.getRecords().size(); i++) { + TaxDeclareRecordListDTO dto = dtoPage.getRecords().get(i); + List permissions = weaTable.getOperatesPermission().get(i); + for (int j = 0; j < permissions.size(); j++) { + Permission permission = permissions.get(j); + if (j == 1 && (dto.getTaxDeclareStatus() != TaxDeclareStatusEnum.NOT_DECLARE || dto.getTaxDeclareType() != TaxDeclareTypeEnum.NORMAL_DECLARE)) { + permission.setVisible(false); + permission.setDisabled(false); + } + } + } + return weaTable; + } + + /** + * 涓◣鐢虫姤琛ㄦ槑缁嗗垪琛 + * + * @param queryParam 鍒楄〃鏌ヨ鏉′欢 + * @param tenantKey 绉熸埛key + * @return + */ + public WeaTable listValuePage(TaxDeclarationValueListQueryParam queryParam, Long employeeId, String tenantKey) { + // 鏌ヨ涓◣鐢虫姤琛 + TaxDeclarationPO taxDeclaration = taxDeclarationService.getById(queryParam.getTaxDeclarationId(), tenantKey); + // 鍒ゆ柇鏄惁鏈夋潈闄愭煡鐪 + boolean canSee = taxDeclareRecordService.checkByAuthority(taxDeclaration, employeeId, tenantKey); + if (!canSee) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(156515, "瀵逛笉璧凤紝鎮ㄦ殏鏃舵病鏈夋潈闄愭煡鐪")); + } + String pageUid = "taxDeclarationValueList"; + SalaryPageUtil.handlePageSize(pageUid, queryParam); + // 鏌ヨ涓◣鐢虫姤琛ㄨ鎯 + Page page = taxDeclarationValueService.listPageByTaxDeclarationIds( + new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true), Collections.singleton(queryParam.getTaxDeclarationId()), tenantKey); + TaxDeclarationValueListDTO taxDeclarationValueListDTO = taxDeclarationValueService.convert2List(taxDeclaration, page.getRecords(), tenantKey); + Page> dtoPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal(), page.isSearchCount()); + dtoPage.setRecords(taxDeclarationValueListDTO.getData()); + // 杞垚鍓嶇鎵闇鐨勬牸寮 + WeaTable> weaTable = new WeaTable<>(); + weaTable.setColumns(taxDeclarationValueListDTO.getColumns()); + weaTable.setPage(dtoPage); + weaTable.setModule(SalaryConstant.MODULE); + weaTable.setPageUid(pageUid); + return weaTable; + } + + /** + * 鏈姤閫佺殑浜哄憳鍒楄〃 + * + * @param queryParam + * @param tenantKey + * @return + */ + public WeaTable listEmployeePage4NotDeclare(AbnormalEmployeeListQueryParam queryParam, String tenantKey) { + String pageUid = "abnormalEmployeeList4NoDeclare"; + SalaryPageUtil.handlePageSize(pageUid, queryParam); + WeaTable weaTable = listEmployeePage("NotDeclare", queryParam, tenantKey); + weaTable.setPageUid(pageUid); + return weaTable; + } + + /** + * 娌℃湁鐢虫姤鏁版嵁鐨勪汉鍛樺垪琛 + * + * @param queryParam + * @param tenantKey + * @return + */ + public WeaTable listEmployeePage4NoValue(AbnormalEmployeeListQueryParam queryParam, String tenantKey) { + String pageUid = "abnormalEmployeeList4NoValue"; + SalaryPageUtil.handlePageSize(pageUid, queryParam); + WeaTable weaTable = listEmployeePage("NoValue", queryParam, tenantKey); + weaTable.setPageUid(pageUid); + return weaTable; + } + + /** + * 鐢虫姤澶辫触鐨勪汉鍛樺垪琛 + * + * @param queryParam + * @param tenantKey + * @return + */ + public WeaTable listEmployeePage4Fail(AbnormalEmployeeListQueryParam queryParam, String tenantKey) { + String pageUid = "failEmployeeList"; + SalaryPageUtil.handlePageSize(pageUid, queryParam); + // 鏌ヨ涓◣鐢虫姤璁板綍 + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRecordService.getById(queryParam.getTaxDeclareRecordId(), tenantKey); + // 鏌ヨ鐢虫姤澶辫触鐨勬暟鎹 + Page page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true); + page = taxDeclareFailService.listPageByTaxDeclareRecordIds(page, Collections.singleton(taxDeclareRecord.getId()), tenantKey); + // 杞崲鎴恉to + Page dtoPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal(), page.isSearchCount()); + dtoPage.setRecords(taxDeclareFailService.convert2FailEmployeeList(taxDeclareRecord, page.getRecords(), tenantKey)); + // 杞垚鍓嶇鎵闇鐨勬牸寮 + return SalaryFormatUtil.getInstance().buildTable(FailEmployeeListDTO.class, dtoPage); + } + + private WeaTable listEmployeePage(String key, AbnormalEmployeeListQueryParam queryParam, String tenantKey) { + WeaTable weaTable; + // 鏌ヨ涓◣鐢虫姤璁板綍 + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRecordService.getById(queryParam.getTaxDeclareRecordId(), tenantKey); + queryParam.setTaxAgentId(taxDeclareRecord.getTaxAgentId()); + queryParam.setTaxCycle(taxDeclareRecord.getTaxCycle()); + if (StringUtils.isEmpty(queryParam.getKeyword())) { + // 鏌ヨ涓◣鐢虫姤璁板綍鐨勪汉鍛 + Page page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true); + if (StringUtils.equals("NotDeclare", key)) { + page = taxDeclareEmployeeService.listPage4NotDeclareByParam(queryParam, tenantKey); + } else if (StringUtils.equals("NoValue", key)) { + page = taxDeclareEmployeeService.listPage4NoValueByParam(queryParam, tenantKey); + } + Page dtoPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal(), page.isSearchCount()); + dtoPage.setRecords(taxDeclareEmployeeService.convert2AbnormalEmployeeList(taxDeclareRecord, page.getRecords(), tenantKey)); + // 杞崲鎴愬墠绔墍闇鐨勬牸寮 + weaTable = SalaryFormatUtil.getInstance().buildTable(AbnormalEmployeeListDTO.class, dtoPage); + } else { + // 鏌ヨ鏉′欢涓寘鍚"keyword"鏃讹紝涓嶅ソ閫氳繃SQL鍒嗛〉锛屾墍浠ュ湪鍐呭瓨涓垎椤 + List taxDeclareEmployees = Collections.emptyList(); + if (StringUtils.equals("NotDeclare", key)) { + taxDeclareEmployees = taxDeclareEmployeeService.list4NotDeclareByParam(queryParam, tenantKey); + } else if (StringUtils.equals("NoValue", key)) { + taxDeclareEmployees = taxDeclareEmployeeService.list4NoValueByParam(queryParam, tenantKey); + } + List dtos = taxDeclareEmployeeService.convert2AbnormalEmployeeList(taxDeclareRecord, taxDeclareEmployees, tenantKey) + .stream() + .filter(e -> StringUtils.contains(e.getEmployeeName(), queryParam.getKeyword()) + || StringUtils.contains(e.getJobNum(), queryParam.getKeyword()) + || StringUtils.contains(e.getCardNum(), queryParam.getKeyword())) + .collect(Collectors.toList()); + Page dtoPage = new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), dtos.size(), true); + dtoPage.setRecords(SalaryPageUtil.subList((int) dtoPage.getCurrent(), (int) dtoPage.getSize(), dtos)); + // 杞崲鎴愬墠绔墍闇鐨勬牸寮 + weaTable = SalaryFormatUtil.getInstance().buildTable(AbnormalEmployeeListDTO.class, dtoPage); + } + return weaTable; + } + + /** + * 鑾峰彇涓◣鐢虫姤璁板綍鐨勮〃鍗 + * + * @param id + * @param tenantKey + * @return + */ + public WeaForm getForm(Long id, Long employeeId, String tenantKey) { + TaxDeclareRecordFormDTO formDTO = new TaxDeclareRecordFormDTO(); + formDTO.setTaxAgentRange(TaxAgentRangeEnum.SELECT_TAX_AGENT); + // 鍒ゆ柇褰撳墠鏄惁寮鍚簡鍒嗘潈 + Boolean openDevolution = taxAgentService.isOpenDevolution(tenantKey); + Boolean isChief = taxAgentService.isChief(employeeId, tenantKey); + // 杞崲鎴愬墠绔墍闇鐨勬暟鎹牸寮 + WeaForm weaForm = SalaryFormatUtil.getInstance().buildForm(TaxDeclareRecordFormDTO.class, formDTO); + weaForm.getItems().forEach((k, v) -> { + if (StringUtils.equals("salaryMonth", k)) { + Map otherParams = new HashMap<>(); + otherParams.put("type", "month"); + v.setOtherParams(otherParams); + } + // 鏈紑鍚垎鏉冿紝娌℃湁"浣滀负绠$悊鍛樼殑涓◣鎵g即涔夊姟浜" + if (!openDevolution && StringUtils.equals("taxAgentRange", k)) { + v.getOptions().remove(1); + } + // 寮鍚垎鏉冿紝浣嗕笉鏄荤鐞嗗憳锛屾病鏈"鎵鏈変釜绋庢墸缂翠箟鍔′汉" + if (openDevolution && !isChief && StringUtils.equals("taxAgentRange", k)) { + v.getOptions().remove(0); + } + }); + return weaForm; + } + + /** + * 鑾峰彇涓◣鐢虫姤璁板綍涓嬬殑涓◣鐢虫姤琛═AB + * + * @param id + * @param tenantKey + * @return + */ + public List getTaxDeclarationTab(Long id, Long employeeId, String tenantKey) { + // 鏌ヨ涓◣鐢虫姤璁板綍 + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRecordService.getById(id, tenantKey); + // 鏌ヨ涓◣鐢虫姤璁板綍涓嬬殑涓◣鐢虫姤琛 + List taxDeclarations = taxDeclarationService.listByTaxCycleAndTaxAgentIds(YearMonth.parse(taxDeclareRecord.getTaxCycle()), + Collections.singleton(taxDeclareRecord.getTaxAgentId()), tenantKey); + taxDeclarations = taxDeclarations.stream() + .filter(e -> Objects.equals(e.getControlView(), 0) || Objects.equals(e.getCreator(), employeeId)) + .collect(Collectors.toList()); + Map taxDeclarationMap = SalaryEntityUtil.convert2Map(taxDeclarations, TaxDeclarationPO::getIncomeCategory); + List tabs = Lists.newArrayList(); + for (IncomeCategoryEnum incomeCategoryEnum : IncomeCategoryEnum.values()) { + TaxDeclarationPO taxDeclaration = taxDeclarationMap.get(incomeCategoryEnum.getValue()); + if (taxDeclaration != null) { + TaxDeclarationTabDTO taxDeclarationTabDTO = new TaxDeclarationTabDTO() + .setTabName(SalaryI18nUtil.getI18nLabel(incomeCategoryEnum.getLabelId(), incomeCategoryEnum.getDefaultLabel())) + .setIncomeCategory(incomeCategoryEnum) + .setTaxDeclarationId(taxDeclaration.getId()); + tabs.add(taxDeclarationTabDTO); + } + } + return tabs; + } + + /** + * 鏌ヨ涓◣鐢虫姤琛ㄧ殑鍩烘湰淇℃伅 + * + * @param id 涓◣鐢虫姤琛╥d + * @param tenantKey 绉熸埛key + * @return + */ + public TaxDeclarationInfoDTO getTaxDeclarationInfoById(Long id, String tenantKey) { + // 鏌ヨ涓◣鐢虫姤琛 + TaxDeclareRecordPO taxDeclareRecord = taxDeclareRecordService.getById(id, tenantKey); + if (Objects.isNull(taxDeclareRecord)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98877, "涓◣鐢虫姤琛ㄤ笉瀛樺湪鎴栧凡鍒犻櫎")); + } + AbnormalEmployeeListQueryParam queryParam = new AbnormalEmployeeListQueryParam() + .setTaxDeclareRecordId(taxDeclareRecord.getId()) + .setTaxAgentId(taxDeclareRecord.getTaxAgentId()) + .setTaxCycle(taxDeclareRecord.getTaxCycle()); + // 鏌ヨ鏄惁瀛樺湪鏈夋湭鎶ラ佺殑浜 + List notDeclareTaxDeclareEmployees = taxDeclareEmployeeService.list4NotDeclareByParam(queryParam, tenantKey); + // 鏌ヨ鏄惁瀛樺湪娌℃湁鐢虫姤鏁版嵁鐨勪汉 + List noValueTaxDeclareEmployees = taxDeclareEmployeeService.list4NoValueByParam(queryParam, tenantKey); + // 鏌ヨ鏄惁瀛樺湪鐢虫姤澶辫触鐨勪汉 + List taxDeclareFails = taxDeclareFailService.listByTaxDeclareRecordIds(Collections.singleton(taxDeclareRecord.getId()), tenantKey); + // 鏌ヨ涓◣鎵g即涔夊姟浜 + TaxAgentPO taxAgentPO = taxAgentService.getById(taxDeclareRecord.getTaxAgentId(), tenantKey); + TaxDeclareTypeEnum taxDeclareTypeEnum = SalaryEnumUtil.enumMatchByValue(taxDeclareRecord.getTaxDeclareType(), TaxDeclareTypeEnum.class); + TaxDeclareStatusEnum taxDeclareStatusEnum = SalaryEnumUtil.enumMatchByValue(taxDeclareRecord.getTaxDeclareStatus(), TaxDeclareStatusEnum.class); + return new TaxDeclarationInfoDTO() + .setSalaryMonth(taxDeclareRecord.getSalaryMonth()) + .setTaxCycle(taxDeclareRecord.getTaxCycle()) + .setTaxAgentId(taxDeclareRecord.getTaxAgentId()) + .setTaxAgentName(Optional.ofNullable(taxAgentPO).map(TaxAgentPO::getName).orElse("")) + .setDeclareType(taxDeclareTypeEnum) + .setDeclareTypeDesc(taxDeclareTypeEnum == null ? "" : SalaryI18nUtil.getI18nLabel(taxDeclareTypeEnum.getLabelId(), taxDeclareTypeEnum.getDefaultLabel())) + .setDeclareStatus(taxDeclareStatusEnum) + .setDeclareStatusDesc(taxDeclareStatusEnum == null ? "" : SalaryI18nUtil.getI18nLabel(taxDeclareStatusEnum.getLabelId(), taxDeclareStatusEnum.getDefaultLabel())) + .setDeclareErrorMsg(taxDeclareRecord.getTaxDeclareErrorMsg()) + .setDisplayIcon(Objects.equals(taxDeclareRecord.getDisplayUpdateIcon(), 1)) + .setDeclareFailSize(taxDeclareFails.size()) + .setAbnormalSize(notDeclareTaxDeclareEmployees.size() + noValueTaxDeclareEmployees.size()) + .setTaxPaidAmount(SalaryEntityUtil.thousandthConvert(taxDeclareRecord.getTaxPaidAmount())); + } + + /** + * 淇濆瓨 + * + * @param saveParam 淇濆瓨鍙傛暟 + * @param employeeId 浜哄憳id + * @param tenantKey 绉熸埛key + */ + public String save(TaxDeclarationSaveParam saveParam, Long employeeId, String tenantKey) { + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true) + .setIndex(Util.null2String(IdGenerator.generate())) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 95836, "鐢熸垚鐢虫姤琛")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + DSTenantKeyThreadVar.tenantKey.set(tenantKey); + taxDeclareRecordService.save(saveParam, employeeId, tenantKey); + taxDeclarationRate.setStatus(true).setFinish(true); + } catch (SalaryRunTimeException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("涓◣鐢虫姤琛ㄧ敓鎴愭姤閿欙細{}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187276, "涓◣鐢虫姤琛ㄧ敓鎴愭姤閿欙細") + e.getMessage()); + } finally { + DSTenantKeyThreadVar.tenantKey.remove(); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "saveTaxDeclaration", localRunnable); + return taxDeclarationRate.getIndex(); + } + + /** + * 鏇存柊涓◣鐢虫姤琛ㄧ殑寰呭埛鏂版暟鎹殑鏍囪瘑 + * + * @param id + * @param employeeId + * @param tenantKey + */ + public void updateIcon(Long id, Long employeeId, String tenantKey) { + taxDeclareRecordService.updateIcon(id, NumberUtils.INTEGER_ZERO, employeeId, tenantKey); + } + + /** + * 鍒犻櫎涓◣鐢虫姤琛 + * + * @param ids + * @param employeeId + * @param tenantKey + */ + public void delete(Collection ids, Long employeeId, String tenantKey) { + taxDeclareRecordService.deleteByIds(ids, tenantKey); + } + + /** + * 鑾峰彇涓◣鐢虫姤琛ㄦ槸鍚﹀凡缁忕敓鎴 + * + * @param index + * @param tenantKey + * @return + */ + public TaxDeclarationRateDTO getRate(String index, String tenantKey) { + return salaryCacheService.get(SalaryCacheKey.TAX_DECLARATION, index, TaxDeclarationRateDTO.class); + } + + /** + * 鐢虫姤 + * + * @param id + * @param tenantKey + */ + public String declare(Long id, Long employeeId, String tenantKey) { + checkBefore(id); + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true).setIndex(Util.null2String(id)) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156454, "鍦ㄧ嚎鐢虫姤")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + DSTenantKeyThreadVar.tenantKey.set(tenantKey); + taxDeclareRecordService.declare(id, employeeId, tenantKey); + taxDeclarationRate.setFinish(true); + } catch (SalaryRunTimeException | SalaryNullException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("鍦ㄧ嚎鐢虫姤澶辫触锛歿}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187274, "鍦ㄧ嚎鐢虫姤澶辫触锛") + e.getMessage()); + } finally { + DSTenantKeyThreadVar.tenantKey.remove(); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "declare", localRunnable); + return taxDeclarationRate.getIndex(); + } + + /** + * 鑾峰彇鐢虫姤鍙嶉 + * + * @param id + * @param tenantKey + */ + public String getDeclareFeedback(Long id, Long employeeId, String tenantKey) { + checkBefore(id); + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true).setIndex(Util.null2String(id)) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 182680, "鑾峰彇鐢虫姤鍙嶉")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + taxDeclareRecordService.getDeclareFeedback(id, taxDeclarationRate, employeeId, tenantKey); + taxDeclarationRate.setFinish(true); + } catch (SalaryRunTimeException | SalaryNullException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("鑾峰彇鐢虫姤鍙嶉澶辫触锛歿}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187255, "鑾峰彇鐢虫姤鍙嶉澶辫触锛") + e.getMessage()); + } finally { + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "getDeclareFeedback", localRunnable); + return taxDeclarationRate.getIndex(); + } + + /** + * 浣滃簾 + * + * @param id + * @param tenantKey + */ + public String cancelDeclare(Long id, Long employeeId, String tenantKey) { + checkBefore(id); + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true).setIndex(Util.null2String(id)) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 158842, "浣滃簾鐢虫姤")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + taxDeclareRecordService.cancelDeclare(id, employeeId, tenantKey); + taxDeclarationRate.setFinish(true); + } catch (SalaryRunTimeException | SalaryNullException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("浣滃簾鐢虫姤澶辫触锛歿}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187272, "浣滃簾鐢虫姤澶辫触锛") + e.getMessage()); + } finally { + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "cancel", localRunnable); + return taxDeclarationRate.getIndex(); + } + + /** + * 鑾峰彇浣滃簾鍙嶉 + * + * @param id + * @param tenantKey + */ + public String getCancelFeedback(Long id, Long employeeId, String tenantKey) { + checkBefore(id); + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true).setIndex(Util.null2String(id)) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 182681, "鑾峰彇浣滃簾鐢虫姤鍙嶉")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + taxDeclareRecordService.getCancelFeedback(id, taxDeclarationRate, employeeId, tenantKey); + taxDeclarationRate.setFinish(true); + } catch (SalaryRunTimeException | SalaryNullException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("鑾峰彇浣滃簾鍙嶉缁撴灉澶辫触锛歿}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187270, "鑾峰彇浣滃簾鍙嶉缁撴灉澶辫触锛") + e.getMessage()); + } finally { + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "getCancelFeedback", localRunnable); + return taxDeclarationRate.getIndex(); + } + + /** + * 鏇存鐢虫姤 + * + * @param id + * @param employeeId + * @param tenantKey + * @return + */ + public String updateDeclare(Long id, Long employeeId, String tenantKey) { + checkBefore(id); + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true).setIndex(Util.null2String(id)) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 177637, "鏇存鐢虫姤")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + taxDeclareRecordService.updateDeclare(id, employeeId, tenantKey); + taxDeclarationRate.setFinish(true); + } catch (SalaryRunTimeException | SalaryNullException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("鏇存鐢虫姤澶辫触锛歿}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187269, "鏇存鐢虫姤澶辫触锛") + e.getMessage()); + } finally { + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "updateDeclare", localRunnable); + return taxDeclarationRate.getIndex(); + } + + /** + * 绋庡眬绔敵鎶ョ姸鎬佹煡璇 + * + * @param id + * @param employeeId + * @param tenantKey + * @return + */ + public String queryDeclareStatus(Long id, Long employeeId, String tenantKey) { + return taxDeclareRecordService.queryDeclareStatus(id, employeeId, tenantKey); + } + + /** + * 绋庡眬绔敵鎶ユ槑缁嗘煡璇 + * + * @param id + * @param employeeId + * @param tenantKey + * @return + */ + public String queryCompanyIncomes(Long id, Long employeeId, String tenantKey) { + return taxDeclareRecordService.queryCompanyIncomes(id, employeeId, tenantKey); + } + + /** + * 鍒锋柊鏁版嵁 + * + * @param id + * @param employeeId + * @param tenantKey + * @return + */ + public String refreshData(Long id, Long employeeId, String tenantKey) { + checkBefore(id); + TaxDeclarationRateDTO taxDeclarationRate = new TaxDeclarationRateDTO().setStatus(true).setIndex(Util.null2String(id)) + .setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 156447, "鍒锋柊鏁版嵁")); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + try { + DSTenantKeyThreadVar.tenantKey.set(tenantKey); + taxDeclareRecordService.refreshData(id, employeeId, tenantKey); + taxDeclarationRate.setFinish(true); + } catch (SalaryRunTimeException | SalaryNullException e) { + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(e.getMessage()); + } catch (Exception e) { + log.error("鍒锋柊鏁版嵁澶辫触锛歿}", e.getMessage(), e); + taxDeclarationRate.setStatus(false).setFinish(true).setMsg(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 187268, "鍒锋柊鏁版嵁澶辫触锛") + e.getMessage()); + } finally { + DSTenantKeyThreadVar.tenantKey.remove(); + salaryCacheService.set(SalaryCacheKey.TAX_DECLARATION, taxDeclarationRate.getIndex(), taxDeclarationRate); + } + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "refreshData", localRunnable); + return taxDeclarationRate.getIndex(); + } + + private void checkBefore(Long id) { + TaxDeclarationRateDTO taxDeclarationRate = salaryCacheService.get(SalaryCacheKey.TAX_DECLARATION, Util.null2String(id), TaxDeclarationRateDTO.class); + if (taxDeclarationRate != null && !taxDeclarationRate.isFinish()) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(182691, "褰撳墠姝e浜庛寋0}銆嶄腑锛岃绋嶅悗鍐嶈瘯").replace("{0}", taxDeclarationRate.getMsg())); + } + } + + /** + * 瀵煎嚭涓◣鐢虫姤鏄庣粏鍒楄〃 + * + * @param queryParam + * @param simpleEmployee + * @return + */ + public Map exportTaxDeclarationValue(TaxDeclarationValueListQueryParam queryParam, SimpleEmployee simpleEmployee) { + ExcelExportParam excelExportParam = new ExcelExportParam() + .setBiz(String.valueOf(IdGenerator.generate())) + .setModule(EntityType.hrmsalary.name()) + .setFunction("exportTaxDeclarationValue"); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + taxDeclarationExcelService.exportTaxDeclarationValue(excelExportParam, queryParam, simpleEmployee); + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "exportTaxDeclarationValue", localRunnable); + return JsonUtil.parseMap(excelExportParam, Object.class); + } + + /** + * 瀵煎嚭鏈姤閫佺殑浜哄憳鍒楄〃 + * + * @param queryParam + * @param simpleEmployee + * @return + */ + public Map exportEmployee4NotDeclare(AbnormalEmployeeListQueryParam queryParam, SimpleEmployee simpleEmployee) { + ExcelExportParam excelExportParam = new ExcelExportParam() + .setBiz(String.valueOf(IdGenerator.generate())) + .setModule(EntityType.hrmsalary.name()) + .setFunction("exportEmployee4NotDeclare"); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + taxDeclarationExcelService.exportEmployee4NotDeclare(excelExportParam, queryParam, simpleEmployee); + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "exportEmployee4NotDeclare", localRunnable); + return JsonUtil.parseMap(excelExportParam, Object.class); + } + + /** + * 瀵煎嚭娌℃湁鐢虫姤鏁版嵁鐨勪汉鍛樺垪琛 + * + * @param queryParam + * @param simpleEmployee + * @return + */ + public Map exportEmployee4NoValue(AbnormalEmployeeListQueryParam queryParam, SimpleEmployee simpleEmployee) { + ExcelExportParam excelExportParam = new ExcelExportParam() + .setBiz(String.valueOf(IdGenerator.generate())) + .setModule(EntityType.hrmsalary.name()) + .setFunction("exportEmployee4NoValue"); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + taxDeclarationExcelService.exportEmployee4NoValue(excelExportParam, queryParam, simpleEmployee); + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "exportEmployee4NoValue", localRunnable); + return JsonUtil.parseMap(excelExportParam, Object.class); + } + + /** + * 瀵煎嚭鐢虫姤澶辫触鐨勪汉鍛樺垪琛 + * + * @param queryParam + * @param simpleEmployee + * @return + */ + public Map exportEmployee4Fail(AbnormalEmployeeListQueryParam queryParam, SimpleEmployee simpleEmployee) { + ExcelExportParam excelExportParam = new ExcelExportParam() + .setBiz(String.valueOf(IdGenerator.generate())) + .setModule(EntityType.hrmsalary.name()) + .setFunction("exportEmployee4Fail"); + LocalRunnable localRunnable = new LocalRunnable() { + @Override + public void execute() { + taxDeclarationExcelService.exportEmployee4Fail(excelExportParam, queryParam, simpleEmployee); + } + }; + ThreadPoolUtil.fixedPoolExecute(ModulePoolEnum.OTHER, "exportEmployee4Fail", localRunnable); + return JsonUtil.parseMap(excelExportParam, Object.class); + } +}