

package com.jeelowcode.core.framework.enhance.example.report.xtsy;

import com.jeelowcode.tool.framework.common.util.json.JsonUtils;
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
import com.jeelowcode.core.framework.config.aspect.enhancereport.plugin.ReportAfterAdvicePlugin;
import com.jeelowcode.core.framework.utils.Func;
import com.jeelowcode.core.framework.utils.FuncWeb;
import com.jeelowcode.framework.utils.utils.JeeLowCodeUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 报表-系统首页-表格
 */
@Component("exampleXtsyFormReportEnhance")
public class ExampleXtsyFormReportEnhance implements ReportAfterAdvicePlugin {

    @Override
    public void execute(EnhanceReportContext enhanceContext) {
        List<Map<String, Object>> records = enhanceContext.getResult().getRecords();
        if (Func.isEmpty(records)) {
            return;
        }
        String jsonStr = records.get(0).get("value").toString();
        List<Map> list = JsonUtils.parseArray(jsonStr, Map.class);
        Map<String, Object> params = enhanceContext.getParam().getParams();
        String type = JeeLowCodeUtils.getMap2Str(params, "type");
        String finalType = Func.isNotEmpty(type) ? type : "1";
        List<Map> list1 = list.stream().filter(item -> finalType.equals(item.get("type").toString())).collect(Collectors.toList());
        List<Map<String, Object>> list2 = (List<Map<String, Object>>) list1.get(0).get("data");
        FuncWeb.setReportResult(enhanceContext, list2);
    }
}
