
package com.lideeyunji.core.framework.mapper;

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

import java.util.List;

@DS(lideeYunJiBaseConstant.DS_lideeyunji)
public interface FormFieldExportMapper extends BaseMapper<FormFieldExportEntity> {

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

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