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

295 lines
16 KiB
Java
Raw Normal View History

2022-04-20 19:12:01 +08:00
package com.engine.salary.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
2022-07-25 09:57:15 +08:00
import com.cloudstore.eccom.pc.table.WeaTableColumn;
2022-04-20 19:12:01 +08:00
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
2022-06-15 10:23:39 +08:00
import com.engine.salary.biz.SIArchivesBiz;
2022-05-31 16:02:41 +08:00
import com.engine.salary.encrypt.siarchives.InsuranceArchivesFundSchemePOEncrypt;
import com.engine.salary.encrypt.siarchives.InsuranceArchivesOtherSchemePOEncrypt;
import com.engine.salary.encrypt.siarchives.InsuranceArchivesSocialSchemePOEncrypt;
2022-04-20 19:12:01 +08:00
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;
2022-07-25 14:33:35 +08:00
import com.engine.salary.mapper.siarchives.SocialSchemeMapper;
2022-04-20 19:12:01 +08:00
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;
2022-08-02 17:57:29 +08:00
import com.engine.salary.util.excel.ExcelComment;
2022-04-20 19:12:01 +08:00
import com.engine.salary.util.excel.ExcelUtil;
2022-07-25 14:33:35 +08:00
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
2022-07-25 09:57:15 +08:00
import com.google.common.collect.Lists;
2022-04-20 19:12:01 +08:00
import org.apache.commons.collections4.CollectionUtils;
2022-07-25 14:33:35 +08:00
import org.apache.ibatis.session.SqlSession;
2022-04-20 19:12:01 +08:00
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2022-07-25 14:33:35 +08:00
import weaver.conn.mybatis.MyBatisFactory;
2022-04-20 19:12:01 +08:00
import weaver.hrm.User;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author weaver_cl
2022-07-13 11:45:16 +08:00
* @Description:
2022-04-20 19:12:01 +08:00
* @Date 2022/4/20
* @Version V1.0
**/
public class SIImportServiceImpl extends Service implements SIImportService {
2022-06-15 10:23:39 +08:00
private SIArchivesBiz siArchivesBiz = new SIArchivesBiz();
2022-04-20 19:12:01 +08:00
public SIArchivesService getSIArchivesService(User user) {
return ServiceUtil.getService(SIArchivesServiceImpl.class,user);
}
@Override
public XSSFWorkbook exportTemplate(InsuranceArchivesListParam param) {
//工作簿list
List<List<Object>> excelSheetData = new ArrayList<>();
2022-07-25 11:13:18 +08:00
Boolean exportData = param.getExportData();
2022-04-20 19:12:01 +08:00
//工作簿名称
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;
}
2022-05-19 09:33:07 +08:00
// 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);
2022-04-20 19:12:01 +08:00
//表头
2022-04-21 15:04:35 +08:00
excelSheetData.add(Arrays.asList(headers.toArray(new String[0])));
2022-07-25 11:13:18 +08:00
/**
* 导出数据
*/
if (exportData != null && exportData){
2022-07-25 14:33:35 +08:00
//查询总页数
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
SocialSchemeMapper socialSchemeMapper = sqlSession.getMapper(SocialSchemeMapper.class);
List<InsuranceArchivesEmployeePO> page = new ArrayList<>();
SalaryPageUtil.start(param.getCurrent(), param.getPageSize());
page = socialSchemeMapper.queryEmployeeList(param);
PageInfo<InsuranceArchivesEmployeePO> pageInfo = new PageInfo<>(page, InsuranceArchivesEmployeePO.class);
int total = (int)pageInfo.getTotal();
param.setPageSize(total);
param.setCurrent(1);
2022-07-25 11:13:18 +08:00
Map<String, Object> dataMap = getSIArchivesService(user).listPage(param);
List<Map<String, Object>> records = (List<Map<String, Object>>)dataMap.get("datas");
List<WeaTableColumn> columns = (List<WeaTableColumn>)dataMap.get("columns");
List<String> rowCloumn = Lists.newArrayList();
List<String> names = columns.stream().map(WeaTableColumn::getText).collect(Collectors.toList());
headers.forEach(header -> {
if (names.contains(header)){
columns.forEach(column -> {
//用来判断columns中是否包含header
if (header.equals(column.getText())){
rowCloumn.add(column.getColumn());
}
});
}else {
rowCloumn.add(null);
}
});
records.forEach(record -> {
List<Object> row = Lists.newArrayList();
rowCloumn.forEach(column -> row.add(record.get(column)));
excelSheetData.add(row);
});
}
2022-07-25 09:57:15 +08:00
2022-06-01 14:53:16 +08:00
// 3.表数据
2022-08-02 17:57:29 +08:00
// 4.注释
List<ExcelComment> excelComments = Lists.newArrayList();
excelComments.add(new ExcelComment(0, 0, 3, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
excelComments.add(new ExcelComment(4, 0, 5, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
excelComments.add(new ExcelComment(5, 0, 6, 2, SalaryI18nUtil.getI18nLabel(100344, "社保,公积金,其他福利方案名称不可同时为空")));
2022-04-20 19:12:01 +08:00
//工作簿数据
2022-08-02 17:57:29 +08:00
return ExcelUtil.genWorkbookV2(excelSheetData, sheetName,excelComments);
2022-04-20 19:12:01 +08:00
}
/**
* 构建档案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, "员工状态"));
2022-08-02 17:57:29 +08:00
result.add(SalaryI18nUtil.getI18nLabel( 86184, "个税扣缴义务人"));
2022-04-20 19:12:01 +08:00
result.add(SalaryI18nUtil.getI18nLabel( 91323, "社保方案名称"));
// result.add(SalaryI18nUtil.getI18nLabel( 91325, "社保缴纳组织"));
2022-04-20 19:12:01 +08:00
//社保福利基数
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, "公积金缴纳组织"));
2022-04-20 19:12:01 +08:00
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, "其他福利缴纳组织"));
2022-04-20 19:12:01 +08:00
//其他福利基数
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<>();
2022-06-15 10:23:39 +08:00
List<InsuranceArchivesSocialSchemePO> socialSchemePOList = siArchivesBiz.getSocialByEmployeeIds(employeeIds);
2022-05-31 16:02:41 +08:00
InsuranceArchivesSocialSchemePOEncrypt.decryptList(socialSchemePOList);
2022-04-20 19:12:01 +08:00
if (CollectionUtils.isNotEmpty(socialSchemePOList)) {
socialSchemePOMap = socialSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesSocialSchemePO::getEmployeeId, Function.identity()));
}
2022-06-15 10:23:39 +08:00
List<InsuranceArchivesFundSchemePO> fundSchemePOList = siArchivesBiz.getFundByEmployeeIds(employeeIds);
2022-05-31 16:02:41 +08:00
InsuranceArchivesFundSchemePOEncrypt.encryptList(fundSchemePOList);
2022-04-20 19:12:01 +08:00
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<>();
2022-06-15 10:23:39 +08:00
List<InsuranceArchivesOtherSchemePO> otherSchemePOList = siArchivesBiz.getOtherByEmployeeIds(employeeIds);
2022-05-31 16:02:41 +08:00
InsuranceArchivesOtherSchemePOEncrypt.decryptList(otherSchemePOList);
2022-04-20 19:12:01 +08:00
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().getDefaultLabel());
2022-04-20 19:12:01 +08:00
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;
}
}