package com.engine.salary.service.impl; import com.alibaba.fastjson.JSON; import com.engine.core.impl.Service; import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.siaccount.param.SaveSupplementaryAccountParam; import com.engine.salary.entity.siaccount.param.SupplementAccountBaseParam; import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO; import com.engine.salary.entity.siarchives.po.InsuranceArchivesAccountPO; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.enums.siaccount.ProjectTypeEnum; import com.engine.salary.enums.sicategory.DataTypeEnum; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.service.SIRepairService; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.google.common.collect.Maps; import java.util.*; import java.util.stream.Collectors; /** * @Author: sy * @Description: 福利台账-补缴实现类 * @Date: 2022/12/27 **/ public class SIRepairServiceImpl extends Service implements SIRepairService { private EncryptUtil encryptUtil = new EncryptUtil(); private InsuranceAccountDetailMapper getInsuranceAccountDetailMapper() { return MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class); } /** * 获取指定月份的福利缴纳基数作为补缴基数 * @param param * @return */ @Override public List> getSupplementPaymentForm(SupplementAccountBaseParam param) { Long paymentOrganization = param.getPaymentOrganization(); String billMonth = param.getBillMonth(); List projects = param.getProjects(); Long employeeId = param.getEmployeeId(); List detailPOList = getInsuranceAccountDetailMapper().queryNormalList(billMonth, paymentOrganization, employeeId); if (detailPOList.size() > 1) { throw new SalaryRunTimeException("该人员本次核算出现多组数据,请删除数据库中多余核算项"); } else if (detailPOList.size() == 0) { throw new SalaryRunTimeException("数据不存在"); } else { InsuranceAccountDetailPO targetDetailPO = detailPOList.get(0); encryptUtil.decrypt(targetDetailPO, InsuranceAccountDetailPO.class); String socialBaseString = targetDetailPO.getSocialPaymentBaseString(); String fundBaseString = targetDetailPO.getFundPaymentBaseString(); String otherBaseString = targetDetailPO.getOtherPaymentBaseString(); Map socialBaseMap = JSON.parseObject(socialBaseString, HashMap.class); Map fundBaseMap = JSON.parseObject(fundBaseString, HashMap.class); Map otherBaseMap = JSON.parseObject(otherBaseString, HashMap.class); Map targetBaseMap = new HashMap<>(); List allCategoryList = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll(); Map categoryNameMap = SalaryEntityUtil.convert2Map(allCategoryList, ICategoryPO::getId, ICategoryPO::getInsuranceName); if (projects.contains(ProjectTypeEnum.ALL.getValue())) { targetBaseMap.putAll(socialBaseMap); targetBaseMap.putAll(fundBaseMap); targetBaseMap.putAll(otherBaseMap); } if (projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { targetBaseMap.putAll(socialBaseMap); } if (!projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { List list = MapperProxyFactory.getProxy(ICategoryMapper.class).listByDataType(DataTypeEnum.SYSTEM.getValue()); if (projects.contains(ProjectTypeEnum.ENDOWMENT_INSURANCE.getValue())) { ICategoryPO insuranceCategoryPO = list.stream().filter(item -> SalaryI18nUtil.getI18nLabel(93113, "养老保险").equals(item.getInsuranceName())).findFirst() .get(); targetBaseMap.put(insuranceCategoryPO.getId().toString(), socialBaseMap.get(insuranceCategoryPO.getId())); } if (projects.contains(ProjectTypeEnum.MEDICAL_INSURANCE.getValue())) { ICategoryPO insuranceCategoryPO = list.stream().filter(item -> SalaryI18nUtil.getI18nLabel(93114, "医疗保险").equals(item.getInsuranceName())).findFirst() .get(); targetBaseMap.put(insuranceCategoryPO.getId().toString(), socialBaseMap.get(insuranceCategoryPO.getId())); } } if (projects.contains(ProjectTypeEnum.FUND.getValue())) { targetBaseMap.putAll(fundBaseMap); } if (projects.contains(ProjectTypeEnum.OTHER.getValue())) { targetBaseMap.putAll(otherBaseMap); } List> resulit = new ArrayList(); if (targetBaseMap.size() > 0) { for (Map.Entry entry : targetBaseMap.entrySet()) { Map map = new HashMap<>(); map.put("insuranceId", entry.getKey()); map.put("insuranceName", categoryNameMap.get(Long.valueOf(entry.getKey()))); map.put("insuranceBase", entry.getValue()); resulit.add(map); } } return resulit; } } }