package cn.ey.biz.module.system.service.rate;

import cn.ey.biz.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ey.biz.module.system.api.rate.dto.GradeLevelResDTO;
import cn.ey.biz.module.system.dal.dataobject.rate.DictGdsRateValueDO;
import cn.ey.biz.module.system.dal.mapper.rate.DictGdsRateValueMapper;
import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * impl dict gds率服务
 *
 * @author ShiJie-SJ.Li
 * @date 2023/06/13
 */
@Slf4j
@Service
@Validated
public class DictGdsRateServiceImpl implements DictGdsRateService {

    @Resource
    private DictGdsRateValueMapper dictGdsRateValueMapper;


    @Override
    public List<GradeLevelResDTO> getGdsRank(String codeBlock) {
        List<GradeLevelResDTO> results = new ArrayList<>();
        LambdaQueryWrapperX<DictGdsRateValueDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.select(DictGdsRateValueDO::getRankCode, DictGdsRateValueDO::getGradeCode).eq(DictGdsRateValueDO::getEmployeeCodeBlock, codeBlock)
                .groupBy(DictGdsRateValueDO::getRankCode, DictGdsRateValueDO::getGradeCode);
        List<DictGdsRateValueDO> result = dictGdsRateValueMapper.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(result)) {
            result.stream().forEach(res -> {
                GradeLevelResDTO gradeLevelResDTO = new GradeLevelResDTO();
                gradeLevelResDTO.setRankCode(res.getRankCode());
                gradeLevelResDTO.setGradeCode(res.getGradeCode());
                results.add(gradeLevelResDTO);
            });
        }
        return results;
    }
}
