weaver-hrm-salary/src/com/engine/salary/service/impl/TaxDeclarationExcelServiceI...

180 lines
8.2 KiB
Java
Raw Normal View History

2022-04-18 18:56:17 +08:00
package com.engine.salary.service.impl;
2022-06-15 16:02:34 +08:00
2023-08-23 18:13:31 +08:00
import com.cloudstore.eccom.pc.table.WeaTableColumn;
2022-04-18 18:56:17 +08:00
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
2022-06-15 16:02:34 +08:00
import com.engine.salary.annotation.SalaryTableColumn;
2023-08-23 18:13:31 +08:00
import com.engine.salary.entity.taxdeclaration.dto.AbnormalEmployeeListDTO;
import com.engine.salary.entity.taxdeclaration.dto.FailEmployeeListDTO;
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationValueListDTO;
import com.engine.salary.entity.taxdeclaration.param.AbnormalEmployeeListQueryParam;
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationValueListQueryParam;
import com.engine.salary.entity.taxdeclaration.po.*;
import com.engine.salary.service.*;
2022-04-18 18:56:17 +08:00
import com.engine.salary.util.JsonUtil;
import com.engine.salary.util.SalaryI18nUtil;
2023-08-23 18:13:31 +08:00
import com.engine.salary.util.excel.ExcelSheetData;
2022-04-18 18:56:17 +08:00
import com.engine.salary.util.excel.ExcelUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2023-08-23 18:13:31 +08:00
import weaver.general.Util;
2022-04-18 18:56:17 +08:00
import weaver.hrm.User;
2022-06-15 16:02:34 +08:00
import java.lang.reflect.Field;
2023-08-23 18:13:31 +08:00
import java.util.Collections;
2022-06-15 16:02:34 +08:00
import java.util.List;
import java.util.Map;
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 {
2022-06-15 16:02:34 +08:00
private TaxDeclarationService getTaxDeclarationService(User user) {
return ServiceUtil.getService(TaxDeclarationServiceImpl.class, user);
}
2023-08-23 18:13:31 +08:00
private TaxDeclarationValueService getTaxDeclarationValueService(User user) {
return ServiceUtil.getService(TaxDeclarationValueServiceImpl.class, user);
}
2022-06-15 16:02:34 +08:00
2023-08-23 18:13:31 +08:00
private TaxDeclareRecordService getTaxDeclareRecordService(User user) {
return ServiceUtil.getService(TaxDeclareRecordServiceImpl.class, user);
}
2022-04-18 18:56:17 +08:00
2023-08-23 18:13:31 +08:00
private TaxDeclareEmployeeService getTaxDeclareEmployeeService(User user) {
return ServiceUtil.getService(TaxDeclareEmployeeServiceImpl.class, user);
}
2022-06-15 16:02:34 +08:00
2023-08-23 18:13:31 +08:00
private TaxDeclareFailService getTaxDeclareFailService(User user) {
return ServiceUtil.getService(TaxDeclareFailServiceImpl.class, user);
}
2022-06-15 16:02:34 +08:00
2023-08-23 18:13:31 +08:00
@Override
public XSSFWorkbook exportTaxDeclarationValue(TaxDeclarationValueListQueryParam queryParam) {
// 查询个税申报表
TaxDeclarationPO taxDeclarationPO = getTaxDeclarationService(user).getById(queryParam.getTaxDeclarationId());
// 查询个税申报表明细
List<TaxDeclarationValuePO> taxDeclarationValues = getTaxDeclarationValueService(user).listByTaxDeclarationIds(Collections.singleton(queryParam.getTaxDeclarationId()));
// 转成个税申报表明细
TaxDeclarationValueListDTO taxDeclarationValueListDTO = getTaxDeclarationValueService(user).convert2List(taxDeclarationPO, taxDeclarationValues);
2022-04-18 18:56:17 +08:00
// excel导出的数据
2023-08-23 18:13:31 +08:00
List<List<String>> rows = Lists.newArrayList();
List<String> headerList = Lists.newArrayList();
2022-06-15 16:02:34 +08:00
List<String> dataIndexList = Lists.newArrayList();
2023-08-23 18:13:31 +08:00
// 解析表头
for (WeaTableColumn column : taxDeclarationValueListDTO.getColumns()) {
headerList.add(column.getText());
dataIndexList.add(column.getColumn());
2023-01-31 14:15:27 +08:00
}
2023-08-23 18:13:31 +08:00
rows.add(headerList);
// 解析表中数据
for (Map<String, Object> datum : taxDeclarationValueListDTO.getData()) {
List<String> row = Lists.newArrayList();
for (String dataIndex : dataIndexList) {
row.add(Util.null2String(datum.get(dataIndex)));
2022-06-15 16:02:34 +08:00
}
2023-08-23 18:13:31 +08:00
rows.add(row);
2022-04-18 18:56:17 +08:00
}
2023-08-23 18:13:31 +08:00
String sheetName = SalaryI18nUtil.getI18nLabel(100090, "个税申报表");
return ExcelUtil.genWorkbook(rows, sheetName);
2022-04-18 18:56:17 +08:00
}
2022-06-15 16:02:34 +08:00
2023-08-23 18:13:31 +08:00
@Override
public XSSFWorkbook exportEmployee4NotDeclare(AbnormalEmployeeListQueryParam queryParam) {
// 查询个税申报记录
TaxDeclareRecordPO taxDeclareRecord = getTaxDeclareRecordService(user).getById(queryParam.getTaxDeclareRecordId());
queryParam.setTaxAgentId(taxDeclareRecord.getTaxAgentId());
queryParam.setTaxCycle(taxDeclareRecord.getTaxCycle());
// 查询个税申报表明细中的人员
List<TaxDeclareEmployeePO> taxDeclareEmployees = getTaxDeclareEmployeeService(user).list4NotDeclareByParam(queryParam);
// 转换成列表dto
List<AbnormalEmployeeListDTO> dtoList = getTaxDeclareEmployeeService(user).convert2AbnormalEmployeeList(taxDeclareRecord, taxDeclareEmployees);
ExcelSheetData excelSheetData = getExcelSheetData(AbnormalEmployeeListDTO.class, dtoList);
return ExcelUtil.genWorkbook(excelSheetData);
}
@Override
public XSSFWorkbook exportEmployee4NoValue(AbnormalEmployeeListQueryParam queryParam) {
// 查询个税申报记录
TaxDeclareRecordPO taxDeclareRecord = getTaxDeclareRecordService(user).getById(queryParam.getTaxDeclareRecordId());
queryParam.setTaxAgentId(taxDeclareRecord.getTaxAgentId());
queryParam.setTaxCycle(taxDeclareRecord.getTaxCycle());
// 查询个税申报表明细中的人员
List<TaxDeclareEmployeePO> taxDeclareEmployees = getTaxDeclareEmployeeService(user).list4NoValueByParam(queryParam);
// 转换成列表dto
List<AbnormalEmployeeListDTO> dtoList = getTaxDeclareEmployeeService(user).convert2AbnormalEmployeeList(taxDeclareRecord, taxDeclareEmployees);
ExcelSheetData excelSheetData = getExcelSheetData(AbnormalEmployeeListDTO.class, dtoList);
return ExcelUtil.genWorkbook(excelSheetData);
}
@Override
public XSSFWorkbook exportEmployee4Fail(AbnormalEmployeeListQueryParam queryParam) {
// 查询个税申报记录
TaxDeclareRecordPO taxDeclareRecord = getTaxDeclareRecordService(user).getById(queryParam.getTaxDeclareRecordId());
queryParam.setTaxAgentId(taxDeclareRecord.getTaxAgentId());
queryParam.setTaxCycle(taxDeclareRecord.getTaxCycle());
// 查询个税申报表明细中的人员
List<TaxDeclareFailPO> taxDeclareFails = getTaxDeclareFailService(user).listByTaxDeclareRecordIds(Collections.singleton(taxDeclareRecord.getId()));
// 转换成列表dto
List<FailEmployeeListDTO> dtoList = getTaxDeclareFailService(user).convert2FailEmployeeList(taxDeclareRecord, taxDeclareFails);
ExcelSheetData excelSheetData = getExcelSheetData(FailEmployeeListDTO.class, dtoList);
return ExcelUtil.genWorkbook(excelSheetData);
}
private <T> ExcelSheetData getExcelSheetData(Class<T> clazz, List<T> dtoList) {
// 导出的表头
List<String> headerList = Lists.newArrayList();
List<String> dataIndexList = Lists.newArrayList();
parseHeader(clazz, headerList, dataIndexList);
// 导出的数据
List<List<Object>> rows = Lists.newArrayListWithExpectedSize(dtoList.size());
dtoList.forEach(dto -> {
Map<String, Object> map = JsonUtil.parseMap(dto, Object.class);
List<Object> row = Lists.newArrayListWithExpectedSize(dataIndexList.size());
dataIndexList.forEach(dataIndex -> row.add(map.get(dataIndex)));
rows.add(row);
});
// 组装excel导出数据
ExcelSheetData excelSheetData = new ExcelSheetData();
excelSheetData.setSheetName(SalaryI18nUtil.getI18nLabel(156423, "个税申报表人员"));
excelSheetData.setHeaders(headerList);
excelSheetData.setRows(rows);
return excelSheetData;
}
2022-06-15 16:02:34 +08:00
/**
* 解析表头
*
* @param clazz
* @param headerList
* @param dataIndexList
* @param <T>
*/
2023-08-23 18:13:31 +08:00
private <T> void parseHeader(Class<T> clazz, List<String> headerList, List<String> dataIndexList) {
2022-06-15 16:02:34 +08:00
Field[] declaredFields = clazz.getDeclaredFields();
for (Field declaredField : declaredFields) {
if (!declaredField.isAnnotationPresent(SalaryTableColumn.class)) {
continue;
}
SalaryTableColumn annotation = declaredField.getAnnotation(SalaryTableColumn.class);
2023-08-23 18:13:31 +08:00
headerList.add(SalaryI18nUtil.getI18nLabel((int) annotation.labelId(), annotation.text()));
2022-06-15 16:02:34 +08:00
dataIndexList.add(declaredField.getName());
}
}
2022-04-18 18:56:17 +08:00
}