
package com.jeelowcode.core.framework.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.jeelowcode.core.framework.entity.FormFieldQueryEntity;
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 FormFieldQueryMapper extends BaseMapper<FormFieldQueryEntity> {

    default void delByDbformId(Long dbFormId){
        QueryWrapper<FormFieldQueryEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq("dbform_id", dbFormId);
        this.delete(queryWrapper);
    }

    @JeelowCodeCache(cacheNames = "'FormFieldQueryMapper:getByFormId:' + #dbFormId", reflexClass = FormFieldQueryEntity.class)
    default List<FormFieldQueryEntity> getByFormId(Long dbFormId){
        LambdaQueryWrapper<FormFieldQueryEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FormFieldQueryEntity::getDbformId, dbFormId);
        queryWrapper.orderByAsc(FormFieldQueryEntity::getId);
        return this.selectList(queryWrapper);
    }
}
