
package com.jeelowcode.core.framework.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.jeelowcode.core.framework.entity.FormFieldExportEntity;
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 com.jeelowcode.framework.utils.enums.YNEnum;

import java.util.List;

@DS(JeeLowCodeBaseConstant.DS_JEELOWCODE)
public interface FormFieldExportMapper extends BaseMapper<FormFieldExportEntity> {

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

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


    default List<FormFieldExportEntity> getDuplicateByFormId(Long dbFormId){
        LambdaQueryWrapper<FormFieldExportEntity> exportWrapper = new LambdaQueryWrapper<>();
        exportWrapper.eq(FormFieldExportEntity::getDbformId, dbFormId);
        exportWrapper.eq(FormFieldExportEntity::getIsImportDuplicate, YNEnum.Y.getCode());
        exportWrapper.orderByAsc(FormFieldExportEntity::getId);
        return this.selectList(exportWrapper);
    }
}
