package com.unis.module.coding.dal.mysql.bank;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.unis.framework.common.pojo.PageResult;
import com.unis.framework.mybatis.core.mapper.BaseMapperX;
import com.unis.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.unis.module.coding.controller.admin.bank.vo.BankPageReqVO;
import com.unis.module.coding.controller.admin.delivery.vo.StoreRespVO;
import com.unis.module.coding.dal.dataobject.bank.BankDO;
import com.unis.module.coding.dal.dataobject.province.ProvinceDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;


/**
 * 银行已选 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface BankMapper extends BaseMapperX<BankDO> {

    default PageResult<BankDO> selectPage(BankPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BankDO>()
                .eqIfPresent(BankDO::getKqId, reqVO.getKqId())
                .eqIfPresent(BankDO::getCaId, reqVO.getCaId())
                .betweenIfPresent(BankDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BankDO::getHyryId, reqVO.getHyryId())
                .likeIfPresent(BankDO::getHyryName, reqVO.getHyryName())
                .eqIfPresent(BankDO::getHyState, reqVO.getHyState())
                .likeIfPresent(BankDO::getRdyhName, reqVO.getRdyhName())
                .orderByDesc(BankDO::getId));
    }
    List<StoreRespVO> getStoreListForBank(@Param("kqId") Long  kqId, @Param("yhmc")String yhmc);

    default int deleteListByKqIdAndCaIdsAndBank(Long  kqId, List<Long> caIds,String bankType) {
        return delete(
                new LambdaUpdateWrapper<BankDO>()
                        .eq(kqId!=null,BankDO::getKqId, kqId)
                        .eq(!StringUtils.isBlank(bankType),BankDO::getRdyhId, bankType)
                        .in(!ObjectUtil.isEmpty(caIds),BankDO::getCaId, caIds)
        );
    }
    default List<BankDO> selectListByKqId(Long  kqId) {
        return selectList(
                new LambdaQueryWrapper<BankDO>()
                        .eq(kqId!=null,BankDO::getKqId, kqId)
        );
    }
    default List<BankDO> selectListBycaIds(List<Long>  caIds) {
        return selectList(
                new LambdaQueryWrapperX<BankDO>()
                        .inIfPresent(BankDO::getCaId, caIds)

        );
    }
    default int deleteListByKqIdsAndBank(List<Long> kqIds,String bankType) {
        return delete(
                new LambdaUpdateWrapper<BankDO>()
                        .in(!ObjectUtil.isEmpty(kqIds),BankDO::getKqId, kqIds)
                        .eq(!StringUtils.isBlank(bankType),BankDO::getRdyhId, bankType)
        );
    }

    default void updateByKqId(BankDO bankDO, Long kqId){
        update(bankDO, new LambdaQueryWrapperX<BankDO>().eq(BankDO::getKqId,kqId));
    }
}