package com.jeequan.jeepay.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeequan.jeepay.converter.BaseConverter;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.IsvInfo;
import com.jeequan.jeepay.core.entity.IsvUserConn;
import com.jeequan.jeepay.core.entity.SysUser;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.DBDefaultConfig;
import com.jeequan.jeepay.db.entity.*;
import com.jeequan.jeepay.service.mapper.IsvInfoMapper;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务商信息表 服务实现类
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2021-04-27
 */
@Service
public class IsvInfoService extends ServiceImpl<IsvInfoMapper, IsvInfoEntity> {

    @Autowired
    private IsvUserConnService isvUserConnService;

    @Autowired
    private MchInfoService mchInfoService;

    @Autowired
    private PayInterfaceConfigService payInterfaceConfigService;

    @Autowired
    private BaseConverter baseConverter;

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private RateConfigService rateConfigService;

    @Autowired
    private AgentInfoService agentInfoService;
    @Autowired
    private IsvUserConnDisabledService isvUserConnDisabledService;
    @Autowired
    private PayInterfaceDefineService payInterfaceDefineService;
    @Autowired
    private TransferInterfaceDefineService transferInterfaceDefineService;
    @Autowired
    private TransferInterfaceConfigService transferInterfaceConfigService;

    public Map<String, IsvUserConn> getIsvUserConn(String infoType, String infoId, @Nullable Byte status) {
        if (infoType.equals(CS.SYS_ROLE_TYPE.AGENT) || infoType.equals(CS.SYS_ROLE_TYPE.MCH)) {
            Map<String, IsvUserConn> isvUserConnMap = isvUserConnService.getBaseMapper().selectNotIsvIfCode(infoType, infoId, status);
            return isvUserConnMap == null ? new HashMap<>() : isvUserConnMap;
        }

        if (infoType.equals(CS.SYS_ROLE_TYPE.ISV)) {
            Map<String, IsvUserConn> isvUserConnMap = isvUserConnService.getBaseMapper().selectIsvIfCode(infoId, status);
            return isvUserConnMap == null ? new HashMap<>() : isvUserConnMap;
        }

        return new HashMap<>();
    }

    public Map<String, IsvUserConn> getTransIsvUserConn(String infoType, String infoId, @Nullable Byte status) {
        if (infoType.equals(CS.SYS_ROLE_TYPE.AGENT) || infoType.equals(CS.SYS_ROLE_TYPE.MCH)) {
            Map<String, IsvUserConn> isvUserConnMap = isvUserConnService.getBaseMapper().selectTransNotIsvIfCode(infoType, infoId, status);
            return isvUserConnMap == null ? new HashMap<>() : isvUserConnMap;
        }

        if (infoType.equals(CS.SYS_ROLE_TYPE.ISV)) {
            Map<String, IsvUserConn> isvUserConnMap = isvUserConnService.getBaseMapper().selectTransIsvIfCode(infoId, status);
            return isvUserConnMap == null ? new HashMap<>() : isvUserConnMap;
        }

        return new HashMap<>();
    }

    @Transactional
    public void removeByIsvNo(String isvNo) {
        // 0.当前服务商是否存在
        IsvInfoEntity isvInfoEntity = getById(isvNo);
        if (isvInfoEntity == null) {
            throw new BizException("该服务商不存在");
        }

        // 1.查询当前服务商下是否存在商户
        long mchCount = isvUserConnService.lambdaQuery()
                .eq(IsvUserConnEntity::getIsvNo, isvNo).eq(IsvUserConnEntity::getInfoType, CS.SYS_ROLE_TYPE.MCH).count();
        if (mchCount > 0) {
            throw new BizException("该服务商下存在商户，不可删除");
        }

        // 2.删除当前服务商支付接口配置参数
        payInterfaceConfigService.remove(PayInterfaceConfig.gw()
                .eq(PayInterfaceConfig::getInfoId, isvNo)
                .eq(PayInterfaceConfig::getInfoType, CS.SYS_ROLE_TYPE.ISV)
        );

        // 3.删除该服务商
        boolean remove = removeById(isvNo);
        if (!remove) {
            throw new BizException("删除服务商失败");
        }
    }

    /**
     * 保存指定渠道和用户的关联关系
     *
     * @param isvNo    渠道号
     * @param infoType 用户类型,
     *                 {@link CS.SYS_ROLE_TYPE#AGENT}
     *                 {@link CS.SYS_ROLE_TYPE#MCH}
     * @param infoId   用户号或服务商(原代理)号
     */
    public void saveIsvConn(@NonNull String isvNo, @NonNull String infoType, @NonNull String infoId, SysUser sysUser) {
        IsvInfoEntity isvInfo = getById(isvNo);
        Assert.notNull(isvInfo, "未知的渠道号");

        IsvUserConnEntity exist = connLambdaQuery()
                .eq(IsvUserConnEntity::getInfoId, infoId)
                .eq(IsvUserConnEntity::getInfoType, infoType)
                .eq(IsvUserConnEntity::getIsvNo, isvInfo.getIsvNo()).one();

        Assert.isNull(exist, "关联关系已存在，请勿重复操作");
//        if (exist != null) {
//            exist.setStatus(IsvUserConnEntity.STATUS_ENABLED);
//            exist.setConfigStatus(IsvUserConnEntity.STATUS_ENABLED);
//            isvUserConnService.updateById(exist);
//        }

        List<IsvUserConnEntity> isvUserConnEntityList;
        AgentInfo bindAgentInfo;
        MchInfo bindMchInfo;

        List<String> bindParentAgentList = new ArrayList<>();

        if (CS.SYS_ROLE_TYPE.AGENT.equals(infoType)) {
            bindAgentInfo = agentInfoService.getById(infoId);
            Optional.ofNullable(bindAgentInfo).map(AgentInfo::getPidArr).ifPresent(r -> {
                bindParentAgentList.addAll(Arrays.asList(r.split(",")));
            });
            isvUserConnEntityList = isvUserConnService.getConnInfoByAgentNo(infoId, isvNo);
        } else if (CS.SYS_ROLE_TYPE.MCH.equals(infoType)) {
            bindMchInfo = mchInfoService.getById(infoId);
            Optional.ofNullable(bindMchInfo).map(MchInfo::getAgentNoArr).ifPresent(r -> {
                bindParentAgentList.addAll(Arrays.asList(r.split(",")));
            });
            isvUserConnEntityList = isvUserConnService.getConnInfoByMchNo(infoId, isvNo);
        } else {
            throw new BizException("不支持的[infoType]类型");
        }

        Map<String, IsvUserConnEntity> existConnMap = new HashMap<>();
        if (!bindParentAgentList.isEmpty()) {
            isvUserConnService.lambdaQuery()
                    .in(IsvUserConnEntity::getInfoId, bindParentAgentList)
                    .eq(IsvUserConnEntity::getIsvNo, isvNo).list()
                    .forEach(r -> existConnMap.put(r.getInfoId(), r));
        }

        List<IsvUserConnEntity> filteredAndModifiedList = isvUserConnEntityList.stream()
                .filter(r -> !existConnMap.containsKey(r.getInfoId()))
                .peek(r -> {
                    if (sysUser != null) {
                        r.setCreatedBy(sysUser.getLoginUsername());
                        r.setCreatedUid(sysUser.getSysUserId());
                    }
                })
                .collect(Collectors.toList());

        isvUserConnService.saveBatch(filteredAndModifiedList);
    }

    /**
     * 获取渠道以及通道示例信息
     *
     * @param infoType 用户类型
     * @param infoId   用户id
     * @param ifCode   支付接口编码
     */
    public List<IsvInfo> getIsvAndPayConfig(String infoType, String isvName, String infoId, String ifCode, String range, Integer state) {
        List<IsvInfo> result = new ArrayList<>();

        PayInterfaceDefine payInterfaceDefine = payInterfaceDefineService.lambdaQuery().eq(PayInterfaceDefine::getIfCode, ifCode)
                .one();

        if (payInterfaceDefine != null) {
            return getMchIsvAndPayConfig(infoType, isvName, infoId, ifCode, range, state);
        }

        TransferInterfaceDefineEntity transferInterfaceDefine = transferInterfaceDefineService.lambdaQuery()
                .eq(TransferInterfaceDefineEntity::getTransIfCode, ifCode).one();

        if (transferInterfaceDefine != null) {
            return getTransIsvAndPayConfig(infoType, isvName, infoId, ifCode, range, state);
        }

        return result;
    }

    /**
     * 获取渠道以及通道示例信息
     *
     * @param infoType 用户类型
     * @param infoId   用户id
     * @param ifCode   支付接口编码
     */
    public List<IsvInfo> getMchIsvAndPayConfig(String infoType, String isvName, String infoId, String ifCode, String range, Integer state) {
        List<IsvInfo> result = new ArrayList<>();

        Map<String, IsvUserConnEntity> isvUserConnMap = isvUserConnService.lambdaQuery()
                .eq(IsvUserConnEntity::getInfoType, infoType)
                .eq(IsvUserConnEntity::getInfoId, infoId)
                .orderByAsc(IsvUserConnEntity::getSort)
                .list().stream()
                .collect(Collectors.toMap(IsvUserConnEntity::getIsvNo, Function.identity()));

        if (isvUserConnMap.isEmpty()) {
            return result;
        }

        List<IsvInfoEntity> isvInfoEntityList = lambdaQuery()
                .in(IsvInfoEntity::getIsvNo, isvUserConnMap.keySet())
                .like(!ObjUtil.isEmpty(isvName), IsvInfoEntity::getIsvName, isvName)
                .list();

        // 获取支付通道配置信息
        List<PayInterfaceConfig> payConfigList = payInterfaceConfigService.lambdaQuery()
                .select(PayInterfaceConfig::getId, PayInterfaceConfig::getInfoId, PayInterfaceConfig::getState, PayInterfaceConfig::getChannelTypes)
                .eq(PayInterfaceConfig::getIfCode, ifCode)
                .eq(PayInterfaceConfig::getInfoType, CS.SYS_ROLE_TYPE.ISV)
                .in(PayInterfaceConfig::getInfoId, isvUserConnMap.keySet())
                .list();

        Map<String, PayInterfaceConfig> payInterfaceConfigMap = payConfigList.stream()
                .collect(Collectors.toMap(PayInterfaceConfig::getInfoId, Function.identity()));

        DBDefaultConfig dbDefaultConfig = sysConfigService.getDBDefaultConfig();

        String defaultAgentNo = dbDefaultConfig.getDefaultAgentNo();

        for (IsvInfoEntity isvInfoEntity : isvInfoEntityList) {
            // 过滤出没有获取到支付通道配置信息的渠道
            PayInterfaceConfig payInterfaceConfig = payInterfaceConfigMap.get(isvInfoEntity.getIsvNo());
            if (payInterfaceConfig == null) {
                continue;
            }

            // 不支持的费率返回，也不做展示
            if (range != null) {
                if (payInterfaceConfig.getChannelTypes() == null) {
                    continue;
                }

                String channelTypes = payInterfaceConfig.getChannelTypes();
                if (range.equals("0") && !channelTypes.contains("1")) {
                    // 线下费率不存在
                    continue;
                }

                if (range.equals("1") && !channelTypes.contains("2")) {
                    // 线上费率不存在
                    continue;
                }

                if (range.equals("2") && !channelTypes.contains("0")) {
                    // 专属费率不存在
                    continue;
                }
            }

            isvInfoEntity.addExt("channelTypes", payInterfaceConfig.getChannelTypes());

            IsvInfo model = baseConverter.toModel(isvInfoEntity);

            if (Objects.equals(defaultAgentNo, model.getOwnerNo())) {
                model.addExt("tag", "官方渠道");
            } else if (Objects.equals(infoId, model.getOwnerNo())) {
                model.addExt("tag", "自有渠道");
            }

            IsvUserConnEntity isvUserConn = isvUserConnMap.get(isvInfoEntity.getIsvNo());
            // 渠道关联配置已禁用则按照渠道
//            model.addExt("connStatus", isvUserConn.getStatus());

            IsvUserConnDisabledEntity isvUserConnDisabledEntity = isvUserConnDisabledService.get(isvInfoEntity.getIsvNo(), ifCode, infoType, infoId);
            model.setState(isvUserConnDisabledEntity == null? CS.YES: CS.NO);

            model.setConfigStatus(((byte) isvUserConn.getConfigStatus()));

            // 渠道配置如果已禁用则按照渠道的来
//            model.addExt("interfaceStatus", payInterfaceConfig.getState());
            if (CS.NO == payInterfaceConfig.getState()) {
                model.setState(CS.NO);
            }

            // 不传状态值则返回全部数据
            if (state == null) {
                result.add(model);
                continue;
            }

            // 返回指定状态的数据
            if (ObjUtil.equals(state.byteValue(), model.getState())) {
                result.add(model);
            }
        }

        // 根据sort排序
        result.sort(Comparator.comparingInt(o -> isvUserConnMap.get(o.getIsvNo()).getSort()));

        return result;
    }

    /**
     * 获取渠道以及通道示例信息
     *
     * @param infoType 用户类型
     * @param infoId   用户id
     * @param ifCode   支付接口编码
     */
    public List<IsvInfo> getTransIsvAndPayConfig(String infoType, String isvName, String infoId, String ifCode, String range, Integer state) {
        List<IsvInfo> result = new ArrayList<>();

        Map<String, IsvUserConnEntity> isvUserConnMap = isvUserConnService.lambdaQuery()
                .eq(IsvUserConnEntity::getInfoType, infoType)
                .eq(IsvUserConnEntity::getInfoId, infoId)
                .orderByAsc(IsvUserConnEntity::getSort)
                .list().stream()
                .collect(Collectors.toMap(IsvUserConnEntity::getIsvNo, Function.identity()));

        if (isvUserConnMap.isEmpty()) {
            return result;
        }

        List<IsvInfoEntity> isvInfoEntityList = lambdaQuery()
                .in(IsvInfoEntity::getIsvNo, isvUserConnMap.keySet())
                .like(!ObjUtil.isEmpty(isvName), IsvInfoEntity::getIsvName, isvName)
                .list();

        // 获取支付通道配置信息
        List<TransferInterfaceConfigEntity> transConfigList = transferInterfaceConfigService.lambdaQuery()
                .select(TransferInterfaceConfigEntity::getId, TransferInterfaceConfigEntity::getInfoId, TransferInterfaceConfigEntity::getInfoType, TransferInterfaceConfigEntity::getState)
                .eq(TransferInterfaceConfigEntity::getTransIfCode, ifCode)
                .eq(TransferInterfaceConfigEntity::getInfoType, CS.SYS_ROLE_TYPE.ISV)
                .in(TransferInterfaceConfigEntity::getInfoId, isvUserConnMap.keySet())
                .list();

        Map<String, TransferInterfaceConfigEntity> transInterfaceConfigMap = transConfigList.stream()
                .collect(Collectors.toMap(TransferInterfaceConfigEntity::getInfoId, Function.identity()));

        DBDefaultConfig dbDefaultConfig = sysConfigService.getDBDefaultConfig();

        String defaultAgentNo = dbDefaultConfig.getDefaultAgentNo();

        for (IsvInfoEntity isvInfoEntity : isvInfoEntityList) {
            // 过滤出没有获取到支付通道配置信息的渠道
            TransferInterfaceConfigEntity payInterfaceConfig = transInterfaceConfigMap.get(isvInfoEntity.getIsvNo());
            if (payInterfaceConfig == null) {
                continue;
            }

            IsvInfo model = baseConverter.toModel(isvInfoEntity);
            model.setInfoType(infoType);

            if (Objects.equals(defaultAgentNo, model.getOwnerNo())) {
                model.addExt("tag", "官方渠道");
            } else if (Objects.equals(infoId, model.getOwnerNo())) {
                model.addExt("tag", "自有渠道");
            }

            IsvUserConnEntity isvUserConn = isvUserConnMap.get(isvInfoEntity.getIsvNo());
            // 渠道关联配置已禁用则按照渠道
//            model.addExt("connStatus", isvUserConn.getStatus());

            IsvUserConnDisabledEntity isvUserConnDisabledEntity = isvUserConnDisabledService.get(isvInfoEntity.getIsvNo(), ifCode, infoType, infoId);
            model.setState(isvUserConnDisabledEntity == null? CS.YES: CS.NO);

            model.setConfigStatus(((byte) isvUserConn.getConfigStatus()));

            // 渠道配置如果已禁用则按照渠道的来
//            model.addExt("interfaceStatus", payInterfaceConfig.getState());
            if (CS.NO == payInterfaceConfig.getState()) {
                model.setState(CS.NO);
            }

            // 不传状态值则返回全部数据
            if (state == null) {
                result.add(model);
                continue;
            }

            // 返回指定状态的数据
            if (ObjUtil.equals(state.byteValue(), model.getState())) {
                result.add(model);
            }
        }

        // 根据sort排序
        result.sort(Comparator.comparingInt(o -> isvUserConnMap.get(o.getIsvNo()).getSort()));

        return result;
    }


    public void autoBindIsvConn(String isvNo, String infoId, String roleType, byte configStatus) {

        if (configStatus != CS.YES) {
            configStatus = CS.NO;
        }

        if (roleType.equals(CS.SYS_ROLE_TYPE.AGENT)) {
            isvUserConnService.lambdaUpdate().eq(IsvUserConnEntity::getIsvNo, isvNo)
                    .eq(IsvUserConnEntity::getInfoId, infoId)
                    .eq(IsvUserConnEntity::getInfoType, CS.SYS_ROLE_TYPE.AGENT)
                    .set(IsvUserConnEntity::getConfigStatus, configStatus)
                    .update();
        } else {
            isvUserConnService.lambdaUpdate().eq(IsvUserConnEntity::getIsvNo, isvNo)
                    .eq(IsvUserConnEntity::getInfoId, infoId)
                    .eq(IsvUserConnEntity::getInfoType, CS.SYS_ROLE_TYPE.MCH)
                    .set(IsvUserConnEntity::getConfigStatus, configStatus)
                    .update();
        }
    }

    /**
     * 根据用户号，获取从用户到其顶级代理的费率信息
     *
     * @param mchNo  用户号
     * @param isvNo  渠道号
     * @param ifCode 通道code
     * @return 费率信息列表
     */
    public List<RateConfig> getMchIsvRateConfig(String mchNo, String isvNo, String ifCode, Integer range, String mccCode) {
        MchInfo mchInfo = mchInfoService.getById(mchNo);
        Assert.notNull(mchInfo, "用户号非法");

        // 获取全部关联的代理、用户信息
        // 逆序将代理从1级起开始排序
        List<String> infoIdList = Arrays.asList(mchInfo.getAgentNoArr().split(","));
        Collections.reverse(infoIdList);
        infoIdList.add(mchNo);
        // infoId为键值
        Map<String, IsvUserConnEntity> isvUserConnEntityMap = isvUserConnService.lambdaQuery()
                .eq(IsvUserConnEntity::getIsvNo, isvNo)
                .in(IsvUserConnEntity::getInfoId, infoIdList)
                .list()
                .stream()
                .collect(Collectors.toMap(IsvUserConnEntity::getInfoId, r -> r, (existing, replacement) -> existing));

        Map<String, RateConfig> rateConfigMap = rateConfigService.lambdaQuery().in(RateConfig::getInfoId, infoIdList)
                .eq(RateConfig::getIsvNo, isvNo)
                .eq(RateConfig::getRange, range)
                .eq(mccCode != null, RateConfig::getMccCode, mccCode)
                .in(RateConfig::getInfoId, infoIdList)
                .list()
                .stream()
                .collect(Collectors.toMap(rc -> rc.getIsvNo() + "_" + rc.getInfoId(), Function.identity()));

        return infoIdList.stream()
                .map(infoId -> {
                    IsvUserConnEntity isvUserConnEntity = isvUserConnEntityMap.get(infoId);
                    RateConfig rateConfig = rateConfigMap.get(infoId);

                    RateConfig item;
                    if (rateConfig == null) {
                        item = RateConfig.builder()
                                .isvNo(isvNo)
                                .ifCode(ifCode)
                                .range(range)
                                .mccCode(mccCode)
                                .infoId(infoId)
                                .build();
                        item.addExt("payConfigStatus", CS.NO);
                    } else {
                        item = rateConfig.toBuilder().build();
                        item.addExt("payConfigStatus", CS.YES);
                    }

                    Optional.ofNullable(isvUserConnEntity)
                            .ifPresent(entity -> item.addExt("status", entity.getStatus()));

                    return item;
                })
                .collect(Collectors.toList());
    }

    /**
     * 获取商户关联的渠道商信息
     *
     * @return
     */
    public List<IsvUserConnEntity> getMchConnInfo(String... mchNo) {
        return isvUserConnService.getConnInfo(CS.SYS_ROLE_TYPE.MCH, mchNo);
    }

    public Set<String> getMchIsvList(String... mchNo) {
        return isvUserConnService.getConnInfo(CS.SYS_ROLE_TYPE.MCH, mchNo)
                .stream()
                .map(IsvUserConnEntity::getIsvNo)
                .collect(Collectors.toSet());
    }

    /**
     * 获取商户关联的渠道商信息
     *
     * @return
     */
    public List<IsvUserConnEntity> getAgentConnInfo(String... agentNo) {
        return isvUserConnService.getConnInfo(CS.SYS_ROLE_TYPE.AGENT, agentNo);
    }

    public Set<String> getAgentIsvList(String... mchNo) {
        return isvUserConnService.getConnInfo(CS.SYS_ROLE_TYPE.AGENT, mchNo)
                .stream()
                .map(IsvUserConnEntity::getIsvNo)
                .collect(Collectors.toSet());
    }

    public LambdaQueryChainWrapper<IsvUserConnEntity> connLambdaQuery() {
        return isvUserConnService.lambdaQuery();
    }

    public QueryChainWrapper<IsvUserConnEntity> connQuery() {
        return isvUserConnService.query();
    }

    public JSONArray getSettType(String ifCode, String infoId) {
        JSONArray settType = new JSONArray();
        PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getOne(PayInterfaceConfig.gw()
                .eq(StringUtils.isNotEmpty(infoId), PayInterfaceConfig::getInfoId, infoId)
                .eq(StringUtils.isNotEmpty(ifCode), PayInterfaceConfig::getIfCode, ifCode));

        JSONArray resultType = new JSONArray();
        if (payInterfaceConfig != null) {
            String ifParams = payInterfaceConfig.getIfParams();
            //斗拱获取
            if ("dgpay".equals(ifCode) && StringUtils.isNotEmpty(ifParams) && ifParams.contains("settleCycle")) {
                JSONObject jsonObject = JSONObject.parseObject(payInterfaceConfig.getIfParams());
                settType = jsonObject.getJSONArray("settleCycle");


            } else {
                if (StringUtils.isNotEmpty(ifParams) && ifParams.contains("settType")) {
                    JSONObject jsonObject = JSONObject.parseObject(payInterfaceConfig.getIfParams());
                    settType = jsonObject.getJSONArray("settType");
                }
            }
        }

        for (int i = 0; i < settType.size(); i++) {
            String item = settType.getString(i);

            if ("1".equals(item) || "T1".equals(item)) {
                resultType.add("T1");
            }

            if ("2".equals(item) || "D1".equals(item)) {
                resultType.add("D1");
            }

            if ("3".equals(item) || "D0".equals(item)) {
                resultType.add("D0");
            }
        }

        return resultType;
    }

    public void editConnStatus(String isvNo, String ifCode, String infoId, String infoType, Integer status) {
        if (!CS.SYS_ROLE_TYPE.AGENT.equals(infoType) && !CS.SYS_ROLE_TYPE.MCH.equals(infoType)) {
            throw new BizException("角色类型[infoType]非法, 只能为AGENT或MCH");
        }

        if (status != CS.YES && status != CS.NO) {
            throw new BizException("状态[state]非法, 只能为1或0");
        }

        if (status == CS.YES) {
            isvUserConnDisabledService.enable(isvNo, ifCode, infoType, infoId);
        }

        if (status == CS.NO) {
            isvUserConnDisabledService.disable(isvNo, ifCode, infoType, infoId);
        }
    }
}
