
package com.lideeyunji.core.framework.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lideeyunji.core.framework.entity.ReportEntity;
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
import com.lideeyunji.tool.framework.yunji.annotation.lideeYunjiCache;
import com.lideeyunji.tool.framework.yunji.constant.lideeRedisConstants;

/**
 * 报表相关
 */
@DS(lideeYunJiBaseConstant.DS_lideeyunji)
public interface ReportMapper extends BaseMapper<ReportEntity> {

    @lideeYunjiCache(cacheNames = "'"+ lideeRedisConstants.REDIS_REPORT+":getById:' + #reportId", reflexClass = ReportEntity.class)
    default ReportEntity getById(Long reportId) {

        LambdaQueryWrapper<ReportEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ReportEntity::getId, reportId);
        return this.selectOne(wrapper);
    }

    @lideeYunjiCache(cacheNames = "'"+ lideeRedisConstants.REDIS_REPORT+":getByCode:' + #reportCode", reflexClass = ReportEntity.class)
    default ReportEntity getByCode(String reportCode) {
        LambdaQueryWrapper<ReportEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ReportEntity::getReportCode, reportCode);
        return this.selectOne(wrapper);
    }

}
