diff --git a/src/com/engine/salary/service/SICategoryService.java b/src/com/engine/salary/service/SICategoryService.java index dfaa84349..b1c9b37f7 100644 --- a/src/com/engine/salary/service/SICategoryService.java +++ b/src/com/engine/salary/service/SICategoryService.java @@ -3,10 +3,12 @@ package com.engine.salary.service; import com.engine.salary.entity.sicategory.dto.ICategoryDTO; import com.engine.salary.entity.sicategory.dto.ICategoryFormDTO; import com.engine.salary.entity.sicategory.dto.ICategoryListDTO; +import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.sischeme.param.InsuranceSchemeParam; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.util.page.PageInfo; +import java.util.List; import java.util.Map; /** @@ -65,4 +67,8 @@ public interface SICategoryService { Map updateCategoryNameAndPayScope(ICategoryFormDTO iCategoryFormDTO); Map deleteCustomCategory(ICategoryFormDTO iCategoryFormDTO); + + ICategoryPO getICategoryPOByID(Long id); + + List listByName(String insuranceName); } diff --git a/src/com/engine/salary/service/SISchemeService.java b/src/com/engine/salary/service/SISchemeService.java index 5e0b8d8de..e465d2740 100644 --- a/src/com/engine/salary/service/SISchemeService.java +++ b/src/com/engine/salary/service/SISchemeService.java @@ -8,6 +8,7 @@ import com.engine.salary.entity.sischeme.dto.InsuranceSchemeListDTO; import com.engine.salary.entity.sischeme.param.InsuranceSchemeDetailUpdateParam; import com.engine.salary.entity.sischeme.param.InsuranceSchemeParam; import com.engine.salary.entity.sischeme.po.InsuranceSchemeDetailPO; +import com.engine.salary.entity.sischeme.po.InsuranceSchemePO; import com.engine.salary.util.page.PageInfo; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -80,4 +81,6 @@ public interface SISchemeService { * @param schemeDetailList */ List updateSchemeDetail(List schemeDetailList); + + List listAll(); } diff --git a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java index 08b7fc624..f08af7c81 100644 --- a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java @@ -147,7 +147,7 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { return MapperProxyFactory.getProxy(TaxAgentMapper.class); } - SICategoryBiz siCategoryBiz = new SICategoryBiz(); +// SICategoryBiz siCategoryBiz = new SICategoryBiz(); private SalarySysConfMapper getSalarySysConfMapper() { return SqlProxyHandle.getProxy(SalarySysConfMapper.class); @@ -2027,7 +2027,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { String payScope = keyName.substring(keyName.length() - 2); //获取福利类型 Integer welfareType; - List categoryPOList = siCategoryBiz.listByName(entry.getKey().substring(0, keyName.length() - 2)); +// List categoryPOList = siCategoryBiz.listByName(entry.getKey().substring(0, keyName.length() - 2)); + List categoryPOList = getSICategoryService(user).listByName(entry.getKey().substring(0, keyName.length() - 2)); if (categoryPOList.size() == 1) { ICategoryPO iCategoryPO = categoryPOList.get(0); welfareType = iCategoryPO.getWelfareType(); @@ -3254,7 +3255,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { for (Map.Entry entry : toDealMap.entrySet()) { //获取福利项信息 - ICategoryPO iCategoryPO = siCategoryBiz.getByID(Long.valueOf(entry.getKey())); +// ICategoryPO iCategoryPO = siCategoryBiz.getByID(Long.valueOf(entry.getKey())); + ICategoryPO iCategoryPO = getSICategoryService(user).getICategoryPOByID(Long.valueOf(entry.getKey())); if (iCategoryPO != null) { String name = groupPrefix + iCategoryPO.getId().toString(); String label = iCategoryPO.getInsuranceName(); diff --git a/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java b/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java index 29859d236..798eed713 100644 --- a/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIArchivesServiceImpl.java @@ -16,8 +16,6 @@ import com.cloudstore.eccom.pc.table.WeaTableColumn; import com.cloudstore.eccom.result.WeaResultMsg; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; -import com.engine.salary.biz.SICategoryBiz; -import com.engine.salary.biz.SISchemeBiz; import com.engine.salary.cmd.siarchives.SIArchivesTipsCmd; import com.engine.salary.common.SalaryContext; import com.engine.salary.constant.SalaryDefaultTenantConstant; @@ -47,10 +45,7 @@ import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.mapper.sischeme.InsuranceSchemeDetailMapper; import com.engine.salary.mapper.sischeme.InsuranceSchemeMapper; import com.engine.salary.mapper.taxagent.TaxAgentMapper; -import com.engine.salary.service.SIArchivesService; -import com.engine.salary.service.SalaryEmployeeService; -import com.engine.salary.service.TaxAgentEmpChangeService; -import com.engine.salary.service.TaxAgentService; +import com.engine.salary.service.*; import com.engine.salary.sys.constant.SalarySysConstant; import com.engine.salary.sys.entity.po.SalarySysConfPO; import com.engine.salary.sys.entity.vo.OrderRuleVO; @@ -149,6 +144,14 @@ public class SIArchivesServiceImpl extends Service implements SIArchivesService return ServiceUtil.getService(TaxAgentWrapper.class, user); } + public SICategoryService getSICategoryService(User user) { + return ServiceUtil.getService(SICategoryServiceImpl.class, user); + } + + private SISchemeService getSISchemeService(User user) { + return ServiceUtil.getService(SISchemeServiceImpl.class,user); + } + @Override public Map getTips(Map params) { return commandExecutor.execute(new SIArchivesTipsCmd(params, user)); @@ -2249,8 +2252,8 @@ public class SIArchivesServiceImpl extends Service implements SIArchivesService return data; } - SISchemeBiz siSchemeBiz = new SISchemeBiz(); - List list = siSchemeBiz.listAll(); +// List list = siSchemeBiz.listAll(); + List list = getSISchemeService(user).listAll(); // 过滤可见性范围 list = filterList(list, taxAgentPOS); List selectItems = new ArrayList<>(); @@ -2671,9 +2674,9 @@ public class SIArchivesServiceImpl extends Service implements SIArchivesService } } - SICategoryBiz siCategoryBiz = new SICategoryBiz(); list.forEach(insuranceSchemeDetail -> { - ICategoryPO iCategoryPO = siCategoryBiz.getByID(insuranceSchemeDetail.getInsuranceId()); +// ICategoryPO iCategoryPO = siCategoryBiz.getByID(insuranceSchemeDetail.getInsuranceId()); + ICategoryPO iCategoryPO = getSICategoryService(user).getICategoryPOByID(insuranceSchemeDetail.getInsuranceId()); if (iCategoryPO != null) { // inputItems.add(SalaryFormItemUtil.inputNumberItem(user, "precision:2", 2, 12, 2, iCategoryPO.getInsuranceName(), String.valueOf(insuranceSchemeDetail.getInsuranceId()))); inputItems.add(SalaryFormItemUtil.inputNumberItemWithMaxAndMin(user, "precision:2", 2, 12, 2, iCategoryPO.getInsuranceName(), String.valueOf(insuranceSchemeDetail.getInsuranceId()) @@ -2690,9 +2693,9 @@ public class SIArchivesServiceImpl extends Service implements SIArchivesService } List list = queryListByPrimaryIdIsPayment(schemeId, welfareType).stream() .filter(f -> f.getPaymentScope().equals(PaymentScopeEnum.SCOPE_COMPANY.getValue())).collect(Collectors.toList()); - SICategoryBiz siCategoryBiz = new SICategoryBiz(); list.forEach(insuranceSchemeDetail -> { - ICategoryPO iCategoryPO = siCategoryBiz.getByID(insuranceSchemeDetail.getInsuranceId()); +// ICategoryPO iCategoryPO = siCategoryBiz.getByID(insuranceSchemeDetail.getInsuranceId()); + ICategoryPO iCategoryPO = getSICategoryService(user).getICategoryPOByID(insuranceSchemeDetail.getInsuranceId()); if (iCategoryPO != null) { // inputItems.add(SalaryFormItemUtil.inputNumberItem(user, "precision:2", 2, 12, 2, iCategoryPO.getInsuranceName(), String.valueOf(insuranceSchemeDetail.getInsuranceId()))); inputItems.add(SalaryFormItemUtil.inputNumberItemWithMaxAndMin(user, "precision:2", 2, 12, 2, iCategoryPO.getInsuranceName(), String.valueOf(insuranceSchemeDetail.getInsuranceId()) @@ -3484,7 +3487,8 @@ public class SIArchivesServiceImpl extends Service implements SIArchivesService public Map getSearchCondition() { List userStatusOptions = Arrays.stream(UserStatusEnum.values()).map(e -> new SearchConditionOption(String.valueOf(e.getValue()), e.getDefaultLabel())).collect(Collectors.toList()); - List list = new SISchemeBiz().listAll(); +// List list = new SISchemeBiz().listAll(); + List list = getSISchemeService(user).listAll(); List schemeOption = list.stream().filter(item -> Objects.equals(item.getWelfareType(), WelfareTypeEnum.SOCIAL_SECURITY.getValue())) .collect(Collectors.toList()) diff --git a/src/com/engine/salary/service/impl/SICategoryServiceImpl.java b/src/com/engine/salary/service/impl/SICategoryServiceImpl.java index 5cf300cf5..b610a2afb 100644 --- a/src/com/engine/salary/service/impl/SICategoryServiceImpl.java +++ b/src/com/engine/salary/service/impl/SICategoryServiceImpl.java @@ -1,19 +1,22 @@ package com.engine.salary.service.impl; +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.bean.SearchConditionOption; +import com.api.browser.util.ConditionFactory; +import com.api.browser.util.ConditionType; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; -import com.engine.salary.cmd.sicategory.SICategoryGetFormCmd; -import com.engine.salary.cmd.sicategory.SICategoryInsertCmd; -import com.engine.salary.cmd.sicategory.SICategoryUpdateCmd; -import com.engine.salary.cmd.sicategory.SICategoryUpdateStatusByIdCmd; import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO; +import com.engine.salary.entity.sicategory.bo.ICategoryBO; import com.engine.salary.entity.sicategory.dto.ICategoryDTO; import com.engine.salary.entity.sicategory.dto.ICategoryFormDTO; import com.engine.salary.entity.sicategory.dto.ICategoryListDTO; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.sischeme.param.InsuranceSchemeParam; +import com.engine.salary.entity.sischeme.po.InsuranceSchemeDetailPO; import com.engine.salary.enums.sicategory.DataTypeEnum; +import com.engine.salary.enums.sicategory.IsPaymentEnum; import com.engine.salary.enums.sicategory.PaymentScopeEnum; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.exception.SalaryRunTimeException; @@ -21,15 +24,19 @@ import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.service.RecordsBuildService; import com.engine.salary.service.SICategoryService; +import com.engine.salary.service.SISchemeService; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryEnumUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.engine.salary.util.page.PageInfo; import com.engine.salary.util.page.SalaryPageUtil; +import com.mzlion.core.utils.BeanUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.session.SqlSession; +import weaver.conn.mybatis.MyBatisFactory; import weaver.hrm.User; import java.util.*; @@ -57,24 +64,93 @@ public class SICategoryServiceImpl extends Service implements SICategoryService private EncryptUtil encryptUtil = new EncryptUtil(); + private SISchemeService getSISchemeService(User user) { + return ServiceUtil.getService(SISchemeServiceImpl.class,user); + } + @Override public Map getForm(Map params) { - return commandExecutor.execute(new SICategoryGetFormCmd(params,user)); +// return commandExecutor.execute(new SICategoryGetFormCmd(params,user)); + Map apidatas = new HashMap<>(16); + Long id = (Long) params.get("id"); +// ICategoryFormDTO form = siCategoryBiz.getForm(id); + ICategoryFormDTO form = getForm(id); + apidatas.put("form",form); + ConditionFactory conditionFactory = new ConditionFactory(user); + Map items = new HashMap<>(); + + SearchConditionItem input = conditionFactory.createCondition(ConditionType.INPUT,0, "insuranceName"); + input.setColSpan(2);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 + input.setFieldcol(12); //条件输入框所占宽度,默认值18 + input.setViewAttr(3); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 + input.setLength(10); // 设置输入长度 + input.setLabel(SalaryI18nUtil.getI18nLabel(0,"福利名称")); //设置文本值 这个将覆盖多语言标签的值 + input.setRules("required"); //设置字段填入规则 + + items.put("insuranceName",input); + + SearchConditionItem radio = conditionFactory.createCondition(ConditionType.RADIO,0,"welfareType"); + List radioOptions = new ArrayList <>(); + radioOptions.add(new SearchConditionOption("SOCIAL_SECURITY",SalaryI18nUtil.getI18nLabel(0,"社保"),true)); + radioOptions.add(new SearchConditionOption("ACCUMULATION_FUND",SalaryI18nUtil.getI18nLabel(0,"公积金"))); + radioOptions.add(new SearchConditionOption("OTHER",SalaryI18nUtil.getI18nLabel(0,"企业年金及其他福利"))); + radio.setColSpan(2); + radio.setFieldcol(12); + radio.setLabelcol(6); + radio.setViewAttr(3); + radio.setIsQuickSearch(false); + radio.setOptions(radioOptions); + radio.setLabel(SalaryI18nUtil.getI18nLabel(0,"类型")); + radio.setRules("required"); + items.put("welfareType",radio); + + SearchConditionItem checkbox = conditionFactory.createCondition(ConditionType.CHECKBOX,0,"paymentScope"); + List checkOptions = new ArrayList <>(); + checkOptions.add(new SearchConditionOption("SCOPE_COMPANY",SalaryI18nUtil.getI18nLabel(0,"公司"))); + checkOptions.add(new SearchConditionOption("SCOPE_PERSON",SalaryI18nUtil.getI18nLabel(0,"个人"))); + checkbox.setColSpan(2); + checkbox.setFieldcol(12); + checkbox.setLabelcol(6); + checkbox.setViewAttr(3); + checkbox.setIsQuickSearch(false); + checkbox.setOptions(checkOptions); + checkbox.setLabel(SalaryI18nUtil.getI18nLabel(0,"缴纳对象")); + checkbox.setRules("required"); + items.put("paymentScope",checkbox); + + apidatas.put("item",items); + return apidatas; } @Override public Map insert(Map params) { - return commandExecutor.execute(new SICategoryInsertCmd(params,user)); +// return commandExecutor.execute(new SICategoryInsertCmd(params,user)); + Map apidatas = new HashMap<>(16); + ICategoryFormDTO iCategoryFormDTO = (ICategoryFormDTO)params.get("iCategoryFormDTO"); +// siCategoryBiz.save(iCategoryFormDTO,(long) user.getUID()); + save(iCategoryFormDTO,(long) user.getUID()); + return apidatas; } @Override public Map update(Map params) { - return commandExecutor.execute(new SICategoryUpdateCmd(params,user)); +// return commandExecutor.execute(new SICategoryUpdateCmd(params,user)); + Map apidatas = new HashMap(16); + ICategoryFormDTO iCategoryFormDTO = (ICategoryFormDTO) params.get("iCategoryFormDTO"); +// siCategoryBiz.update(iCategoryFormDTO, (long) user.getUID()); + update(iCategoryFormDTO); + return apidatas; } @Override public Map updateStatusById(Map params) { - return commandExecutor.execute(new SICategoryUpdateStatusByIdCmd(params,user)); +// return commandExecutor.execute(new SICategoryUpdateStatusByIdCmd(params,user)); + Map apidatas = new HashMap(16); + Long id = (Long) params.get("id"); + Integer isUse = (Integer) params.get("isUse"); +// siCategoryBiz.updateStatusById(id, isUse,(long) user.getUID()); + updateStatusById(id, isUse); + return apidatas; } @Override @@ -238,4 +314,153 @@ public class SICategoryServiceImpl extends Service implements SICategoryService List collect = paymentScopes.stream().map(scope -> PaymentScopeEnum.getDefaultLabelByValue(SalaryEntityUtil.string2Integer(scope))).collect(Collectors.toList()); return StringUtils.join(collect, ","); } + /*****以下代码为SICategoryBiz中逻辑迁移,旨在减少Biz类的使用*****/ + + /** + * 自定义福利表单 + * id == null ? 新建表单 : 查看已有数据内容表单 + * @param id 自定义福利主键 + * @return 表单 + */ + public ICategoryFormDTO getForm(Long id) { + if (id != null) { + ICategoryPO iCategoryPO = getICategoryPOByID(id); + ICategoryFormDTO iCategoryFormDTO = new ICategoryFormDTO(); + if (Objects.isNull(iCategoryPO)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"数据不存在")); + } + BeanUtils.copyProperties(iCategoryPO,iCategoryFormDTO); + return iCategoryFormDTO; + } + + return ICategoryFormDTO.builder().welfareType(WelfareTypeEnum.SOCIAL_SECURITY).build(); + } + + /** + * 根据id获取 + * @param id + * @return + */ + @Override + public ICategoryPO getICategoryPOByID(Long id) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class); + ICategoryPO iCategoryPO = iCategoryMapper.getById(id); + return iCategoryPO; + + } finally { + sqlSession.close(); + } + } + + /** + * 根据名称获取 + * @param insuranceName + * @return + */ + @Override + public List listByName(String insuranceName) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + + try{ + ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class); + List iCategoryPOS = iCategoryMapper.listByName(insuranceName); + return iCategoryPOS; + + } finally { + sqlSession.close(); + } + } + + /** + * 保存 + * @param iCategoryFormDTO + * @param employeeId DataTypeEnum.SYSTEM.getValue() + */ + public void save(ICategoryFormDTO iCategoryFormDTO, long employeeId) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class); + iCategoryFormDTO.setInsuranceName(StringUtils.trim(iCategoryFormDTO.getInsuranceName())); + List iCategoryPOS = listByName(iCategoryFormDTO.getInsuranceName()); + if (CollectionUtils.isNotEmpty(iCategoryPOS)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"福利名称不允许重复")); + } + ICategoryPO iCategoryPO = ICategoryBO.convertToInsuranceCategoryPO(iCategoryFormDTO, employeeId); + iCategoryMapper.insert(iCategoryPO); + + sqlSession.commit(); + + } finally { + sqlSession.close(); + } + } + + /** + * 更新 + * @param iCategoryFormDTO + */ + public void update(ICategoryFormDTO iCategoryFormDTO) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try{ + if (iCategoryFormDTO.getId() == null) { + throw new SalaryRunTimeException("id is required"); + } + ICategoryPO iCategoryPO = getICategoryPOByID(iCategoryFormDTO.getId()); + if (Objects.isNull(iCategoryPO)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"数据不存在")); + } + List iCategoryPOS = listByName(iCategoryFormDTO.getInsuranceName()); + if (CollectionUtils.isNotEmpty(iCategoryPOS)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"福利名称不允许重复")); + } + iCategoryPO.setInsuranceName(iCategoryFormDTO.getInsuranceName()); +// iCategoryPO.setWelfareType(iCategoryFormDTO.getWelfareType().getValue()); +// iCategoryPO.setPaymentScope(SalaryEnumUtil.enumArrToString(iCategoryFormDTO.getPaymentScope())); + iCategoryPO.setUpdateTime(new Date()); + ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class); + iCategoryMapper.update(iCategoryPO); + + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + /** + * 更新状态 + * @param id + * @param isUse + */ + public void updateStatusById(Long id, Integer isUse) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + if(id == null) { + throw new SalaryRunTimeException("id is required"); + } + if (isUse == null) { + throw new SalaryRunTimeException("isUse is required"); + } +// List insuranceSchemeDetailPOS = new SISchemeBiz().queryListByInsuranceIdIsPayment(id, IsPaymentEnum.YES.getValue()); + List insuranceSchemeDetailPOS = getSISchemeService(user).queryListByInsuranceIdIsPayment(id, IsPaymentEnum.YES.getValue()); + if(CollectionUtils.isNotEmpty(insuranceSchemeDetailPOS) && isUse == 0) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"该福利开启缴费,不可删除(或停用)")); + } + ICategoryPO iCategoryPO = getICategoryPOByID(id); + if (Objects.isNull(iCategoryPO)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"数据记录不存在")); + } + iCategoryPO.setIsUse(isUse); + ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class); + iCategoryMapper.updateById(iCategoryPO); + + sqlSession.commit(); + }finally { + sqlSession.close(); + } + } + + /*****以上代码为SICategoryBiz中方法逻辑迁移,旨在减少Biz类的使用*****/ + } diff --git a/src/com/engine/salary/service/impl/SISchemeServiceImpl.java b/src/com/engine/salary/service/impl/SISchemeServiceImpl.java index 3ab971917..dbe70e770 100644 --- a/src/com/engine/salary/service/impl/SISchemeServiceImpl.java +++ b/src/com/engine/salary/service/impl/SISchemeServiceImpl.java @@ -4,10 +4,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.api.formmode.mybatis.util.SqlProxyHandle; import com.cloudstore.eccom.pc.table.WeaTableColumn; +import com.cloudstore.eccom.result.WeaResultMsg; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; -import com.engine.salary.biz.SISchemeBiz; -import com.engine.salary.cmd.sischeme.*; +import com.engine.salary.component.SalaryWeaTable; import com.engine.salary.constant.SalaryDefaultTenantConstant; import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.datacollection.DataCollectionEmployee; @@ -15,11 +15,17 @@ import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; import com.engine.salary.entity.siarchives.param.SIArchiveImportParam; import com.engine.salary.entity.siarchives.po.*; import com.engine.salary.entity.sicategory.po.ICategoryPO; +import com.engine.salary.entity.sischeme.bo.InsuranceSchemeBO; +import com.engine.salary.entity.sischeme.dto.InsuranceSchemeDTO; +import com.engine.salary.entity.sischeme.dto.InsuranceSchemeDetailDTO; import com.engine.salary.entity.sischeme.dto.InsuranceSchemeListDTO; import com.engine.salary.entity.sischeme.param.InsuranceSchemeDetailUpdateParam; import com.engine.salary.entity.sischeme.param.InsuranceSchemeParam; +import com.engine.salary.entity.sischeme.param.InsuranceSchemeReqParam; import com.engine.salary.entity.sischeme.po.InsuranceSchemeDetailPO; import com.engine.salary.entity.sischeme.po.InsuranceSchemePO; +import com.engine.salary.entity.sischeme.vo.InsuranceSchemeFormVO; +import com.engine.salary.entity.sischeme.vo.SISchemeTableVO; import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO; import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO; import com.engine.salary.entity.taxagent.param.TaxAgentManageRangeSaveParam; @@ -30,6 +36,7 @@ import com.engine.salary.enums.salarysob.TargetTypeEnum; import com.engine.salary.enums.siaccount.EmployeeStatusEnum; import com.engine.salary.enums.sicategory.*; import com.engine.salary.exception.SalaryRunTimeException; +import com.engine.salary.mapper.siaccount.SIAccountUtilMapper; import com.engine.salary.mapper.siarchives.FundSchemeMapper; import com.engine.salary.mapper.siarchives.InsuranceBaseInfoMapper; import com.engine.salary.mapper.siarchives.OtherSchemeMapper; @@ -60,16 +67,21 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; +import org.apache.ibatis.session.SqlSession; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.BeanUtils; +import weaver.conn.mybatis.MyBatisFactory; import weaver.file.ImageFileManager; +import weaver.general.Util; import weaver.hrm.User; import java.io.InputStream; +import java.math.BigDecimal; import java.util.*; import java.util.function.Function; +import java.util.regex.Pattern; import java.util.stream.Collectors; import static com.engine.salary.sys.constant.SalarySysConstant.WEL_BASE_AUTO_ADJUST; @@ -127,7 +139,7 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { } // private SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); - private SISchemeBiz siSchemeBiz = new SISchemeBiz(); +// private SISchemeBiz siSchemeBiz = new SISchemeBiz(); private SalaryEmployeeService getSalaryEmployeeService(User user) { return (SalaryEmployeeService) ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user); @@ -153,39 +165,134 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { return ServiceUtil.getService(SIArchivesServiceImpl.class,user); } + private SIAccountUtilMapper getSIAccountUtilMapper() { + return SqlProxyHandle.getProxy(SIAccountUtilMapper.class); + } + @Override public Map getForm(Map params) { - return commandExecutor.execute(new SISchemeGetFormCmd(params, user)); +// return commandExecutor.execute(new SISchemeGetFormCmd(params, user)); + Map apidatas = new HashMap<>(16); + + Long id = null; + if (Objects.nonNull(params.get("id"))) { + id =Long.valueOf(Util.null2String(params.get("id"))); + } + WelfareTypeEnum welfareTypeEnum = (WelfareTypeEnum)params.get("welfareTypeEnum"); +// InsuranceSchemeFormVO form = siSchemeBiz.getForm(id, welfareTypeEnum); + InsuranceSchemeFormVO form = getForm(id, welfareTypeEnum); + apidatas.put("form",form); + return apidatas; } @Override public Map insertScheme(Map params) { - return commandExecutor.execute(new SISchemeInsertCmd(params, user)); +// return commandExecutor.execute(new SISchemeInsertCmd(params, user)); + Map apidatas = new HashMap(16); + InsuranceSchemeReqParam insuranceSchemeReqParam = (InsuranceSchemeReqParam) params.get("insuranceSchemeReqParam"); +// siSchemeBiz.save(insuranceSchemeReqParam, (long) user.getUID()); + save(insuranceSchemeReqParam, (long) user.getUID()); + return apidatas; } @Override public Map update(Map params) { - return commandExecutor.execute(new SISchemeUpdateCmd(params, user)); +// return commandExecutor.execute(new SISchemeUpdateCmd(params, user)); + Map apidatas = new HashMap(16); + InsuranceSchemeReqParam insuranceSchemeReqParam = (InsuranceSchemeReqParam) params.get("insuranceSchemeReqParam"); +// siSchemeBiz.update(insuranceSchemeReqParam, (long) user.getUID()); + update(insuranceSchemeReqParam, (long) user.getUID()); + return apidatas; } @Override public Map delete(Map params) { - return commandExecutor.execute(new SISchemeDeleteCmd(params, user)); +// return commandExecutor.execute(new SISchemeDeleteCmd(params, user)); + Map apidatas = new HashMap(16); + Collection ids = (Collection)params.get("ids"); + if (CollectionUtils.isEmpty(ids)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"参数错误")); + } + //校验带上类型 + int welfareTypeId = (Integer) params.get("welfareTypeId"); + if(WelfareTypeEnum.SOCIAL_SECURITY.getValue() == welfareTypeId){ +// int num = siSchemeBiz.checkBeforeDeleteSocialscheme(params); + int num = checkBeforeDeleteSocialscheme(params); + if (num > 0){ + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"该社保方案已被使用")); + } + } + if(WelfareTypeEnum.ACCUMULATION_FUND.getValue() == welfareTypeId){ +// int accumulationfundNum = siSchemeBiz.checkBeforeDeleteAccumulationfund(params); + int accumulationfundNum = checkBeforeDeleteAccumulationfund(params); + if (accumulationfundNum > 0){ + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"该公积金方案已被使用")); + } + } + if(WelfareTypeEnum.OTHER.getValue() == welfareTypeId){ +// int otherschemeNum = siSchemeBiz.checkBeforeDeleteOtherscheme(params); + int otherschemeNum = checkBeforeDeleteOtherscheme(params); + if (otherschemeNum > 0){ + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"该其他福利方案已被使用")); + } + } + +// int billNum = siSchemeBiz.checkBeforeDeleteBill(params,welfareTypeId); + int billNum = checkBeforeDeleteBill(params,welfareTypeId); + if (billNum > 0){ + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"该福利方案已被核算")); + } +// siSchemeBiz.deleteSocialscheme(params); + deleteSocialscheme(params); + + return apidatas; } @Override public Map copyScheme(Map params) { - return commandExecutor.execute(new SISchemeCopyCmd(params, user)); +// return commandExecutor.execute(new SISchemeCopyCmd(params, user)); + Map apidatas = new HashMap(16); + Long id = (Long) params.get("id"); + String schemeName = Util.null2String(params.get("schemeName")); +// siSchemeBiz.copy(id,schemeName,(long) user.getUID()); + copy(id,schemeName,(long) user.getUID()); + return apidatas; } @Override public List queryListByInsuranceIdIsPayment(Long insuranceId, Integer isPayment) { - return new SISchemeBiz().queryListByInsuranceIdIsPayment(insuranceId, isPayment); +// return new SISchemeBiz().queryListByInsuranceIdIsPayment(insuranceId, isPayment); + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); + List insuranceSchemeDetailPOList = insuranceSchemeDetailMapper.queryListByInsuranceIdIsPayment(insuranceId, isPayment); + encryptUtil.decryptList(insuranceSchemeDetailPOList, InsuranceSchemeDetailPO.class); + return insuranceSchemeDetailPOList; + } finally { + sqlSession.close(); + } } @Override public Map listPage(Map params) { - return commandExecutor.execute(new SISchemeListCmd(params, user)); +// return commandExecutor.execute(new SISchemeListCmd(params, user)); + SalaryWeaTable table = new SalaryWeaTable<>(user,SISchemeTableVO.class); + String sqlWhere = buildSqlWhere(params); + table.setSqlwhere(sqlWhere); + + WeaResultMsg result = new WeaResultMsg(false); + result.putAll(table.makeDataResult()); + result.success(); + return result.getResultMap(); + } + + private String buildSqlWhere(Map params) { + String sqlWhere = "where a.id = b.primary_id and b.insurance_id = c.id and a.delete_Type = 0"; + Integer welfareType = (Integer)params.get("welfareType"); + if (Objects.nonNull(welfareType)){ + sqlWhere += " and a.welfare_type ="+welfareType; + } + return sqlWhere; } @Override @@ -1991,7 +2098,8 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { schemeDetailList.forEach(f -> { schemeDetailUpdateMap.put(f.getInsuranceId() + "-" + f.getPaymentScope(), f); }); - List schemeDetailPOS = siSchemeBiz.listByPrimaryId(primaryId); +// List schemeDetailPOS = siSchemeBiz.listByPrimaryId(primaryId); + List schemeDetailPOS = listByPrimaryId(primaryId); //替换修改字段 if (schemeDetailPOS.size() > 0) { schemeDetailPOS.forEach(f -> { @@ -2012,5 +2120,423 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { } return errorInfo; } + /*****以下代码为SISchemeBiz中逻辑迁移,旨在减少Biz类的使用*****/ + /** + * 获取社保方案 + * + * @param id + * @param welfareTypeEnum + * @return + */ + public InsuranceSchemeFormVO getForm(Long id, WelfareTypeEnum welfareTypeEnum) { + InsuranceSchemeDTO insuranceSchemeDTO = getSchemeFormDTO(welfareTypeEnum, id); + List insuranceSchemeDetailDTOList = getSchemeDetailFormDTO(welfareTypeEnum, id); + return InsuranceSchemeFormVO.builder().schemeBatch(insuranceSchemeDTO).schemeDetailList(insuranceSchemeDetailDTOList).build(); + } + + /** + * 获取方案主表信息 新建|详情 + * + * @param welfareTypeEnum 福利类型 + * @param id 方案主键id + * @return form + */ + private InsuranceSchemeDTO getSchemeFormDTO(WelfareTypeEnum welfareTypeEnum, Long id) { + InsuranceSchemeDTO insuranceSchemeDTO = InsuranceSchemeDTO.builder().paymentType(PaymentTypeEnum.SCHEME_TOWN).welfareType(welfareTypeEnum).build(); + if (id != null) { + InsuranceSchemePO insuranceSchemePO = getById(id); + SalaryAssert.notNull(insuranceSchemePO, SalaryI18nUtil.getI18nLabel(0,"福利方案不存在")); + //BeanUtils.copyProperties(insuranceSchemePO, insuranceSchemeDTO); + insuranceSchemeDTO.setId(insuranceSchemePO.getId()); + insuranceSchemeDTO.setPaymentArea(insuranceSchemePO.getPaymentArea()); + insuranceSchemeDTO.setRemarks(insuranceSchemePO.getRemarks()); + insuranceSchemeDTO.setSchemeName(insuranceSchemePO.getSchemeName()); + insuranceSchemeDTO.setPaymentType(SalaryEnumUtil.enumMatchByValue(insuranceSchemePO.getPaymentType(), PaymentTypeEnum.values(), PaymentTypeEnum.class)); + insuranceSchemeDTO.setWelfareType(welfareTypeEnum); + insuranceSchemeDTO.setSharedType(StringUtils.isBlank(insuranceSchemePO.getSharedType()) ? "0" : insuranceSchemePO.getSharedType()); + insuranceSchemeDTO.setTaxAgentIds(insuranceSchemePO.getTaxAgentIds()); + } + return insuranceSchemeDTO; + } + + /** + * 获取方案明细表集合 新建|详情 + * + * @param welfareTypeEnum 福利类型 + * @param id 方案主键id + * @return form + */ + public List getSchemeDetailFormDTO(WelfareTypeEnum welfareTypeEnum, Long id) { + List insuranceCategoryPOS = listByWelfareType(welfareTypeEnum.getValue()); + List insuranceSchemeDetailDTOList = new ArrayList<>(); + insuranceCategoryPOS.forEach(item -> { + PaymentScopeEnum[] paymentScopeEnums = SalaryEnumUtil.stringToEnums(item.getPaymentScope(), ","); + Arrays.stream(paymentScopeEnums).forEach(e -> { + InsuranceSchemeDetailDTO insuranceSchemeDetailDTO = InsuranceSchemeDetailDTO.builder().build(); + InsuranceSchemeDetailPO insuranceSchemeDetailPO = getByPPI(id, e.getValue(), item.getId()); + if (insuranceSchemeDetailPO == null) { + insuranceSchemeDetailDTO = InsuranceSchemeDetailDTO.builder() + .id((long) (Math.random() * 10000)) + .insuranceId(item.getId()) + .insuranceName(item.getInsuranceName()) + .paymentScope(e.getDefaultLabel()) + .rententionRule(String.valueOf(RententionRuleEnum.ROUND.getValue())) + .cycleSetting("000000000000") + .paymentCycle("0") + .accountType("0") + .build(); + if (Objects.equals(item.getDataType(), DataTypeEnum.SYSTEM.getValue())) { + insuranceSchemeDetailDTO.setIsPayment(true); + } else { + insuranceSchemeDetailDTO.setIsPayment(false); + } + } else { + //BeanUtils.copyProperties(insuranceSchemeDetailPO, insuranceSchemeDetailDTO); + insuranceSchemeDetailDTO.setEffectiveTime(insuranceSchemeDetailPO.getEffectiveTime()); + insuranceSchemeDetailDTO.setExpirationTime(insuranceSchemeDetailPO.getExpirationTime()); + insuranceSchemeDetailDTO.setId(insuranceSchemeDetailPO.getId()); + insuranceSchemeDetailDTO.setInsuranceId(insuranceSchemeDetailPO.getInsuranceId()); + insuranceSchemeDetailDTO.setPaymentScopeValue(insuranceSchemeDetailPO.getPaymentScope()); + insuranceSchemeDetailDTO.setPrimaryId(insuranceSchemeDetailPO.getPrimaryId()); + insuranceSchemeDetailDTO.setValidNum(insuranceSchemeDetailPO.getValidNum()); + + if (insuranceSchemeDetailPO.getIsPayment() != null) { + insuranceSchemeDetailDTO.setIsPayment(Objects.equals(insuranceSchemeDetailPO.getIsPayment(), IsPaymentEnum.YES.getValue())); + } + if (insuranceSchemeDetailPO.getPaymentCycle() != null) { + insuranceSchemeDetailDTO.setPaymentCycle(insuranceSchemeDetailPO.getPaymentCycle() + ""); + } else { + insuranceSchemeDetailDTO.setPaymentCycle("0"); + } + if (insuranceSchemeDetailPO.getAccountType() != null) { + insuranceSchemeDetailDTO.setAccountType(insuranceSchemeDetailPO.getAccountType() + ""); + } else { + insuranceSchemeDetailDTO.setAccountType("0"); + } + if (insuranceSchemeDetailPO.getCycleSetting() == null) { + insuranceSchemeDetailDTO.setCycleSetting("000000000000"); + } else { + insuranceSchemeDetailDTO.setCycleSetting(insuranceSchemeDetailPO.getCycleSetting()); + } + if (StringUtils.isNotBlank(insuranceSchemeDetailPO.getUpperLimit())) { + BigDecimal bigDecimal = new BigDecimal(insuranceSchemeDetailPO.getUpperLimit()); + insuranceSchemeDetailDTO.setUpperLimit(numberCheck(bigDecimal.toPlainString()) ? null : bigDecimal); + } + if (StringUtils.isNotBlank(insuranceSchemeDetailPO.getLowerLimit())) { + BigDecimal bigDecimal = new BigDecimal(insuranceSchemeDetailPO.getLowerLimit()); + insuranceSchemeDetailDTO.setLowerLimit(numberCheck(bigDecimal.toPlainString()) ? null : bigDecimal); + } + if (StringUtils.isNotBlank(insuranceSchemeDetailPO.getPaymentProportion())) { + BigDecimal bigDecimal = new BigDecimal(insuranceSchemeDetailPO.getPaymentProportion()); + insuranceSchemeDetailDTO.setPaymentProportion(numberCheck(bigDecimal.toPlainString()) ? null : bigDecimal); + } + if (StringUtils.isNotBlank(insuranceSchemeDetailPO.getFixedCost())) { + BigDecimal bigDecimal = new BigDecimal(insuranceSchemeDetailPO.getFixedCost()); + insuranceSchemeDetailDTO.setFixedCost(numberCheck(bigDecimal.toPlainString()) ? null : bigDecimal); + } + insuranceSchemeDetailDTO.setInsuranceName(item.getInsuranceName()); + insuranceSchemeDetailDTO.setRententionRule(String.valueOf(insuranceSchemeDetailPO.getRententionRule())); + insuranceSchemeDetailDTO.setPaymentScope(e.getDefaultLabel()); + + } + insuranceSchemeDetailDTO.setPaymentScopeValue(e.getValue()); + insuranceSchemeDetailDTOList.add(insuranceSchemeDetailDTO); + }); + }); + return insuranceSchemeDetailDTOList; + } + + /** + * 社保方案基础信息主表 + * + * @param id + * @return + */ + public InsuranceSchemePO getById(Long id) { + + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class); + InsuranceSchemePO insuranceSchemePO = insuranceSchemeMapper.getById(id); + + return insuranceSchemePO; + } finally { + sqlSession.close(); + } + } + + /** + * 根据福利类型获取 + * + * @param welfareType + * @return + */ + public List listByWelfareType(Integer welfareType) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class); + List insuranceCategoryPOS = iCategoryMapper.listByWelfareType(welfareType, null); + return insuranceCategoryPOS; + } finally { + sqlSession.close(); + } + } + + public boolean numberCheck(String number) { + return Pattern.compile("^0\\.[0]*").matcher(number).matches(); + } + + private InsuranceSchemeDetailPO getByPPI(Long primaryId, Integer paymentScope, Long insuranceId) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); + InsuranceSchemeDetailPO insuranceSchemeDetailPO = insuranceSchemeDetailMapper.getByPPI(primaryId, paymentScope, insuranceId); + encryptUtil.decrypt(insuranceSchemeDetailPO, InsuranceSchemeDetailPO.class); + return insuranceSchemeDetailPO; + } finally { + sqlSession.close(); + } + } + + /** + * 新增 + * + * @param saveParam + * @param employeeId + */ + public void save(InsuranceSchemeReqParam saveParam, long employeeId) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + //保存福利项目主表 + InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class); + saveParam.getInsuranceScheme().setSchemeName(StringUtils.trim(saveParam.getInsuranceScheme().getSchemeName())); + List listResult = insuranceSchemeMapper.listByName(saveParam.getInsuranceScheme().getSchemeName()); + SalaryAssert.isEmpty(listResult, SalaryI18nUtil.getI18nLabel(0,"该福利名称已经存在,福利名称系统全局唯一")); + + InsuranceSchemePO insuranceSchemePO = InsuranceSchemeBO.convert2BatchPO(saveParam.getInsuranceScheme(), employeeId); + 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,"方案可见性为私有时,未设置可见范围")); + } + } + insuranceSchemeMapper.insert(insuranceSchemePO); + //保存福利项目明细表 + InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); + List insuranceSchemeDetailPOS = InsuranceSchemeBO.convertToInsuranceSchemeDetailPoList(saveParam.getInsuranceSchemeDetailList(), employeeId, insuranceSchemePO.getId()); + encryptUtil.encryptList(insuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class); + insuranceSchemeDetailPOS.forEach(insuranceSchemeDetailMapper::insert); + + sqlSession.commit(); + + } finally { + sqlSession.close(); + } + } + + /** + * 更新 + * + * @param updateParam + * @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(); + } + } + + public int checkBeforeDeleteSocialscheme(Map params) { + return getSIAccountUtilMapper().checkBeforeDeleteSocialscheme((Collection) params.get("ids")).get(0).getNum(); + } + + public int checkBeforeDeleteAccumulationfund(Map params) { + return getSIAccountUtilMapper().checkBeforeDeleteAccumulationfund((Collection) params.get("ids")).get(0).getNum(); + } + + public int checkBeforeDeleteOtherscheme(Map params) { + return getSIAccountUtilMapper().checkBeforeDeleteOtherscheme((Collection) params.get("ids")).get(0).getNum(); + } + + public int checkBeforeDeleteBill(Map params, Integer welfareTypeId) { + return getSIAccountUtilMapper().checkBeforeDeleteBill((Collection) params.get("ids"), welfareTypeId).get(0).getNum(); + } + + public void deleteSocialscheme(Map params) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); + InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class); + + insuranceSchemeMapper.deleteByIds((Collection) params.get("ids")); + insuranceSchemeDetailMapper.deleteByIds((Collection) params.get("ids")); + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + /** + * 复制方案 + * + * @param id + * @param schemeName + * @param employeeId + */ + public void copy(Long id, String schemeName, long employeeId) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class); + //去除入参中方案名称的空格 + schemeName = StringUtils.trim(schemeName); + + List listResult = insuranceSchemeMapper.listByName(schemeName); + SalaryAssert.isEmpty(listResult, SalaryI18nUtil.getI18nLabel(0,"方案名称重复")); + + InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); + if (Objects.isNull(id)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"方案id为空")); + } + + if (Objects.isNull(schemeName)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"复制方案名为空")); + } + + InsuranceSchemePO insuranceSchemePO = getById(id); + if (Objects.isNull(insuranceSchemePO)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"方案不存在")); + } + + if (insuranceSchemePO.getSchemeName().equals(schemeName)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0,"方案名称重复")); + } + + InsuranceSchemePO batchPO = InsuranceSchemePO.builder() + .creator(employeeId) + .createTime(new Date()) + .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) + .schemeName(schemeName) + .paymentArea(insuranceSchemePO.getPaymentArea()) + .updateTime(new Date()) + .deleteType(DeleteTypeEnum.NOT_DELETED.getValue()) + .paymentType(insuranceSchemePO.getPaymentType()) + .remarks(insuranceSchemePO.getRemarks()) + .welfareType(insuranceSchemePO.getWelfareType()) + .isUse(insuranceSchemePO.getIsUse()) + .build(); + insuranceSchemeMapper.insert(batchPO); + + List detailList = insuranceSchemeDetailMapper.queryListBySchemeId(id); + detailList = encryptUtil.decryptList(detailList,InsuranceSchemeDetailPO.class); + if (CollectionUtils.isNotEmpty(detailList)) { + List detailPOS = detailList.stream().map(item -> InsuranceSchemeDetailPO.builder() + .creator(employeeId) + .createTime(new Date()) + .deleteType(DeleteTypeEnum.NOT_DELETED.getValue()) + .effectiveTime(item.getEffectiveTime()) + .expirationTime(item.getExpirationTime()) + .fixedCost(item.getFixedCost()) + .insuranceId(item.getInsuranceId()) + .isPayment(item.getIsPayment()) + .lowerLimit(item.getLowerLimit()) + .paymentScope(item.getPaymentScope()) + .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) + .paymentProportion(item.getPaymentProportion()) + .updateTime(new Date()) + .primaryId(batchPO.getId()) + .rententionRule(item.getRententionRule()) + .upperLimit(item.getUpperLimit()) + .validNum(item.getValidNum()) + .build() + ).collect(Collectors.toList()); + encryptUtil.encryptList(detailPOS, InsuranceSchemeDetailPO.class); + detailPOS.forEach(insuranceSchemeDetailMapper::insert); + } + + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + /** + * 社保方案基础信息明细表 + * + * @param primaryId + * @return + */ + public List listByPrimaryId(Long primaryId) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class); + List insuranceSchemeDetailPOS = insuranceSchemeDetailMapper.queryListBySchemeId(primaryId); + encryptUtil.decryptList(insuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class); + return insuranceSchemeDetailPOS; + } finally { + sqlSession.close(); + } + + } + + /** + * 获取所有方案 + * + * @return + */ + @Override + public List listAll(){ + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class); + List insuranceSchemePOList = insuranceSchemeMapper.listAll(); + return insuranceSchemePOList; + } finally { + sqlSession.close(); + } + } + + /*****以上代码为SISchemeBiz中方法逻辑迁移,旨在减少Biz类的使用*****/ }