package com.engine.salary.biz;

import com.api.formmode.mybatis.util.SqlProxyHandle;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
import com.engine.salary.encrypt.EncryptUtil;
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.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.enums.SalaryRoundingModeEnum;
import com.engine.salary.enums.sicategory.*;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.siaccount.SIAccountUtilMapper;
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.util.SalaryAssert;
import com.engine.salary.util.SalaryEnumUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import weaver.conn.mybatis.MyBatisFactory;

import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


/**
 * @Author weaver_cl
 * @Date 2022/3/7
 * @Version V1.0
 **/
public class SISchemeBiz {

    private SIAccountUtilMapper getSIAccountUtilMapper() {
        return SqlProxyHandle.getProxy(SIAccountUtilMapper.class);
    }

    private EncryptUtil encryptUtil = new EncryptUtil();

    /**
     * 获取社保方案
     *
     * @param id
     * @param welfareTypeEnum
     * @return
     */
    public InsuranceSchemeFormVO getForm(Long id, WelfareTypeEnum welfareTypeEnum) {
        InsuranceSchemeDTO insuranceSchemeDTO = getSchemeFormDTO(welfareTypeEnum, id);
        List<InsuranceSchemeDetailDTO> insuranceSchemeDetailDTOList = getSchemeDetailFormDTO(welfareTypeEnum, id);
        return InsuranceSchemeFormVO.builder().schemeBatch(insuranceSchemeDTO).schemeDetailList(insuranceSchemeDetailDTOList).build();
    }

    /**
     * 获取方案明细表集合 新建|详情
     *
     * @param welfareTypeEnum 福利类型
     * @param id              方案主键id
     * @return form
     */
    public List<InsuranceSchemeDetailDTO> getSchemeDetailFormDTO(WelfareTypeEnum welfareTypeEnum, Long id) {
        List<ICategoryPO> insuranceCategoryPOS = listByWelfareType(welfareTypeEnum.getValue());
        List<InsuranceSchemeDetailDTO> 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(SalaryRoundingModeEnum.ROUNDING.getValue()))
                            .validNum(2)
                            .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() == null ? 2 : 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 welfareType
     * @return
     */
    public List<ICategoryPO> listByWelfareType(Integer welfareType) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            ICategoryMapper iCategoryMapper = sqlSession.getMapper(ICategoryMapper.class);
            List<ICategoryPO> 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 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, "福利方案不存在");
            //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 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();
        }
    }


    /**
     * 获取所有方案
     *
     * @return
     */
    public List<InsuranceSchemePO> listAll(){
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class);
            List<InsuranceSchemePO> insuranceSchemePOList = insuranceSchemeMapper.listAll();
            return insuranceSchemePOList;
        } finally {
            sqlSession.close();
        }
    }


    /**
     * 社保方案基础信息明细表
     *
     * @param primaryId
     * @return
     */
    public List<InsuranceSchemeDetailPO> listByPrimaryId(Long primaryId) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class);
            List<InsuranceSchemeDetailPO> insuranceSchemeDetailPOS = insuranceSchemeDetailMapper.queryListBySchemeId(primaryId);
            encryptUtil.decryptList(insuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class);
//            return decryptSchemeDetailList(insuranceSchemeDetailPOS);
            return insuranceSchemeDetailPOS;
        } 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<InsuranceSchemePO> listResult = insuranceSchemeMapper.listByName(saveParam.getInsuranceScheme().getSchemeName());
            SalaryAssert.isEmpty(listResult, "该福利名称已经存在,福利名称系统全局唯一");

            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("方案可见性为私有时，未设置可见范围");
                }
            }


            insuranceSchemeMapper.insert(insuranceSchemePO);


            //保存福利项目明细表
            InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class);
            List<InsuranceSchemeDetailPO> 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("福利方案不存在");
            }
            //去除入参中方案名称的空格
            updateParam.getInsuranceScheme().setSchemeName(StringUtils.trim(updateParam.getInsuranceScheme().getSchemeName()));
            //福利方案名称重复
            List<InsuranceSchemePO> 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, "福利方案名称重复");
            }

            if (insuranceSchemePO.getSharedType() == null) {
                insuranceSchemePO.setSharedType(SharedTypeEnum.PUBLIC.getValue());
            } else {
                if (insuranceSchemePO.getSharedType().equals(SharedTypeEnum.PRIVATE.getValue()) && StringUtils.isBlank(insuranceSchemePO.getTaxAgentIds())) {
                    throw new SalaryRunTimeException("方案可见性为私有时，未设置可见范围");
                }
            }

            //更新福利方案主表
            InsuranceSchemePO insuranceSchemePO1 = InsuranceSchemeBO.buildInsuranceSchemePO(insuranceSchemePO, updateParam.getInsuranceScheme());
            insuranceSchemeMapper.update(insuranceSchemePO1);

            //更新福利方案明细表 先删后插
            insuranceSchemeDetailMapper.batchDeleteByPrimaryIds(Collections.singleton(updateParam.getInsuranceScheme().getId()));
            //更新明细表
            List<InsuranceSchemeDetailPO> insuranceSchemeDetailPOS = InsuranceSchemeBO.convertToInsuranceSchemeDetailPoList(updateParam.getInsuranceSchemeDetailList(), employeeId, insuranceSchemePO.getId());
            encryptUtil.encryptList(insuranceSchemeDetailPOS, InsuranceSchemeDetailPO.class);
            insuranceSchemeDetailPOS.forEach(insuranceSchemeDetailMapper::insert);

            //记录操作日志

            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<InsuranceSchemePO> listResult = insuranceSchemeMapper.listByName(schemeName);
            SalaryAssert.isEmpty(listResult, "方案名称重复");

            InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class);
            if (Objects.isNull(id)) {
                throw new SalaryRunTimeException("方案id为空");
            }

            if (Objects.isNull(schemeName)) {
                throw new SalaryRunTimeException("复制方案名为空");
            }

            InsuranceSchemePO insuranceSchemePO = getById(id);
            if (Objects.isNull(insuranceSchemePO)) {
                throw new SalaryRunTimeException("方案不存在");
            }

            if (insuranceSchemePO.getSchemeName().equals(schemeName)) {
                throw new SalaryRunTimeException("方案名称重复");
            }

            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<InsuranceSchemeDetailPO> detailList = insuranceSchemeDetailMapper.queryListBySchemeId(id);
            detailList = encryptUtil.decryptList(detailList,InsuranceSchemeDetailPO.class);
            if (CollectionUtils.isNotEmpty(detailList)) {
                List<InsuranceSchemeDetailPO> 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()==null?2:item.getValidNum())
                        .build()
                ).collect(Collectors.toList());
                encryptUtil.encryptList(detailPOS, InsuranceSchemeDetailPO.class);
                detailPOS.forEach(insuranceSchemeDetailMapper::insert);
            }

            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }

    /**
     * 根据险种id和是否缴费查询社保方案明细表
     *
     * @param insuranceId 险种id
     * @param isPayment   是否缴费
     * @return list
     */
    public List<InsuranceSchemeDetailPO> queryListByInsuranceIdIsPayment(Long insuranceId, Integer isPayment) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {
            InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class);
            List<InsuranceSchemeDetailPO> insuranceSchemeDetailPOList = insuranceSchemeDetailMapper.queryListByInsuranceIdIsPayment(insuranceId, isPayment);
            encryptUtil.decryptList(insuranceSchemeDetailPOList, InsuranceSchemeDetailPO.class);
            return insuranceSchemeDetailPOList;
        } finally {
            sqlSession.close();
        }

    }

    public int checkBeforeDeleteSocialscheme(Map<String, Object> params) {
        return getSIAccountUtilMapper().checkBeforeDeleteSocialscheme((Collection<Long>) params.get("ids")).get(0).getNum();
    }

    public int checkBeforeDeleteAccumulationfund(Map<String, Object> params) {
        return getSIAccountUtilMapper().checkBeforeDeleteAccumulationfund((Collection<Long>) params.get("ids")).get(0).getNum();
    }

    public int checkBeforeDeleteOtherscheme(Map<String, Object> params) {
        return getSIAccountUtilMapper().checkBeforeDeleteOtherscheme((Collection<Long>) params.get("ids")).get(0).getNum();
    }

    public int checkBeforeDeleteBill(Map<String, Object> params, Integer welfareTypeId) {
        return getSIAccountUtilMapper().checkBeforeDeleteBill((Collection<Long>) params.get("ids"), welfareTypeId).get(0).getNum();
    }

    public void deleteSocialscheme(Map<String, Object> params) {
        SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
        try {

            InsuranceSchemeDetailMapper insuranceSchemeDetailMapper = sqlSession.getMapper(InsuranceSchemeDetailMapper.class);
            InsuranceSchemeMapper insuranceSchemeMapper = sqlSession.getMapper(InsuranceSchemeMapper.class);

            insuranceSchemeMapper.deleteByIds((Collection<Long>) params.get("ids"));
            insuranceSchemeDetailMapper.deleteByIds((Collection<Long>) params.get("ids"));
            sqlSession.commit();
        } finally {
            sqlSession.close();
        }
    }


}
