package com.yd.csf.api.service.impl;

import com.yd.csf.api.service.ApiMemberGradeConfigService;
import com.yd.csf.service.model.MemberGradeConfig;
import com.yd.csf.service.service.IMemberGradeConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;

@Slf4j
@Service
public class ApiMemberGradeConfigServiceImpl implements ApiMemberGradeConfigService {

    @Resource
    private IMemberGradeConfigService iMemberGradeConfigService;

    /**
     * 根据初始化等级获取初始化积分值
     * @param initGrade
     * @return
     */
    @Override
    public BigDecimal getInitEffect(String initGrade) {
        MemberGradeConfig memberGradeConfig = iMemberGradeConfigService.queryOne(initGrade);
        if (memberGradeConfig == null) {
            return BigDecimal.ZERO;
        }
        //最大积分值等于空，返回最小积分值。否则返回最大积分值-1
        return memberGradeConfig.getMaxValue() == null ? memberGradeConfig.getMinValue() : memberGradeConfig.getMaxValue().subtract(new BigDecimal("1.00"));
    }
}
