<%@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 = "E7";

    Map<String,Map<String,String>> E9DepartmentMap = getE9HrmDepartmentList();
    Map<String,Map<String,String>> E7DepartmentMap = getE7HrmDepartmentList2(dataResource);
    out.println("E9DepartmentMap:"+E9DepartmentMap.size()+"</br>");
    out.println("E7DepartmentMap:"+E7DepartmentMap.size()+"</br>");
    String E7IDS = "";
    out.println("E7和E9不一致的:</br>");

    Iterator<Map.Entry<String,Map<String,String>>> iterator = E7DepartmentMap.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 e7departmentname = E7Map.get("departmentname");
        String e7departmentcode = E7Map.get("departmentcode");
        String e7canceled = E7Map.get("canceled");

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

            String e9departmentname = E9Map.get("departmentname");
            String e9departmentcode = E9Map.get("departmentcode");
            String e9canceled = E9Map.get("canceled");

            if(!e7canceled.equals(e9canceled)
               || !e7departmentname.equals(e9departmentname)
               || !e7departmentcode.equals(e9departmentcode)
            ){
                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 = E9DepartmentMap.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 e9departmentname = E9Map.get("departmentname");
        String e9departmentcode = E9Map.get("departmentcode");
        String e9canceled = E9Map.get("canceled");

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

            String e7departmentname = E7Map.get("departmentname");
            String e7departmentcode = E7Map.get("departmentcode");
            String e7canceled = E7Map.get("canceled");

            if(!e7canceled.equals(e9canceled)
                    || !e7departmentname.equals(e9departmentname)
                    || !e7departmentcode.equals(e9departmentcode)
            ){
                E9IDS += StringUtils.isBlank(E9IDS) ? outkey : ","+outkey ;
            }
        }
    }
    out.println(E9IDS+"</br>");
%>

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

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


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


    public Map<String,Map<String,String>> getE7HrmDepartmentList2(String dataResource){
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7SubcompanyMap = new HashMap<String,Map<String,String>>();
        String sql = " select id,departmentname,departmentcode,canceled from hrmdepartment  " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String departmentname = Util.null2String(rsd.getString("departmentname"));
            String canceled = Util.null2String(rsd.getString("canceled"));
            String departmentcode = Util.null2String(rsd.getString("departmentcode"));
            Map<String,String> map = new HashMap<String,String>();
            map.put("id",id);
            map.put("departmentname",departmentname);
            map.put("departmentcode",departmentcode);
            map.put("canceled",canceled);

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




