qq_38342082
唯一的果果
2017-09-29 03:44

关于导入修改的问题,求大神解答

  • 效率
  • 数据库

修改导入是导入数据对数据库中的数据进行修改,因为用户的手机号和邮箱不能重复,我是先判断这个手机号或者邮箱在数据库中存不存在,然后再判断是不是这个用户本人的,然后这样循环,我做的性能很差。有什么好的改进措施么。代码如下:
private List checknewList(List userList) {

    List<LoginInfo> loginInfoNameList = userDAO.getUserLoginName();
    List<LoginInfo> loginInfoPhoneList = userDAO.getUserLoginPhone();
    List<LoginInfo> loginInfoEmailList = userDAO.getUserLoginEmail();
    List<String>    deptnoList = userDAO.getDpetnos();
    List<String>    rolesList = userDAO.getroles();

    List<ExcelErrInfo> errorlist = new ArrayList<ExcelErrInfo>();
    Map<String,LoginInfo> dbloginnamecheckmap = loginInfoNameList.stream().collect(  
            Collectors.toMap(LoginInfo::getLoginname, (p) -> p));
    Map<String,LoginInfo> dbloginphonecheckmap = loginInfoPhoneList.stream().collect(  
            Collectors.toMap(LoginInfo::getLoginphone, (p) -> p));      
    Map<String,LoginInfo> dbloginmailcheckmap = loginInfoEmailList.stream().collect(  
            Collectors.toMap(LoginInfo::getLoginemail, (p) -> p));


    Map<String,String> deptnomap = deptnoList.stream().collect(  
            Collectors.toMap((p) -> p, (p) -> p));

    Map<String,String> rolesmap = rolesList.stream().collect(  
            Collectors.toMap((p) -> p, (p) -> p));
    Map<String,Integer> loginphonecheckmap = new HashMap<String, Integer>();
    Map<String,Integer> loginmailcheckmap = new HashMap<String, Integer>();

    for (int i = 0, len = userList.size(); i < len; i++)
    {
        DBUser temp = userList.get(i);
        String msg = "";
        msg = checkOneuserInfo(temp);

        if(!temp.getLoginname().equals("")){
            if(dbloginnamecheckmap.containsKey(temp.getLoginname())) {
                                        if(!temp.getLoginphone().equals("")){
                    if(dbloginphonecheckmap.containsKey(temp.getLoginphone())) {

                        if(!temp.getLoginphone().equals(userDAO.getNewUserLoginPhone(temp.getLoginphone()))) {
                            msg=msg+"该登录手机号码已注册;";
                                    loginphonecheckmap.put(temp.getLoginphone(),i+2);
                                    }
                    }       
                }
                        if(!temp.getLoginemail().equals("")){
                    if(dbloginmailcheckmap.containsKey(temp.getLoginemail())) {
                        if(!temp.getLoginemail().equals(userDAO.getNewUserLoginEmail(temp.getLoginemail()))) {
                            msg=msg+"该登录手机邮箱已注册;";
                                    loginmailcheckmap.put(temp.getLoginemail(),i+2);
                                    }
                    }
                }
                        主要效率就在这里  后面的就不贴了,贴下userDAO的代码,很简单就是从数据库里取
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答