diff --git a/src/com/engine/salary/service/impl/SISchemeServiceImpl.java b/src/com/engine/salary/service/impl/SISchemeServiceImpl.java index cf93763f7..22e584b4f 100644 --- a/src/com/engine/salary/service/impl/SISchemeServiceImpl.java +++ b/src/com/engine/salary/service/impl/SISchemeServiceImpl.java @@ -13,7 +13,7 @@ import com.engine.salary.constant.SalaryDefaultTenantConstant; import com.engine.salary.elog.entity.dto.LoggerContext; import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.datacollection.DataCollectionEmployee; -import com.engine.salary.entity.salaryitem.po.SalaryItemPO; +import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO; import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; import com.engine.salary.entity.siarchives.param.SIArchiveImportParam; import com.engine.salary.entity.siarchives.po.*; @@ -2376,50 +2376,54 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { * @param employeeId */ public void update(InsuranceSchemeReqParam updateParam, long employeeId) { - SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); - try { - InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class); - InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); - - //查询是否存在福利方案 - InsuranceSchemePO insuranceSchemePO = getById(updateParam.getInsuranceScheme().getId()); - if (Objects.isNull(insuranceSchemePO)) { - throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"福利方案不存在")); - } - //去除入参中方案名称的空格 - updateParam.getInsuranceScheme().setSchemeName(StringUtils.trim(updateParam.getInsuranceScheme().getSchemeName())); - //福利方案名称重复 - List insuranceSchemePOList = insuranceSchemeMapper.listByName(updateParam.getInsuranceScheme().getSchemeName()); - if (CollectionUtils.isNotEmpty(insuranceSchemePOList)) { - boolean repeat = insuranceSchemePOList.stream().anyMatch(item -> !Objects.equals(item.getId(), updateParam.getInsuranceScheme().getId())); - SalaryAssert.isTrue(!repeat, SalaryI18nUtil.getI18nLabel(0,"福利方案名称重复")); - } - - if (insuranceSchemePO.getSharedType() == null) { - insuranceSchemePO.setSharedType(SharedTypeEnum.PUBLIC.getValue()); - } else { - if (insuranceSchemePO.getSharedType().equals(SharedTypeEnum.PRIVATE.getValue()) && StringUtils.isBlank(insuranceSchemePO.getTaxAgentIds())) { - throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"方案可见性为私有时,未设置可见范围")); - } - } - - //更新福利方案主表 - InsuranceSchemePO insuranceSchemePO1 = InsuranceSchemeBO.buildInsuranceSchemePO(insuranceSchemePO, updateParam.getInsuranceScheme()); - insuranceSchemeMapper.update(insuranceSchemePO1); - - //更新福利方案明细表 先删后插 - insuranceSchemeDetailMapper.batchDeleteByPrimaryIds(Collections.singleton(updateParam.getInsuranceScheme().getId())); - //更新明细表 - List insuranceSchemeDetailPOS = InsuranceSchemeBO.convertToInsuranceSchemeDetailPoList(updateParam.getInsuranceSchemeDetailList(), employeeId, insuranceSchemePO.getId()); - encryptUtil.encryptList(insuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class); - insuranceSchemeDetailPOS.forEach(insuranceSchemeDetailMapper::insert); - - //记录操作日志 - - sqlSession.commit(); - } finally { - sqlSession.close(); + //查询是否存在福利方案 + InsuranceSchemePO insuranceSchemePO = getById(updateParam.getInsuranceScheme().getId()); + if (Objects.isNull(insuranceSchemePO)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"福利方案不存在")); } + //去除入参中方案名称的空格 + updateParam.getInsuranceScheme().setSchemeName(StringUtils.trim(updateParam.getInsuranceScheme().getSchemeName())); + //福利方案名称重复 + List insuranceSchemePOList = getInsuranceSchemeMapper().listByName(updateParam.getInsuranceScheme().getSchemeName()); + if (CollectionUtils.isNotEmpty(insuranceSchemePOList)) { + boolean repeat = insuranceSchemePOList.stream().anyMatch(item -> !Objects.equals(item.getId(), updateParam.getInsuranceScheme().getId())); + SalaryAssert.isTrue(!repeat, SalaryI18nUtil.getI18nLabel(0,"福利方案名称重复")); + } + + if (insuranceSchemePO.getSharedType() == null) { + insuranceSchemePO.setSharedType(SharedTypeEnum.PUBLIC.getValue()); + } else { + if (insuranceSchemePO.getSharedType().equals(SharedTypeEnum.PRIVATE.getValue()) && StringUtils.isBlank(insuranceSchemePO.getTaxAgentIds())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"方案可见性为私有时,未设置可见范围")); + } + } + //记录操作日志 + LoggerContext loggerContext = new LoggerContext<>(); + loggerContext.setUser(user); + loggerContext.setTargetId(insuranceSchemePO.getId().toString()); + loggerContext.setTargetName(insuranceSchemePO.getSchemeName()); + loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); + loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "福利方案保存")); + loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "福利方案保存") + ": " + insuranceSchemePO.getSchemeName()); + loggerContext.setOldValues(insuranceSchemePO); + //更新福利方案主表 + InsuranceSchemePO insuranceSchemePO1 = InsuranceSchemeBO.buildInsuranceSchemePO(insuranceSchemePO, updateParam.getInsuranceScheme()); + getInsuranceSchemeMapper().update(insuranceSchemePO1); + //记录操作日志 + loggerContext.setNewValues(insuranceSchemePO1); + SalaryElogConfig.salaryAcctRecordLoggerTemplate.write(loggerContext); + List oldInsuranceSchemeDetailPOS = getInsuranceSchemeDetailMapper().queryListBySchemeId(updateParam.getInsuranceScheme().getId()); + encryptUtil.decryptList(oldInsuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class); + + //更新福利方案明细表 先删后插 + getInsuranceSchemeDetailMapper().batchDeleteByPrimaryIds(Collections.singleton(updateParam.getInsuranceScheme().getId())); + //更新明细表 + List insuranceSchemeDetailPOS = InsuranceSchemeBO.convertToInsuranceSchemeDetailPoList(updateParam.getInsuranceSchemeDetailList(), employeeId, insuranceSchemePO.getId()); + encryptUtil.encryptList(insuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class); + insuranceSchemeDetailPOS.forEach(getInsuranceSchemeDetailMapper()::insert); + //记录操作日志, todo + + } public int checkBeforeDeleteSocialscheme(Map params) {