package com.engine.salary.service.impl; import com.alibaba.fastjson.JSON; import com.api.formmode.mybatis.util.SqlProxyHandle; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.encrypt.siaccount.InsuranceAccountDetailPOEncrypt; import com.engine.salary.entity.hrm.dto.HrmInfoDTO; import com.engine.salary.entity.hrm.param.HrmQueryParam; import com.engine.salary.entity.siaccount.param.InsuranceAccountDetailParam; import com.engine.salary.entity.siaccount.param.RecessionParam; import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO; import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO; import com.engine.salary.enums.siaccount.BillStatusEnum; import com.engine.salary.enums.siaccount.PaymentStatusEnum; import com.engine.salary.enums.siaccount.ProjectTypeEnum; import com.engine.salary.enums.sicategory.DeleteTypeEnum; import com.engine.salary.mapper.datacollection.EmployMapper; import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper; import com.engine.salary.service.SIRecessionService; import com.engine.salary.service.TaxAgentService; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.engine.salary.util.page.PageInfo; import com.engine.salary.util.page.SalaryPageUtil; import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.apache.commons.collections4.CollectionUtils; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.SalaryAssert; import weaver.hrm.User; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * @Author: sy * @Description: 社保福利台账-退差实现类 * @Date: 2022/11/15 **/ public class SIRecessionServiceImpl extends Service implements SIRecessionService { private InsuranceAccountDetailMapper getInsuranceAccountDetailMapper() { return SqlProxyHandle.getProxy(InsuranceAccountDetailMapper.class); } private TaxAgentService getTaxAgentService(User user) { return ServiceUtil.getService(TaxAgentServiceImpl.class, user); } private EmployMapper getEmployMapper() { return MapperProxyFactory.getProxy(EmployMapper.class); } @Override public void save(RecessionParam param, Long employeeId) { //入参判断 if (StringUtils.isBlank(param.getPaymentOrganization()) || StringUtils.isBlank(param.getBillMonth()) || CollectionUtils.isEmpty(param.getRecessionMonthList()) || CollectionUtils.isEmpty(param.getIncludes()) || CollectionUtils.isEmpty(param.getProjects())) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误")); } //需要退差的员工 List employeeIds = param.getIncludes(); if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(param.getExcludes())) { employeeIds = employeeIds.stream().filter(item -> !param.getExcludes().contains(item)).collect(Collectors.toList()); } SalaryAssert.notEmpty(employeeIds, SalaryI18nUtil.getI18nLabel(133967, "无退差人员")); //查询退差员工对应的退差月份的正常缴纳的福利台账数据 List detailPOS= getInsuranceAccountDetailMapper().list(InsuranceAccountDetailParam.builder() .paymentStatus(PaymentStatusEnum.COMMON.getValue()) .recessionMonthList(param.getRecessionMonthList()) .employeeIds(employeeIds) .paymentOrganization(param.getPaymentOrganization()) .build()); InsuranceAccountDetailPOEncrypt.decryptInsuranceAccountDetailPOList(detailPOS); //处理数据 List finalDetailPOS = detailPOS; List finalRecessionDetails = new ArrayList<>(); employeeIds.forEach(id -> { param.getRecessionMonthList().forEach(billMonth -> { Optional detailPOOptional = finalDetailPOS.stream().filter( detail -> Objects.equals(billMonth, detail.getBillMonth()) && Objects.equals(id, detail.getEmployeeId())).findFirst(); detailPOOptional.ifPresent(insuranceAccountDetailPO -> recessionAccount(param, insuranceAccountDetailPO, finalRecessionDetails)); }); }); //退差数据入库 if (CollectionUtils.isNotEmpty(finalRecessionDetails)) { InsuranceAccountDetailPOEncrypt.encryptInsuranceAccountDetailPOList(finalRecessionDetails); List> partition = Lists.partition((List) finalRecessionDetails, 20); partition.forEach(getInsuranceAccountDetailMapper()::batchSaveAccountDetails); } } @Override public void del(Collection ids, Long employeeId) { //入参判断 if (CollectionUtils.isEmpty(ids)) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误")); } //根据id删除 List> partition = Lists.partition((List) ids, 100); partition.forEach(getInsuranceAccountDetailMapper()::batchDelAccountDetailsByIds); } private void recessionAccount(RecessionParam param, InsuranceAccountDetailPO insuranceAccountDetailPO, List recessionDetails) { List projects = param.getProjects(); InsuranceAccountDetailPO temp = new InsuranceAccountDetailPO(); recessionBaseBuild(param, temp, insuranceAccountDetailPO); if (projects.contains(ProjectTypeEnum.ALL.getValue())) { recessionSocial(param, temp, insuranceAccountDetailPO); recessionFund(param, temp, insuranceAccountDetailPO); recessionOther(param, temp, insuranceAccountDetailPO); } if (projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { recessionSocial(param, temp, insuranceAccountDetailPO); } if (projects.contains(ProjectTypeEnum.FUND.getValue())) { recessionFund(param, temp, insuranceAccountDetailPO); } if (projects.contains(ProjectTypeEnum.OTHER.getValue())) { recessionOther(param, temp, insuranceAccountDetailPO); } account(temp); recessionDetails.add(temp); } private void recessionBaseBuild(RecessionParam param, InsuranceAccountDetailPO temp, InsuranceAccountDetailPO insuranceAccountDetailPO) { temp.setPaymentStatus(PaymentStatusEnum.RECESSION.getValue()); // temp.setId(IdGenerator.generate()); temp.setCreateTime(new Date()); temp.setUpdateTime(new Date()); temp.setCreator(insuranceAccountDetailPO.getCreator()); temp.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); temp.setTenantKey(insuranceAccountDetailPO.getTenantKey()); temp.setEmployeeId(insuranceAccountDetailPO.getEmployeeId()); temp.setBillMonth(param.getBillMonth()); temp.setBillStatus(BillStatusEnum.NOT_ARCHIVED.getValue()); temp.setSupplementaryMonth(insuranceAccountDetailPO.getBillMonth()); temp.setSupplementaryProjects(String.join(",", param.getProjects() == null ? new ArrayList<>() : param.getProjects().stream().map(String::valueOf).collect(Collectors.toList()))); temp.setResourceFrom(insuranceAccountDetailPO.getResourceFrom()); temp.setSocialAccount(insuranceAccountDetailPO.getSocialAccount()); temp.setSocialSchemeId(insuranceAccountDetailPO.getSocialSchemeId()); temp.setSocialPaymentBaseString(insuranceAccountDetailPO.getSocialPaymentBaseString()); temp.setFundAccount(insuranceAccountDetailPO.getFundAccount()); temp.setSupplementFundAccount(insuranceAccountDetailPO.getSupplementFundAccount()); temp.setFundSchemeId(insuranceAccountDetailPO.getFundSchemeId()); temp.setFundPaymentBaseString(insuranceAccountDetailPO.getFundPaymentBaseString()); temp.setOtherSchemeId(insuranceAccountDetailPO.getOtherSchemeId()); temp.setOtherPaymentBaseString(insuranceAccountDetailPO.getOtherPaymentBaseString()); // temp.setExternalFlag(insuranceAccountDetailPO.getExternalFlag()); temp.setPaymentOrganization(insuranceAccountDetailPO.getPaymentOrganization()); // temp.setPaymentAgency(insuranceAccountDetailPO.getPaymentAgency()); } private void recessionSocial(RecessionParam param, InsuranceAccountDetailPO temp, InsuranceAccountDetailPO insuranceAccountDetailPO) { //退差社保个人缴费 String socialPerJson = insuranceAccountDetailPO.getSocialPerJson(); if (StringUtils.isNotBlank(socialPerJson)) { HashMap jsonMap = new HashMap<>(); HashMap hashMap = JSON.parseObject(socialPerJson, new HashMap().getClass()); hashMap.forEach((k, v) -> { if (StringUtils.isNotBlank(v)) { v = new BigDecimal(v).negate().toPlainString(); jsonMap.put(k, v); } }); temp.setSocialPerJson(JSON.toJSONString(jsonMap)); } if (StringUtils.isNotBlank(insuranceAccountDetailPO.getSocialPerSum())) { temp.setSocialPerSum(new BigDecimal(insuranceAccountDetailPO.getSocialPerSum()).negate().toPlainString()); } //退差社保单位缴费 String socialComJson = insuranceAccountDetailPO.getSocialComJson(); if (StringUtils.isNotBlank(socialComJson)) { HashMap jsonMap = new HashMap<>(); HashMap hashMap = JSON.parseObject(socialPerJson, new HashMap().getClass()); hashMap.forEach((k, v) -> { if (StringUtils.isNotBlank(v)) { v = new BigDecimal(v).negate().toPlainString(); jsonMap.put(k, v); } }); temp.setSocialComJson(JSON.toJSONString(jsonMap)); } if (StringUtils.isNotBlank(insuranceAccountDetailPO.getSocialComSum())) { temp.setSocialComSum(new BigDecimal(insuranceAccountDetailPO.getSocialComSum()).negate().toPlainString()); } } private void recessionFund(RecessionParam param, InsuranceAccountDetailPO temp, InsuranceAccountDetailPO insuranceAccountDetailPO) { //退差公积金个人缴费 String fundPerJson = insuranceAccountDetailPO.getFundPerJson(); if (StringUtils.isNotBlank(fundPerJson)) { HashMap jsonMap = new HashMap<>(); HashMap hashMap = JSON.parseObject(fundPerJson, new HashMap().getClass()); hashMap.forEach((k, v) -> { if (StringUtils.isNotBlank(v)) { v = new BigDecimal(v).negate().toPlainString(); jsonMap.put(k, v); } }); temp.setFundPerJson(JSON.toJSONString(jsonMap)); } if (StringUtils.isNotBlank(insuranceAccountDetailPO.getFundPerSum())) { temp.setFundPerSum(new BigDecimal(insuranceAccountDetailPO.getFundPerSum()).negate().toPlainString()); } //退差公积金单位缴费 String fundComJson = insuranceAccountDetailPO.getFundComJson(); if (StringUtils.isNotBlank(fundComJson)) { HashMap jsonMap = new HashMap<>(); HashMap hashMap = JSON.parseObject(fundPerJson, new HashMap().getClass()); hashMap.forEach((k, v) -> { if (StringUtils.isNotBlank(v)) { v = new BigDecimal(v).negate().toPlainString(); jsonMap.put(k, v); } }); temp.setFundComJson(JSON.toJSONString(jsonMap)); } if (StringUtils.isNotBlank(insuranceAccountDetailPO.getFundComSum())) { temp.setFundComSum(new BigDecimal(insuranceAccountDetailPO.getFundComSum()).negate().toPlainString()); } } private void recessionOther(RecessionParam param, InsuranceAccountDetailPO temp, InsuranceAccountDetailPO insuranceAccountDetailPO) { //退差其他福利个人缴费 String otherPerJson = insuranceAccountDetailPO.getOtherPerJson(); if (StringUtils.isNotBlank(otherPerJson)) { HashMap jsonMap = new HashMap<>(); HashMap hashMap = JSON.parseObject(otherPerJson, new HashMap().getClass()); hashMap.forEach((k, v) -> { if (StringUtils.isNotBlank(v)) { v = new BigDecimal(v).negate().toPlainString(); jsonMap.put(k, v); } }); temp.setOtherPerJson(JSON.toJSONString(jsonMap)); } if (StringUtils.isNotBlank(insuranceAccountDetailPO.getOtherPerSum())) { temp.setOtherPerSum(new BigDecimal(insuranceAccountDetailPO.getOtherPerSum()).negate().toPlainString()); } //退差其他福利单位缴费 String otherComJson = insuranceAccountDetailPO.getOtherComJson(); if (StringUtils.isNotBlank(otherComJson)) { HashMap jsonMap = new HashMap<>(); HashMap hashMap = JSON.parseObject(otherPerJson, new HashMap().getClass()); hashMap.forEach((k, v) -> { if (StringUtils.isNotBlank(v)) { v = new BigDecimal(v).negate().toPlainString(); jsonMap.put(k, v); } }); temp.setOtherComJson(JSON.toJSONString(jsonMap)); } if (StringUtils.isNotBlank(insuranceAccountDetailPO.getOtherComSum())) { temp.setOtherComSum(new BigDecimal(insuranceAccountDetailPO.getOtherComSum()).negate().toPlainString()); } } private void account(InsuranceAccountDetailPO insuranceAccountDetailPO) { //个人合计 BigDecimal socialPerson = StringUtils.isBlank(insuranceAccountDetailPO.getSocialPerSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getSocialPerSum()); BigDecimal fundPerson = StringUtils.isBlank(insuranceAccountDetailPO.getFundPerSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getFundPerSum()); BigDecimal otherPerson = StringUtils.isBlank(insuranceAccountDetailPO.getOtherPerSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getOtherPerSum()); BigDecimal perSum = socialPerson.add(fundPerson).add(otherPerson); insuranceAccountDetailPO.setPerSum(perSum.toPlainString()); //单位合计 BigDecimal socialCom = StringUtils.isBlank(insuranceAccountDetailPO.getSocialComSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getSocialComSum()); BigDecimal fundCom = StringUtils.isBlank(insuranceAccountDetailPO.getFundComSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getFundComSum()); BigDecimal otherCom = StringUtils.isBlank(insuranceAccountDetailPO.getOtherComSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getOtherComSum()); BigDecimal comSum = socialCom.add(fundCom).add(otherCom); insuranceAccountDetailPO.setComSum(comSum.toPlainString()); //社保合计 insuranceAccountDetailPO.setSocialSum(socialPerson.add(socialCom).toPlainString()); //公积金合计 insuranceAccountDetailPO.setFundSum(fundPerson.add(fundCom).toPlainString()); //其他福利合计 insuranceAccountDetailPO.setOtherSum(otherPerson.add(otherCom).toPlainString()); //合计 insuranceAccountDetailPO.setTotal(perSum.add(comSum).toPlainString()); } /** * 获取当前登录人所控制的个税扣缴义务人的人员范围 */ @Override public PageInfo getEmployeeListByTaxAgent(HrmQueryParam param) { // 当前登录人员 Long currentEmployeeId = (long) user.getUID(); List taxAgentEmployeeDTOS = getTaxAgentService(user).listTaxAgentAndEmployee(currentEmployeeId); Set employeeIds = SalaryEntityUtil.properties(taxAgentEmployeeDTOS, TaxAgentEmployeeDTO::getEmployeeId); List empIds = new ArrayList(employeeIds); List resultData = new ArrayList<>(); if (employeeIds.size() > 0) { List> partition = Lists.partition(empIds, 1000); partition.forEach(p -> { param.setIds(p); resultData.addAll(getEmployMapper().listHrmInfoByIdAndName(param)); }); } // 分页 PageInfo page = new PageInfo<>(); if (null == resultData) { return page; } page.setTotal(resultData.size()); page.setList(SalaryPageUtil.subList(param.getPageNum(), param.getPageSize(), resultData)); page.setPageSize(param.getPageSize()); page.setPageNum(param.getPageNum()); return page; } }