package com.kingdee.eas.custom.projectbonus.web.handler;

import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.dynamic.util.ExportHelper;
import com.kingdee.shr.base.syssetting.web.handler.DynamicListHandler;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 奖金同步动态列表
 * @Date 2024/6/19 20:30
 * @Created by Heyuan
 */
public class ProjectBonusDynamicHandler extends DynamicListHandler {
    //设置金额字段显示精度
    private static List decimalPrecisionFields = new ArrayList();

    static {
        decimalPrecisionFields.add("bdpapd.opinionamount");
        decimalPrecisionFields.add("bdpapd.indivbonusamount");
        decimalPrecisionFields.add("bdpapd.approvalamount");
        decimalPrecisionFields.add("bdp.bonusamount");
        decimalPrecisionFields.add("bdp.totalbonushalf");
        decimalPrecisionFields.add("bdp.totalbonusreal");
        decimalPrecisionFields.add("bdp.directmanprojbonus");
        decimalPrecisionFields.add("bdp.contramanprojbonus");
        decimalPrecisionFields.add("bdp.condmanprojectbonus");
        decimalPrecisionFields.add("bdp.stramanprojectbonus");
        decimalPrecisionFields.add("bdp.bonusadjustment");
    }

    /**
     * 设置金额字段精度
     *
     * @param request
     * @param helper
     * @return
     * @throws SHRWebException
     */
    @Override
    protected Map<String, Object> initExportExcelConfig(HttpServletRequest request, ExportHelper helper) throws SHRWebException {
        Map<String, Object> excelConfig = super.initExportExcelConfig(request, helper);
        List<Map<String, Object>> columnModels = (List) excelConfig.get("columnModel");
        for (int i = 0; i < columnModels.size(); i++) {
            Map<String, Object> columnModel = columnModels.get(i);
            String name = (String) columnModel.get("name");
            Map<String, Object> attributes = new HashMap<>();
            attributes.putAll((Map<? extends String, ?>) columnModel.get("attributes"));
            if (decimalPrecisionFields.contains(name)) {
                attributes.put("decimalPrecision", 6);
            }else{
                attributes.put("decimalPrecision", 2);
            }
            columnModel.put("attributes", attributes);
        }
        return excelConfig;
    }
}
