weaver-hrm-salary/src/com/engine/salary/service/impl/AddUpSituationServiceImpl.java

720 lines
39 KiB
Java
Raw Normal View History

2022-03-08 13:17:54 +08:00
package com.engine.salary.service.impl;
import com.engine.core.impl.Service;
2022-05-27 11:49:23 +08:00
import com.engine.core.interceptor.CommandContext;
2022-04-11 20:17:47 +08:00
import com.engine.salary.biz.AddUpSituationBiz;
2022-05-09 14:11:07 +08:00
import com.engine.salary.biz.EmployBiz;
2022-05-27 11:49:23 +08:00
import com.engine.salary.biz.TaxAgentBiz;
import com.engine.salary.cmd.datacollection.AddUpSituationGetSearchConditionCmd;
import com.engine.salary.cmd.datacollection.AddUpSituationImportCmd;
import com.engine.salary.cmd.datacollection.AddUpSituationPreviewCmd;
2022-04-11 20:17:47 +08:00
import com.engine.salary.entity.datacollection.AddUpSituation;
2022-05-09 14:11:07 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
2022-04-28 17:44:26 +08:00
import com.engine.salary.entity.datacollection.dto.AddUpSituationDTO;
2022-05-27 11:49:23 +08:00
import com.engine.salary.entity.datacollection.dto.AddUpSituationRecordDTO;
import com.engine.salary.entity.datacollection.param.AddUpSituationImportParam;
2022-04-28 17:44:26 +08:00
import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam;
2022-05-27 11:49:23 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO;
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.entity.taxrate.TaxAgent;
2022-04-11 20:17:47 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
2022-04-28 17:44:26 +08:00
import com.engine.salary.mapper.datacollection.AddUpSituationMapper;
2022-05-27 11:49:23 +08:00
import com.engine.salary.service.AddUpDeductionService;
2022-03-08 13:17:54 +08:00
import com.engine.salary.service.AddUpSituationService;
2022-05-27 11:49:23 +08:00
import com.engine.salary.service.SalaryEmployeeService;
import com.engine.salary.service.TaxAgentV2Service;
2022-04-11 20:17:47 +08:00
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryI18nUtil;
2022-04-28 17:44:26 +08:00
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.excel.ExcelComment;
2022-05-27 11:49:23 +08:00
import com.engine.salary.util.excel.ExcelParseHelper;
2022-04-28 17:44:26 +08:00
import com.engine.salary.util.excel.ExcelUtil;
2022-05-27 11:49:23 +08:00
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
2022-04-28 17:44:26 +08:00
import com.google.common.collect.Lists;
2022-05-27 11:49:23 +08:00
import com.google.common.collect.Maps;
import lombok.SneakyThrows;
2022-05-09 14:11:07 +08:00
import org.apache.commons.collections4.CollectionUtils;
2022-05-27 11:49:23 +08:00
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.IOUtils;
2022-03-10 11:09:08 +08:00
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2022-05-27 11:49:23 +08:00
import weaver.file.ImageFileManager;
2022-05-20 14:41:42 +08:00
import weaver.general.Util;
2022-03-08 13:17:54 +08:00
2022-05-27 11:49:23 +08:00
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
2022-04-11 20:17:47 +08:00
import java.time.YearMonth;
2022-05-09 14:11:07 +08:00
import java.util.*;
import java.util.stream.Collectors;
2022-03-08 13:17:54 +08:00
2022-05-27 11:49:23 +08:00
import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
2022-03-08 13:17:54 +08:00
public class AddUpSituationServiceImpl extends Service implements AddUpSituationService {
2022-04-28 17:44:26 +08:00
private AddUpSituationMapper getAddUpSituationMapper() {
return MapperProxyFactory.getProxy(AddUpSituationMapper.class);
}
2022-04-11 20:17:47 +08:00
2022-05-27 11:49:23 +08:00
private TaxAgentV2Service taxAgentService;
private AddUpDeductionService addUpDeductionService;
private SalaryEmployeeService salaryEmployeeService;
AddUpSituationBiz biz = new AddUpSituationBiz();
2022-03-08 13:17:54 +08:00
@Override
2022-05-27 11:49:23 +08:00
public Map<String, Object> getSearchCondition(Map<String, Object> params) {
return commandExecutor.execute(new AddUpSituationGetSearchConditionCmd(params, user));
2022-03-08 13:17:54 +08:00
}
2022-05-27 11:49:23 +08:00
2022-03-08 13:17:54 +08:00
@Override
2022-05-27 11:49:23 +08:00
public AddUpSituation getById(Long id) {
return getAddUpSituationMapper().getById(id);
}
@Override
public PageInfo<AddUpSituationDTO> listPage(AddUpSituationQueryParam queryParam) {
long employeeId = user.getUID();
// handleHistory();
// 未开启分权或是薪酬模块总管理员
if (!taxAgentService.isOpenDevolution() || taxAgentService.isChief(employeeId)) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AddUpSituationDTO> list = getAddUpSituationMapper().list(queryParam);
return new PageInfo<>(list, AddUpSituationDTO.class);
} else {
List<TaxAgentEmployeeDTO> taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<AddUpSituation> lastList = getLastListByModifier(employeeId, tenantKey);
// List<ExtEmployeePO> extEmployeeList = extEmployeeService.listCanUseByEmployeeId(employeeId, tenantKey);
List<AddUpSituationDTO> list = getAddUpSituationMapper().list(queryParam);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// // 作为分管理员
// || TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// // 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l -> l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getTaxYearMonth().isBefore(f.getTaxYearMonth()))
// // 外部人员
// || extEmployeeList.stream().anyMatch(t -> t.getTaxAgentId().equals(f.getTaxAgentId()) && t.getId().equals(f.getEmployeeId()))
).collect(Collectors.toList());
// 分页参数
PageInfo<AddUpSituationDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), AddUpSituationDTO.class);
// 填充总数和当页数据
dtoPage.setTotal(list.size());
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getSize(), list));
return dtoPage;
}
}
@Override
public PageInfo<AddUpSituationRecordDTO> recordListPage(AddUpSituationQueryParam queryParam) {
long employeeId = user.getUID();
// 未开启分权或是薪酬模块总管理员
if (!taxAgentService.isOpenDevolution() || taxAgentService.isChief(employeeId)) {
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<AddUpSituationRecordDTO> list = getAddUpSituationMapper().recordList(queryParam);
return new PageInfo<>(list, AddUpSituationRecordDTO.class);
} else {
List<TaxAgentEmployeeDTO> taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<AddUpSituationPO> lastList = getLastListByModifier(employeeId, tenantKey);
// List<ExtEmployeePO> extEmployeeList = extEmployeeService.listCanUseByEmployeeId(employeeId, tenantKey);
List<AddUpSituationRecordDTO> list = getAddUpSituationMapper().recordList(queryParam);
// 分页参数
PageInfo<AddUpSituationRecordDTO> dtoPage = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), AddUpSituationRecordDTO.class);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// // 作为分管理员
// || TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// // 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l -> l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getTaxYearMonth().isBefore(f.getTaxYearMonth()))
// // 外部人员
// || extEmployeeList.stream().anyMatch(t -> t.getTaxAgentId().equals(f.getTaxAgentId()) && t.getId().equals(f.getEmployeeId()))
).collect(Collectors.toList());
// 填充总数和当页数据
dtoPage.setTotal(list.size());
dtoPage.setList(SalaryPageUtil.subList(dtoPage.getPageNum(), dtoPage.getSize(), list));
return dtoPage;
}
}
@Override
public List<AddUpSituation> getAddUpSituationList(YearMonth taxYearMonth, List<Long> employeeIds) {
if (taxYearMonth == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100353, "参数有误:税款所属期必传"));
}
2022-05-09 14:11:07 +08:00
AddUpSituationBiz biz = new AddUpSituationBiz();
2022-05-27 11:49:23 +08:00
return biz.listSome(AddUpSituation.builder().taxYearMonth(SalaryDateUtil.toDateStartOfMonth(taxYearMonth)).employeeIds(employeeIds).build());
2022-03-08 13:17:54 +08:00
}
@Override
2022-05-27 11:49:23 +08:00
public boolean deleteAddUpSituationList(YearMonth taxYearMonth, List<Long> employeeIds) {
if (taxYearMonth == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100353, "参数有误:税款所属期必传"));
}
AddUpSituationBiz biz = new AddUpSituationBiz();
biz.deleteSome(AddUpSituation.builder().employeeIds(employeeIds).taxYearMonth(SalaryDateUtil.toDateStartOfMonth(taxYearMonth)).build());
return Boolean.TRUE;
2022-03-08 13:17:54 +08:00
}
2022-05-27 11:49:23 +08:00
2022-03-08 13:17:54 +08:00
@Override
2022-05-27 11:49:23 +08:00
public XSSFWorkbook export(AddUpSituationQueryParam queryParam) {
//获取操作按钮资源
List<List<String>> rowList = getExcelRowList(queryParam);
//获取excel
return ExcelUtil.genWorkbook(rowList, "累计情况");
}
/**
* 获取excel数据行
*
* @return 导出数据行集合
*/
private List<List<String>> getExcelRowList(AddUpSituationQueryParam param) {
long employeeId = user.getUID();
// excel标题
final List<String> title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计收入额", "累计减除费用",
"累计社保个人合计", "累计公积金个人合计", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人",
"累计大病医疗", "累计企业(职业)年金及其他福利", "累计其他扣除", "累计免税收入", "累计准予扣除的捐赠额", "累计减免税额", "累计已预扣预缴税额", "累计婴幼儿照护");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
List<AddUpSituationDTO> list = biz.list(param);
// 开启分权并且不是薪酬模块总管理员
if (taxAgentService.isOpenDevolution() && !taxAgentService.isChief(employeeId)) {
List<TaxAgentEmployeeDTO> taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// // 作为分管理员
// || TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// // 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l->l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getTaxYearMonth().isBefore(f.getTaxYearMonth()))
// // 外部人员
// || extEmployeeList.stream().anyMatch(t -> t.getTaxAgentId().equals(f.getTaxAgentId()) && t.getId().equals(f.getEmployeeId()))
).collect(Collectors.toList());
}
final List<List<String>> dataRowList = Optional.ofNullable(list)
.map(List::stream)
.map(operatorStream -> operatorStream.map(dto -> {
List<String> cellList = new ArrayList<>();
cellList.add(Util.null2String(dto.getUsername()));
cellList.add(Util.null2String(dto.getTaxAgentName()));
cellList.add(Util.null2String(dto.getDepartmentName()));
cellList.add(Util.null2String(dto.getMobile()));
cellList.add(Util.null2String(dto.getJobNum()));
cellList.add(Util.null2String(dto.getIdNo()));
cellList.add(dto.getHiredate() == null ? "" : formatter.format(dto.getHiredate()));
cellList.add(String.valueOf(dto.getAddUpIncome()));
cellList.add(String.valueOf(dto.getAddUpSubtraction()));
cellList.add(String.valueOf(dto.getAddUpSocialSecurityTotal()));
cellList.add(String.valueOf(dto.getAddUpAccumulationFundTotal()));
cellList.add(String.valueOf(dto.getAddUpChildEducation()));
cellList.add(String.valueOf(dto.getAddUpContinuingEducation()));
cellList.add(String.valueOf(dto.getAddUpHousingLoanInterest()));
cellList.add(String.valueOf(dto.getAddUpHousingRent()));
cellList.add(String.valueOf(dto.getAddUpSupportElderly()));
cellList.add(String.valueOf(dto.getAddUpIllnessMedical()));
cellList.add(String.valueOf(dto.getAddUpEnterpriseAndOther()));
cellList.add(String.valueOf(dto.getAddUpOtherDeduction()));
cellList.add(String.valueOf(dto.getAddUpTaxExemptIncome()));
cellList.add(String.valueOf(dto.getAddUpAllowedDonation()));
cellList.add(String.valueOf(dto.getAddUpTaxSavings()));
cellList.add(String.valueOf(dto.getAddUpAdvanceTax()));
cellList.add(String.valueOf(dto.getAddUpInfantCare()));
return cellList;
}).collect(Collectors.toList()))
.orElse(Collections.emptyList());
List<List<String>> rowList = new ArrayList<>();
rowList.add(title);
rowList.addAll(dataRowList);
return rowList;
}
/**
* 导出详情
*
* @param param
* @return
*/
private List<List<String>> getExcelRowDetailList(AddUpSituationQueryParam param) {
long employeeId = user.getUID();
//excel标题
List<String> title = Arrays.asList("姓名", "税款所属期", "个税扣缴义务人", "部门", "手机号", "工号", "累计收入额", "累计减除费用", "累计社保个人合计",
"累计公积金个人合计", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人", "累计大病医疗", "累计企业(职业)年金及其他福利",
"累计其他扣除", "累计免税收入", "累计准予扣除的捐赠额", "累计减免税额", "累计已预扣预缴税额", "累计婴幼儿照护");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
//查询详细信息
List<AddUpSituationRecordDTO> list = biz.recordList(param);
// 开启了分权
if (taxAgentService.isOpenDevolution() || !taxAgentService.isChief(employeeId)) {
List<TaxAgentEmployeeDTO> taxAgentEmployees = taxAgentService.listTaxAgentAndEmployee(employeeId);
List<Long> taxAgentIdsAsAdmin = taxAgentService.listAllTaxAgentsAsAdmin(employeeId).stream().map(TaxAgentPO::getId).collect(Collectors.toList());
// List<ExtEmployeePO> extEmployeeList = extEmployeeService.listCanUseByEmployeeId(employeeId);
// List<AddUpSituationPO> lastList = getLastListByModifier(employeeId);
list = list.stream().filter(f ->
// 作为管理员
taxAgentIdsAsAdmin.contains(f.getTaxAgentId())
// // 作为分管理员
// || TaxAgentBO.checkTaxAgentAndEmployee(taxAgentEmployees, f.getTaxAgentId(), f.getEmployeeId())
// // 自己最后修改过的,则可以看到最新和其历史
// || lastList.stream().anyMatch(l->l.getEmployeeId().equals(f.getEmployeeId()) && l.getTaxAgentId().equals(f.getTaxAgentId()) && !l.getTaxYearMonth().isBefore(f.getTaxYearMonth()))
// // 外部人员
// || extEmployeeList.stream().anyMatch(t -> t.getTaxAgentId().equals(f.getTaxAgentId()) && t.getId().equals(f.getEmployeeId()))
).collect(Collectors.toList());
}
final List<List<String>> dataRowList = Optional.ofNullable(list)
.map(List::stream)
.map(operatorStream -> operatorStream.map(dto -> {
List<String> cellList = new ArrayList<>();
cellList.add(Util.null2String(dto.getUsername()));
cellList.add(Util.null2String(dto.getTaxYearMonth() == null ? "" : formatter.format(dto.getTaxYearMonth())));
cellList.add(Util.null2String(dto.getTaxAgentName()));
cellList.add(Util.null2String(dto.getDepartmentName()));
cellList.add(Util.null2String(dto.getMobile()));
cellList.add(Util.null2String(dto.getJobNum()));
cellList.add(Util.null2String(dto.getAddUpIncome()));
cellList.add(Util.null2String(dto.getAddUpSubtraction()));
cellList.add(Util.null2String(dto.getAddUpSocialSecurityTotal()));
cellList.add(Util.null2String(dto.getAddUpAccumulationFundTotal()));
cellList.add(Util.null2String(dto.getAddUpChildEducation()));
cellList.add(Util.null2String(dto.getAddUpContinuingEducation()));
cellList.add(Util.null2String(dto.getAddUpHousingLoanInterest()));
cellList.add(Util.null2String(dto.getAddUpHousingRent()));
cellList.add(Util.null2String(dto.getAddUpSupportElderly()));
cellList.add(Util.null2String(dto.getAddUpIllnessMedical()));
cellList.add(Util.null2String(dto.getAddUpEnterpriseAndOther()));
cellList.add(Util.null2String(dto.getAddUpOtherDeduction()));
cellList.add(Util.null2String(dto.getAddUpTaxExemptIncome()));
cellList.add(Util.null2String(dto.getAddUpAllowedDonation()));
cellList.add(Util.null2String(dto.getAddUpTaxSavings()));
cellList.add(Util.null2String(dto.getAddUpAdvanceTax()));
cellList.add(Util.null2String(dto.getAddUpInfantCare()));
return cellList;
}).collect(Collectors.toList()))
.orElse(Collections.emptyList());
List<List<String>> rowList = new ArrayList<>();
rowList.add(title);
rowList.addAll(dataRowList);
return rowList;
2022-03-08 13:17:54 +08:00
}
2022-03-10 11:09:08 +08:00
2022-05-27 11:49:23 +08:00
2022-03-10 11:09:08 +08:00
@Override
public XSSFWorkbook exportDetail(Map<String, Object> params) {
2022-05-09 14:11:07 +08:00
AddUpSituationQueryParam queryParam = (AddUpSituationQueryParam) params.get("queryParam");
AddUpSituationBiz biz = new AddUpSituationBiz();
EmployBiz employBiz = new EmployBiz();
Long id = queryParam.getAccumulatedSituationId();
if (id == null) {
throw new SalaryRunTimeException("id不能为空");
}
AddUpSituation po = biz.getById(id);
if (po == null) {
2022-05-09 17:47:19 +08:00
throw new SalaryRunTimeException(String.format("累计情况不存在" + "[id:%s]", id));
2022-05-09 14:11:07 +08:00
}
List<DataCollectionEmployee> employeeList = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId()));
if (CollectionUtils.isEmpty(employeeList)) {
throw new SalaryRunTimeException("员工信息不存在");
}
//查询参数
queryParam.setEmployeeId(po.getEmployeeId());
//申报月份
List<String> taxYearMonths = queryParam.getTaxYearMonth();
if (CollectionUtils.isNotEmpty(taxYearMonths)) {
queryParam.setTaxYearMonth(taxYearMonths.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
}
2022-05-27 11:49:23 +08:00
//获取操作按钮资源
List<List<String>> rowList = getExcelRowDetailList(queryParam);
//获取excel
return ExcelUtil.genWorkbook(rowList, "累计情况明细");
2022-03-10 17:57:46 +08:00
}
2022-05-27 11:49:23 +08:00
2022-03-10 17:57:46 +08:00
@Override
public Map<String, Object> preview(Map<String, Object> params) {
return commandExecutor.execute(new AddUpSituationPreviewCmd(params, user));
}
2022-04-11 20:17:47 +08:00
2022-04-28 17:44:26 +08:00
@Override
public XSSFWorkbook downloadTemplate(AddUpSituationQueryParam queryParam) {
2022-05-09 17:47:19 +08:00
String sheetName = SalaryI18nUtil.getI18nLabel(101605, "往期累计情况导入模板");
2022-04-28 17:44:26 +08:00
String[] header = {
2022-05-09 17:47:19 +08:00
SalaryI18nUtil.getI18nLabel(85429, "姓名"),
SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"),
SalaryI18nUtil.getI18nLabel(86185, "部门"),
SalaryI18nUtil.getI18nLabel(86186, "手机号"),
SalaryI18nUtil.getI18nLabel(86317, "工号"),
SalaryI18nUtil.getI18nLabel(86318, "证件号码"),
SalaryI18nUtil.getI18nLabel(86319, "入职日期"),
SalaryI18nUtil.getI18nLabel(86712, "累计收入额"),
SalaryI18nUtil.getI18nLabel(86711, "累计减除费用"),
SalaryI18nUtil.getI18nLabel(86710, "累计社保个人合计"),
SalaryI18nUtil.getI18nLabel(86709, "累计公积金个人合计"),
SalaryI18nUtil.getI18nLabel(86321, "累计子女教育"),
SalaryI18nUtil.getI18nLabel(86323, "累计继续教育"),
SalaryI18nUtil.getI18nLabel(86324, "累计住房贷款利息"),
SalaryI18nUtil.getI18nLabel(86325, "累计住房租金"),
SalaryI18nUtil.getI18nLabel(86326, "累计赡养老人"),
SalaryI18nUtil.getI18nLabel(105142, "累计大病医疗"),
SalaryI18nUtil.getI18nLabel(90567, "累计企业(职业)年金及其他福利"),
SalaryI18nUtil.getI18nLabel(93902, "累计其他免税扣除"),
SalaryI18nUtil.getI18nLabel(86704, "累计免税收入"),
SalaryI18nUtil.getI18nLabel(86703, "累计准予扣除的捐赠额"),
SalaryI18nUtil.getI18nLabel(105478, "累计减免税额"),
2022-05-20 14:41:42 +08:00
SalaryI18nUtil.getI18nLabel(86702, "累计已预扣预缴税额"),
SalaryI18nUtil.getI18nLabel(86702, "累计婴幼儿照护")
2022-04-28 17:44:26 +08:00
};
// 2.表头
List<Object> headerList = Arrays.asList(header);
List<List<Object>> rows = new ArrayList<>();
2022-05-09 17:47:19 +08:00
rows.add(headerList);
2022-05-27 11:49:23 +08:00
// // 获取累计情况
// List<AddUpSituationDTO> list = getAddUpSituationMapper().list(queryParam);
// // 人员信息赋值
// list.forEach(m -> {
// // todo 身份证号
// m.setIdNo("");
// });
//
// for (AddUpSituationDTO dto : list) {
// List<Object> row = new ArrayList<>();
// row.add(Util.null2String(dto.getUsername()));
// row.add(Util.null2String(dto.getTaxAgentName()));
// row.add(Util.null2String(dto.getDepartmentName()));
// row.add(Util.null2String(dto.getMobile()));
// row.add(Util.null2String(dto.getJobNum()));
// row.add(Util.null2String(dto.getIdNo()));
// row.add(Util.null2String(dto.getHiredate()));
// row.add(Util.null2String(dto.getAddUpIncome()));
// row.add(Util.null2String(dto.getAddUpSubtraction()));
// row.add(Util.null2String(dto.getAddUpSocialSecurityTotal()));
// row.add(Util.null2String(dto.getAddUpAccumulationFundTotal()));
// row.add(Util.null2String(dto.getAddUpChildEducation()));
// row.add(Util.null2String(dto.getAddUpContinuingEducation()));
// row.add(Util.null2String(dto.getAddUpHousingLoanInterest()));
// row.add(Util.null2String(dto.getAddUpHousingRent()));
// row.add(Util.null2String(dto.getAddUpSupportElderly()));
// row.add(Util.null2String(dto.getAddUpIllnessMedical()));
// row.add(Util.null2String(dto.getAddUpEnterpriseAndOther()));
// row.add(Util.null2String(dto.getAddUpOtherDeduction()));
// row.add(Util.null2String(dto.getAddUpTaxExemptIncome()));
// row.add(Util.null2String(dto.getAddUpAllowedDonation()));
// row.add(Util.null2String(dto.getAddUpTaxSavings()));
// row.add(Util.null2String(dto.getAddUpAdvanceTax()));
// row.add(Util.null2String(dto.getAddUpInfantCare()));
// rows.add(row);
// }
2022-04-28 17:44:26 +08:00
// 4.注释
List<ExcelComment> excelComments = Lists.newArrayList();
excelComments.add(new ExcelComment(0, 0, 3, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
excelComments.add(new ExcelComment(1, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
excelComments.add(new ExcelComment(7, 0, 10, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(8, 0, 11, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(9, 0, 14, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(10, 0, 15, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(11, 0, 16, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(12, 0, 17, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(13, 0, 18, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(14, 0, 19, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(15, 0, 20, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(16, 0, 21, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(17, 0, 22, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(18, 0, 23, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(19, 0, 24, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(20, 0, 25, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(21, 0, 26, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
excelComments.add(new ExcelComment(22, 0, 27, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
2022-05-20 14:41:42 +08:00
excelComments.add(new ExcelComment(23, 0, 28, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字")));
2022-04-28 17:44:26 +08:00
XSSFWorkbook book = ExcelUtil.genWorkbookV2(rows, sheetName, excelComments);
return book;
}
2022-05-09 17:47:19 +08:00
@Override
public boolean deleteByTaxYearMonthAndTaxAgentIds(YearMonth taxYearMonth, Collection<Long> taxAgentIds) {
if (taxYearMonth == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100353, "参数有误:税款所属期必传"));
}
Date date = SalaryDateUtil.localDateToDate(taxYearMonth.atDay(1));
getAddUpSituationMapper().deleteByTaxYearMonthAndTaxAgentIds(AddUpSituation.builder().taxYearMonth(date).taxAgentIds(taxAgentIds).build());
return Boolean.TRUE;
}
2022-05-27 11:49:23 +08:00
@Override
public Map<String, Object> importAddUpSituation(Map<String, Object> params) {
Map<String, Object> apidatas = new HashMap<String, Object>();
EmployBiz employBiz = new EmployBiz();
AddUpSituationBiz biz = new AddUpSituationBiz();
//检验参数
checkImportParam();
//导入参数
AddUpSituationImportParam importParam = (AddUpSituationImportParam) params.get("importParam");
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
//税款所属期
String taxYearMonthStr = Util.null2String(importParam.getTaxYearMonth());
Long currentEmployeeId = (long)user.getUID();
// 获取所有个税扣缴义务人
Collection<TaxAgentManageRangeEmployeeDTO> taxAgentList = taxAgentService.listTaxAgentAndEmployeeTree(currentEmployeeId);
// 获取租户下所有的人员
List<DataCollectionEmployee> employees = employBiz.listEmployee();
// 获取可以使用的外部人员
List<ExtEmployeePO> extEmployeeList = extEmployeeService.listCanUseByEmployeeId(currentEmployeeId, tenantKey);
// 已经核算过的不可操作
// 获取已经核算的数据
List<SalaryAcctEmployeePO> salaryAcctEmployees = addUpDeductionService.getAccountedEmployeeData(taxYearMonth, tenantKey);
// 查询已有数据
List<AddUpSituationPO> list = new LambdaQueryChainWrapper<>(getAddUpSituationMapper())
.eq(AddUpSituationPO::getDeleteType, 0)
.eq(AddUpSituationPO::getTenantKey, tenantKey)
.eq(AddUpSituationPO::getTaxYearMonth, LocalDate.parse(taxYearMonth+"-01", SalaryDateUtil.DATE_FORMATTER))
.list();
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.valueOf(imageId));
List<AddUpSituationDTO> excelDates = ExcelParseHelper.parse2Map(fileInputStream, AddUpSituationDTO.class, 0, 1, 24, "template.xlsx");
int total = excelDates.size();
int index = 0;
int successCount = 0;
int errorCount = 0;
//人员信息
List<DataCollectionEmployee> employees = employBiz.listEmployee();
List<TaxAgent> taxAgents = new TaxAgentBiz().listAll();
//税款所属期
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date taxYearMonth = simpleDateFormat.parse(taxYearMonthStr + "-01");
Date now = new Date();
// 错误excel内容
List<Map> errorData = new ArrayList<>();
//合规数据
List<AddUpSituation> eligibleData = new ArrayList<>();
for (int i = 0; i < excelDates.size(); i++) {
//excel中的数据
AddUpSituationDTO dto = excelDates.get(i);
//待插入数据库对象
AddUpSituation po = AddUpSituation.builder().tenantKey(DEFAULT_TENANT_KEY)
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.year(Integer.valueOf(taxYearMonthStr.split("-")[0]))
.taxYearMonth(taxYearMonth)
.build();
//异常点数量
int errorSum = 0;
//行号
String rowIndex = String.format("第%s行", i + 2);
//相同的姓名
String userName = dto.getUsername();
String deparmentName = dto.getDepartmentName();
List<Long> employeeSameIds = employees.stream().filter(e -> (StringUtils.isBlank(userName) || Objects.equals(e.getUsername(), userName))
&& (StringUtils.isBlank(deparmentName) || Objects.equals(e.getDepartmentName(), deparmentName))).map(DataCollectionEmployee::getEmployeeId)
.collect(Collectors.toList());
if (StringUtils.isBlank(userName)) {
//姓名 不能为空
//错误消息对象
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "姓名不能为空");
errorData.add(errorMessageMap);
errorSum += 1;
} else if (CollectionUtils.isEmpty(employeeSameIds) || employeeSameIds.size() > 1) {
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "员工信息不能为空且不可重复(姓名与部门同时确认唯一)");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
Long employeeId = CollectionUtils.isNotEmpty(employeeSameIds) && employeeSameIds.size() == 1 ? employeeSameIds.get(0) : null;
if (employeeId != null && employeeId > 0) {
po.setEmployeeId(employeeId);
} else {
//姓名错误,系统内不存在该姓名
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "姓名错误,系统内不存在该姓名");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
String taxAgentName = dto.getTaxAgentName();
if (StringUtils.isBlank(taxAgentName)) {
//个税扣缴义务人不能为空
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不能为空");
errorData.add(errorMessageMap);
errorSum += 1;
} else {
Optional<TaxAgent> optionalTemp = taxAgents.stream().filter(m -> m.getName().equals(taxAgentName)).findFirst();
if (optionalTemp.isPresent()) {
po.setTaxAgentId(optionalTemp.get().getId());
} else {
//个税扣缴义务人不存在
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", rowIndex + "个税扣缴义务人不存在");
errorData.add(errorMessageMap);
errorSum += 1;
}
}
// 分权判断
AddUpSituation finalPoE = po;
Optional<TaxAgentManageRangeEmployeeDTO.TaxAgentEmployee> optionalTaxAgentEmp = taxAgentEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPoE.getEmployeeId())).findFirst();
if (!optionalTaxAgentEmp.isPresent() && !isExt) {
salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 109618, "该条数据不在数据权限范围内,不可导入"), errorCount+1, errorCount+1, 0, 0);
errorSum += 1;
}
// 判断是否有核算过
if (CollectionUtils.isNotEmpty(salaryAcctEmployees)) {
AddUpSituationPO finalPo = po;
Optional<SalaryAcctEmployeePO> optionalAcctEmp = salaryAcctEmployees.stream().filter(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId())).findFirst();
boolean isExist = list.stream().anyMatch(f -> f.getEmployeeId().equals(finalPo.getEmployeeId()) && f.getTaxAgentId().equals(finalPo.getTaxAgentId()));
if (optionalAcctEmp.isPresent() && isExist) {
salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 107442, "该年月这条数据已经核算过,不可导入"), errorCount+1, errorCount+1, 0, 0);
errorSum += 1;
}
}
//累计收入额
String addUpIncome = dto.getAddUpIncome();
po.setAddUpIncome(Util.null2String(addUpIncome));
//累计减除费用
String addUpSubtraction = dto.getAddUpSubtraction();
po.setAddUpSubtraction(addUpSubtraction);
//累计社保个人合计
String addUpSocialSecurityTotal = dto.getAddUpSocialSecurityTotal();
po.setAddUpSocialSecurityTotal(addUpSocialSecurityTotal);
//累计公积金个人合计
String addUpAccumulationFundTotal = dto.getAddUpAccumulationFundTotal();
po.setAddUpAccumulationFundTotal(addUpAccumulationFundTotal);
//累计子女教育
String addUpChildEducation = dto.getAddUpChildEducation();
po.setAddUpChildEducation(Util.null2String(addUpChildEducation));
//累计继续教育
String addUpContinuingEducation = dto.getAddUpContinuingEducation();
po.setAddUpContinuingEducation(Util.null2String(addUpContinuingEducation));
//累计住房贷款利息
String addUpHousingLoanInterest = dto.getAddUpHousingLoanInterest();
po.setAddUpHousingLoanInterest(Util.null2String(addUpHousingLoanInterest));
//累计住房租金
String addUpHousingRent = dto.getAddUpHousingRent();
po.setAddUpHousingRent(Util.null2String(addUpHousingRent));
//累计赡养老人
String addUpSupportElderly = dto.getAddUpSupportElderly();
po.setAddUpSupportElderly(Util.null2String(addUpSupportElderly));
//累计企业(职业)年金及其他福利
String addUpEnterpriseAndOther = dto.getAddUpEnterpriseAndOther();
po.setAddUpEnterpriseAndOther(addUpEnterpriseAndOther);
//累计其他扣除
String addUpOtherDeduction = dto.getAddUpOtherDeduction();
po.setAddUpOtherDeduction(addUpOtherDeduction);
//累计免税收入
String addUpTaxExemptIncome = dto.getAddUpTaxExemptIncome();
po.setAddUpTaxExemptIncome(addUpTaxExemptIncome);
//累计准予扣除的捐赠额
String addUpAllowedDonation = dto.getAddUpAllowedDonation();
po.setAddUpAllowedDonation(addUpAllowedDonation);
//累计已预扣预缴税额
String addUpAdvanceTax = dto.getAddUpAdvanceTax();
po.setAddUpAdvanceTax(addUpAdvanceTax);
po.setAddUpIllnessMedical(dto.getAddUpIllnessMedical());
po.setAddUpTaxSavings(dto.getAddUpTaxSavings());
po.setAddUpInfantCare(dto.getAddUpInfantCare());
if (errorSum == 0) {
successCount += 1;
// 合格数据
eligibleData.add(po);
} else {
errorCount += 1;
// 添加错误数据
}
}
//入库
biz.handleImportData(eligibleData);
apidatas.put("successCount", successCount);
apidatas.put("errorCount", errorCount);
apidatas.put("errorData", errorData);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
private void checkImportParam() {
AddUpSituationImportParam importParam = (AddUpSituationImportParam) params.get("importParam");
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
//税款所属期
String declareMonthStr = Util.null2String(importParam.getTaxYearMonth());
if (StringUtils.isBlank(imageId)) {
throw new SalaryRunTimeException("文件不存在");
}
if (StringUtils.isBlank(declareMonthStr)) {
throw new SalaryRunTimeException("税款所属期为空");
}
}
2022-03-08 13:17:54 +08:00
}