2022-04-08 19:08:59 +08:00
package com.engine.salary.service.impl ;
2025-02-17 15:54:35 +08:00
import cn.hutool.core.collection.CollUtil ;
2022-04-12 19:25:19 +08:00
import com.engine.common.util.ServiceUtil ;
2022-04-08 19:08:59 +08:00
import com.engine.core.impl.Service ;
2024-04-01 20:25:23 +08:00
import com.engine.hrmelog.entity.dto.LoggerContext ;
2022-04-29 17:15:22 +08:00
import com.engine.salary.cache.SalaryCacheKey ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.common.LocalDateRange ;
2024-01-24 09:50:58 +08:00
import com.engine.salary.config.SalaryElogConfig ;
2023-12-05 14:57:34 +08:00
import com.engine.salary.constant.SalaryDefaultTenantConstant ;
2022-12-12 16:42:44 +08:00
import com.engine.salary.encrypt.EncryptUtil ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee ;
2022-04-11 20:17:47 +08:00
import com.engine.salary.entity.datacollection.dto.AttendQuoteFieldListDTO ;
2024-08-09 10:21:40 +08:00
import com.engine.salary.entity.datacollection.po.VariableItemPO ;
2024-07-25 14:04:14 +08:00
import com.engine.salary.entity.hrm.DeptInfo ;
import com.engine.salary.entity.hrm.JobCallInfo ;
import com.engine.salary.entity.hrm.PositionInfo ;
import com.engine.salary.entity.hrm.SubCompanyInfo ;
2023-06-27 14:58:33 +08:00
import com.engine.salary.entity.progress.ProgressDTO ;
2022-07-11 17:31:33 +08:00
import com.engine.salary.entity.report.po.SalaryAcctResultReportPO ;
2023-05-15 10:28:17 +08:00
import com.engine.salary.entity.salaryacct.bo.* ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.entity.salaryacct.dto.ConsolidatedTaxDetailDTO ;
2025-08-06 18:09:19 +08:00
import com.engine.salary.entity.salaryacct.dto.LtSalaryReportConfigDTO ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.entity.salaryacct.dto.SalaryAcctResultDetailDTO ;
2022-08-02 14:58:18 +08:00
import com.engine.salary.entity.salaryacct.dto.SalaryAcctResultListColumnDTO ;
2022-11-17 09:28:40 +08:00
import com.engine.salary.entity.salaryacct.param.* ;
2023-05-15 10:28:17 +08:00
import com.engine.salary.entity.salaryacct.po.* ;
2025-08-06 18:09:19 +08:00
import com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO ;
import com.engine.salary.entity.salaryarchive.po.SalaryArchivePO ;
2022-04-28 15:02:11 +08:00
import com.engine.salary.entity.salaryformula.ExpressFormula ;
2023-09-07 15:15:59 +08:00
import com.engine.salary.entity.salaryformula.po.FormulaVar ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.entity.salaryitem.po.SalaryItemPO ;
2022-08-02 14:58:18 +08:00
import com.engine.salary.entity.salarysob.dto.* ;
2022-08-24 10:31:42 +08:00
import com.engine.salary.entity.salarysob.po.* ;
2022-05-31 16:41:11 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentPO ;
2024-01-24 09:50:58 +08:00
import com.engine.salary.enums.OperateTypeEnum ;
2023-10-08 13:38:37 +08:00
import com.engine.salary.enums.UserStatusEnum ;
2024-01-24 09:50:58 +08:00
import com.engine.salary.enums.common.FilterEnum ;
2024-06-20 10:39:40 +08:00
import com.engine.salary.enums.common.SalaryLogGroupTypeEnum ;
import com.engine.salary.enums.common.SalaryLogOperateTypeEnum ;
2022-11-17 09:28:40 +08:00
import com.engine.salary.enums.salaryaccounting.LockStatusEnum ;
2022-04-11 20:17:47 +08:00
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum ;
2023-05-15 10:28:17 +08:00
import com.engine.salary.enums.salaryaccounting.SalaryAcctResultDataSourceEnum ;
2023-09-07 15:15:59 +08:00
import com.engine.salary.enums.salaryformula.SalaryFormulaReferenceEnum ;
2022-09-27 15:47:13 +08:00
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.enums.salarysob.IncomeCategoryEnum ;
import com.engine.salary.exception.SalaryRunTimeException ;
import com.engine.salary.mapper.salaryacct.SalaryAcctResultMapper ;
2023-06-15 18:48:31 +08:00
import com.engine.salary.report.service.SalaryStatisticsReportService ;
import com.engine.salary.report.service.impl.SalaryStatisticsReportServiceImpl ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.service.* ;
2023-06-02 15:25:46 +08:00
import com.engine.salary.sys.constant.SalarySysConstant ;
import com.engine.salary.sys.entity.po.SalarySysConfPO ;
2023-07-04 09:32:12 +08:00
import com.engine.salary.sys.enums.TaxDeclarationFunctionEnum ;
2023-06-02 15:25:46 +08:00
import com.engine.salary.sys.service.SalarySysConfService ;
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl ;
2025-08-06 18:09:19 +08:00
import com.engine.salary.util.JsonUtil ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.util.SalaryDateUtil ;
import com.engine.salary.util.SalaryEntityUtil ;
import com.engine.salary.util.SalaryI18nUtil ;
2022-04-12 19:25:19 +08:00
import com.engine.salary.util.db.MapperProxyFactory ;
2022-04-08 19:08:59 +08:00
import com.engine.salary.util.page.PageInfo ;
2023-10-08 15:44:09 +08:00
import com.engine.salary.util.page.SalaryPageUtil ;
2023-12-05 14:57:34 +08:00
import com.engine.salary.util.valid.ValidUtil ;
2022-04-11 20:17:47 +08:00
import com.google.common.collect.Lists ;
2022-08-02 14:58:18 +08:00
import com.google.common.collect.Maps ;
2022-04-11 20:17:47 +08:00
import com.weaver.util.threadPool.ThreadPoolUtil ;
import com.weaver.util.threadPool.constant.ModulePoolEnum ;
import com.weaver.util.threadPool.entity.LocalRunnable ;
2022-04-08 19:08:59 +08:00
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections4.CollectionUtils ;
2022-04-11 20:17:47 +08:00
import org.apache.commons.collections4.MapUtils ;
2022-04-08 19:08:59 +08:00
import org.apache.commons.lang3.StringUtils ;
2022-08-02 14:58:18 +08:00
import org.apache.commons.lang3.math.NumberUtils ;
2023-09-07 15:15:59 +08:00
import org.jetbrains.annotations.NotNull ;
import org.springframework.beans.BeanUtils ;
2022-04-08 19:08:59 +08:00
import org.springframework.jdbc.datasource.DataSourceTransactionManager ;
2023-09-26 14:29:12 +08:00
import org.springframework.util.StopWatch ;
2025-08-06 18:09:19 +08:00
import weaver.conn.RecordSet ;
import weaver.conn.RecordSetDataSource ;
import weaver.formmode.setup.ModeRightInfo ;
2024-09-02 18:11:00 +08:00
import weaver.general.BaseBean ;
2025-08-06 18:09:19 +08:00
import weaver.general.TimeUtil ;
2022-04-12 19:25:19 +08:00
import weaver.hrm.User ;
2025-08-06 18:09:19 +08:00
import weaver.wechat.util.Utils ;
2022-04-08 19:08:59 +08:00
2022-04-11 20:17:47 +08:00
import java.math.BigDecimal ;
2025-08-06 18:09:19 +08:00
import java.math.RoundingMode ;
import java.text.SimpleDateFormat ;
import java.time.YearMonth ;
2022-04-08 19:08:59 +08:00
import java.util.* ;
2022-04-11 20:17:47 +08:00
import java.util.concurrent.BlockingDeque ;
import java.util.concurrent.CountDownLatch ;
import java.util.concurrent.LinkedBlockingDeque ;
2023-09-07 15:15:59 +08:00
import java.util.regex.Matcher ;
2022-04-08 19:08:59 +08:00
import java.util.stream.Collectors ;
2023-09-07 15:15:59 +08:00
import static com.engine.salary.constant.SalaryFormulaFieldConstant.SALARY_PATTERN ;
2025-08-06 18:09:19 +08:00
import static com.engine.salary.sys.constant.SalarySysConstant.SALARY_ACCT_SYNC_TYPE ;
2023-09-07 15:15:59 +08:00
2022-04-08 19:08:59 +08:00
/ * *
* 薪资核算结果
* < p > Copyright : Copyright ( c ) 2022 < / p >
* < p > Company : 泛微软件 < / p >
*
* @author qiantao
* @version 1 . 0
* * /
@Slf4j
public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctResultService {
2022-12-12 16:42:44 +08:00
private EncryptUtil encryptUtil = new EncryptUtil ( ) ;
2022-04-08 19:08:59 +08:00
2022-04-29 17:15:22 +08:00
private SalaryAcctResultMapper getSalaryAcctResultMapper ( ) {
2022-04-12 19:25:19 +08:00
return MapperProxyFactory . getProxy ( SalaryAcctResultMapper . class ) ;
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalaryAcctEmployeeService getSalaryAcctEmployeeService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryAcctEmployeeServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalarySobItemService getSalarySobItemService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalarySobItemServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalaryItemService getSalaryItemService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryItemServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalarySobEmpFieldService getSalarySobEmpFieldService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalarySobEmpFieldServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalarySobService getSalarySobService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalarySobServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalaryAcctRecordService getSalaryAcctRecordService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryAcctRecordServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-05-31 21:05:59 +08:00
private TaxAgentService getTaxAgentService ( User user ) {
return ServiceUtil . getService ( TaxAgentServiceImpl . class , user ) ;
2022-05-31 16:41:11 +08:00
}
2022-04-08 19:08:59 +08:00
2022-04-12 19:25:19 +08:00
private SalaryEmployeeService getSalaryEmployeeService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryEmployeeServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalaryFormulaService getSalaryFormulaService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryFormulaServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-04-12 19:25:19 +08:00
private SalarySobAdjustRuleService getSalarySobAdjustRuleService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalarySobAdjustRuleServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-08-24 10:31:42 +08:00
private SalarySobItemHideService getSalarySobItemHideService ( User user ) {
return ( SalarySobItemHideService ) ServiceUtil . getService ( SalarySobItemHideServiceImpl . class , user ) ;
}
2022-04-12 19:25:19 +08:00
private SalaryAcctCalculateService getSalaryAcctCalculateService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryAcctCalculateServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2023-06-06 10:30:49 +08:00
private ProgressService getSalaryAcctProgressService ( User user ) {
return ServiceUtil . getService ( ProgressServiceImpl . class , user ) ;
2022-04-29 17:15:22 +08:00
}
2022-04-08 19:08:59 +08:00
private DataSourceTransactionManager dataSourceTransactionManager ;
2022-04-12 19:25:19 +08:00
private SalaryAcctResultTempService getSalaryAcctResultTempService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SalaryAcctResultTempServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-08 19:08:59 +08:00
2022-04-28 15:02:11 +08:00
private SIAccountService getSIAccountService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( SIAccountServiceImpl . class , user ) ;
2022-04-28 15:02:11 +08:00
}
2022-04-08 19:08:59 +08:00
2022-04-12 19:25:19 +08:00
private AttendQuoteFieldService getAttendQuoteFieldService ( User user ) {
2022-07-11 17:31:33 +08:00
return ServiceUtil . getService ( AttendQuoteFieldServiceImpl . class , user ) ;
}
private SalaryAcctReportService getSalaryAcctReportService ( User user ) {
return ServiceUtil . getService ( SalaryAcctReportServiceImpl . class , user ) ;
2022-04-12 19:25:19 +08:00
}
2022-04-29 17:15:22 +08:00
2022-08-24 10:31:42 +08:00
private SalarySobItemGroupService getSalarySobItemGroupService ( User user ) {
return ( SalarySobItemGroupService ) ServiceUtil . getService ( SalarySobItemGroupServiceImpl . class , user ) ;
}
2022-12-02 17:35:14 +08:00
private SalarySobBackItemService getSalarySobBackItemService ( User user ) {
return ServiceUtil . getService ( SalarySobBackItemServiceImpl . class , user ) ;
}
2023-05-11 14:40:10 +08:00
private SalaryAcctResultService getSalaryAcctResultService ( User user ) {
return ( SalaryAcctResultService ) ServiceUtil . getService ( SalaryAcctResultServiceImpl . class , user ) ;
}
2023-05-15 10:28:17 +08:00
private SalaryAcctResultLogService getSalaryAcctResultLogService ( User user ) {
return ServiceUtil . getService ( SalaryAcctResultLogServiceImpl . class , user ) ;
}
2023-06-02 15:25:46 +08:00
private SalarySysConfService getSalarySysConfService ( User user ) {
return ServiceUtil . getService ( SalarySysConfServiceImpl . class , user ) ;
}
2023-06-15 18:48:31 +08:00
private SalaryStatisticsReportService getSalaryStatisticsReportService ( User user ) {
return ServiceUtil . getService ( SalaryStatisticsReportServiceImpl . class , user ) ;
}
2023-06-27 14:58:33 +08:00
private TaxAgentAdminService getTaxAgentAdminService ( User user ) {
return ServiceUtil . getService ( TaxAgentAdminServiceImpl . class , user ) ;
}
2024-08-09 10:21:40 +08:00
private VariableItemService getVariableItemService ( User user ) {
return ServiceUtil . getService ( VariableItemServiceImpl . class , user ) ;
}
2025-02-17 15:54:35 +08:00
2024-04-29 16:08:18 +08:00
private SalaryApprovalRuleService getSalaryApprovalRuleService ( User user ) {
return ServiceUtil . getService ( SalaryApprovalRuleServiceImpl . class , user ) ;
}
2024-08-09 10:21:40 +08:00
2022-04-12 19:25:19 +08:00
private SalaryCheckResultService salaryCheckResultService ;
2022-04-08 19:08:59 +08:00
2024-05-06 16:03:29 +08:00
private SalaryAcctSobConfigService getSalaryAcctSobConfigService ( User user ) {
return ServiceUtil . getService ( SalaryAcctSobConfigServiceImpl . class , user ) ;
}
2024-05-06 17:41:39 +08:00
2024-07-02 15:39:31 +08:00
private SalarySobTaxRuleService getSalarySobTaxRuleService ( User user ) {
return ServiceUtil . getService ( SalarySobTaxRuleServiceImpl . class , user ) ;
}
2025-08-06 18:09:19 +08:00
private VariableArchiveService getVariableArchiveService ( User user ) {
return ServiceUtil . getService ( VariableArchiveServiceImpl . class , user ) ;
}
private VariableArchiveItemService getVariableArchiveItemService ( User user ) {
return ServiceUtil . getService ( VariableArchiveItemServiceImpl . class , user ) ;
}
private SalaryArchiveService getSalaryArchiveService ( User user ) {
return ServiceUtil . getService ( SalaryArchiveServiceImpl . class , user ) ;
}
private SalaryArchiveItemService getSalaryArchiveItemService ( User user ) {
return ServiceUtil . getService ( SalaryArchiveItemServiceImpl . class , user ) ;
}
2022-04-08 19:08:59 +08:00
@Override
public List < SalaryAcctResultPO > listBySalaryAcctRecordIds ( Collection < Long > salaryAcctRecordIds ) {
if ( CollectionUtils . isEmpty ( salaryAcctRecordIds ) ) {
return Collections . emptyList ( ) ;
}
2022-07-11 17:31:33 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctRecordIds ( salaryAcctRecordIds ) . build ( ) ) ;
2022-12-12 16:42:44 +08:00
encryptUtil . decryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
2022-05-24 09:23:17 +08:00
return salaryAcctResultPOS ;
2022-04-08 19:08:59 +08:00
}
@Override
public List < SalaryAcctResultPO > listBySalaryAcctEmployeeId ( Long salaryAcctEmployeeId ) {
2022-05-24 09:23:17 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctEmpId ( salaryAcctEmployeeId ) . build ( ) ) ;
2022-12-12 16:42:44 +08:00
encryptUtil . decryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
2022-05-24 09:23:17 +08:00
// 解密
return salaryAcctResultPOS ;
2022-04-08 19:08:59 +08:00
}
@Override
public List < SalaryAcctResultPO > listBySalaryAcctEmployeeIds ( Collection < Long > salaryAcctEmployeeIds ) {
if ( CollectionUtils . isEmpty ( salaryAcctEmployeeIds ) ) {
return Collections . emptyList ( ) ;
}
2023-05-05 17:15:25 +08:00
List < List < Long > > partition = Lists . partition ( ( List < Long > ) salaryAcctEmployeeIds , 500 ) ;
2023-05-04 11:56:34 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = new ArrayList < > ( ) ;
partition . forEach ( empIds - > {
2024-06-12 17:35:06 +08:00
List < SalaryAcctResultPO > resultPOS = getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctEmpIds ( empIds ) . build ( ) ) ;
encryptUtil . decryptList ( resultPOS , SalaryAcctResultPO . class ) ;
salaryAcctResultPOS . addAll ( resultPOS ) ;
2023-05-04 11:56:34 +08:00
} ) ;
2022-05-24 09:23:17 +08:00
// 解密
return salaryAcctResultPOS ;
2022-04-08 19:08:59 +08:00
}
@Override
public List < SalaryAcctResultPO > listBySalaryAcctRecordIdsAndEmployeeIds ( Collection < Long > salaryAcctRecordIds , Collection < Long > employeeIds ) {
if ( CollectionUtils . isEmpty ( salaryAcctRecordIds ) | | CollectionUtils . isEmpty ( employeeIds ) ) {
return Collections . emptyList ( ) ;
}
2023-05-05 17:15:25 +08:00
List < List < Long > > partition = Lists . partition ( ( List < Long > ) employeeIds , 500 ) ;
2023-05-04 11:56:34 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = new ArrayList < > ( ) ;
partition . forEach ( empIds - > {
salaryAcctResultPOS . addAll ( getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctRecordIds ( salaryAcctRecordIds ) . employeeIds ( empIds ) . build ( ) ) ) ;
} ) ;
2022-12-12 16:42:44 +08:00
encryptUtil . decryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
2022-05-24 09:23:17 +08:00
return salaryAcctResultPOS ;
2022-04-08 19:08:59 +08:00
}
@Override
public SalaryAcctResultDetailDTO getBySalaryAcctEmployeeId ( Long salaryAcctEmployeeId ) {
// 查询薪资核算人员
2022-04-12 19:25:19 +08:00
SalaryAcctEmployeePO salaryAcctEmployeePO = getSalaryAcctEmployeeService ( user ) . getById ( salaryAcctEmployeeId ) ;
2022-04-08 19:08:59 +08:00
if ( Objects . isNull ( salaryAcctEmployeePO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98831 , " 薪资核算人员不存在或已被删除 " ) ) ;
}
2022-12-02 17:35:14 +08:00
// 查询是否是回算
2024-05-06 17:41:39 +08:00
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) ;
boolean isBackCal = Objects . equals ( salaryAcctRecordPO . getBackCalcStatus ( ) , 1 ) ;
2022-08-24 10:31:42 +08:00
2024-05-07 18:48:38 +08:00
SalaryAcctConfig salaryAcctConfig = getSalaryAcctSobConfigService ( user ) . getSalaryAcctConfig ( salaryAcctRecordPO . getId ( ) ) ;
2022-08-24 10:31:42 +08:00
// 查询薪资账套的薪资项目分类
2024-05-07 18:48:38 +08:00
List < SalarySobItemGroupPO > salarySobItemGroupPOS = salaryAcctConfig . getSalarySobItemGroups ( ) ;
2022-08-24 10:31:42 +08:00
// 过滤关闭显示的薪资项目分类
2024-05-06 17:41:39 +08:00
salarySobItemGroupPOS = salarySobItemGroupPOS . stream ( ) . filter ( group - > group . getItemHide ( ) = = null | | group . getItemHide ( ) . equals ( 0L ) ) . collect ( Collectors . toList ( ) ) ;
2022-08-24 10:31:42 +08:00
// 获取薪资项目分类ID
List < Long > salarySobItemGroupIds = salarySobItemGroupPOS . stream ( ) . map ( SalarySobItemGroupPO : : getId ) . collect ( Collectors . toList ( ) ) ;
2023-03-02 11:25:25 +08:00
//加上未分类
salarySobItemGroupIds . add ( 0L ) ;
2022-08-24 10:31:42 +08:00
// 查询薪资账套的薪资项目副本(已经过滤关闭分类显示按钮的薪资项目)
2024-05-07 18:48:38 +08:00
List < SalarySobItemPO > salarySobItemPOS = salaryAcctConfig . getSalarySobItems ( ) ;
2022-08-24 10:31:42 +08:00
// 过滤薪资项目
2024-05-06 17:41:39 +08:00
salarySobItemPOS = salarySobItemPOS . stream ( ) . filter ( item - > item . getItemHide ( ) = = null | | item . getItemHide ( ) . equals ( 0L ) ) . collect ( Collectors . toList ( ) ) ;
2022-08-24 10:31:42 +08:00
2022-12-02 17:35:14 +08:00
// 查询已发补发薪资项目
List < SalarySobBackItemPO > salarySobBackItemPOList = Collections . emptyList ( ) ;
List < SalaryItemPO > salaryBackItemPOS = Collections . emptyList ( ) ;
// key:账套中回算薪资项目的薪资项目id value:账套中回算薪资项目所对应的公式内容
Map < Long , String > salaryBackItemFormula = new HashMap < > ( ) ;
2023-05-04 11:56:34 +08:00
if ( isBackCal ) {
2024-05-07 18:48:38 +08:00
salarySobBackItemPOList = salaryAcctConfig . getSalarySobBackItems ( ) ;
2022-12-02 17:35:14 +08:00
Set < Long > salarySobBackItemIds = SalaryEntityUtil . properties ( salarySobBackItemPOList , SalarySobBackItemPO : : getSalaryItemId ) ;
salaryBackItemPOS = getSalaryItemService ( user ) . listByIds ( salarySobBackItemIds ) ;
// 查询薪资账套中已发补发的公式内容
List < ExpressFormula > expressFormulas = getSalaryFormulaService ( user ) . listExpressFormula ( SalaryEntityUtil . properties ( salarySobBackItemPOList , SalarySobBackItemPO : : getFormulaId ) ) ;
Map < Long , String > expressFormulaMap = SalaryEntityUtil . convert2Map ( expressFormulas , ExpressFormula : : getId , ExpressFormula : : getFormula ) ;
2023-05-04 11:56:34 +08:00
for ( SalarySobBackItemPO salarySobBackItemPO : salarySobBackItemPOList ) {
2022-12-02 17:35:14 +08:00
String exp = Objects . equals ( expressFormulaMap . get ( salarySobBackItemPO . getFormulaId ( ) ) , 0 ) ? " 输入 " : expressFormulaMap . get ( salarySobBackItemPO . getFormulaId ( ) ) ;
2023-05-04 11:56:34 +08:00
salaryBackItemFormula . put ( salarySobBackItemPO . getSalaryItemId ( ) , exp ) ;
2022-12-02 17:35:14 +08:00
}
}
2022-08-24 10:31:42 +08:00
2022-04-08 19:08:59 +08:00
// 查询薪资项目
Set < Long > salaryItemIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getSalaryItemId ) ;
2022-04-12 19:25:19 +08:00
List < SalaryItemPO > salaryItemPOS = getSalaryItemService ( user ) . listByIds ( salaryItemIds ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算所用薪资账套的人员信息字段
2024-05-07 18:48:38 +08:00
List < SalarySobEmpFieldPO > salarySobEmpFieldPOS = salaryAcctConfig . getSalarySobEmpFields ( ) ;
2022-04-08 19:08:59 +08:00
// 查询人员信息
2022-04-12 19:25:19 +08:00
DataCollectionEmployee simpleEmployee = getSalaryEmployeeService ( user ) . getEmployeeById ( salaryAcctEmployeePO . getEmployeeId ( ) ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算结果
List < SalaryAcctResultPO > salaryAcctResultPOS = listBySalaryAcctEmployeeId ( salaryAcctEmployeeId ) ;
// 查询个税扣缴义务人
2022-05-31 16:41:11 +08:00
TaxAgentPO taxAgent = getTaxAgentService ( user ) . getById ( salaryAcctEmployeePO . getTaxAgentId ( ) ) ;
2023-05-16 15:41:11 +08:00
// 查询公式
Map < String , SalaryAcctResultListColumnDTO > formulaContentMap = getSalaryAcctResultService ( user ) . getColumnBySalaryAcctRecordId ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) ;
2024-05-06 17:41:39 +08:00
List < Long > lockItems = salaryAcctRecordPO . getLockSalaryItemIds ( ) = = null ? Collections . emptyList ( ) : salaryAcctRecordPO . getLockSalaryItemIds ( ) ;
2022-08-24 10:31:42 +08:00
2022-04-08 19:08:59 +08:00
// 转换成薪资核算结果详情dto
2023-12-06 16:05:08 +08:00
return SalaryAcctResultBO . convert2DetailDTO ( simpleEmployee , taxAgent , salaryAcctEmployeePO , salarySobEmpFieldPOS , salarySobItemGroupPOS , salarySobItemPOS , salaryItemPOS , salaryAcctResultPOS , salarySobBackItemPOList , salaryBackItemPOS , salaryBackItemFormula , formulaContentMap , lockItems ) ;
2022-04-08 19:08:59 +08:00
}
@Override
public PageInfo < Map < String , Object > > listPageByParam ( SalaryAcctResultQueryParam queryParam ) {
2023-10-08 15:44:09 +08:00
PageInfo < SalaryAcctEmployeePO > page = null ;
//其他条件
List < SalaryAcctResultQueryParam . OtherCondition > otherConditions = queryParam . getOtherConditions ( ) ;
if ( CollectionUtils . isNotEmpty ( otherConditions ) ) {
List < Long > items = SalaryEntityUtil . properties ( otherConditions , SalaryAcctResultQueryParam . OtherCondition : : getItemId , Collectors . toList ( ) ) ;
List < SalaryAcctResultPO > list = listBySalaryAcctRecordIdsAndSalaryItemIds ( Collections . singletonList ( queryParam . getSalaryAcctRecordId ( ) ) , items ) ;
for ( int i = 0 ; i < otherConditions . size ( ) ; i + + ) {
SalaryAcctResultQueryParam . OtherCondition otherCondition = otherConditions . get ( i ) ;
Long itemId = otherCondition . getItemId ( ) ;
FilterEnum filter = otherCondition . getFilter ( ) ;
List < String > params = otherCondition . getParams ( ) ;
list = list . stream ( ) . filter ( a - > Objects . equals ( a . getSalaryItemId ( ) , itemId ) ) . filter ( a - > filter . filter ( params ) . test ( a . getResultValue ( ) ) ) . collect ( Collectors . toList ( ) ) ;
}
List < Long > salaryAcctEmpId = SalaryEntityUtil . properties ( list , SalaryAcctResultPO : : getSalaryAcctEmpId , Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( salaryAcctEmpId ) ) {
//条件不满足直接返回空列表
page = SalaryPageUtil . buildPage ( queryParam . getCurrent ( ) , queryParam . getPageSize ( ) , new ArrayList < > ( ) , SalaryAcctEmployeePO . class ) ;
} else {
queryParam . setIds ( salaryAcctEmpId ) ;
// 查询薪资核算人员(分页)
page = getSalaryAcctEmployeeService ( user ) . listPageByResultQueryParam ( queryParam ) ;
}
} else {
// 查询薪资核算人员(分页)
page = getSalaryAcctEmployeeService ( user ) . listPageByResultQueryParam ( queryParam ) ;
}
2022-04-08 19:08:59 +08:00
// 查询薪资核算结果
List < Map < String , Object > > data = listBySalaryAcctEmployees ( page . getList ( ) , queryParam ) ;
// 薪资核算结果的分页结果
PageInfo < Map < String , Object > > resultPage = new PageInfo < > ( ) ;
resultPage . setList ( data ) ;
2022-04-19 19:32:09 +08:00
resultPage . setTotal ( page . getTotal ( ) ) ;
resultPage . setPageNum ( page . getPageNum ( ) ) ;
resultPage . setPageSize ( page . getPageSize ( ) ) ;
2022-04-08 19:08:59 +08:00
return resultPage ;
}
2022-09-27 15:47:13 +08:00
@Override
public Map < String , Object > sumRow ( SalaryAcctResultQueryParam queryParam ) {
2023-10-30 19:19:07 +08:00
//其他条件
List < SalaryAcctResultQueryParam . OtherCondition > otherConditions = queryParam . getOtherConditions ( ) ;
2024-01-30 10:26:44 +08:00
if ( CollectionUtils . isNotEmpty ( otherConditions ) ) {
2023-10-30 19:19:07 +08:00
List < Long > items = SalaryEntityUtil . properties ( otherConditions , SalaryAcctResultQueryParam . OtherCondition : : getItemId , Collectors . toList ( ) ) ;
List < SalaryAcctResultPO > list = listBySalaryAcctRecordIdsAndSalaryItemIds ( Collections . singletonList ( queryParam . getSalaryAcctRecordId ( ) ) , items ) ;
for ( int i = 0 ; i < otherConditions . size ( ) ; i + + ) {
SalaryAcctResultQueryParam . OtherCondition otherCondition = otherConditions . get ( i ) ;
Long itemId = otherCondition . getItemId ( ) ;
FilterEnum filter = otherCondition . getFilter ( ) ;
List < String > params = otherCondition . getParams ( ) ;
list = list . stream ( ) . filter ( a - > Objects . equals ( a . getSalaryItemId ( ) , itemId ) ) . filter ( a - > filter . filter ( params ) . test ( a . getResultValue ( ) ) ) . collect ( Collectors . toList ( ) ) ;
}
List < Long > salaryAcctEmpId = SalaryEntityUtil . properties ( list , SalaryAcctResultPO : : getSalaryAcctEmpId , Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( salaryAcctEmpId ) ) {
//条件不满足直接返回空列表
return new HashMap < > ( ) ;
} else {
queryParam . setIds ( salaryAcctEmpId ) ;
}
}
2022-09-27 15:47:13 +08:00
// 查询薪资核算人员
List < SalaryAcctEmployeePO > salaryAcctEmployeePOS = getSalaryAcctEmployeeService ( user ) . listByResultQueryParam ( queryParam ) ;
if ( CollectionUtils . isEmpty ( salaryAcctEmployeePOS ) ) {
return null ;
}
// 查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( queryParam . getSalaryAcctRecordId ( ) ) ;
if ( Objects . isNull ( salaryAcctRecordPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资核算记录不存在或已被删除 " ) ) ;
}
// 查询薪资核算所用薪资账套的薪资项目
List < SalarySobItemPO > salarySobItemPOS = getSalarySobItemService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
2023-07-25 16:46:57 +08:00
Map < Long , SalarySobItemPO > salaryItemIdKeySalarySobItemPOMap = SalaryEntityUtil . convert2Map ( salarySobItemPOS , SalarySobItemPO : : getSalaryItemId ) ;
2022-09-27 15:47:13 +08:00
Set < Long > salaryItemIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getSalaryItemId ) ;
2023-09-07 15:15:59 +08:00
if ( Objects . equals ( salaryAcctRecordPO . getBackCalcStatus ( ) , NumberUtils . INTEGER_ONE ) ) {
2023-04-28 16:04:52 +08:00
// 是回算,获取回算项
List < SalarySobBackItemPO > salarySobBackItemPOS = getSalarySobBackItemService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
salaryItemIds . addAll ( salarySobBackItemPOS . stream ( ) . map ( SalarySobBackItemPO : : getSalaryItemId ) . collect ( Collectors . toList ( ) ) ) ;
}
2022-09-27 15:47:13 +08:00
List < SalaryItemPO > salaryItemPOS = getSalaryItemService ( user ) . listByIds ( salaryItemIds ) ;
2023-07-25 16:46:57 +08:00
2022-09-27 15:47:13 +08:00
// 查询薪资核算结果
2023-09-07 15:15:59 +08:00
List < Long > salaryAcctEmployeeIds = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getId , Collectors . toList ( ) ) ;
2022-09-27 15:47:13 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = listBySalaryAcctEmployeeIds ( salaryAcctEmployeeIds ) ;
Map < String , Object > map = new HashMap < > ( ) ;
Map < Long , List < SalaryAcctResultPO > > acctResultMap = SalaryEntityUtil . group2Map ( salaryAcctResultPOS , SalaryAcctResultPO : : getSalaryItemId ) ;
salaryItemPOS . stream ( ) . filter ( item - > SalaryDataTypeEnum . NUMBER . getValue ( ) . equals ( item . getDataType ( ) ) ) . forEach ( item - > {
2023-09-26 17:18:27 +08:00
BigDecimal sum = Optional . ofNullable ( acctResultMap . get ( item . getId ( ) ) ) . orElse ( new ArrayList < > ( ) ) . stream ( ) . map ( SalaryAcctResultPO : : getResultValue ) . filter ( NumberUtils : : isCreatable ) . map ( BigDecimal : : new ) . reduce ( BigDecimal . ZERO , BigDecimal : : add ) ;
2023-07-25 16:46:57 +08:00
map . put ( item . getId ( ) . toString ( ) , SalaryAcctFormulaBO . roundResultValue ( sum . toString ( ) , item , Collections . emptyList ( ) , Collections . emptyMap ( ) , salaryItemIdKeySalarySobItemPOMap ) ) ;
2022-09-27 15:47:13 +08:00
} ) ;
return map ;
}
2022-04-08 19:08:59 +08:00
@Override
public List < Map < String , Object > > listByParam ( SalaryAcctResultQueryParam queryParam ) {
// 查询薪资核算人员
2022-04-12 19:25:19 +08:00
List < SalaryAcctEmployeePO > salaryAcctEmployeePOS = getSalaryAcctEmployeeService ( user ) . listByResultQueryParam ( queryParam ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算结果
return listBySalaryAcctEmployees ( salaryAcctEmployeePOS , queryParam ) ;
}
/ * *
* 根据薪资核算人员查询薪资核算结果
*
* @param salaryAcctEmployeePOS 薪资核算人员
* @param queryParam 列表查询条件
* @return
* /
2022-07-11 17:31:33 +08:00
private List < Map < String , Object > > listBySalaryAcctEmployees ( List < SalaryAcctEmployeePO > salaryAcctEmployeePOS , SalaryAcctResultQueryParam queryParam ) {
2022-04-08 19:08:59 +08:00
if ( CollectionUtils . isEmpty ( salaryAcctEmployeePOS ) ) {
return Collections . emptyList ( ) ;
}
// 查询薪资核算记录
2022-04-12 19:25:19 +08:00
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( queryParam . getSalaryAcctRecordId ( ) ) ;
2022-04-08 19:08:59 +08:00
if ( Objects . isNull ( salaryAcctRecordPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资核算记录不存在或已被删除 " ) ) ;
}
2022-12-02 17:35:14 +08:00
boolean isBackCalc = Objects . equals ( salaryAcctRecordPO . getBackCalcStatus ( ) , 1 ) ;
2024-05-06 16:03:29 +08:00
SalaryAcctConfig salaryAcctConfig = getSalaryAcctSobConfigService ( user ) . getSalaryAcctConfig ( queryParam . getSalaryAcctRecordId ( ) ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算所用的薪资账套的员工信息字段
2024-05-06 16:03:29 +08:00
List < SalarySobEmpFieldPO > salarySobEmpFieldPOS = salaryAcctConfig . getSalarySobEmpFields ( ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算所用薪资账套的薪资项目
2024-05-06 16:03:29 +08:00
List < SalarySobItemPO > salarySobItemPOS = salaryAcctConfig . getSalarySobItems ( ) ;
2022-04-08 19:08:59 +08:00
Set < Long > salaryItemIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getSalaryItemId ) ;
2022-12-02 17:35:14 +08:00
// 是否是回算
List < SalarySobBackItemPO > salarySobBackItemPOList = Collections . emptyList ( ) ;
if ( isBackCalc ) {
// 根据薪资账套获取回算信息项
salarySobBackItemPOList = getSalarySobBackItemService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
salaryItemIds . addAll ( salarySobBackItemPOList . stream ( ) . map ( SalarySobBackItemPO : : getSalaryItemId ) . collect ( Collectors . toList ( ) ) ) ;
}
2022-04-12 19:25:19 +08:00
List < SalaryItemPO > salaryItemPOS = getSalaryItemService ( user ) . listByIds ( salaryItemIds ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算结果
2023-09-07 15:15:59 +08:00
List < Long > salaryAcctEmployeeIds = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getId , Collectors . toList ( ) ) ;
2022-04-08 19:08:59 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = listBySalaryAcctEmployeeIds ( salaryAcctEmployeeIds ) ;
// 查询人员信息
List < Long > employeeIds = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getEmployeeId , Collectors . toList ( ) ) ;
2023-04-12 15:27:35 +08:00
List < DataCollectionEmployee > simpleEmployees = getSalaryEmployeeService ( user ) . getEmployeeByIdsAll ( employeeIds ) ;
2023-10-08 15:44:09 +08:00
simpleEmployees . forEach ( e - > {
2023-10-08 13:38:37 +08:00
UserStatusEnum userStatusEnum = UserStatusEnum . parseByValue ( Integer . parseInt ( e . getStatus ( ) ) ) ;
2023-10-08 15:44:09 +08:00
if ( userStatusEnum ! = null ) {
2023-10-08 13:38:37 +08:00
e . setStatusName ( userStatusEnum . getDefaultLabel ( ) ) ;
}
} ) ;
2022-04-08 19:08:59 +08:00
// 查询个税扣缴义务人
Set < Long > taxAgentIds = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getTaxAgentId ) ;
2022-05-31 16:41:11 +08:00
List < TaxAgentPO > taxAgentPOS = getTaxAgentService ( user ) . listByIds ( taxAgentIds ) ;
2022-04-08 19:08:59 +08:00
// 判断是否存在合并计税
Set < Long > salaryAcctEmployeeIds4ConsolidatedTax ;
if ( StringUtils . isNotEmpty ( queryParam . getConsolidatedTaxation ( ) ) ) {
// 如果查询条件中含有"合并计税", 那么在入参中的salaryAcctEmployeePOS就已经全部都是存在合并计税的人员了( 前面已经过滤了) , 无需再次查询合并计税的人员
salaryAcctEmployeeIds4ConsolidatedTax = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getId ) ;
} else {
// 如果查询条件中没有包含"合并计税",那么就需要查询出存在合并计税的人,标记给前端
2024-01-30 10:26:44 +08:00
SalaryAcctEmployeeQueryParam accEmployeeQueryParam = SalaryAcctEmployeeQueryParam . builder ( ) . salaryAcctRecordId ( queryParam . getSalaryAcctRecordId ( ) ) . ids ( SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getId , Collectors . toList ( ) ) ) . build ( ) ;
2022-04-12 19:25:19 +08:00
List < SalaryAcctEmployeePO > salaryAcctEmployeePOS4ConsolidatedTax = getSalaryAcctEmployeeService ( user ) . listByParam4ConsolidatedTax ( accEmployeeQueryParam ) ;
2022-04-08 19:08:59 +08:00
salaryAcctEmployeeIds4ConsolidatedTax = SalaryEntityUtil . properties ( salaryAcctEmployeePOS4ConsolidatedTax , SalaryAcctEmployeePO : : getId ) ;
}
// 查询公式详情
Set < Long > formulaIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getFormulaId ) ;
2022-12-06 15:29:08 +08:00
// 获取回算公式
2022-12-02 17:35:14 +08:00
if ( isBackCalc ) {
2023-05-04 11:56:34 +08:00
formulaIds . addAll ( salarySobBackItemPOList . stream ( ) . map ( SalarySobBackItemPO : : getFormulaId ) . collect ( Collectors . toList ( ) ) ) ;
2022-12-02 17:35:14 +08:00
}
2022-04-12 19:25:19 +08:00
List < ExpressFormula > expressFormulas = getSalaryFormulaService ( user ) . listExpressFormula ( formulaIds ) ;
2022-04-08 19:08:59 +08:00
Map < Long , String > expressFormulaMap = SalaryEntityUtil . convert2Map ( expressFormulas , ExpressFormula : : getId , ExpressFormula : : getFormula ) ;
Map < Long , String > customParameters = SalaryEntityUtil . convert2Map ( salarySobItemPOS , SalarySobItemPO : : getSalaryItemId , salarySobItemPO - > {
if ( salarySobItemPO . getFormulaId ( ) < = 0 ) {
return SalaryI18nUtil . getI18nLabel ( 92004 , " 输入/导入 " ) ;
}
return expressFormulaMap . getOrDefault ( salarySobItemPO . getFormulaId ( ) , StringUtils . EMPTY ) ;
} ) ;
2022-12-02 17:35:14 +08:00
// 回算公式内容转换
Map < Long , String > customBackCalcParameters = SalaryEntityUtil . convert2Map ( salarySobBackItemPOList , SalarySobBackItemPO : : getSalaryItemId , salarySobBackItemPO - > {
if ( salarySobBackItemPO . getFormulaId ( ) < = 0 ) {
return SalaryI18nUtil . getI18nLabel ( 92004 , " 输入/导入 " ) ;
}
return expressFormulaMap . getOrDefault ( salarySobBackItemPO . getFormulaId ( ) , StringUtils . EMPTY ) ;
} ) ;
2022-04-08 19:08:59 +08:00
// 转换成薪资核算结果列表
2024-06-18 15:28:31 +08:00
return SalaryAcctResultBO . buildTableData ( salaryItemPOS , salarySobEmpFieldPOS , simpleEmployees , salaryAcctEmployeePOS , salaryAcctResultPOS , taxAgentPOS , salaryAcctEmployeeIds4ConsolidatedTax , customParameters , customBackCalcParameters , queryParam . isDynamicEmpInfo ( ) ) ;
2022-04-08 19:08:59 +08:00
}
@Override
public ConsolidatedTaxDetailDTO getConsolidatedTaxDetail ( Long salaryAcctEmployeeId ) {
// 查询当前的薪资核算人员
2022-04-12 19:25:19 +08:00
SalaryAcctEmployeePO salaryAcctEmployeePO = getSalaryAcctEmployeeService ( user ) . getById ( salaryAcctEmployeeId ) ;
2022-04-08 19:08:59 +08:00
if ( Objects . isNull ( salaryAcctEmployeePO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98831 , " 薪资核算人员不存在或已被删除 " ) ) ;
}
// 查询当前的薪资核算人员的个税扣缴义务人
2022-05-31 16:41:11 +08:00
TaxAgentPO taxAgentPO = getTaxAgentService ( user ) . getById ( salaryAcctEmployeePO . getTaxAgentId ( ) ) ;
2022-04-08 19:08:59 +08:00
// 查询当前的薪资核算人员的人员信息
2022-04-12 19:25:19 +08:00
DataCollectionEmployee simpleEmployee = getSalaryEmployeeService ( user ) . getEmployeeById ( salaryAcctEmployeePO . getEmployeeId ( ) ) ;
2022-04-08 19:08:59 +08:00
// 查询当前的薪资核算记录
2022-04-12 19:25:19 +08:00
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) ;
2022-04-08 19:08:59 +08:00
// 查询当前薪资核算记录所用的薪资账套
2022-04-12 19:25:19 +08:00
SalarySobPO salarySobPO = getSalarySobService ( user ) . getById ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
2022-04-08 19:08:59 +08:00
// 当前薪资核算记录所用的薪资账套的员工信息字段
2022-04-12 19:25:19 +08:00
List < SalarySobEmpFieldPO > salarySobEmpFieldPOS = getSalarySobEmpFieldService ( user ) . listBySalarySobId ( salarySobPO . getId ( ) ) ;
2022-04-08 19:08:59 +08:00
List < SalaryAcctRecordPO > salaryAcctRecordPOS = Collections . singletonList ( salaryAcctRecordPO ) ;
List < SalaryAcctEmployeePO > salaryAcctEmployeePOS = Collections . singletonList ( salaryAcctEmployeePO ) ;
// 如果当前薪资核算记录所用的薪资账套的薪资类型是工资薪金,代表可能存在合并计税
if ( Objects . equals ( salarySobPO . getIncomeCategory ( ) , IncomeCategoryEnum . WAGES_AND_SALARIES . getValue ( ) ) ) {
// 查询所有薪资类型为工资薪金的账套
2022-04-12 19:25:19 +08:00
List < SalarySobPO > salarySobPOS = getSalarySobService ( user ) . listByIncomeCategory ( IncomeCategoryEnum . WAGES_AND_SALARIES ) ;
2022-04-08 19:08:59 +08:00
// 查询相同税款所属期内的薪资类型为工资薪金的账套的所有核算记录
Set < Long > salarySobIds = SalaryEntityUtil . properties ( salarySobPOS , SalarySobPO : : getId ) ;
LocalDateRange taxCycleDateRange = SalaryDateUtil . localDate2Range ( salaryAcctRecordPO . getTaxCycle ( ) ) ;
2022-09-13 16:03:55 +08:00
salaryAcctRecordPOS = getSalaryAcctRecordService ( user ) . listBySalarySobIdsAndTaxCycle ( salarySobIds , taxCycleDateRange ) ;
2022-04-08 19:08:59 +08:00
// 查询当前薪资核算人员所涉及的合并计税的所有薪资核算人员
Set < Long > salaryAcctRecordIds = SalaryEntityUtil . properties ( salaryAcctRecordPOS , SalaryAcctRecordPO : : getId ) ;
2022-07-11 17:31:33 +08:00
salaryAcctEmployeePOS = getSalaryAcctEmployeeService ( user ) . listByRecordIdsAndEmpIdAndTaxAgentId ( salaryAcctRecordIds , salaryAcctEmployeePO . getEmployeeId ( ) , salaryAcctEmployeePO . getTaxAgentId ( ) ) ;
2022-04-08 19:08:59 +08:00
}
// 查询薪资核算人员的薪资核算结果
2023-09-07 15:15:59 +08:00
List < Long > salaryAcctEmployeeIds = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getId , Collectors . toList ( ) ) ;
2022-04-08 19:08:59 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = listBySalaryAcctEmployeeIds ( salaryAcctEmployeeIds ) ;
// 查询薪资核算人员所有合并计税的薪资核算记录所用的账套
Set < Long > salarySobIds = SalaryEntityUtil . properties ( salaryAcctEmployeePOS , SalaryAcctEmployeePO : : getSalarySobId ) ;
2022-04-12 19:25:19 +08:00
List < SalarySobPO > salarySobPOS = getSalarySobService ( user ) . listByIds ( salarySobIds ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资项目所引用的薪资项目
2022-04-12 19:25:19 +08:00
List < SalarySobItemPO > salarySobItemPOS = getSalarySobItemService ( user ) . listBySalarySobIds ( salarySobIds ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资项目
Set < Long > salaryItemIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getSalaryItemId ) ;
2022-04-12 19:25:19 +08:00
List < SalaryItemPO > salaryItemPOS = getSalaryItemService ( user ) . listByIds ( salaryItemIds ) ;
2022-04-08 19:08:59 +08:00
// 转换成合并计税详情dto
2022-07-11 17:31:33 +08:00
return SalaryAcctResultBO . convert2ConsolidatedTaxDetailDTO ( simpleEmployee , taxAgentPO , salarySobEmpFieldPOS , salaryItemPOS , salaryAcctEmployeePOS , salarySobPOS , salaryAcctRecordPOS , salaryAcctResultPOS ) ;
2022-04-08 19:08:59 +08:00
}
2022-08-02 14:58:18 +08:00
@Override
public Map < String , SalaryAcctResultListColumnDTO > getColumnBySalaryAcctRecordId ( Long salaryAcctRecordId ) {
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( salaryAcctRecordId ) ;
if ( Objects . isNull ( salaryAcctRecordPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资核算记录不存在或已被删除 " ) ) ;
}
Map < String , SalaryAcctResultListColumnDTO > resultMap = Maps . newHashMap ( ) ;
// 查询薪资核算使用的薪资账套下的薪资项目
2024-05-28 17:29:18 +08:00
SalarySobItemAggregateDTO salarySobItemAggregateDTO = getSalarySobItemService ( user ) . getAggregateByRecordId ( salaryAcctRecordId , true ) ;
2022-08-02 14:58:18 +08:00
for ( SalarySobItemIncomeCategoryDTO incomeCategoryDTO : salarySobItemAggregateDTO . getIncomeCategories ( ) ) {
for ( SalarySobItemGroupDTO salarySobItemGroupDTO : incomeCategoryDTO . getItemGroups ( ) ) {
for ( SalarySobItemDTO salarySobItemDTO : salarySobItemGroupDTO . getItems ( ) ) {
2023-09-26 17:18:27 +08:00
SalaryAcctResultListColumnDTO salaryAcctResultListColumnDTO = new SalaryAcctResultListColumnDTO ( ) . setColumnName ( salarySobItemDTO . getName ( ) ) . setFormulaId ( salarySobItemDTO . getFormulaId ( ) ) . setFormulaContent ( salarySobItemDTO . getFormulaContent ( ) ) . setShowLock ( ( ! Objects . equals ( salarySobItemDTO . getFormulaId ( ) , NumberUtils . LONG_ZERO ) & & salarySobItemDTO . isCanEdit ( ) ) | | Objects . equals ( salarySobItemDTO . getUseInEmployeeSalary ( ) , NumberUtils . INTEGER_ONE ) ) ;
2022-08-02 14:58:18 +08:00
resultMap . put ( " " + salarySobItemDTO . getSalaryItemId ( ) , salaryAcctResultListColumnDTO ) ;
}
}
for ( SalarySobItemDTO salarySobItemDTO : incomeCategoryDTO . getItems ( ) ) {
2023-09-26 17:18:27 +08:00
SalaryAcctResultListColumnDTO salaryAcctResultListColumnDTO = new SalaryAcctResultListColumnDTO ( ) . setColumnName ( salarySobItemDTO . getName ( ) ) . setFormulaId ( salarySobItemDTO . getFormulaId ( ) ) . setFormulaContent ( salarySobItemDTO . getFormulaContent ( ) ) . setShowLock ( ( ! Objects . equals ( salarySobItemDTO . getFormulaId ( ) , NumberUtils . LONG_ZERO ) & & salarySobItemDTO . isCanEdit ( ) ) | | Objects . equals ( salarySobItemDTO . getUseInEmployeeSalary ( ) , NumberUtils . INTEGER_ONE ) ) ;
2022-08-02 14:58:18 +08:00
resultMap . put ( " " + salarySobItemDTO . getSalaryItemId ( ) , salaryAcctResultListColumnDTO ) ;
}
}
2022-12-02 17:35:14 +08:00
// 查询回算薪资项目
if ( Objects . equals ( salaryAcctRecordPO . getBackCalcStatus ( ) , 1 ) ) {
List < SalarySobItemDTO > backCalcItems = salarySobItemAggregateDTO . getBackCalcItems ( ) ;
for ( SalarySobItemDTO backCalcItem : backCalcItems ) {
2023-09-26 17:18:27 +08:00
SalaryAcctResultListColumnDTO salaryAcctResultListColumnDTO = new SalaryAcctResultListColumnDTO ( ) . setColumnName ( backCalcItem . getName ( ) ) . setFormulaId ( backCalcItem . getFormulaId ( ) ) . setFormulaContent ( backCalcItem . getFormulaContent ( ) ) . setShowLock ( true ) ;
2022-12-02 17:35:14 +08:00
resultMap . put ( " " + backCalcItem . getSalaryItemId ( ) , salaryAcctResultListColumnDTO ) ;
}
}
2022-08-02 14:58:18 +08:00
return resultMap ;
}
2022-04-08 19:08:59 +08:00
@Override
public void save ( SalaryAcctResultSaveParam saveParam ) {
2022-07-11 17:31:33 +08:00
List < DataCollectionEmployee > dataCollectionEmployees = getSalaryEmployeeService ( user ) . listAllForReport ( ) ;
Map < Long , DataCollectionEmployee > emps = SalaryEntityUtil . convert2Map ( dataCollectionEmployees , DataCollectionEmployee : : getEmployeeId ) ;
2022-04-08 19:08:59 +08:00
// 查询薪资核算人员
2022-04-12 19:25:19 +08:00
SalaryAcctEmployeePO salaryAcctEmployeePO = getSalaryAcctEmployeeService ( user ) . getById ( saveParam . getSalaryAcctEmpId ( ) ) ;
2022-04-08 19:08:59 +08:00
if ( Objects . isNull ( salaryAcctEmployeePO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98831 , " 薪资核算人员不存在或已被删除 " ) ) ;
}
2024-07-25 14:04:14 +08:00
// 更新员工基本信息值
saveParam . getEmployeeInfos ( ) . stream ( ) . forEach ( info - > {
if ( info . getFieldValue ( ) ! = null & & StringUtils . isNotBlank ( info . getFieldValue ( ) . toString ( ) ) ) {
if ( info . getFieldCode ( ) . equals ( " departmentName " ) | | info . getFieldCode ( ) . equals ( " departmentId " ) ) {
// 修改部门信息
DeptInfo deptInfo = getSalaryEmployeeService ( user ) . getDeptInfoById ( NumberUtils . isCreatable ( info . getFieldValue ( ) . toString ( ) )
? Long . valueOf ( info . getFieldValue ( ) . toString ( ) ) : 0L ) ;
if ( Objects . nonNull ( deptInfo ) ) {
salaryAcctEmployeePO . setDepartmentName ( deptInfo . getName ( ) ) ;
salaryAcctEmployeePO . setDepartmentId ( deptInfo . getId ( ) ) ;
}
} else if ( info . getFieldCode ( ) . equals ( " subcompanyName " ) | | info . getFieldCode ( ) . equals ( " subcompanyId " ) ) {
// 修改分部信息
SubCompanyInfo subCompanyInfo = getSalaryEmployeeService ( user ) . getSubCompanyInfoById ( NumberUtils . isCreatable ( info . getFieldValue ( ) . toString ( ) )
? Long . valueOf ( info . getFieldValue ( ) . toString ( ) ) : 0L ) ;
if ( Objects . nonNull ( subCompanyInfo ) ) {
salaryAcctEmployeePO . setSubcompanyName ( subCompanyInfo . getName ( ) ) ;
salaryAcctEmployeePO . setSubcompanyId ( subCompanyInfo . getId ( ) ) ;
}
} else if ( info . getFieldCode ( ) . equals ( " jobtitleName " ) | | info . getFieldCode ( ) . equals ( " jobtitleId " ) ) {
// 修改岗位信息
PositionInfo positionInfo = getSalaryEmployeeService ( user ) . getPositionInfoById ( NumberUtils . isCreatable ( info . getFieldValue ( ) . toString ( ) )
? Long . valueOf ( info . getFieldValue ( ) . toString ( ) ) : 0L ) ;
if ( Objects . nonNull ( positionInfo ) ) {
salaryAcctEmployeePO . setJobtitleName ( positionInfo . getName ( ) ) ;
salaryAcctEmployeePO . setJobtitleId ( positionInfo . getId ( ) ) ;
}
} else if ( info . getFieldCode ( ) . equals ( " jobcall " ) | | info . getFieldCode ( ) . equals ( " jobcallId " ) ) {
// 修改职称信息
JobCallInfo jobCallInfo = getSalaryEmployeeService ( user ) . getJobCallInfoById ( NumberUtils . isCreatable ( info . getFieldValue ( ) . toString ( ) )
? Long . valueOf ( info . getFieldValue ( ) . toString ( ) ) : 0L ) ;
if ( Objects . nonNull ( jobCallInfo ) ) {
salaryAcctEmployeePO . setJobcall ( jobCallInfo . getName ( ) ) ;
salaryAcctEmployeePO . setJobcallId ( jobCallInfo . getId ( ) ) ;
}
}
}
} ) ;
getSalaryAcctEmployeeService ( user ) . updateIgnoreNull ( salaryAcctEmployeePO ) ;
2024-04-29 16:08:18 +08:00
// 校验是否可以编辑
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) ;
boolean recordIsCanEdit = getSalaryApprovalRuleService ( user ) . getRecordIsCanEdit ( salaryAcctRecordPO ) ;
if ( ! recordIsCanEdit ) {
throw new SalaryRunTimeException ( " 该核算记录已经发起审批,无法编辑或核算,请先删除审批流程 " ) ;
}
2022-12-02 17:35:14 +08:00
// 查询原来的薪资核算结果
List < SalaryAcctResultPO > salaryAcctResultPOSOld = getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctEmpId ( saveParam . getSalaryAcctEmpId ( ) ) . build ( ) ) ;
// 解密
2023-05-04 11:56:34 +08:00
encryptUtil . decryptList ( salaryAcctResultPOSOld , SalaryAcctResultPO . class ) ;
2022-04-08 19:08:59 +08:00
// 保存参数转换成薪资核算结果po
2022-12-02 17:35:14 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = SalaryAcctResultBO . convert2PO ( salaryAcctResultPOSOld , saveParam , salaryAcctEmployeePO , ( long ) user . getUID ( ) ) ;
2023-06-02 15:25:46 +08:00
SalarySysConfPO autoLock = getSalarySysConfService ( user ) . getOneByCode ( SalarySysConstant . EDIT_IMPORT_AUTO_LOCK ) ;
2023-09-07 15:15:59 +08:00
if ( autoLock ! = null & & StringUtils . equals ( autoLock . getConfValue ( ) , " 1 " ) ) {
2023-06-02 15:25:46 +08:00
// 对比核算结果提取修改了哪些薪资项目
Set < Long > needLockItems = new HashSet < > ( ) ;
Map < Long , SalaryAcctResultPO > oldResutMap = SalaryEntityUtil . convert2Map ( salaryAcctResultPOSOld , SalaryAcctResultPO : : getSalaryItemId ) ;
salaryAcctResultPOS . stream ( ) . forEach ( PO - > {
String oldValue = Optional . ofNullable ( oldResutMap . get ( PO . getSalaryItemId ( ) ) ) . map ( SalaryAcctResultPO : : getResultValue ) . orElse ( " " ) ;
2023-09-07 15:15:59 +08:00
if ( ! StringUtils . equals ( oldValue , PO . getResultValue ( ) ) ) {
2023-06-02 15:25:46 +08:00
needLockItems . add ( PO . getSalaryItemId ( ) ) ;
}
} ) ;
// 编辑的列都自动锁定
2023-09-26 17:18:27 +08:00
SalaryAcctResultUpdateLockStatusParam updateLockStatusParam = SalaryAcctResultUpdateLockStatusParam . builder ( ) . salaryItemIds ( needLockItems ) . salaryAcctRecordId ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) . lockStatus ( LockStatusEnum . LOCK ) . build ( ) ;
2023-06-02 15:25:46 +08:00
getSalaryAcctResultService ( user ) . updateLockStatusByParam ( updateLockStatusParam ) ;
}
2023-05-11 14:40:10 +08:00
// SalaryAcctRecordPO byId = getSalaryAcctRecordService(user).getById(salaryAcctEmployeePO.getSalaryAcctRecordId());
2022-12-02 17:35:14 +08:00
// 若保存编辑时一同传已发补发,则删除以下代码
// if(byId.getBackCalcStatus() != null && Objects.equals(byId.getBackCalcStatus(),1)){
// // 是回算
// List<Long> salarySobBackItemIds = getSalarySobBackItemService(user).listBySalarySobId(byId.getSalarySobId()).stream().map(SalarySobBackItemPO::getSalaryItemId).collect(Collectors.toList());
// // 获取已发待发的薪资核算结果
// List<SalaryAcctResultPO> salarySobBackItemResultPO = salaryAcctResultPOSOld.stream().filter(po -> salarySobBackItemIds.contains(po.getSalaryItemId())).collect(Collectors.toList());
// salaryAcctResultPOS.addAll(salarySobBackItemResultPO);
// }
2022-04-08 19:08:59 +08:00
// 删除原来的薪资核算结果
2023-11-20 11:09:43 +08:00
List < Long > saveItemIds = saveParam . getItems ( ) . stream ( ) . map ( SalaryAcctResultSaveParam . SalaryAcctResultDetailItemParam : : getSalaryItemId ) . collect ( Collectors . toList ( ) ) ;
2023-11-20 11:21:58 +08:00
deleteByAcctEmployeeIdsAndSalaryItemIds ( Collections . singletonList ( saveParam . getSalaryAcctEmpId ( ) ) , saveItemIds ) ;
2022-04-08 19:08:59 +08:00
// 保存薪资核算结果
if ( CollectionUtils . isNotEmpty ( salaryAcctResultPOS ) ) {
2022-06-02 17:01:26 +08:00
// 加密
2022-12-12 16:42:44 +08:00
encryptUtil . encryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
2022-06-16 17:55:26 +08:00
List < List < SalaryAcctResultPO > > partition = Lists . partition ( salaryAcctResultPOS , 100 ) ;
partition . forEach ( getSalaryAcctResultMapper ( ) : : batchInsert ) ;
2022-04-08 19:08:59 +08:00
}
2024-10-17 14:07:27 +08:00
//报表
// getSalaryAcctReportService(user).deleteByAcctEmployeeIdsAndSalaryItemIds(Collections.singletonList(saveParam.getSalaryAcctEmpId()), saveItemIds);
// List<SalaryAcctResultReportPO> salaryAcctResultReportPOS = SalaryAcctResultReportBO.convert2PO(saveParam, salaryAcctEmployeePO, (long) user.getUID(), emps);
// if (CollectionUtils.isNotEmpty(salaryAcctResultReportPOS)) {
// getSalaryAcctReportService(user).batchSave(salaryAcctResultReportPOS);
// }
2022-07-04 18:58:49 +08:00
2023-06-15 18:48:31 +08:00
2023-05-15 10:28:17 +08:00
// 存储薪资核算结果数据来源日志
2023-05-18 14:28:31 +08:00
salaryAcctResultPOS = getSalaryAcctRecordService ( user ) . listBySalaryAcctEmpId ( saveParam . getSalaryAcctEmpId ( ) ) ;
2023-05-15 10:28:17 +08:00
2022-04-08 19:08:59 +08:00
// 查询操作日志的targetName
2024-01-24 09:50:58 +08:00
String targetName = getSalaryAcctRecordService ( user ) . getLogTargetNameById ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) ;
// 查询人员信息
DataCollectionEmployee simpleEmployee = getSalaryEmployeeService ( user ) . getEmployeeById ( salaryAcctEmployeePO . getEmployeeId ( ) ) ;
// 查询个税扣缴义务人
TaxAgentPO taxAgentPO = getTaxAgentService ( user ) . getById ( salaryAcctEmployeePO . getTaxAgentId ( ) ) ;
// 记录日志
String operateDesc = simpleEmployee . getUsername ( ) + " ( " + Optional . ofNullable ( taxAgentPO ) . map ( TaxAgentPO : : getName ) . orElse ( StringUtils . EMPTY ) + " ) " ;
LoggerContext < SalaryCheckResultPO > loggerContext = new LoggerContext < > ( ) ;
loggerContext . setUser ( user ) ;
loggerContext . setTargetId ( String . valueOf ( salaryAcctEmployeePO . getSalaryAcctRecordId ( ) ) ) ;
loggerContext . setTargetName ( targetName ) ;
loggerContext . setOperateType ( OperateTypeEnum . UPDATE . getValue ( ) ) ;
2024-02-04 15:10:35 +08:00
loggerContext . setOperateTypeName ( SalaryI18nUtil . getI18nLabel ( 0 , " 编辑薪资核算结果 " ) + " : " + operateDesc ) ;
loggerContext . setOperatedesc ( SalaryI18nUtil . getI18nLabel ( 0 , " 编辑薪资核算结果 " ) + " : " + operateDesc ) ;
2024-01-24 09:50:58 +08:00
loggerContext . setNewValueList ( Lists . newArrayList ( salaryAcctResultPOS ) ) ;
2024-01-30 09:58:13 +08:00
SalaryElogConfig . salaryAcctRecordLoggerTemplate . write ( loggerContext ) ;
2022-04-08 19:08:59 +08:00
}
2023-05-15 10:28:17 +08:00
/ * *
* 存储薪资核算结果数据来源日志
2023-09-07 15:15:59 +08:00
*
2023-05-15 10:28:17 +08:00
* @param salaryAcctResultPOSOld
* @param salaryAcctResultPOS
* /
private void saveSalaryAcctResultLog ( List < SalaryAcctResultPO > salaryAcctResultPOSOld , List < SalaryAcctResultPO > salaryAcctResultPOS ) {
// 对比核算结果提取修改了哪些薪资项目
List < SalaryAcctResultPO > editItems = new ArrayList < > ( ) ;
Map < Long , SalaryAcctResultPO > oldResutMap = SalaryEntityUtil . convert2Map ( salaryAcctResultPOSOld , SalaryAcctResultPO : : getSalaryItemId ) ;
salaryAcctResultPOS . stream ( ) . forEach ( PO - > {
2023-09-07 15:15:59 +08:00
if ( oldResutMap . get ( PO . getSalaryItemId ( ) ) = = null ) {
2023-05-15 10:28:17 +08:00
editItems . add ( PO ) ;
2023-09-07 15:15:59 +08:00
} else {
2023-05-25 17:06:03 +08:00
String oldValue = oldResutMap . get ( PO . getSalaryItemId ( ) ) . getResultValue ( ) ;
2023-09-07 15:15:59 +08:00
if ( ! StringUtils . equals ( oldValue , PO . getResultValue ( ) ) ) {
2023-05-25 17:06:03 +08:00
editItems . add ( PO ) ;
}
2023-05-15 10:28:17 +08:00
}
} ) ;
List < SalaryAcctResultLogPO > needInsertList = SalaryAcctResultLogBO . buildSalaryAcctResultLog ( editItems , Long . valueOf ( user . getUID ( ) ) , SalaryAcctResultDataSourceEnum . EDIT ) ;
getSalaryAcctResultLogService ( user ) . batchInsert ( needInsertList ) ;
}
2022-12-02 17:35:14 +08:00
2022-04-08 19:08:59 +08:00
@Override
2023-09-26 17:18:27 +08:00
public void batchSave ( List < SalaryAcctResultPO > salaryAcctResultPOS ) {
2022-04-08 19:08:59 +08:00
if ( CollectionUtils . isNotEmpty ( salaryAcctResultPOS ) ) {
2022-06-16 17:55:26 +08:00
// 数据加密
2023-09-26 17:18:27 +08:00
encryptUtil . encryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
List < List < SalaryAcctResultPO > > partition = Lists . partition ( salaryAcctResultPOS , 100 ) ;
2022-06-16 17:55:26 +08:00
partition . forEach ( getSalaryAcctResultMapper ( ) : : batchInsert ) ;
2023-06-15 18:48:31 +08:00
2022-04-08 19:08:59 +08:00
}
}
2024-06-06 13:51:33 +08:00
public void batchUpdate ( List < SalaryAcctResultPO > salaryAcctResultPOS ) {
if ( CollectionUtils . isNotEmpty ( salaryAcctResultPOS ) ) {
// 数据加密
encryptUtil . encryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
List < List < SalaryAcctResultPO > > partition = Lists . partition ( salaryAcctResultPOS , 100 ) ;
partition . forEach ( getSalaryAcctResultMapper ( ) : : batchUpdate ) ;
}
}
2022-07-11 17:31:33 +08:00
2022-04-08 19:08:59 +08:00
@Override
public void deleteBySalaryAcctEmployeeIds ( Collection < Long > salaryAcctEmployeeIds ) {
2022-04-12 19:25:19 +08:00
getSalaryAcctResultMapper ( ) . deleteBySalaryAcctEmpIds ( salaryAcctEmployeeIds ) ;
2022-04-08 19:08:59 +08:00
}
2022-12-02 17:35:14 +08:00
2022-04-08 19:08:59 +08:00
@Override
2023-11-20 10:56:03 +08:00
public void deleteByAcctEmployeeIdsAndSalaryItemIds ( List < Long > salaryAcctEmployeeIds , Collection < Long > salaryItemIds ) {
List < List < Long > > partition = Lists . partition ( salaryAcctEmployeeIds , 300 ) ;
partition . forEach ( part - > getSalaryAcctResultMapper ( ) . deleteByAcctEmpIdsAndSalaryItemIds ( part , salaryItemIds ) ) ;
2022-04-08 19:08:59 +08:00
}
@Override
public void deleteBySalaryAcctRecordIds ( Collection < Long > salaryAcctRecordIds ) {
2022-04-12 19:25:19 +08:00
getSalaryAcctResultMapper ( ) . deleteBySalaryAcctRecordIds ( salaryAcctRecordIds ) ;
2022-04-08 19:08:59 +08:00
}
2022-04-11 20:17:47 +08:00
@Override
public void calculate ( SalaryAcctCalculateParam calculateParam , DataCollectionEmployee simpleEmployee ) {
try {
2024-09-19 14:17:47 +08:00
log . info ( " 开始核算V2 {} " , calculateParam ) ;
StopWatch stopWatch = new StopWatch ( " 总核算耗时, id: " + calculateParam . getSalaryAcctRecordId ( ) ) ;
2024-05-16 15:56:49 +08:00
stopWatch . start ( " 数据准备 " ) ;
2022-04-11 20:17:47 +08:00
// 1、查询薪资核算记录
2022-04-12 19:25:19 +08:00
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( calculateParam . getSalaryAcctRecordId ( ) ) ;
2022-04-11 20:17:47 +08:00
if ( Objects . isNull ( salaryAcctRecordPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资核算记录不存在或已被删除 " ) ) ;
}
2022-06-15 17:53:12 +08:00
//查询对应账套
SalarySobPO salarySobPO = getSalarySobService ( user ) . getById ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
if ( Objects . isNull ( salarySobPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资账套不存在或已被删除 " ) ) ;
}
2024-05-06 16:03:29 +08:00
// 不是查询薪资账套下实时的薪资项目,而是查询发起薪资核算时存储的薪资项目快照
SalaryAcctConfig salaryAcctSobConfig = getSalaryAcctSobConfigService ( user ) . getSalaryAcctConfig ( calculateParam . getSalaryAcctRecordId ( ) ) ;
2022-04-11 20:17:47 +08:00
// 1.1、如果薪资核算记录已经归档了,就不能继续核算
if ( ! Objects . equals ( salaryAcctRecordPO . getStatus ( ) , SalaryAcctRecordStatusEnum . NOT_ARCHIVED . getValue ( ) ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 99148 , " 当前薪资核算记录已归档,请重新打开后再进行核算 " ) ) ;
}
// 2、查询薪资核算记录的薪资周期、考勤周期等
2022-04-12 19:25:19 +08:00
SalarySobCycleDTO salarySobCycleDTO = getSalaryAcctRecordService ( user ) . getSalarySobCycleById ( calculateParam . getSalaryAcctRecordId ( ) ) ;
2022-04-11 20:17:47 +08:00
// 3、查询薪资核算记录所用薪资账套的薪资项目副本
2024-05-06 16:03:29 +08:00
List < SalarySobItemPO > salarySobItemPOS = salaryAcctSobConfig . getSalarySobItems ( ) ;
2022-04-11 20:17:47 +08:00
if ( CollectionUtils . isEmpty ( salarySobItemPOS ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 99151 , " 当前所用的薪资账套未选择任何薪资项目,无法核算 " ) ) ;
}
2022-12-02 17:35:14 +08:00
// 回算薪资项目
List < SalarySobBackItemPO > salarySobBackItems = Collections . emptyList ( ) ;
2023-05-04 11:56:34 +08:00
if ( Objects . equals ( salaryAcctRecordPO . getBackCalcStatus ( ) , 1 ) ) {
2024-05-06 17:41:39 +08:00
salarySobBackItems = salaryAcctSobConfig . getSalarySobBackItems ( ) ;
2022-12-02 17:35:14 +08:00
}
2022-04-11 20:17:47 +08:00
// 4、查询当前租户的所有薪资项目
2022-04-12 19:25:19 +08:00
List < SalaryItemPO > salaryItemPOS = getSalaryItemService ( user ) . listAll ( ) ;
2022-04-11 20:17:47 +08:00
// 5、查询薪资核算记录所用薪资账套的调薪计薪规则
2022-04-12 19:25:19 +08:00
List < SalarySobAdjustRulePO > salarySobAdjustRulePOS = getSalarySobAdjustRuleService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
2022-04-28 15:02:11 +08:00
// 6、查询社保福利的所有字段
Map < String , String > welfareColumns = getSIAccountService ( user ) . welfareColumns ( ) ;
2022-04-11 20:17:47 +08:00
// 7、查询考勤引用的所有字段
2022-04-12 19:25:19 +08:00
List < AttendQuoteFieldListDTO > attendQuoteFieldListDTOS = getAttendQuoteFieldService ( user ) . listAll ( ) ;
2024-08-09 10:21:40 +08:00
List < VariableItemPO > variableItemPOS = getVariableItemService ( user ) . listAll ( ) ;
2022-11-17 09:28:40 +08:00
2022-04-11 20:17:47 +08:00
// 8、查询公式详情
Set < Long > formulaIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getFormulaId ) ;
formulaIds . addAll ( SalaryEntityUtil . properties ( salaryItemPOS , SalaryItemPO : : getFormulaId ) ) ;
2023-05-04 11:56:34 +08:00
formulaIds . addAll ( SalaryEntityUtil . properties ( salarySobBackItems , SalarySobBackItemPO : : getFormulaId ) ) ;
2022-04-14 10:03:49 +08:00
List < ExpressFormula > expressFormulas = getSalaryFormulaService ( user ) . listExpressFormula ( formulaIds ) ;
2022-12-02 17:35:14 +08:00
// 本次运算的回算薪资项目所涉及的变量
2023-09-07 15:15:59 +08:00
Set < String > issuedFieldIds = getIssuedFieldIds ( salarySobBackItems ) ;
2022-04-11 20:17:47 +08:00
// 9、计算薪资项目的运算优先级
2023-09-07 15:15:59 +08:00
List < Long > salarySobItemsWithPriority = sortItems ( salarySobItemPOS , salarySobBackItems , salaryItemPOS , expressFormulas ) ;
2024-07-02 15:39:31 +08:00
//账套中配置的个税字段,不需要系统算
List < SalarySobTaxRulePO > salarySobTaxRulePOS = getSalarySobTaxRuleService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
List < Long > taxIds = SalaryEntityUtil . properties ( salarySobTaxRulePOS , SalarySobTaxRulePO : : getSalaryItemId , Collectors . toList ( ) ) ;
2023-09-06 14:01:56 +08:00
2022-04-11 20:17:47 +08:00
// 10、根据id查询其他合并计税的薪资核算记录
2022-04-12 19:25:19 +08:00
List < SalaryAcctRecordPO > otherSalaryAcctRecordPOS = getSalaryAcctRecordService ( user ) . listById4OtherConsolidatedTax ( salaryAcctRecordPO . getId ( ) ) ;
2022-04-11 20:17:47 +08:00
// 11、查询本次核算人员
List < SalaryAcctEmployeePO > salaryAcctEmployeePOS ;
if ( CollectionUtils . isEmpty ( calculateParam . getIds ( ) ) ) {
2022-04-12 19:25:19 +08:00
salaryAcctEmployeePOS = getSalaryAcctEmployeeService ( user ) . listBySalaryAcctRecordId ( salaryAcctRecordPO . getId ( ) ) ;
2022-04-11 20:17:47 +08:00
} else {
2022-04-12 19:25:19 +08:00
salaryAcctEmployeePOS = getSalaryAcctEmployeeService ( user ) . listByIds ( calculateParam . getIds ( ) ) ;
2022-04-11 20:17:47 +08:00
}
if ( CollectionUtils . isEmpty ( salaryAcctEmployeePOS ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 103378 , " 薪资核算人员不能为空 " ) ) ;
}
2023-09-26 14:29:12 +08:00
stopWatch . stop ( ) ;
2024-05-16 15:56:49 +08:00
stopWatch . start ( " 核算耗时 " ) ;
2023-09-26 14:29:12 +08:00
2022-04-11 20:17:47 +08:00
// 11.1、初始化进度
2023-06-06 10:30:49 +08:00
ProgressDTO initProgress = new ProgressDTO ( ) . setTitle ( SalaryI18nUtil . getI18nLabel ( 97515 , " 核算中 " ) ) . setTitleLabelId ( 97515L ) . setTotalQuantity ( salaryAcctEmployeePOS . size ( ) * 2 + 1 ) . setCalculatedQuantity ( 0 ) . setProgress ( BigDecimal . ZERO ) . setStatus ( true ) . setMessage ( StringUtils . EMPTY ) ;
2022-04-29 17:15:22 +08:00
getSalaryAcctProgressService ( user ) . initProgress ( SalaryCacheKey . ACCT_PROGRESS + calculateParam . getSalaryAcctRecordId ( ) , initProgress ) ;
2022-04-11 20:17:47 +08:00
// 12、对薪资核算人员进行拆分
2024-09-02 18:11:00 +08:00
String personNumberInOneThread = new BaseBean ( ) . getPropValue ( " hrmSalaryCustom " , " personNumberInOneThread " ) ;
2024-09-19 14:17:47 +08:00
int size = 100 ;
if ( StringUtils . isNotBlank ( personNumberInOneThread ) ) {
2024-09-02 18:11:00 +08:00
size = Integer . parseInt ( personNumberInOneThread ) ;
}
List < List < SalaryAcctEmployeePO > > partition = Lists . partition ( salaryAcctEmployeePOS , size ) ;
2022-04-11 20:17:47 +08:00
// 12.1、监控子线程的任务执行
CountDownLatch childMonitor = new CountDownLatch ( partition . size ( ) ) ;
// 12.2、记录子线程的执行结果
BlockingDeque < SalaryAcctCalculateBO . Result > calculateResults = new LinkedBlockingDeque < > ( partition . size ( ) ) ;
// 12.3、生成本次运算的key
String calculateKey = UUID . randomUUID ( ) . toString ( ) ;
2023-07-04 09:32:12 +08:00
// 12.4、是否采用系统算税
TaxDeclarationFunctionEnum taxDeclarationFunction = getSalarySysConfService ( user ) . getTaxDeclaration ( ) ;
// 12.5、多线程运算,运算结果存放在临时表中
2025-03-19 17:18:09 +08:00
//是否同步计算
2025-03-19 18:08:19 +08:00
boolean isSync = " 0 " . equals ( getSalarySysConfService ( user ) . getValueByCode ( SALARY_ACCT_SYNC_TYPE ) ) ;
2022-04-11 20:17:47 +08:00
for ( List < SalaryAcctEmployeePO > acctEmployeePOS : partition ) {
2024-05-14 13:28:58 +08:00
SalaryAcctCalculateBO salaryAcctCalculateBO = new SalaryAcctCalculateBO ( )
. setSalaryAcctRecordPO ( salaryAcctRecordPO )
. setSalarySobPO ( salarySobPO )
. setSalarySobCycleDTO ( salarySobCycleDTO )
. setOtherSalaryAcctRecordPOS ( otherSalaryAcctRecordPOS )
. setSalarySobItemPOS ( salarySobItemPOS )
. setSalaryItemIdWithPriorityList ( salarySobItemsWithPriority )
. setExpressFormulas ( expressFormulas )
. setSalaryItemPOS ( salaryItemPOS )
. setSalarySobAdjustRulePOS ( salarySobAdjustRulePOS )
. setWelfareColumns ( MapUtils . emptyIfNull ( welfareColumns ) )
. setAttendQuoteFieldListDTOS ( attendQuoteFieldListDTOS )
. setSalaryAcctEmployeePOS ( acctEmployeePOS )
. setIssuedFieldIds ( issuedFieldIds )
. setChildMonitor ( childMonitor )
. setResults ( calculateResults )
. setCalculateKey ( calculateKey )
2024-08-09 10:21:40 +08:00
. setVariableItems ( variableItemPOS )
2024-07-02 15:39:31 +08:00
. setTaxDeclarationFunction ( taxDeclarationFunction )
. setTaxIds ( taxIds ) ;
2022-12-02 17:35:14 +08:00
List < SalarySobBackItemPO > finalSalarySobBackItems = salarySobBackItems ;
2025-03-19 17:18:09 +08:00
if ( isSync ) {
getSalaryAcctCalculateService ( user ) . calculate ( salaryAcctCalculateBO , simpleEmployee , finalSalarySobBackItems ) ;
} else {
LocalRunnable localRunnable = new LocalRunnable ( ) {
@Override
public void execute ( ) {
getSalaryAcctCalculateService ( user ) . calculate ( salaryAcctCalculateBO , simpleEmployee , finalSalarySobBackItems ) ;
}
} ;
ThreadPoolUtil . fixedPoolExecute ( ModulePoolEnum . HRM , " salaryAcctCalculate " , localRunnable ) ;
}
2022-04-11 20:17:47 +08:00
}
// 13、等待所有子线程执行完毕
childMonitor . await ( ) ;
2023-09-26 14:29:12 +08:00
stopWatch . stop ( ) ;
2024-05-16 15:56:49 +08:00
stopWatch . start ( " 数据写入耗时 " ) ;
2023-09-26 14:29:12 +08:00
2022-04-11 20:17:47 +08:00
// 14、判断子线程执行结果
boolean allSuccess = calculateResults . stream ( ) . allMatch ( SalaryAcctCalculateBO . Result : : isStatus ) ;
if ( ! allSuccess ) {
// 薪资核算实现的线程的错误信息
2022-07-11 17:31:33 +08:00
String errorMsg = calculateResults . stream ( ) . filter ( result - > ! result . isStatus ( ) ) . map ( SalaryAcctCalculateBO . Result : : getErrMsg ) . collect ( Collectors . joining ( " | " ) ) ;
2022-04-29 17:15:22 +08:00
getSalaryAcctProgressService ( user ) . fail ( SalaryCacheKey . ACCT_PROGRESS + calculateParam . getSalaryAcctRecordId ( ) , errorMsg ) ;
2022-04-11 20:17:47 +08:00
// 删除薪资核算临时存储表中的数据
2022-04-12 19:25:19 +08:00
getSalaryAcctResultTempService ( user ) . deleteByCalculateKey ( calculateKey ) ;
2022-04-11 20:17:47 +08:00
return ;
}
// 15、处理核算结果临时表数据
handleSalaryAcctResultTemp ( calculateParam , calculateKey ) ;
// 16、开始运行校验规则
2022-04-07 16:54:10 +08:00
// SalaryAcctCheckParam salaryAcctCheckParam = new SalaryAcctCheckParam()
// .setSalaryAcctRecordId(calculateParam.getSalaryAcctRecordId())
// .setIds(calculateParam.getIds());
2022-04-08 19:08:59 +08:00
// salaryCheckResultService.check(salaryAcctCheckParam, true, simpleEmployee);
2022-04-29 17:15:22 +08:00
// Thread.sleep(10);
getSalaryAcctProgressService ( user ) . finish ( SalaryCacheKey . ACCT_PROGRESS + calculateParam . getSalaryAcctRecordId ( ) , true ) ;
2023-05-15 10:28:17 +08:00
2024-10-24 10:55:44 +08:00
//更新薪资核算记录最后操作日期
2025-02-17 15:54:35 +08:00
getSalaryAcctRecordService ( user ) . updateDate ( salaryAcctRecordPO . getId ( ) , new Date ( ) ) ;
2024-10-24 10:55:44 +08:00
2023-09-26 14:29:12 +08:00
stopWatch . stop ( ) ;
log . info ( stopWatch . prettyPrint ( ) ) ;
2024-05-28 17:29:18 +08:00
2022-04-11 20:17:47 +08:00
// 记录日志
// 查询操作日志的targetName
2024-01-24 09:50:58 +08:00
String targetName = getSalaryAcctRecordService ( user ) . getLogTargetNameById ( calculateParam . getSalaryAcctRecordId ( ) ) ;
2025-03-06 17:35:25 +08:00
Collection < Long > ids = calculateParam . getIds ( ) ;
if ( CollectionUtils . isNotEmpty ( ids ) ) {
targetName + = ids ;
}
2024-01-24 09:50:58 +08:00
LoggerContext < SalaryCheckResultPO > loggerContext = new LoggerContext < > ( ) ;
loggerContext . setUser ( user ) ;
loggerContext . setTargetId ( String . valueOf ( calculateParam . getSalaryAcctRecordId ( ) ) ) ;
loggerContext . setTargetName ( targetName ) ;
loggerContext . setOperateType ( OperateTypeEnum . UPDATE . getValue ( ) ) ;
2024-02-04 15:10:35 +08:00
loggerContext . setOperateTypeName ( SalaryI18nUtil . getI18nLabel ( 0 , " 薪资核算 " ) ) ;
loggerContext . setOperatedesc ( SalaryI18nUtil . getI18nLabel ( 0 , " 薪资核算 " ) ) ;
2024-01-30 09:58:13 +08:00
SalaryElogConfig . salaryAcctRecordLoggerTemplate . write ( loggerContext ) ;
2022-04-11 20:17:47 +08:00
} catch ( Exception e ) {
log . info ( " 薪资核算出错:{} " , e . getMessage ( ) , e ) ;
2022-04-29 17:15:22 +08:00
// throw new SalaryRunTimeException(e);
getSalaryAcctProgressService ( user ) . fail ( SalaryCacheKey . ACCT_PROGRESS + calculateParam . getSalaryAcctRecordId ( ) , SalaryI18nUtil . getI18nLabel ( 99642 , " 薪资核算出错 " ) + " : " + e . getMessage ( ) ) ;
2022-04-11 20:17:47 +08:00
} finally {
// 数据库字段加密用
}
}
2022-04-08 19:08:59 +08:00
2024-07-17 09:03:31 +08:00
@Override
public void afterTaxAccounting ( SalaryAfterTaxAcctCalculateParam calculateParam , DataCollectionEmployee simpleEmployee ) {
Long salaryAcctRecordId = calculateParam . getSalaryAcctRecordId ( ) ;
try {
// 1、查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( salaryAcctRecordId ) ;
if ( Objects . isNull ( salaryAcctRecordPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资核算记录不存在或已被删除 " ) ) ;
}
//查询对应账套
SalarySobPO salarySobPO = getSalarySobService ( user ) . getById ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
if ( Objects . isNull ( salarySobPO ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 98747 , " 薪资账套不存在或已被删除 " ) ) ;
}
// 不是查询薪资账套下实时的薪资项目,而是查询发起薪资核算时存储的薪资项目快照
SalaryAcctConfig salaryAcctSobConfig = getSalaryAcctSobConfigService ( user ) . getSalaryAcctConfig ( salaryAcctRecordId ) ;
// 1.1、如果薪资核算记录已经归档了,就不能继续核算
if ( ! Objects . equals ( salaryAcctRecordPO . getStatus ( ) , SalaryAcctRecordStatusEnum . NOT_ARCHIVED . getValue ( ) ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 99148 , " 当前薪资核算记录已归档,请重新打开后再进行核算 " ) ) ;
}
// 2、查询薪资核算记录的薪资周期、考勤周期等
SalarySobCycleDTO salarySobCycleDTO = getSalaryAcctRecordService ( user ) . getSalarySobCycleById ( salaryAcctRecordId ) ;
// 3、查询薪资核算记录所用薪资账套的薪资项目副本
List < SalarySobItemPO > salarySobItemPOS = salaryAcctSobConfig . getSalarySobItems ( ) ;
if ( CollectionUtils . isEmpty ( salarySobItemPOS ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 99151 , " 当前所用的薪资账套未选择任何薪资项目,无法核算 " ) ) ;
}
// 回算薪资项目
List < SalarySobBackItemPO > salarySobBackItems = Collections . emptyList ( ) ;
if ( Objects . equals ( salaryAcctRecordPO . getBackCalcStatus ( ) , 1 ) ) {
salarySobBackItems = salaryAcctSobConfig . getSalarySobBackItems ( ) ;
}
// 4、查询当前租户的所有薪资项目
List < SalaryItemPO > salaryItemPOS = getSalaryItemService ( user ) . listAll ( ) ;
// 5、查询薪资核算记录所用薪资账套的调薪计薪规则
List < SalarySobAdjustRulePO > salarySobAdjustRulePOS = getSalarySobAdjustRuleService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
// 6、查询社保福利的所有字段
Map < String , String > welfareColumns = getSIAccountService ( user ) . welfareColumns ( ) ;
// 7、查询考勤引用的所有字段
List < AttendQuoteFieldListDTO > attendQuoteFieldListDTOS = getAttendQuoteFieldService ( user ) . listAll ( ) ;
2024-10-22 17:32:00 +08:00
List < VariableItemPO > variableItemPOS = getVariableItemService ( user ) . listAll ( ) ;
2024-07-17 09:03:31 +08:00
// 8、查询公式详情
Set < Long > formulaIds = SalaryEntityUtil . properties ( salarySobItemPOS , SalarySobItemPO : : getFormulaId ) ;
formulaIds . addAll ( SalaryEntityUtil . properties ( salaryItemPOS , SalaryItemPO : : getFormulaId ) ) ;
formulaIds . addAll ( SalaryEntityUtil . properties ( salarySobBackItems , SalarySobBackItemPO : : getFormulaId ) ) ;
List < ExpressFormula > expressFormulas = getSalaryFormulaService ( user ) . listExpressFormula ( formulaIds ) ;
// 本次运算的回算薪资项目所涉及的变量
Set < String > issuedFieldIds = getIssuedFieldIds ( salarySobBackItems ) ;
// 9、计算薪资项目的运算优先级
List < Long > salarySobItemsWithPriority = sortItems ( salarySobItemPOS , salarySobBackItems , salaryItemPOS , expressFormulas ) ;
//账套中配置的个税字段,不需要系统算
List < SalarySobTaxRulePO > salarySobTaxRulePOS = getSalarySobTaxRuleService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
List < Long > taxIds = SalaryEntityUtil . properties ( salarySobTaxRulePOS , SalarySobTaxRulePO : : getSalaryItemId , Collectors . toList ( ) ) ;
2024-07-17 13:37:39 +08:00
/ * *
* 计算税后薪资
* /
int index = salarySobItemsWithPriority . size ( ) - 1 ;
for ( Long id : taxIds ) {
int i = salarySobItemsWithPriority . indexOf ( id ) ;
if ( i ! = - 1 & & i < index ) {
index = i ;
}
}
salarySobItemsWithPriority = salarySobItemsWithPriority . subList ( index , salarySobItemsWithPriority . size ( ) ) ;
2024-07-17 09:03:31 +08:00
// 10、根据id查询其他合并计税的薪资核算记录
List < SalaryAcctRecordPO > otherSalaryAcctRecordPOS = getSalaryAcctRecordService ( user ) . listById4OtherConsolidatedTax ( salaryAcctRecordPO . getId ( ) ) ;
// 11、查询本次核算人员
List < SalaryAcctEmployeePO > salaryAcctEmployeePOS = getSalaryAcctEmployeeService ( user ) . listBySalaryAcctRecordId ( salaryAcctRecordPO . getId ( ) ) ;
if ( CollectionUtils . isEmpty ( salaryAcctEmployeePOS ) ) {
throw new SalaryRunTimeException ( SalaryI18nUtil . getI18nLabel ( 103378 , " 薪资核算人员不能为空 " ) ) ;
}
// 11.1、初始化进度
ProgressDTO initProgress = new ProgressDTO ( ) . setTitle ( SalaryI18nUtil . getI18nLabel ( 97515 , " 核算中 " ) ) . setTitleLabelId ( 97515L ) . setTotalQuantity ( salaryAcctEmployeePOS . size ( ) * 2 + 1 ) . setCalculatedQuantity ( 0 ) . setProgress ( BigDecimal . ZERO ) . setStatus ( true ) . setMessage ( StringUtils . EMPTY ) ;
getSalaryAcctProgressService ( user ) . initProgress ( SalaryCacheKey . AFTER_TAXA_CCT_PROGRESS + salaryAcctRecordId , initProgress ) ;
// 12、对薪资核算人员进行拆分
List < List < SalaryAcctEmployeePO > > partition = Lists . partition ( salaryAcctEmployeePOS , 100 ) ;
// 12.1、监控子线程的任务执行
CountDownLatch childMonitor = new CountDownLatch ( partition . size ( ) ) ;
// 12.2、记录子线程的执行结果
BlockingDeque < SalaryAcctCalculateBO . Result > calculateResults = new LinkedBlockingDeque < > ( partition . size ( ) ) ;
// 12.3、生成本次运算的key
String calculateKey = UUID . randomUUID ( ) . toString ( ) ;
// 12.4、是否采用系统算税
TaxDeclarationFunctionEnum taxDeclarationFunction = getSalarySysConfService ( user ) . getTaxDeclaration ( ) ;
// 12.5、多线程运算,运算结果存放在临时表中
for ( List < SalaryAcctEmployeePO > acctEmployeePOS : partition ) {
SalaryAcctCalculateBO salaryAcctCalculateBO = new SalaryAcctCalculateBO ( )
. setSalaryAcctRecordPO ( salaryAcctRecordPO )
. setSalarySobPO ( salarySobPO )
. setSalarySobCycleDTO ( salarySobCycleDTO )
. setOtherSalaryAcctRecordPOS ( otherSalaryAcctRecordPOS )
. setSalarySobItemPOS ( salarySobItemPOS )
. setSalaryItemIdWithPriorityList ( salarySobItemsWithPriority )
. setExpressFormulas ( expressFormulas )
. setSalaryItemPOS ( salaryItemPOS )
. setSalarySobAdjustRulePOS ( salarySobAdjustRulePOS )
. setWelfareColumns ( MapUtils . emptyIfNull ( welfareColumns ) )
. setAttendQuoteFieldListDTOS ( attendQuoteFieldListDTOS )
. setSalaryAcctEmployeePOS ( acctEmployeePOS )
. setIssuedFieldIds ( issuedFieldIds )
. setChildMonitor ( childMonitor )
. setResults ( calculateResults )
. setCalculateKey ( calculateKey )
2024-10-22 17:32:00 +08:00
. setVariableItems ( variableItemPOS )
2024-07-17 09:03:31 +08:00
. setTaxDeclarationFunction ( taxDeclarationFunction )
. setTaxIds ( taxIds ) ;
List < SalarySobBackItemPO > finalSalarySobBackItems = salarySobBackItems ;
LocalRunnable localRunnable = new LocalRunnable ( ) {
@Override
public void execute ( ) {
getSalaryAcctCalculateService ( user ) . calculate ( salaryAcctCalculateBO , simpleEmployee , finalSalarySobBackItems ) ;
}
} ;
ThreadPoolUtil . fixedPoolExecute ( ModulePoolEnum . HRM , " salaryAcctCalculate " , localRunnable ) ;
}
// 13、等待所有子线程执行完毕
childMonitor . await ( ) ;
// 14、判断子线程执行结果
boolean allSuccess = calculateResults . stream ( ) . allMatch ( SalaryAcctCalculateBO . Result : : isStatus ) ;
if ( ! allSuccess ) {
// 薪资核算实现的线程的错误信息
String errorMsg = calculateResults . stream ( ) . filter ( result - > ! result . isStatus ( ) ) . map ( SalaryAcctCalculateBO . Result : : getErrMsg ) . collect ( Collectors . joining ( " | " ) ) ;
getSalaryAcctProgressService ( user ) . fail ( SalaryCacheKey . AFTER_TAXA_CCT_PROGRESS + salaryAcctRecordId , errorMsg ) ;
// 删除薪资核算临时存储表中的数据
getSalaryAcctResultTempService ( user ) . deleteByCalculateKey ( calculateKey ) ;
return ;
}
// 15、处理核算结果临时表数据
2024-07-17 13:37:39 +08:00
handleSalaryAfterTaxAcctResultTemp ( salaryAcctRecordId , calculateKey , salarySobItemsWithPriority ) ;
2024-07-17 09:03:31 +08:00
// 16、开始运行校验规则
// SalaryAcctCheckParam salaryAcctCheckParam = new SalaryAcctCheckParam()
// .setSalaryAcctRecordId(calculateParam.getSalaryAcctRecordId())
// .setIds(calculateParam.getIds());
// salaryCheckResultService.check(salaryAcctCheckParam, true, simpleEmployee);
// Thread.sleep(10);
getSalaryAcctProgressService ( user ) . finish ( SalaryCacheKey . AFTER_TAXA_CCT_PROGRESS + salaryAcctRecordId , true ) ;
// 记录日志
// 查询操作日志的targetName
String targetName = getSalaryAcctRecordService ( user ) . getLogTargetNameById ( salaryAcctRecordId ) ;
LoggerContext < SalaryCheckResultPO > loggerContext = new LoggerContext < > ( ) ;
loggerContext . setUser ( user ) ;
loggerContext . setTargetId ( String . valueOf ( salaryAcctRecordId ) ) ;
loggerContext . setTargetName ( targetName ) ;
loggerContext . setOperateType ( OperateTypeEnum . UPDATE . getValue ( ) ) ;
loggerContext . setOperateTypeName ( SalaryI18nUtil . getI18nLabel ( 0 , " 核算税后薪资 " ) ) ;
loggerContext . setOperatedesc ( SalaryI18nUtil . getI18nLabel ( 0 , " 核算税后薪资 " ) ) ;
SalaryElogConfig . salaryAcctRecordLoggerTemplate . write ( loggerContext ) ;
} catch ( Exception e ) {
log . info ( " 核算税后薪资出错:{} " , e . getMessage ( ) , e ) ;
getSalaryAcctProgressService ( user ) . fail ( SalaryCacheKey . AFTER_TAXA_CCT_PROGRESS + salaryAcctRecordId , SalaryI18nUtil . getI18nLabel ( 99642 , " 薪资核算出错 " ) + " : " + e . getMessage ( ) ) ;
} finally {
// 数据库字段加密用
}
}
2023-09-07 15:15:59 +08:00
@NotNull
private List < Long > sortItems ( List < SalarySobItemPO > salarySobItemPOS , List < SalarySobBackItemPO > salarySobBackItems , List < SalaryItemPO > salaryItemPOS , List < ExpressFormula > expressFormulas ) {
List < SalarySobItemPO > temp = salarySobBackItems . stream ( )
. map ( e - > {
SalarySobItemPO salarySobItem = new SalarySobItemPO ( ) ;
BeanUtils . copyProperties ( e , salarySobItem ) ;
return salarySobItem ;
} ) . collect ( Collectors . toList ( ) ) ;
salarySobItemPOS . addAll ( temp ) ;
SalaryCalcItemGraph salaryCalcItemGraph = new SalaryCalcItemGraph ( salarySobItemPOS , salaryItemPOS , expressFormulas ) ;
List < SalaryCalcItem > salaryCalcItems = salaryCalcItemGraph . sort ( ) ;
return SalaryEntityUtil . properties ( salaryCalcItems , SalaryCalcItem : : getSalaryItemId , Collectors . toList ( ) ) ;
}
/ * *
* 获取回算变量
*
* @param salarySobBackItems
* @return
* /
@NotNull
private Set < String > getIssuedFieldIds ( List < SalarySobBackItemPO > salarySobBackItems ) {
Set < String > issuedFieldIds ;
Set < Long > issuedFormulaIds = SalaryEntityUtil . properties ( salarySobBackItems , SalarySobBackItemPO : : getFormulaId ) ;
List < ExpressFormula > expressFormulas1 = getSalaryFormulaService ( user ) . listExpressFormula ( issuedFormulaIds ) ;
List < FormulaVar > issuedFormulaVars = new ArrayList < > ( ) ;
expressFormulas1 . forEach ( f - > issuedFormulaVars . addAll ( f . getParameters ( ) ) ) ;
issuedFieldIds = issuedFormulaVars . stream ( )
. map ( FormulaVar : : getFieldId )
. filter ( StringUtils : : isNotBlank )
. filter ( v - > v . startsWith ( SalaryFormulaReferenceEnum . ISSUED . getValue ( ) + " _ " ) )
. map ( SALARY_PATTERN : : matcher )
. filter ( Matcher : : find )
. map ( m - > m . group ( 2 ) )
. collect ( Collectors . toSet ( ) ) ;
return issuedFieldIds ;
}
2022-04-08 19:08:59 +08:00
/ * *
* 处理薪资核算临时存储表中的数据
*
* @param calculateParam
* @param calculateKey
* /
2022-04-11 20:17:47 +08:00
private void handleSalaryAcctResultTemp ( SalaryAcctCalculateParam calculateParam , String calculateKey ) {
2023-09-26 17:35:23 +08:00
StopWatch sw = new StopWatch ( calculateParam . getSalaryAcctRecordId ( ) + " " ) ;
2022-04-29 17:15:22 +08:00
// 查询薪资核算结果的临时存储
2023-09-26 17:18:27 +08:00
sw . start ( " 处理核算数据,查询薪资核算结果的临时存储 " ) ;
2022-04-29 17:15:22 +08:00
List < SalaryAcctResultTempPO > salaryAcctResultTempPOS = getSalaryAcctResultTempService ( user ) . listByCalculateKey ( calculateKey ) ;
2023-09-26 17:18:27 +08:00
sw . stop ( ) ;
2022-04-29 17:15:22 +08:00
// 删除原来的薪资核算结果
2023-09-26 17:18:27 +08:00
sw . start ( " 处理核算数据,删除原来的薪资核算结果 " ) ;
2022-04-29 17:15:22 +08:00
if ( CollectionUtils . isNotEmpty ( calculateParam . getIds ( ) ) ) {
getSalaryAcctResultMapper ( ) . deleteBySalaryAcctEmpIds ( calculateParam . getIds ( ) ) ;
} else {
getSalaryAcctResultMapper ( ) . deleteBySalaryAcctRecordIds ( Collections . singleton ( calculateParam . getSalaryAcctRecordId ( ) ) ) ;
2022-07-11 17:31:33 +08:00
getSalaryAcctReportService ( user ) . deleteBySalaryAcctRecordId ( calculateParam . getSalaryAcctRecordId ( ) ) ;
2022-04-29 17:15:22 +08:00
}
2023-09-26 17:18:27 +08:00
sw . stop ( ) ;
2022-04-29 17:15:22 +08:00
// 保存薪资的薪资核算结果
2023-09-26 17:18:27 +08:00
sw . start ( " 处理核算数据,保存薪资的薪资核算结果 " ) ;
2022-04-29 17:15:22 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = SalaryAcctResultBO . convert2ResultPO ( salaryAcctResultTempPOS ) ;
batchSave ( salaryAcctResultPOS ) ;
2023-09-26 17:18:27 +08:00
sw . stop ( ) ;
2022-04-29 17:15:22 +08:00
// 删除薪资核算临时存储表中的数据
2023-09-26 17:18:27 +08:00
sw . start ( " 处理核算数据,删除薪资核算临时存储表中的数据 " ) ;
2022-04-29 17:15:22 +08:00
getSalaryAcctResultTempService ( user ) . deleteByCalculateKey ( calculateKey ) ;
2023-09-26 17:18:27 +08:00
sw . stop ( ) ;
log . info ( sw . prettyPrint ( ) ) ;
2022-04-11 20:17:47 +08:00
}
2022-06-07 19:10:40 +08:00
2024-07-17 09:03:31 +08:00
private void handleSalaryAfterTaxAcctResultTemp ( Long salaryAcctRecordId , String calculateKey , List < Long > afterTaxItemIds ) {
// 查询薪资核算结果的临时存储
List < SalaryAcctResultTempPO > salaryAcctResultTempPOS = getSalaryAcctResultTempService ( user ) . listByCalculateKey ( calculateKey ) ;
// 删除原来的薪资核算结果
getSalaryAcctResultMapper ( ) . deleteBySalaryAcctRecordIdAndSalaryItemIds ( salaryAcctRecordId , afterTaxItemIds ) ;
// 保存薪资的薪资核算结果
List < SalaryAcctResultPO > salaryAcctResultPOS = SalaryAcctResultBO . convert2ResultPO ( salaryAcctResultTempPOS ) ;
batchSave ( salaryAcctResultPOS ) ;
// 删除薪资核算临时存储表中的数据
getSalaryAcctResultTempService ( user ) . deleteByCalculateKey ( calculateKey ) ;
}
2022-06-07 19:10:40 +08:00
@Override
public List < SalaryAcctResultPO > listBySalaryAcctRecordIdsAndTaxAgentIds ( Collection < Long > salaryAcctRecordIds , Collection < Long > taxAgentIds ) {
if ( CollectionUtils . isEmpty ( salaryAcctRecordIds ) ) {
return Collections . emptyList ( ) ;
}
2023-09-26 17:18:27 +08:00
return encryptUtil . decryptList ( getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctRecordIds ( salaryAcctRecordIds ) . taxAgentIds ( taxAgentIds ) . build ( ) ) , SalaryAcctResultPO . class ) ;
2022-06-07 19:10:40 +08:00
}
2022-11-17 09:28:40 +08:00
// /**
// * 查询薪资核算人员
// *
// * @param queryParam
// * @param salaryAcctRecord
// * @return
// */
// private List<SalaryAcctEmployeePO> querySalaryAcctEmployee(SalaryAcctResultListContext salaryAcctResultListContext, SalaryAcctResultQueryParam queryParam, SalaryAcctRecordPO salaryAcctRecord) {
// // 构建薪资核算人员的查询参数
// SalaryAcctEmployeeQueryParam salaryAcctEmployeeListQueryParam = new SalaryAcctEmployeeQueryParam();
// BeanUtils.copyProperties(queryParam, salaryAcctEmployeeListQueryParam);
// // 查询薪资核算人员
// List<SalaryAcctEmployeePO> salaryAcctEmployees = getSalaryAcctEmployeeService(user).listByParam(salaryAcctEmployeeListQueryParam);
// // 查询相同税款所属期内的薪资核算人员
// List<SalaryAcctEmployeePO> sameTaxCycleSalaryAcctEmployees = salaryAcctEmployeeService
// .listSameTaxCycle(salaryAcctEmployees, SalaryDateUtil.getFormatYearMonth(salaryAcctRecord.getTaxCycle()));
// Set<String> sameTaxCycleKeySet = SalaryEntityUtil.properties(sameTaxCycleSalaryAcctEmployees, o -> o.getEmployeeId() + "-" + o.getTaxAgentId());
// salaryAcctResultListContext.setSameTaxCycleKeySet(sameTaxCycleKeySet);
// // 过滤合并计税的人员
// if (StringUtils.isNotEmpty(queryParam.getConsolidatedTaxation())) {
// salaryAcctEmployees = salaryAcctEmployees.stream()
// .filter(salaryAcctEmployeePO -> sameTaxCycleKeySet.contains(salaryAcctEmployeePO.getEmployeeId() + "-" + salaryAcctEmployeePO.getTaxAgentId()))
// .collect(Collectors.toList());
// }
// // 根据权限过滤
// return salaryAcctEmployeeService.filterByAuthority(salaryAcctEmployees, employeeId);
// }
2024-10-17 18:27:37 +08:00
2022-11-17 09:28:40 +08:00
@Override
2024-10-17 18:27:37 +08:00
public void lock ( SalaryAcctResultLockParam param ) {
ValidUtil . doValidator ( param ) ;
SalaryAcctEmployeePO salaryAcctEmployeePO = getSalaryAcctEmployeeService ( user ) . getById ( param . getAcctEmpId ( ) ) ;
if ( salaryAcctEmployeePO = = null ) {
return ;
2022-11-17 09:28:40 +08:00
}
2024-10-17 18:27:37 +08:00
List < Long > lockItemIds = salaryAcctEmployeePO . getLockItems ( ) = = null ? new ArrayList < > ( ) : salaryAcctEmployeePO . getLockItems ( ) ;
Long salaryItemId = param . getSalaryItemId ( ) ;
if ( param . getLockStatus ( ) = = LockStatusEnum . LOCK ) {
lockItemIds . add ( salaryItemId ) ;
} else {
2024-10-18 16:49:17 +08:00
lockItemIds . removeIf ( salaryItemId : : equals ) ;
2022-11-17 09:28:40 +08:00
}
2024-10-17 18:27:37 +08:00
2024-10-18 16:49:17 +08:00
salaryAcctEmployeePO . setLockItems ( Lists . newArrayList ( new HashSet ( lockItemIds ) ) ) ;
2024-10-17 18:27:37 +08:00
getSalaryAcctEmployeeService ( user ) . lock ( salaryAcctEmployeePO ) ;
}
@Override
public void updateLockStatusByParam ( SalaryAcctResultUpdateLockStatusParam updateParam ) {
2022-11-17 09:28:40 +08:00
List < SalaryAcctEmployeePO > salaryAcctEmployees = getSalaryAcctEmployeeService ( user ) . listBySalaryAcctRecordId ( updateParam . getSalaryAcctRecordId ( ) ) ;
if ( CollectionUtils . isEmpty ( salaryAcctEmployees ) ) {
return ;
}
2023-05-11 10:51:43 +08:00
Set < Long > salaryItemIds ;
2023-09-07 15:15:59 +08:00
if ( CollectionUtils . isNotEmpty ( updateParam . getSalaryItemIds ( ) ) ) {
2023-05-11 10:51:43 +08:00
salaryItemIds = updateParam . getSalaryItemIds ( ) ;
2023-09-07 15:15:59 +08:00
} else {
2023-05-11 10:51:43 +08:00
salaryItemIds = Collections . singleton ( updateParam . getSalaryItemId ( ) ) ;
}
2024-10-17 18:27:37 +08:00
salaryAcctEmployees . forEach ( salaryAcctEmployeePO - > {
List < Long > lockItemIds = salaryAcctEmployeePO . getLockItems ( ) = = null ? new ArrayList < > ( ) : salaryAcctEmployeePO . getLockItems ( ) ;
if ( updateParam . getLockStatus ( ) = = LockStatusEnum . LOCK ) {
lockItemIds . addAll ( salaryItemIds ) ;
} else {
lockItemIds . removeAll ( salaryItemIds ) ;
}
2024-10-18 16:49:17 +08:00
salaryAcctEmployeePO . setLockItems ( Lists . newArrayList ( new HashSet ( lockItemIds ) ) ) ;
2024-10-17 18:27:37 +08:00
getSalaryAcctEmployeeService ( user ) . lock ( salaryAcctEmployeePO ) ;
} ) ;
2022-11-17 09:28:40 +08:00
}
2022-12-02 17:35:14 +08:00
@Override
public void reCalc ( Long id ) {
// 无需解密
SalaryAcctResultPO build = SalaryAcctResultPO . builder ( ) . salaryAcctRecordId ( id ) . deleteType ( 0 ) . build ( ) ;
List < SalaryAcctResultPO > salaryAcctResultPOS = getSalaryAcctResultMapper ( ) . listSome ( build ) ;
// 回算前的薪资核算结果
2023-09-26 17:18:27 +08:00
salaryAcctResultPOS . forEach ( salaryAcctResult - > salaryAcctResult . setOriginResultValue ( salaryAcctResult . getResultValue ( ) ) ) ;
2022-12-02 17:35:14 +08:00
// 批量更新
batchUpdateOriginResultValue ( salaryAcctResultPOS ) ;
}
2022-12-06 15:29:08 +08:00
@Override
public List < SalaryAcctResultPO > listBySalaryAcctRecordIdsAndSalaryItemIds ( Collection < Long > salaryAcctRecordIds , Collection < Long > salaryItemIds ) {
2023-05-04 11:56:34 +08:00
if ( CollectionUtils . isEmpty ( salaryAcctRecordIds ) | | CollectionUtils . isEmpty ( salaryItemIds ) ) {
2022-12-06 15:29:08 +08:00
return Collections . emptyList ( ) ;
}
2023-04-04 17:29:56 +08:00
List < SalaryAcctResultPO > list = getSalaryAcctResultMapper ( ) . listSome ( SalaryAcctResultPO . builder ( ) . salaryAcctRecordIds ( salaryAcctRecordIds ) . salaryItemIds ( salaryItemIds ) . build ( ) ) ;
2023-05-04 11:56:34 +08:00
return encryptUtil . decryptList ( list , SalaryAcctResultPO . class ) ;
2022-12-06 15:29:08 +08:00
}
2022-12-26 23:17:32 +08:00
@Override
2023-06-28 16:26:20 +08:00
public List < SalaryAcctResultPO > listByAcctEmployeeIdsAndSalaryItemIds ( List < Long > salaryAcctEmployeeIds , Collection < Long > salaryItemIds ) {
2023-09-07 15:15:59 +08:00
if ( CollectionUtils . isEmpty ( salaryAcctEmployeeIds ) ) {
2023-06-20 17:27:18 +08:00
return Collections . emptyList ( ) ;
}
2024-10-18 16:54:34 +08:00
List < List < Long > > partition = Lists . partition ( salaryAcctEmployeeIds , 200 ) ;
2023-06-20 17:27:18 +08:00
List < SalaryAcctResultPO > result = new ArrayList < > ( ) ;
partition . forEach ( empIds - > {
SalaryAcctResultPO build = SalaryAcctResultPO . builder ( ) . salaryAcctEmpIds ( empIds ) . salaryItemIds ( salaryItemIds ) . build ( ) ;
result . addAll ( getSalaryAcctResultMapper ( ) . listSome ( build ) ) ;
} ) ;
2022-12-26 23:17:32 +08:00
// 数据解密
2023-06-20 17:27:18 +08:00
encryptUtil . decryptList ( result , SalaryAcctResultPO . class ) ;
return result ;
2022-12-26 23:17:32 +08:00
}
2022-12-02 17:35:14 +08:00
@Override
public void batchUpdateOriginResultValue ( List < SalaryAcctResultPO > salaryAcctResultValues ) {
2022-12-15 11:32:32 +08:00
int batchSize = 500 ;
2022-12-02 17:35:14 +08:00
List < List < SalaryAcctResultPO > > partition = Lists . partition ( salaryAcctResultValues , batchSize ) ;
for ( List < SalaryAcctResultPO > subSalaryAcctResultValues : partition ) {
getSalaryAcctResultMapper ( ) . batchUpdateOriginResultValue ( subSalaryAcctResultValues ) ;
}
}
2023-06-20 17:27:18 +08:00
@Override
public List < Long > listAcctEmpIdByAcctEmpId ( List < Long > salaryAcctEmployeeIds ) {
2023-09-07 15:15:59 +08:00
if ( CollectionUtils . isEmpty ( salaryAcctEmployeeIds ) ) {
2023-06-20 17:27:18 +08:00
return Collections . emptyList ( ) ;
}
2023-09-07 15:15:59 +08:00
List < List < Long > > partition = Lists . partition ( ( List < Long > ) salaryAcctEmployeeIds , 1000 ) ;
2023-06-20 17:27:18 +08:00
List < Long > result = new ArrayList < > ( ) ;
partition . forEach ( empIds - > {
result . addAll ( getSalaryAcctResultMapper ( ) . getAcctEmpIsExist ( empIds ) ) ;
} ) ;
return result ;
}
2023-06-27 14:58:33 +08:00
@Override
public Boolean checkAuth ( Long salaryAcctRecordId ) {
// 获取该核算记录的个税扣缴义务
2024-09-03 15:48:20 +08:00
// SalaryAcctRecordPO recordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
// if (Objects.isNull(recordPO)) {
// return false;
// }
// SalarySobPO salarySobPO = getSalarySobService(user).getById(recordPO.getSalarySobId());
// Long taxAgentId = salarySobPO.getTaxAgentId();
// List<TaxAgentAdminPO> adminTaxAgentList = getTaxAgentAdminService(user).listByEmployeeId((long) user.getUID());
// Optional<TaxAgentAdminPO> canOperate = adminTaxAgentList.stream().filter(po -> NumberUtils.compare(taxAgentId, po.getTaxAgentId()) == 0).findFirst();
// if (!canOperate.isPresent()) {
// return false;
// }
2023-06-27 14:58:33 +08:00
return true ;
}
2023-12-05 14:57:34 +08:00
@Override
2023-12-06 16:05:08 +08:00
public void batchUpdate ( SalaryAcctResultBatchUpdateParam param ) {
2023-12-05 14:57:34 +08:00
ValidUtil . doValidator ( param ) ;
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService ( user ) . getById ( param . getSalaryAcctRecordId ( ) ) ;
2024-04-01 20:25:23 +08:00
if ( salaryAcctRecordPO = = null ) {
2023-12-05 14:57:34 +08:00
throw new SalaryRunTimeException ( " 薪资核算记录不存在,或已被删除 " ) ;
}
List < SalarySobItemPO > salarySobItemPOS = getSalarySobItemService ( user ) . listBySalarySobId ( salaryAcctRecordPO . getSalarySobId ( ) ) ;
// 薪资账套中包含的薪资项目
List < Long > salarySobItemIds = salarySobItemPOS . stream ( ) . map ( SalarySobItemPO : : getSalaryItemId ) . collect ( Collectors . toList ( ) ) ;
if ( ! salarySobItemIds . contains ( param . getSalaryItemId ( ) ) ) {
throw new SalaryRunTimeException ( " 该账套不包含该薪资项目或已被删除,请先检查账套 " ) ;
}
// 获取需要更新的核算人员信息
2023-12-06 16:05:08 +08:00
List < SalaryAcctEmployeePO > salaryAcctEmployeePOList = new ArrayList < > ( ) ;
if ( CollectionUtils . isEmpty ( param . getIdList ( ) ) ) {
2023-12-05 14:57:34 +08:00
// 没有选择核算人员,更新核算记录中所有人员
salaryAcctEmployeePOList . addAll ( getSalaryAcctEmployeeService ( user ) . listBySalaryAcctRecordId ( salaryAcctRecordPO . getId ( ) ) ) ;
} else {
2023-12-06 16:05:08 +08:00
salaryAcctEmployeePOList . addAll ( getSalaryAcctEmployeeService ( user ) . listByIds ( param . getIdList ( ) ) ) ;
2023-12-05 14:57:34 +08:00
}
if ( CollectionUtils . isNotEmpty ( salaryAcctEmployeePOList ) ) {
List < Long > salaryAcctEmployeeIdList = SalaryEntityUtil . properties ( salaryAcctEmployeePOList , SalaryAcctEmployeePO : : getId , Collectors . toList ( ) ) ;
// 查询薪资核算结果
List < SalaryAcctResultPO > resultPOS = listByAcctEmployeeIdsAndSalaryItemIds ( salaryAcctEmployeeIdList , Collections . singleton ( param . getSalaryItemId ( ) ) ) ;
Map < Long , SalaryAcctResultPO > salaryAcctResultPOMap = SalaryEntityUtil . convert2Map ( resultPOS , SalaryAcctResultPO : : getSalaryAcctEmpId ) ;
2023-12-06 16:05:08 +08:00
List < DataCollectionEmployee > dataCollectionEmployees = getSalaryEmployeeService ( user ) . listAllForReport ( ) ;
Map < Long , DataCollectionEmployee > emps = SalaryEntityUtil . convert2Map ( dataCollectionEmployees , DataCollectionEmployee : : getEmployeeId ) ;
2023-12-05 14:57:34 +08:00
List < SalaryAcctResultPO > needUpdateList = new ArrayList < > ( ) ;
List < SalaryAcctResultPO > needInsertList = new ArrayList < > ( ) ;
Date now = new Date ( ) ;
2023-12-06 16:05:08 +08:00
List < SalaryAcctResultReportPO > salaryAcctResultReportPOS = new ArrayList < > ( ) ;
2023-12-05 14:57:34 +08:00
salaryAcctEmployeePOList . forEach ( salaryAcctEmployeePO - > {
if ( salaryAcctResultPOMap . containsKey ( salaryAcctEmployeePO . getId ( ) ) ) {
// 更新
SalaryAcctResultPO po = salaryAcctResultPOMap . get ( salaryAcctEmployeePO . getId ( ) ) ;
po . setResultValue ( param . getValue ( ) ) ;
po . setUpdateTime ( now ) ;
needUpdateList . add ( po ) ;
} else {
// 新增
needInsertList . add ( SalaryAcctResultPO . builder ( )
. salarySobId ( salaryAcctRecordPO . getSalarySobId ( ) )
. salaryItemId ( param . getSalaryItemId ( ) )
. salaryAcctRecordId ( param . getSalaryAcctRecordId ( ) )
. salaryAcctEmpId ( salaryAcctEmployeePO . getId ( ) )
. employeeId ( salaryAcctEmployeePO . getEmployeeId ( ) )
. taxAgentId ( salaryAcctEmployeePO . getTaxAgentId ( ) )
2023-12-06 16:05:08 +08:00
. resultValue ( param . getValue ( ) )
2023-12-05 14:57:34 +08:00
. originResultValue ( " " )
. creator ( Long . valueOf ( user . getUID ( ) ) )
. createTime ( now )
. updateTime ( now )
. deleteType ( NumberUtils . INTEGER_ZERO )
. tenantKey ( SalaryDefaultTenantConstant . DEFAULT_TENANT_KEY )
. build ( ) ) ;
}
2023-12-06 16:05:08 +08:00
// 报表
2024-10-17 14:07:27 +08:00
// SalaryAcctResultReportPO po = SalaryAcctResultReportPO.builder()
// .id(IdGenerator.generate())
// .salarySobId(salaryAcctRecordPO.getSalarySobId())
// .salaryItemId(param.getSalaryItemId())
// .salaryAcctRecordId(param.getSalaryAcctRecordId())
// .salaryAcctEmpId(salaryAcctEmployeePO.getId().toString())
// .employeeId(salaryAcctEmployeePO.getEmployeeId().toString())
// .taxAgentId(salaryAcctEmployeePO.getTaxAgentId())
// .resultValue(param.getValue())
// .creator(Long.valueOf(user.getUID()))
// .createTime(now)
// .updateTime(now)
// .deleteType(NumberUtils.INTEGER_ZERO)
// .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
// .build();
// DataCollectionEmployee dataCollectionEmployee = emps.get(salaryAcctEmployeePO.getEmployeeId());
// if (dataCollectionEmployee != null) {
// po.setDepartmentId(dataCollectionEmployee.getDepartmentId());
// po.setSubcompanyId(dataCollectionEmployee.getSubcompanyid());
// po.setCostcenterId(dataCollectionEmployee.getCostcenterId());
// po.setJobtitleId(dataCollectionEmployee.getJobtitleId());
// po.setLocationId(dataCollectionEmployee.getLocationId());
// }
// salaryAcctResultReportPOS.add(po);
2023-12-05 14:57:34 +08:00
} ) ;
2023-12-06 16:05:08 +08:00
2023-12-05 14:57:34 +08:00
// 入库
if ( CollectionUtils . isNotEmpty ( needUpdateList ) ) {
2023-12-06 15:55:47 +08:00
// 数据加密
encryptUtil . encryptList ( needUpdateList , SalaryAcctResultPO . class ) ;
List < List < SalaryAcctResultPO > > partition = Lists . partition ( needUpdateList , 100 ) ;
partition . forEach ( getSalaryAcctResultMapper ( ) : : batchUpdate ) ;
2023-12-05 14:57:34 +08:00
}
2023-12-06 15:55:47 +08:00
batchSave ( needInsertList ) ;
2023-12-06 16:05:08 +08:00
// 报表入库前先删除
2024-10-17 14:07:27 +08:00
// getSalaryAcctReportService(user).deleteByAcctEmployeeIdsAndSalaryItemIds(param.getIdList(), Collections.singletonList(param.getSalaryItemId()));
// getSalaryAcctReportService(user).batchSave(salaryAcctResultReportPOS);
2023-12-06 16:05:08 +08:00
2023-12-05 14:57:34 +08:00
}
}
2024-06-20 10:39:40 +08:00
2025-02-17 15:54:35 +08:00
@Override
public List < SalaryAcctResultPO > listBySobSalaryMonth ( Date salaryMonth , Long salarySobId , List < Long > employeeIds ) {
List < SalaryAcctRecordPO > salaryAcctRecordPOS = getSalaryAcctRecordService ( user ) . listSome ( SalaryAcctRecordPO . builder ( ) . salarySobId ( salarySobId ) . salaryMonth ( salaryMonth ) . build ( ) ) ;
List < Long > recordIds = SalaryEntityUtil . properties ( salaryAcctRecordPOS , SalaryAcctRecordPO : : getId , Collectors . toList ( ) ) ;
2025-02-19 10:07:01 +08:00
if ( CollUtil . isEmpty ( recordIds ) ) {
2025-02-17 16:34:35 +08:00
return new ArrayList < > ( ) ;
}
2025-02-19 10:07:01 +08:00
List < SalaryAcctResultPO > salaryAcctResultPOS = new ArrayList < > ( ) ;
2025-02-17 15:54:35 +08:00
SalaryAcctResultPO resultParam = SalaryAcctResultPO . builder ( ) . salaryAcctRecordIds ( recordIds ) . build ( ) ;
2025-02-19 10:07:01 +08:00
if ( CollUtil . isNotEmpty ( employeeIds ) ) {
List < List < Long > > partition = Lists . partition ( employeeIds , 500 ) ;
for ( List < Long > ids : partition ) {
resultParam . setEmployeeIds ( ids ) ;
List < SalaryAcctResultPO > acctResultPOS = getSalaryAcctResultMapper ( ) . listSome ( resultParam ) ;
salaryAcctResultPOS . addAll ( acctResultPOS ) ;
}
} else {
salaryAcctResultPOS = getSalaryAcctResultMapper ( ) . listSome ( resultParam ) ;
2025-02-17 15:54:35 +08:00
}
encryptUtil . decryptList ( salaryAcctResultPOS , SalaryAcctResultPO . class ) ;
return salaryAcctResultPOS ;
}
2025-03-26 15:48:02 +08:00
2024-06-20 10:39:40 +08:00
@Override
public void writeBatchLog ( SalaryAcctRecordPO salaryAcctRecord ,
Map < String , String > newResultValueMap ,
SalaryLogOperateTypeEnum operateType ) {
LoggerContext < Map < String , String > > context = new LoggerContext < > ( ) ;
context . setUser ( user ) ;
context . setTargetId ( salaryAcctRecord . getId ( ) . toString ( ) ) ;
2024-07-17 09:03:31 +08:00
context . setTargetName ( SalaryI18nUtil . getI18nLabel ( 268573 , " 全部人员 " ) ) ;
context . setOperator ( user . getUID ( ) + " " ) ;
2024-06-20 10:39:40 +08:00
context . setOperateType ( operateType . getValue ( ) ) ;
context . setOperateTypeName ( operateType . getDefaultLabel ( ) ) ;
context . setGroupId ( SalaryLogGroupTypeEnum . SALARY_ACCT_RESULT_VALUE . getValue ( ) ) ;
context . setGroupNameLabel ( SalaryLogGroupTypeEnum . SALARY_ACCT_RESULT_VALUE . getLabelId ( ) . toString ( ) ) ;
context . setNewValues ( newResultValueMap ) ;
SalaryElogConfig . salaryAcctRecordLoggerTemplate . write ( context ) ;
}
2025-08-06 18:09:19 +08:00
/ * *
* 联特 - 生成部门社保明细表
* @param salaryMonth
* @return
* /
@Override
public String ltGenBmsbmxb ( String salaryMonth ) {
if ( ! SalaryDateUtil . checkYearMonth ( salaryMonth ) ) {
throw new SalaryRunTimeException ( " 年月错误 " ) ;
}
YearMonth yearMonth = SalaryDateUtil . String2YearMonth ( salaryMonth ) ;
// 查询需要生成哪些浮动薪资项目
BaseBean baseBean = new BaseBean ( ) ;
String configStr = baseBean . getPropValue ( " ltSalaryReport " , " bmsbmxb_ys_config " ) ;
List < LtSalaryReportConfigDTO > configs = JsonUtil . parseList ( configStr , LtSalaryReportConfigDTO . class ) ;
List < Long > variableItemIds = configs . stream ( ) . map ( LtSalaryReportConfigDTO : : getItem ) . collect ( Collectors . toList ( ) ) ;
// 获取浮动档案
List < Map < String , Object > > variableMapList = getVariableArchiveService ( user ) . listBySalaryMonthAndItems ( yearMonth , variableItemIds ) ;
// 过滤数据, 不能所有值为0或空
List < String > keyList = configs . stream ( ) . map ( dto - > dto . getItem ( ) + " _variableItem " ) . collect ( Collectors . toList ( ) ) ;
variableMapList = variableMapList . stream ( ) . filter ( map - > {
for ( String key : keyList ) {
String val = Utils . null2String ( map . get ( key ) ) ;
if ( StringUtils . isNotBlank ( val ) & & NumberUtils . isCreatable ( val ) & & new BigDecimal ( val ) . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
return true ;
}
}
return false ;
} ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( variableMapList ) ) {
return null ;
}
log . info ( " 部门社保明细表size{} " , variableMapList . size ( ) ) ;
// 获取人员信息
List < Long > empIds = variableMapList . stream ( ) . map ( map - > Utils . null2String ( map . get ( " employeeId " ) ) ) . filter ( NumberUtils : : isCreatable ) . map ( Long : : valueOf ) . collect ( Collectors . toList ( ) ) ;
// Map<Long, DataCollectionEmployee> employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).listByIds(empIds), DataCollectionEmployee::getEmployeeId);
// 查询快照表中人员信息
Map < Long , DataCollectionEmployee > employeeMap = SalaryEntityUtil . convert2Map ( getSalaryEmployeeService ( user ) . snapshot ( empIds , SalaryDateUtil . localDateToDate ( yearMonth . atDay ( 1 ) ) ) , DataCollectionEmployee : : getEmployeeId ) ;
// 删除建模数据
RecordSet rs = new RecordSet ( ) ;
rs . execute ( " delete from uf_bmsbmxb where xzszy = ' " + salaryMonth + " ' " ) ;
// 插入建模
String currDate = String . format ( " '%s' " , TimeUtil . getCurrentDateString ( ) ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( " HH:mm:ss " ) ;
String currTime = String . format ( " '%s' " , sdf . format ( new Date ( ) ) ) ;
// 获取建模模块id
String modeId = baseBean . getPropValue ( " ltSalaryReport " , " bmsbmxb_mode_id " ) ;
// 先插入一条数据
Map < String , Object > firstData = variableMapList . get ( 0 ) ;
StringBuilder firstSb = new StringBuilder ( ) ;
String fieldStr = configs . stream ( ) . map ( LtSalaryReportConfigDTO : : getField ) . collect ( Collectors . joining ( " , " ) ) ;
DataCollectionEmployee employee = employeeMap . getOrDefault ( firstData . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
firstSb . append ( " insert into uf_bmsbmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx, " + fieldStr + " ) values ( " ) ;
firstSb . append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employee . getWorkcode ( ) ) . append ( " ', " )
. append ( employee . getEmployeeId ( ) ) . append ( " , " )
. append ( employee . getDepartmentId ( ) ) . append ( " , " )
. append ( employee . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employee . getLtCbzx ( ) ) ) . append ( " ' " ) ;
for ( LtSalaryReportConfigDTO dto : configs ) {
String val = Utils . null2String ( firstData . get ( Utils . null2String ( dto . getItem ( ) ) + " _variableItem " ) ) ;
firstSb . append ( " , " ) . append ( NumberUtils . isCreatable ( val ) ? val : 0 ) ;
}
firstSb . append ( " ) " ) ;
rs . execute ( firstSb . toString ( ) ) ;
variableMapList . remove ( 0 ) ;
// 获取最大值 作为权限重构的起始id
rs . execute ( " select max(id) from uf_bmsbmxb " ) ;
int minId = 0 ;
if ( rs . next ( ) ) {
minId = rs . getInt ( 1 ) ;
}
int maxId = minId + variableMapList . size ( ) ;
List < List < Map < String , Object > > > partition = Lists . partition ( variableMapList , 500 ) ;
partition . forEach ( part - > {
StringBuilder sb = new StringBuilder ( ) ;
sb . append ( " insert into uf_bmsbmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx, " + fieldStr + " ) values " ) ;
for ( Map < String , Object > data : part ) {
DataCollectionEmployee employeePo = employeeMap . getOrDefault ( data . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
sb . append ( " ( " )
. append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employeePo . getWorkcode ( ) ) . append ( " ', " )
. append ( employeePo . getEmployeeId ( ) ) . append ( " , " )
. append ( employeePo . getDepartmentId ( ) ) . append ( " , " )
. append ( employeePo . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employeePo . getLtCbzx ( ) ) ) . append ( " ' " ) ;
for ( LtSalaryReportConfigDTO dto : configs ) {
String val = Utils . null2String ( data . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) + " _variableItem " , " " ) ) ;
sb . append ( " , " ) . append ( NumberUtils . isCreatable ( val ) ? val : 0 ) ;
}
sb . append ( " ), " ) ;
}
rs . execute ( sb . substring ( 0 , sb . length ( ) - 1 ) . toString ( ) ) ;
} ) ;
// 权限重构
log . info ( " 部门社保明细表min{} max{} " , minId , maxId ) ;
if ( modeId ! = null & & NumberUtils . isCreatable ( modeId ) ) {
Integer modeIdValue = Integer . valueOf ( modeId ) ;
for ( int i = minId ; i < = maxId ; i + + ) {
ModeRightInfo ModeRightInfo = new ModeRightInfo ( ) ;
ModeRightInfo . setNewRight ( true ) ;
ModeRightInfo . editModeDataShare ( 1 , modeIdValue , i ) ;
}
}
return " success " ;
}
@Override
public String ltGenBmgjjmxb ( String salaryMonth ) {
if ( ! SalaryDateUtil . checkYearMonth ( salaryMonth ) ) {
throw new SalaryRunTimeException ( " 年月错误 " ) ;
}
YearMonth yearMonth = SalaryDateUtil . String2YearMonth ( salaryMonth ) ;
// 查询需要生成哪些浮动薪资项目
BaseBean baseBean = new BaseBean ( ) ;
String configStr = baseBean . getPropValue ( " ltSalaryReport " , " bmgjjmxb_ys_config " ) ;
List < LtSalaryReportConfigDTO > configs = JsonUtil . parseList ( configStr , LtSalaryReportConfigDTO . class ) ;
List < Long > variableItemIds = configs . stream ( ) . map ( LtSalaryReportConfigDTO : : getItem ) . collect ( Collectors . toList ( ) ) ;
// 获取浮动档案
List < Map < String , Object > > variableMapList = getVariableArchiveService ( user ) . listBySalaryMonthAndItems ( yearMonth , variableItemIds ) ;
// 过滤数据, 不能所有值为0或空
List < String > keyList = configs . stream ( ) . map ( dto - > dto . getItem ( ) + " _variableItem " ) . collect ( Collectors . toList ( ) ) ;
variableMapList = variableMapList . stream ( ) . filter ( map - > {
for ( String key : keyList ) {
String val = Utils . null2String ( map . get ( key ) ) ;
if ( StringUtils . isNotBlank ( val ) & & NumberUtils . isCreatable ( val ) & & new BigDecimal ( val ) . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
return true ;
}
}
return false ;
} ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( variableMapList ) ) {
return null ;
}
log . info ( " 部门公积金明细size{} " , variableMapList . size ( ) ) ;
// 获取人员信息
List < Long > empIds = variableMapList . stream ( ) . map ( map - > Utils . null2String ( map . get ( " employeeId " ) ) ) . filter ( NumberUtils : : isCreatable ) . map ( Long : : valueOf ) . collect ( Collectors . toList ( ) ) ;
// Map<Long, DataCollectionEmployee> employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).listByIds(empIds), DataCollectionEmployee::getEmployeeId);
// 查询快照表中人员信息
Map < Long , DataCollectionEmployee > employeeMap = SalaryEntityUtil . convert2Map ( getSalaryEmployeeService ( user ) . snapshot ( empIds , SalaryDateUtil . localDateToDate ( yearMonth . atDay ( 1 ) ) ) , DataCollectionEmployee : : getEmployeeId ) ;
// 删除建模数据
RecordSet rs = new RecordSet ( ) ;
rs . execute ( " delete from uf_bmgjjmxb where xzszy = ' " + salaryMonth + " ' " ) ;
// 插入建模
String currDate = String . format ( " '%s' " , TimeUtil . getCurrentDateString ( ) ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( " HH:mm:ss " ) ;
String currTime = String . format ( " '%s' " , sdf . format ( new Date ( ) ) ) ;
// 获取建模模块id
String modeId = baseBean . getPropValue ( " ltSalaryReport " , " bmgjjmxb_mode_id " ) ;
// 先插入一条数据
Map < String , Object > firstData = variableMapList . get ( 0 ) ;
StringBuilder firstSb = new StringBuilder ( ) ;
String fieldStr = configs . stream ( ) . map ( LtSalaryReportConfigDTO : : getField ) . collect ( Collectors . joining ( " , " ) ) ;
DataCollectionEmployee employee = employeeMap . getOrDefault ( firstData . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
firstSb . append ( " insert into uf_bmgjjmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx, " + fieldStr + " ) values ( " ) ;
firstSb . append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employee . getWorkcode ( ) ) . append ( " ', " )
. append ( employee . getEmployeeId ( ) ) . append ( " , " )
. append ( employee . getDepartmentId ( ) ) . append ( " , " )
. append ( employee . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employee . getLtCbzx ( ) ) ) . append ( " ' " ) ;
for ( LtSalaryReportConfigDTO dto : configs ) {
String val = Utils . null2String ( firstData . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) + " _variableItem " , " " ) ) ;
firstSb . append ( " , " ) . append ( NumberUtils . isCreatable ( val ) ? val : 0 ) ;
}
firstSb . append ( " ) " ) ;
rs . execute ( firstSb . toString ( ) ) ;
variableMapList . remove ( 0 ) ;
// 获取最大值 作为权限重构的起始id
rs . execute ( " select max(id) from uf_bmgjjmxb " ) ;
int minId = 0 ;
if ( rs . next ( ) ) {
minId = rs . getInt ( 1 ) ;
}
int maxId = minId + variableMapList . size ( ) ;
List < List < Map < String , Object > > > partition = Lists . partition ( variableMapList , 500 ) ;
partition . forEach ( part - > {
StringBuilder sb = new StringBuilder ( ) ;
sb . append ( " insert into uf_bmgjjmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx, " + fieldStr + " ) values " ) ;
for ( Map < String , Object > data : part ) {
DataCollectionEmployee employeePo = employeeMap . getOrDefault ( data . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
sb . append ( " ( " )
. append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employeePo . getWorkcode ( ) ) . append ( " ', " )
. append ( employeePo . getEmployeeId ( ) ) . append ( " , " )
. append ( employeePo . getDepartmentId ( ) ) . append ( " , " )
. append ( employeePo . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employeePo . getLtCbzx ( ) ) ) . append ( " ' " ) ;
for ( LtSalaryReportConfigDTO dto : configs ) {
String val = Utils . null2String ( data . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) + " _variableItem " , " " ) ) ;
sb . append ( " , " ) . append ( NumberUtils . isCreatable ( val ) ? val : 0 ) ;
}
sb . append ( " ), " ) ;
}
rs . execute ( sb . substring ( 0 , sb . length ( ) - 1 ) . toString ( ) ) ;
} ) ;
// 权限重构
log . info ( " 部门公积金明细min{} max{} " , minId , maxId ) ;
if ( modeId ! = null & & NumberUtils . isCreatable ( modeId ) ) {
Integer modeIdValue = Integer . valueOf ( modeId ) ;
for ( int i = minId ; i < = maxId ; i + + ) {
ModeRightInfo ModeRightInfo = new ModeRightInfo ( ) ;
ModeRightInfo . setNewRight ( true ) ;
ModeRightInfo . editModeDataShare ( 1 , modeIdValue , i ) ;
}
}
return " success " ;
}
@Override
public String ltGenBmgzjjmxJt ( String salaryMonth ) {
if ( ! SalaryDateUtil . checkYearMonth ( salaryMonth ) ) {
throw new SalaryRunTimeException ( " 年月错误 " ) ;
}
YearMonth yearMonth = SalaryDateUtil . String2YearMonth ( salaryMonth ) ;
// 查询需要生成哪些浮动薪资项目
BaseBean baseBean = new BaseBean ( ) ;
String configStr = baseBean . getPropValue ( " ltSalaryReport " , " bmsbmxb_ys_config " ) ;
List < LtSalaryReportConfigDTO > configs = JsonUtil . parseList ( configStr , LtSalaryReportConfigDTO . class ) ;
String gjjConfigStr = baseBean . getPropValue ( " ltSalaryReport " , " bmgjjmxb_ys_config " ) ;
configs . addAll ( JsonUtil . parseList ( gjjConfigStr , LtSalaryReportConfigDTO . class ) ) ;
List < Long > variableItemIds = configs . stream ( ) . map ( LtSalaryReportConfigDTO : : getItem ) . collect ( Collectors . toList ( ) ) ;
// 获取浮动档案
List < Map < String , Object > > variableMapList = getVariableArchiveService ( user ) . listBySalaryMonthAndItems ( yearMonth , variableItemIds ) ;
log . info ( " 部门工资奖金明细表计提size{} " , variableMapList = = null ? 0 : variableMapList . size ( ) ) ;
// 获取直接人工工资分摊表的人
String dataSourceId = baseBean . getPropValue ( " ltSalaryReport " , " zjrycqgsft_data_source_id " ) ;
RecordSetDataSource extRs = new RecordSetDataSource ( dataSourceId ) ;
extRs . execute ( " select month, user_code from dws_oa.work_hour_apportion_report where month=' " + salaryMonth + " ' " ) ;
List < String > needExcludeWorkCodeList = new ArrayList < > ( ) ;
while ( extRs . next ( ) ) {
needExcludeWorkCodeList . add ( extRs . getString ( " user_code " ) ) ;
}
if ( CollectionUtils . isNotEmpty ( needExcludeWorkCodeList ) ) {
// 获取需要去除的人员id
List < String > excludeEmpIds = getSalaryEmployeeService ( user ) . listByWorkCodes ( needExcludeWorkCodeList ) . stream ( ) . map ( emp - > Utils . null2String ( emp . getEmployeeId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
variableMapList = variableMapList . stream ( ) . filter ( map - > ! excludeEmpIds . contains ( Utils . null2String ( map . get ( " employeeId " ) ) ) ) . collect ( Collectors . toList ( ) ) ;
}
log . info ( " 部门工资奖金明细表计提size afterexclude{} " , variableMapList = = null ? 0 : variableMapList . size ( ) ) ;
// 过滤数据, 不能所有值为0或空
List < String > keyList = configs . stream ( ) . map ( dto - > dto . getItem ( ) + " _variableItem " ) . collect ( Collectors . toList ( ) ) ;
variableMapList = variableMapList . stream ( ) . filter ( map - > {
for ( String key : keyList ) {
String val = Utils . null2String ( map . get ( key ) ) ;
if ( StringUtils . isNotBlank ( val ) & & NumberUtils . isCreatable ( val ) & & new BigDecimal ( val ) . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
return true ;
}
}
return false ;
} ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( variableMapList ) ) {
return null ;
}
log . info ( " 部门工资奖金明细表实发size afterexclude2{} " , variableMapList . size ( ) ) ;
List < Long > employeeIdList = variableMapList . stream ( ) . map ( m - > Utils . null2String ( m . get ( " employeeId " ) ) )
. filter ( NumberUtils : : isCreatable ) . map ( Long : : valueOf ) . collect ( Collectors . toList ( ) ) ;
// 查询生成的报表映射关系
String reportConfigStr = baseBean . getPropValue ( " ltSalaryReport " , " bmgzjjmxbjt_ys_config " ) ;
List < LtSalaryReportConfigDTO > reportConfigs = JsonUtil . parseList ( reportConfigStr , LtSalaryReportConfigDTO . class ) ;
List < Long > salaryItemIds = reportConfigs . stream ( ) . map ( LtSalaryReportConfigDTO : : getItem ) . collect ( Collectors . toList ( ) ) ;
List < SalaryItemPO > salaryItemList = getSalaryItemService ( user ) . listByIds ( salaryItemIds ) ;
// 查询薪资核算结果(包含未归档)
Date salaryMonthDate = SalaryDateUtil . localDateToDate ( yearMonth . atDay ( 1 ) ) ;
List < SalaryAcctRecordPO > salaryAcctRecordList = getSalaryAcctRecordService ( user ) . listBySalaryMonth ( LocalDateRange . builder ( ) . fromDate ( salaryMonthDate ) . endDate ( salaryMonthDate ) . build ( ) ) ;
// 账套范围
List < Long > sobIds = Arrays . stream ( baseBean . getPropValue ( " ltSalaryReport " , " bmgzjjmxbjt_sob_ids " ) . split ( " , " ) ) . filter ( NumberUtils : : isCreatable ) . map ( Long : : valueOf ) . collect ( Collectors . toList ( ) ) ;
salaryAcctRecordList = salaryAcctRecordList . stream ( ) . filter ( sobId - > sobIds . contains ( sobId ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( salaryAcctRecordList ) ) {
return " success " ;
}
List < Long > salaryAcctRecordIds = salaryAcctRecordList . stream ( ) . map ( SalaryAcctRecordPO : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SalaryAcctEmployeePO > salaryAcctEmployeeList = getSalaryAcctEmployeeService ( user ) . listBySalaryAcctRecordIdsAndEmployeeIds ( salaryAcctRecordIds , employeeIdList ) ;
List < DataCollectionEmployee > employeeList = getSalaryEmployeeService ( user ) . listByIds ( employeeIdList ) ;
// 查询薪资核算结果
List < Long > salaryAcctEmpIds = salaryAcctEmployeeList . stream ( ) . map ( SalaryAcctEmployeePO : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SalaryAcctResultPO > acctResultList = getSalaryAcctResultService ( user ) . listByAcctEmployeeIdsAndSalaryItemIds ( salaryAcctEmpIds , salaryItemIds ) ;
List < TaxAgentPO > taxAgentPOS = getTaxAgentService ( user ) . listAll ( ) ;
List < Map < String , Object > > acctResultMap = SalaryAcctResultBO . buildTableData ( salaryItemList , Collections . emptyList ( ) , employeeList , salaryAcctEmployeeList ,
acctResultList , taxAgentPOS , Collections . emptySet ( ) , Collections . emptyMap ( ) , Collections . emptyMap ( ) , false ) ;
Map < String , Map < String , Object > > acctResultMapByEmpId = SalaryEntityUtil . convert2Map ( acctResultMap , m - > Utils . null2String ( m . get ( " employeeId " ) ) ) ;
// 查询员工薪资档案
List < SalaryArchivePO > salaryArchiveList = getSalaryArchiveService ( user ) . listSome ( SalaryArchivePO . builder ( ) . employeeIds ( employeeIdList ) . build ( ) ) ;
Map < String , Long > archiveIdMap = SalaryEntityUtil . convert2Map ( salaryArchiveList , archive - > archive . getTaxAgentId ( ) + " _ " + archive . getEmployeeId ( ) , archive - > archive . getId ( ) ) ;
List < Long > salaryArchiveIds = salaryArchiveList . stream ( ) . map ( SalaryArchivePO : : getId ) . collect ( Collectors . toList ( ) ) ;
// 查询档案中对应的绩效工资
Long jdjxItemId = NumberUtils . isCreatable ( baseBean . getPropValue ( " ltSalaryReport " , " jdjx_item_id " ) ) ? Long . valueOf ( baseBean . getPropValue ( " ltSalaryReport " , " jdjx_item_id " ) ) : 0L ;
Date lastDayOfMonth = SalaryDateUtil . getLastDayOfMonth ( salaryMonthDate ) ;
List < SalaryArchiveItemPO > salaryArchiveItemCurrentList = getSalaryArchiveItemService ( user ) . getEffectiveItemListBySalaryMonth ( salaryArchiveIds , Collections . singletonList ( jdjxItemId ) , lastDayOfMonth ) ;
Map < Long , SalaryArchiveItemPO > archiveItemByArchiveId = SalaryEntityUtil . convert2Map ( salaryArchiveItemCurrentList , archive - > archive . getSalaryArchiveId ( ) ) ;
// 查询快照表中人员信息
Map < Long , DataCollectionEmployee > employeeMap = SalaryEntityUtil . convert2Map ( getSalaryEmployeeService ( user ) . snapshot ( employeeIdList , SalaryDateUtil . localDateToDate ( yearMonth . atDay ( 1 ) ) ) , DataCollectionEmployee : : getEmployeeId ) ;
// 入库
// 删除建模数据
RecordSet rs = new RecordSet ( ) ;
rs . execute ( " delete from uf_bmjjjt where xzszy = ' " + salaryMonth + " ' " ) ;
// 插入建模
String currDate = String . format ( " '%s' " , TimeUtil . getCurrentDateString ( ) ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( " HH:mm:ss " ) ;
String currTime = String . format ( " '%s' " , sdf . format ( new Date ( ) ) ) ;
// 获取建模模块id
String modeId = baseBean . getPropValue ( " ltSalaryReport " , " bmgzjjmxbjt_mode_id " ) ;
// 先插入一条数据
Map < String , Object > firstData = variableMapList . get ( 0 ) ;
StringBuilder firstSb = new StringBuilder ( ) ;
String fieldStr = reportConfigs . stream ( ) . map ( LtSalaryReportConfigDTO : : getField ) . collect ( Collectors . joining ( " , " ) ) ;
DataCollectionEmployee employee = employeeMap . getOrDefault ( firstData . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
// 获取员工档案绩效工资
Long archiveId = archiveIdMap . get ( Utils . null2String ( firstData . get ( " taxAgentId " ) ) + " _ " + employee . getEmployeeId ( ) ) ;
SalaryArchiveItemPO salaryArchiveItemPO = archiveItemByArchiveId . get ( archiveId = = null ? 0L : archiveId ) ;
String jxgz = ( salaryArchiveItemPO = = null | | ! NumberUtils . isCreatable ( salaryArchiveItemPO . getItemValue ( ) ) ) ? " 0 " : new BigDecimal ( salaryArchiveItemPO . getItemValue ( ) ) . divide ( new BigDecimal ( " 3 " ) , 2 , RoundingMode . HALF_UP ) . toString ( ) ;
// 获取薪资核算结果
Map < String , Object > singleAcctResultMap = acctResultMapByEmpId . get ( Utils . null2String ( employee . getEmployeeId ( ) ) ) ;
firstSb . append ( " insert into uf_bmjjjt(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3, " + fieldStr + " ) values ( " ) ;
firstSb . append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employee . getWorkcode ( ) ) . append ( " ', " )
. append ( employee . getEmployeeId ( ) ) . append ( " , " )
. append ( employee . getDepartmentId ( ) ) . append ( " , " )
. append ( employee . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employee . getLtCbzx ( ) ) ) . append ( " ', " )
. append ( jxgz ) ;
for ( LtSalaryReportConfigDTO dto : reportConfigs ) {
BigDecimal val = new BigDecimal ( " 0 " ) ;
if ( singleAcctResultMap ! = null ) {
String valStr = Utils . null2String ( singleAcctResultMap . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) , " 0 " ) ) ;
if ( NumberUtils . isCreatable ( valStr ) ) {
val = new BigDecimal ( valStr ) ;
}
}
firstSb . append ( " , " ) . append ( val . toPlainString ( ) ) ;
}
firstSb . append ( " ) " ) ;
rs . execute ( firstSb . toString ( ) ) ;
variableMapList . remove ( 0 ) ;
// 获取最大值 作为权限重构的起始id
rs . execute ( " select max(id) from uf_bmjjjt " ) ;
int minId = 0 ;
if ( rs . next ( ) ) {
minId = rs . getInt ( 1 ) ;
}
int maxId = minId + variableMapList . size ( ) ;
List < List < Map < String , Object > > > partition = Lists . partition ( variableMapList , 500 ) ;
for ( List < Map < String , Object > > part : partition ) {
StringBuilder sb = new StringBuilder ( ) ;
sb . append ( " insert into uf_bmjjjt(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3, " + fieldStr + " ) values " ) ;
for ( Map < String , Object > data : part ) {
employee = employeeMap . getOrDefault ( data . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
// 获取员工档案绩效工资
// 获取员工档案绩效工资
archiveId = archiveIdMap . get ( Utils . null2String ( data . get ( " taxAgentId " ) ) + " _ " + employee . getEmployeeId ( ) ) ;
salaryArchiveItemPO = archiveItemByArchiveId . get ( archiveId = = null ? 0L : archiveId ) ;
jxgz = ( salaryArchiveItemPO = = null | | ! NumberUtils . isCreatable ( salaryArchiveItemPO . getItemValue ( ) ) ) ? " 0 " : new BigDecimal ( salaryArchiveItemPO . getItemValue ( ) ) . divide ( new BigDecimal ( " 3 " ) , 2 , RoundingMode . HALF_UP ) . toString ( ) ;
// 获取薪资核算结果
singleAcctResultMap = acctResultMapByEmpId . get ( Utils . null2String ( employee . getEmployeeId ( ) ) ) ;
sb . append ( " ( " )
. append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employee . getWorkcode ( ) ) . append ( " ', " )
. append ( employee . getEmployeeId ( ) ) . append ( " , " )
. append ( employee . getDepartmentId ( ) ) . append ( " , " )
. append ( employee . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employee . getLtCbzx ( ) ) ) . append ( " ', " )
. append ( jxgz ) ;
for ( LtSalaryReportConfigDTO dto : reportConfigs ) {
BigDecimal val = new BigDecimal ( " 0 " ) ;
if ( singleAcctResultMap ! = null ) {
String valStr = Utils . null2String ( singleAcctResultMap . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) , " 0 " ) ) ;
if ( NumberUtils . isCreatable ( valStr ) ) {
val = new BigDecimal ( valStr ) ;
}
}
sb . append ( " , " ) . append ( val . toPlainString ( ) ) ;
}
sb . append ( " ), " ) ;
}
rs . execute ( sb . substring ( 0 , sb . length ( ) - 1 ) . toString ( ) ) ;
}
// 权限重构
log . info ( " 部门工资奖金明细表计提min{} max{} " , minId , maxId ) ;
if ( modeId ! = null & & NumberUtils . isCreatable ( modeId ) ) {
Integer modeIdValue = Integer . valueOf ( modeId ) ;
for ( int i = minId ; i < = maxId ; i + + ) {
ModeRightInfo ModeRightInfo = new ModeRightInfo ( ) ;
ModeRightInfo . setNewRight ( true ) ;
ModeRightInfo . editModeDataShare ( 1 , modeIdValue , i ) ;
}
}
return " success " ;
}
@Override
public String ltGenBmgzjjmxSf ( String salaryMonth ) {
if ( ! SalaryDateUtil . checkYearMonth ( salaryMonth ) ) {
throw new SalaryRunTimeException ( " 年月错误 " ) ;
}
YearMonth yearMonth = SalaryDateUtil . String2YearMonth ( salaryMonth ) ;
// 查询需要生成哪些浮动薪资项目
BaseBean baseBean = new BaseBean ( ) ;
String configStr = baseBean . getPropValue ( " ltSalaryReport " , " bmsbmxb_ys_config " ) ;
List < LtSalaryReportConfigDTO > configs = JsonUtil . parseList ( configStr , LtSalaryReportConfigDTO . class ) ;
String gjjConfigStr = baseBean . getPropValue ( " ltSalaryReport " , " bmgjjmxb_ys_config " ) ;
configs . addAll ( JsonUtil . parseList ( gjjConfigStr , LtSalaryReportConfigDTO . class ) ) ;
List < Long > variableItemIds = configs . stream ( ) . map ( LtSalaryReportConfigDTO : : getItem ) . collect ( Collectors . toList ( ) ) ;
// 获取浮动档案
List < Map < String , Object > > variableMapList = getVariableArchiveService ( user ) . listBySalaryMonthAndItems ( yearMonth , variableItemIds ) ;
log . info ( " 部门工资奖金明细表实发size{} " , variableMapList = = null ? 0 : variableMapList . size ( ) ) ;
// 获取直接人工工资分摊表的人
String dataSourceId = baseBean . getPropValue ( " ltSalaryReport " , " zjrycqgsft_data_source_id " ) ;
RecordSetDataSource extRs = new RecordSetDataSource ( dataSourceId ) ;
extRs . execute ( " select month, user_code from dws_oa.work_hour_apportion_report where month=' " + salaryMonth + " ' " ) ;
List < String > needExcludeWorkCodeList = new ArrayList < > ( ) ;
while ( extRs . next ( ) ) {
needExcludeWorkCodeList . add ( extRs . getString ( " user_code " ) ) ;
}
if ( CollectionUtils . isNotEmpty ( needExcludeWorkCodeList ) ) {
// 获取需要去除的人员id
List < String > excludeEmpIds = getSalaryEmployeeService ( user ) . listByWorkCodes ( needExcludeWorkCodeList ) . stream ( ) . map ( emp - > Utils . null2String ( emp . getEmployeeId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
variableMapList = variableMapList . stream ( ) . filter ( map - > ! excludeEmpIds . contains ( Utils . null2String ( map . get ( " employeeId " ) ) ) ) . collect ( Collectors . toList ( ) ) ;
}
log . info ( " 部门工资奖金明细表实发size afterexclude{} " , variableMapList = = null ? 0 : variableMapList . size ( ) ) ;
// 过滤数据, 不能所有值为0或空
List < String > keyList = configs . stream ( ) . map ( dto - > dto . getItem ( ) + " _variableItem " ) . collect ( Collectors . toList ( ) ) ;
variableMapList = variableMapList . stream ( ) . filter ( map - > {
for ( String key : keyList ) {
String val = Utils . null2String ( map . get ( key ) ) ;
if ( StringUtils . isNotBlank ( val ) & & NumberUtils . isCreatable ( val ) & & new BigDecimal ( val ) . compareTo ( BigDecimal . ZERO ) ! = 0 ) {
return true ;
}
}
return false ;
} ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( variableMapList ) ) {
return null ;
}
log . info ( " 部门工资奖金明细表实发size afterexclude2{} " , variableMapList . size ( ) ) ;
List < Long > employeeIdList = variableMapList . stream ( ) . map ( m - > Utils . null2String ( m . get ( " employeeId " ) ) )
. filter ( NumberUtils : : isCreatable ) . map ( Long : : valueOf ) . collect ( Collectors . toList ( ) ) ;
// 查询生成的报表映射关系
String reportConfigStr = baseBean . getPropValue ( " ltSalaryReport " , " bmgzjjmxbsf_ys_config " ) ;
List < LtSalaryReportConfigDTO > reportConfigs = JsonUtil . parseList ( reportConfigStr , LtSalaryReportConfigDTO . class ) ;
List < Long > salaryItemIds = reportConfigs . stream ( ) . map ( LtSalaryReportConfigDTO : : getItem ) . collect ( Collectors . toList ( ) ) ;
List < SalaryItemPO > salaryItemList = getSalaryItemService ( user ) . listByIds ( salaryItemIds ) ;
// 查询薪资核算结果(包含未归档)
Date salaryMonthDate = SalaryDateUtil . localDateToDate ( yearMonth . atDay ( 1 ) ) ;
List < SalaryAcctRecordPO > salaryAcctRecordList = getSalaryAcctRecordService ( user ) . listBySalaryMonth ( LocalDateRange . builder ( ) . fromDate ( salaryMonthDate ) . endDate ( salaryMonthDate ) . build ( ) ) ;
// 账套范围
List < Long > sobIds = Arrays . stream ( baseBean . getPropValue ( " ltSalaryReport " , " bmgzjjmxbsf_sob_ids " ) . split ( " , " ) ) . filter ( NumberUtils : : isCreatable ) . map ( Long : : valueOf ) . collect ( Collectors . toList ( ) ) ;
salaryAcctRecordList = salaryAcctRecordList . stream ( ) . filter ( sobId - > sobIds . contains ( sobId ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isEmpty ( salaryAcctRecordList ) ) {
return " success " ;
}
List < Long > salaryAcctRecordIds = salaryAcctRecordList . stream ( ) . map ( SalaryAcctRecordPO : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SalaryAcctEmployeePO > salaryAcctEmployeeList = getSalaryAcctEmployeeService ( user ) . listBySalaryAcctRecordIdsAndEmployeeIds ( salaryAcctRecordIds , employeeIdList ) ;
List < DataCollectionEmployee > employeeList = getSalaryEmployeeService ( user ) . listByIds ( employeeIdList ) ;
// 查询薪资核算结果
List < Long > salaryAcctEmpIds = salaryAcctEmployeeList . stream ( ) . map ( SalaryAcctEmployeePO : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SalaryAcctResultPO > acctResultList = getSalaryAcctResultService ( user ) . listByAcctEmployeeIdsAndSalaryItemIds ( salaryAcctEmpIds , salaryItemIds ) ;
List < TaxAgentPO > taxAgentPOS = getTaxAgentService ( user ) . listAll ( ) ;
List < Map < String , Object > > acctResultMap = SalaryAcctResultBO . buildTableData ( salaryItemList , Collections . emptyList ( ) , employeeList , salaryAcctEmployeeList ,
acctResultList , taxAgentPOS , Collections . emptySet ( ) , Collections . emptyMap ( ) , Collections . emptyMap ( ) , false ) ;
Map < String , Map < String , Object > > acctResultMapByEmpId = SalaryEntityUtil . convert2Map ( acctResultMap , m - > Utils . null2String ( m . get ( " employeeId " ) ) ) ;
// 查询员工薪资档案
List < SalaryArchivePO > salaryArchiveList = getSalaryArchiveService ( user ) . listSome ( SalaryArchivePO . builder ( ) . employeeIds ( employeeIdList ) . build ( ) ) ;
Map < String , Long > archiveIdMap = SalaryEntityUtil . convert2Map ( salaryArchiveList , archive - > archive . getTaxAgentId ( ) + " _ " + archive . getEmployeeId ( ) , archive - > archive . getId ( ) ) ;
List < Long > salaryArchiveIds = salaryArchiveList . stream ( ) . map ( SalaryArchivePO : : getId ) . collect ( Collectors . toList ( ) ) ;
// 查询档案中对应的绩效工资
Long jdjxItemId = NumberUtils . isCreatable ( baseBean . getPropValue ( " ltSalaryReport " , " jdjx_item_id " ) ) ? Long . valueOf ( baseBean . getPropValue ( " ltSalaryReport " , " jdjx_item_id " ) ) : 0L ;
Date lastDayOfMonth = SalaryDateUtil . getLastDayOfMonth ( salaryMonthDate ) ;
List < SalaryArchiveItemPO > salaryArchiveItemCurrentList = getSalaryArchiveItemService ( user ) . getEffectiveItemListBySalaryMonth ( salaryArchiveIds , Collections . singletonList ( jdjxItemId ) , lastDayOfMonth ) ;
Map < Long , SalaryArchiveItemPO > archiveItemByArchiveId = SalaryEntityUtil . convert2Map ( salaryArchiveItemCurrentList , archive - > archive . getSalaryArchiveId ( ) ) ;
// 查询快照表中人员信息
Map < Long , DataCollectionEmployee > employeeMap = SalaryEntityUtil . convert2Map ( getSalaryEmployeeService ( user ) . snapshot ( employeeIdList , SalaryDateUtil . localDateToDate ( yearMonth . atDay ( 1 ) ) ) , DataCollectionEmployee : : getEmployeeId ) ;
// 入库
// 删除建模数据
RecordSet rs = new RecordSet ( ) ;
rs . execute ( " delete from uf_bmjjjt where xzszy = ' " + salaryMonth + " ' " ) ;
// 插入建模
String currDate = String . format ( " '%s' " , TimeUtil . getCurrentDateString ( ) ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( " HH:mm:ss " ) ;
String currTime = String . format ( " '%s' " , sdf . format ( new Date ( ) ) ) ;
// 获取建模模块id
String modeId = baseBean . getPropValue ( " ltSalaryReport " , " bmgzjjmxbsf_mode_id " ) ;
// 先插入一条数据
Map < String , Object > firstData = variableMapList . get ( 0 ) ;
StringBuilder firstSb = new StringBuilder ( ) ;
String fieldStr = reportConfigs . stream ( ) . map ( LtSalaryReportConfigDTO : : getField ) . collect ( Collectors . joining ( " , " ) ) ;
DataCollectionEmployee employee = employeeMap . getOrDefault ( firstData . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
// 获取员工档案绩效工资
Long archiveId = archiveIdMap . get ( Utils . null2String ( firstData . get ( " taxAgentId " ) ) + " _ " + employee . getEmployeeId ( ) ) ;
SalaryArchiveItemPO salaryArchiveItemPO = archiveItemByArchiveId . get ( archiveId = = null ? 0L : archiveId ) ;
String jxgz = ( salaryArchiveItemPO = = null | | ! NumberUtils . isCreatable ( salaryArchiveItemPO . getItemValue ( ) ) ) ? " 0 " : new BigDecimal ( salaryArchiveItemPO . getItemValue ( ) ) . divide ( new BigDecimal ( " 3 " ) , 2 , RoundingMode . HALF_UP ) . toString ( ) ;
// 获取薪资核算结果
Map < String , Object > singleAcctResultMap = acctResultMapByEmpId . get ( Utils . null2String ( employee . getEmployeeId ( ) ) ) ;
firstSb . append ( " insert into uf_bmjjsf(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3, " + fieldStr + " ) values ( " ) ;
firstSb . append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employee . getWorkcode ( ) ) . append ( " ', " )
. append ( employee . getEmployeeId ( ) ) . append ( " , " )
. append ( employee . getDepartmentId ( ) ) . append ( " , " )
. append ( employee . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employee . getLtCbzx ( ) ) ) . append ( " ', " )
. append ( jxgz ) ;
for ( LtSalaryReportConfigDTO dto : reportConfigs ) {
BigDecimal val = new BigDecimal ( " 0 " ) ;
if ( singleAcctResultMap ! = null ) {
String valStr = Utils . null2String ( singleAcctResultMap . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) , " 0 " ) ) ;
if ( NumberUtils . isCreatable ( valStr ) ) {
val = new BigDecimal ( valStr ) ;
}
}
firstSb . append ( " , " ) . append ( val . toPlainString ( ) ) ;
}
firstSb . append ( " ) " ) ;
rs . execute ( firstSb . toString ( ) ) ;
variableMapList . remove ( 0 ) ;
// 获取最大值 作为权限重构的起始id
rs . execute ( " select max(id) from uf_bmjjsf " ) ;
int minId = 0 ;
if ( rs . next ( ) ) {
minId = rs . getInt ( 1 ) ;
}
int maxId = minId + variableMapList . size ( ) ;
List < List < Map < String , Object > > > partition = Lists . partition ( variableMapList , 500 ) ;
for ( List < Map < String , Object > > part : partition ) {
StringBuilder sb = new StringBuilder ( ) ;
sb . append ( " insert into uf_bmjjsf(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3, " + fieldStr + " ) values " ) ;
for ( Map < String , Object > data : part ) {
employee = employeeMap . getOrDefault ( data . get ( " employeeId " ) , DataCollectionEmployee . builder ( ) . build ( ) ) ;
// 获取员工档案绩效工资
archiveId = archiveIdMap . get ( Utils . null2String ( data . get ( " taxAgentId " ) ) + " _ " + employee . getEmployeeId ( ) ) ;
salaryArchiveItemPO = archiveItemByArchiveId . get ( archiveId = = null ? 0L : archiveId ) ;
jxgz = ( salaryArchiveItemPO = = null | | ! NumberUtils . isCreatable ( salaryArchiveItemPO . getItemValue ( ) ) ) ? " 0 " : new BigDecimal ( salaryArchiveItemPO . getItemValue ( ) ) . divide ( new BigDecimal ( " 3 " ) , 2 , RoundingMode . HALF_UP ) . toString ( ) ;
// 获取薪资核算结果
singleAcctResultMap = acctResultMapByEmpId . get ( Utils . null2String ( employee . getEmployeeId ( ) ) ) ;
sb . append ( " ( " )
. append ( modeId ) . append ( " ,1,0, " ) . append ( currDate ) . append ( " , " ) . append ( currTime ) . append ( " ,' " )
. append ( employee . getWorkcode ( ) ) . append ( " ', " )
. append ( employee . getEmployeeId ( ) ) . append ( " , " )
. append ( employee . getDepartmentId ( ) ) . append ( " , " )
. append ( employee . getJobtitleId ( ) ) . append ( " ,' " )
. append ( salaryMonth ) . append ( " ',' " )
. append ( Utils . null2String ( employee . getLtCbzx ( ) ) ) . append ( " ', " )
. append ( jxgz ) ;
for ( LtSalaryReportConfigDTO dto : reportConfigs ) {
BigDecimal val = new BigDecimal ( " 0 " ) ;
if ( singleAcctResultMap ! = null ) {
String valStr = Utils . null2String ( singleAcctResultMap . getOrDefault ( Utils . null2String ( dto . getItem ( ) ) , " 0 " ) ) ;
if ( NumberUtils . isCreatable ( valStr ) ) {
val = new BigDecimal ( valStr ) ;
}
}
sb . append ( " , " ) . append ( val . toPlainString ( ) ) ;
}
sb . append ( " ), " ) ;
}
rs . execute ( sb . substring ( 0 , sb . length ( ) - 1 ) . toString ( ) ) ;
}
// 权限重构
log . info ( " 部门工资奖金明细表实发min{} max{} " , minId , maxId ) ;
if ( modeId ! = null & & NumberUtils . isCreatable ( modeId ) ) {
Integer modeIdValue = Integer . valueOf ( modeId ) ;
for ( int i = minId ; i < = maxId ; i + + ) {
ModeRightInfo ModeRightInfo = new ModeRightInfo ( ) ;
ModeRightInfo . setNewRight ( true ) ;
ModeRightInfo . editModeDataShare ( 1 , modeIdValue , i ) ;
}
}
return " success " ;
}
2023-05-11 14:40:10 +08:00
}