Browse Source

:sparkles: 添加新特性
1.添加通过excel导入用户后端接口

yapeng.li 4 years ago
parent
commit
235982d8cf

+ 4 - 0
build.gradle

@@ -303,6 +303,10 @@ subprojects {
     	 //tomcat embed
     	 compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.36'
     	 compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-logging-juli', version: '8.5.2'
+
+         //easyExcel
+        compile group: 'com.alibaba', name: 'easyexcel', version: '2.1.6'
+
     }
     
     jar {  

+ 61 - 0
maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoListener.java

@@ -0,0 +1,61 @@
+package org.maxkey.persistence.service;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.fastjson.JSON;
+import org.maxkey.domain.UserInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author yapeng.li
+ */
+public class UserInfoListener extends AnalysisEventListener<UserInfo> {
+
+    private static final Logger LOGGER =
+            LoggerFactory.getLogger(UserInfoListener.class);
+
+    /**
+     * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
+     */
+    private static final int BATCH_COUNT = 20;
+    List<UserInfo> list = new ArrayList<UserInfo>();
+
+
+    private UserInfoService userInfoService;
+
+    public UserInfoListener(UserInfoService userInfoService) {
+        this.userInfoService = userInfoService;
+    }
+
+    @Override
+    public void invoke(UserInfo data, AnalysisContext context) {
+        LOGGER.info("解析到一条数据:{}", JSON.toJSONString(data));
+        list.add(data);
+        // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
+        if (list.size() >= BATCH_COUNT) {
+            saveData();
+            // 存储完成清理 list
+            list.clear();
+        }
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext context) {
+        // 这里也要保存数据,确保最后遗留的数据也存储到数据库
+        saveData();
+        LOGGER.info("所有数据解析完成!");
+    }
+
+    /**
+     * 加上存储数据库
+     */
+    private void saveData() {
+        LOGGER.info("{}条数据,开始存储数据库!", list.size());
+        userInfoService.batchInsert(list);
+        LOGGER.info("存储数据库成功!");
+    }
+}

+ 243 - 223
maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java

@@ -41,40 +41,41 @@ import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.List;
+
 
 /**
  * @author Crystal.Sea
- *
  */
 @Service
 public class UserInfoService extends JpaBaseService<UserInfo> {
-	final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class);
+    final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class);
 
-	final static  String UPDATE_GRIDLIST_SQL = "UPDATE MXK_USERINFO SET GRIDLIST = ? WHERE ID = ?";
-	@Autowired
-	private PasswordEncoder passwordEncoder;
+    final static String UPDATE_GRIDLIST_SQL = "UPDATE MXK_USERINFO SET GRIDLIST = ? WHERE ID = ?";
+    @Autowired
+    private PasswordEncoder passwordEncoder;
 
-	@Autowired
-	PasswordPolicyValidator passwordPolicyValidator;
+    @Autowired
+    PasswordPolicyValidator passwordPolicyValidator;
 
-	@Autowired
-	KafkaProvisioningService kafkaProvisioningService;
+    @Autowired
+    KafkaProvisioningService kafkaProvisioningService;
 
-	 @Autowired
-	 protected JdbcTemplate jdbcTemplate;
+    @Autowired
+    protected JdbcTemplate jdbcTemplate;
 
-	public UserInfoService() {
-		super(UserInfoMapper.class);
-	}
+    public UserInfoService() {
+        super(UserInfoMapper.class);
+    }
 
-	/* (non-Javadoc)
-	 * @see com.connsec.db.service.BaseService#getMapper()
-	 */
-	@Override
-	public UserInfoMapper getMapper() {
-		// TODO Auto-generated method stub
-		return (UserInfoMapper)super.getMapper();
-	}
+    /* (non-Javadoc)
+     * @see com.connsec.db.service.BaseService#getMapper()
+     */
+    @Override
+    public UserInfoMapper getMapper() {
+        // TODO Auto-generated method stub
+        return (UserInfoMapper) super.getMapper();
+    }
 
     public boolean insert(UserInfo userInfo) {
         userInfo = passwordEncoder(userInfo);
@@ -89,6 +90,22 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
         return false;
     }
 
+    public boolean batchInsert(List<UserInfo> userInfos) {
+        for (UserInfo userInfo : userInfos) {
+            userInfo.setId(userInfo.generateId());
+            passwordEncoder(userInfo);
+        }
+        if (super.batchInsert(userInfos)) {
+            kafkaProvisioningService.send(
+                    KafkaIdentityTopic.USERINFO_TOPIC,
+                    userInfos,
+                    KafkaIdentityAction.CREATE_ACTION);
+            return true;
+        }
+
+        return false;
+    }
+
     public boolean update(UserInfo userInfo) {
         userInfo = passwordEncoder(userInfo);
         if (super.update(userInfo)) {
@@ -103,138 +120,138 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
         return false;
     }
 
-    public ImportResultVO importing(MultipartFile file,Integer type){
+    public ImportResultVO importing(MultipartFile file, Integer type) {
 
-		// 校验当前文件格式是不是excel文件
+        // 校验当前文件格式是不是excel文件
 
-		// 解析excel文件中数据
+        // 解析excel文件中数据
 
-		// 判断当前类型 0忽略 1覆盖 2终止
-		// 返回导入结果
+        // 判断当前类型 0忽略 1覆盖 2终止
+        // 返回导入结果
 
-		return new ImportResultVO();
-	}
+        return new ImportResultVO();
+    }
 
-	public boolean delete(UserInfo userInfo) {
-		if( super.delete(userInfo)){
-		    kafkaProvisioningService.send(
-		            KafkaIdentityTopic.USERINFO_TOPIC,
-		            userInfo,
-		            KafkaIdentityAction.DELETE_ACTION);
-			 return true;
-		}
-		return false;
-	}
+    public boolean delete(UserInfo userInfo) {
+        if (super.delete(userInfo)) {
+            kafkaProvisioningService.send(
+                    KafkaIdentityTopic.USERINFO_TOPIC,
+                    userInfo,
+                    KafkaIdentityAction.DELETE_ACTION);
+            return true;
+        }
+        return false;
+    }
 
-	public boolean updateGridList(String gridList) {
-	    try {
-    	    if (gridList != null && !gridList.equals("")) {
+    public boolean updateGridList(String gridList) {
+        try {
+            if (gridList != null && !gridList.equals("")) {
                 int intGridList = Integer.parseInt(gridList);
                 jdbcTemplate.update(UPDATE_GRIDLIST_SQL, intGridList,
                         WebContext.getUserInfo().getId());
                 WebContext.getUserInfo().setGridList(intGridList);
             }
-	    }catch(Exception e) {
+        } catch (Exception e) {
             e.printStackTrace();
             return false;
         }
-	    return true;
-	}
-
-
-	public boolean updateProtectedApps(UserInfo userinfo) {
-		try {
-			if(WebContext.getUserInfo() != null) {
-				userinfo.setModifiedBy(WebContext.getUserInfo().getId());
-			}
-			userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
-			return getMapper().updateProtectedApps(userinfo) > 0;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return false;
-	}
-
-	public UserInfo loadByUsername(String username) {
-		return getMapper().loadByUsername(username);
-	}
-
-	public UserInfo loadByAppIdAndUsername(String appId,String username){
-		try {
-			UserInfo userinfo = new UserInfo();
-			userinfo.setUsername(username);
-			return getMapper().loadByAppIdAndUsername(userinfo) ;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-
-	public void logisticDeleteAllByCid(String cid){
-		try {
-			 getMapper().logisticDeleteAllByCid(cid);
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	public UserInfo passwordEncoder(UserInfo userInfo) {
-	    //密码不为空,则需要进行加密处理
-	    if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
-    	    String password = passwordEncoder.encode(userInfo.getPassword());
+        return true;
+    }
+
+
+    public boolean updateProtectedApps(UserInfo userinfo) {
+        try {
+            if (WebContext.getUserInfo() != null) {
+                userinfo.setModifiedBy(WebContext.getUserInfo().getId());
+            }
+            userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
+            return getMapper().updateProtectedApps(userinfo) > 0;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public UserInfo loadByUsername(String username) {
+        return getMapper().loadByUsername(username);
+    }
+
+    public UserInfo loadByAppIdAndUsername(String appId, String username) {
+        try {
+            UserInfo userinfo = new UserInfo();
+            userinfo.setUsername(username);
+            return getMapper().loadByAppIdAndUsername(userinfo);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    public void logisticDeleteAllByCid(String cid) {
+        try {
+            getMapper().logisticDeleteAllByCid(cid);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public UserInfo passwordEncoder(UserInfo userInfo) {
+        //密码不为空,则需要进行加密处理
+        if (userInfo.getPassword() != null && !userInfo.getPassword().equals("")) {
+            String password = passwordEncoder.encode(userInfo.getPassword());
             userInfo.setDecipherable(ReciprocalUtils.encode(PasswordReciprocal.getInstance().rawPassword(userInfo.getUsername(), userInfo.getPassword())));
-            _logger.debug("decipherable : "+userInfo.getDecipherable());
+            _logger.debug("decipherable : " + userInfo.getDecipherable());
             userInfo.setPassword(password);
             userInfo.setPasswordLastSetTime(DateUtils.getCurrentDateTimeAsString());
 
             userInfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
-	    }
+        }
         return userInfo;
-	}
-
-
-	public boolean changePassword(String oldPassword,
-            String newPassword,
-            String confirmPassword) {
-		try {
-		    WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, "");
-	        UserInfo userInfo = WebContext.getUserInfo();
-	        UserInfo changeUserInfo = new UserInfo();
-	        changeUserInfo.setUsername(userInfo.getUsername());
-	        changeUserInfo.setPassword(newPassword);
-	        changeUserInfo.setId(userInfo.getId());
-	        changeUserInfo.setDecipherable(userInfo.getDecipherable());
-
-	        if(newPassword.equals(confirmPassword)){
-	            if(oldPassword==null ||
-	                    passwordEncoder.matches(oldPassword, userInfo.getPassword())){
-	                if(changePassword(changeUserInfo) ){
-	                    userInfo.setPassword(changeUserInfo.getPassword());
+    }
+
+
+    public boolean changePassword(String oldPassword,
+                                  String newPassword,
+                                  String confirmPassword) {
+        try {
+            WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, "");
+            UserInfo userInfo = WebContext.getUserInfo();
+            UserInfo changeUserInfo = new UserInfo();
+            changeUserInfo.setUsername(userInfo.getUsername());
+            changeUserInfo.setPassword(newPassword);
+            changeUserInfo.setId(userInfo.getId());
+            changeUserInfo.setDecipherable(userInfo.getDecipherable());
+
+            if (newPassword.equals(confirmPassword)) {
+                if (oldPassword == null ||
+                        passwordEncoder.matches(oldPassword, userInfo.getPassword())) {
+                    if (changePassword(changeUserInfo)) {
+                        userInfo.setPassword(changeUserInfo.getPassword());
                         userInfo.setDecipherable(changeUserInfo.getDecipherable());
-	                    return true;
-	                }
-	                return false;
-	            }else {
-	                if(oldPassword!=null &&
-	                        passwordEncoder.matches(newPassword, userInfo.getPassword())) {
-	                    WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
-	                            WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH"));
-	                }else {
-	                    WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
-	                        WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH"));
-	                }
-	            }
-	        }else {
-	            WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
-	                    WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH"));
-	        }
-		 } catch (Exception e) {
-             e.printStackTrace();
-         }
-
-		return false;
-	}
+                        return true;
+                    }
+                    return false;
+                } else {
+                    if (oldPassword != null &&
+                            passwordEncoder.matches(newPassword, userInfo.getPassword())) {
+                        WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
+                                WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH"));
+                    } else {
+                        WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
+                                WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH"));
+                    }
+                }
+            } else {
+                WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
+                        WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH"));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return false;
+    }
 
     public boolean changePassword(UserInfo changeUserInfo) {
         try {
@@ -266,13 +283,13 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
         return false;
     }
 
-	public String randomPassword() {
-	    return passwordPolicyValidator.generateRandomPassword();
-	}
+    public String randomPassword() {
+        return passwordPolicyValidator.generateRandomPassword();
+    }
 
-	public void changePasswordProvisioning(UserInfo userInfo) {
-	    if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
-    	    ChangePassword changePassword=new ChangePassword();
+    public void changePasswordProvisioning(UserInfo userInfo) {
+        if (userInfo.getPassword() != null && !userInfo.getPassword().equals("")) {
+            ChangePassword changePassword = new ChangePassword();
             changePassword.setId(userInfo.getId());
             changePassword.setUid(userInfo.getId());
             changePassword.setUsername(userInfo.getUsername());
@@ -282,95 +299,98 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
                     KafkaIdentityTopic.PASSWORD_TOPIC,
                     changePassword,
                     KafkaIdentityAction.PASSWORD_ACTION);
-	    }
-	}
-
-	public boolean changeAppLoginPassword(UserInfo userinfo) {
-		try {
-			if(WebContext.getUserInfo() != null) {
-				userinfo.setModifiedBy(WebContext.getUserInfo().getId());
-			}
-			userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
-			return getMapper().changeAppLoginPassword(userinfo) > 0;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return false;
-	}
-
-
-	/**
-	 * 锁定用户:islock:1 用户解锁 2 用户锁定
-	 * @param userInfo
-	 */
-	public void locked(UserInfo userInfo) {
-		try {
-			if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
-				userInfo.setIsLocked(ConstantsStatus.STOP);
-				getMapper().locked(userInfo);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * 用户登录成功后,重置错误密码次数和解锁用户
-	 * @param userInfo
-	 */
-	public void unlock(UserInfo userInfo) {
-		try {
-			if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
-				userInfo.setIsLocked(ConstantsStatus.START);
-				userInfo.setBadPasswordCount(0);
-				getMapper().unlock(userInfo);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * 更新错误密码次数
-	 * @param userInfo
-	 */
-	public void updateBadPasswordCount(UserInfo userInfo) {
-		try {
-			if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
-				int updateBadPWDCount = userInfo.getBadPasswordCount() + 1;
-				userInfo.setBadPasswordCount(updateBadPWDCount);
-				getMapper().updateBadPWDCount(userInfo);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	public boolean changeSharedSecret(UserInfo userInfo){
-		return getMapper().changeSharedSecret(userInfo)>0;
-	}
-
-	public boolean changePasswordQuestion(UserInfo userInfo){
-		return getMapper().changePasswordQuestion(userInfo)>0;
-	}
-
-	public boolean changeAuthnType(UserInfo userInfo){
-		return getMapper().changeAuthnType(userInfo)>0;
-	}
-
-	public boolean changeEmail(UserInfo userInfo){
-		return getMapper().changeEmail(userInfo)>0;
-	}
-
-	public boolean changeMobile(UserInfo userInfo){
-		return getMapper().changeMobile(userInfo)>0;
-	}
+        }
+    }
+
+    public boolean changeAppLoginPassword(UserInfo userinfo) {
+        try {
+            if (WebContext.getUserInfo() != null) {
+                userinfo.setModifiedBy(WebContext.getUserInfo().getId());
+            }
+            userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
+            return getMapper().changeAppLoginPassword(userinfo) > 0;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+
+    /**
+     * 锁定用户:islock:1 用户解锁 2 用户锁定
+     *
+     * @param userInfo
+     */
+    public void locked(UserInfo userInfo) {
+        try {
+            if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
+                userInfo.setIsLocked(ConstantsStatus.STOP);
+                getMapper().locked(userInfo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 用户登录成功后,重置错误密码次数和解锁用户
+     *
+     * @param userInfo
+     */
+    public void unlock(UserInfo userInfo) {
+        try {
+            if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
+                userInfo.setIsLocked(ConstantsStatus.START);
+                userInfo.setBadPasswordCount(0);
+                getMapper().unlock(userInfo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 更新错误密码次数
+     *
+     * @param userInfo
+     */
+    public void updateBadPasswordCount(UserInfo userInfo) {
+        try {
+            if (userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
+                int updateBadPWDCount = userInfo.getBadPasswordCount() + 1;
+                userInfo.setBadPasswordCount(updateBadPWDCount);
+                getMapper().updateBadPWDCount(userInfo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public boolean changeSharedSecret(UserInfo userInfo) {
+        return getMapper().changeSharedSecret(userInfo) > 0;
+    }
+
+    public boolean changePasswordQuestion(UserInfo userInfo) {
+        return getMapper().changePasswordQuestion(userInfo) > 0;
+    }
+
+    public boolean changeAuthnType(UserInfo userInfo) {
+        return getMapper().changeAuthnType(userInfo) > 0;
+    }
+
+    public boolean changeEmail(UserInfo userInfo) {
+        return getMapper().changeEmail(userInfo) > 0;
+    }
+
+    public boolean changeMobile(UserInfo userInfo) {
+        return getMapper().changeMobile(userInfo) > 0;
+    }
 
     public UserInfo queryUserInfoByEmailMobile(String emailMobile) {
         return getMapper().queryUserInfoByEmailMobile(emailMobile);
     }
 
-    public int updateProfile(UserInfo userInfo){
+    public int updateProfile(UserInfo userInfo) {
 
         return getMapper().updateProfile(userInfo);
     }

+ 110 - 110
maxkey-web-manage/src/main/java/org/maxkey/web/contorller/UserInfoController.java

@@ -1,23 +1,24 @@
 /*
  * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *     http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 
 package org.maxkey.web.contorller;
 
 import java.beans.PropertyEditorSupport;
+import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
@@ -25,10 +26,12 @@ import java.util.Map;
 
 import javax.validation.Valid;
 
+import com.alibaba.excel.EasyExcel;
 import org.apache.mybatis.jpa.persistence.JpaPageResults;
 import org.maxkey.constants.ConstantsOperateMessage;
 import org.maxkey.crypto.ReciprocalUtils;
 import org.maxkey.domain.UserInfo;
+import org.maxkey.persistence.service.UserInfoListener;
 import org.maxkey.persistence.service.UserInfoService;
 import org.maxkey.util.JsonUtils;
 import org.maxkey.util.StringUtils;
@@ -51,6 +54,7 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.ModelAndView;
 
 
@@ -62,81 +66,100 @@ import org.springframework.web.servlet.ModelAndView;
 @RequestMapping(value = { "/userinfo" })
 public class UserInfoController {
 	final static Logger _logger = LoggerFactory.getLogger(UserInfoController.class);
-	
+
 	@Autowired
 	@Qualifier("userInfoService")
 	private UserInfoService userInfoService;
 
-	
-	/**
-	 * 查询用户列表
-	 * @param user
-	 * @return
-	 */
-	@RequestMapping(value={"/grid"})
-	@ResponseBody
-	public JpaPageResults<UserInfo> forwardUsersList(@ModelAttribute("userInfo") UserInfo userInfo){
-		return userInfoService.queryPageResults(userInfo);
-		
-	}
-	
-	@RequestMapping(value={"/forwardAdd"})
-	public ModelAndView forwardSelectUserType(){
-		ModelAndView modelAndView=new ModelAndView("/userinfo/userAdd");
-		//List<UserType> userTypeList=userTypeService.query(null);
-		//modelAndView.addObject("userTypeList", userTypeList);
-		return modelAndView;
-	}
-	
-	
-	
-	
-	@RequestMapping(value={"/list"})
-	public ModelAndView usersList(){
-		return new ModelAndView("/userinfo/usersList");
-	}
-	
-	@RequestMapping(value={"/select"})
-	public ModelAndView usersSelect(){
-		ModelAndView modelAndView= new ModelAndView("/userinfo/userinfoSelect");
-		return modelAndView;
-	}
-	
-	/**
-	 * 新增
-	 * @param userInfo
-	 * @param result
-	 * @return
-	 */
-	@RequestMapping(value="/add") 
-	public ModelAndView addUsers(@Valid  @ModelAttribute("userInfo")UserInfo userInfo,BindingResult result) {
-		_logger.debug(userInfo.toString());
-		if(result.hasErrors()){
-			// new Message(WebContext.getValidErrorText(),result);
-		}
-		
-		userInfo.setId(userInfo.generateId());
-		//userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true));
-		//userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false));
-		if( userInfoService.insert(userInfo)) {
-			  new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_SUCCESS),userInfo,MessageType.success,OperateType.add,MessageScope.DB);
-		}
-		
-		 new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_ERROR),MessageType.error);
-		return   WebContext.forward("forwardUpdate/"+userInfo.getId());
-	}
-	
-	@RequestMapping(value={"/forwardUpdate/{id}"})
-	public ModelAndView forwardUpdateUsers(@PathVariable("id")String id){
-		ModelAndView modelAndView=new ModelAndView("/userinfo/userUpdate");
-		UserInfo userInfo=userInfoService.get(id);
-		if(userInfo.getPicture()!=null){
-			WebContext.getSession().setAttribute(userInfo.getId(), userInfo.getPicture());
-		}
-		
-		modelAndView.addObject("model", userInfo);
-		return modelAndView;
-	}
+
+    /**
+     * 查询用户列表
+     *
+     * @param user
+     * @return
+     */
+    @RequestMapping(value = {"/grid"})
+    @ResponseBody
+    public JpaPageResults<UserInfo> forwardUsersList(@ModelAttribute("userInfo") UserInfo userInfo) {
+        return userInfoService.queryPageResults(userInfo);
+
+    }
+
+    @RequestMapping(value = {"/forwardAdd"})
+    public ModelAndView forwardSelectUserType() {
+        ModelAndView modelAndView = new ModelAndView("/userinfo/userAdd");
+        //List<UserType> userTypeList=userTypeService.query(null);
+        //modelAndView.addObject("userTypeList", userTypeList);
+        return modelAndView;
+    }
+
+
+    @RequestMapping(value = {"/list"})
+    public ModelAndView usersList() {
+        return new ModelAndView("/userinfo/usersList");
+    }
+
+    @RequestMapping(value = {"/select"})
+    public ModelAndView usersSelect() {
+        ModelAndView modelAndView = new ModelAndView("/userinfo/userinfoSelect");
+        return modelAndView;
+    }
+
+    /**
+     * 新增
+     *
+     * @param userInfo
+     * @param result
+     * @return
+     */
+    @RequestMapping(value = "/add")
+    public ModelAndView addUsers(@Valid @ModelAttribute("userInfo") UserInfo userInfo, BindingResult result) {
+        _logger.debug(userInfo.toString());
+        if (result.hasErrors()) {
+            // new Message(WebContext.getValidErrorText(),result);
+        }
+
+        userInfo.setId(userInfo.generateId());
+        //userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true));
+        //userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false));
+        if (userInfoService.insert(userInfo)) {
+            new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_SUCCESS), userInfo, MessageType.success, OperateType.add, MessageScope.DB);
+        }
+
+        new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_ERROR), MessageType.error);
+        return WebContext.forward("forwardUpdate/" + userInfo.getId());
+    }
+
+    /**
+     * 用户excel导入
+     *
+     * @param userInfo
+     * @param result
+     * @return
+     */
+    /**
+     *
+     * @param file excel文件
+     * @return
+     */
+    @RequestMapping(value = "/importing")
+    public Object importing(MultipartFile file) throws IOException {
+        EasyExcel.read(file.getInputStream(), UserInfo.class, new UserInfoListener(userInfoService)).sheet().doRead();
+        return "success";
+    }
+
+
+    @RequestMapping(value = {"/forwardUpdate/{id}"})
+    public ModelAndView forwardUpdateUsers(@PathVariable("id") String id) {
+        ModelAndView modelAndView = new ModelAndView("/userinfo/userUpdate");
+        UserInfo userInfo = userInfoService.get(id);
+        if (userInfo.getPicture() != null) {
+            WebContext.getSession().setAttribute(userInfo.getId(), userInfo.getPicture());
+        }
+
+        modelAndView.addObject("model", userInfo);
+        return modelAndView;
+    }
 
 	/**
 	 * 查询用户,根据id
@@ -144,7 +167,7 @@ public class UserInfoController {
 	 * @return
 	 */
 	@ResponseBody
-	@RequestMapping(value="/getUsers/{id}") 
+	@RequestMapping(value="/getUsers/{id}")
 	public UserInfo getUserInfo(@PathVariable("id")String id) {
 		_logger.debug(id);
 		UserInfo userInfo = userInfoService.get(id);
@@ -157,14 +180,14 @@ public class UserInfoController {
 		}
 		return userInfo;
 	}
-	
-	
+
+
     @ResponseBody
     @RequestMapping(value = "/randomPassword")
     public String randomPassword() {
         return userInfoService.randomPassword();
     }
-	   
+
 	/**
 	 * 修改用户
 	 * @param userInfo
@@ -192,31 +215,6 @@ public class UserInfoController {
         return WebContext.forward("forwardUpdate/" + userInfo.getId());
     }
 
-    /**
-     * 用户excel导入
-     *
-     * @param userInfo
-     * @param result
-     * @return
-     */
-    /**
-     *
-     * @param file excel文件
-     * @param type //重名处理方式 0忽略 1覆盖 2终止
-     * @return
-     */
-    @RequestMapping(value = "/importing")
-    public Object importing(@RequestParam(value = "file") MultipartFile file,@RequestParam Integer type ) {
-    	// 判断当前上传文件是否存在
-        if (file == null || file.getSize() <= 0) {
-            return new Message(WebContext.getI18nValue(ConstantsOperateMessage.IMPORT_ERROR), MessageType.error);
-        }
-        if (file.getSize() > 1048576 * 256) {
-            return new Message(WebContext.getI18nValue(ConstantsOperateMessage.IMPORT_ERROR), MessageType.error);
-        }
-        _logger.debug(file.getOriginalFilename(),type);
-        return userInfoService.importing(file,type);
-    }
 
 
     /**
@@ -301,10 +299,12 @@ public class UserInfoController {
                 }
             }
 
-		    
-		});
-		 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-	        dateFormat.setLenient(false);  
-	        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
-	}
+
+        });
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        dateFormat.setLenient(false);
+        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
+    }
+
+
 }