
package com.lideeyunji.core.framework.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lideeyunji.core.framework.entity.FormIndexEntity;
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 java.util.List;

@DS(lideeYunJiBaseConstant.DS_lideeyunji)
public interface FormIndexMapper extends BaseMapper<FormIndexEntity> {

    @lideeYunjiCache(cacheNames = "'"+ lideeRedisConstants.REDIS_DBFORM +":index:getByDbFormId:' + #dbFormId", reflexClass = FormIndexEntity.class)
    default List<FormIndexEntity> getByDbFormId(Long dbFormId) {
        LambdaQueryWrapper<FormIndexEntity> indexWrapper = new LambdaQueryWrapper<>();
        indexWrapper.eq(FormIndexEntity::getDbformId, dbFormId);
        indexWrapper.orderByAsc(FormIndexEntity::getId);
        List<FormIndexEntity> indexList = this.selectList(indexWrapper);
        return indexList;
    }

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

}
