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

229 lines
9.5 KiB
Java
Raw Normal View History

package com.engine.salary.service.impl;
import com.engine.core.impl.Service;
import com.engine.salary.encrypt.siexport.AccountExportPOEncrypt;
import com.engine.salary.encrypt.siexport.ExcelAccountExportPOEncrypt;
import com.engine.salary.entity.siaccount.bo.InsuranceComparisonResultBO;
import com.engine.salary.entity.siaccount.dto.InsuranceComparisonResultListDTO;
import com.engine.salary.entity.siaccount.param.InsuranceComparisonResultQueryParam;
import com.engine.salary.entity.sicategory.po.ICategoryPO;
import com.engine.salary.entity.siexport.param.InsuranceExportParam;
import com.engine.salary.entity.siexport.po.AccountExportPO;
import com.engine.salary.entity.siexport.po.ExcelAccountExportPO;
import com.engine.salary.mapper.InsuranceExportMapper;
import com.engine.salary.mapper.sicategory.ICategoryMapper;
import com.engine.salary.service.SIAComparisonResultService;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.excel.ExcelUtil;
import com.engine.salary.util.page.Column;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.engine.salary.util.valid.ValidUtil;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author: sy
* @Description: 福利核算的线下对比结果
* @Date: 2022/9/28
**/
public class SIAComparisonResultServiceImpl extends Service implements SIAComparisonResultService {
private InsuranceExportMapper getInsuranceExportMapper() {
return MapperProxyFactory.getProxy(InsuranceExportMapper.class);
}
/**
* 根据列表查询条件查询线下对比结果分页
*/
@Override
public InsuranceComparisonResultListDTO listPageByParam(InsuranceComparisonResultQueryParam queryParam) {
return listByParam(true, queryParam);
}
/**
* 根据列表查询条件查询线下对比结果
*/
@Override
public InsuranceComparisonResultListDTO listByParam(InsuranceComparisonResultQueryParam queryParam) {
return listByParam(false, queryParam);
}
@Override
public XSSFWorkbook exportComparisonResult(InsuranceComparisonResultQueryParam queryParam) {
ValidUtil.doValidator(queryParam);
// 查询线下对比结果
InsuranceComparisonResultListDTO insuranceComparisonResultListDTO = listByParam(queryParam);
// 薪资核算线下对比结果列表表头
List<Object> headerList = Lists.newArrayList();
Set<String> employeeInfo = employeeInfo();
Set<String> welfareInfo = welfareInfo();
for (Column weaTableColumn : insuranceComparisonResultListDTO.getWeaTableColumns()) {
// 员工信息字段
if (employeeInfo.contains(weaTableColumn.getKey())) {
headerList.add(weaTableColumn.getTitle());
}
// 薪资项目的表头
if (welfareInfo.contains(weaTableColumn.getKey())) {
headerList.add(weaTableColumn.getTitle() + " (线上值)");
headerList.add(weaTableColumn.getTitle() + " (线下值)");
}
}
List<Map<String, Object>> resultMapList = insuranceComparisonResultListDTO.getData().getList();
// excel导出的数据
List<List<Object>> rows = new ArrayList<>();
rows.add(headerList);
for (Map<String, Object> map : resultMapList) {
List<Object> row = Lists.newArrayList();
for (Column weaTableColumn : insuranceComparisonResultListDTO.getWeaTableColumns()) {
// 员工信息字段的值
if (employeeInfo.contains(weaTableColumn.getKey())) {
row.add(map.get(weaTableColumn.getKey()));
}
// 福利项目的值
if (welfareInfo.contains(weaTableColumn.getKey())) {
Map tempMap = (Map) map.getOrDefault(weaTableColumn.getKey(), Collections.emptyMap());
row.add(tempMap.get("acctResultValue"));
row.add(tempMap.get("excelResultValue"));
}
}
rows.add(row);
}
String sheetName = "线下对比结果";
return ExcelUtil.genWorkbookV2(rows, sheetName);
}
/**
* 根据福利核算人员查询福利核算线下对比结果
*/
private InsuranceComparisonResultListDTO listByParam(boolean needPage, InsuranceComparisonResultQueryParam queryParam) {
//1-查询线上福利核算记录
InsuranceExportParam insuranceExportParam = new InsuranceExportParam();
insuranceExportParam.setBillMonth(queryParam.getBillMonth());
insuranceExportParam.setPaymentOrganization(queryParam.getPaymentOrganization());
List<AccountExportPO> accountExportPOS = getInsuranceExportMapper().exportAccount(queryParam.getPaymentStatus(), insuranceExportParam);
//如果入参包含姓名信息
if (queryParam.getUserName() != null) {
accountExportPOS = accountExportPOS.stream().filter(v -> v.getUserName().contains(queryParam.getUserName())).collect(Collectors.toList());
}
AccountExportPOEncrypt.decryptAccountExportPOList(accountExportPOS);
//2-查询线下对比数据
List<ExcelAccountExportPO> excelAccountExportPOS = getInsuranceExportMapper().exportExcelAccount(queryParam);
ExcelAccountExportPOEncrypt.decryptExcelAccountExportPOList(excelAccountExportPOS);
//3-构建福利核算对比结果列表表头
List<Column> weaTableColumns = InsuranceComparisonResultBO.buildTableColumns4ComparisonResult();
//4-通过线上线下两份数据获得对比结果
List<Map<String, Object>> resultMapList = InsuranceComparisonResultBO.buildComparisonTableData(accountExportPOS, excelAccountExportPOS);
// 系统值和线下值一致的人员
if (queryParam.isOnlyDiffEmployee()) {
// 过滤系统值和线下值一致的薪资核算人员
resultMapList = resultMapList.stream()
.filter(map -> BooleanUtils.toBoolean(String.valueOf(map.get("different"))))
.collect(Collectors.toList());
}
// 分页
PageInfo<Map<String, Object>> dtoPage = new PageInfo<>();
dtoPage.setTotal(resultMapList.size());
if (needPage) {
dtoPage.setList(SalaryPageUtil.subList(queryParam.getCurrent(), queryParam.getPageSize(), resultMapList));
dtoPage.setPageSize(queryParam.getPageSize());
dtoPage.setPageNum(queryParam.getCurrent());
} else {
dtoPage.setList(resultMapList);
}
// 返回结果
return new InsuranceComparisonResultListDTO().setWeaTableColumns(weaTableColumns).setData(dtoPage);
}
private Set<String> welfareInfo() {
Set<String> info = new HashSet<>();
List<ICategoryPO> listAll = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll();
List<ICategoryPO> socialWelfareList = listAll.stream().filter(e -> e.getWelfareType() == 1).collect(Collectors.toList());
List<ICategoryPO> fundWelfareList = listAll.stream().filter(e -> e.getWelfareType() == 2).collect(Collectors.toList());
List<ICategoryPO> otherWelfareList = listAll.stream().filter(e -> e.getWelfareType() == 3).collect(Collectors.toList());
//组装社保基数
for (ICategoryPO po : socialWelfareList) {
info.add(po.getId() + "socialBase");
}
//组装公积金基数
for (ICategoryPO po : fundWelfareList) {
info.add(po.getId() + "fundBase");
}
//组装其他福利基数
for (ICategoryPO po : otherWelfareList) {
info.add(po.getId() + "otherBase");
}
//社保个人(生育保险个人、工伤保险个人、失业保险个人、养老保险个人、医疗保险个人)
for (ICategoryPO po : socialWelfareList) {
info.add(po.getId() + "socialPer");
}
info.add("socialPerSum");
//住房公积金个人、补充住房公积金个人
for (ICategoryPO po : fundWelfareList) {
info.add(po.getId() + "fundPer");
}
info.add("fundPerSum");
//其他个人(比如企业年金个人)
for (ICategoryPO po : otherWelfareList) {
info.add(po.getId() + "otherPer");
}
info.add("otherPerSum");
info.add("perSum");
//社保单位(生育保险单位、工伤保险单位、失业保险单位、养老保险单位、医疗保险单位)
for (ICategoryPO po : socialWelfareList) {
info.add(po.getId() + "socialCom");
}
info.add("socialComSum");
//住房公积金单位、补充住房公积金单位
for (ICategoryPO po : fundWelfareList) {
info.add(po.getId() + "fundCom");
}
info.add("fundComSum");
//其他单位(比如企业年金单位)
for (ICategoryPO po : otherWelfareList) {
info.add(po.getId() + "otherCom");
}
info.add("otherComSum");
info.add("comSum");
info.add("socialSum");
info.add("fundSum");
info.add("otherSum");
info.add("total");
return info;
}
private Set<String> employeeInfo() {
Set<String> info = new HashSet<>();
info.add("userName");
info.add("department");
info.add("mobile");
info.add("workcode");
info.add("socialPayOrg");
return info;
}
}