package nckd.jxccl.swc.init.plugin.form;

import kd.bos.form.mcontrol.mobtable.MobTablePackageDataHandler;
import kd.bos.form.mcontrol.mobtable.MobTableRowBuilder;
import kd.bos.form.mcontrol.mobtable.MobTableRowData;
import kd.bos.form.mcontrol.mobtable.events.MobTableHandleResult;
import kd.bos.form.mcontrol.mobtable.events.MobTablePackageDataHandlerArgs;
import kd.bos.form.mcontrol.mobtable.tablecolumn.MobTableColumn;
import java.math.BigDecimal;
import java.util.*;

/**
 * 移动表格数据处理
 * @Description:
 * @Author: turborao
 * @Date: 2025/11/26
 */
public class EmpSalaryQueryMobDataHandler extends MobTablePackageDataHandler {
    @Override
    public MobTableHandleResult handleData(MobTablePackageDataHandlerArgs args) {
        List<MobTableColumn> mobTableColumns = args.getMobTableColumns();
        MobTableHandleResult mobTableHandleResult = new MobTableHandleResult();
        List<MobTableRowData> mobTableRowDataList = new ArrayList<>();
        Map<String, BigDecimal> calItemAmtMap = args.getCustomParam("calItemAmt");
        Map<String, String> itemNameMap = args.getCustomParam("itemName");

        if(calItemAmtMap != null && calItemAmtMap.size() > 0 && itemNameMap != null && calItemAmtMap.size() > 0) {
            int index = 0;
            for (Map.Entry<String, BigDecimal> entry : calItemAmtMap.entrySet()) {
                String key = entry.getKey();
                BigDecimal value = entry.getValue();

                // 处理 key 和 value
                MobTableRowData mobTableRowData = MobTableRowBuilder.buildTemplateRowData(index, mobTableColumns);
                mobTableRowData.setValue("nckd_item", itemNameMap.get(key));
                mobTableRowData.setValue("nckd_amt", calItemAmtMap.get(key));
                mobTableRowDataList.add(mobTableRowData);
                index++;
                System.out.println("Key: " + key + "name：, " + itemNameMap.get(key) + "Value: " + value);
            }

            mobTableHandleResult.setMobTableRowDataList(mobTableRowDataList);
            // 额外格式化信息如日期、金额，支持重写
            mobTableHandleResult.setFmtInfo(getFmtInfo(args));
        }
        return mobTableHandleResult;
    }

}