package weaver.mfbdt.util;

import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.soa.workflow.request.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * action工具类
 *
 * @author wangj
 * @Date    创建日期
 * @version 1.00版本
 */
public class ActionsUtil {

    /**
    * 根据requestInfo获取主表数据
    * */
    public static Map getMainInfo(RequestInfo requestInfo){
        Map map = new HashMap();
        Property[] property = requestInfo.getMainTableInfo().getProperty();
        for (int i = 0; i < property.length; i++) {
            map.put(property[i].getName().toLowerCase(), Util.null2String(property[i].getValue()));
        }
        return map;
    }

    /**
     * 根据requestInfo获取明细表数据
     * */
    public static List getDetailInfo(RequestInfo requestInfo,int num){
        DetailTable detailTable = requestInfo.getDetailTableInfo().getDetailTable(num);
        //dtltable数组中的行数据集合
        Row[] rows = detailTable.getRow();
        List sublist = new ArrayList();
        for (int i = 0; i < rows.length; i++) {
            Row row = rows[i];
            Map onerow = new HashMap();
            sublist.add(onerow);
            Cell[] cells = row.getCell();
            for (int j = 0; j < cells.length; j++) {
                Cell cell = cells[j];
                onerow.put(cell.getName(), Util.null2String(cell.getValue()));
            }
        }
        return sublist;
    }

}
