package org.dromara.ems.info.service.impl;

import org.dromara.ems.info.mapper.CommonClearMapper;
import org.dromara.ems.info.service.ICommonClearService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 通用数据清空Service业务层处理
 * 
 * @author System
 * @date 2025-01-20
 */
@Service
@RequiredArgsConstructor
public class CommonClearServiceImpl implements ICommonClearService 
{

    private final CommonClearMapper commonClearMapper;

    /**
     * 清空指定表的所有数据
     * 使用事务确保数据一致性
     * 
     * @param tableName 表名（已通过白名单验证）
     * @return 删除的记录数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int clearTableData(String tableName)
    {
        // 表名已在Controller层通过白名单验证，这里直接执行
        return commonClearMapper.clearTableData(tableName);
    }
} 
