2023-08-11 14:20:14 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
2024-01-18 09:54:56 +08:00
|
|
|
import cn.hutool.core.util.NumberUtil;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.cloudstore.eccom.pc.table.WeaTableColumn;
|
2023-08-17 19:04:20 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
2023-08-11 14:20:14 +08:00
|
|
|
import com.engine.core.impl.Service;
|
2024-03-01 13:52:27 +08:00
|
|
|
import com.engine.salary.component.SalaryWeaTable;
|
2024-03-08 11:14:00 +08:00
|
|
|
import com.engine.salary.config.SalaryElogConfig;
|
2023-12-14 17:55:48 +08:00
|
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
2024-03-12 18:58:36 +08:00
|
|
|
import com.engine.hrmelog.entity.dto.LoggerContext;
|
2023-08-17 19:04:20 +08:00
|
|
|
import com.engine.salary.encrypt.EncryptUtil;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
|
|
|
|
import com.engine.salary.entity.employeedeclare.po.EmployeeDeclarePO;
|
|
|
|
|
import com.engine.salary.entity.extemp.po.ExtEmpPO;
|
2024-03-01 13:52:27 +08:00
|
|
|
import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveListDTO;
|
2024-03-08 11:14:00 +08:00
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.bo.TaxDeclarationValueList;
|
2024-01-23 11:23:50 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.dto.ContrastListDTO;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationValueListDTO;
|
2024-01-22 14:15:36 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.param.ContrastQueryParam;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationValueListQueryParam;
|
2023-12-14 17:55:48 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.param.TaxDeclareRecordDetailSaveParam;
|
2024-04-08 14:40:47 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.po.*;
|
2024-03-08 11:14:00 +08:00
|
|
|
import com.engine.salary.enums.OperateTypeEnum;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.enums.salaryaccounting.EmployeeTypeEnum;
|
2023-12-27 17:33:53 +08:00
|
|
|
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
|
2023-12-27 17:33:53 +08:00
|
|
|
import com.engine.salary.enums.sicategory.DeleteTypeEnum;
|
|
|
|
|
import com.engine.salary.enums.taxdeclaration.SourceEnum;
|
2023-12-14 17:55:48 +08:00
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationValueMapper;
|
2023-12-28 15:36:27 +08:00
|
|
|
import com.engine.salary.mapper.taxdeclaration.TaxDeclareRecordMapper;
|
2024-01-08 09:52:04 +08:00
|
|
|
import com.engine.salary.remote.tax.client.DeclareClient;
|
2024-03-29 10:44:55 +08:00
|
|
|
import com.engine.salary.remote.tax.response.declare.GetDeclareTaxResultFeedbackResponse;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.service.*;
|
2024-03-08 11:14:00 +08:00
|
|
|
import com.engine.salary.util.*;
|
2024-02-29 18:09:58 +08:00
|
|
|
import com.engine.salary.util.db.IdGenerator;
|
2023-08-17 19:04:20 +08:00
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
2024-02-29 18:09:58 +08:00
|
|
|
import com.engine.salary.util.excel.ExcelUtilPlus;
|
2023-08-11 14:20:14 +08:00
|
|
|
import com.engine.salary.util.page.PageInfo;
|
2023-08-14 20:07:29 +08:00
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2023-08-17 19:04:20 +08:00
|
|
|
import com.google.common.collect.Lists;
|
2023-12-27 17:33:53 +08:00
|
|
|
import com.google.common.collect.Maps;
|
2024-03-01 13:52:27 +08:00
|
|
|
import com.wbi.core.entity.WeaResultMsg;
|
2023-08-11 14:20:14 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2024-02-27 15:16:13 +08:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2024-02-29 18:09:58 +08:00
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
2024-03-08 11:14:00 +08:00
|
|
|
import org.springframework.beans.BeanUtils;
|
2024-01-18 09:54:56 +08:00
|
|
|
import weaver.general.Util;
|
2023-08-17 19:04:20 +08:00
|
|
|
import weaver.hrm.User;
|
2023-08-11 14:20:14 +08:00
|
|
|
|
2024-01-18 09:54:56 +08:00
|
|
|
import java.math.BigDecimal;
|
2023-08-11 14:20:14 +08:00
|
|
|
import java.util.*;
|
2024-01-23 11:23:50 +08:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2023-08-11 14:20:14 +08:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-07 15:15:59 +08:00
|
|
|
* 个税申报表
|
2023-08-23 16:49:45 +08:00
|
|
|
* <p>Copyright: Copyright (c) 2023</p>
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
*
|
|
|
|
|
* @author qiantao
|
|
|
|
|
* @version 1.0
|
|
|
|
|
**/
|
2023-08-11 14:20:14 +08:00
|
|
|
@Slf4j
|
|
|
|
|
public class TaxDeclarationValueServiceImpl extends Service implements TaxDeclarationValueService {
|
2023-08-17 19:04:20 +08:00
|
|
|
public EncryptUtil encryptUtil = new EncryptUtil();
|
2023-08-11 14:20:14 +08:00
|
|
|
|
2023-08-17 19:04:20 +08:00
|
|
|
private TaxDeclarationValueMapper getTaxDeclarationValueMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(TaxDeclarationValueMapper.class);
|
|
|
|
|
}
|
2023-08-20 14:03:43 +08:00
|
|
|
|
2023-12-28 15:36:27 +08:00
|
|
|
private TaxDeclareRecordMapper getTaxDeclareRecordMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(TaxDeclareRecordMapper.class);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 14:40:47 +08:00
|
|
|
private TaxDeclareStatusService getTaxDeclareStatusService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxDeclareStatusServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-17 19:04:20 +08:00
|
|
|
private SalaryEmployeeService getSalaryEmployeeService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user);
|
|
|
|
|
}
|
2023-08-20 14:03:43 +08:00
|
|
|
|
2023-08-17 19:04:20 +08:00
|
|
|
private ExtEmpService getExtEmpService(User user) {
|
|
|
|
|
return ServiceUtil.getService(ExtEmpServiceImpl.class, user);
|
|
|
|
|
}
|
2023-08-20 14:03:43 +08:00
|
|
|
|
2023-08-17 19:04:20 +08:00
|
|
|
private EmployeeDeclareService getEmployeeDeclareService(User user) {
|
|
|
|
|
return ServiceUtil.getService(EmployeeDeclareServiceImpl.class, user);
|
|
|
|
|
}
|
2023-08-20 14:03:43 +08:00
|
|
|
|
2023-08-17 19:04:20 +08:00
|
|
|
private TaxReportColumnService getTaxReportColumnService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxReportColumnServiceImpl.class, user);
|
|
|
|
|
}
|
2023-08-20 14:03:43 +08:00
|
|
|
|
2023-12-14 17:55:48 +08:00
|
|
|
private TaxDeclarationService getTaxDeclarationService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 11:14:00 +08:00
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 14:20:14 +08:00
|
|
|
@Override
|
2024-02-27 15:16:13 +08:00
|
|
|
public PageInfo<TaxDeclarationValuePO> listPageByTaxDeclarationIds(TaxDeclarationValueListQueryParam queryParam, Collection<Long> taxDeclarationIds, String keyword) {
|
2023-08-17 19:04:20 +08:00
|
|
|
List<TaxDeclarationValuePO> taxDeclarationValuePOS = getTaxDeclarationValueMapper().listSome(TaxDeclarationValuePO.builder().taxDeclarationIds(taxDeclarationIds).build());
|
2024-02-27 15:16:13 +08:00
|
|
|
// 根据关键词查人员信息
|
|
|
|
|
if (StringUtils.isNotBlank(keyword)) {
|
|
|
|
|
List<DataCollectionEmployee> employeeList = getSalaryEmployeeService(user).listByKeyword(keyword);
|
|
|
|
|
List<Long> empIds = employeeList.stream().map(DataCollectionEmployee::getEmployeeId).collect(Collectors.toList());
|
|
|
|
|
taxDeclarationValuePOS = taxDeclarationValuePOS.stream().filter(po -> empIds.contains(po.getEmployeeId())).collect(Collectors.toList());
|
|
|
|
|
}
|
2023-08-20 14:03:43 +08:00
|
|
|
taxDeclarationValuePOS = decryptBatch(taxDeclarationValuePOS);
|
2023-08-14 20:07:29 +08:00
|
|
|
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), taxDeclarationValuePOS, TaxDeclarationValuePO.class);
|
2023-08-11 14:20:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TaxDeclarationValuePO> listByTaxDeclarationIds(Collection<Long> taxDeclarationIds) {
|
2023-08-17 19:04:20 +08:00
|
|
|
List<TaxDeclarationValuePO> taxDeclarationValues = getTaxDeclarationValueMapper().listSome(TaxDeclarationValuePO.builder().taxDeclarationIds(taxDeclarationIds).build());
|
2023-08-11 14:20:14 +08:00
|
|
|
return decryptBatch(taxDeclarationValues);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 18:12:38 +08:00
|
|
|
@Override
|
|
|
|
|
public List<TaxDeclarationValuePO> listByTaxDeclarationId(Long taxDeclarationId) {
|
|
|
|
|
List<TaxDeclarationValuePO> taxDeclarationValues = getTaxDeclarationValueMapper().listSome(TaxDeclarationValuePO.builder().taxDeclarationId(taxDeclarationId).build());
|
|
|
|
|
return decryptBatch(taxDeclarationValues);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 14:20:14 +08:00
|
|
|
@Override
|
|
|
|
|
public List<TaxDeclarationValuePO> listByTaxDeclarationIdsNoDecrypt(Collection<Long> taxDeclarationIds) {
|
2023-08-17 19:04:20 +08:00
|
|
|
return getTaxDeclarationValueMapper().listSome(TaxDeclarationValuePO.builder().taxDeclarationIds(taxDeclarationIds).build());
|
2023-08-11 14:20:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public TaxDeclarationValueListDTO convert2List(TaxDeclarationPO taxDeclaration, List<TaxDeclarationValuePO> taxDeclarationValues) {
|
|
|
|
|
// 查询个税申报表表头
|
|
|
|
|
IncomeCategoryEnum incomeCategoryEnum = SalaryEnumUtil.enumMatchByValue(taxDeclaration.getIncomeCategory(), IncomeCategoryEnum.class);
|
2024-01-04 15:35:23 +08:00
|
|
|
List<TaxReportColumnPO> taxReportColumns = getTaxReportColumnService(user).listByIncomeCategory(incomeCategoryEnum, 0);
|
2023-08-11 14:20:14 +08:00
|
|
|
// 人员id
|
|
|
|
|
Set<Long> employeeIds = SalaryEntityUtil.properties(taxDeclarationValues, TaxDeclarationValuePO::getEmployeeId);
|
|
|
|
|
// 查询报送的人员
|
2023-08-17 19:04:20 +08:00
|
|
|
List<EmployeeDeclarePO> employeeDeclares = getEmployeeDeclareService(user).listByTaxCycleAndTaxAgentIdAndEmployeeIds(taxDeclaration.getTaxCycle(), taxDeclaration.getTaxAgentId(), employeeIds);
|
2023-08-11 14:20:14 +08:00
|
|
|
// 查询人员信息
|
2024-01-22 14:15:36 +08:00
|
|
|
List<Long> simpleEmployeeIds = taxDeclarationValues.stream().filter(taxDeclarationValue -> taxDeclarationValue.getEmployeeType() == null || Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.ORGANIZATION.getValue())).map(TaxDeclarationValuePO::getEmployeeId).distinct().collect(Collectors.toList());
|
2023-08-17 19:04:20 +08:00
|
|
|
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).getEmployeeByIds(simpleEmployeeIds);
|
2023-08-11 14:20:14 +08:00
|
|
|
// 查询人员薪资(身份证号码等)
|
2023-08-17 19:04:20 +08:00
|
|
|
List<DataCollectionEmployee> simpleUserInfos = getSalaryEmployeeService(user).getEmployeeByIds(simpleEmployeeIds);
|
2023-08-11 14:20:14 +08:00
|
|
|
// 查询外部人员
|
2024-01-22 14:15:36 +08:00
|
|
|
List<Long> extEmployeeIds = taxDeclarationValues.stream().filter(taxDeclarationValue -> Objects.equals(taxDeclarationValue.getEmployeeType(), EmployeeTypeEnum.EXT_EMPLOYEE.getValue())).map(TaxDeclarationValuePO::getEmployeeId).collect(Collectors.toList());
|
2023-08-17 19:04:20 +08:00
|
|
|
List<ExtEmpPO> extEmployees = getExtEmpService(user).getExtEmpByIds(extEmployeeIds);
|
2023-08-11 14:20:14 +08:00
|
|
|
|
|
|
|
|
// 列表表头
|
|
|
|
|
List<WeaTableColumn> weaTableColumns = TaxDeclarationValueList.buildTableColumns(taxReportColumns);
|
|
|
|
|
// 列表数据
|
2024-01-22 14:15:36 +08:00
|
|
|
List<Map<String, Object>> data = TaxDeclarationValueList.buildTableData(incomeCategoryEnum, taxReportColumns, taxDeclarationValues, employeeDeclares, simpleEmployees, simpleUserInfos, extEmployees, false);
|
2023-08-11 14:20:14 +08:00
|
|
|
|
|
|
|
|
return new TaxDeclarationValueListDTO().setColumns(weaTableColumns).setData(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void batchSave(List<TaxDeclarationValuePO> taxDeclarationValues) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(taxDeclarationValues)) {
|
2023-08-17 19:04:20 +08:00
|
|
|
// 加密
|
2024-01-22 14:15:36 +08:00
|
|
|
taxDeclarationValues.forEach(taxDeclarationValue -> taxDeclarationValue.setResultValueJson(JsonUtil.toJsonString(taxDeclarationValue.getResultValue())));
|
2023-08-17 19:04:20 +08:00
|
|
|
taxDeclarationValues = encryptUtil.encryptList(taxDeclarationValues, TaxDeclarationValuePO.class);
|
|
|
|
|
// 分批保存
|
|
|
|
|
List<List<TaxDeclarationValuePO>> partition = Lists.partition(taxDeclarationValues, 100);
|
|
|
|
|
for (List<TaxDeclarationValuePO> subTaxDeclarationValues : partition) {
|
2023-08-20 14:03:43 +08:00
|
|
|
subTaxDeclarationValues.forEach(getTaxDeclarationValueMapper()::insertIgnoreNull);
|
2023-12-28 18:12:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void batchEdit(List<TaxDeclarationValuePO> taxDeclarationValues) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(taxDeclarationValues)) {
|
|
|
|
|
// 加密
|
2024-01-22 14:15:36 +08:00
|
|
|
taxDeclarationValues.forEach(taxDeclarationValue -> taxDeclarationValue.setResultValueJson(JsonUtil.toJsonString(taxDeclarationValue.getResultValue())));
|
2023-12-28 18:12:38 +08:00
|
|
|
taxDeclarationValues = encryptUtil.encryptList(taxDeclarationValues, TaxDeclarationValuePO.class);
|
|
|
|
|
// 分批保存
|
|
|
|
|
List<List<TaxDeclarationValuePO>> partition = Lists.partition(taxDeclarationValues, 100);
|
|
|
|
|
for (List<TaxDeclarationValuePO> subTaxDeclarationValues : partition) {
|
|
|
|
|
subTaxDeclarationValues.forEach(getTaxDeclarationValueMapper()::updateIgnoreNull);
|
2023-08-17 19:04:20 +08:00
|
|
|
}
|
2023-08-11 14:20:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-14 17:55:48 +08:00
|
|
|
@Override
|
|
|
|
|
public void save(TaxDeclareRecordDetailSaveParam param) {
|
|
|
|
|
TaxDeclarationPO taxDeclaration = getTaxDeclarationService(user).getById(param.getTaxDeclarationId());
|
2023-12-27 17:33:53 +08:00
|
|
|
if (taxDeclaration == null) {
|
2023-12-14 17:55:48 +08:00
|
|
|
throw new SalaryRunTimeException("个税申报表不存在!");
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 15:36:27 +08:00
|
|
|
Long taxDeclareRecordId = taxDeclaration.getTaxDeclareRecordId();
|
|
|
|
|
TaxDeclareRecordPO declareRecordPO = getTaxDeclareRecordMapper().getById(taxDeclareRecordId);
|
|
|
|
|
if (declareRecordPO == null) {
|
|
|
|
|
throw new SalaryRunTimeException("个税申报记录不存在!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-22 14:15:36 +08:00
|
|
|
TaxDeclarationValuePO po = TaxDeclarationValuePO.builder().id(IdGenerator.generate()).taxDeclarationId(param.getTaxDeclarationId()).taxDeclareRecordId(taxDeclareRecordId).employeeId(param.getEmployeeId()).employeeType(param.getEmployeeType()).resultValue(param.getTaxReportColumnValues()).resultValueJson(JsonUtil.toJsonString(param.getTaxReportColumnValues())).createTime(new Date()).updateTime(new Date()).source(SourceEnum.ADD.getValue()).creator((long) user.getUID()).deleteType(0).tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY).build();
|
2024-03-08 11:14:00 +08:00
|
|
|
TaxDeclarationValuePO po4log = new TaxDeclarationValuePO();
|
|
|
|
|
BeanUtils.copyProperties(po,po4log);
|
2023-12-14 17:55:48 +08:00
|
|
|
encryptUtil.encrypt(po, TaxDeclarationValuePO.class);
|
|
|
|
|
getTaxDeclarationValueMapper().insertIgnoreNull(po);
|
|
|
|
|
|
2024-03-08 11:14:00 +08:00
|
|
|
// 记录日志
|
|
|
|
|
TaxAgentPO taxAgent = getTaxAgentService(user).getById(taxDeclaration.getTaxAgentId());
|
|
|
|
|
LoggerContext<TaxDeclarationPO> loggerContext = new LoggerContext<>();
|
|
|
|
|
loggerContext.setUser(user);
|
|
|
|
|
loggerContext.setTargetId(po.getTaxDeclareRecordId().toString());
|
|
|
|
|
loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(0, "个税扣缴义务人「{0}」,税款所属期「{1}」,人员id「{3}」")
|
|
|
|
|
.replace("{0}", taxAgent.getName())
|
|
|
|
|
.replace("{1}", SalaryDateUtil.getFormatYearMonth(declareRecordPO.getTaxCycle()))
|
|
|
|
|
.replace("{2}", po.getEmployeeId().toString()));
|
|
|
|
|
loggerContext.setOperateType(OperateTypeEnum.ADD.getValue());
|
|
|
|
|
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel( 0, "新增人员"));
|
|
|
|
|
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel( 0, "新增人员"));
|
|
|
|
|
loggerContext.setNewValues(po4log);
|
|
|
|
|
SalaryElogConfig.taxDeclarationLoggerTemplate.write(loggerContext);
|
|
|
|
|
|
2023-12-28 15:36:27 +08:00
|
|
|
//新增年终奖
|
|
|
|
|
if (IncomeCategoryEnum.ONETIME_ANNUAL_BONUS.getValue().equals(taxDeclaration.getIncomeCategory())) {
|
|
|
|
|
autoAddWagesDeclare(declareRecordPO);
|
|
|
|
|
}
|
2023-12-14 17:55:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void edit(TaxDeclareRecordDetailSaveParam param) {
|
|
|
|
|
TaxDeclarationValuePO po = getById(param.getId());
|
2024-03-08 11:14:00 +08:00
|
|
|
TaxDeclarationValuePO oldPo = new TaxDeclarationValuePO();
|
|
|
|
|
BeanUtils.copyProperties(po, oldPo);
|
2023-12-14 17:55:48 +08:00
|
|
|
po.setResultValue(param.getTaxReportColumnValues());
|
|
|
|
|
po.setResultValueJson(JsonUtil.toJsonString(param.getTaxReportColumnValues()));
|
|
|
|
|
po.setUpdateTime(new Date());
|
2023-12-27 17:33:53 +08:00
|
|
|
po.setSource(SourceEnum.EDIT.getValue());
|
2023-12-14 17:55:48 +08:00
|
|
|
encryptUtil.encrypt(po, TaxDeclarationValuePO.class);
|
|
|
|
|
getTaxDeclarationValueMapper().updateIgnoreNull(po);
|
2024-03-08 11:14:00 +08:00
|
|
|
TaxDeclarationValuePO po4log = getTaxDeclarationValueMapper().getById(po.getId());
|
|
|
|
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
TaxDeclareRecordPO taxDeclareRecordPO = getTaxDeclareRecordMapper().getById(po.getTaxDeclareRecordId());
|
|
|
|
|
TaxAgentPO taxAgent = getTaxAgentService(user).getById(taxDeclareRecordPO.getTaxAgentId());
|
|
|
|
|
LoggerContext<TaxDeclarationValuePO> loggerContext = new LoggerContext<>();
|
|
|
|
|
loggerContext.setUser(user);
|
|
|
|
|
loggerContext.setTargetId(po.getTaxDeclareRecordId().toString());
|
|
|
|
|
loggerContext.setTargetName(SalaryI18nUtil.getI18nLabel(0, "个税扣缴义务人「{0}」税款所属期「{1}」人员id「{3}」")
|
|
|
|
|
.replace("{0}", taxAgent.getName())
|
|
|
|
|
.replace("{1}", SalaryDateUtil.getFormatYearMonth(taxDeclareRecordPO.getTaxCycle()))
|
|
|
|
|
.replace("{2}", po.getEmployeeId().toString()));
|
|
|
|
|
loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue());
|
|
|
|
|
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel( 0, "修改个税申报数据"));
|
|
|
|
|
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel( 0, "修改个税申报数据"));
|
|
|
|
|
loggerContext.setOldValues(oldPo);
|
|
|
|
|
loggerContext.setNewValues(po4log);
|
|
|
|
|
SalaryElogConfig.taxDeclarationLoggerTemplate.write(loggerContext);
|
2023-12-14 17:55:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public TaxDeclarationValuePO getById(Long id) {
|
|
|
|
|
TaxDeclarationValuePO po = getTaxDeclarationValueMapper().getById(id);
|
2023-12-27 17:33:53 +08:00
|
|
|
if (po == null) {
|
2023-12-14 17:55:48 +08:00
|
|
|
throw new SalaryRunTimeException("个税申报明细不存在!");
|
|
|
|
|
}
|
2023-12-27 17:33:53 +08:00
|
|
|
encryptUtil.decrypt(po, TaxDeclarationValuePO.class);
|
2023-12-14 17:55:48 +08:00
|
|
|
po.setResultValue(JsonUtil.parseMap(po.getResultValueJson(), String.class));
|
|
|
|
|
|
|
|
|
|
return po;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 14:20:14 +08:00
|
|
|
@Override
|
|
|
|
|
public void deleteByTaxDeclareRecordIds(Collection<Long> taxDeclareRecordIds) {
|
|
|
|
|
if (CollectionUtils.isEmpty(taxDeclareRecordIds)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-17 19:04:20 +08:00
|
|
|
getTaxDeclarationValueMapper().deleteBytaxDeclareRecordIds(taxDeclareRecordIds);
|
2023-08-11 14:20:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TaxDeclarationValuePO> decryptBatch(List<TaxDeclarationValuePO> taxDeclarationValues) {
|
|
|
|
|
if (CollectionUtils.isEmpty(taxDeclarationValues)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
2023-08-17 19:04:20 +08:00
|
|
|
// 解密
|
|
|
|
|
taxDeclarationValues = encryptUtil.decryptList(taxDeclarationValues, TaxDeclarationValuePO.class);
|
|
|
|
|
taxDeclarationValues.forEach(salaryAcctResultValue -> {
|
|
|
|
|
salaryAcctResultValue.setResultValue(JsonUtil.parseMap(salaryAcctResultValue.getResultValueJson(), String.class));
|
|
|
|
|
});
|
2023-08-11 14:20:14 +08:00
|
|
|
return taxDeclarationValues;
|
|
|
|
|
}
|
2023-12-27 17:33:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void autoAddWagesDeclare(TaxDeclareRecordPO taxDeclareRecord) {
|
|
|
|
|
|
|
|
|
|
Long taxDeclareRecordId = taxDeclareRecord.getId();
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
|
|
|
|
//非正常薪资的人员
|
|
|
|
|
List<Long> notWagesEmpIds = getTaxDeclarationValueMapper().queryNotWagesEmpIds(taxDeclareRecordId);
|
|
|
|
|
if (CollectionUtils.isEmpty(notWagesEmpIds)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//正常薪资人员
|
|
|
|
|
List<Long> wagesEmpIds = getTaxDeclarationValueMapper().queryWagesEmpIds(taxDeclareRecordId);
|
|
|
|
|
|
|
|
|
|
//比较差异
|
|
|
|
|
List<Long> autoAddIds = notWagesEmpIds.stream().filter(id -> !wagesEmpIds.contains(id)).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(autoAddIds)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//正常薪资的表头
|
2024-01-04 15:35:23 +08:00
|
|
|
List<TaxReportColumnPO> taxReportColumns = getTaxReportColumnService(user).listByIncomeCategory(IncomeCategoryEnum.WAGES_AND_SALARIES, 0);
|
2023-12-27 17:33:53 +08:00
|
|
|
Map<String, String> valueMap = Maps.newHashMap();
|
|
|
|
|
for (TaxReportColumnPO taxReportColumn : taxReportColumns) {
|
|
|
|
|
String value = Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue()) ? "0.00" : "";
|
|
|
|
|
valueMap.put(taxReportColumn.getReportColumnDataIndex(), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//当前申报表是否含正常申报
|
|
|
|
|
List<TaxDeclarationPO> list = getTaxDeclarationService(user).listByTaxDeclareRecordId(taxDeclareRecordId, IncomeCategoryEnum.WAGES_AND_SALARIES.getValue());
|
|
|
|
|
TaxDeclarationPO taxDeclarationPO;
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
|
if (list.size() > 1) {
|
|
|
|
|
throw new SalaryRunTimeException("存在多条正常工资薪金申报表数据");
|
|
|
|
|
}
|
|
|
|
|
taxDeclarationPO = list.get(0);
|
|
|
|
|
} else {
|
2024-01-22 14:15:36 +08:00
|
|
|
taxDeclarationPO = TaxDeclarationPO.builder().id(IdGenerator.generate()).taxDeclareRecordId(taxDeclareRecordId).incomeCategory(IncomeCategoryEnum.WAGES_AND_SALARIES.getValue()).taxAgentId(taxDeclareRecord.getTaxAgentId()).salaryMonth(taxDeclareRecord.getSalaryMonth()).taxCycle(taxDeclareRecord.getTaxCycle()).description(taxDeclareRecord.getRemark()).controlView(0).creator((long) user.getUID()).createTime(now).updateTime(now).deleteType(DeleteTypeEnum.NOT_DELETED.getValue()).tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY).build();
|
2023-12-27 17:33:53 +08:00
|
|
|
List<TaxDeclarationPO> taxList = new ArrayList<>();
|
|
|
|
|
getTaxDeclarationService(user).saveBatch(taxList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//组装数据,自动补足
|
|
|
|
|
List<TaxDeclarationValuePO> autoAddValuePOs = autoAddIds.stream().map((empId -> {
|
2024-01-22 14:15:36 +08:00
|
|
|
TaxDeclarationValuePO taxDeclarationValue = TaxDeclarationValuePO.builder().id(IdGenerator.generate()).taxDeclareRecordId(taxDeclarationPO.getTaxDeclareRecordId()).taxDeclarationId(taxDeclarationPO.getId()).employeeType(0).employeeId(empId).resultValue(valueMap).tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY).creator((long) user.getUID()).deleteType(DeleteTypeEnum.NOT_DELETED.getValue()).createTime(now).updateTime(now).source(SourceEnum.AUTO.getValue()).build();
|
2023-12-27 17:33:53 +08:00
|
|
|
return taxDeclarationValue;
|
|
|
|
|
})).collect(Collectors.toList());
|
|
|
|
|
batchSave(autoAddValuePOs);
|
|
|
|
|
}
|
2024-01-04 15:35:23 +08:00
|
|
|
|
2024-02-02 14:48:01 +08:00
|
|
|
@Override
|
|
|
|
|
public void deleteById(Long deleteId) {
|
|
|
|
|
getTaxDeclarationValueMapper().deleteByIds(Collections.singletonList(deleteId));
|
|
|
|
|
}
|
2023-08-11 14:20:14 +08:00
|
|
|
}
|