package com.jeequan.jeepay.thirdparty.channel.zftpay;

import cn.hutool.core.util.ObjUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.interfaces.paychannel.IGetApplymentDataService;
import com.jeequan.jeepay.db.entity.BankBranchZft;
import com.jeequan.jeepay.service.impl.BankBranchZftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * TODO
 *
 * @author deng
 * @since 2024/4/10
 */
@Service
public class ZftpayGetApplymentDataService implements IGetApplymentDataService {

    @Autowired
    private BankBranchZftService bankBranchZftService;

    public List<JSONObject> getBankBranchInfo(String isvNo, String bankAliasCode, String cityCode, String bankName, String branchName) throws BizException {
        List<BankBranchZft> list = bankBranchZftService.lambdaQuery()
                .eq(BankBranchZft::getCity, cityCode)
                .like(!ObjUtil.isEmpty(branchName), BankBranchZft::getBranchName, branchName)
                .last("limit 1000")
                .list();

        return list.stream().map( t -> ((JSONObject) JSON.toJSON(t))).collect(Collectors.toList());
    }
}
