
package com.jeelowcode.core.framework.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.jeelowcode.core.framework.entity.FormIndexEntity;
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
import com.jeelowcode.framework.utils.annotation.JeelowCodeCache;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

@DS(JeeLowCodeBaseConstant.DS_JEELOWCODE)
public interface FormIndexMapper extends BaseMapper<FormIndexEntity> {

    @JeelowCodeCache(cacheNames = "'FormIndexMapper: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);
    }

}
