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

import cn.ey.biz.module.system.api.dict.dto.DictGradeRateRefReqDTO;
import cn.ey.biz.module.system.api.dict.dto.DictGradeRateRefRespDTO;
import cn.ey.biz.module.system.convert.dict.DictGradeRateRefConvert;
import cn.ey.biz.module.system.dal.dataobject.dict.DictGradeRateRefDO;
import cn.ey.biz.module.system.dal.mapper.dict.DictGradeRateRefMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class DictGradeRateRefServiceImpl extends ServiceImpl<DictGradeRateRefMapper, DictGradeRateRefDO>
        implements DictGradeRateRefService {

    @Override
    public DictGradeRateRefRespDTO getGradeRateRefDetail(DictGradeRateRefReqDTO dictGradeRateRefReqDTO) {

       /* int year = DateUtil.year(DateUtil.date());
        String yearSuffix = String.valueOf(year).substring(2);*/
        //获取rate值并设置
        LambdaQueryWrapper<DictGradeRateRefDO> wrapper= Wrappers.lambdaQuery(DictGradeRateRefDO.class)
                .eq(DictGradeRateRefDO::getCountryRegion, dictGradeRateRefReqDTO.getCountryRegion())
                .eq(DictGradeRateRefDO::getMgmtRegion, dictGradeRateRefReqDTO.getMgmtRegion())
                .eq(DictGradeRateRefDO::getSlCode, dictGradeRateRefReqDTO.getSlCode())
                .eq(DictGradeRateRefDO::getSslCode, dictGradeRateRefReqDTO.getSslCode())
                .eq(DictGradeRateRefDO::getCompetencyCode, dictGradeRateRefReqDTO.getCompetencyCode())
                .eq(DictGradeRateRefDO::getSmuCode, dictGradeRateRefReqDTO.getSmuCode())
                .eq(DictGradeRateRefDO::getGradeCode, dictGradeRateRefReqDTO.getGradeCode())
                .eq(DictGradeRateRefDO::getFisicalYear, dictGradeRateRefReqDTO.getFisicalYear());
        //设置false,该方法存在多条时不会抛异常，会取索引位置为0的数据
        DictGradeRateRefDO dictGradeRateRefDO = super.getOne(wrapper, false);
        return DictGradeRateRefConvert.INSTANCE.convert(dictGradeRateRefDO);
    }
}
