Merge branch 'fix/核算效率' into release/2.9.6.2310.01

This commit is contained in:
钱涛 2023-10-07 10:05:49 +08:00
commit 6fe4b855ec
5 changed files with 119 additions and 114 deletions

View File

@ -118,7 +118,7 @@ public interface SalaryAcctResultService {
*
* @param salaryAcctResultPOS 薪资核算结果
*/
void batchSave(Collection<SalaryAcctResultPO> salaryAcctResultPOS);
void batchSave(List<SalaryAcctResultPO> salaryAcctResultPOS);
/**
* 根据薪资核算人员id删除薪资核算结果

View File

@ -34,6 +34,7 @@ import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.util.StopWatch;
import weaver.general.BaseBean;
import weaver.hrm.User;
import weaver.wechat.util.Utils;
@ -111,17 +112,23 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
@Override
public void calculate(SalaryAcctCalculateBO salaryAcctCalculateBO, DataCollectionEmployee simpleEmployee, List<SalarySobBackItemPO> salarySobBackItems) {
StopWatch sw = new StopWatch(salaryAcctCalculateBO.getSalaryAcctRecordPO().getId()+"");
Date now = new Date();
try {
// 数据库字段加密用
// 1查询人员信息
sw.start("核算耗时查询人员信息");
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getSalaryAcctEmployeePOS(), SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
List<DataCollectionEmployee> simpleEmployees = getSalaryEmployeeService(user).getEmployeeByIdsAll(employeeIds);
SalarySobCycleDTO salarySobCycleDTO = salaryAcctCalculateBO.getSalarySobCycleDTO();
Long taxAgentId = salaryAcctCalculateBO.getSalarySobPO().getTaxAgentId();
sw.stop();
// 2查询薪资档案的数据
sw.start("核算耗时查询薪资档案的数据");
List<SalaryArchiveDataDTO> salaryArchiveData = getSalaryArchiveService(user).getSalaryArchiveData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
sw.stop();
// 3查询往期累计情况(查询的是上个税款所属期的的累计情况)
sw.start("核算耗时查询往期累计情况");
List<AddUpSituation> addUpSituationPOS;
if (salarySobCycleDTO.getTaxCycle().getMonth() == Month.JANUARY) {
// 3.1如果当前税款所属期是本年度第一个税款所属期就不需要查询往期累计情况
@ -129,19 +136,30 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
} else {
addUpSituationPOS = getAddUpSituationService(user).getAddUpSituationList(salarySobCycleDTO.getTaxCycle().plusMonths(-1), employeeIds);
}
sw.stop();
// 4查询累计专项附加扣除
sw.start("核算耗时查询累计专项附加扣除");
List<AddUpDeduction> addUpDeductionPOS = getAddUpDeductionService(user).getAddUpDeductionList(salarySobCycleDTO.getTaxCycle(), employeeIds, taxAgentId);
sw.stop();
// 5查询其他免税扣除
sw.start("核算耗时查询其他免税扣除");
List<OtherDeductionPO> otherDeductionPOS = getOtherDeductionService(user).getOtherDeductionList(salarySobCycleDTO.getTaxCycle(), employeeIds, taxAgentId);
sw.stop();
//6查询社保福利
sw.start("核算耗时查询社保福利");
List<Map<String, Object>> welfareData = getSIAccountService(user).welfareData(salarySobCycleDTO.getSocialSecurityCycle().toString(), employeeIds, taxAgentId);
sw.stop();
// 7查询考勤数据
sw.start("核算耗时查询考勤数据");
List<AttendQuoteDataDTO> attendQuoteDataDTOS = getAttendQuoteDataService(user).getAttendQuoteData(salarySobCycleDTO.getSalaryMonth(), salarySobCycleDTO.getSalarySobId(), employeeIds);
sw.stop();
// 8查询薪资核算人员的薪资核算结果
sw.start("核算耗时查询薪资核算人员的薪资核算结果");
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getSalaryAcctEmployeePOS(), SalaryAcctEmployeePO::getId, Collectors.toList());
List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
sw.stop();
// 薪资回算时回算前的核算结果 (没有回算项)
sw.start("核算耗时查询薪资回算时回算前的核算结果");
Map<String, List<SalaryAcctResultPO>> collect = salaryAcctResultPOS.stream().collect(Collectors.groupingBy(k -> k.getEmployeeId() + "-" + k.getTaxAgentId() + "-" + k.getSalaryItemId()));
Map<String, String> salaryAcctResultPOMap = new HashMap<>();
for (Map.Entry<String, List<SalaryAcctResultPO>> et : collect.entrySet()) {
@ -150,18 +168,24 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
//核算锁定的值
Map<String, SalaryAcctResultPO> salaryAcctLockResultPOS = MapUtils.emptyIfNull(salaryAcctCalculateBO.getSalaryAcctLockResultPOS());
List<Long> lockSalaryItemIds = ListUtils.emptyIfNull(salaryAcctCalculateBO.getLockSalaryItemIds());
sw.stop();
// 9查询相同税款所属期内涉及合并计税的其他薪资核算结果
sw.start("核算耗时查询相同税款所属期内涉及合并计税的其他薪资核算结果");
Set<Long> otherSalaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctCalculateBO.getOtherSalaryAcctRecordPOS(), SalaryAcctRecordPO::getId);
List<SalaryAcctResultPO> otherSalaryAcctResultPOS = getSalaryAcctResultService(user).listBySalaryAcctRecordIdsAndEmployeeIds(otherSalaryAcctRecordIds, employeeIds);
Map<String, List<SalaryAcctResultPO>> otherSalaryAcctResultPOMap = SalaryEntityUtil.group2Map(otherSalaryAcctResultPOS, e -> e.getEmployeeId() + "_" + e.getTaxAgentId());
sw.stop();
// 9.1查询相同税款所属期内设计合并计税的其他薪资核算人员
sw.start("核算耗时查询相同税款所属期内设计合并计税的其他薪资核算人员");
List<SalaryAcctEmployeePO> otherSalaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIdsAndEmployeeIds(otherSalaryAcctRecordIds, employeeIds);
Map<String, List<SalaryAcctEmployeePO>> otherSalaryAcctEmployeePOMap = SalaryEntityUtil.group2Map(otherSalaryAcctEmployeePOS, salaryAcctEmployeePO -> salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId());
sw.stop();
// 10转换成公式编辑器中的变量
sw.start("核算耗时转换成公式编辑器中的变量");
CalculateFormulaVarBO calculateFormulaVarBO = new CalculateFormulaVarBO(simpleEmployees, salaryArchiveData, addUpSituationPOS, addUpDeductionPOS, otherDeductionPOS, welfareData, attendQuoteDataDTOS, salaryAcctResultPOS);
Map<String, List<CalculateFormulaVarBO.FormulaVarValue>> formulaVarMap = calculateFormulaVarBO.convert2FormulaVar(salaryAcctCalculateBO);
sw.stop();
sw.start("核算耗时数据结构准备");
// 本次薪资核算所用的薪资账套下的薪资项目
Map<Long, SalarySobItemPO> salaryItemIdKeySalarySobItemPOMap = SalaryEntityUtil.convert2Map(salaryAcctCalculateBO.getSalarySobItemPOS(), SalarySobItemPO::getSalaryItemId);
// 本次薪资核算所用的公式
@ -172,7 +196,9 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
Set<Long> salarySobBackItemIds = SalaryEntityUtil.properties(salarySobBackItems, SalarySobBackItemPO::getSalaryItemId);
Map<Long, SalarySobBackItemPO> salarySobBackItemMap = SalaryEntityUtil.convert2Map(salarySobBackItems, SalarySobBackItemPO::getSalaryItemId);
List<SalaryAcctResultTempPO> salaryAcctResultTempPOS = Lists.newArrayList();
sw.stop();
// 开始核算
sw.start("核算耗时核算耗时");
StringBuffer noticeMsg = new StringBuffer();
for (SalaryAcctEmployeePO salaryAcctEmployeePO : salaryAcctCalculateBO.getSalaryAcctEmployeePOS()) {
Long salaryAcctEmployeePOId = salaryAcctEmployeePO.getId();
@ -262,13 +288,19 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
}
}
}
sw.stop();
// 保存新的薪资核算结果临时存储
sw.start("核算耗时保存新的薪资核算结果(临时存储)");
getSalaryAcctResultTempService(user).batchSave(salaryAcctResultTempPOS);
sw.stop();
// 更新薪资核算进度
sw.start("更新薪资核算进度");
getSalaryAcctProgressService(user).getAndAddCalculatedQty(SalaryCacheKey.ACCT_PROGRESS + salaryAcctCalculateBO.getSalaryAcctRecordPO().getId(),
salaryAcctCalculateBO.getSalaryAcctEmployeePOS().size(),
noticeMsg.toString()
);
sw.stop();
log.info("核算耗时明细" + sw.prettyPrint());
// 记录子线程执行结果
salaryAcctCalculateBO.getResults().add(new SalaryAcctCalculateBO.Result(true, StringUtils.EMPTY));
} catch (Exception e) {

View File

@ -55,6 +55,7 @@ import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.util.StopWatch;
import weaver.hrm.User;
import java.math.BigDecimal;
@ -331,7 +332,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
Map<Long, SalarySobItemPO> salaryItemIdKeySalarySobItemPOMap = SalaryEntityUtil.convert2Map(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
if(Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), NumberUtils.INTEGER_ONE)){
if (Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), NumberUtils.INTEGER_ONE)) {
// 是回算获取回算项
List<SalarySobBackItemPO> salarySobBackItemPOS = getSalarySobBackItemService(user).listBySalarySobId(salaryAcctRecordPO.getSalarySobId());
salaryItemIds.addAll(salarySobBackItemPOS.stream().map(SalarySobBackItemPO::getSalaryItemId).collect(Collectors.toList()));
@ -339,19 +340,13 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds);
// 查询薪资核算结果
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId,Collectors.toList());
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
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 -> {
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);
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);
map.put(item.getId().toString(), SalaryAcctFormulaBO.roundResultValue(sum.toString(), item, Collections.emptyList(), Collections.emptyMap(), salaryItemIdKeySalarySobItemPOMap));
});
return map;
@ -396,7 +391,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
}
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(salaryItemIds);
// 查询薪资核算结果
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId,Collectors.toList());
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
// 查询人员信息
List<Long> employeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getEmployeeId, Collectors.toList());
@ -438,8 +433,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
});
// 转换成薪资核算结果列表
return SalaryAcctResultBO.buildTableData(salaryItemPOS, salarySobEmpFieldPOS, simpleEmployees, salaryAcctEmployeePOS, salaryAcctResultPOS, taxAgentPOS,
salaryAcctEmployeeIds4ConsolidatedTax, customParameters, customBackCalcParameters, isBackCalc);
return SalaryAcctResultBO.buildTableData(salaryItemPOS, salarySobEmpFieldPOS, simpleEmployees, salaryAcctEmployeePOS, salaryAcctResultPOS, taxAgentPOS, salaryAcctEmployeeIds4ConsolidatedTax, customParameters, customBackCalcParameters, isBackCalc);
}
@ -477,7 +471,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
salaryAcctEmployeePOS = getSalaryAcctEmployeeService(user).listByRecordIdsAndEmpIdAndTaxAgentId(salaryAcctRecordIds, salaryAcctEmployeePO.getEmployeeId(), salaryAcctEmployeePO.getTaxAgentId());
}
// 查询薪资核算人员的薪资核算结果
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId,Collectors.toList());
List<Long> salaryAcctEmployeeIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getId, Collectors.toList());
List<SalaryAcctResultPO> salaryAcctResultPOS = listBySalaryAcctEmployeeIds(salaryAcctEmployeeIds);
// 查询薪资核算人员所有合并计税的薪资核算记录所用的账套
Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctEmployeePOS, SalaryAcctEmployeePO::getSalarySobId);
@ -503,22 +497,12 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
for (SalarySobItemIncomeCategoryDTO incomeCategoryDTO : salarySobItemAggregateDTO.getIncomeCategories()) {
for (SalarySobItemGroupDTO salarySobItemGroupDTO : incomeCategoryDTO.getItemGroups()) {
for (SalarySobItemDTO salarySobItemDTO : salarySobItemGroupDTO.getItems()) {
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));
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));
resultMap.put("" + salarySobItemDTO.getSalaryItemId(), salaryAcctResultListColumnDTO);
}
}
for (SalarySobItemDTO salarySobItemDTO : incomeCategoryDTO.getItems()) {
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));
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));
resultMap.put("" + salarySobItemDTO.getSalaryItemId(), salaryAcctResultListColumnDTO);
}
}
@ -526,11 +510,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
if (Objects.equals(salaryAcctRecordPO.getBackCalcStatus(), 1)) {
List<SalarySobItemDTO> backCalcItems = salarySobItemAggregateDTO.getBackCalcItems();
for (SalarySobItemDTO backCalcItem : backCalcItems) {
SalaryAcctResultListColumnDTO salaryAcctResultListColumnDTO = new SalaryAcctResultListColumnDTO()
.setColumnName(backCalcItem.getName())
.setFormulaId(backCalcItem.getFormulaId())
.setFormulaContent(backCalcItem.getFormulaContent())
.setShowLock(true);
SalaryAcctResultListColumnDTO salaryAcctResultListColumnDTO = new SalaryAcctResultListColumnDTO().setColumnName(backCalcItem.getName()).setFormulaId(backCalcItem.getFormulaId()).setFormulaContent(backCalcItem.getFormulaContent()).setShowLock(true);
resultMap.put("" + backCalcItem.getSalaryItemId(), salaryAcctResultListColumnDTO);
}
}
@ -555,22 +535,19 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// 保存参数转换成薪资核算结果po
List<SalaryAcctResultPO> salaryAcctResultPOS = SalaryAcctResultBO.convert2PO(salaryAcctResultPOSOld, saveParam, salaryAcctEmployeePO, (long) user.getUID());
SalarySysConfPO autoLock = getSalarySysConfService(user).getOneByCode(SalarySysConstant.EDIT_IMPORT_AUTO_LOCK);
if(autoLock != null && StringUtils.equals(autoLock.getConfValue(),"1")){
if (autoLock != null && StringUtils.equals(autoLock.getConfValue(), "1")) {
// 对比核算结果提取修改了哪些薪资项目
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("");
if(!StringUtils.equals(oldValue,PO.getResultValue())){
if (!StringUtils.equals(oldValue, PO.getResultValue())) {
needLockItems.add(PO.getSalaryItemId());
}
});
// 编辑的列都自动锁定
SalaryAcctResultUpdateLockStatusParam updateLockStatusParam = SalaryAcctResultUpdateLockStatusParam.builder()
.salaryItemIds(needLockItems)
.salaryAcctRecordId(salaryAcctEmployeePO.getSalaryAcctRecordId())
.lockStatus(LockStatusEnum.LOCK).build();
SalaryAcctResultUpdateLockStatusParam updateLockStatusParam = SalaryAcctResultUpdateLockStatusParam.builder().salaryItemIds(needLockItems).salaryAcctRecordId(salaryAcctEmployeePO.getSalaryAcctRecordId()).lockStatus(LockStatusEnum.LOCK).build();
getSalaryAcctResultService(user).updateLockStatusByParam(updateLockStatusParam);
}
// SalaryAcctRecordPO byId = getSalaryAcctRecordService(user).getById(salaryAcctEmployeePO.getSalaryAcctRecordId());
@ -601,7 +578,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// 存储薪资核算结果数据来源日志
salaryAcctResultPOS = getSalaryAcctRecordService(user).listBySalaryAcctEmpId(saveParam.getSalaryAcctEmpId());
saveSalaryAcctResultLog(salaryAcctResultPOSOld,salaryAcctResultPOS);
saveSalaryAcctResultLog(salaryAcctResultPOSOld, salaryAcctResultPOS);
// 查询操作日志的targetName
// String targetName = getSalaryAcctRecordService(user).getLogTargetNameById(salaryAcctEmployeePO.getSalaryAcctRecordId());
@ -623,6 +600,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
/**
* 存储薪资核算结果数据来源日志
*
* @param salaryAcctResultPOSOld
* @param salaryAcctResultPOS
*/
@ -631,11 +609,11 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
List<SalaryAcctResultPO> editItems = new ArrayList<>();
Map<Long, SalaryAcctResultPO> oldResutMap = SalaryEntityUtil.convert2Map(salaryAcctResultPOSOld, SalaryAcctResultPO::getSalaryItemId);
salaryAcctResultPOS.stream().forEach(PO -> {
if(oldResutMap.get(PO.getSalaryItemId()) == null){
if (oldResutMap.get(PO.getSalaryItemId()) == null) {
editItems.add(PO);
}else{
} else {
String oldValue = oldResutMap.get(PO.getSalaryItemId()).getResultValue();
if(!StringUtils.equals(oldValue,PO.getResultValue())){
if (!StringUtils.equals(oldValue, PO.getResultValue())) {
editItems.add(PO);
}
}
@ -646,12 +624,11 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
@Override
public void batchSave(Collection<SalaryAcctResultPO> salaryAcctResultPOS) {
public void batchSave(List<SalaryAcctResultPO> salaryAcctResultPOS) {
if (CollectionUtils.isNotEmpty(salaryAcctResultPOS)) {
List<SalaryAcctResultPO> list = (List<SalaryAcctResultPO>) salaryAcctResultPOS;
// 数据加密
encryptUtil.encryptList(list, SalaryAcctResultPO.class);
List<List<SalaryAcctResultPO>> partition = Lists.partition(list, 100);
encryptUtil.encryptList(salaryAcctResultPOS, SalaryAcctResultPO.class);
List<List<SalaryAcctResultPO>> partition = Lists.partition(salaryAcctResultPOS, 100);
partition.forEach(getSalaryAcctResultMapper()::batchInsert);
}
@ -676,7 +653,9 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
@Override
public void calculate(SalaryAcctCalculateParam calculateParam, DataCollectionEmployee simpleEmployee) {
StopWatch stopWatch = new StopWatch(calculateParam.getSalaryAcctRecordId() + "");
try {
stopWatch.start("核算总耗时数据准备");
// 1查询薪资核算记录
SalaryAcctRecordPO salaryAcctRecordPO = getSalaryAcctRecordService(user).getById(calculateParam.getSalaryAcctRecordId());
if (Objects.isNull(salaryAcctRecordPO)) {
@ -718,11 +697,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
if (CollectionUtils.isNotEmpty(lockSalaryItemIds)) {
List<SalaryAcctResultPO> acctResultPOS = listBySalaryAcctRecordIdsAndSalaryItemIds(Collections.singleton(calculateParam.getSalaryAcctRecordId()), lockSalaryItemIds);
// List<SalaryAcctResultPO> acctResultPOS = listBySalaryAcctRecordIds(Collections.singleton(calculateParam.getSalaryAcctRecordId()));
acctResults = Optional.ofNullable(acctResultPOS)
.orElse(new ArrayList<>())
.stream()
.filter(po -> lockSalaryItemIds.contains(po.getSalaryItemId()))
.collect(Collectors.toMap(po -> po.getSalaryItemId() + "_" + po.getSalaryAcctEmpId(), a -> a, (a, b) -> a));
acctResults = Optional.ofNullable(acctResultPOS).orElse(new ArrayList<>()).stream().filter(po -> lockSalaryItemIds.contains(po.getSalaryItemId())).collect(Collectors.toMap(po -> po.getSalaryItemId() + "_" + po.getSalaryAcctEmpId(), a -> a, (a, b) -> a));
}
// 8查询公式详情
@ -746,6 +721,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(103378, "薪资核算人员不能为空"));
}
stopWatch.stop();
stopWatch.start("核算完毕计时");
// 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.ACCT_PROGRESS + calculateParam.getSalaryAcctRecordId(), initProgress);
@ -761,26 +740,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
TaxDeclarationFunctionEnum taxDeclarationFunction = getSalarySysConfService(user).getTaxDeclaration();
// 12.5多线程运算运算结果存放在临时表中
for (List<SalaryAcctEmployeePO> acctEmployeePOS : partition) {
SalaryAcctCalculateBO salaryAcctCalculateBO = new SalaryAcctCalculateBO()
.setSalaryAcctRecordPO(salaryAcctRecordPO)
.setSalarySobPO(salarySobPO)
.setSalarySobCycleDTO(salarySobCycleDTO)
.setOtherSalaryAcctRecordPOS(otherSalaryAcctRecordPOS)
.setSalaryAcctLockResultPOS(MapUtils.emptyIfNull(acctResults))
.setLockSalaryItemIds(lockSalaryItemIds)
.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)
.setTaxDeclarationFunction(taxDeclarationFunction);
SalaryAcctCalculateBO salaryAcctCalculateBO = new SalaryAcctCalculateBO().setSalaryAcctRecordPO(salaryAcctRecordPO).setSalarySobPO(salarySobPO).setSalarySobCycleDTO(salarySobCycleDTO).setOtherSalaryAcctRecordPOS(otherSalaryAcctRecordPOS).setSalaryAcctLockResultPOS(MapUtils.emptyIfNull(acctResults)).setLockSalaryItemIds(lockSalaryItemIds).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).setTaxDeclarationFunction(taxDeclarationFunction);
List<SalarySobBackItemPO> finalSalarySobBackItems = salarySobBackItems;
LocalRunnable localRunnable = new LocalRunnable() {
@Override
@ -792,6 +752,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
}
// 13等待所有子线程执行完毕
childMonitor.await();
stopWatch.stop();
stopWatch.start("核算入库计时");
// 14判断子线程执行结果
boolean allSuccess = calculateResults.stream().allMatch(SalaryAcctCalculateBO.Result::isStatus);
if (!allSuccess) {
@ -812,15 +776,15 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// Thread.sleep(10);
getSalaryAcctProgressService(user).finish(SalaryCacheKey.ACCT_PROGRESS + calculateParam.getSalaryAcctRecordId(), true);
stopWatch.stop();
log.info(stopWatch.prettyPrint());
// 存储薪资核算数据来源日志
new Thread() {
public void run() {
List<Long> exceptItemIds = new ArrayList<>();
List<Long> salaryAcctEmployeeIds = salaryAcctEmployeePOS.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList());
exceptItemIds.addAll(lockSalaryItemIds);
exceptItemIds.addAll(salaryItemPOS.stream().filter(PO -> Objects.equals(PO.getValueType(), NumberUtils.INTEGER_ONE) &&
Objects.equals(PO.getUseInEmployeeSalary(),0))
.map(SalaryItemPO::getId).collect(Collectors.toList()) );
exceptItemIds.addAll(salaryItemPOS.stream().filter(PO -> Objects.equals(PO.getValueType(), NumberUtils.INTEGER_ONE) && Objects.equals(PO.getUseInEmployeeSalary(), 0)).map(SalaryItemPO::getId).collect(Collectors.toList()));
getSalaryAcctResultLogService(user).deleteBySalaryAcctEmpIdExceptItemIds(salaryAcctEmployeeIds, exceptItemIds);
}
}.start();
@ -850,31 +814,37 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
* @param calculateKey
*/
private void handleSalaryAcctResultTemp(SalaryAcctCalculateParam calculateParam, String calculateKey) {
// TransactionStatus status = dataSourceTransactionManager.getTransaction(new DefaultTransactionDefinition());
// try {
StopWatch sw = new StopWatch(calculateParam.getSalaryAcctRecordId() + "");
// 查询薪资核算结果的临时存储
sw.start("处理核算数据,查询薪资核算结果的临时存储");
List<SalaryAcctResultTempPO> salaryAcctResultTempPOS = getSalaryAcctResultTempService(user).listByCalculateKey(calculateKey);
sw.stop();
// 删除原来的薪资核算结果
sw.start("处理核算数据,删除原来的薪资核算结果");
if (CollectionUtils.isNotEmpty(calculateParam.getIds())) {
getSalaryAcctResultMapper().deleteBySalaryAcctEmpIds(calculateParam.getIds());
} else {
getSalaryAcctResultMapper().deleteBySalaryAcctRecordIds(Collections.singleton(calculateParam.getSalaryAcctRecordId()));
getSalaryAcctReportService(user).deleteBySalaryAcctRecordId(calculateParam.getSalaryAcctRecordId());
}
sw.stop();
// 保存薪资的薪资核算结果
sw.start("处理核算数据,保存薪资的薪资核算结果");
List<SalaryAcctResultPO> salaryAcctResultPOS = SalaryAcctResultBO.convert2ResultPO(salaryAcctResultTempPOS);
batchSave(salaryAcctResultPOS);
//保存核算报表数据
List<SalaryAcctResultReportPO> salaryAcctResultReportPOS = SalaryAcctResultReportBO.convert2ReportPO(salaryAcctResultTempPOS, calculateParam.getEmps());
getSalaryAcctReportService(user).batchSave(salaryAcctResultReportPOS);
sw.stop();
new Thread() {
public void run() {
//保存核算报表数据
List<SalaryAcctResultReportPO> salaryAcctResultReportPOS = SalaryAcctResultReportBO.convert2ReportPO(salaryAcctResultTempPOS, calculateParam.getEmps());
getSalaryAcctReportService(user).batchSave(salaryAcctResultReportPOS);
}
}.start();
// 删除薪资核算临时存储表中的数据
sw.start("处理核算数据,删除薪资核算临时存储表中的数据");
getSalaryAcctResultTempService(user).deleteByCalculateKey(calculateKey);
// // 提交事务
// dataSourceTransactionManager.commit(status);
// } catch (Exception e) {
// dataSourceTransactionManager.rollback(status);
// throw e;
// }
sw.stop();
log.info(sw.prettyPrint());
}
@Override
@ -882,8 +852,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
if (CollectionUtils.isEmpty(salaryAcctRecordIds)) {
return Collections.emptyList();
}
return encryptUtil.decryptList(getSalaryAcctResultMapper().listSome(SalaryAcctResultPO.builder().salaryAcctRecordIds(salaryAcctRecordIds).taxAgentIds(taxAgentIds).build()),
SalaryAcctResultPO.class);
return encryptUtil.decryptList(getSalaryAcctResultMapper().listSome(SalaryAcctResultPO.builder().salaryAcctRecordIds(salaryAcctRecordIds).taxAgentIds(taxAgentIds).build()), SalaryAcctResultPO.class);
}
@ -940,9 +909,9 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
// }
Set<Long> salaryItemIds;
if(CollectionUtils.isNotEmpty(updateParam.getSalaryItemIds())){
if (CollectionUtils.isNotEmpty(updateParam.getSalaryItemIds())) {
salaryItemIds = updateParam.getSalaryItemIds();
}else{
} else {
salaryItemIds = Collections.singleton(updateParam.getSalaryItemId());
}
if (updateParam.getLockStatus() == LockStatusEnum.LOCK) {
@ -963,8 +932,7 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
SalaryAcctResultPO build = SalaryAcctResultPO.builder().salaryAcctRecordId(id).deleteType(0).build();
List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultMapper().listSome(build);
// 回算前的薪资核算结果
salaryAcctResultPOS.forEach(salaryAcctResult ->
salaryAcctResult.setOriginResultValue(salaryAcctResult.getResultValue()));
salaryAcctResultPOS.forEach(salaryAcctResult -> salaryAcctResult.setOriginResultValue(salaryAcctResult.getResultValue()));
// 批量更新
batchUpdateOriginResultValue(salaryAcctResultPOS);
}
@ -981,10 +949,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
@Override
public List<SalaryAcctResultPO> listByAcctEmployeeIdsAndSalaryItemIds(List<Long> salaryAcctEmployeeIds, Collection<Long> salaryItemIds) {
if(CollectionUtils.isEmpty(salaryAcctEmployeeIds)){
if (CollectionUtils.isEmpty(salaryAcctEmployeeIds)) {
return Collections.emptyList();
}
List<List<Long>> partition = Lists.partition((List<Long>)salaryAcctEmployeeIds, 200);
List<List<Long>> partition = Lists.partition((List<Long>) salaryAcctEmployeeIds, 200);
List<SalaryAcctResultPO> result = new ArrayList<>();
partition.forEach(empIds -> {
SalaryAcctResultPO build = SalaryAcctResultPO.builder().salaryAcctEmpIds(empIds).salaryItemIds(salaryItemIds).build();
@ -1007,10 +975,10 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
@Override
public List<Long> listAcctEmpIdByAcctEmpId(List<Long> salaryAcctEmployeeIds) {
if(CollectionUtils.isEmpty(salaryAcctEmployeeIds)){
if (CollectionUtils.isEmpty(salaryAcctEmployeeIds)) {
return Collections.emptyList();
}
List<List<Long>> partition = Lists.partition((List<Long>)salaryAcctEmployeeIds, 1000);
List<List<Long>> partition = Lists.partition((List<Long>) salaryAcctEmployeeIds, 1000);
List<Long> result = new ArrayList<>();
partition.forEach(empIds -> {
result.addAll(getSalaryAcctResultMapper().getAcctEmpIsExist(empIds));
@ -1047,15 +1015,15 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe
public Boolean checkAuth(Long salaryAcctRecordId) {
// 获取该核算记录的个税扣缴义务
SalaryAcctRecordPO recordPO = getSalaryAcctRecordService(user).getById(salaryAcctRecordId);
if(Objects.isNull(recordPO)) {
if (Objects.isNull(recordPO)) {
return false;
}
SalarySobPO salarySobPO = getSalarySobService(user).getById(recordPO.getSalarySobId());
Long taxAgentId = salarySobPO.getTaxAgentId();
List<TaxAgentAdminPO> adminTaxAgentList = getTaxAgentAdminService(user).listByEmployeeId(Long.valueOf(user.getUID()));
Optional<TaxAgentAdminPO> canOperate = adminTaxAgentList.stream().filter(po -> NumberUtils.compare(taxAgentId, po.getTaxAgentId()) == 0).findFirst();
if(!canOperate.isPresent()){
return false;
if (!canOperate.isPresent()) {
return false;
}
return true;
}

View File

@ -21,17 +21,15 @@ import java.util.List;
* @version 1.0
**/
public class SalaryAcctResultTempServiceImpl extends Service implements SalaryAcctResultTempService {
private SalaryAcctResultTempMapper getSalaryAcctResultTempMapper(){
private SalaryAcctResultTempMapper getSalaryAcctResultTempMapper() {
return MapperProxyFactory.getProxy(SalaryAcctResultTempMapper.class);
}
@Override
public List<SalaryAcctResultTempPO> listByCalculateKey(String calculateKey) {
if (StringUtils.isBlank(calculateKey)){
if (StringUtils.isBlank(calculateKey)) {
return Lists.newArrayList();
}
return getSalaryAcctResultTempMapper().listSome(SalaryAcctResultTempPO.builder().calculateKey(calculateKey).build());
@ -43,7 +41,7 @@ public class SalaryAcctResultTempServiceImpl extends Service implements SalaryAc
public void batchSave(Collection<SalaryAcctResultTempPO> salaryAcctResultTempPOS) {
if (CollectionUtils.isNotEmpty(salaryAcctResultTempPOS)) {
List<List<SalaryAcctResultTempPO>> partition = Lists.partition((List<SalaryAcctResultTempPO>) salaryAcctResultTempPOS, 100);
partition.forEach(p->getSalaryAcctResultTempMapper().batchInsert(p));
partition.forEach(p -> getSalaryAcctResultTempMapper().batchInsert(p));
}
}

View File

@ -74,6 +74,9 @@ import static java.util.concurrent.Executors.newFixedThreadPool;
**/
@Slf4j
public class SalarySysConfServiceImpl extends Service implements SalarySysConfService {
private static volatile Boolean encryptStatus = null;
private EncryptUtil encryptUtil = new EncryptUtil();
private SalarySysConfMapper getSalarySysConfMapper() {
@ -382,11 +385,15 @@ public class SalarySysConfServiceImpl extends Service implements SalarySysConfSe
@Override
public boolean encryptIsOpen() {
SalarySysConfPO sysConfPo = getOneByCode(SalarySysConstant.OPEN_APPLICATION_ENCRYPT);
if (sysConfPo != null && sysConfPo.getConfValue().equals(OpenEnum.OFF.getValue())) {
return false;
if (encryptStatus == null) {
SalarySysConfPO sysConfPo = getOneByCode(SalarySysConstant.OPEN_APPLICATION_ENCRYPT);
if (sysConfPo != null && sysConfPo.getConfValue().equals(OpenEnum.OFF.getValue())) {
encryptStatus = false;
} else {
encryptStatus = true;
}
}
return true;
return encryptStatus;
}
@Override
@ -447,7 +454,7 @@ public class SalarySysConfServiceImpl extends Service implements SalarySysConfSe
@Override
public List<SalarySysConfPO> getListByCodes(List<String> codes) {
if(CollectionUtils.isEmpty(codes)){
if (CollectionUtils.isEmpty(codes)) {
return Collections.emptyList();
}
return getSalarySysConfMapper().getListByCodes(codes);
@ -519,11 +526,11 @@ public class SalarySysConfServiceImpl extends Service implements SalarySysConfSe
}
SalarySysConfPO salaryAcctEmployeeRule = salarySysConfMap.get(SALARY_ACCT_EMPLOYEE_RULE);
if (salaryAcctEmployeeRule == null ) {
if (salaryAcctEmployeeRule == null) {
// 薪资核算人员匹配规则
appSettingVO.setSalaryAcctEmployeeRule(SalaryAcctEmployeeRuleEnum.BYPAYENDTIME.getValue());
} else {
appSettingVO.setSalaryAcctEmployeeRule( SalaryAcctEmployeeRuleEnum.parseByValue(salaryAcctEmployeeRule.getConfValue()).getValue() );
appSettingVO.setSalaryAcctEmployeeRule(SalaryAcctEmployeeRuleEnum.parseByValue(salaryAcctEmployeeRule.getConfValue()).getValue());
}
SalarySysConfPO withDrawRule = salarySysConfMap.get(WITHDRAW_TAX_DECLARATION);
@ -544,7 +551,7 @@ public class SalarySysConfServiceImpl extends Service implements SalarySysConfSe
SalarySysConfPO salarySendFeedbackPO = salarySysConfMap.get(SALARY_SEND_FEEDBACK);
if (salarySendFeedbackPO == null ) {
if (salarySendFeedbackPO == null) {
// 是否开启工资单反馈默认不开启
appSettingVO.setSalarySendFeedback("0");
} else {