package com.engine.htsc.fkxnbm.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;

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

public class FkxnbmCmd extends AbstractCommonCommand<Map<String, Object>> {
    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    public FkxnbmCmd(Map<String, Object> params) {
        this.params = params;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> appdate = new HashMap<String, Object>();
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        try{
            List<Map<String,String>> list = new ArrayList<Map<String,String>>();
            Map<String,String> map = null;
            String sql = "select dept_code,dept_name,parent_dept_code,parent_dept_name,director_code,director_name from uf_fkxnbmpzb ";
            rs.execute(sql);
            while (rs.next()){
                map = new HashMap<String,String>();
                String dept_code = Util.null2String(rs.getString("dept_code"));
                String dept_name = Util.null2String(rs.getString("dept_name"));
                String parent_dept_code = Util.null2String(rs.getString("parent_dept_code"));
                String parent_dept_name = Util.null2String(rs.getString("parent_dept_name"));
                String director_code = Util.null2String(rs.getString("director_code"));
                String director_name = Util.null2String(rs.getString("director_name"));

                map.put("dept_code",dept_code);
                map.put("dept_name",dept_name);
                map.put("parent_dept_code",parent_dept_code);
                map.put("parent_dept_name",parent_dept_name);
                map.put("parent_dept_name",parent_dept_name);
                map.put("director_code",director_code);
                map.put("director_name",director_name);
                list.add(map);
            }

            System.out.println("list:"+list.size());
            appdate.put("data",list);
        }catch (Exception e){
            bb.writeLog("e:"+e);
        }
        return appdate;
    }

    public static void main(String[] args) {
        GCONST.setRootPath("WEB-INF/");
        GCONST.setServerName("ecology");
        Map<String, Object> params=new HashMap<>();

        FkxnbmCmd htscMhjcCmd=new FkxnbmCmd(params);
        CommandContext ceshi = new CommandContext(null,null);
        htscMhjcCmd.execute(ceshi);
    }
}
