package com.tofly.feesapi.bmgl.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.tofly.feesapi.bmgl.entity.BmCbpl;
import com.tofly.feesapi.bmgl.entity.dto.BmcbplFilter;
import com.tofly.feesapi.bmgl.mapper.BmCbplMapper;
import com.tofly.feesapi.bmgl.service.BmCbplService;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import org.springframework.stereotype.Service;

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

@Service("bmCbplService")
public class BmCbplServiceImpl extends ServiceImpl<BmCbplMapper, BmCbpl> implements BmCbplService {

    @Override
    public String getMaxid() {
        return this.baseMapper.getMaxid();
    }

    public PageResult<BmCbpl> getPage(PageDto pageDto, BmcbplFilter filter) {

        PageDto<BmCbpl> page = this.baseMapper.getPage(pageDto, filter);
        return page.toVo();
    }

    @Override
    public Map<String, String> getCbplMap() {
        List<BmCbpl> bmCbpls = baseMapper.selectList(new QueryWrapper<>());
        if (CollectionUtil.isEmpty(bmCbpls)) {
            return new HashMap<>();
        }

        return bmCbpls.stream().collect(Collectors.toMap(BmCbpl::getCode, BmCbpl::getCbyf));
    }

}
