Procházet zdrojové kódy

大数据量下测试

anderx před 7 roky
rodič
revize
c24bd9fedb

+ 58 - 9
src/main/java/com/goafanti/admin/service/impl/AdminServiceImpl.java

@@ -20,6 +20,7 @@ import com.goafanti.common.dao.AdminLocationMapper;
 import com.goafanti.common.dao.AdminMapper;
 import com.goafanti.common.dao.UserRoleMapper;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.PasswordUtil;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
@@ -239,19 +240,67 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 
 	@Override
 	public int updateLockAdmin() {
-		List<Admin> list=adminMapper.selectAllAdmin();
+		int count=0;
+		List<Admin> list=adminMapper.selectAllAdmin();//获取所有用户
+		List<List<Admin>>aList=groupList(list);//拆分成多个
 		String lockIds = "";
-		for (Admin a : list) {
-			String pwd=a.getPassword();
-			a.setPassword("123456");
-			String pwd2=passwordUtil.getEncryptPwd(a);
-			if (pwd.equals(pwd2)) {
-				lockIds += a.getId() + ",";
+		for(List<Admin> al:aList){
+			for (Admin a : al) {
+				String pwd=a.getPassword();
+				a.setPassword("123456");
+				String pwd2=passwordUtil.getEncryptPwd(a);
+				if (pwd.equals(pwd2)) {
+					lockIds += a.getId() + ",";
+				}
+			}
+			if(lockIds.length()>0){
+				try {
+				lockIds = "'" + lockIds.substring(0,lockIds.length()-1).replace(",", "','") + "'";
+				count+= adminMapper.updateLockIds(lockIds);
+					Thread.sleep(1000);
+				} catch (InterruptedException e) {
+					LoggerUtils.error(getClass(), "未修改管理员锁定失败", e);
+				}
 			}
 		}
-		if(lockIds.length()>0)lockIds = "'" + lockIds.substring(0,lockIds.length()-1).replace(",", "','") + "'";
-		return adminMapper.updateLockIds(lockIds);
+		return count;
 	}
+	
+	  /*
+     * List分割
+     */
+    public  List<List<Admin>> groupList(List<Admin> list) {
+        List<List<Admin>> listGroup = new ArrayList<List<Admin>>();
+        int listSize = list.size();
+        //子集合的长度
+        int toIndex = 100;
+        for (int i = 0; i < list.size(); i += 100) {
+            if (i + 100 > listSize) {
+                toIndex = listSize - i;
+            }
+            List<Admin> newList = list.subList(i, i + toIndex);
+            listGroup.add(newList);
+        }
+        return listGroup;
+    }
+   /* public static void main(String[] args) {
+    	List<String> list=new ArrayList<>();
+		for (int i = 1; i < 888; i++) {
+			list.add(String.valueOf(i));
+		}
+		  List<List<String>> listGroup = new ArrayList<List<String>>();
+	        int listSize = list.size();
+	        //子集合的长度
+	        int toIndex = 100;
+	        for (int i = 0; i < list.size(); i += 100) {
+	            if (i + 100 > listSize) {
+	                toIndex = listSize - i;
+	            }
+	            List<String> newList = list.subList(i, i + toIndex);
+	            listGroup.add(newList);
+	        }
+	        System.out.println(listGroup);
+	}*/
 
 	
 

+ 1 - 1
src/main/resources/props/config_test.properties

@@ -1,7 +1,7 @@
 #Driver
 jdbc.driverClassName=com.mysql.jdbc.Driver
 #\u6570\u636e\u5e93\u94fe\u63a5\uff0c
-jdbc.url=jdbc:mysql://127.0.0.1:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+jdbc.url=jdbc:mysql://127.0.0.1:3306/aft20180522?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
 #\u5e10\u53f7
 jdbc.username=root
 #\u5bc6\u7801