
package com.lideeyunji.core.framework.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lideeyunji.core.framework.entity.FormSummaryEntity;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
import com.lideeyunji.tool.framework.yunji.annotation.lideeYunjiCache;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lideeyunji.tool.framework.yunji.constant.lideeRedisConstants;
import com.lideeyunji.tool.framework.yunji.enums.YNEnum;

import java.util.List;

//统计配置
@DS(lideeYunJiBaseConstant.DS_lideeyunji)
public interface FormSummaryMapper extends BaseMapper<FormSummaryEntity> {

    default void delByDbFormId(Long dbFormId){
        QueryWrapper<FormSummaryEntity> summaryWrapper = new QueryWrapper();
        summaryWrapper.eq("dbform_id", dbFormId);
        this.delete(summaryWrapper);
    }

    default List<FormSummaryEntity>  getByFormId(Long dbFormId){
        LambdaQueryWrapper<FormSummaryEntity> summaryWrapper = new LambdaQueryWrapper<>();
        summaryWrapper.eq(FormSummaryEntity::getDbformId, dbFormId);
        summaryWrapper.orderByAsc(FormSummaryEntity::getId);
        return this.selectList(summaryWrapper);
    }

    @lideeYunjiCache(cacheNames = "'"+ lideeRedisConstants.REDIS_DBFORM +":summary:getTopSummaryList:' + #dbFormId", reflexClass = FormSummaryEntity.class,nullIsSave = true)
    default List<FormSummaryEntity>  getTopSummaryList(Long dbFormId){
        LambdaQueryWrapper<FormSummaryEntity> topWrapper = new LambdaQueryWrapper<>();
        topWrapper.eq(FormSummaryEntity::getDbformId, dbFormId);
        topWrapper.eq(FormSummaryEntity::getSummaryType, "top");//顶部
        topWrapper.orderByAsc(FormSummaryEntity::getSortNum);
        topWrapper.orderByDesc(FormSummaryEntity::getId);
        return this.selectList(topWrapper);
    }

    @lideeYunjiCache(cacheNames = "'"+ lideeRedisConstants.REDIS_DBFORM +":summary:getBottomSummaryList:' + #dbFormId", reflexClass = FormSummaryEntity.class,nullIsSave = true)
    default List<FormSummaryEntity>  getBottomSummaryList(Long dbFormId){
        LambdaQueryWrapper<FormSummaryEntity> bottomWrapper = new LambdaQueryWrapper<>();
        bottomWrapper.eq(FormSummaryEntity::getDbformId, dbFormId);
        bottomWrapper.eq(FormSummaryEntity::getSummaryType, "bottom");//顶部
        bottomWrapper.orderByAsc(FormSummaryEntity::getSortNum);
        bottomWrapper.orderByDesc(FormSummaryEntity::getId);
        return this.selectList(bottomWrapper);
    }
    default List<FormSummaryEntity>  getSummaryList(Long dbFormId,String summaryType){
        LambdaQueryWrapper<FormSummaryEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FormSummaryEntity::getDbformId, dbFormId);
        wrapper.eq(FormSummaryEntity::getSummaryShow, YNEnum.Y.getCode());
        wrapper.eq(Func.isNotEmpty(summaryType), FormSummaryEntity::getSummaryType, summaryType);
        return this.selectList(wrapper);
    }


}
