package com.api.customization.smartwg.doc.impl;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent;
import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceAfter;
import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaAfterReplaceParam;
import weaver.general.Util;

import javax.servlet.http.HttpServletRequest;


//WeaIocReplaceComponent这个注解用于标识拦截类、如不标注名称，则按类的全路径注入
@WeaIocReplaceComponent
public class docApiImpl {

    @WeaReplaceAfter(value = "/api/public/browser/condition/141", order = 1, description = "后置拦截的方法！！！")
    public String after(WeaAfterReplaceParam weaAfterReplaceParam) {
        String data = weaAfterReplaceParam.getData();
        JSONObject jo = JSONObject.parseObject(data);
        HttpServletRequest request = weaAfterReplaceParam.getRequest();
        String wfid = Util.null2String(request.getParameter("wfid"));
        if (!wfid.isEmpty()) {
            JSONArray columns = jo.getJSONArray("columns");
            for (int i = 0; i < columns.size(); i++) {
                JSONObject items = columns.getJSONObject(i);
                String dataIndex = items.getString("dataIndex");
                if (dataIndex.equals("seclevel")) {
                    columns.remove(i);
                }
            }
        }
        return jo.toJSONString();
    }
}
