package cn.pluss.platform.mswitch;

import cn.pluss.platform.api.PageInfo;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.entity.CommonSwitch;
import cn.pluss.platform.mapper.CommonSwitchMapper;
import cn.pluss.platform.util.PageUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * @author djh 通用
 */
public interface CommonSwitchService extends IService<CommonSwitch> {

    /**
     * 是否允许异地支付
     * @return
     */
   default boolean allowEcdemicPay() {
        CommonSwitch commonSwitch = new CommonSwitch().setCode("PAY_ECDEMIC_SWITCH");
        CommonSwitch switchIns = getBaseMapper().selectOne(new QueryWrapper<>(commonSwitch));
        return "1".equals(switchIns.getValue());
    }

    /**
     * 是否允许商户进件
     * @return
     */
    default boolean allowMerchantRegister() {
        CommonSwitch commonSwitch = new CommonSwitch().setCode("MER_REG_SWITCH");
        CommonSwitch switchIns = getBaseMapper().selectOne(new QueryWrapper<>(commonSwitch));
        return "1".equals(switchIns.getValue());
    }

    default PageInfo<CommonSwitch> pageData(Page<CommonSwitch> page , CommonSwitch commonSwitch) {
        QueryWrapper<CommonSwitch> queryWrapper = new QueryWrapper<>(commonSwitch).orderByAsc("sort");
        IPage<CommonSwitch> pageData = getBaseMapper().selectPage(page, queryWrapper);
        return PageUtils.page(pageData);
    }
}
