
package com.lideeyunji.core.framework.mapper;

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

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

    @lideeYunjiCache(cacheNames = "'"+ lideeRedisConstants.REDIS_DBFORM +":query: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);
    }
}
