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

1436 lines
70 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.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.cloudstore.eccom.pc.table.*;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.biz.*;
import com.engine.salary.component.SalaryWeaTable;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
import com.engine.salary.encrypt.siaccount.InsuranceAccountDetailPOEncrypt;
import com.engine.salary.encrypt.siaccount.SiAccountEncrypt;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.siaccount.bo.InsuranceAccountBO;
import com.engine.salary.entity.siaccount.dto.InsuranceAccountBatchListDTO;
import com.engine.salary.entity.siaccount.dto.InsuranceAccountTabDTO;
import com.engine.salary.entity.siaccount.dto.InsuranceAccountViewListDTO;
import com.engine.salary.entity.siaccount.param.*;
import com.engine.salary.entity.siaccount.po.InsuranceAccountBatchPO;
import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO;
import com.engine.salary.entity.siaccount.po.InsuranceAccountInspectPO;
import com.engine.salary.entity.siarchives.po.InsuranceArchivesEmployeePO;
import com.engine.salary.entity.sicategory.po.ICategoryPO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.enums.UserStatusEnum;
import com.engine.salary.enums.siaccount.BillStatusEnum;
import com.engine.salary.enums.siaccount.InspectStatusEnum;
import com.engine.salary.enums.siaccount.PaymentStatusEnum;
import com.engine.salary.enums.siaccount.ProjectTypeEnum;
import com.engine.salary.enums.sicategory.WelfareTypeEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.siaccount.InsuranceAccountBatchMapper;
import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper;
import com.engine.salary.mapper.siaccount.InsuranceAccountInspectMapper;
import com.engine.salary.mapper.sicategory.ICategoryMapper;
import com.engine.salary.mapper.taxagent.TaxAgentMapper;
import com.engine.salary.service.*;
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryFormItemUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.excel.ExcelParseHelper;
import com.engine.salary.util.excel.ExcelSupport;
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 com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.file.ImageFileManager;
import weaver.general.Util;
import weaver.hrm.User;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static com.engine.salary.util.excel.ExcelSupport.EXCEL_TYPE_XLSX;
/**
* @Author weaver_cl
* @Description:
* @Date 2022/4/11
* @Version V1.0
**/
public class SIAccountServiceImpl extends Service implements SIAccountService {
// private SIAccountBiz siAccountBiz = new SIAccountBiz();
private SIArchivesBiz siArchivesBiz = new SIArchivesBiz();
public RecordsBuildService getService(User user) {
return ServiceUtil.getService(RecordsBuildServiceImpl.class, user);
}
public SIAccountBiz getSiAccountBiz(User user) {
return ServiceUtil.getService(SIAccountBiz.class, user);
}
public ColumnBuildService getColumnBuildService(User user) {
return ServiceUtil.getService(ColumnBuildServiceImpl.class, user);
}
public SICategoryService getSICategoryService(User user) {
return ServiceUtil.getService(SICategoryServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private InsuranceAccountBatchMapper getInsuranceAccountBatchMapper() {
return MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class);
}
private InsuranceAccountDetailMapper getInsuranceAccountDetailMapper() {
return MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class);
}
private SalaryItemService getSalaryItemService(User user) {
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
private TaxAgentMapper getTaxAgentMapper() {
return MapperProxyFactory.getProxy(TaxAgentMapper.class);
}
SICategoryBiz siCategoryBiz = new SICategoryBiz();
@Override
public Map<String, Object> listPage(InsuranceAccountBatchParam queryParam) {
Long employeeId = (long) user.getUID();
Map<String, Object> datas = new HashMap<>();
// 分权逻辑
Boolean needAuth = getTaxAgentService(user).isNeedAuth((long) user.getUID());
if (needAuth) {
Collection<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAllTaxAgents((long) user.getUID());
List<Long> taxAgents = taxAgentPOS.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(taxAgents)) {
//防止普通用户查询
queryParam.setTaxAgents(Collections.singletonList(-1L));
} else {
queryParam.setTaxAgents(taxAgents);
}
}
//福利台账列表
PageInfo<InsuranceAccountBatchPO> pageInfo = getSiAccountBiz(user).listPage(queryParam);
Collection<InsuranceAccountBatchPO> insuranceAccountBatchPOS = pageInfo.getList();
List<InsuranceAccountBatchListDTO> insuranceAccountBatchListDTOS = InsuranceAccountBO.buildAccountBatchDTOList(insuranceAccountBatchPOS);
PageInfo<InsuranceAccountBatchListDTO> pageInfos = new PageInfo<>(insuranceAccountBatchListDTOS, InsuranceAccountBatchListDTO.class);
pageInfos.setTotal(pageInfo.getTotal());
pageInfos.setPageNum(queryParam.getCurrent());
pageInfos.setPageSize(queryParam.getPageSize());
List<Map<Integer, List<Permission>>> operatesPermission = new ArrayList<>();
SalaryWeaTable<InsuranceAccountBatchListDTO> table = new SalaryWeaTable<>(user, InsuranceAccountBatchListDTO.class);
List<Column> columns = pageInfos.getColumns();
List<WeaTableColumn> weaTableColumn = columns.stream().map(v -> new WeaTableColumn("100", v.getTitle(), v.getKey())).collect(Collectors.toList());
table.setColumns(weaTableColumn);
//table.getColumns().get(0).setFixed("left");
// for (int i = 0; i < insuranceAccountBatchListDTOS.size(); i++) {
// InsuranceAccountBatchListDTO insuranceAccountBatchListDTO = insuranceAccountBatchListDTOS.get(i);
// if (Objects.equals(insuranceAccountBatchListDTO.getBillStatus(), BillStatusEnum.ARCHIVED.getDefaultLabel())) {
// table.getOperates().getOperate().get(i).getIndex();
//
// resultTable.getOperatesPermission().get(i).get(0).setVisible(false);
// resultTable.getOperatesPermission().get(i).get(1).setVisible(false);
// resultTable.getOperatesPermission().get(i).get(2).setVisible(false);
// resultTable.getOperatesPermission().get(i).get(3).setVisible(false);
// resultTable.getOperates().get(4).setOuter(true);
// }
// if (Objects.equals(insuranceAccountBatchListDTO.getBillStatus(), BillStatusEnum.NOT_ARCHIVED.getDefaultLabel())) {
// resultTable.getOperatesPermission().get(i).get(4).setVisible(false);
// List<InsuranceAccountInspectPO> insuranceAccountInspectPOS = siAccountInspectService.listByBillMonth(insuranceAccountBatchListDTO.getBillMonth(), tenantKey);
// if (CollectionUtils.isEmpty(insuranceAccountInspectPOS)) {
// resultTable.getOperatesPermission().get(i).get(2).setVisible(false);
// }
// }
// }
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
datas.put("pageInfo", pageInfos);
datas.put("operatesPermission", operatesPermission);
datas.put("dataKey", result.getResultMap());
return datas;
// WeaTable<InsuranceAccountBatchListDTO> resultTable = FormatManager.<InsuranceAccountBatchListDTO>getInstance()
// .genTable(InsuranceAccountBatchListDTO.class, insuranceAccountBatchListDTOPage);
//
// resultTable.getOperates().forEach(e -> {
// if (e.getIndex() == 0) {
// e.setOuter(true);
// }
// });
// resultTable.setModule("hrmsalary");
// resultTable.getColumns().get(0).setFixed("left");
// return WeaResult.success(resultTable);
}
@Override
public Map<String, Object> listCommonPage(InsuranceAccountDetailParam queryParam) {
Long employeeId = (long) user.getUID();
Map<String, Object> datas = new HashMap<>();
//正常缴纳列表
PageInfo<InsuranceAccountDetailPO> pageInfo = getSiAccountBiz(user).listCommonPage(queryParam);
List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = pageInfo.getList();
//数据组装
List<Map<String, Object>> records = getService(user).buildCommonRecords(insuranceAccountDetailPOS, employeeId);
PageInfo<Map<String, Object>> pageInfos = new PageInfo<>(records);
pageInfos.setTotal(pageInfo.getTotal());
pageInfos.setPageNum(queryParam.getCurrent());
pageInfos.setPageSize(queryParam.getPageSize());
//动态列组装
List<WeaTableColumn> weaTableColumn = getColumnBuildService(user).buildCommonColumnsWithStyle(insuranceAccountDetailPOS, employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, false);
WeaTable table = new WeaTable();
table.setPageUID(UUID.randomUUID().toString());
table.setColumns(weaTableColumn);
List<Column> columns = weaTableColumn.stream().map(v -> new Column(v.getText(), v.getColumn(), v.getColumn())).collect(Collectors.toList());
pageInfos.setColumns(columns);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
datas.put("pageInfo", pageInfos);
//datas.put("dataKey",result.getResultMap());
return datas;
}
@Override
public Map<String, Object> listCommonPageByName(InsuranceAccountDetailParam queryParam) {
//增加查询参数userName
if (StringUtils.isNotBlank(queryParam.getUserName())) {
queryParam.setUserName(queryParam.getUserName());
}
return listCommonPage(queryParam);
}
@Override
public Map<String, Object> listSupplementaryPage(InsuranceAccountDetailParam queryParam) {
Long employeeId = (long) user.getUID();
Map<String, Object> datas = new HashMap<>();
//补缴缴纳列表
queryParam.setPaymentStatus(PaymentStatusEnum.REPAIR.getValue());
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
List<InsuranceAccountDetailPO> list = getInsuranceAccountDetailMapper().list(queryParam);
PageInfo<InsuranceAccountDetailPO> pageInfo = new PageInfo<>(list, InsuranceAccountDetailPO.class);
List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = pageInfo.getList();
InsuranceAccountDetailPOEncrypt.decryptInsuranceAccountDetailPOList(insuranceAccountDetailPOS);
//数据组装
List<Map<String, Object>> records = getService(user).buildCommonRecords(insuranceAccountDetailPOS, employeeId);
PageInfo<Map<String, Object>> pageInfos = new PageInfo<>(records);
pageInfos.setTotal(pageInfo.getTotal());
pageInfos.setPageNum(queryParam.getCurrent());
pageInfos.setPageSize(queryParam.getPageSize());
//动态列组装
List<WeaTableColumn> weaTableColumn = getColumnBuildService(user).buildCommonColumnsWithStyle(insuranceAccountDetailPOS, employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, true);
SalaryWeaTable<InsuranceAccountDetailPO> table = new SalaryWeaTable<>(user, InsuranceAccountDetailPO.class);
table.setColumns(weaTableColumn);
List<Column> columns = weaTableColumn.stream().map(v -> new Column(v.getText(), v.getColumn(), v.getColumn())).collect(Collectors.toList());
pageInfos.setColumns(columns);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
datas.put("pageInfo", pageInfos);
//datas.put("dataKey",result.getResultMap());
return datas;
}
@Override
public Map<String, Object> supplementaryByNameList(InsuranceAccountDetailParam queryParam) {
//增加查询参数userName
if (StringUtils.isNotBlank(queryParam.getUserName())) {
queryParam.setUserName(queryParam.getUserName());
}
return listSupplementaryPage(queryParam);
}
@Override
public Map<String, Object> getForm(Map<String, Object> params) {
Map<String, Object> apidatas = new HashMap<>();
//条件组
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> conditionItems = new ArrayList<>();
SearchConditionItem datePickerItem = SalaryFormItemUtil.datePickerItem(user, 2, 16, true, 2, "账单月份", "billMonth");
String minDate = SalaryDateUtil.getYearMonth(-1, 0);
String maxDate = SalaryDateUtil.getYearMonth(0, 6);
datePickerItem.setOtherParams(new HashMap<>());
datePickerItem.getOtherParams().put("minDate", minDate);
datePickerItem.getOtherParams().put("maxDate", maxDate);
List<InsuranceAccountBatchPO> billMonthList = getInsuranceAccountBatchMapper().listByTimeRange(minDate, maxDate);
SiAccountEncrypt.decryptInsuranceAccountBatchList(billMonthList);
if (CollectionUtils.isEmpty(billMonthList)) {
datePickerItem.getOtherParams().put("disabledData", Collections.emptyList());
} else {
datePickerItem.getOtherParams().put("disabledData", billMonthList.stream().map(InsuranceAccountBatchPO::getBillMonth).collect(Collectors.toList()));
}
datePickerItem.getOtherParams().put("type", "month");
datePickerItem.getOtherParams().put("format", "YYYY-MM");
datePickerItem.getOtherParams().put("showFormat", "YYYY-MM");
conditionItems.add(datePickerItem);
SearchConditionItem textareaItem = SalaryFormItemUtil.textareaItem(user, 2, 16, true, 2, 60, "备注", "remarks");
conditionItems.add(textareaItem);
addGroups.add(new SearchConditionGroup("常用条件", true, conditionItems));
apidatas.put("billMonth", SalaryDateUtil.getYearMonth(0, 0));
apidatas.put("condition", addGroups);
return apidatas;
}
@Override
public void save(AccountParam param) {
ValidUtil.doValidator(param);
Long employeeId = (long) user.getUID();
String lastName = user.getLastname();
getSiAccountBiz(user).save(param.isFlag(), param, employeeId, lastName);
}
@Override
public void commonAccount(SaveCommonAccountParam param) {
ValidUtil.doValidator(param);
Long employeeId = (long) user.getUID();
String currentUserName = user.getLastname();
getSiAccountBiz(user).saveCommonAccount(param, employeeId, currentUserName);
}
@Override
public void delete(AccountParam accountParam) {
Long employeeId = (long) user.getUID();
getSiAccountBiz(user).delete(accountParam, employeeId);
}
@Override
public void saveCommonAccount(SaveCommonAccountParam accountParam) {
Long employeeId = (long) user.getUID();
String currentUserName = user.getLastname();
getSiAccountBiz(user).saveCommonAccount(accountParam, employeeId, currentUserName);
}
@Override
public void saveSupplementaryAccount(SaveSupplementaryAccountParam saveSupplementaryAccountParam) {
ValidUtil.doValidator(saveSupplementaryAccountParam);
Long employeeId = (long) user.getUID();
String currentUserName = user.getLastname();
getSiAccountBiz(user).saveSupplementaryAccount(saveSupplementaryAccountParam, employeeId, currentUserName);
}
@Override
public void deleteCommonAccount(SaveCommonAccountParam param) {
ValidUtil.doValidator(param);
Long employeeId = (long) user.getUID();
String currentUserName = user.getLastname();
getSiAccountBiz(user).deleteCommonAccount(param, employeeId, currentUserName);
}
@Override
public void deleteSummplementaryAccount(List<SupplementAccountBaseParam> supplementAccountBaseParams) {
Long employeeId = (long) user.getUID();
String currentUserName = user.getLastname();
getSiAccountBiz(user).deleteSupplementaryAccount(supplementAccountBaseParams, employeeId, currentUserName);
}
@Override
public void file(AccountParam accountParam) {
Long employeeId = (long) user.getUID();
String billMonth = accountParam.getBillMonth();
getSiAccountBiz(user).file(billMonth, employeeId, accountParam.getPaymentOrganization());
}
@Override
public void unconfirmed(Collection<Long> ids) {
List<InsuranceAccountInspectPO> insuranceAccountInspectPOS = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getByInspectStatusAndIds(InspectStatusEnum.COMFORED.getValue(), ids);
if (CollectionUtils.isNotEmpty(insuranceAccountInspectPOS)) {
getInsuranceAccountDetailMapper().batchUnConfirmedInspectDetails(insuranceAccountInspectPOS.stream().map(InsuranceAccountInspectPO::getId).collect(Collectors.toList()));
}
}
@Override
public Map<String, Boolean> buttonCheck(String billMonth) {
Map<String, Boolean> result = new HashMap<>();
List<InsuranceAccountInspectPO> list = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getByInspectStatusAndBillMonth(InspectStatusEnum.IGNORE.getValue(), billMonth);
if (CollectionUtils.isEmpty(list)) {
result.put("displayFlag", false);
return result;
}
result.put("displayFlag", true);
return result;
}
@Override
public void ignore(Collection<Long> ids) {
List<InsuranceAccountInspectPO> insuranceAccountInspectPOS = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getByInspectStatusAndIds(InspectStatusEnum.IGNORE.getValue(), ids);
if (CollectionUtils.isNotEmpty(insuranceAccountInspectPOS)) {
getInsuranceAccountDetailMapper().batchIgnoreInspectDetails(insuranceAccountInspectPOS.stream().map(InsuranceAccountInspectPO::getId).collect(Collectors.toList()));
}
}
@Override
public InsuranceAccountTabDTO tabList(AccountParam build) {
InsuranceAccountTabDTO insuranceAccountTabDTO = InsuranceAccountTabDTO.builder().build();
InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(build.getBillMonth(), build.getPaymentOrganization());
insuranceAccountBatchPO = SiAccountEncrypt.decryptInsuranceAccountBatch(insuranceAccountBatchPO);
boolean isShow = false;
if (insuranceAccountBatchPO == null || insuranceAccountBatchPO.getBillStatus() == BillStatusEnum.NOT_ARCHIVED.getValue()) {
isShow = true;
}
if (insuranceAccountBatchPO != null) {
insuranceAccountTabDTO.setRemarks(insuranceAccountBatchPO.getRemarks());
}
List<Map<String, Object>> tabList = new ArrayList<>();
Map<String, Object> common = new HashMap<>();
common.put("id", "1");
common.put("content", SalaryI18nUtil.getI18nLabel(92265, "正常缴纳"));
tabList.add(common);
if (isShow) {
Map<String, Object> change = new HashMap<>();
change.put("id", "2");
change.put("content", SalaryI18nUtil.getI18nLabel(100509, "异动清单"));
tabList.add(change);
}
Map<String, Object> repair = new HashMap<>();
repair.put("id", "3");
repair.put("content", SalaryI18nUtil.getI18nLabel(92267, "补缴"));
tabList.add(repair);
Map<String, Object> overView = new HashMap<>();
overView.put("id", "4");
overView.put("content", SalaryI18nUtil.getI18nLabel(99927, "总览"));
tabList.add(overView);
insuranceAccountTabDTO.setTabList(tabList);
insuranceAccountTabDTO.setShow(isShow);
insuranceAccountTabDTO.setBillMonth(build.getBillMonth());
return insuranceAccountTabDTO;
}
@Override
public Map<String, Object> changeList(InsuranceAccountDetailParam param) {
Map<String, Object> datas = new HashMap<>();
Long employeeId = (long) user.getUID();
SalaryPageUtil.start(param.getCurrent(), param.getPageSize());
List<InsuranceArchivesEmployeePO> insuranceArchivesEmployeePOS = getInsuranceAccountDetailMapper().changeList(param.getUserName());
PageInfo<InsuranceArchivesEmployeePO> pageInfo = new PageInfo<>(insuranceArchivesEmployeePOS);
List<Map<String, Object>> records = siArchivesBiz.buildTableData(insuranceArchivesEmployeePOS);
PageInfo<Map<String, Object>> pageInfos = new PageInfo<>(records);
pageInfos.setTotal(pageInfo.getTotal());
pageInfos.setPageNum(param.getCurrent());
pageInfos.setPageSize(param.getPageSize());
List<WeaTableColumn> weaTableColumns = siArchivesBiz.buildWeaTableColumns(insuranceArchivesEmployeePOS, employeeId);
WeaTable table = new WeaTable();
table.setPageUID(UUID.randomUUID().toString());
table.setColumns(weaTableColumns);
table.setTableType(WeaTableType.CHECKBOX);
WeaTableOperates weaTableOperates = new WeaTableOperates();
WeaTableOperate weaTableOperate = new WeaTableOperate();
weaTableOperate.setIndex("0");
weaTableOperate.setText("移除");
WeaTableOperate weaTableOperate1 = new WeaTableOperate();
weaTableOperate1.setIndex("1");
weaTableOperate1.setText("添加");
table.setOperates(weaTableOperates);
List<List<Permission>> permissions = new ArrayList<>();
for (int i = 0; i < records.size(); i++) {
List<Permission> permission = new ArrayList<>();
if (UserStatusEnum.DEPARTURE.getDefaultLabel().equals(records.get(i).get("status"))) {
permission.add(new Permission(true, false));
permission.add(new Permission(false, false));
permissions.add(permission);
}
if (UserStatusEnum.DEPARTURE.getDefaultLabel().equals(records.get(i).get("status"))) {
permission.add(new Permission(false, false));
permission.add(new Permission(true, false));
permissions.add(permission);
}
}
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
datas.put("permissions", permissions);
datas.put("pageInfo", pageInfos);
datas.put("dataKey", result.getResultMap());
return datas;
}
@Override
public void accountInspect(InspectAccountParam param) {
Long employeeId = (long) user.getUID();
ValidUtil.doValidator(param);
String currentUserName = user.getLastname();
getSiAccountBiz(user).accountInspect(param.getIds(), param.getBillMonth(), employeeId, currentUserName);
}
@Override
public Map<String, Object> getInspectTable(InsuranceAccountDetailParam param) {
Map<String, Object> datas = new HashMap<>();
SalaryPageUtil.start(param.getCurrent(), param.getPageSize());
List<InsuranceAccountInspectPO> insuranceAccountInspectPOS = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getByBillMonth(param.getBillMonth());
List<Map<String, Object>> records = getService(user).buildInspectRecords(insuranceAccountInspectPOS);
PageInfo<Map<String, Object>> pageInfos = new PageInfo<>(records);
pageInfos.setTotal(records.size());
pageInfos.setPageNum(param.getCurrent());
pageInfos.setPageSize(param.getPageSize());
List<WeaTableColumn> weaTableColumns = getColumnBuildService(user).buildInspectColumns(insuranceAccountInspectPOS);
WeaTable table = new WeaTable();
table.setPageUID(UUID.randomUUID().toString());
table.setColumns(weaTableColumns);
table.setTableType(WeaTableType.CHECKBOX);
WeaTableOperates weaTableOperates = new WeaTableOperates();
WeaTableOperate weaTableOperate = new WeaTableOperate();
weaTableOperate.setIndex("0");
weaTableOperate.setText("忽略");
WeaTableOperate weaTableOperate1 = new WeaTableOperate();
weaTableOperate1.setIndex("1");
weaTableOperate1.setText("重置");
table.setOperates(weaTableOperates);
List<List<Permission>> permissions = new ArrayList<>();
for (int i = 0; i < records.size(); i++) {
List<Permission> permission = new ArrayList<>();
Permission permissionCheckBox = new Permission();
if (InspectStatusEnum.IGNORE.getValue() == records.get(i).get("inspectStatus")) {
permissionCheckBox.setVisible(true);
permissionCheckBox.setDisabled(false);
permission.add(new Permission(true, false));
permission.add(new Permission(false, true));
permissions.add(permission);
}
if (InspectStatusEnum.COMFORED.getValue() == records.get(i).get("inspectStatus")) {
permissionCheckBox.setVisible(true);
permissionCheckBox.setDisabled(true);
permission.add(new Permission(false, true));
permission.add(new Permission(true, false));
permissions.add(permission);
}
}
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
datas.put("permissions", permissions);
datas.put("pageInfo", pageInfos);
datas.put("dataKey", result.getResultMap());
return datas;
}
@Override
public Map<String, Object> getCommonForm(Map<String, Object> params) {
Map<String, Object> apidatas = new HashMap<>();
//条件组
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> conditionItems = new ArrayList<>();
List<SearchConditionItem> conditionItem = new ArrayList<>();
SearchConditionItem includes = SalaryFormItemUtil.browserItem(user, 18, 12, 2, true, "对象", "required", "17", "includes");
conditionItems.add(includes);
SearchConditionItem excludes = SalaryFormItemUtil.browserItem(user, 18, 12, 2, true, "选择人员", "required", "17", "excludes");
conditionItem.add(excludes);
addGroups.add(new SearchConditionGroup("人员范围", true, conditionItems));
addGroups.add(new SearchConditionGroup("人员范围排除", true, conditionItem));
apidatas.put("condition", addGroups);
return apidatas;
}
@Override
public Map<String, Object> getSupplementaryForm(Map<String, Object> params) {
Map<String, Object> apidatas = new HashMap<>();
//条件组
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> condition = new ArrayList<>();
List<SearchConditionItem> conditionItems = new ArrayList<>();
List<SearchConditionItem> conditionItem = new ArrayList<>();
SearchConditionItem billMonthList = SalaryFormItemUtil.datePickerItem(user, 2, 16, true, 2, "账单月份", "billMonth");
billMonthList.setMultiple(true);
billMonthList.setOtherParams(new HashMap<>());
billMonthList.getOtherParams().put("type", "months");
billMonthList.getOtherParams().put("format", "YYYY-MM");
billMonthList.getOtherParams().put("showFormat", "YYYY-MM");
billMonthList.setMultiple(true);
condition.add(billMonthList);
SearchConditionItem billProjects = SalaryFormItemUtil.selectItem(user, buildBillProjectsOptions(), 2, 16, 6, true, "补缴项目", "projects");
billProjects.setDetailtype(2);
condition.add(billProjects);
SearchConditionItem includes = SalaryFormItemUtil.browserItem(user, 18, 6, 3, true, "对象", "required", "17", "includes");
conditionItems.add(includes);
// SearchConditionItem excludes = SalaryFormItemUtil.browserItem(user, 18, 6, 2, true, "选择人员", "required", "17", "excludes");
// excludes.setViewAttr(2);
// conditionItem.add(excludes);
addGroups.add(new SearchConditionGroup("基础信息", true, condition));
addGroups.add(new SearchConditionGroup("人员范围", true, conditionItems));
// addGroups.add(new SearchConditionGroup("人员范围排除",true,conditionItem));
apidatas.put("condition", addGroups);
return apidatas;
}
@Override
public PageInfo<InsuranceAccountViewListDTO> overView(InsuranceAccountDetailParam queryParam) {
PageInfo<InsuranceAccountViewListDTO> pageInfos = getSiAccountBiz(user).overView(queryParam);
return pageInfos;
}
@Override
public List<Map<String, Object>> welfareData(String billMonth, List<Long> employeeIds, Long taxAgentId) {
InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(billMonth, taxAgentId);
insuranceAccountBatchPO = SiAccountEncrypt.decryptInsuranceAccountBatch(insuranceAccountBatchPO);
if (insuranceAccountBatchPO == null || Objects.equals(BillStatusEnum.NOT_ARCHIVED.getValue(), insuranceAccountBatchPO.getBillStatus())) {
return Lists.newArrayList();
}
List<InsuranceAccountDetailPO> list = queryList(billMonth, taxAgentId, employeeIds);
List<Map<String, Object>> result = new ArrayList<>();
list.stream().forEach(item -> {
Map<String, Object> record = new HashMap<>();
record.put("employeeId", item.getEmployeeId());
if (StringUtils.isNotEmpty(item.getSocialPerJson())) {
Map<String, Object> socialJson = JSON.parseObject(item.getSocialPerJson(), new HashMap<String, Object>().getClass());
socialJson.forEach((k, v) -> {
record.put(k + "socialPer", v);
});
}
if (StringUtils.isNotEmpty(item.getSocialComJson())) {
Map<String, Object> socialJson = JSON.parseObject(item.getSocialComJson(), new HashMap<String, Object>().getClass());
socialJson.forEach((k, v) -> {
record.put(k + "socialCom", v);
});
}
record.put("socialPerSum", item.getSocialPerSum());
record.put("socialComSum", item.getSocialComSum());
if (StringUtils.isNotEmpty(item.getFundPerJson())) {
Map<String, Object> fundPerJson = JSON.parseObject(item.getFundPerJson(), new HashMap<String, Object>().getClass());
fundPerJson.forEach((k, v) -> {
record.put(k + "fundPer", v);
});
}
if (StringUtils.isNotEmpty(item.getFundComJson())) {
Map<String, Object> fundPerJson = JSON.parseObject(item.getFundComJson(), new HashMap<String, Object>().getClass());
fundPerJson.forEach((k, v) -> {
record.put(k + "fundCom", v);
});
}
record.put("fundPerSum", item.getFundPerSum());
record.put("fundComSum", item.getFundComSum());
if (StringUtils.isNotEmpty(item.getOtherPerJson())) {
Map<String, Object> fundPerJson = JSON.parseObject(item.getOtherPerJson(), new HashMap<String, Object>().getClass());
fundPerJson.forEach((k, v) -> {
record.put(k + "otherPer", v);
});
}
if (StringUtils.isNotEmpty(item.getOtherComJson())) {
Map<String, Object> fundComJson = JSON.parseObject(item.getOtherComJson(), new HashMap<String, Object>().getClass());
if (fundComJson != null) {
}
fundComJson.forEach((k, v) -> {
record.put(k + "otherCom", v);
});
}
record.put("otherPerSum", item.getOtherPerSum());
record.put("otherComSum", item.getOtherComSum());
record.put("perSum", item.getPerSum());
record.put("comSum", item.getComSum());
result.add(record);
});
return result;
}
@Override
public Map<String, String> welfareColumns() {
List<ICategoryPO> listAll = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll();
List<ICategoryPO> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(listAll)) {
list.addAll(listAll);
}
Map<String, String> result = new LinkedHashMap<>();
result.put(SalaryI18nUtil.getI18nLabel(100393, "个人合计"), "perSum");
result.put(SalaryI18nUtil.getI18nLabel(100388, "社保个人合计"), "socialPerSum");
result.put(SalaryI18nUtil.getI18nLabel(100390, "公积金个人合计"), "fundPerSum");
result.put(SalaryI18nUtil.getI18nLabel(100392, "其他福利个人合计"), "otherPerSum");
Map<String, String> categoryIdNameMap = getSICategoryService(user).categoryIdNameMap();
list.stream().forEach(item -> {
if (Objects.equals(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), item.getWelfareType())) {
result.put(categoryIdNameMap.get(String.valueOf(item.getId())) + SalaryI18nUtil.getI18nLabel(87159, "个人"), item.getId() + "socialPer");
}
if (Objects.equals(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), item.getWelfareType())) {
result.put(categoryIdNameMap.get(String.valueOf(item.getId())) + SalaryI18nUtil.getI18nLabel(87159, "个人"), item.getId() + "fundPer");
}
if (Objects.equals(WelfareTypeEnum.OTHER.getValue(), item.getWelfareType())) {
result.put(categoryIdNameMap.get(String.valueOf(item.getId())) + SalaryI18nUtil.getI18nLabel(87159, "个人"), item.getId() + "otherPer");
}
});
result.put(SalaryI18nUtil.getI18nLabel(100397, "单位合计"), "comSum");
result.put(SalaryI18nUtil.getI18nLabel(100394, "社保单位合计"), "socialComSum");
result.put(SalaryI18nUtil.getI18nLabel(100395, "公积金单位合计"), "fundComSum");
result.put(SalaryI18nUtil.getI18nLabel(100396, "其他福利单位合计"), "otherComSum");
list.stream().forEach(item -> {
if (Objects.equals(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), item.getWelfareType())) {
result.put(categoryIdNameMap.get(String.valueOf(item.getId())) + SalaryI18nUtil.getI18nLabel(100289, "单位"), item.getId() + "socialCom");
}
if (Objects.equals(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), item.getWelfareType())) {
result.put(categoryIdNameMap.get(String.valueOf(item.getId())) + SalaryI18nUtil.getI18nLabel(100289, "单位"), item.getId() + "fundCom");
}
if (Objects.equals(WelfareTypeEnum.OTHER.getValue(), item.getWelfareType())) {
result.put(categoryIdNameMap.get(String.valueOf(item.getId())) + SalaryI18nUtil.getI18nLabel(100289, "单位"), item.getId() + "otherCom");
}
});
return result;
}
public List<SearchConditionOption> buildBillProjectsOptions() {
List<SearchConditionOption> options = new ArrayList<>();
options.add(new SearchConditionOption(String.valueOf(ProjectTypeEnum.ALL.getValue()),
SalaryI18nUtil.getI18nLabel(ProjectTypeEnum.ALL.getLabelId(), ProjectTypeEnum.ALL.getDefaultLabel())));
options.add(new SearchConditionOption(String.valueOf(ProjectTypeEnum.SOCIAL.getValue()),
SalaryI18nUtil.getI18nLabel(ProjectTypeEnum.SOCIAL.getLabelId(), ProjectTypeEnum.SOCIAL.getDefaultLabel())));
options.add(new SearchConditionOption(String.valueOf(ProjectTypeEnum.FUND.getValue()),
SalaryI18nUtil.getI18nLabel(ProjectTypeEnum.FUND.getLabelId(), ProjectTypeEnum.FUND.getDefaultLabel())));
options.add(new SearchConditionOption(String.valueOf(ProjectTypeEnum.OTHER.getValue()),
SalaryI18nUtil.getI18nLabel(ProjectTypeEnum.OTHER.getLabelId(), ProjectTypeEnum.OTHER.getDefaultLabel())));
options.add(new SearchConditionOption(String.valueOf(ProjectTypeEnum.ENDOWMENT_INSURANCE.getValue()),
SalaryI18nUtil.getI18nLabel(ProjectTypeEnum.ENDOWMENT_INSURANCE.getLabelId(), ProjectTypeEnum.ENDOWMENT_INSURANCE.getDefaultLabel())));
options.add(new SearchConditionOption(String.valueOf(ProjectTypeEnum.MEDICAL_INSURANCE.getValue()),
SalaryI18nUtil.getI18nLabel(ProjectTypeEnum.MEDICAL_INSURANCE.getLabelId(), ProjectTypeEnum.MEDICAL_INSURANCE.getDefaultLabel())));
return options;
}
public List<InsuranceAccountDetailPO> queryList(String billMonth, Long taxAgentId, List<Long> employeeIds) {
List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().queryList(billMonth, taxAgentId, employeeIds);
List<InsuranceAccountDetailPO> list = buildNewInsuranceDetailPOS(insuranceAccountDetailPOS);
// InsuranceAccountDetailPOEncrypt.decryptInsuranceAccountDetailPOList(list);
return list;
}
public List<InsuranceAccountDetailPO> buildNewInsuranceDetailPOS(List<InsuranceAccountDetailPO> list) {
List<InsuranceAccountDetailPO> newList = new ArrayList<>();
if (CollectionUtils.isEmpty(list)) {
return newList;
}
Map<Long, List<InsuranceAccountDetailPO>> employeeMap = list.stream().filter(item -> item.getEmployeeId() != null)
.collect(Collectors.groupingBy(InsuranceAccountDetailPO::getEmployeeId));
for (Map.Entry<Long, List<InsuranceAccountDetailPO>> entry : employeeMap.entrySet()) {
Long k = entry.getKey();
List<InsuranceAccountDetailPO> v = entry.getValue();
InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO();
insuranceAccountDetailPO.setEmployeeId(k);
Map<String, String> socialPerMap = new HashMap<>();
Map<String, String> fundPerMap = new HashMap<>();
Map<String, String> otherPerMap = new HashMap<>();
Map<String, String> socialComMap = new HashMap<>();
Map<String, String> fundComMap = new HashMap<>();
Map<String, String> otherComMap = new HashMap<>();
BigDecimal socialPer = new BigDecimal("0");
BigDecimal socialCom = new BigDecimal("0");
BigDecimal fundPer = new BigDecimal("0");
BigDecimal fundCom = new BigDecimal("0");
BigDecimal otherPer = new BigDecimal("0");
BigDecimal otherCom = new BigDecimal("0");
BigDecimal perSum = new BigDecimal("0");
BigDecimal comSum = new BigDecimal("0");
for (InsuranceAccountDetailPO item : v) {
InsuranceAccountDetailPOEncrypt.decryptItem(item);
BigDecimal socialPerSum = StringUtils.isBlank(item.getSocialPerSum()) ? new BigDecimal("0") : new BigDecimal(item.getSocialPerSum());
BigDecimal socialComSum = StringUtils.isBlank(item.getSocialComSum()) ? new BigDecimal("0") : new BigDecimal(item.getSocialComSum());
BigDecimal fundPerSum = StringUtils.isBlank(item.getFundPerSum()) ? new BigDecimal("0") : new BigDecimal(item.getFundPerSum());
BigDecimal fundComSum = StringUtils.isBlank(item.getFundComSum()) ? new BigDecimal("0") : new BigDecimal(item.getFundComSum());
BigDecimal otherPerSum = StringUtils.isBlank(item.getOtherPerSum()) ? new BigDecimal("0") : new BigDecimal(item.getOtherPerSum());
BigDecimal otherComSum = StringUtils.isBlank(item.getOtherComSum()) ? new BigDecimal("0") : new BigDecimal(item.getOtherComSum());
BigDecimal perSumItem = StringUtils.isBlank(item.getPerSum()) ? new BigDecimal("0") : new BigDecimal(item.getPerSum());
BigDecimal comSumItem = StringUtils.isBlank(item.getComSum()) ? new BigDecimal("0") : new BigDecimal(item.getComSum());
socialPer = socialPer.add(socialPerSum);
socialCom = socialCom.add(socialComSum);
fundPer = fundPer.add(fundPerSum);
fundCom = fundCom.add(fundComSum);
otherPer = otherPer.add(otherPerSum);
otherCom = otherCom.add(otherComSum);
perSum = perSum.add(perSumItem);
comSum = comSum.add(comSumItem);
if (StringUtils.isNotBlank(item.getSocialPerJson())) {
Map<String, String> socialJson = JSON.parseObject(item.getSocialPerJson(), new HashMap<String, String>().getClass());
if (socialJson != null) {
socialJson.forEach((insuranceId, num) -> {
if (socialPerMap.get(insuranceId) == null) {
socialPerMap.put(insuranceId, num);
} else {
String oldNum = socialPerMap.get(insuranceId);
BigDecimal insuanceNum = new BigDecimal("0");
BigDecimal oldDecimal = new BigDecimal(oldNum);
BigDecimal numDecimal = num == null ? new BigDecimal("0") : new BigDecimal(num);
insuanceNum = insuanceNum.add(numDecimal).add(oldDecimal);
socialPerMap.put(insuranceId, insuanceNum.toPlainString());
}
});
}
}
if (StringUtils.isNotBlank(item.getSocialComJson())) {
Map<String, String> socialJson = JSON.parseObject(item.getSocialComJson(), new HashMap<String, String>().getClass());
if (socialJson != null) {
socialJson.forEach((insuranceId, num) -> {
if (socialComMap.get(insuranceId) == null) {
socialComMap.put(insuranceId, num);
} else {
String oldNum = socialComMap.get(insuranceId);
BigDecimal insuanceNum = new BigDecimal("0");
BigDecimal oldDecimal = new BigDecimal(oldNum);
BigDecimal numDecimal = num == null ? new BigDecimal("0") : new BigDecimal(num);
insuanceNum = insuanceNum.add(numDecimal).add(oldDecimal);
socialComMap.put(insuranceId, insuanceNum.toPlainString());
}
});
}
}
if (StringUtils.isNotBlank(item.getFundPerJson())) {
Map<String, String> fundJson = JSON.parseObject(item.getFundPerJson(), new HashMap<String, String>().getClass());
if (fundJson != null) {
fundJson.forEach((insuranceId, num) -> {
if (fundPerMap.get(insuranceId) == null) {
fundPerMap.put(insuranceId, num);
} else {
String oldNum = fundPerMap.get(insuranceId);
BigDecimal insuanceNum = new BigDecimal("0");
BigDecimal oldDecimal = new BigDecimal(oldNum);
BigDecimal numDecimal = num == null ? new BigDecimal("0") : new BigDecimal(num);
insuanceNum = insuanceNum.add(numDecimal).add(oldDecimal);
fundPerMap.put(insuranceId, insuanceNum.toPlainString());
}
});
}
}
if (StringUtils.isNotBlank(item.getFundComJson())) {
Map<String, String> fundJson = JSON.parseObject(item.getFundComJson(), new HashMap<String, String>().getClass());
if (fundJson != null) {
fundJson.forEach((insuranceId, num) -> {
if (fundComMap.get(insuranceId) == null) {
fundComMap.put(insuranceId, num);
} else {
String oldNum = fundComMap.get(insuranceId);
BigDecimal insuanceNum = new BigDecimal("0");
BigDecimal oldDecimal = new BigDecimal(oldNum);
BigDecimal numDecimal = num == null ? new BigDecimal("0") : new BigDecimal(num);
insuanceNum = insuanceNum.add(numDecimal).add(oldDecimal);
fundComMap.put(insuranceId, insuanceNum.toPlainString());
}
});
}
}
if (StringUtils.isNotBlank(item.getOtherPerJson())) {
Map<String, String> otherJson = JSON.parseObject(item.getOtherPerJson(), new HashMap<String, String>().getClass());
if (otherJson != null) {
otherJson.forEach((insuranceId, num) -> {
if (otherPerMap.get(insuranceId) == null) {
otherPerMap.put(insuranceId, num);
} else {
String oldNum = otherPerMap.get(insuranceId);
BigDecimal insuanceNum = new BigDecimal("0");
BigDecimal oldDecimal = new BigDecimal(oldNum);
BigDecimal numDecimal = num == null ? new BigDecimal("0") : new BigDecimal(num);
insuanceNum = insuanceNum.add(numDecimal).add(oldDecimal);
otherPerMap.put(insuranceId, insuanceNum.toPlainString());
}
});
}
}
if (StringUtils.isNotBlank(item.getOtherComJson())) {
Map<String, String> otherJson = JSON.parseObject(item.getOtherComJson(), new HashMap<String, String>().getClass());
if (otherJson != null) {
otherJson.forEach((insuranceId, num) -> {
if (otherComMap.get(insuranceId) == null) {
otherComMap.put(insuranceId, num);
} else {
String oldNum = otherComMap.get(insuranceId);
BigDecimal insuanceNum = new BigDecimal("0");
BigDecimal oldDecimal = new BigDecimal(oldNum);
BigDecimal numDecimal = num == null ? new BigDecimal("0") : new BigDecimal(num);
insuanceNum = insuanceNum.add(numDecimal).add(oldDecimal);
otherComMap.put(insuranceId, insuanceNum.toPlainString());
}
});
}
}
}
insuranceAccountDetailPO.setSocialPerJson(JSON.toJSONString(socialPerMap));
insuranceAccountDetailPO.setSocialComJson(JSON.toJSONString(socialComMap));
insuranceAccountDetailPO.setFundPerJson(JSON.toJSONString(fundPerMap));
insuranceAccountDetailPO.setFundComJson(JSON.toJSONString(fundComMap));
insuranceAccountDetailPO.setOtherPerJson(JSON.toJSONString(otherPerMap));
insuranceAccountDetailPO.setOtherComJson(JSON.toJSONString(otherComMap));
insuranceAccountDetailPO.setSocialPerSum(socialPer.toPlainString());
insuranceAccountDetailPO.setSocialComSum(socialCom.toPlainString());
insuranceAccountDetailPO.setFundPerSum(fundPer.toPlainString());
insuranceAccountDetailPO.setFundComSum(fundCom.toPlainString());
insuranceAccountDetailPO.setOtherPerSum(otherPer.toPlainString());
insuranceAccountDetailPO.setOtherComSum(otherCom.toPlainString());
insuranceAccountDetailPO.setPerSum(perSum.toPlainString());
insuranceAccountDetailPO.setComSum(comSum.toPlainString());
newList.add(insuranceAccountDetailPO);
}
return newList;
}
@Override
public List<InsuranceAccountInspectPO> allInspects(Collection<Long> ids, String billMonth) {
InsuranceAccountInspectMapper siAccountInspectMapper = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class);
List<InsuranceAccountInspectPO> list = siAccountInspectMapper.getList(billMonth, InspectStatusEnum.IGNORE.getValue(), ids);
if (CollectionUtils.isNotEmpty(list)) {
return list;
}
return Collections.emptyList();
}
@Override
public Collection<TaxAgentPO> getAdminTaxAgentList() {
return getTaxAgentService(user).listAllTaxAgentsAsAdmin((long) user.getUID());
}
@Override
public void socialSecurityBenefitsRecalculate(InsuranceAccountBatchPO param) {
int num = getSiAccountBiz(user).checkIfBusinessaccounting(param);
//表示已经被核算过不能重新核算
if (num > 0) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98831, "已被薪酬核算给核算过,无法重新核算!"));
}
param.setBillStatus(0);
getSiAccountBiz(user).updateById(param);
}
/**
* 导出“福利核算导入模板”
*/
@Override
public XSSFWorkbook exportImportTemplate(InsuranceAcctDetailImportTemplateParam param) {
ValidUtil.doValidator(param);
// 必须选择导入模板所需的薪资项目(福利项)
if (CollectionUtils.isEmpty(param.getWelfareNames())) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(99019, "参数错误,请选择导入模板所需的福利项目核算项"));
}
// 模板表头(默认必带"个税扣缴义务人"、"姓名")
List<Object> headerList = Lists.newArrayList(SalaryI18nUtil.getI18nLabel(85429, "姓名"),
"部门",
SalaryI18nUtil.getI18nLabel(86186, "手机号"),
SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"),
"账单月份");
// List<String> dataIndexList = Lists.newArrayList("username", "departmentName", "mobile", "taxAgentName", "billMonth");
// 查询福利核算项目
List<String> welfareNames = (List<String>) param.getWelfareNames();
headerList.addAll(welfareNames);
// excel导出的数据
List<List<Object>> rows = new ArrayList<>();
rows.add(headerList);
String sheetName = "福利核算导入模板";
return ExcelUtil.genWorkbookV2(rows, sheetName);
}
/**
* 将福利核算模板导入的数据更新到数据库
*/
@Override
public Map<String, Object> importInsuranceAcctDetail(InsuranceAcctImportParam importParam) {
// long currentEmployeeId = user.getUID();
// Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
Map<String, Object> apidatas = new HashMap<String, Object>();
EmployBiz employBiz = new EmployBiz();
//检验参数
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
if (StringUtils.isBlank(imageId)) {
throw new SalaryRunTimeException("文件不存在");
}
// // 获取所有个税扣缴义务人
// List<TaxAgentPO> taxAgents = getTaxAgentService(user).listAll();
// Map<String, Long> taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgents, TaxAgentPO::getName, TaxAgentPO::getId);
// 获取租户下所有的人员
List<DataCollectionEmployee> salaryEmployees = employBiz.listEmployee();
// 失败的数量
int failCount = 0;
// 成功的数量
int successCount = 0;
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(importParam.getImageId()));
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
// 错误提示信息
List<Map> excelComments = Lists.newArrayList();
// 存在错误的那行数据
List<Map<String, Object>> errorDatas = Lists.newArrayList();
// 表头
List<String> headers = ExcelSupport.getSheetHeader(sheet, 0);
// 处理数值
List<Map<String, Object>> data = ExcelParseHelper.parse2Map(sheet, 1);
if (CollectionUtils.isEmpty(headers)) {
throw new RuntimeException("表头为空");
}
if (CollectionUtils.isEmpty(data)) {
throw new RuntimeException("无数据");
}
//存储待更新的InsuranceAccountDetailPO数据
List<InsuranceAccountDetailPO> updateInsuranceAccountDetailList = new ArrayList<>();
//遍历excel表具体数据
for (int i = 0; i < data.size(); i++) {
String row = "" + (i + 2) + "";
boolean isError = false;
Map<String, Object> map = data.get(i);
Long employeeId = 0L;
// Long taxAgentId = 0L;
List<InsuranceAccountDetailPO> list = new ArrayList<>();
String billMonth = (String) map.getOrDefault("账单月份", "");
String taxAgentName = (String) map.getOrDefault("个税扣缴义务人", "");
Long paymentOrganization = 0L;
List<TaxAgentPO> taxAgentPoList = getTaxAgentMapper().listByName(taxAgentName);
if (taxAgentPoList.size() == 1) {
paymentOrganization = taxAgentPoList.get(0).getId();
} else {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + SalaryI18nUtil.getI18nLabel(100579, SalaryI18nUtil.getI18nLabel(102840, "个税扣缴义务人错误,系统内不存在该个税扣缴义务人")));
excelComments.add(errorMessageMap);
}
if (!checkBillMonth(billMonth)) {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + SalaryI18nUtil.getI18nLabel(100579, "账单月份输入有误请参照“2022-09”这种格式进行检查"));
excelComments.add(errorMessageMap);
}
//遍历表头
for (int j = 0; j < headers.size(); j++) {
String header = headers.get(j);
String dataKey = header;
if (dataKey == null) {
continue;
}
String dataValue = (String) map.getOrDefault(dataKey.toString(), "");
String deparmentName = (String) map.getOrDefault("部门", "");
String mobile = (String) map.getOrDefault("手机号", "");
if (StringUtils.equals(SalaryI18nUtil.getI18nLabel(85429, "姓名"), dataKey.toString())) {
if (StringUtils.isEmpty(dataValue)) {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + SalaryI18nUtil.getI18nLabel(102838, "姓名不能为空"));
excelComments.add(errorMessageMap);
} else {
List<DataCollectionEmployee> employeeSameIds = salaryEmployees.stream().filter(e -> (StringUtils.isBlank(dataValue) || Objects.equals(e.getUsername(), dataValue))
&& (StringUtils.isBlank(deparmentName) || Objects.equals(e.getDepartmentName(), deparmentName))
&& (StringUtils.isBlank(mobile) || Objects.equals(e.getMobile(), mobile)))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(employeeSameIds)) {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + SalaryI18nUtil.getI18nLabel(100579, "姓名错误,系统内不存在该姓名"));
excelComments.add(errorMessageMap);
} else if (employeeSameIds.size() > 1) {
//存在离职和在职状态取在职状态
employeeSameIds = employeeSameIds.stream()
.filter(e -> UserStatusEnum.getNormalStatus().contains(e.getStatus()))
.collect(Collectors.toList());
if (employeeSameIds.size() != 1) {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + "员工信息不能为空且不可重复(姓名、部门和手机号同时确认唯一)");
excelComments.add(errorMessageMap);
} else {
employeeId = CollectionUtils.isNotEmpty(employeeSameIds) && employeeSameIds.size() == 1 ? employeeSameIds.get(0).getEmployeeId() : null;
}
} else {
employeeId = employeeSameIds.get(0).getEmployeeId();
}
}
}else if (StringUtils.equals(SalaryI18nUtil.getI18nLabel(86184, "部门"), dataKey.toString())) {
} else if (StringUtils.equals(SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"), dataKey.toString())) {
}
}
if (!isError){
List<Long> employeeIds = new ArrayList<>();
employeeIds.add(employeeId);
//如果福利核算信息查询不到唯一匹配数据,不支持导入
//根据员工id、个税扣缴义务人id、账单月份查询
list = queryList(billMonth, paymentOrganization, employeeIds);
if (list.isEmpty()) {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + SalaryI18nUtil.getI18nLabel(100579, "本次福利核算不包含该人员"));
excelComments.add(errorMessageMap);
} else if (list.size() > 1) {
isError = true;
Map<String, String> errorMessageMap = Maps.newHashMap();
errorMessageMap.put("message", row + SalaryI18nUtil.getI18nLabel(100579, "该人员本次核算出现多组数据,请删除数据库中多余核算项"));
excelComments.add(errorMessageMap);
} else {
//拼装待更新数据
updateInsuranceAccountDetailList.add(handleInsuranceAccountDetail(list.get(0), map));
}
}
if (isError) {
failCount++;
errorDatas.add(map);
} else {
successCount++;
}
}
//将待更新列表加密
InsuranceAccountDetailPOEncrypt.encryptInsuranceAccountDetailPOList(updateInsuranceAccountDetailList);
//更新
for(InsuranceAccountDetailPO po : updateInsuranceAccountDetailList) {
getSiAccountBiz(user).updateByEmployeeIdAndBillMonth(po);
}
apidatas.put("successCount", successCount);
apidatas.put("errorCount", failCount);
apidatas.put("errorData", excelComments);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
/**
* 预览“福利核算导入”模板导入的数据
*/
@Override
public Map<String, Object> preview(InsuranceAcctImportParam param) {
//1、参数校验
String imageId = param.getImageId();
if (StringUtils.isBlank(imageId)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100593, "文件id为空"));
}
Map<String, Object> map = new HashMap<>();
InputStream fileInputStream = null;
try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(imageId));
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
List<String> headers = ExcelSupport.getSheetHeader(sheet, 0);
map.put("headers", headers);
map.put("list", ExcelParseHelper.parse2List(sheet, 1));
return map;
} finally {
IOUtils.closeQuietly(fileInputStream);
}
}
/**
* 将更新的数据设置到老的insuranceAccountDetailPO对象中
*/
private InsuranceAccountDetailPO handleInsuranceAccountDetail(InsuranceAccountDetailPO insuranceAccountDetailPO, Map<String, Object> baseMap) {
//组装json数据,格式Map<String, Object>
Map<String, String> socialPerMap = new HashMap<>();
Map<String, String> fundPerMap = new HashMap<>();
Map<String, String> otherPerMap = new HashMap<>();
Map<String, String> socialComMap = new HashMap<>();
Map<String, String> fundComMap = new HashMap<>();
Map<String, String> otherComMap = new HashMap<>();
//筛选出福利核算项
Map<String, Object> toDealMap =
baseMap.entrySet().stream()
.filter(map -> !"姓名".equals(map.getKey())
&& !"部门".equals(map.getKey())
&& !"手机号".equals(map.getKey())
&& !"个税扣缴义务人".equals(map.getKey())
&& !"账单月份".equals(map.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
for(Map.Entry<String, Object> entry : toDealMap.entrySet()) {
//判断元素是否属于福利类
String keyName = entry.getKey();
//获取元素名后缀,方便之后判断“个人”或“单位”
String payScope = keyName.substring(keyName.length() - 2);
//获取福利类型
Integer welfareType;
List<ICategoryPO> categoryPOList = siCategoryBiz.listByName(entry.getKey().substring(0, keyName.length() - 2));
if (categoryPOList.size() == 1) {
ICategoryPO iCategoryPO = categoryPOList.get(0);
welfareType = iCategoryPO.getWelfareType();
if ("个人".equals(payScope)) {
switch (welfareType) {
case 1:
socialPerMap.put(iCategoryPO.getId().toString(), entry.getValue().toString());
break;
case 2:
fundPerMap.put(iCategoryPO.getId().toString(), entry.getValue().toString());
break;
case 3:
otherPerMap.put(iCategoryPO.getId().toString(), entry.getValue().toString());
break;
default:
throw new SalaryRunTimeException("福利类型不存在");
}
} else if ("单位".equals(payScope)) {
switch (welfareType) {
case 1:
socialComMap.put(iCategoryPO.getId().toString(), entry.getValue().toString());
break;
case 2:
fundComMap.put(iCategoryPO.getId().toString(), entry.getValue().toString());
break;
case 3:
otherComMap.put(iCategoryPO.getId().toString(), entry.getValue().toString());
break;
default:
throw new SalaryRunTimeException("福利类型不存在");
}
}
}
}
// //解密insuranceAccountDetailPO
// InsuranceAccountDetailPOEncrypt.decryptItem(insuranceAccountDetailPO);
//组装新的insuranceAccountDetailPO对象数据
if (!socialPerMap.isEmpty()) {
//对比新旧json中数据并输出最终json
checkJsonMap(socialPerMap, insuranceAccountDetailPO.getSocialPerJson());
insuranceAccountDetailPO.setSocialPerJson(JSON.toJSONString(socialPerMap));
}
if (!socialComMap.isEmpty()) {
checkJsonMap(socialComMap, insuranceAccountDetailPO.getSocialComJson());
insuranceAccountDetailPO.setSocialComJson(JSON.toJSONString(socialComMap));
}
if (!fundPerMap.isEmpty()) {
checkJsonMap(fundPerMap, insuranceAccountDetailPO.getFundPerJson());
insuranceAccountDetailPO.setFundPerJson(JSON.toJSONString(fundPerMap));
}
if (!fundComMap.isEmpty()) {
checkJsonMap(fundComMap, insuranceAccountDetailPO.getFundComJson());
insuranceAccountDetailPO.setFundComJson(JSON.toJSONString(fundComMap));
}
if (!otherPerMap.isEmpty()) {
checkJsonMap(otherPerMap, insuranceAccountDetailPO.getOtherPerJson());
insuranceAccountDetailPO.setOtherPerJson(JSON.toJSONString(otherPerMap));
}
if (!otherComMap.isEmpty()) {
checkJsonMap(otherComMap, insuranceAccountDetailPO.getOtherComJson());
insuranceAccountDetailPO.setOtherComJson(JSON.toJSONString(otherComMap));
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("个人合计", "").toString())) {
insuranceAccountDetailPO.setPerSum(baseMap.get("个人合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("社保个人合计", "").toString())) {
insuranceAccountDetailPO.setSocialPerSum(baseMap.get("社保个人合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("公积金个人合计", "").toString())) {
insuranceAccountDetailPO.setFundPerSum(baseMap.get("公积金个人合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("其他福利个人合计", "").toString())) {
insuranceAccountDetailPO.setOtherPerSum(baseMap.get("其他福利个人合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("单位合计", "").toString())) {
insuranceAccountDetailPO.setComSum(baseMap.get("单位合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("社保单位合计", "").toString())) {
insuranceAccountDetailPO.setSocialComSum(baseMap.get("社保单位合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("公积金单位合计", "").toString())) {
insuranceAccountDetailPO.setFundComSum(baseMap.get("公积金单位合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("其他福利单位合计", "").toString())) {
insuranceAccountDetailPO.setOtherComSum(baseMap.get("其他福利单位合计").toString());
}
if (!StringUtils.isEmpty(baseMap.getOrDefault("账单月份", "").toString())) {
insuranceAccountDetailPO.setBillMonth(baseMap.get("账单月份").toString());
}
insuranceAccountDetailPO.setUpdateTime(new Date());
return insuranceAccountDetailPO;
}
/**
* 对比新旧两份数据,并更新数据
*/
private Map<String, String> checkJsonMap(Map<String, String> newMap, String oldJson) {
Map<String, String> oldMap = JSON.parseObject(oldJson, HashMap.class);
//校验newMap中的value值是否为整数或者小数
for(Map.Entry<String, String> newEntry : newMap.entrySet()) {
String newValue = newEntry.getValue();
int l = newValue.length();
if (newValue.length() > 0 && !isNumeric(newValue)) {
throw new SalaryRunTimeException("请检查导入Excel中个人或单位对应的福利项数值是否为整数或小数");
}
}
//保留oldMap无变动数据更新newMap已变动数据
for (Map.Entry<String, String> oldEntry : oldMap.entrySet()) {
if (!newMap.containsKey(oldEntry.getKey())) {
newMap.put(oldEntry.getKey(), oldEntry.getValue());
} else if (newMap.containsKey(oldEntry.getKey()) && "".equals(newMap.get(oldEntry.getKey()))) {
newMap.put(oldEntry.getKey(), oldEntry.getValue());
}
}
return newMap;
}
/**
* 判断字符串是否为整数或者小数
*/
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*\\.?[0-9]+");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
/**
* 校验福利核算的账单月份输入格式是否正确
*/
public boolean checkBillMonth(String billMonth) {
//校验内容billMonth的长度是否为7、年月连接符是否为“-”
String connector;
if(billMonth.length() == 7){
connector = billMonth.substring(4,5);
return "-".equals(connector);
} else {
return false;
}
}
}