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

234 lines
14 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.engine.salary.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam;
import com.engine.salary.entity.siarchives.po.InsuranceArchivesEmployeePO;
import com.engine.salary.entity.siarchives.po.InsuranceArchivesFundSchemePO;
import com.engine.salary.entity.siarchives.po.InsuranceArchivesOtherSchemePO;
import com.engine.salary.entity.siarchives.po.InsuranceArchivesSocialSchemePO;
import com.engine.salary.entity.sicategory.po.ICategoryPO;
import com.engine.salary.entity.sischeme.po.InsuranceSchemePO;
import com.engine.salary.entity.taxrate.TaxAgent;
import com.engine.salary.enums.sicategory.WelfareTypeEnum;
import com.engine.salary.mapper.TaxAgentMapper;
import com.engine.salary.mapper.siarchives.FundSchemeMapper;
import com.engine.salary.mapper.siarchives.OtherSchemeMapper;
import com.engine.salary.mapper.siarchives.SocialSchemeMapper;
import com.engine.salary.mapper.sicategory.ICategoryMapper;
import com.engine.salary.mapper.sischeme.InsuranceSchemeMapper;
import com.engine.salary.service.SIArchivesService;
import com.engine.salary.service.SIImportService;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.excel.ExcelComment;
import com.engine.salary.util.excel.ExcelUtil;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.hrm.User;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author weaver_cl
* @Description: TODO
* @Date 2022/4/20
* @Version V1.0
**/
public class SIImportServiceImpl extends Service implements SIImportService {
public SIArchivesService getSIArchivesService(User user) {
return ServiceUtil.getService(SIArchivesServiceImpl.class,user);
}
@Override
public XSSFWorkbook exportTemplate(InsuranceArchivesListParam param) {
//工作簿list
List<List<Object>> excelSheetData = new ArrayList<>();
//工作簿名称
String sheetName = SalaryI18nUtil.getI18nLabel(85368, "社保福利档案"); //表头
List<String> headers = buildHeader();
InsuranceArchivesListParam request = InsuranceArchivesListParam.builder().build();
if (param.getHireDate() != null && param.getHireDate().length == 2) {
param.setHiredateStart(param.getHireDate()[0]);
param.setHiredateEnd(param.getHireDate()[1]);
}
if (param.getDimissionDate() != null && param.getDimissionDate().length == 2) {
param.setDimissionDateStart(param.getDimissionDate()[0]);
param.setDimissionDateEnd(param.getDimissionDate()[1]);
}
if (Objects.equals("fromQuickSearch", param.getDataSource())) {
request.setStatuses(param.getStatuses());
request.setKeyword(param.getUserName());
request.setStartNum(param.getStartNum());
request.setPageSize(param.getPageSize());
} else {
request = param;
}
// request.setPageSize(null);
// request.setStartNum(null);
// List<InsuranceArchivesEmployeePO> insuranceArchivesEmployeePOS = getSIArchivesService(user).listPageEmployeePOS(request);
// if (insuranceArchivesEmployeePOS == null) {
// insuranceArchivesEmployeePOS = new ArrayList<>();
// }
// List<Map<String, Object>> datas = buildTableData(insuranceArchivesEmployeePOS);
//表头
excelSheetData.add(Arrays.asList(headers.toArray(new String[0])));
// 3.表数据
//工作簿数据
return ExcelUtil.genWorkbookV2(excelSheetData, sheetName);
}
/**
* 构建档案excel的表头
*
* @return
*/
public List<String> buildHeader() {
List<String> result = new ArrayList<>();
result.add(SalaryI18nUtil.getI18nLabel( 85429, "姓名"));
result.add(SalaryI18nUtil.getI18nLabel( 86185, "部门"));
result.add(SalaryI18nUtil.getI18nLabel( 86186, "手机号"));
result.add(SalaryI18nUtil.getI18nLabel( 86187, "员工状态"));
result.add(SalaryI18nUtil.getI18nLabel( 91323, "社保方案名称"));
result.add(SalaryI18nUtil.getI18nLabel( 91325, "社保缴纳组织"));
//社保福利基数
Map<String, Long> socialMap = welfareNameIdMap( WelfareTypeEnum.SOCIAL_SECURITY);
socialMap.forEach((k, v) -> result.add(k + SalaryI18nUtil.getI18nLabel( 100293, "申报基数")));
result.add(SalaryI18nUtil.getI18nLabel( 91324, "社保账号"));
result.add(SalaryI18nUtil.getI18nLabel( 91319, "社保起始缴纳月"));
result.add(SalaryI18nUtil.getI18nLabel( 91320, "社保最后缴纳月"));
result.add(SalaryI18nUtil.getI18nLabel( 91485, "公积金方案名称"));
result.add(SalaryI18nUtil.getI18nLabel( 91488, "公积金缴纳组织"));
result.add(SalaryI18nUtil.getI18nLabel( 91486, "公积金账号"));
//公积金福利基数
Map<String, Long> fundMap = welfareNameIdMap( WelfareTypeEnum.ACCUMULATION_FUND);
fundMap.forEach((k, v) -> result.add(k + SalaryI18nUtil.getI18nLabel( 100293, "申报基数")));
result.add(SalaryI18nUtil.getI18nLabel( 91487, "补充公积金账号"));
result.add(SalaryI18nUtil.getI18nLabel( 91483, "公积金起始缴纳月"));
result.add(SalaryI18nUtil.getI18nLabel( 91484, "公积金最后缴纳月"));
result.add(SalaryI18nUtil.getI18nLabel( 91496, "其他福利方案名称"));
result.add(SalaryI18nUtil.getI18nLabel( 91497, "其他福利缴纳组织"));
//其他福利基数
Map<String, Long> otherMap = welfareNameIdMap( WelfareTypeEnum.OTHER);
otherMap.forEach((k, v) -> result.add(k + SalaryI18nUtil.getI18nLabel( 100293, "申报基数")));
result.add(SalaryI18nUtil.getI18nLabel( 91490, "其他福利起始缴纳月"));
result.add(SalaryI18nUtil.getI18nLabel( 91494, "其他福利最后缴纳月"));
return result;
}
/**
* 获取福利类型名称-id的map
*
* @param welfareTypeEnum
* @return
*/
public Map<String, Long> welfareNameIdMap(WelfareTypeEnum welfareTypeEnum) {
return MapperProxyFactory.getProxy(ICategoryMapper.class).listByWelfareType(welfareTypeEnum.getValue(),null).stream().collect(Collectors.toMap(ICategoryPO::getInsuranceName, ICategoryPO::getId));
}
public Map<Long, String> welfareMap() {
return MapperProxyFactory.getProxy(ICategoryMapper.class).listAll().stream().collect(Collectors.toMap(ICategoryPO::getId, ICategoryPO::getInsuranceName));
}
/**
* 获取缴纳组织id-名称集合
*
* @return
*/
public Map<Long, String> paymentOrganizationIdNameMap() {
List<TaxAgent> list = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll();
if (CollectionUtils.isEmpty(list)) {
return new HashMap<>();
}
return list.stream().collect(Collectors.toMap(TaxAgent::getId, TaxAgent::getName));
}
public List<Map<String, Object>> buildTableData(List<InsuranceArchivesEmployeePO> insuranceArchivesEmployeePOS) {
List<Map<String, Object>> records = new ArrayList<>();
//获取id,福利名称的map用于下面组装福利数据
Map<Long, String> welfareMap = welfareMap();
//获取缴纳组织id-name集合
Map<Long, String> paymentMap = paymentOrganizationIdNameMap();
//获取id,方案名称的map用于下面组装福利数据
Map<Long, String> schemeMap = new HashMap<>();
List<InsuranceSchemePO> schemeList = MapperProxyFactory.getProxy(InsuranceSchemeMapper.class).listAll();
if (CollectionUtils.isNotEmpty(schemeList)) {
schemeMap = schemeList.stream().collect(Collectors.toMap(InsuranceSchemePO::getId, InsuranceSchemePO::getSchemeName));
}
List<Long> employeeIds = insuranceArchivesEmployeePOS.stream().map(InsuranceArchivesEmployeePO::getEmployeeId).collect(Collectors.toList());
Map<Long, InsuranceArchivesSocialSchemePO> socialSchemePOMap = new HashMap<>();
List<InsuranceArchivesSocialSchemePO> socialSchemePOList = MapperProxyFactory.getProxy(SocialSchemeMapper.class).getSocialByEmployeeId(employeeIds);
if (CollectionUtils.isNotEmpty(socialSchemePOList)) {
socialSchemePOMap = socialSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesSocialSchemePO::getEmployeeId, Function.identity()));
}
List<InsuranceArchivesFundSchemePO> fundSchemePOList = MapperProxyFactory.getProxy(FundSchemeMapper.class).getFundByEmployeeId(employeeIds);
Map<Long, InsuranceArchivesFundSchemePO> fundSchemePOMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(fundSchemePOList)) {
fundSchemePOMap = fundSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesFundSchemePO::getEmployeeId, Function.identity()));
}
Map<Long, InsuranceArchivesOtherSchemePO> otherSchemePOMap = new HashMap<>();
List<InsuranceArchivesOtherSchemePO> otherSchemePOList = MapperProxyFactory.getProxy(OtherSchemeMapper.class).getOtherByEmployeeId(employeeIds);
if (CollectionUtils.isNotEmpty(otherSchemePOList)) {
otherSchemePOMap = otherSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesOtherSchemePO::getEmployeeId, Function.identity()));
}
for (InsuranceArchivesEmployeePO item : insuranceArchivesEmployeePOS) {
InsuranceArchivesSocialSchemePO socialItem = socialSchemePOMap.get(item.getEmployeeId());
InsuranceArchivesFundSchemePO fundItem = fundSchemePOMap.get(item.getEmployeeId());
InsuranceArchivesOtherSchemePO otherItem = otherSchemePOMap.get(item.getEmployeeId());
Map<String, Object> map = new HashMap<>();
map.put(SalaryI18nUtil.getI18nLabel( 85429, "姓名"), item.getUserName());
map.put(SalaryI18nUtil.getI18nLabel( 86185, "部门"), item.getDepartmentName());
map.put(SalaryI18nUtil.getI18nLabel( 86186, "手机号"), item.getTelephone());
map.put(SalaryI18nUtil.getI18nLabel( 86187, "员工状态"), item.getUserStatusEnum() == null ? "" : item.getUserStatusEnum().getDescription());
if (socialItem != null) {
map.put(SalaryI18nUtil.getI18nLabel( 91323, "社保方案名称"), schemeMap.get(socialItem.getSocialSchemeId()));
map.put(SalaryI18nUtil.getI18nLabel( 91325, "社保缴纳组织"), paymentMap.get(socialItem.getPaymentOrganization()));
Map<String, Object> socialJson = JSON.parseObject(socialItem.getSocialPaymentBaseString(), new TypeReference<Map<String, Object>>() {
});
if (socialJson != null) {
socialJson.forEach((k, v) -> map.put(welfareMap.get(Long.valueOf(k)) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), v));
}
map.put(SalaryI18nUtil.getI18nLabel( 91324, "社保账号"), socialItem.getSocialAccount());
map.put(SalaryI18nUtil.getI18nLabel( 91319, "社保起始缴纳月"), socialItem.getSocialStartTime());
map.put(SalaryI18nUtil.getI18nLabel( 91320, "社保最后缴纳月"), socialItem.getSocialEndTime());
}
if (fundItem != null) {
map.put(SalaryI18nUtil.getI18nLabel( 91485, "公积金方案名称"), schemeMap.get(fundItem.getFundSchemeId()));
map.put(SalaryI18nUtil.getI18nLabel( 91488, "公积金缴纳组织"), paymentMap.get(fundItem.getPaymentOrganization()));
map.put(SalaryI18nUtil.getI18nLabel( 91486, "公积金账号"), fundItem.getFundAccount());
Map<String, Object> fundJson = JSON.parseObject(fundItem.getFundPaymentBaseString(), new TypeReference<Map<String, Object>>() {
});
if (fundJson != null) {
fundJson.forEach((k, v) -> map.put(welfareMap.get(Long.valueOf(k)) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), v));
}
map.put(SalaryI18nUtil.getI18nLabel( 91487, "补充公积金账号"), fundItem.getSupplementFundAccount());
map.put(SalaryI18nUtil.getI18nLabel( 91483, "公积金起始缴纳月"), fundItem.getFundStartTime());
map.put(SalaryI18nUtil.getI18nLabel( 91484, "公积金最后缴纳月"), fundItem.getFundEndTime());
}
if (otherItem != null) {
map.put(SalaryI18nUtil.getI18nLabel( 91496, "其他福利方案名称"), schemeMap.get(otherItem.getOtherSchemeId()));
map.put(SalaryI18nUtil.getI18nLabel( 91497, "其他福利缴纳组织"), paymentMap.get(otherItem.getPaymentOrganization()));
Map<String, Object> otherJson = JSON.parseObject(otherItem.getOtherPaymentBaseString(), new TypeReference<Map<String, Object>>() {
});
if (otherJson != null) {
otherJson.forEach((k, v) -> map.put(welfareMap.get(Long.valueOf(k)) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), v));
}
map.put(SalaryI18nUtil.getI18nLabel( 91490, "其他福利起始缴纳月"), otherItem.getOtherStartTime());
map.put(SalaryI18nUtil.getI18nLabel( 91494, "其他福利最后缴纳月"), otherItem.getOtherEndTime());
}
records.add(map);
}
return records;
}
}