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

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.config.aspect.enhance.model.EnhanceResult;
import com.lideeyunji.core.framework.config.aspect.enhance.plugin.BeforeAdvicePlugin;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.tool.framework.exception.lideeYunJiException;
import com.lideeyunji.tool.framework.yunji.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, "lideeyunji")) {
            throw new lideeYunJiException("不允许使用lideeyunji");
        }
        params.replace("name",FuncBase.getMap2Str(params,"name")+"before_enhance");

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