package com.sunxung.factoring.service.cashflowmanage.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sunxung.factoring.entity.GridPage;
import com.sunxung.factoring.entity.cashflowmanage.BankCardInfo;
import com.sunxung.factoring.entity.cashflowmanage.vo.CompanyBelongResultVo;
import com.sunxung.factoring.entity.cashflowmanage.vo.SearchBankCardInfoSetVo;
import com.sunxung.factoring.mapper.cashflowmanage.BankCardInfoSetMapper;
import com.sunxung.factoring.service.cashflowmanage.BankCardInfoSetService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description : 采购发票货物信息service实现类
 * @Author : JiaYf
 * @Date: 2021-10-18 19:18
 */
@Service
public class BankCardInfoSetServiceImpl extends ServiceImpl<BankCardInfoSetMapper, BankCardInfo>
        implements BankCardInfoSetService {


    @Override
    public GridPage<BankCardInfo> queryPage(SearchBankCardInfoSetVo searchBankCardInfoSetVo) {
        Page<SearchBankCardInfoSetVo> page = PageHelper.startPage(searchBankCardInfoSetVo.getPage(), searchBankCardInfoSetVo.getRows());
        List<BankCardInfo> bankCardInfoList = baseMapper.findList(searchBankCardInfoSetVo);
        return new GridPage<>(searchBankCardInfoSetVo.getRows(), searchBankCardInfoSetVo.getPage(), page.getTotal(), bankCardInfoList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(BankCardInfo bankCardInfo, HttpServletRequest request) {
        baseMapper.insert(bankCardInfo);
    }

    @Override
    public BankCardInfo get(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteById(Long id) {
        baseMapper.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void enable(Long id, Integer flag) {
        BankCardInfo bankCardInfo = baseMapper.selectById(id);
        bankCardInfo.setStatus(flag);
        baseMapper.updateById(bankCardInfo);
    }

    @Override
    public List<CompanyBelongResultVo> getCompanyBelong() {
        return baseMapper.getCompanyBelong();
    }

    @Override
    public List<String> getBankName(Long companyBelong) {
        return baseMapper.getBankName(companyBelong);
    }

    @Override
    public List<String> getBankAccount(Long companyBelong, String bankName) {
        return baseMapper.getBankAccount(companyBelong, bankName);
    }
}
