2022-04-18 18:56:17 +08:00
|
|
|
|
package com.engine.salary.service.impl;
|
2022-06-15 16:02:34 +08:00
|
|
|
|
|
2022-04-18 18:56:17 +08:00
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
|
import com.engine.core.impl.Service;
|
2024-02-21 18:19:02 +08:00
|
|
|
|
import com.engine.salary.config.SalaryElogConfig;
|
2024-03-12 14:34:44 +08:00
|
|
|
|
import com.engine.hrmelog.entity.dto.LoggerContext;
|
2024-02-21 18:19:02 +08:00
|
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
2023-01-31 14:15:27 +08:00
|
|
|
|
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationAnnualListDTO;
|
2022-06-15 16:02:34 +08:00
|
|
|
|
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationLaborListDTO;
|
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationWageListDTO;
|
2022-04-18 18:56:17 +08:00
|
|
|
|
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationDetailListQueryParam;
|
2022-06-15 16:02:34 +08:00
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO;
|
2024-02-21 18:19:02 +08:00
|
|
|
|
import com.engine.salary.enums.OperateTypeEnum;
|
2022-06-15 16:02:34 +08:00
|
|
|
|
import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
|
2022-04-18 18:56:17 +08:00
|
|
|
|
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationDetailMapper;
|
2024-02-21 18:19:02 +08:00
|
|
|
|
import com.engine.salary.service.TaxAgentService;
|
2022-04-18 18:56:17 +08:00
|
|
|
|
import com.engine.salary.service.TaxDeclarationDetailService;
|
|
|
|
|
|
import com.engine.salary.service.TaxDeclarationExcelService;
|
|
|
|
|
|
import com.engine.salary.service.TaxDeclarationService;
|
|
|
|
|
|
import com.engine.salary.util.JsonUtil;
|
2024-02-21 18:19:02 +08:00
|
|
|
|
import com.engine.salary.util.SalaryDateUtil;
|
2022-04-18 18:56:17 +08:00
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
|
|
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
|
|
|
|
import com.engine.salary.util.excel.ExcelUtil;
|
|
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
2022-06-15 16:02:34 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Objects;
|
2022-04-18 18:56:17 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-15 16:31:40 +08:00
|
|
|
|
* 个税申报表导出
|
|
|
|
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author qiantao
|
|
|
|
|
|
* @version 1.0
|
|
|
|
|
|
**/
|
2022-04-18 18:56:17 +08:00
|
|
|
|
@Slf4j
|
|
|
|
|
|
public class TaxDeclarationExcelServiceImpl extends Service implements TaxDeclarationExcelService {
|
|
|
|
|
|
|
|
|
|
|
|
private TaxDeclarationDetailService getTaxDeclarationDetailService(User user) {
|
2022-06-15 16:02:34 +08:00
|
|
|
|
return ServiceUtil.getService(TaxDeclarationDetailServiceImpl.class, user);
|
2022-04-18 18:56:17 +08:00
|
|
|
|
}
|
2022-06-15 16:02:34 +08:00
|
|
|
|
private TaxDeclarationDetailMapper getTaxDeclarationDetailMapper() {
|
2022-04-18 18:56:17 +08:00
|
|
|
|
return MapperProxyFactory.getProxy(TaxDeclarationDetailMapper.class);
|
|
|
|
|
|
}
|
2022-06-15 16:02:34 +08:00
|
|
|
|
private TaxDeclarationService getTaxDeclarationService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-21 18:19:02 +08:00
|
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-15 16:02:34 +08:00
|
|
|
|
|
2022-04-18 18:56:17 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public XSSFWorkbook exportTaxDeclaration(Long taxDeclarationId) {
|
|
|
|
|
|
// 1.工作簿名称
|
|
|
|
|
|
String sheetName = SalaryI18nUtil.getI18nLabel(85368, "个税申报表");
|
2022-06-15 16:02:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TaxDeclarationPO taxDeclarationPO = getTaxDeclarationService(user).getById(taxDeclarationId);
|
2022-04-18 18:56:17 +08:00
|
|
|
|
// 查询当前个税申报表一共有多少人员
|
2022-06-15 16:02:34 +08:00
|
|
|
|
int count = getTaxDeclarationDetailMapper().countEmployeeId(taxDeclarationId);
|
2022-04-18 18:56:17 +08:00
|
|
|
|
// 以1000个人员一页,一共有多少页
|
2022-06-15 16:02:34 +08:00
|
|
|
|
int totalPages = (count % 1000 == 0) ? (count / 1000) : (count / 1000 + 1); //总页数
|
2022-04-18 18:56:17 +08:00
|
|
|
|
// excel导出的数据
|
|
|
|
|
|
List<List<Object>> rows = Lists.newArrayListWithExpectedSize(count);
|
2022-06-15 16:02:34 +08:00
|
|
|
|
List<Object> headerList = Lists.newArrayList();
|
|
|
|
|
|
List<String> dataIndexList = Lists.newArrayList();
|
|
|
|
|
|
if (Objects.equals(taxDeclarationPO.getIncomeCategory(), IncomeCategoryEnum.WAGES_AND_SALARIES.getValue())) {
|
|
|
|
|
|
// 解析表头
|
2023-12-28 15:47:05 +08:00
|
|
|
|
ExcelUtil.parseHeader(TaxDeclarationWageListDTO.class, headerList, dataIndexList);
|
2022-06-15 16:02:34 +08:00
|
|
|
|
rows.add(headerList);
|
|
|
|
|
|
for (int i = 0; i < totalPages; i++) {
|
|
|
|
|
|
TaxDeclarationDetailListQueryParam queryParam = new TaxDeclarationDetailListQueryParam();
|
|
|
|
|
|
queryParam.setTaxDeclarationId(taxDeclarationId);
|
2022-11-03 10:36:50 +08:00
|
|
|
|
queryParam.setCurrent(i+1);
|
2022-06-15 16:02:34 +08:00
|
|
|
|
queryParam.setPageSize(1000);
|
|
|
|
|
|
PageInfo<TaxDeclarationWageListDTO> dtoPage = getTaxDeclarationDetailService(user).listDtoPageByParam4Wage(queryParam);
|
|
|
|
|
|
List<TaxDeclarationWageListDTO> list = dtoPage.getList();
|
|
|
|
|
|
for (TaxDeclarationWageListDTO taxDeclarationWageListDTO : list) {
|
|
|
|
|
|
List<Object> row = Lists.newArrayListWithExpectedSize(dataIndexList.size());
|
|
|
|
|
|
Map<String, Object> map = JsonUtil.parseMap(taxDeclarationWageListDTO, Object.class);
|
|
|
|
|
|
for (String dataIndex : dataIndexList) {
|
|
|
|
|
|
row.add(map.get(dataIndex));
|
|
|
|
|
|
}
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Objects.equals(taxDeclarationPO.getIncomeCategory(), IncomeCategoryEnum.REMUNERATION_FOR_LABOR.getValue())) {
|
|
|
|
|
|
// 解析表头
|
2023-12-28 15:47:05 +08:00
|
|
|
|
ExcelUtil.parseHeader(TaxDeclarationLaborListDTO.class, headerList, dataIndexList);
|
2022-06-15 16:02:34 +08:00
|
|
|
|
rows.add(headerList);
|
|
|
|
|
|
for (int i = 0; i < totalPages; i++) {
|
|
|
|
|
|
TaxDeclarationDetailListQueryParam queryParam = new TaxDeclarationDetailListQueryParam();
|
|
|
|
|
|
queryParam.setTaxDeclarationId(taxDeclarationId);
|
|
|
|
|
|
queryParam.setCurrent(i);
|
|
|
|
|
|
queryParam.setPageSize(1000);
|
|
|
|
|
|
PageInfo<TaxDeclarationLaborListDTO> dtoPage = getTaxDeclarationDetailService(user).listDtoPageByParam4Labor(queryParam);
|
|
|
|
|
|
List<TaxDeclarationLaborListDTO> list = dtoPage.getList();
|
|
|
|
|
|
for (TaxDeclarationLaborListDTO taxDeclarationLaborListDTO : list) {
|
|
|
|
|
|
List<Object> row = Lists.newArrayListWithExpectedSize(dataIndexList.size());
|
|
|
|
|
|
Map<String, Object> map = JsonUtil.parseMap(taxDeclarationLaborListDTO, Object.class);
|
2023-01-31 14:15:27 +08:00
|
|
|
|
for (String dataIndex : dataIndexList) {
|
|
|
|
|
|
row.add(map.get(dataIndex));
|
|
|
|
|
|
}
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(taxDeclarationPO.getIncomeCategory(), IncomeCategoryEnum.ONETIME_ANNUAL_BONUS.getValue())) {
|
|
|
|
|
|
// 解析表头
|
2023-12-28 15:47:05 +08:00
|
|
|
|
ExcelUtil.parseHeader(TaxDeclarationAnnualListDTO.class, headerList, dataIndexList);
|
2023-01-31 14:15:27 +08:00
|
|
|
|
rows.add(headerList);
|
|
|
|
|
|
for (int i = 0; i < totalPages; i++) {
|
|
|
|
|
|
TaxDeclarationDetailListQueryParam queryParam = new TaxDeclarationDetailListQueryParam();
|
|
|
|
|
|
queryParam.setTaxDeclarationId(taxDeclarationId);
|
|
|
|
|
|
queryParam.setCurrent(i);
|
|
|
|
|
|
queryParam.setPageSize(1000);
|
|
|
|
|
|
PageInfo<TaxDeclarationAnnualListDTO> dtoPage = getTaxDeclarationDetailService(user).listDtoPageByParam4Annual(queryParam);
|
|
|
|
|
|
List<TaxDeclarationAnnualListDTO> list = dtoPage.getList();
|
|
|
|
|
|
for (TaxDeclarationAnnualListDTO taxDeclarationLaborListDTO : list) {
|
|
|
|
|
|
List<Object> row = Lists.newArrayListWithExpectedSize(dataIndexList.size());
|
|
|
|
|
|
Map<String, Object> map = JsonUtil.parseMap(taxDeclarationLaborListDTO, Object.class);
|
2022-06-15 16:02:34 +08:00
|
|
|
|
for (String dataIndex : dataIndexList) {
|
|
|
|
|
|
row.add(map.get(dataIndex));
|
|
|
|
|
|
}
|
|
|
|
|
|
rows.add(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-04-18 18:56:17 +08:00
|
|
|
|
}
|
2024-02-21 18:19:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 查询个税扣缴义务人名称
|
|
|
|
|
|
String bar = "_";
|
|
|
|
|
|
TaxAgentPO taxAgentPO = getTaxAgentService(user).getById(taxDeclarationPO.getTaxAgentId());
|
|
|
|
|
|
String targetName = SalaryDateUtil.getFormatYearMonth(taxDeclarationPO.getSalaryMonth()) + bar + taxAgentPO.getName() + bar + IncomeCategoryEnum.parseByValue(taxDeclarationPO.getIncomeCategory()).getDefaultLabel();
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
|
LoggerContext<TaxDeclarationPO> loggerContext = new LoggerContext<>();
|
|
|
|
|
|
loggerContext.setUser(user);
|
|
|
|
|
|
loggerContext.setTargetId(taxDeclarationId.toString());
|
|
|
|
|
|
loggerContext.setTargetName(targetName);
|
|
|
|
|
|
loggerContext.setOperateType(OperateTypeEnum.EXCEL_EXPORT.getValue());
|
|
|
|
|
|
loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel( 0, "导出个税申报表"));
|
|
|
|
|
|
loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel( 0, "导出个税申报表"));
|
|
|
|
|
|
SalaryElogConfig.taxDeclarationLoggerTemplate.write(loggerContext);
|
2022-04-18 18:56:17 +08:00
|
|
|
|
return ExcelUtil.genWorkbookV2(rows, sheetName);
|
|
|
|
|
|
}
|
2022-06-15 16:02:34 +08:00
|
|
|
|
|
2022-04-18 18:56:17 +08:00
|
|
|
|
}
|