<%@page import="weaver.conn.RecordSet"%>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.conn.RecordSetDataSource" %>
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    String dataResource = "E7TEST";

    Map<String,Map<String,String>> E9SubcompanyMap = getE9HrmSubcompanyList();
    Map<String,Map<String,String>> E7SubcompanyMap = getE7HrmSubcompanyList2(dataResource);
    out.println("E9SubcompanyMap:"+E9SubcompanyMap.size()+"</br>");
    out.println("E7SubcompanyMap:"+E7SubcompanyMap.size()+"</br>");
    String E7IDS = "";
    out.println("E7和E9不一致的:</br>");

    Iterator<Map.Entry<String,Map<String,String>>> iterator = E7SubcompanyMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String,Map<String,String>> entry = iterator.next();
        String e7id = entry.getKey();
        Map<String,String> E7Map = entry.getValue();
        String e7subcompanyname = E7Map.get("subcompanyname");
        String e7subcompanycode = E7Map.get("subcompanycode");
        String e7canceled = E7Map.get("canceled");

        if(E9SubcompanyMap.containsKey(e7id)){
            Map<String,String> E9Map = E9SubcompanyMap.get(e7id);

            String e9subcompanyname = E9Map.get("subcompanyname");
            String e9subcompanycode = E9Map.get("subcompanycode");
            String e9canceled = E9Map.get("canceled");

            if(!e7canceled.equals(e9canceled)
               || !e7subcompanyname.equals(e9subcompanyname)
               || !e7subcompanycode.equals(e9subcompanycode)
            ){
                E7IDS += StringUtils.isBlank(E7IDS) ? e7id : ","+e7id ;
            }
        }
    }

    out.println(E7IDS+"</br>");

    out.println("E9比E7多的:</br>");
    String E9IDS = "";
    Iterator<Map.Entry<String,Map<String,String>>> iterator2 = E9SubcompanyMap.entrySet().iterator();
    while (iterator2.hasNext()) {
        Map.Entry<String,Map<String,String>> entry = iterator2.next();
        String outkey = entry.getKey();
        Map<String,String> E9Map = entry.getValue();
        String e9subcompanyname = E9Map.get("subcompanyname");
        String e9subcompanycode = E9Map.get("subcompanycode");
        String e9canceled = E9Map.get("canceled");

        if(E7SubcompanyMap.containsKey(outkey)){
            Map<String,String> E7Map = E7SubcompanyMap.get(outkey);

            String e7subcompanyname = E7Map.get("subcompanyname");
            String e7subcompanycode = E7Map.get("subcompanycode");
            String e7canceled = E7Map.get("canceled");

            if(!e7canceled.equals(e9canceled)
                    || !e7subcompanyname.equals(e9subcompanyname)
                    || !e7subcompanycode.equals(e9subcompanycode)
            ){
                E9IDS += StringUtils.isBlank(E9IDS) ? outkey : ","+outkey ;
            }
        }
    }
    out.println(E9IDS+"</br>");
%>

<%!
    /***
     *
     * @return
     */
    public Map<String,Map<String,String>> getE9HrmSubcompanyList(){
        RecordSet rs = new RecordSet();
        Map<String,Map<String,String>> E9SubcompanyMap = new HashMap<String,Map<String,String>>();
        String sql = " select outkey,subcompanyname,subcompanycode,canceled from hrmsubcompany " ;
        rs.execute(sql);
        while (rs.next()){
            String outkey = Util.null2String(rs.getString("outkey"));
            String subcompanyname = Util.null2String(rs.getString("subcompanyname"));
            String subcompanycode = Util.null2String(rs.getString("subcompanycode"));
            String canceled = Util.null2String(rs.getString("canceled"));

            Map<String,String> map = new HashMap<String,String>();
            map.put("outkey",outkey);
            map.put("subcompanyname",subcompanyname);
            map.put("subcompanycode",subcompanycode);
            map.put("canceled",canceled);


            E9SubcompanyMap.put(outkey,map);
        }
        return E9SubcompanyMap;
    }


    public Map<String,Map<String,String>> getE7HrmSubcompanyList2(String dataResource){
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7SubcompanyMap = new HashMap<String,Map<String,String>>();
        String sql = " select id,subcompanyname,subcompanydesc,supsubcomid,canceled,subcompanycode from hrmsubcompany  " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String subcompanyname = Util.null2String(rsd.getString("subcompanyname"));
            String canceled = Util.null2String(rsd.getString("canceled"));
            String subcompanycode = Util.null2String(rsd.getString("subcompanycode"));
            Map<String,String> map = new HashMap<String,String>();
            map.put("id",id);
            map.put("subcompanyname",subcompanyname);
            map.put("subcompanycode",subcompanycode);
            map.put("canceled",canceled);

            E7SubcompanyMap.put(id,map);
        }
        return E7SubcompanyMap;
    }
%>




