com.job5156.jsDateJoin.event.InputCompanyTO29.java Source code

Java tutorial

Introduction

Here is the source code for com.job5156.jsDateJoin.event.InputCompanyTO29.java

Source

package com.job5156.jsDateJoin.event;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.job5156.jsDateJoin.entity.ComBaseInfo;
import com.job5156.jsDateJoin.entity.ComUserInfo;
import com.job5156.jsDateJoin.entity.unit;
import com.job5156.server.EntityManager;
import com.job5156.server.LocalSessionManager;
import com.job5156.server.SessionManager;
import com.job5156.util.DateUtil;
import com.job5156.util.StringUtil;

public class InputCompanyTO29 {
    private static Logger log = Logger.getLogger(InputCompanyTO29.class);

    public static void main(String[] args) {
        //InputMap iMap = new InputMap();
        //String temp = iMap.getJob5156Code(InputMap.sexT, "1", true);
        System.out.println("----------   --------------");
        long begintime = System.currentTimeMillis();
        Session localsession = LocalSessionManager.currentSession();
        Session session29 = SessionManager.currentSession();
        runCompanyDate(localsession, session29);
        session29.close();
        localsession.close();
        long endtime = System.currentTimeMillis();
        System.out.println("----------   "
                + (endtime - begintime) / 1000 / 60 + " ");
        log.error("   " + (endtime - begintime) / 1000 / 60 + " ");

    }

    public static void runCompanyDate(Session localsession, Session session29) {
        String hqlCount = "SELECT COUNT(u.id) FROM unit u order by u.id";
        String hql = "SELECT u FROM unit u order by u.id";

        int allRecord = EntityManager.getAllEntityNumberByHql(hqlCount, localsession);
        int dataLoadNumber = 2000;
        int allPage = allRecord > 0 ? 1 : 0;
        if (allRecord > dataLoadNumber) {
            allPage = allRecord / dataLoadNumber + ((allRecord % dataLoadNumber == 0) ? 0 : 1);
        }

        for (int m = 5; m < allPage; m++) {
            System.out.println(" " + m + "");
            //List listCBI = new ArrayList();// ComBaseInfo  List
            int k = 0;
            List list = EntityManager.getEntityByHqlAndStartRecords(hql, localsession, m * dataLoadNumber,
                    dataLoadNumber);
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    //
                    unit u = (unit) list.get(i);
                    String name = StringUtil.getNotNullStr(u.getName());
                    boolean flag = isTrue(name, 1, session29);

                    if (flag) {
                        try {
                            // ComBaseInfo 
                            System.out.println(" " + i + "");
                            ComBaseInfo cbi = getCBI(u);
                            EntityManager.saveEntity(cbi, session29);
                            int comID = StringUtil.parseInt(cbi.getId());

                            // ComUserInfo 
                            ComUserInfo cui = getCUI(u, comID, session29);
                            EntityManager.saveEntity(cui, session29);
                            k++;
                            if (k > 100) {
                                session29.clear();
                                k = 0;
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            log.error(" " + m * dataLoadNumber + i + "");
                        }

                    }

                    try {
                        Thread.sleep(500);
                        System.out.println("");
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        System.out.println(" ");
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public static ComUserInfo getCUI(unit u, int comID, Session session29) {
        ComUserInfo c = new ComUserInfo();
        c.setComid(comID);
        c.setDeptid(0);
        boolean flag = isChince(StringUtil.getNotNullStr(u.getUname()));
        boolean flag1 = isTrueAccount(u, session29);
        if (flag && flag1) {
            c.setUsername(StringUtil.getNotNullStr(u.getUname()));

        } else {
            c.setUsername("job5156" + comID);

        }
        c.setPassword(StringUtil.getNotNullStr(u.getPwd()));
        System.out.println(c.getUsername() + "  " + c.getPassword());
        c.setIsadmin(true);
        c.setRegisterdate(StringUtil.getNotNullStr(u.getRegistertime()));
        c.setUpdatedate(DateUtil.getNowDateTime());
        c.setLastLogindate(StringUtil.getNotNullStr(u.getLastlogintime()));
        c.setLoginnum(0);
        c.setMenu(null);
        c.setSafeSet(0);
        c.setUsedNum(0);
        c.setIsCount(0);
        c.setCountPosNum(0);
        return c;
    }

    public static boolean isChince(String str) {
        boolean flag = true;
        if ("".equals(str)) {
            flag = false;
        }
        int count = 0;
        String regEx = "[\\u4e00-\\u9fa5]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        while (m.find()) {
            for (int i = 0; i <= m.groupCount(); i++) {
                count = count + 1;
                break;
            }
        }
        if (count > 0) {
            flag = false;
        }

        return flag;
    }

    public static ComBaseInfo getCBI(unit u) {

        ComBaseInfo c = new ComBaseInfo();
        InputMap imap = new InputMap();
        c.setComname(StringUtil.getNotNullStr(u.getName())); //
        c.setLicencenumber(u.getBusilicense()); //
        //
        int callingT = StringUtil
                .parseInt(imap.getJob5156Code(imap.CallingT, StringUtil.getNotNullStr(u.getUnitproperty()), true));
        c.setCalling(callingT); //                  
        c.setProperity(0); //
        c.setFounddate(""); //
        int regfund = StringUtil.parseInt(u.getRegfund()) * 1000;
        c.setRegisterfund(StringUtil.getNotNullStr(regfund));//
        c.setCurrency("RMB");

        int employNumber = StringUtil.parseInt(u.getEmployeea()) + StringUtil.parseInt(u.getEmployeeb())
                + StringUtil.parseInt(u.getEmployeec()) + StringUtil.parseInt(u.getEmployeed())
                + StringUtil.parseInt(u.getEmployeee()) + StringUtil.parseInt(u.getEmployeef())
                + StringUtil.parseInt(u.getEmployeeg()) + StringUtil.parseInt(u.getEmployeeg())
                + StringUtil.parseInt(u.getEmployeeh());

        c.setEmployeenumber(StringUtil.getNotNullStr(employNumber)); //
        c.setCompanyintroduction(StringUtil.getNotNullStr(u.getIntro())); //
        c.setProductintroduction("");
        c.setContactperson(StringUtil.getNotNullStr(u.getLinkman())); //
        c.setContactposition(StringUtil.getNotNullStr(u.getLinkmanpost())); //
        c.setContactdepartment("");//
        c.setContacttel(StringUtil.getNotNullStr(u.getPhone()));//
        c.setContact1(1);//
        c.setContact2(2);// 
        c.setTelshowflag(0);//  0  1
        c.setTelshowflag2(0);//  0  1
        c.setContactfax(StringUtil.getNotNullStr(u.getFax()));//
        c.setEmail(StringUtil.getNotNullStr(u.getEmail()));//
        c.setEmailshowflag(0);// email 0  1
        c.setAddressp(1600); //
        c.setAddress(StringUtil.getNotNullStr(u.getBusiaddress()));//
        c.setZipcode(StringUtil.getNotNullStr(u.getBusizipcode()));//
        c.setHomepage(StringUtil.getNotNullStr(u.getHttp()));//
        c.setMailcode(0);// 0   1  
        c.setRegisterdate(StringUtil.getNotNullStr(u.getRegistertime()));//
        c.setUpdatedate(DateUtil.getNowDateTime());//
        c.setComflag(10); //    10 
        c.setLasteditby("");
        c.setStatus(0);// //0, 1, 5, 6, 7, 8,
        c.setFilterperid(""); //ID  
        c.setRegip(""); //IP
        c.setAddressc(0); //
        c.setInterviewadd(StringUtil.getNotNullStr(u.getBusiaddress())); //
        c.setEmailmode(0);// 01    0
        c.setIshunt(0);//[01]    0
        c.setBusway("");//
        c.setEmailwilling(1);//1-0EmailWilling  1
        c.setMapBeginDate(null);//  
        c.setMapValidDay(0);//      
        c.setExtendFlag(null); //  Null
        c.setSalerName("");
        c.setSalerId(109);
        c.setSalerIssee(0);//..0 ..1
        c.setCanUseOrder(0);// 1   0
        c.setUnLaw(null);//       null
        c.setComIDFilterIP(0);// IP0

        return c;
    }

    public static boolean isTrue(String name, int temp, Session session29) {
        boolean flag = true;
        String hql = "";
        if (1 == temp) {
            hql = "SELECT COUNT(c.id) FROM ComBaseInfo c WHERE c.comname = '" + name + "'";

        } else if (2 == temp) {

        }
        int num = EntityManager.getAllEntityNumberByHql(hql, session29);
        if (num > 0) {
            flag = false;
        }
        return flag;
    }

    public static void saveDate(Session session29, List list) {
        Object[] obj = new Object[list.size()];

        for (int j = 0; j < list.size(); j++) {
            obj[j] = list.get(j);
        }

        EntityManager.batchSave(obj, session29);
        session29.flush();
        session29.clear();
        obj = null;
    }

    public static boolean isTrueAccount(unit u, Session session29) {
        boolean flag = true;
        String hql = "SELECT COUNT(c.id) FROM ComUserInfo c WHERE c.username = '" + u.getUname()
                + "' and c.password = '" + u.getPwd() + "'";
        int num = 0;
        num = EntityManager.getAllEntityNumberByHql(hql, session29);
        if (num > 0) {
            flag = false;
        }
        System.out.println(num);
        return flag;
    }

}