package com.simuwang.manage.service.impl;

import com.simuwang.base.common.support.MybatisPage;
import com.simuwang.base.mapper.FundInfoMapper;
import com.simuwang.base.pojo.dos.FundInfoDO;
import com.simuwang.base.pojo.dos.FundInformationDO;
import com.simuwang.base.pojo.dto.query.FundInfoPageQuery;
import com.simuwang.base.pojo.dto.query.FundInputPageQuery;
import com.simuwang.base.pojo.vo.FundInfoSearchVO;
import com.simuwang.base.pojo.vo.FundInfoVO;
import com.simuwang.base.pojo.vo.FundInformationVO;
import com.simuwang.manage.service.FundInformationService;
import com.smppw.common.pojo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * FileName: FundInformationServiceImpl
 * Author:   chenjianhua
 * Date:     2024/9/6 15:08
 * Description: ${DESCRIPTION}
 */
@Service
public class FundInformationServiceImpl implements FundInformationService {
    @Autowired
    private FundInfoMapper fundInfoMapper;
    @Override
    public MybatisPage<FundInfoSearchVO> searchFundInfo(FundInputPageQuery fundInputPageQuery) {
        List<Map<String,String>> fundInfoList = fundInfoMapper.searchFundInfoByKeyword(fundInputPageQuery);
        List<FundInfoSearchVO> fundInfoSearchVOList = new ArrayList<>();
        for(Map<String,String> map : fundInfoList){
            FundInfoSearchVO vo = new FundInfoSearchVO();
            vo.setFundId(map.get("fundId"));
            vo.setFundName(map.get("fundShortName"));
            vo.setRegisterNumber(map.get("registerNumber"));
            fundInfoSearchVOList.add(vo);
        }
        long total = fundInfoMapper.countFundInfoByKeyword(fundInputPageQuery);
        return MybatisPage.of(total,fundInfoSearchVOList);
    }

    @Override
    public MybatisPage<FundInformationVO> searchFundInfoList(FundInfoPageQuery fundInfoPageQuery) {
        List<FundInformationDO> result = fundInfoMapper.searchFundInfoList(fundInfoPageQuery);
        List<FundInformationVO> fundInformationVOList = result.stream().map(FundInformationDO::toVO).collect(Collectors.toList());
        long total = fundInfoMapper.countFundInfo(fundInfoPageQuery);
        return MybatisPage.of(total,fundInformationVOList);
    }

    @Override
    public ResultVo<FundInfoVO> searchFundDetail(String fundId) {
        FundInfoDO fundInfoDO = fundInfoMapper.searchFundDetail(fundId);
        FundInfoVO fundInfoVO = fundInfoDO.toVO();
        return ResultVo.ok(fundInfoVO);
    }
}
