package com.lideeyunji.core.framework.config.aspect.enhance.strategy.sql;

import com.lideeyunji.core.framework.config.aspect.enhance.model.EnhanceContext;
import com.lideeyunji.core.framework.config.aspect.enhance.model.EnhanceParam;
import com.lideeyunji.core.framework.entity.EnhanceSqlEntity;
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 删除策略
 */
public class DelEnhanceSqlStrategy extends BaseEnhanceSqlStrategy  implements EnhanceSqlStrategy {

    @Override
    public void execute(EnhanceContext context, EnhanceSqlEntity enhanceSqlEntity) {
        EnhanceParam param = context.getParam();
        Map<String, Object> params = param.getParams();
        List<Long> dataIdList = (List<Long>) params.getOrDefault("dataIdList", null);

        String executeSql = enhanceSqlEntity.getExecuteSql();
        if (FuncBase.isEmpty(executeSql)) {
            return;
        }
        //因为是批量删除的，需要拆分出来
        for (Long dataId : dataIdList) {
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("id", dataId);

            //执行sql
            super.executeSql(executeSql, dataMap);
        }
    }

}
