<%@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" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="weaver.formmode.setup.ModeRightInfo" %>
<jsp:useBean id="bb" class="weaver.general.BaseBean" scope="page" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%
    String dataResource = "E7TEST";
    int modifier = 1;
    int creater = 1;
    String mainid = synSubcompanyData(modifier,creater,dataResource);
    out.println("mainid:"+mainid);
    synDepartmentData(modifier,creater,dataResource,mainid);
    synHrmJobGroupData(modifier,creater,dataResource,mainid);
    synHrmJobActivityData(modifier,creater,dataResource,mainid);
    synHrmJobTitleData(modifier,creater,dataResource,mainid);
    synHrmresourceData(modifier,creater,dataResource,mainid);

%>


<%!
    public String synSubcompanyData(int modifier,int creater,String dataResource){

        int totle_count = 0;
        int update_success_count = 0;
        int update_fail_count = 0;
        int update_exp_count = 0;

        int insert_success_count = 0;
        int insert_fail_count = 0;
        int insert_exp_count = 0;

        int unchanged_count = 0;
        int data_error_count = 0;

        List<String> dataErrorList = new ArrayList<String>();
        List<Map<String,String>> sqlList = new ArrayList<Map<String,String>>();

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);

        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        Map<String,String> E9SubcompanyOutkey = getE9SubcompanyOutkey();
        Map<String,Map<String,String>> E7SubcompanyMap = getE7HrmSubcompanyList2(dataResource);

        List<Map<String,Object>> topInsertList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> topUpdateList = new ArrayList<Map<String,Object>>();

        List<String> topList = new ArrayList<>();
        String sql =" select id,subcompanyname,subcompanydesc,supsubcomid,canceled,subcompanycode,outkey,showorder " +
                    " from hrmsubcompany \n" +
                    " where (supsubcomid is null or supsubcomid = -1 or supsubcomid = 0) \n" ;
        rs.execute(sql);
        while(rs.next()) {
            totle_count++;

            String e9Id = Util.null2String(rs.getString("id"));
            topList.add(e9Id);

            String subcompanyname = Util.null2String(rs.getString("subcompanyname"));
            String subcompanydesc = Util.null2String(rs.getString("subcompanydesc"));
            String canceled = Util.null2String(rs.getString("canceled"));
            String subcompanycode = Util.null2String(rs.getString("subcompanycode"));
            String supsubcomid = Util.null2String(rs.getString("supsubcomid")).trim();
            int showorder = Util.getIntValue(rs.getString("showorder"));
            String outkey = Util.null2String(rs.getString("outkey"));  //E7的hrmsubcompany的ID

            Map<String,Object> E9Map = new HashMap<String, Object>();
            E9Map.put("e9id", e9Id);
            E9Map.put("subcompanyname", subcompanyname);
            if (StringUtils.isNotBlank(subcompanydesc)) {
                E9Map.put("subcompanydesc", subcompanydesc);
            }
            if (StringUtils.isNotBlank(canceled)) {
                E9Map.put("canceled", canceled);
            }
            if (showorder > -1) {
                E9Map.put("showorder", showorder);
            }
            if(StringUtils.isNotBlank(subcompanycode)){
                E9Map.put("subcompanycode", subcompanycode);
            }

            String supsubcomOutKey = "" ;
            if("0".equals(supsubcomid) || "-1".equals(supsubcomid) || StringUtils.isBlank(supsubcomid+"")){
                supsubcomOutKey = "0";
            }else{
                if(E9SubcompanyOutkey.containsKey(supsubcomid)){
                    supsubcomOutKey = E9SubcompanyOutkey.get(supsubcomid);
                }
            }

            if(StringUtils.isNotBlank(outkey)){
                if(E7SubcompanyMap.containsKey(outkey)){
                    if(StringUtils.isNotBlank(supsubcomOutKey) && E7SubcompanyMap.containsKey(supsubcomOutKey)){
                        Map<String,String> E7SubcompanyInfo = E7SubcompanyMap.get(outkey);
                        String e7subcompanyname = Util.null2String(E7SubcompanyInfo.get("subcompanyname"));
                        String e7subcompanydesc = Util.null2String(E7SubcompanyInfo.get("subcompanydesc"));
                        String e7supsubcomid = Util.null2String(E7SubcompanyInfo.get("supsubcomid"));
                        String e7canceled = Util.null2String(E7SubcompanyInfo.get("canceled"));
                        String e7subcompanycode = Util.null2String(E7SubcompanyInfo.get("subcompanycode"));

                        if(!e7subcompanyname.equals(subcompanyname)
                                || !e7subcompanydesc.equals(subcompanydesc)
                                || !e7supsubcomid.equals(supsubcomOutKey)
                                || !e7canceled.equals(canceled)
                                || !e7subcompanycode.equals(subcompanycode)
                        ){
                            E9Map.put("supsubcomid", supsubcomOutKey);
                            E9Map.put("e7id", outkey);
                            topUpdateList.add(E9Map);
                        }else{
                            unchanged_count++;
                        }
                    }else{
                        data_error_count++;
                        dataErrorList.add(e9Id);
                    }
                }else{
                    data_error_count++;
                    dataErrorList.add(e9Id);
                }
            }else{
                if(StringUtils.isNotBlank(supsubcomOutKey) && E7SubcompanyMap.containsKey(supsubcomOutKey)){
                    E9Map.put("supsubcomid", supsubcomOutKey);
                    topInsertList.add(E9Map);
                }else{
                    data_error_count++;
                    dataErrorList.add(e9Id);
                }
            }
        }

        bb.writeLog("topUpdateList:"+topUpdateList.size());
        bb.writeLog("topInsertList:"+topInsertList.size());

        for(Map<String,Object> E9Map : topInsertList){

            String e9id = Util.null2String(E9Map.get("e9id"));

            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            E9Map.put("modifier",modifier);
            E9Map.put("creater",creater);
            E9Map.put("UUID",uuid);
            E9Map.put("companyid",1);//默认公司是1

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }
            }

            try {
                sql = " insert into hrmsubcompany(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
                boolean isTrue = rsd.execute(sql);
                if(isTrue){
                    String newE7Id = "";
                    sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                    rsd.executeSql(sql);
                    if(rs.next()){
                        newE7Id = Util.null2String(rs.getString("id"));
                    }

                    if(StringUtils.isNotBlank(newE7Id)){
                        sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                        boolean isTrue2 = rs.executeUpdate(sql);
                        if(isTrue2){
                            insert_success_count++;
                        }else{
                            insert_exp_count++;
                        }
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_fail_count++;
                }

                Map<String,String> sqlMap = new HashMap<String,String>();
                sqlMap.put("zxyj",sql);
                sqlMap.put("fbid",e9id);
                sqlMap.put("zxjg",isTrue ? "true" : "false");
                sqlList.add(sqlMap);
            }catch (Exception e){
                bb.writeLog("e:"+e);
                insert_exp_count++;
            }
        }

        for(Map<String,Object> E9Map : topUpdateList){
            String e7id = Util.null2String(E9Map.get("e7id"));
            String e9id = Util.null2String(E9Map.get("e9id"));

            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
                }
            }

            try{
                sql = "update hrmsubcompany set "+valuesStr+" where id = '"+e7id+"' ";
                boolean isTrue = rsd.execute(sql);
                if(isTrue){
                    update_success_count++;
                }else{
                    update_fail_count++;
                }

                Map<String,String> sqlMap = new HashMap<String,String>();
                sqlMap.put("zxyj",sql);
                sqlMap.put("fbid",e9id);
                sqlMap.put("zxjg",isTrue ? "true" : "false");
                sqlList.add(sqlMap);
            }catch (Exception e){
                bb.writeLog("e:"+e);
                update_exp_count++;
            }
        }

        List<Map<String,Object>> insertList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> updateList = new ArrayList<Map<String,Object>>();

        for(String subcompanyid : topList){
            if(StringUtils.isNotBlank(subcompanyid)){
                sql = " select id,subcompanyname,subcompanydesc,supsubcomid,showorder,\n" +
                        " canceled,subcompanycode,outkey from hrmsubcompany \n" +
                        " connect by prior  id = supsubcomid \n" +
                        " start with supsubcomid = "+subcompanyid;

                rs.executeQuery(sql);
                while (rs.next()){

                    totle_count++;

                    String e9Id = Util.null2String(rs.getString("id"));
                    String subcompanyname = Util.null2String(rs.getString("subcompanyname"));
                    String subcompanydesc = Util.null2String(rs.getString("subcompanydesc"));
                    String canceled = Util.null2String(rs.getString("canceled"));
                    String subcompanycode = Util.null2String(rs.getString("subcompanycode"));
                    String supsubcomid = Util.null2String(rs.getString("supsubcomid")).trim();
                    int showorder = Util.getIntValue(rs.getString("showorder"));
                    String outkey = Util.null2String(rs.getString("outkey"));  //E7的hrmsubcompany的ID

                    Map<String,Object> E9Map = new HashMap<String, Object>();
                    E9Map.put("e9id", e9Id);
                    E9Map.put("subcompanyname", subcompanyname);
                    if (StringUtils.isNotBlank(subcompanydesc)) {
                        E9Map.put("subcompanydesc", subcompanydesc);
                    }
                    if (StringUtils.isNotBlank(canceled)) {
                        E9Map.put("canceled", canceled);
                    }
                    if (showorder > -1) {
                        E9Map.put("showorder", showorder);
                    }
                    if(StringUtils.isNotBlank(subcompanycode)){
                        E9Map.put("subcompanycode", subcompanycode);
                    }

                    String supsubcomOutKey = "" ;
                    if("0".equals(supsubcomid) || "-1".equals(supsubcomid) || StringUtils.isBlank(supsubcomid+"")){
                        supsubcomOutKey = "0";
                    }else{
                        if(E9SubcompanyOutkey.containsKey(supsubcomid)){
                            supsubcomOutKey = E9SubcompanyOutkey.get(supsubcomid);
                        }
                    }

                    if(StringUtils.isNotBlank(outkey)){
                        if(E7SubcompanyMap.containsKey(outkey)){

                            if(StringUtils.isNotBlank(supsubcomOutKey) && E7SubcompanyMap.containsKey(supsubcomOutKey)){


                                Map<String,String> E7SubcompanyInfo = E7SubcompanyMap.get(outkey);
                                String e7subcompanyname = Util.null2String(E7SubcompanyInfo.get("subcompanyname"));
                                String e7subcompanydesc = Util.null2String(E7SubcompanyInfo.get("subcompanydesc"));
                                String e7supsubcomid = Util.null2String(E7SubcompanyInfo.get("supsubcomid"));
                                String e7canceled = Util.null2String(E7SubcompanyInfo.get("canceled"));
                                String e7subcompanycode = Util.null2String(E7SubcompanyInfo.get("subcompanycode"));

                                if(!e7subcompanyname.equals(subcompanyname)
                                        || !e7subcompanydesc.equals(subcompanydesc)
                                        || !e7supsubcomid.equals(supsubcomOutKey)
                                        || !e7canceled.equals(canceled)
                                        || !e7subcompanycode.equals(subcompanycode)
                                ){
                                    E9Map.put("supsubcomid", supsubcomOutKey);
                                    E9Map.put("e7id", outkey);
                                    updateList.add(E9Map);
                                }else{
                                    data_error_count++;
                                    dataErrorList.add(e9Id);
                                }
                            }else{
                                data_error_count++;
                                dataErrorList.add(e9Id);
                            }
                        }else{
                            data_error_count++;
                            dataErrorList.add(e9Id);
                        }
                    }else{
                        if(StringUtils.isNotBlank(supsubcomOutKey) && E7SubcompanyMap.containsKey(supsubcomOutKey)){
                            E9Map.put("supsubcomid", supsubcomOutKey);
                            insertList.add(E9Map);
                        }else{
                            data_error_count++;
                            dataErrorList.add(e9Id);
                        }
                    }
                }
            }
        }

        bb.writeLog("insertList:"+insertList.size()+"</br>");
        bb.writeLog("updateList:"+updateList.size()+"</br>");

        for(Map<String,Object> E9Map : insertList){

            String e9id = Util.null2String(E9Map.get("e9id"));

            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            E9Map.put("modifier",modifier);
            E9Map.put("creater",creater);
            E9Map.put("UUID",uuid);
            E9Map.put("companyid",1);//默认公司是1

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }
            }

            try {
                sql = " insert into hrmsubcompany(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
                boolean isTrue = rsd.execute(sql);
                if(isTrue){
                    String newE7Id = "";
                    sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                    rsd.executeSql(sql);
                    if(rs.next()){
                        newE7Id = Util.null2String(rs.getString("id"));
                    }

                    if(StringUtils.isNotBlank(newE7Id)){
                        sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                        boolean isTrue2 = rs.executeUpdate(sql);
                        if(isTrue2){
                            insert_success_count++;
                        }else{
                            insert_exp_count++;
                        }
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_fail_count++;
                }

                Map<String,String> sqlMap = new HashMap<String,String>();
                sqlMap.put("zxyj",sql);
                sqlMap.put("fbid",e9id);
                sqlMap.put("zxjg",isTrue ? "true" : "false");
                sqlList.add(sqlMap);
            }catch (Exception e){
                bb.writeLog("e:"+e);
                insert_exp_count++;
            }
        }

        for(Map<String,Object> E9Map : updateList){
            String e7id = Util.null2String(E9Map.get("e7id"));
            String e9id = Util.null2String(E9Map.get("e9id"));

            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
                }
            }

            try{
                sql = "update hrmsubcompany set "+valuesStr+" where id = '"+e7id+"' ";
                boolean isTrue = rsd.execute(sql);
                if(isTrue){
                    update_success_count++;
                }else{
                    update_fail_count++;
                }

                Map<String,String> sqlMap = new HashMap<String,String>();
                sqlMap.put("zxyj",sql);
                sqlMap.put("fbid",e9id);
                sqlMap.put("zxjg",isTrue ? "true" : "false");
                sqlList.add(sqlMap);
            }catch (Exception e){
                bb.writeLog("e:"+e);
                update_exp_count++;
            }
        }

        String fbtbjg = "分部共:"+totle_count+"行数据,数据一致工:"+unchanged_count+"。新增成功:"+insert_success_count+",新增失败:"+insert_fail_count+",新增异常:"+insert_exp_count+"。"+
                         "更新成功:"+update_success_count+",更新失败:"+update_fail_count+",更新异常:"+update_exp_count+"。"+
                         "数据异常(ID在E7中不存在):"+data_error_count ;

        String mainid = recordSynMainlog("",fbtbjg,"","","","","");
        return mainid;

    }
%>


<%!
    public void synDepartmentData(int modifier,int creater,String dataResource,String mainid){
        int totle_count = 0;
        int update_success_count = 0;
        int update_fail_count = 0;
        int update_exp_count = 0;

        int insert_success_count = 0;
        int insert_fail_count = 0;
        int insert_exp_count = 0;


        int unchanged_count = 0;
        int data_error_count = 0;

        List<String> dataErrorList = new ArrayList<String>();
        List<Map<String,String>> sqlList = new ArrayList<Map<String,String>>();
        RecordSet rs = new RecordSet();
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);

        BaseBean bb = new BaseBean();
        Map<String,String> subCompanyOutkeyMap = getE9SubcompanyOutkey();
        Map<String,String> departmentOutkeyMap = getE9DepartmentOutkey();
        Map<String,Map<String,String>> E7DepartmentMap = getE7DepartmentData(dataResource);
        List<String> E7SubcompanyList = getE7HrmSubcompanyList(dataResource);

        bb.writeLog("subCompanyOutkeyMap:"+subCompanyOutkeyMap.size()+"</br>");
        bb.writeLog("departmentOutkeyMap:"+departmentOutkeyMap.size()+"</br>");
        bb.writeLog("E7DepartmentMap:"+E7DepartmentMap.size()+"</br>");
        bb.writeLog("E7SubcompanyList:"+E7SubcompanyList.size()+"</br>");

        List<Map<String,Object>> topInsertList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> topUpdateList = new ArrayList<Map<String,Object>>();
        List<String> topList = new ArrayList<>();
        String sql =" select id,departmentmark,departmentname,subcompanyid1,supdepid,allsupdepid,canceled,departmentcode,outkey,tlevel,showorderoftree,showorder\n" +
                    " from hrmdepartment \n" +
                    " where supdepid = 0 \n" ;
        bb.writeLog("e9-sql:"+sql+"</br>");
        rs.execute(sql);
        while(rs.next()) {
            totle_count++;
            String e9Id = Util.null2String(rs.getString("id"));
            topList.add(e9Id);

            String departmentmark = Util.null2String(rs.getString("departmentmark"));
            String departmentname = Util.null2String(rs.getString("departmentname"));
            String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
            String supdepid = Util.null2String(rs.getString("supdepid"));
            String allsupdepid = Util.null2String(rs.getString("allsupdepid"));
            String canceled = Util.null2String(rs.getString("canceled"));
            String departmentcode = Util.null2String(rs.getString("departmentcode"));
            String outkey = Util.null2String(rs.getString("outkey"));  //E7的hrmsubcompany的ID

            String tlevel = Util.null2String(rs.getString("tlevel"));
            String showorderoftree = Util.null2String(rs.getString("showorderoftree"));
            String showorder = Util.null2String(rs.getString("showorder"));

            Map<String,Object> E9Map = new HashMap<String, Object>();
            E9Map.put("e9id", e9Id);
            E9Map.put("departmentname", departmentname);

            if (StringUtils.isNotBlank(departmentmark)) {
                E9Map.put("departmentmark", departmentmark);
            }
            if (StringUtils.isNotBlank(canceled)) {
                E9Map.put("canceled", canceled);
            }
            if (StringUtils.isNotBlank(departmentcode)) {
                E9Map.put("departmentcode", departmentcode);
            }
            if(StringUtils.isNotBlank(canceled)){
                E9Map.put("canceled", canceled);
            }

            if (StringUtils.isNotBlank(tlevel)) {
                E9Map.put("tlevel", tlevel);
            }
            if (StringUtils.isNotBlank(showorderoftree)) {
                E9Map.put("showorderoftree", showorderoftree);
            }
            if (StringUtils.isNotBlank(showorder)) {
                E9Map.put("showorder", showorder);
            }


            String subcompanyOutKey = "" ;
            if(subCompanyOutkeyMap.containsKey(subcompanyid1)){
                subcompanyOutKey = subCompanyOutkeyMap.get(subcompanyid1);
            }

            String supdepidOutKey = "";
            if(StringUtils.isNotBlank(supdepid)){
                if("0".equals(supdepid) || "-1".equals(supdepid) || StringUtils.isBlank(supdepid)){
                    supdepidOutKey = "0";
                }else{
                    if(departmentOutkeyMap.containsKey(supdepid)){
                        supdepidOutKey = departmentOutkeyMap.get(supdepid);
                    }
                }
            }

            String allsupdepidOutKey = "";
            if(StringUtils.isNotBlank(allsupdepid)){
                String[] supdepids = allsupdepid.split(",");
                for(int i=0;i<supdepids.length;i++){
                    if(StringUtils.isNotBlank(supdepids[i])){
                        if(departmentOutkeyMap.containsKey(supdepids[i])){
                            String supdepid_OutKey = departmentOutkeyMap.get(supdepids[i]);
                            allsupdepidOutKey += StringUtils.isBlank(allsupdepidOutKey) ? supdepid_OutKey : ","+supdepid_OutKey ;
                        }
                    }
                }
            }

            if(StringUtils.isNotBlank(outkey)){
                if(E7DepartmentMap.containsKey(outkey)){
                    if(StringUtils.isNotBlank(subcompanyOutKey) && E7SubcompanyList.contains(subcompanyOutKey) ) {
                        if (StringUtils.isNotBlank(supdepidOutKey)) {

                            Map<String,String> e7DeptMap = E7DepartmentMap.get(outkey);
                            String e7departmentmark = Util.null2String(e7DeptMap.get("e7departmentmark"));
                            String e7departmentname = Util.null2String(e7DeptMap.get("e7departmentname"));
                            String e7subcompanyid1 = Util.null2String(e7DeptMap.get("e7subcompanyid1"));
                            String e7supdepid = Util.null2String(e7DeptMap.get("e7supdepid"));
                            String e7allsupdepid = Util.null2String(e7DeptMap.get("e7allsupdepid"));
                            String e7canceled = Util.null2String(e7DeptMap.get("e7canceled"));
                            String e7departmentcode = Util.null2String(e7DeptMap.get("e7departmentcode"));
                            String e7tlevel = Util.null2String(e7DeptMap.get("e7tlevel"));
                            String e7showorder = Util.null2String(e7DeptMap.get("e7showorder"));
                            if(!e7departmentmark.equals(departmentmark)
                                    || !e7departmentname.equals(departmentname)
                                    || !e7subcompanyid1.equals(subcompanyOutKey)
                                    || !e7supdepid.equals(supdepidOutKey)
                                    || !e7canceled.equals(canceled)
                                    || !e7departmentcode.equals(departmentcode)
                                    || !e7allsupdepid.equals(allsupdepidOutKey)
                            ){
                                E9Map.put("subcompanyid1", subcompanyOutKey);
                                E9Map.put("supdepid", supdepidOutKey);
                                E9Map.put("e7id", outkey);
                                topUpdateList.add(E9Map);
                            }else{
                                unchanged_count++;
                            }
                        }else{
                            dataErrorList.add(e9Id);
                            data_error_count++;
                        }
                    }else{
                        dataErrorList.add(e9Id);
                        data_error_count++;
                    }
                }else{
                    dataErrorList.add(e9Id);
                    data_error_count++;
                }
            }else{

                if(StringUtils.isNotBlank(subcompanyOutKey) && E7SubcompanyList.contains(subcompanyOutKey) ) {
                    if (StringUtils.isNotBlank(supdepidOutKey) && E7DepartmentMap.containsKey(supdepidOutKey)) {
                        E9Map.put("subcompanyid1", subcompanyOutKey);
                        E9Map.put("supdepid", supdepidOutKey);
                        topInsertList.add(E9Map);
                    }else{
                        dataErrorList.add(subcompanyid1);
                        data_error_count++;
                    }
                }else{
                    dataErrorList.add(subcompanyid1);
                    data_error_count++;
                }
            }
        }

        bb.writeLog("topUpdateList:"+topUpdateList.size()+"</br>");
        bb.writeLog("topInsertList:"+topInsertList.size()+"</br>");
        for(Map<String,Object> E9Map : topInsertList){
            String e9id = Util.null2String(E9Map.get("e9id"));

            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            E9Map.put("modifier",modifier);
            E9Map.put("creater",creater);
            E9Map.put("UUID",uuid);

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }
            }
            try{
                sql = " insert into hrmdepartment(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
                boolean isTrue = rsd.execute(sql);
                if(isTrue){
                    String newE7Id = "";
                    sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                    rsd.executeSql(sql);
                    if(rs.next()){
                        newE7Id = Util.null2String(rs.getString("id"));
                    }

                    if(StringUtils.isNotBlank(newE7Id)){
                        sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                        boolean isTrue2 = rs.executeUpdate(sql);
                        if(isTrue2){
                            insert_success_count++;
                        }else{
                            insert_exp_count++;
                        }
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_fail_count++;
                }

                Map<String,String> sqlMap = new HashMap<String,String>();
                sqlMap.put("zxyj",sql);
                sqlMap.put("fbid",e9id);
                sqlMap.put("zxjg",isTrue ? "true" : "false");
                sqlList.add(sqlMap);

            }catch (Exception e){
                bb.writeLog("");
                insert_exp_count++;
            }
        }

        for(Map<String,Object> E9Map : topUpdateList){
            String e7id = Util.null2String(E9Map.get("e7id"));
            String e9id = Util.null2String(E9Map.get("e9id"));

            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
                }
            }
            try{
                sql = "update hrmdepartment set "+valuesStr+" where id = '"+e7id+"' ";
                boolean isTrue = rsd.execute(sql);
                if(isTrue){
                    update_success_count++;
                }else{
                    update_fail_count++;
                }

                Map<String,String> sqlMap = new HashMap<String,String>();
                sqlMap.put("zxyj",sql);
                sqlMap.put("fbid",e9id);
                sqlMap.put("zxjg",isTrue ? "true" : "false");
                sqlList.add(sqlMap);

            }catch (Exception e){
                update_exp_count++;
            }
        }
        List<Map<String,Object>> insertList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> updateList = new ArrayList<Map<String,Object>>();
        for(String departmentid : topList){
            if(StringUtils.isNotBlank(departmentid)){
                sql =   " select id,departmentmark,departmentname,subcompanyid1,supdepid,allsupdepid,canceled,departmentcode,outkey,tlevel,showorderoftree,showorder \n" +
                        " from hrmdepartment  \n" +
                        " connect by prior id = supdepid \n" +
                        " start with supdepid = "+departmentid;

                rs.executeQuery(sql);
                while (rs.next()){
                    totle_count++;

                    String e9Id = Util.null2String(rs.getString("id"));
                    String departmentmark = Util.null2String(rs.getString("departmentmark"));
                    String departmentname = Util.null2String(rs.getString("departmentname"));
                    String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
                    String supdepid = Util.null2String(rs.getString("supdepid"));
                    String allsupdepid = Util.null2String(rs.getString("allsupdepid"));
                    String canceled = Util.null2String(rs.getString("canceled"));
                    String departmentcode = Util.null2String(rs.getString("departmentcode"));
                    String outkey = Util.null2String(rs.getString("outkey"));  //E7的hrmsubcompany的ID

                    String tlevel = Util.null2String(rs.getString("tlevel"));
                    String showorderoftree = Util.null2String(rs.getString("showorderoftree"));
                    String showorder = Util.null2String(rs.getString("showorder"));

                    Map<String,Object> E9Map = new HashMap<String, Object>();
                    E9Map.put("e9Id", e9Id);
                    E9Map.put("departmentname", departmentname);

                    if (StringUtils.isNotBlank(departmentmark)) {
                        E9Map.put("departmentmark", departmentmark);
                    }
                    if (StringUtils.isNotBlank(canceled)) {
                        E9Map.put("canceled", canceled);
                    }
                    if (StringUtils.isNotBlank(departmentcode)) {
                        E9Map.put("departmentcode", departmentcode);
                    }
                    if(StringUtils.isNotBlank(canceled)){
                        E9Map.put("canceled", canceled);
                    }

                    if (StringUtils.isNotBlank(tlevel)) {
                        E9Map.put("tlevel", tlevel);
                    }
                    if (StringUtils.isNotBlank(showorderoftree)) {
                        E9Map.put("showorderoftree", showorderoftree);
                    }
                    if (StringUtils.isNotBlank(showorder)) {
                        E9Map.put("showorder", showorder);
                    }

                    String subcompanyOutKey = "" ;
                    if(subCompanyOutkeyMap.containsKey(subcompanyid1)){
                        subcompanyOutKey = subCompanyOutkeyMap.get(subcompanyid1);
                    }

                    String supdepidOutKey = "";
                    if(StringUtils.isNotBlank(supdepid)){
                        if(departmentOutkeyMap.containsKey(supdepid)){
                            supdepidOutKey = departmentOutkeyMap.get(supdepid);
                        }
                    }

                    String allsupdepidOutKey = "";
                    if(StringUtils.isNotBlank(allsupdepid)){
                        String[] supdepids = allsupdepid.split(",");
                        for(int i=0;i<supdepids.length;i++){
                            if(StringUtils.isNotBlank(supdepids[i])){
                                if(departmentOutkeyMap.containsKey(supdepids[i])){
                                    String supdepid_OutKey = departmentOutkeyMap.get(supdepids[i]);
                                    allsupdepidOutKey += StringUtils.isBlank(allsupdepidOutKey) ? supdepid_OutKey : ","+supdepid_OutKey ;
                                }
                            }
                        }
                    }

                    if(StringUtils.isNotBlank(outkey)){
                        if(E7DepartmentMap.containsKey(outkey)){
                            if(StringUtils.isNotBlank(subcompanyOutKey) && E7SubcompanyList.contains(subcompanyOutKey) ) {
                                if (StringUtils.isNotBlank(supdepidOutKey) && E7DepartmentMap.containsKey(supdepidOutKey)) {

                                    Map<String,String> e7DeptMap = E7DepartmentMap.get(outkey);
                                    String e7departmentmark = Util.null2String(e7DeptMap.get("e7departmentmark"));
                                    String e7departmentname = Util.null2String(e7DeptMap.get("e7departmentname"));
                                    String e7subcompanyid1 = Util.null2String(e7DeptMap.get("e7subcompanyid1"));
                                    String e7supdepid = Util.null2String(e7DeptMap.get("e7supdepid"));
                                    String e7allsupdepid = Util.null2String(e7DeptMap.get("e7allsupdepid"));
                                    String e7canceled = Util.null2String(e7DeptMap.get("e7canceled"));
                                    String e7departmentcode = Util.null2String(e7DeptMap.get("e7departmentcode"));
                                    String e7tlevel = Util.null2String(e7DeptMap.get("e7tlevel"));
                                    String e7showorder = Util.null2String(e7DeptMap.get("e7showorder"));

                                    if(!e7departmentmark.equals(departmentmark)
                                            || !e7departmentname.equals(departmentname)
                                            || !e7subcompanyid1.equals(subcompanyOutKey)
                                            || !e7supdepid.equals(supdepidOutKey)
                                            || !e7canceled.equals(canceled)
                                            || !e7departmentcode.equals(departmentcode)
                                            || !e7allsupdepid.equals(allsupdepidOutKey)
                                    ){
                                        E9Map.put("subcompanyid1", subcompanyOutKey);
                                        E9Map.put("supdepid", supdepidOutKey);
                                        E9Map.put("e7id", outkey);
                                        updateList.add(E9Map);
                                    }else{
                                        unchanged_count++;
                                    }
                                }else{
                                    dataErrorList.add(e9Id);
                                    data_error_count++;
                                }
                            }else{
                                dataErrorList.add(e9Id);
                                data_error_count++;
                            }
                        }else{
                            dataErrorList.add(e9Id);
                            data_error_count++;
                        }
                    }else{

                        if(StringUtils.isNotBlank(subcompanyOutKey) && E7SubcompanyList.contains(subcompanyOutKey) ) {
                            if (StringUtils.isNotBlank(supdepidOutKey) && E7DepartmentMap.containsKey(supdepidOutKey)) {
                                E9Map.put("subcompanyid1", subcompanyOutKey);
                                E9Map.put("supdepid", supdepidOutKey);
                                insertList.add(E9Map);
                            }else{
                                dataErrorList.add(e9Id);
                                data_error_count++;
                            }
                        }else{
                            dataErrorList.add(e9Id);
                            data_error_count++;
                        }
                    }
                }
            }
        }

        bb.writeLog("insertList:"+insertList.size()+"</br>");
        bb.writeLog("updateList:"+updateList.size()+"</br>");

        for(Map<String,Object> E9Map : insertList){
            String e9id = Util.null2String(E9Map.get("e9id"));
            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            E9Map.put("modifier",modifier);
            E9Map.put("creater",creater);
            E9Map.put("UUID",uuid);

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }
            }

            sql = " insert into hrmsubcompany(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                String newE7Id = "";
                sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                rsd.executeSql(sql);
                if(rs.next()){
                    newE7Id = Util.null2String(rs.getString("id"));
                }

                if(StringUtils.isNotBlank(newE7Id)){
                    sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                    boolean isTrue2 = rs.executeUpdate(sql);
                    if(isTrue2){
                        insert_success_count++;
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_exp_count++;
                }
            }else{
                insert_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);

        }


        for(Map<String,Object> E9Map : updateList){
            String e7id = Util.null2String(E9Map.get("e7id"));
            String e9id = Util.null2String(E9Map.get("e9id"));

            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = E9Map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
                }
            }
            sql = "update hrmsubcompany set "+valuesStr+" where id = '"+e7id+"' ";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                update_success_count++;
            }else{
                update_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);
        }

        String bmtbjg ="部门共:"+totle_count+"行数据,数据一致工:"+unchanged_count+"。新增成功:"+insert_success_count+",新增失败:"+insert_fail_count+",新增异常:"+insert_exp_count+"。"+
                        "更新成功:"+update_success_count+",更新失败:"+update_fail_count+",更新异常:"+update_exp_count+"。"+
                        "数据异常(ID在E7中不存在):"+data_error_count ;
        recordSynMainlog(mainid,"",bmtbjg,"","","","");

    }
%>


<%!
    public void synHrmJobGroupData(int modifier,int creater,String dataResource,String mainid){
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);

        int totle_count = 0;
        int update_success_count = 0;
        int update_fail_count = 0;
        int update_exp_count = 0;

        int insert_success_count = 0;
        int insert_fail_count = 0;
        int insert_exp_count = 0;


        int unchanged_count = 0;
        int data_error_count = 0;

        List<String> dataErrorList = new ArrayList<String>();
        List<Map<String,String>> sqlList = new ArrayList<Map<String,String>>();


        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        Map<String,Map<String,String>> E7GroupMap = getE7HrmGroupList2(dataResource);
        List<Map<String,Object>> insertGroupList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> updateGroupList = new ArrayList<Map<String,Object>>();
        String sql = " select id,jobgroupname,jobgroupremark,outkey from hrmjobgroups ";
        rs.execute(sql);
        while(rs.next()){
            String e9Id = Util.null2String(rs.getString("id"));
            String jobgroupname = Util.null2String(rs.getString("jobgroupname"));
            String jobgroupremark = Util.null2String(rs.getString("jobgroupremark"));
            String outkey = Util.null2String(rs.getString("outkey"));

            Map<String,Object> groupMap = new HashMap<String,Object>();
            groupMap.put("e9Id",e9Id);
            groupMap.put("jobgroupname",jobgroupname);
            groupMap.put("jobgroupremark",jobgroupremark);

            if(StringUtils.isNotBlank(outkey)){
                if(E7GroupMap.containsKey(outkey)){

                    Map<String,String> e7Map = E7GroupMap.get(outkey);
                    String e7jobgroupname = e7Map.get("e7jobgroupname");
                    String e7jobgroupremark = e7Map.get("e7jobgroupremark");
                    if(!e7jobgroupname.equals(jobgroupname) || !e7jobgroupremark.equals(jobgroupremark)){
                        groupMap.put("e7id",outkey);
                        updateGroupList.add(groupMap);
                    }else{
                        unchanged_count++;
                    }
                }else{
                    data_error_count++;
                    dataErrorList.add(e9Id);
                }
            }else{
                insertGroupList.add(groupMap);
            }
        }
        bb.writeLog("updateGroupList:"+updateGroupList.size());
        bb.writeLog("insertGroupList:"+insertGroupList.size());

        for(Map<String,Object> item : insertGroupList)
        {
            String e9id = Util.null2String(item.get("e9id"));

            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            item.put("modifier",modifier);
            item.put("creater",creater);
            item.put("UUID",uuid);

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }
            }
            sql = " insert into hrmjobgroups(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";

            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                String newE7Id = "";
                sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                rsd.executeSql(sql);
                if(rs.next()){
                    newE7Id = Util.null2String(rs.getString("id"));
                }

                if(StringUtils.isNotBlank(newE7Id)){
                    sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                    boolean isTrue2 = rs.executeUpdate(sql);
                    if(isTrue2){
                        insert_success_count++;
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_exp_count++;
                }
            }else{
                insert_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);

        }

        for(Map<String,Object> item : updateGroupList) {
            String e7id = Util.null2String(item.get("e7id"));

            String e9id = Util.null2String(item.get("e9id"));

            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key + "='" + value + "'" : "," + key + "='" + value + "'";
                }
            }
            sql = "update hrmjobgroups set " + valuesStr + " where id = '" + e7id + "' ";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                update_success_count++;
            }else{
                update_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);
        }

        String zwlxtbjg ="职务类型共:"+totle_count+"行数据,数据一致工:"+unchanged_count+"。新增成功:"+insert_success_count+",新增失败:"+insert_fail_count+",新增异常:"+insert_exp_count+"。"+
                        "更新成功:"+update_success_count+",更新失败:"+update_fail_count+",更新异常:"+update_exp_count+"。"+
                        "数据异常(ID在E7中不存在):"+data_error_count ;

        recordSynMainlog(mainid,"","",zwlxtbjg,"","","");
    }

%>


<%!
    public void synHrmJobActivityData(int modifier,int creater,String dataResource,String mainid){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);

        int totle_count = 0;
        int update_success_count = 0;
        int update_fail_count = 0;
        int update_exp_count = 0;

        int insert_success_count = 0;
        int insert_fail_count = 0;
        int insert_exp_count = 0;


        int unchanged_count = 0;
        int data_error_count = 0;

        List<String> dataErrorList = new ArrayList<String>();
        List<Map<String,String>> sqlList = new ArrayList<Map<String,String>>();

        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        Map<String,Map<String,String>> E7ActivitiesMap  = getE7HrmActivitiesList2(dataResource) ;
        Map<String,String> E9GroupMap = getE9HrmGroupData();
        List<String> E7GroupMap = getE7HrmGroupData(dataResource);

        List<Map<String,Object>> insertJobActivityList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> updateJobActivityList = new ArrayList<Map<String,Object>>();
        String sql =" select * from hrmjobactivities where id in(select jobactivityid from hrmjobtitles) ";

        rs.execute(sql);
        while(rs.next()){
            totle_count++;

            String e9id = Util.null2String(rs.getString("id"));
            String jobactivitymark = Util.null2String(rs.getString("jobactivitymark"));
            String jobactivityname = Util.null2String(rs.getString("jobactivityname"));
            String jobgroupid = Util.null2String(rs.getString("jobgroupid"));
            String outkey = Util.null2String(rs.getString("outkey"));

            Map<String,Object> groupMap = new HashMap<String,Object>();
            groupMap.put("e9id",e9id);
            groupMap.put("jobactivitymark",jobactivitymark);
            groupMap.put("jobactivityname",jobactivityname);
            String E9GroupOutkey = "";
            if(StringUtils.isNotBlank(jobgroupid)){
                if(E9GroupMap.containsKey(jobgroupid)){
                    E9GroupOutkey = E9GroupMap.get(jobgroupid);
                }
            }
            if(StringUtils.isNotBlank(outkey)){
                if(E7GroupMap.contains(E9GroupOutkey)){
                    if(E7ActivitiesMap.containsKey(outkey)){
                        Map<String,String> activitiesMap = E7ActivitiesMap.get(outkey);

                        String e7jobactivitymark = Util.null2String(activitiesMap.get("e7jobactivitymark"));
                        String e7jobactivityname = Util.null2String(activitiesMap.get("e7jobactivityname"));
                        String e7jobgroupid = Util.null2String(activitiesMap.get("e7jobgroupid"));

                        if(!e7jobactivitymark.equals(jobactivitymark)
                                || !e7jobactivityname.equals(jobactivityname)
                                || !e7jobgroupid.equals(E9GroupOutkey)
                        ){
                            groupMap.put("jobgroupid",E9GroupOutkey);
                            groupMap.put("e7id",outkey);
                            updateJobActivityList.add(groupMap);
                        }else{
                            unchanged_count++;
                        }
                    }else{
                        data_error_count++;
                        dataErrorList.add(e9id);
                    }
                }else{
                    data_error_count++;
                    dataErrorList.add(e9id);
                }
            }else{
                if(E7GroupMap.contains(E9GroupOutkey)){
                    insertJobActivityList.add(groupMap);
                }else{
                    data_error_count++;
                    dataErrorList.add(e9id);
                }
            }
        }
        bb.writeLog("updateJobActivityList:"+updateJobActivityList.size());
        bb.writeLog("insertJobActivityList:"+insertJobActivityList.size());

        for(Map<String,Object> item : insertJobActivityList)
        {
            String e9id = Util.null2String(item.get("e9id"));
            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            item.put("modifier",modifier);
            item.put("creater",creater);
            item.put("UUID",uuid);

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }

            }
            sql = " insert into hrmjobactivities(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                String newE7Id = "";
                sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                rsd.executeSql(sql);
                if(rs.next()){
                    newE7Id = Util.null2String(rs.getString("id"));
                }

                if(StringUtils.isNotBlank(newE7Id)){
                    sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                    boolean isTrue2 = rs.executeUpdate(sql);
                    if(isTrue2){
                        insert_success_count++;
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_exp_count++;
                }
            }else{
                insert_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);
        }

        for(Map<String,Object> item : updateJobActivityList) {
            String e7id = Util.null2String(item.get("e7id"));
            String e9id = Util.null2String(item.get("e9id"));
            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key + "='" + value + "'" : "," + key + "='" + value + "'";
                }
            }
            sql = "update hrmjobactivities set " + valuesStr + " where id = '" + e7id + "' ";

            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                update_success_count++;
            }else{
                update_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);
        }

        String zztbjg = "职责共:"+totle_count+"行数据,数据一致工:"+unchanged_count+"。新增成功:"+insert_success_count+",新增失败:"+insert_fail_count+",新增异常:"+insert_exp_count+"。"+
                        "更新成功:"+update_success_count+",更新失败:"+update_fail_count+",更新异常:"+update_exp_count+"。"+
                        "数据异常(ID在E7中不存在):"+data_error_count ;
        recordSynMainlog(mainid,"","","",zztbjg,"","");
    }
%>

<%!

    public void synHrmJobTitleData(int modifier,int creater,String dataResource,String mainid){
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();


        int totle_count = 0;
        int update_success_count = 0;
        int update_fail_count = 0;
        int update_exp_count = 0;

        int insert_success_count = 0;
        int insert_fail_count = 0;
        int insert_exp_count = 0;


        int unchanged_count = 0;
        int data_error_count = 0;

        List<String> dataErrorList = new ArrayList<String>();
        List<Map<String,String>> sqlList = new ArrayList<Map<String,String>>();


        List<Map<String,Object>> insertTitleList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> updateTitleList = new ArrayList<Map<String,Object>>();

        Map<String,String> E9JobActivitiesMap = getE9HrmJobActivitiesList();
        Map<String,String> E9DepartmentMap = getE9DepartmentOutkey();
        List<String> E7HrmactivitiesList = getE7HrmActivitiesList(dataResource);

        bb.writeLog("=====E9JobActivitiesMap:"+E9JobActivitiesMap.size()+"</br>");
        bb.writeLog("=====E9DepartmentMap:"+E9DepartmentMap.size()+""+"</br>");
        bb.writeLog("=====E7HrmactivitiesList:"+E7HrmactivitiesList.size()+""+"</br>");

        Map<String,Map<String,String>> E7JobTitlesMap = getE7HrmTitlesList2(dataResource);
        bb.writeLog("=====E7JobTitlesMap:"+E7JobTitlesMap.size()+""+"</br>");
        String sql = " select id,jobtitlemark,jobtitlename,jobactivityid,jobdepartmentid,outkey,jobtitlecode from hrmjobtitles ";
        rs.execute(sql);
        while(rs.next()) {

            String e9id = Util.null2String(rs.getString("id"));
            String jobtitlename = Util.null2String(rs.getString("jobtitlename")).trim();
            String jobtitlemark = Util.null2String(rs.getString("jobtitlemark")).trim();
            String jobactivityid = Util.null2String(rs.getString("jobactivityid"));
            String jobdepartmentid = Util.null2String(rs.getString("jobdepartmentid"));
            String outkey = Util.null2String(rs.getString("outkey"));
            String jobtitlecode = Util.null2String(rs.getString("jobtitlecode"));

            Map<String,Object> titlesMap = new HashMap<String,Object>();
            titlesMap.put("jobtitlename", jobtitlename);
            titlesMap.put("jobtitlemark", jobtitlemark);
            titlesMap.put("jobtitlecode", jobtitlecode);

            String jobactivityOutkey = "";
            if(StringUtils.isNotBlank(jobactivityid)){
                if(E9JobActivitiesMap.containsKey(jobactivityid)){
                    jobactivityOutkey = E9JobActivitiesMap.get(jobactivityid);
                }
            }

            String departmentOutkey = "";
            if(StringUtils.isNotBlank(jobdepartmentid)){
                if(E9DepartmentMap.containsKey(jobdepartmentid)){
                    departmentOutkey = E9DepartmentMap.get(jobdepartmentid);
                }
            }

            if(StringUtils.isNotBlank(outkey)){
                if(E7JobTitlesMap.containsKey(outkey)){
                    if(StringUtils.isNotBlank(jobactivityOutkey) && E7HrmactivitiesList.contains(jobactivityOutkey)){
                        Map<String,String> jobTitlesMap = E7JobTitlesMap.get(outkey);
                        String e7jobtitlemark = Util.null2String(jobTitlesMap.get("e7jobtitlemark")).trim();
                        String e7jobtitlename = Util.null2String(jobTitlesMap.get("e7jobtitlename")).trim();
                        String e7jobactivityid = Util.null2String(jobTitlesMap.get("e7jobactivityid")).trim();
                        String e7jobdepartmentid = Util.null2String(jobTitlesMap.get("e7jobdepartmentid")).trim();
                        String e7jobtitlecode = Util.null2String(jobTitlesMap.get("e7jobtitlecode")).trim();

                        if(!e7jobtitlemark.equals(jobtitlemark)
                                || !e7jobtitlename.equals(jobtitlename)
                                || !e7jobactivityid.equals(jobactivityOutkey)
                                || !e7jobdepartmentid.equals(departmentOutkey)
                                || !e7jobtitlecode.equals(jobtitlecode)
                        ){
                            titlesMap.put("e7id", outkey);
                            titlesMap.put("jobdepartmentid", departmentOutkey);
                            titlesMap.put("jobactivityid", jobactivityOutkey);
                            updateTitleList.add(titlesMap);
                        }else{
                            unchanged_count++;
                        }
                    }else{
                        data_error_count++;
                        dataErrorList.add(e9id);
                    }
                }else{
                    data_error_count++;
                    dataErrorList.add(e9id);
                }
            }else{
                if(StringUtils.isNotBlank(jobactivityOutkey) && E7HrmactivitiesList.contains(jobactivityOutkey)){
                    titlesMap.put("jobdepartmentid", departmentOutkey);
                    titlesMap.put("jobactivityid", jobactivityOutkey);
                    insertTitleList.add(titlesMap);
                }else{
                    data_error_count++;
                    dataErrorList.add(e9id);

                }
            }
        }

        bb.writeLog("updateTitleList:"+updateTitleList.size());
        bb.writeLog("insertTitleList:"+insertTitleList.size());

        for(Map<String,Object> item : insertTitleList)
        {
            String e9id = Util.null2String(item.get("e9id"));
            String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();
            item.put("modifier",modifier);
            item.put("creater",creater);
            item.put("UUID",uuid);

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }

            }
            sql = " insert into hrmjobtitles(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                String newE7Id = "";
                sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                rsd.executeSql(sql);
                if(rs.next()){
                    newE7Id = Util.null2String(rs.getString("id"));
                }

                if(StringUtils.isNotBlank(newE7Id)){
                    sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                    boolean isTrue2 = rs.executeUpdate(sql);
                    if(isTrue2){
                        insert_success_count++;
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_exp_count++;
                }
            }else{
                insert_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);
        }

        for(Map<String,Object> item : updateTitleList) {
            String e7id = Util.null2String(item.get("e7id"));
            String e9id = Util.null2String(item.get("e9id"));
            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key + "='" + value + "'" : "," + key + "='" + value + "'";
                }
            }
            sql = "update hrmjobtitles set " + valuesStr + " where id = '" + e7id + "' ";

            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                update_success_count++;
            }else{
                update_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);

        }

        String gwtbjg = "岗位共:"+totle_count+"行数据,数据一致工:"+unchanged_count+"。新增成功:"+insert_success_count+",新增失败:"+insert_fail_count+",新增异常:"+insert_exp_count+"。"+
                        "更新成功:"+update_success_count+",更新失败:"+update_fail_count+",更新异常:"+update_exp_count+"。"+
                        "数据异常(ID在E7中不存在):"+data_error_count ;

        recordSynMainlog(mainid,"","","","",gwtbjg,"");
    }

%>


<%!
    /**
     *
     * @param dataResource
     */
    public void synHrmresourceData(int modifier,int creater,String dataResource,String mainid){


        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();

        int totle_count = 0;
        int update_success_count = 0;
        int update_fail_count = 0;
        int update_exp_count = 0;

        int insert_success_count = 0;
        int insert_fail_count = 0;
        int insert_exp_count = 0;

        int unchanged_count = 0;
        int data_error_count = 0;

        List<String> dataErrorList = new ArrayList<String>();
        List<Map<String,String>> sqlList = new ArrayList<Map<String,String>>();

        List<Map<String,Object>> insertResourceList = new ArrayList<Map<String,Object>>();
        List<Map<String,Object>> updateResourceList = new ArrayList<Map<String,Object>>();

        Map<String,String> E9ResourceMap = getE9ResourceOutkey();
        Map<String,String> E9DepartmentMap = getE9DepartmentOutkey();
        Map<String,String> E9SubcompanyMap = getE9SubcompanyOutkey();
        Map<String,String> E9JobtitleMap =  getE7HrmJobTitlesOutkey();

        bb.writeLog("E9ResourceMap:"+E9ResourceMap.size()+"</br>");
        bb.writeLog("E9DepartmentMap:"+E9DepartmentMap.size()+"</br>");
        bb.writeLog("E9SubcompanyMap:"+E9SubcompanyMap.size()+"</br>");
        bb.writeLog("E9JobtitleMap:"+E9JobtitleMap.size()+"</br>");

        List<String> E7DepartmentList = getE7HrmDepartmentList(dataResource);
        List<String> E7SubcompanyList = getE7HrmSubcompanyList(dataResource);
        List<String> E7JobTitleList = getE7HrmJobTitlesList(dataResource);

        Map<String,Map<String,String>> E7ResourceMap = getE7HrmResourceMap(dataResource);
        bb.writeLog("E7ResourceMap:"+E7ResourceMap.size()+"</br>");
        bb.writeLog("E7DepartmentList:"+E7DepartmentList.size()+"</br>");
        bb.writeLog("E7SubcompanyList:"+E7SubcompanyList.size()+"</br>");
        bb.writeLog("E7JobTitleList:"+E7JobTitleList.size()+"</br>");

        String sql =" select id,workcode,status,dsporder,mobile,jobtitle,password,lastname,loginid,systemlanguage," +
                " sex,birthday,departmentid," +
                " subcompanyid1,seclevel,accounttype,belongto,managerid,outkey " +
                " from hrmresource where id < 200" +
                " connect by prior id = managerid \n" +
                " start with managerid is null";

        bb.writeLog("E9--sql:"+sql+"</br>");
        rs.executeQuery(sql);
        while(rs.next()) {
            totle_count++;
            String e9id = Util.null2String(rs.getString("id"));
            String workcode = Util.null2String(rs.getString("workcode")).trim();
            String status = Util.null2String(rs.getString("status")).trim();
            String dsporder = Util.null2String(rs.getString("dsporder")).trim();
            String mobile = Util.null2String(rs.getString("mobile")).trim();
            String jobtitle = Util.null2String(rs.getString("jobtitle")).trim();
            String password = Util.null2String(rs.getString("password")).trim();
            String lastname = Util.null2String(rs.getString("lastname")).trim();
            String loginid = Util.null2String(rs.getString("loginid")).trim();
            String systemlanguage = Util.null2String(rs.getString("systemlanguage")).trim();
            String sex = Util.null2String(rs.getString("sex")).trim();
            String birthday = Util.null2String(rs.getString("birthday")).trim();
            String lastmoddate = Util.null2String(rs.getString("lastmoddate")).trim();
            String createdate = Util.null2String(rs.getString("createdate")).trim();
            String jobactivitydesc = Util.null2String(rs.getString("jobactivitydesc")).trim();
            String departmentid = Util.null2String(rs.getString("departmentid")).trim();
            String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1")).trim();
            String seclevel = Util.null2String(rs.getString("seclevel")).trim();
            String accounttype = Util.null2String(rs.getString("accounttype")).trim();
            String belongto = Util.null2String(rs.getString("belongto")).trim();
            String managerid = Util.null2String(rs.getString("managerid")).trim();
            String outkey = Util.null2String(rs.getString("outkey")).trim();

            if(StringUtils.isBlank(systemlanguage)){
                systemlanguage = "7";
            }
            if("-1".equals(accounttype) || StringUtils.isBlank(accounttype)){
                accounttype = "0";
            }
            if("-1".equals(belongto) || "0".equals(belongto)){
                belongto = "";
            }
            if("0".equals(managerid)){
                managerid = "";
            }

            Map<String,Object> ResourceMap = new HashMap<String,Object>();
            ResourceMap.put("e9id", e9id);
            ResourceMap.put("workcode", workcode);
            ResourceMap.put("status", status);
            ResourceMap.put("dsporder", dsporder);
            ResourceMap.put("mobile", mobile);
            ResourceMap.put("password", password);
            ResourceMap.put("lastname", lastname);
            ResourceMap.put("loginid", loginid);
            ResourceMap.put("systemlanguage", systemlanguage);
            ResourceMap.put("sex", sex);
            ResourceMap.put("birthday", birthday);
            ResourceMap.put("lastmoddate", lastmoddate);
            ResourceMap.put("createdate", createdate);
            ResourceMap.put("jobactivitydesc", jobactivitydesc);
            ResourceMap.put("seclevel", seclevel);
            ResourceMap.put("accounttype", accounttype);

            String managerOutkey = "";
            if(StringUtils.isNotBlank(managerid)){
                if(E9ResourceMap.containsKey(managerid)){
                    managerOutkey = E9ResourceMap.get(managerid);
                }
            }

            String belongtoOutkey = "";
            if(StringUtils.isNotBlank(belongto)){
                if(E9ResourceMap.containsKey(belongto)){
                    belongtoOutkey = E9ResourceMap.get(belongto);
                }
            }

            String departmentOutkey = "";
            if(StringUtils.isNotBlank(departmentid+"")){
                if(E9DepartmentMap.containsKey(departmentid)){
                    departmentOutkey = E9DepartmentMap.get(departmentid);
                }
            }

            String subcompanyOutkey = "";
            if(StringUtils.isNotBlank(subcompanyid1)){
                if(E9SubcompanyMap.containsKey(subcompanyid1)){
                    subcompanyOutkey = E9SubcompanyMap.get(subcompanyid1);
                }
            }

            String jobtitleOutkey = "";
            if(StringUtils.isNotBlank(jobtitle)){
                if(E9JobtitleMap.containsKey(jobtitle)){
                    jobtitleOutkey = E9JobtitleMap.get(jobtitle);
                }
            }

            if(StringUtils.isNotBlank(outkey)){
                if(E7ResourceMap.containsKey(outkey)){
                    if(StringUtils.isNotBlank(departmentOutkey) && E7DepartmentList.contains(departmentOutkey)){
                        if(StringUtils.isNotBlank(subcompanyOutkey) && E7SubcompanyList.contains(subcompanyOutkey)){
                            if(StringUtils.isNotBlank(jobtitleOutkey) && E7JobTitleList.contains(jobtitleOutkey)){

                                Map<String,String> resourceMap = E7ResourceMap.get(outkey);

                                String e7lastname = Util.null2String(resourceMap.get("e7lastname"));
                                String e7loginid = Util.null2String(resourceMap.get("e7loginid"));
                                String e7password = Util.null2String(resourceMap.get("e7password"));
                                String e7sex = Util.null2String(resourceMap.get("e7sex"));
                                String e7birthday = Util.null2String(resourceMap.get("e7birthday"));
                                String e7mobile = Util.null2String(resourceMap.get("e7mobile"));
                                String e7jobtitle = Util.null2String(resourceMap.get("e7jobtitle"));
                                String e7departmentid = Util.null2String(resourceMap.get("e7departmentid"));
                                String e7subcompanyid1 = Util.null2String(resourceMap.get("e7subcompanyid1"));
                                String e7seclevel = Util.null2String(resourceMap.get("e7seclevel"));
                                String e7workcode = Util.null2String(resourceMap.get("e7workcode"));
                                String e7status = Util.null2String(resourceMap.get("e7status"));
                                String e7dsporder = Util.null2String(resourceMap.get("e7dsporder"));
                                String e7systemlanguage = Util.null2String(resourceMap.get("e7systemlanguage"));
                                String e7accounttype = Util.null2String(resourceMap.get("e7accounttype"));
                                String e7belongto = Util.null2String(resourceMap.get("e7belongto"));
                                String e7managerid = Util.null2String(resourceMap.get("e7managerid"));

                                if(!e7lastname.equals(lastname)
                                        || !e7loginid.equals(loginid)
                                        || !e7password.equals(password)
                                        || !e7sex.equals(sex)
                                        || !e7birthday.equals(birthday)
                                        || !e7mobile.equals(mobile)
                                        || !e7jobtitle.equals(jobtitleOutkey)
                                        || !e7departmentid.equals(departmentOutkey)
                                        || !e7subcompanyid1.equals(subcompanyOutkey)
                                        || !e7seclevel.equals(seclevel)
                                        || !e7workcode.equals(workcode)
                                        || !e7status.equals(status)
                                        || !e7dsporder.equals(dsporder)
                                        || !e7systemlanguage.equals(systemlanguage)
                                        || !e7accounttype.equals(accounttype)
                                        || !e7belongto.equals(belongtoOutkey)
                                        || !e7managerid.equals(managerOutkey)
                                ){
                                    ResourceMap.put("e7id", outkey);
                                    ResourceMap.put("jobtitle", jobtitleOutkey);
                                    ResourceMap.put("belongto", belongtoOutkey);
                                    ResourceMap.put("managerid", managerOutkey);
                                    ResourceMap.put("departmentid", departmentOutkey);
                                    ResourceMap.put("subcompanyid1", subcompanyOutkey);
                                    updateResourceList.add(ResourceMap);
                                }else{
                                    unchanged_count++;
                                }
                            }else{
                                data_error_count++;
                                dataErrorList.add(e9id);
                            }
                        }else{
                            data_error_count++;
                            dataErrorList.add(e9id);
                        }
                    }else{
                        data_error_count++;
                        dataErrorList.add(e9id);
                    }
                }else{
                    data_error_count++;
                    dataErrorList.add(e9id);
                }
            }else{
                if(StringUtils.isNotBlank(departmentOutkey) && E7DepartmentList.contains(departmentOutkey)){
                    if(StringUtils.isNotBlank(subcompanyOutkey) && E7SubcompanyList.contains(subcompanyOutkey)){
                        if(StringUtils.isNotBlank(jobtitleOutkey) && E7JobTitleList.contains(jobtitleOutkey)){
                            ResourceMap.put("jobtitle", jobtitleOutkey);
                            ResourceMap.put("belongto", belongtoOutkey);
                            ResourceMap.put("managerid", managerOutkey);
                            ResourceMap.put("departmentid", departmentOutkey);
                            ResourceMap.put("subcompanyid1", subcompanyOutkey);
                            insertResourceList.add(ResourceMap);
                        }else{
                            data_error_count++;
                            dataErrorList.add(e9id);
                        }
                    }else{
                        data_error_count++;
                        dataErrorList.add(e9id);
                    }
                }else{
                    data_error_count++;
                    dataErrorList.add(e9id);
                }
            }
        }

        bb.writeLog("insertResourceList:"+insertResourceList.size()+"</br>");
        bb.writeLog("updateResourceList:"+updateResourceList.size()+"</br>");

        for(int i=0;i<insertResourceList.size();i++) {

            Map<String, Object> item = insertResourceList.get(i);
            String e9id = Util.null2String(item.get("e9id"));
            String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();
            item.put("modifier", modifier);
            item.put("creater", creater);
            item.put("UUID", uuid);

            rsd.executeProc("HRMRESOURCEMAXID_GET", "");
            rsd.next();
            int id = rsd.getInt(1);
            item.put("id", id);

            String keyString = "";
            String valueString = "";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                String value = Util.null2String(entry.getValue());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    keyString += keyString == "" ? key : ","+key ;
                    valueString += valueString == "" ? "'"+value+"'" : ",'"+value+"' ";
                }
            }
            sql = " insert into hrmresource(modified,created,"+keyString+") values(systimestamp,systimestamp,"+valueString+")";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                String newE7Id = "";
                sql = " select id hrmdepartment from where uuid = '"+uuid+"' ";
                rsd.executeSql(sql);
                if(rs.next()){
                    newE7Id = Util.null2String(rs.getString("id"));
                }

                if(StringUtils.isNotBlank(newE7Id)){
                    sql = "update hrmdepartment set outkey="+newE7Id+" where id = "+e9id;
                    boolean isTrue2 = rs.executeUpdate(sql);
                    if(isTrue2){
                        insert_success_count++;
                    }else{
                        insert_exp_count++;
                    }
                }else{
                    insert_exp_count++;
                }
            }else{
                insert_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);

        }

        for(int i=0;i<updateResourceList.size();i++) {
            Map<String, Object> item = updateResourceList.get(i);
            String e7id = Util.null2String(item.get("e7id"));
            String e9id = Util.null2String(item.get("e9id"));
            String valuesStr = " modified=systimestamp,modifier=1";
            Iterator<Map.Entry<String, Object>> it = item.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
                }
            }

            sql = "update hrmresource set " + valuesStr + " where id = "+e7id+"";
            boolean isTrue = rsd.execute(sql);
            if(isTrue){
                update_success_count++;
            }else{
                update_fail_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",sql);
            sqlMap.put("fbid",e9id);
            sqlMap.put("zxjg",isTrue ? "true" : "false");
            sqlList.add(sqlMap);
        }
        String rytbjg ="共:"+totle_count+"行数据,数据一致工:"+unchanged_count+"。新增成功:"+insert_success_count+",新增失败:"+insert_fail_count+",新增异常:"+insert_exp_count+"。"+
                        "更新成功:"+update_success_count+",更新失败:"+update_fail_count+",更新异常:"+update_exp_count+"。"+
                        "数据异常(ID在E7中不存在):"+data_error_count ;

        recordSynMainlog(mainid,"","","","","",rytbjg);
    }


%>

<%!


    public Map<String,String> getE9SubcompanyOutkey(){

        RecordSet rs = new RecordSet();
        Map<String,String> outkeyMap = new HashMap<String,String>();
        String sql = " select id,outkey from hrmsubcompany " ;
        rs.executeQuery(sql);
        while (rs.next()){
            String id = Util.null2String(rs.getString("id"));
            String outkey = Util.null2String(rs.getString("outkey"));
            outkeyMap.put(id,outkey);
        }
        return outkeyMap;
    }


    public Map<String,String> getE9DepartmentOutkey(){

        RecordSet rs = new RecordSet();
        Map<String,String> outkeyMap = new HashMap<String,String>();
        String sql = " select id,outkey from hrmdepartment " ;
        rs.executeQuery(sql);
        while (rs.next()){
            String id = Util.null2String(rs.getString("id"));
            String outkey = Util.null2String(rs.getString("outkey"));
            outkeyMap.put(id,outkey);
        }
        return outkeyMap;
    }



    public Map<String,Map<String,String>> getE7DepartmentData(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7DepartmentMap = new HashMap<String,Map<String,String>>();
        String sql = " select id,departmentmark,departmentname,subcompanyid1,supdepid,allsupdepid,canceled,departmentcode,tlevel,showorder from hrmdepartment " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String e7departmentmark = Util.null2String(rsd.getString("departmentmark"));
            String e7departmentname = Util.null2String(rsd.getString("departmentname"));
            String e7subcompanyid1 = Util.null2String(rsd.getString("subcompanyid1"));
            String e7supdepid = Util.null2String(rsd.getString("supdepid"));
            String e7allsupdepid = Util.null2String(rsd.getString("allsupdepid"));
            String e7canceled = Util.null2String(rsd.getString("canceled"));
            String e7departmentcode = Util.null2String(rsd.getString("departmentcode"));
            String e7tlevel = Util.null2String(rsd.getString("departmentcode"));
            String e7showorder = Util.null2String(rsd.getString("departmentcode"));

            Map<String,String> deptMap= new HashMap<String,String>();
            deptMap.put("e7departmentmark",e7departmentmark);
            deptMap.put("e7departmentname",e7departmentname);
            deptMap.put("e7subcompanyid1",e7subcompanyid1);
            deptMap.put("e7supdepid",e7supdepid);
            deptMap.put("e7allsupdepid",e7allsupdepid);
            deptMap.put("e7canceled",e7canceled);
            deptMap.put("e7departmentcode",e7departmentcode);
            deptMap.put("e7tlevel",e7tlevel);
            deptMap.put("e7showorder",e7showorder);

            E7DepartmentMap.put(id,deptMap);
        }
        return E7DepartmentMap;
    }

    /***
     *
     * @return
     */
    public List<String> getE7HrmSubcompanyList(String dataResource){
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> E7SubcompanyList = new ArrayList<String>();
        String sql = " select id from hrmsubcompany " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            E7SubcompanyList.add(id);
        }
        return E7SubcompanyList;
    }

    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 subcompanydesc = Util.null2String(rsd.getString("subcompanydesc"));
            String supsubcomid = Util.null2String(rsd.getString("supsubcomid"));
            String canceled = Util.null2String(rsd.getString("canceled"));
            String subcompanycode = Util.null2String(rsd.getString("subcompanycode"));

            Map<String,String> subcompanyMap = new HashMap<>();
            subcompanyMap.put("id",id);
            subcompanyMap.put("subcompanyname",subcompanyname);
            subcompanyMap.put("subcompanydesc",subcompanydesc);
            subcompanyMap.put("supsubcomid",supsubcomid);
            subcompanyMap.put("canceled",canceled);
            subcompanyMap.put("subcompanycode",subcompanycode);
            E7SubcompanyMap.put(id,subcompanyMap);

        }
        return E7SubcompanyMap;
    }


    public Map<String,Map<String,String>> getE7HrmGroupList2(String dataResource){
        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7GroupMap = new HashMap<String,Map<String,String>>();
        String sql = " select id,jobgroupname,jobgroupremark from hrmjobgroups" ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String jobgroupname = Util.null2String(rsd.getString("jobgroupname"));
            String jobgroupremark = Util.null2String(rsd.getString("jobgroupremark"));

            Map<String,String> groupMap = new HashMap<String,String>();
            groupMap.put("e7jobgroupname",jobgroupname);
            groupMap.put("e7jobgroupremark",jobgroupremark);
            E7GroupMap.put(id,groupMap);
        }
        return E7GroupMap;
    }

    public List<String> getE7HrmGroupData(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> groupList = new ArrayList<String>();
        String sql = " select id from hrmjobgroups " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            groupList.add(id);
        }
        return groupList;
    }

    /***
     *
     * @return
     */
    public Map<String,String> getE9HrmGroupData(){

        RecordSet rsd = new RecordSet();
        Map<String,String> groupMap = new HashMap<String,String>();
        String sql = " select id,outkey from hrmjobgroups" ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String outkey = Util.null2String(rsd.getString("outkey"));
            groupMap.put(id,outkey);
        }
        return groupMap;
    }


    public Map<String,Map<String,String>> getE7HrmActivitiesList2(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7ActivitiesMap = new HashMap<String,Map<String,String>>();
        String sql =" select id,jobactivitymark,jobactivityname,jobgroupid \n" +
                " from hrmjobactivities \n" ;

        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String e7jobactivitymark = Util.null2String(rsd.getString("jobactivitymark"));
            String e7jobactivityname = Util.null2String(rsd.getString("jobactivityname"));
            String e7jobgroupid = Util.null2String(rsd.getString("jobgroupid"));

            Map<String,String> activitiesMap = new HashMap<String,String>();
            activitiesMap.put("e7jobactivitymark",e7jobactivitymark);
            activitiesMap.put("e7jobactivityname",e7jobactivityname);
            activitiesMap.put("e7jobgroupid",e7jobgroupid);
            E7ActivitiesMap.put(id,activitiesMap);
        }
        return E7ActivitiesMap;
    }


    /***
     *
     * @return
     */
    public List<String> getE7HrmActivitiesList(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> E7HrmactivitiesList = new ArrayList<String>();
        String sql = " select id from hrmjobactivities " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            E7HrmactivitiesList.add(id);
        }
        return E7HrmactivitiesList;
    }


    public List<String> getE7HrmTitlesList(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> E7JobtitlesList = new ArrayList<String>();
        String sql = " select id from hrmjobactivities " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            E7JobtitlesList.add(id);
        }
        return E7JobtitlesList;
    }


    public Map<String,String> getE9HrmJobActivitiesList(){

        RecordSet rs = new RecordSet();
        Map<String,String> E7JobtitlesMap = new HashMap<String,String>();
        String sql =" select id,outkey from hrmjobactivities where id in(select jobactivityid from hrmjobtitles) ";
        rs.execute(sql);
        while (rs.next()){
            String id = Util.null2String(rs.getString("id"));
            String outkey = Util.null2String(rs.getString("outkey"));
            E7JobtitlesMap.put(id,outkey);
        }
        return E7JobtitlesMap;
    }


    public Map<String,Map<String,String>> getE7HrmTitlesList2(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7JobtitlesMap = new HashMap<String,Map<String,String>>();
        String sql = " select id,jobtitlemark,jobtitlename,jobactivityid,jobdepartmentid,jobtitlecode from hrmjobtitles " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            String e7jobtitlemark = Util.null2String(rsd.getString("jobtitlemark"));
            String e7jobtitlename = Util.null2String(rsd.getString("jobtitlename"));
            String e7jobactivityid = Util.null2String(rsd.getString("jobactivityid"));
            String e7jobdepartmentid = Util.null2String(rsd.getString("jobdepartmentid"));
            String e7jobtitlecode = Util.null2String(rsd.getString("jobtitlecode"));

            Map<String,String> jobtitlesMap = new HashMap<String,String>();
            jobtitlesMap.put("e7jobtitlemark",e7jobtitlemark);
            jobtitlesMap.put("e7jobtitlename",e7jobtitlename);
            jobtitlesMap.put("e7jobactivityid",e7jobactivityid);
            jobtitlesMap.put("e7jobdepartmentid",e7jobdepartmentid);
            jobtitlesMap.put("e7jobtitlecode",e7jobtitlecode);
            E7JobtitlesMap.put(id,jobtitlesMap);
        }
        return E7JobtitlesMap;
    }


    public Map<String,String> getE9ResourceOutkey(){

        Map<String,String> E9ResourceMap = new HashMap<String,String>();
        RecordSet rs = new RecordSet();
        String sql =" select id,outkey from hrmresource ";
        rs.executeQuery(sql);
        while(rs.next()) {
            String id = Util.null2String(rs.getString("id"));
            String outkey = Util.null2String(rs.getString("outkey"));
            E9ResourceMap.put(id,outkey);
        }

        return E9ResourceMap;
    }





    public Map<String,String> getE7HrmJobTitlesOutkey(){

        RecordSet rs = new RecordSet();

        Map<String,String> E9JobtitleMap = new HashMap<String,String>();
        String sql = " select id,outkey from hrmjobtitles " ;
        rs.execute(sql);
        while (rs.next()){
            String id = Util.null2String(rs.getString("id"));
            String outkey = Util.null2String(rs.getString("outkey"));
            E9JobtitleMap.put(id,outkey);
        }
        return E9JobtitleMap;
    }


    public List<String> getE7HrmJobTitlesList(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> E7JobtitlesList = new ArrayList<String>();
        String sql = " select id from hrmjobtitles " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            E7JobtitlesList.add(id);
        }
        return E7JobtitlesList;
    }


    public List<String> getE7HrmDepartmentList(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> E7DepartmentList = new ArrayList<String>();
        String sql = " select id from hrmdepartment " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            E7DepartmentList.add(id);
        }
        return E7DepartmentList;
    }


    public List<String> getE7HrmResourceList(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        List<String> E7ResourceList = new ArrayList<String>();
        String sql = " select id from hrmresource " ;
        rsd.execute(sql);
        while (rsd.next()){
            String id = Util.null2String(rsd.getString("id"));
            E7ResourceList.add(id);
        }
        return E7ResourceList;
    }


    public Map<String,Map<String,String>> getE7HrmResourceMap(String dataResource){

        RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
        Map<String,Map<String,String>> E7ResourceMap = new HashMap<String,Map<String,String>>();
        String sql =" select id,workcode,status,dsporder,mobile,jobtitle,password,lastname,loginid,systemlanguage," +
                " sex,birthday,lastmoddate,createdate,jobactivitydesc,departmentid," +
                " subcompanyid1,seclevel,accounttype,belongto,managerid " +
                " from hrmresource " ;
        rsd.execute(sql);
        while (rsd.next()){
            String e7id = Util.null2String(rsd.getString("id")).trim();
            String e7lastname = Util.null2String(rsd.getString("lastname")).trim();
            String e7loginid = Util.null2String(rsd.getString("loginid")).trim();
            String e7password = Util.null2String(rsd.getString("password")).trim();
            String e7sex = Util.null2String(rsd.getString("sex")).trim();
            String e7birthday = Util.null2String(rsd.getString("birthday")).trim();
            String e7mobile = Util.null2String(rsd.getString("mobile")).trim();
            String e7jobtitle = Util.null2String(rsd.getString("jobtitle")).trim();
            String e7departmentid = Util.null2String(rsd.getString("departmentid")).trim();
            String e7subcompanyid1 = Util.null2String(rsd.getString("subcompanyid1")).trim();
            String e7seclevel = Util.null2String(rsd.getString("seclevel")).trim();
            String e7workcode = Util.null2String(rsd.getString("workcode")).trim();
            String e7status = Util.null2String(rsd.getString("status")).trim();
            String e7dsporder = Util.null2String(rsd.getString("dsporder")).trim();

            String e7systemlanguage = Util.null2String(rsd.getString("systemlanguage")).trim();
            if(StringUtils.isBlank(e7systemlanguage)){
                e7systemlanguage = "7";
            }
            String e7accounttype = Util.null2String(rsd.getString("accounttype")).trim();
            if("-1".equals(e7accounttype) || StringUtils.isBlank(e7accounttype)){
                e7accounttype = "0";
            }
            String e7belongto = Util.null2String(rsd.getString("belongto")).trim();
            if("-1".equals(e7belongto) || "0".equals(e7belongto)){
                e7belongto = "";
            }
            String e7managerid = Util.null2String(rsd.getString("managerid")).trim();
            if("0".equals(e7managerid)){
                e7managerid = "";
            }

            Map<String,String> resourceMap = new HashMap<String,String>();
            resourceMap.put("e7lastname",e7lastname);
            resourceMap.put("e7loginid",e7loginid);
            resourceMap.put("e7password",e7password);
            resourceMap.put("e7sex",e7sex);

            resourceMap.put("e7birthday",e7birthday);
            resourceMap.put("e7mobile",e7mobile);
            resourceMap.put("e7jobtitle",e7jobtitle);
            resourceMap.put("e7departmentid",e7departmentid);
            resourceMap.put("e7subcompanyid1",e7subcompanyid1);
            resourceMap.put("e7seclevel",e7seclevel);
            resourceMap.put("e7workcode",e7workcode);
            resourceMap.put("e7status",e7status);

            resourceMap.put("e7dsporder",e7dsporder);
            resourceMap.put("e7systemlanguage",e7systemlanguage);
            resourceMap.put("e7accounttype",e7accounttype);
            resourceMap.put("e7belongto",e7belongto);
            resourceMap.put("e7managerid",e7managerid);

            E7ResourceMap.put(e7id,resourceMap);
        }
        return E7ResourceMap;
    }


%>

<%!
    /***
     *
     * @param id
     * @param fbtbjg
     * @param bmtbjg
     * @param zwlxtbjg
     * @param zztbjg
     * @param gwtbjg
     * @param rytbjg
     * @return
     */
    public String recordSynMainlog(String id,String fbtbjg,String bmtbjg,String zwlxtbjg,String zztbjg,String gwtbjg,String rytbjg){
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        String dataid = "" ;
        String uf_table = "uf_zzjgtbrz";
        String modedatacreater = "1";
        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");//设置日期格式
        String modedatacreatedate = sdfDate.format(new Date());
        String modedatacreatetime = sdfTime.format(new Date());
        String modedatacreatertype = "0";

        String formmodeid = "" ;
        String sql =" select k.id from modeinfo k  \n" +
                    " inner join workflow_bill l on formid = l.id\n" +
                    " where l.tablename = '"+uf_table+"' " ;
        rs.execute(sql);
        if(rs.next()){
            formmodeid = Util.null2String(rs.getString("id"));
        }

        if(StringUtils.isBlank(id)){

            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);

            String uuid = UUID.randomUUID().toString();
            Map<String,String> mainMap = new HashMap<String,String>();
            mainMap.put("formmodeid",formmodeid);
            mainMap.put("modedatacreater",modedatacreater);
            mainMap.put("modedatacreatertype",modedatacreatertype);
            mainMap.put("modedatacreatedate",modedatacreatedate);
            mainMap.put("modedatacreatetime",modedatacreatetime);
            if(StringUtils.isNotBlank(fbtbjg)){
                mainMap.put("fbtbjg",fbtbjg);
            }

            if(StringUtils.isNotBlank(bmtbjg)){
                mainMap.put("bmtbjg",bmtbjg);
            }

            if(StringUtils.isNotBlank(zwlxtbjg)){
                mainMap.put("zwlxtbjg",zwlxtbjg);
            }

            if(StringUtils.isNotBlank(zztbjg)){
                mainMap.put("zztbjg",zztbjg);
            }

            if(StringUtils.isNotBlank(gwtbjg)){
                mainMap.put("gwtbjg",gwtbjg);
            }

            if(StringUtils.isNotBlank(gwtbjg)){
                mainMap.put("rytbjg",rytbjg);
            }

            String tablename = "" ;
            String tablenvalue = "" ;
            for (Map.Entry<String, String> entry : mainMap.entrySet())
            {
                String fieldname = Util.null2String(entry.getKey()).trim();
                String fieldvalue = Util.null2String(entry.getValue()).replace("'", "''").trim();
                tablename += tablename==""? fieldname :","+fieldname ;
                tablenvalue += tablenvalue=="" ? "'"+fieldvalue+"'" :",'"+fieldvalue+"'" ;
            }
            if(tablename !="" && tablenvalue !="")
            {
                sql = " insert into "+uf_table+"("+tablename+") values ("+ tablenvalue +")";
                boolean boo = rs.execute(sql);
                if(boo)
                {

                    sql = " select * from "+uf_table+" where uuid='"+uuid+"' " ;
                    bb.writeLog("sql:"+sql);
                    rs.execute(sql);
                    if(rs.next()){
                        dataid = Util.null2String(rs.getString("id"));
                    }
                    bb.writeLog("dataid:"+dataid);
                    if(!"".equals(dataid))
                    {
                        modeRightInfo.editModeDataShare(Integer.valueOf(modedatacreater), Integer.parseInt(formmodeid), Integer.parseInt(dataid));
                    }
                }
            }
        }else{
            dataid = id ;
            Map<String,String> mainMap = new HashMap<String,String>();
            if(StringUtils.isNotBlank(fbtbjg)){
                mainMap.put("fbtbjg",fbtbjg);
            }

            if(StringUtils.isNotBlank(bmtbjg)){
                mainMap.put("bmtbjg",bmtbjg);
            }

            if(StringUtils.isNotBlank(zwlxtbjg)){
                mainMap.put("zwlxtbjg",zwlxtbjg);
            }

            if(StringUtils.isNotBlank(zztbjg)){
                mainMap.put("zztbjg",zztbjg);
            }

            if(StringUtils.isNotBlank(gwtbjg)){
                mainMap.put("gwtbjg",gwtbjg);
            }

            if(StringUtils.isNotBlank(gwtbjg)){
                mainMap.put("rytbjg",rytbjg);
            }

            String valuesStr = "";
            Iterator<Map.Entry<String, String>> it = mainMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> entry = it.next();
                String key = Util.null2String(entry.getKey());
                if(!"e7id".equals(key) && !"e9id".equals(key)){
                    String value = Util.null2String(entry.getValue());
                    valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
                }
            }

            if(StringUtils.isNotBlank(valuesStr)){
                sql = "update hrmresource set " + valuesStr + " where id = "+id+"";
                boolean isTrue = rs.execute(sql);
            }
        }

        return dataid;
    }


    public void recordSynDetaillog(List<Map<String,String>> dt1List){

    }

%>




