package com.friday.custody.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.friday.custody.entity.AccountInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 资金账户基本信息表
 * 
 * @author lyb
 * @email k0051582@gmail.com
 * @date 2022-03-04 16:12:06
 */
@Mapper
public interface AccountInfoDao extends BaseMapper<AccountInfoEntity> {

    List<String> queryFundCodeByTrustNo(Map map);

    List<String> getFundCodeList(@Param("trustNo") String trustNo, @Param("admin") String admin);

    String getDataByFundCode(@Param("fundCode") String fundCode, @Param("trustNo") String trustNo, @Param("admin") String admin);

    void updateBankCodeAndCurrencyByBankAcco(@Param("bankCode") String bankCode,
                                             @Param("currency") String currency,
                                             @Param("bankAcco") String bankAcco,
                                             @Param("trustNo") String trustNo,
                                             @Param("admin") String admin);

    List<AccountInfoEntity> getDataList(@Param("trustNo") String trustNo,
                                        @Param("accoTypeCode") String accoTypeCode,
                                        @Param("admin") String admin);

    AccountInfoEntity selectData(String account,String trustNo);

    List<String> getBankAcco(@Param("trustNo") String trustNo, @Param("admin") String admin);

    default Set<String> queryUniqueKeyList(List<String> rawUniqueKeyList){
        LambdaQueryWrapper<AccountInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(AccountInfoEntity::getUniqueKey).in(AccountInfoEntity::getUniqueKey, rawUniqueKeyList);
        List<AccountInfoEntity> entityList = this.selectList(queryWrapper);
        Set<String> result = entityList.stream().map(AccountInfoEntity::getUniqueKey).collect(Collectors.toSet());
        return result;
    }

    default int deleteByUniqueKeys(Set<String> uniqueKeySet){
        LambdaQueryWrapper<AccountInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(AccountInfoEntity::getUniqueKey, uniqueKeySet);
        return delete(queryWrapper);
    }
}
