package com.xjrsoft.module.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.xjrsoft.common.enums.DeleteMark;
import com.xjrsoft.module.student.dto.QuotaFormulaRulePageDto;
import com.xjrsoft.module.student.entity.QuotaFormulaRule;
import com.xjrsoft.module.student.mapper.QuotaFormulaRuleMapper;
import com.xjrsoft.module.student.service.IQuotaFormulaRuleService;
import com.xjrsoft.module.student.vo.QuotaFormulaRulePageVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @title: 指标公式规则管理
* @Author szs
* @Date: 2024-01-29
* @Version 1.0
*/
@Service
@AllArgsConstructor
public class QuotaFormulaRuleServiceImpl extends MPJBaseServiceImpl<QuotaFormulaRuleMapper, QuotaFormulaRule> implements IQuotaFormulaRuleService {
    private final QuotaFormulaRuleMapper quotaFormulaRuleMapper;
    @Override
    public Page<QuotaFormulaRulePageVo> getPage(Page<QuotaFormulaRulePageDto> page, QuotaFormulaRulePageDto dto) {
        return quotaFormulaRuleMapper.getPage(page, dto);
    }

    @Override
    public String getFormulaByQuota(String bindQuota) {
        List<QuotaFormulaRule> list = list(
                new QueryWrapper<QuotaFormulaRule>().lambda()
                        .eq(QuotaFormulaRule::getDeleteMark, DeleteMark.NODELETE.getCode())
                        .eq(QuotaFormulaRule::getBindQuota, bindQuota)
                        .orderByDesc(QuotaFormulaRule::getCreateDate)
        );
        if(!list.isEmpty()){
            return list.get(0).getFormula();
        }
        return null;
    }
}
