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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.feesapi.bmgl.entity.BmYslx;
import com.tofly.feesapi.bmgl.entity.dto.BmYslxFilter;
import com.tofly.feesapi.bmgl.entity.vo.BmYslxSelect;
import com.tofly.feesapi.bmgl.service.BmYslxService;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import com.tofly.feesapi.udb.entity.Company;
import com.tofly.feesapi.udb.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tofly.feesapi.bmgl.mapper.BmYslxMapper;

import java.util.List;

@Service("bmYslxService")
public class BmYslxServiceImpl extends ServiceImpl<BmYslxMapper, BmYslx> implements BmYslxService {


    @Autowired
    private ICompanyService companyService;

    @Override
    public PageResult<BmYslxSelect> getPage(PageDto pageDto, BmYslxFilter filter) {
        PageResult<BmYslxSelect> result = this.baseMapper.getPage(pageDto, filter).toVo();
        List<Company> companyList = companyService.list();
        result.getRecords().forEach(e -> {
            if (e.getSsgs() != null) {
                Company company = companyList.stream().filter(item -> item.getId().equals(Long.valueOf(e.getSsgs()))).findFirst().get();
                if (company != null) {
                    e.setSsgsmc(company.getCompanyName());
                } else {
                    e.setSsgsmc(e.getSsgs());
                }
            }
        });
        return result;
    }
}
