package com.engine.htsc.hthy.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.Util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HymbDataListCmd extends AbstractCommonCommand<Map<String, Object>> {

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

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        RecordSet rs = new RecordSet();

        BaseBean bb = new BaseBean();
        Map<String, Object> apimap = new HashMap<String, Object>();
        List<Map<String,Object>> dt1list = new ArrayList<Map<String,Object>>();
        Map<String,Object> dt1map = null;

        List<Map<String,Object>> dt2list = new ArrayList<Map<String,Object>>();
        Map<String,Object> dt2map = null;

        String hylx = Util.null2String(params.get("hylx"));
        try{

            if(!"".equals(hylx)){
//                String sql1 =   " select l.ryxm, l.id\n" +
//                                "  from uf_hyxx l\n" +
//                                "  where l.id in (select xm\n" +
//                                "                  from uf_hymb t\n" +
//                                "                 inner join uf_hymb_dt1 k\n" +
//                                "                    on k.mainid = t.id\n" +
//                                "                 where hylxxz = '"+hylx+"')";

                String sql1 =   "  select l.ryxm,l.id,p.hylxxz\n" +
                                "  from uf_hyxx l\n" +
                                "  inner join uf_hymb_dt1 k on k.xm = l.id\n" +
                                "    inner join uf_hymb p on k.mainid = p.id \n" +
                                "  where p.hylxxz = '"+hylx+"'\n" +
                                "  order by k.mainidorder  ";
                bb.writeLog("sql1:"+sql1);
                rs.executeQuery(sql1);
                while (rs.next()){
                    String id = Util.null2String(rs.getString("id"));
                    String ryxm = Util.null2String(rs.getString("ryxm"));
                    dt1map = new HashMap<String,Object>();
                    dt1map.put("id",id);
                    dt1map.put("name",ryxm);
                    dt1list.add(dt1map);
                }

//                String sql2 =   " select l.ryxm, l.id\n" +
//                                "  from uf_hyxx l\n" +
//                                "  where l.id in (select xm\n" +
//                                "                  from uf_hymb t\n" +
//                                "                 inner join uf_hymb_dt2 k\n" +
//                                "                    on k.mainid = t.id\n" +
//                                "                 where hylxxz = '"+hylx+"')";

                String sql2 =   "  select l.ryxm,l.id,p.hylxxz\n" +
                                "  from uf_hyxx l\n" +
                                "  inner join uf_hymb_dt2 k on k.xm = l.id\n" +
                                "    inner join uf_hymb p on k.mainid = p.id \n" +
                                "  where p.hylxxz = '"+hylx+"'\n" +
                                "  order by k.mainidorder  ";

                bb.writeLog("sql2:"+sql2);
                rs.executeQuery(sql2);
                while (rs.next()){
                    String id = Util.null2String(rs.getString("id"));
                    String ryxm = Util.null2String(rs.getString("ryxm"));
                    bb.writeLog("ryxm:"+ryxm);
                    dt2map = new HashMap<String,Object>();
                    dt2map.put("id",id);
                    dt2map.put("name",ryxm);
                    dt2list.add(dt2map);
                }
            }
        }catch (Exception e){
            System.out.println(e);
        }
        apimap.put("data1",dt1list);
        apimap.put("data2",dt2list);
        return apimap;
    }
}
