
package com.jeelowcode.module.biz.demo.test;

import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceParam;
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.BeforeAdvicePlugin;
import com.jeelowcode.core.framework.utils.Func;
import com.jeelowcode.framework.exception.JeeLowCodeException;
import com.jeelowcode.framework.utils.utils.FuncBase;


import java.util.Map;

/**
 * @author JX
 * @create 2024-08-15 11:31
 * @dedescription: 前置增强测试
 */
public class DemoBeforeAdvicePlugin implements BeforeAdvicePlugin {


    @Override
    public void execute(EnhanceContext enhanceContext) {
        EnhanceParam param = enhanceContext.getParam();
        Map<String, Object> params = param.getParams();
        String name = FuncBase.getMap2Str(params, "name");
        if (Func.equals(name, "jeelowcode")) {
            throw new JeeLowCodeException("不允许使用jeelowcode");
        }
        params.replace("name",FuncBase.getMap2Str(params,"name")+"before_enhance");

        EnhanceResult result = new EnhanceResult();
        result.setExitFlag(false);
        enhanceContext.setResult(result);
    }
}
