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

<%

    String dataResource = "E7TEST";
    RecordSetDataSource rsd = new RecordSetDataSource(dataResource);
    int modifier = 1;
    int creater = 1;

    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();
    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 =  getE9HrmJobTitlesOutkey();

    out.println("E9ResourceMap:"+E9ResourceMap.size()+"</br>");
    out.println("E9DepartmentMap:"+E9DepartmentMap.size()+"</br>");
    out.println("E9SubcompanyMap:"+E9SubcompanyMap.size()+"</br>");
    out.println("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);

    out.println("E7ResourceMap:"+E7ResourceMap.size()+"</br>");
    out.println("E7DepartmentList:"+E7DepartmentList.size()+"</br>");
    out.println("E7SubcompanyList:"+E7SubcompanyList.size()+"</br>");
    out.println("E7JobTitleList:"+E7JobTitleList.size()+"</br>");

    String sql =" select id,workcode,status,dsporder,mobile,jobtitle,password,lastname,loginid,systemlanguage," +
                " sex,birthday,lastmoddate,createdate,jobactivitydesc,departmentid," +
                " subcompanyid1,seclevel,accounttype,belongto,managerid,outkey,telephone,email,startdate,enddate " +
                " from hrmresource " +
                " 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 managerstr = Util.null2String(rs.getString("managerstr")).trim();
        //        String locationid = Util.null2String(rs.getString("locationid")).trim();

        String e9id = Util.null2String(rs.getString("id"));
        String loginid = Util.null2String(rs.getString("loginid")).trim();
        String password = Util.null2String(rs.getString("password")).trim();
        String lastname = Util.null2String(rs.getString("lastname")).trim();
        String sex = Util.null2String(rs.getString("sex")).trim();
        String birthday = Util.null2String(rs.getString("birthday")).trim();
        String systemlanguage = Util.null2String(rs.getString("systemlanguage")).trim();
        String telephone = Util.null2String(rs.getString("telephone")).trim();
        String mobile = Util.null2String(rs.getString("mobile")).trim();
        String email = Util.null2String(rs.getString("email")).trim();
        String jobtitle = Util.null2String(rs.getString("jobtitle")).trim();
        String seclevel = Util.null2String(rs.getString("seclevel")).trim();
        String departmentid = Util.null2String(rs.getString("departmentid")).trim();
        String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1")).trim();
        String managerid = Util.null2String(rs.getString("managerid")).trim();
        String dsporder = Util.null2String(rs.getString("dsporder")).trim();
        String workcode = Util.null2String(rs.getString("workcode")).trim();
        String status = Util.null2String(rs.getString("status")).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 accounttype = Util.null2String(rs.getString("accounttype")).trim();
        String belongto = Util.null2String(rs.getString("belongto")).trim();
        String outkey = Util.null2String(rs.getString("outkey")).trim();
        String startdate = Util.null2String(rs.getString("startdate")).trim();
        String enddate = Util.null2String(rs.getString("enddate")).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) || "-1".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);
        ResourceMap.put("email", email);
        ResourceMap.put("enddate", enddate);
        ResourceMap.put("telephone", telephone);
        ResourceMap.put("startdate", startdate);

        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"));
                            String e7email = Util.null2String(resourceMap.get("e7email"));
                            String e7jobactivitydesc = Util.null2String(resourceMap.get("e7jobactivitydesc"));
                            String e7startdate = Util.null2String(resourceMap.get("e7startdate"));
                            String e7enddate = Util.null2String(resourceMap.get("e7enddate"));
                            String e7telephone = Util.null2String(resourceMap.get("e7telephone")).trim();
                            String e7lastmoddate = Util.null2String(resourceMap.get("e7lastmoddate")).trim();
                            String e7createdate = Util.null2String(resourceMap.get("e7createdate")).trim();

                            out.println("lastname:"+lastname+" sex:"+sex+" birthday:"+birthday+" mobile:"+mobile+" jobtitle:"+jobtitleOutkey+" departmentid:"+departmentOutkey+" subcompanyid1:"+subcompanyOutkey+" seclevel:"+seclevel+" workcode:"+workcode+" status:"+status +" dsporder:"+dsporder+" systemlanguage:"+systemlanguage+" accounttype:"+accounttype+" belongto:"+belongtoOutkey+" managerid:"+managerOutkey+"</br>");
                            out.println("e7lastname:"+e7lastname+" e7sex:"+e7sex+" e7birthday:"+e7birthday+" e7mobile:"+e7mobile+" e7jobtitle:"+e7jobtitle+" e7departmentid:"+e7departmentid+" e7subcompanyid1:"+e7subcompanyid1+" e7seclevel:"+e7seclevel+" e7workcode:"+e7workcode+" e7status:"+e7status +" e7dsporder:"+e7dsporder+" e7systemlanguage:"+e7systemlanguage+" e7accounttype:"+e7accounttype+" e7belongto:"+e7belongto+" e7managerid:"+e7managerid+"</br>");


                            out.println("loginid:"+lastname+" password:"+password+" email:"+email+" jobactivitydesc:"+jobactivitydesc+" startdate:"+startdate+" enddate:"+enddate+"  telephone:"+telephone+" lastmoddate:"+lastmoddate+" createdate:"+createdate+"</br>");
                            out.println("e7loginid:"+e7lastname+" e7password:"+e7password+" e7email:"+e7email+" e7jobactivitydesc:"+e7jobactivitydesc+" e7startdate:"+e7startdate+" e7enddate:"+e7enddate+" e7telephone:"+e7telephone+" e7lastmoddate:"+e7lastmoddate+" e7createdate:"+e7createdate+"</br>");


                            if(!e7lastname.equals(lastname)
                                    || !e7loginid.equals(loginid)
                                    || !e7sex.equals(sex)
                                    || !e7password.equals(password)
                                    || !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)
                                    || !e7email.equals(email)
                                    || !e7jobactivitydesc.equals(jobactivitydesc)
                                    || !e7startdate.equals(startdate)
                                    || !e7enddate.equals(enddate)
                                    || !e7telephone.equals(telephone)
                                    || !e7lastmoddate.equals(lastmoddate)
                                    || !e7createdate.equals(createdate)
                            ){
                                out.println("更新--outkey:"+outkey+"</br>");
                                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{
                if(StringUtils.isNotBlank(departmentOutkey) && E7DepartmentList.contains(departmentOutkey)){
                    if(StringUtils.isNotBlank(subcompanyOutkey) && E7SubcompanyList.contains(subcompanyOutkey)){
                        if(StringUtils.isNotBlank(jobtitleOutkey) && E7JobTitleList.contains(jobtitleOutkey)){
                            out.println("新增</br>");
                            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);
                }
            }
        }else{
            if(StringUtils.isNotBlank(departmentOutkey) && E7DepartmentList.contains(departmentOutkey)){
                if(StringUtils.isNotBlank(subcompanyOutkey) && E7SubcompanyList.contains(subcompanyOutkey)){
                    if(StringUtils.isNotBlank(jobtitleOutkey) && E7JobTitleList.contains(jobtitleOutkey)){
                        out.println("新增</br>");
                        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);
            }
        }
    }

    out.println("insertResourceList:"+insertResourceList.size()+"</br>");
    out.println("updateResourceList:"+updateResourceList.size()+"</br>");

    for(int i=0;i<insertResourceList.size();i++) {
        int e7newid = getE7HrmResourceId(rsd);
        out.println("e7newid:"+e7newid+"</br>");
        if(e7newid > -1){
            Map<String, Object> item = insertResourceList.get(i);
            String e9id = Util.null2String(item.get("e9id"));
            String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();
            item.put("lastmodid", modifier);
            item.put("createrid", creater);
            item.put("textfield1", uuid);
            item.put("id", e7newid);

            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+"' ";
                }
            }

            boolean isTrue2 = false;
            String insert_sql = " insert into hrmresource("+keyString+") values("+valueString+")";
            boolean isTrue = insertE7HrmResourceData(rsd,insert_sql,uuid,insert_fail_count);
            out.println("insert_sql:"+insert_sql+"   isTrue:"+isTrue+"</br>");
            if(isTrue){
                String up_sql = " update hrmresource set outkey="+e7newid+" where id = "+e9id;
                isTrue2 = rs.executeUpdate(up_sql);
                out.println("up_sql:"+up_sql+"   isTrue2:"+isTrue2+"</br>");
                if(isTrue2){
                    insert_success_count++;
                }else{
                    insert_exp_count++;
                }
            }else{
                insert_exp_count++;
            }

            Map<String,String> sqlMap = new HashMap<String,String>();
            sqlMap.put("zxyj",insert_sql);
            sqlMap.put("dataid",e9id);
            sqlMap.put("zxjg",isTrue2 ? "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 = "";
        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+"'" ;
            }
        }

        String update_sql = "update hrmresource set " + valuesStr + " where id = "+e7id+"";
        boolean isTrue = updateE7HrmResourceData(rsd,update_sql);
        out.println("update_sql:"+update_sql+"   isTrue:"+isTrue+"</br>");
        if(isTrue){
            update_success_count++;
        }else{
            update_fail_count++;
        }

        Map<String,String> sqlMap = new HashMap<String,String>();
        sqlMap.put("zxyj",update_sql);
        sqlMap.put("dataid",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 ;

    Map<String,String> mainMap = new HashMap<String,String>();
    mainMap.put("rytbjg",rytbjg);
    if(dataErrorList.size() > 0){
        String ryycsj = String.join(",", dataErrorList);
        mainMap.put("ryycsj",ryycsj);
    }

    String mainid = recordSynMainlog("",mainMap);
    out.println("mainid:"+mainid);
    if(StringUtils.isNotBlank(mainid)){
        insertLogDetail6(mainid,sqlList);
    }

%>


<%!
    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,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> getE9HrmJobTitlesOutkey(){

        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> 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 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,telephone,email,enddate,startdate  " +
                    " from hrmresource " ;
        rsd.execute(sql);
        while (rsd.next()){
            String e7id = Util.null2String(rsd.getString("id")).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 e7mobile = Util.null2String(rsd.getString("mobile")).trim();
            String e7jobtitle = Util.null2String(rsd.getString("jobtitle")).trim();
            String e7password = Util.null2String(rsd.getString("password")).trim();
            String e7lastname = Util.null2String(rsd.getString("lastname")).trim();
            String e7loginid = Util.null2String(rsd.getString("loginid")).trim();
            String e7systemlanguage = Util.null2String(rsd.getString("systemlanguage")).trim();
            String e7sex = Util.null2String(rsd.getString("sex")).trim();
            String e7birthday = Util.null2String(rsd.getString("birthday")).trim();
            String e7lastmoddate = Util.null2String(rsd.getString("lastmoddate")).trim();
            String e7createdate = Util.null2String(rsd.getString("createdate")).trim();
            String e7jobactivitydesc = Util.null2String(rsd.getString("jobactivitydesc")).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 e7accounttype = Util.null2String(rsd.getString("accounttype")).trim();
            String e7belongto = Util.null2String(rsd.getString("belongto")).trim();
            String e7managerid = Util.null2String(rsd.getString("managerid")).trim();
            String e7telephone = Util.null2String(rsd.getString("telephone")).trim();
            String e7email = Util.null2String(rsd.getString("email")).trim();
            String e7startdate = Util.null2String(rsd.getString("startdate")).trim();
            String e7enddate = Util.null2String(rsd.getString("enddate")).trim();


            if(StringUtils.isBlank(e7systemlanguage)){
                e7systemlanguage = "7";
            }

            if("-1".equals(e7accounttype) || StringUtils.isBlank(e7accounttype)){
                e7accounttype = "0";
            }

            if("-1".equals(e7belongto) || "0".equals(e7belongto)){
                e7belongto = "";
            }

            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);
            resourceMap.put("e7telephone",e7telephone);
            resourceMap.put("e7email",e7email);
            resourceMap.put("e7lastmoddate",e7lastmoddate);
            resourceMap.put("e7createdate",e7createdate);
            resourceMap.put("e7jobactivitydesc",e7jobactivitydesc);
            resourceMap.put("e7startdate",e7startdate);
            resourceMap.put("e7enddate",e7enddate);

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



    public String recordSynMainlog(String id,Map<String,String> mainMap){
        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();
            mainMap.put("uuid",uuid);
            mainMap.put("formmodeid",formmodeid);
            mainMap.put("modedatacreater",modedatacreater);
            mainMap.put("modedatacreatertype",modedatacreatertype);
            mainMap.put("modedatacreatedate",modedatacreatedate);
            mainMap.put("modedatacreatetime",modedatacreatetime);

            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);
                bb.writeLog("insert-istrue:"+boo);
                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 ;
            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());
                String value = Util.null2String(entry.getValue());
                valuesStr += valuesStr == "" ? key+"='"+value+"'" : ","+key+"='"+value+"'" ;
            }
            if(StringUtils.isNotBlank(valuesStr)){
                sql = "update "+uf_table+" set " + valuesStr + " where id = "+id+"";
                boolean isTrue = rs.execute(sql);
                bb.writeLog("update-istrue:"+isTrue);
            }
        }
        return dataid;
    }


    /***
     *
     * @param dt1List
     * @param mainid
     */
    public void insertLogDetail2(String mainid,List<Map<String,String>> dt1List){
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        for(int i=0;i<dt1List.size();i++){
            Map<String,String> dt1Map = dt1List.get(i);
            String dataid = dt1Map.get("dataid");
            String zxyj = dt1Map.get("zxyj");
            if(StringUtils.isNotBlank(zxyj) && zxyj.contains("'")){
                zxyj = zxyj.replace("'", "''");
            }
            String zxjg = dt1Map.get("zxjg");

            String sql = " insert into uf_zzjgtbrz_dt2(mainid,bmid,zxyj,zxjg) values("+mainid+",'"+dataid+"','"+zxyj+"','"+zxjg+"')" ;
            bb.writeLog("sql:"+sql);
            boolean istrue = rs.executeUpdate(sql);
            bb.writeLog("istrue:"+istrue);
        }
    }


    public boolean insertE7HrmResourceData(RecordSetDataSource rsd,String insert_sql,String uuid,int insert_fail_count){
        boolean isTrue = rsd.execute(insert_sql);
        if(!isTrue){
            insert_fail_count++;
        }
        return isTrue;
    }


    public boolean updateE7HrmResourceData(RecordSetDataSource rsd,String update_sql){
        boolean isTrue = rsd.execute(update_sql);
        return isTrue;
    }


    public int getE7HrmResourceId(RecordSetDataSource rsd){
        int id = -1;
        BaseBean bb = new BaseBean();
        try{
            String sql = " update SequenceIndex set currentid = (select currentid  from SequenceIndex where indexdesc='resourceid'\n" +
                    " )+1 where indexdesc='resourceid' ";
            boolean isTrue = rsd.executeSql(sql);
            if(isTrue){
                sql = " select currentid  from SequenceIndex where indexdesc='resourceid' ";
                rsd.execute(sql);
                if(rsd.next()){
                    id = Util.getIntValue(Util.null2String(rsd.getString("currentid")));
                }
            }
        }catch (Exception e){
            bb.writeLog(e);
        }
        return id;
    }


    /***
     *
     * @param dt1List
     * @param mainid
     */
    private void insertLogDetail6(String mainid,List<Map<String,String>> dt1List){
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        for(int i=0;i<dt1List.size();i++){
            Map<String,String> dt1Map = dt1List.get(i);
            String dataid = dt1Map.get("dataid");
            String zxyj = dt1Map.get("zxyj");
            if(StringUtils.isNotBlank(zxyj) && zxyj.contains("'")){
                zxyj = zxyj.replace("'", "''");
            }
            String zxjg = dt1Map.get("zxjg");

            String sql = " insert into uf_zzjgtbrz_dt6(mainid,ryid,zxyj,zxjg) values("+mainid+",'"+dataid+"','"+zxyj+"','"+zxjg+"')" ;
            bb.writeLog("sql:"+sql);
            boolean istrue = rs.executeUpdate(sql);
            bb.writeLog("istrue:"+istrue);
        }
    }

%>



