1.添加用户导入controller

This commit is contained in:
yapeng.li 2020-09-21 21:36:38 +08:00
parent 6fd8255d87
commit 9b39775eb0
6 changed files with 383 additions and 150 deletions

View File

@ -28,4 +28,7 @@ public final class ConstantsOperateMessage {
public static final String DELETE_SUCCESS = "message.action.delete.success";
public static final String DELETE_ERROR = "message.action.delete.error";
public static final String import_success = "message.action.import.success";
public static final String IMPORT_ERROR = "message.action.import.error";
}

View File

@ -0,0 +1,64 @@
package org.maxkey.domain;
import org.apache.commons.lang.StringUtils;
/**
* @author yapeng.li
* @date 2019.3.6
*/
public class ImportResultBaseVO {
/**
* 资源名
*/
private String name;
/**
* 状态
*/
private String status;
/**
* 描述
*/
private String desc;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(Integer status) {
if(status==0){
this.status = "SUCCESS";
}else if(status==1){
this.status = "FAILURE";
}else{
this.status = "IGNORE";
}
}
public String getDesc() {
if(StringUtils.isEmpty(desc)){
return "";
}
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
@Override
public String toString() {
return "ImportResultBaseVO{" +
"name='" + name + '\'' +
", status='" + status + '\'' +
", desc='" + desc + '\'' +
'}';
}
}

View File

@ -0,0 +1,105 @@
package org.maxkey.domain;
import java.util.ArrayList;
import java.util.List;
/**
* @author yapeng.li
* @since 2020/9/21 21:12
*/
public class ImportResultVO {
/**
* 成功结果
*/
List<ImportResultBaseVO> success;
/**
* 失败结果
*/
List<ImportResultBaseVO> error;
/**
* 忽略结果
*/
List<ImportResultBaseVO> ignore;
/**
* 成功次数
*/
Integer successCount;
/**
* 失败次数
*/
Integer errorCount;
/**
* 忽略次数
*/
Integer ignoreCount;
public List<ImportResultBaseVO> getSuccess() {
if(success==null){
success = new ArrayList<>();
}
return success;
}
public void setSuccess(List<ImportResultBaseVO> success) {
this.success = success;
}
public List<ImportResultBaseVO> getError() {
if(error==null){
error = new ArrayList<>();
}
return error;
}
public void setError(List<ImportResultBaseVO> error) {
this.error = error;
}
public List<ImportResultBaseVO> getIgnore() {
if(ignore==null){
ignore = new ArrayList<>();
}
return ignore;
}
public void setIgnore(List<ImportResultBaseVO> ignore) {
this.ignore = ignore;
}
public Integer getSuccessCount() {
return successCount;
}
public void setSuccessCount(Integer successCount) {
this.successCount = successCount;
}
public Integer getErrorCount() {
return errorCount;
}
public void setErrorCount(Integer errorCount) {
this.errorCount = errorCount;
}
public Integer getIgnoreCount() {
return ignoreCount;
}
public void setIgnoreCount(Integer ignoreCount) {
this.ignoreCount = ignoreCount;
}
@Override
public String toString() {
return "ImportResultVO{" +
"success=" + success +
", error=" + error +
", ignore=" + ignore +
", successCount=" + successCount +
", errorCount=" + errorCount +
", ignoreCount=" + ignoreCount +
'}';
}
}

View File

@ -0,0 +1,20 @@
package org.maxkey.util;
import org.maxkey.domain.UserInfo;
import java.io.InputStream;
import java.util.List;
/**
* @author yapeng.li
* @since 2020/9/21 21:06
*/
public class ExcelUtils {
public static List<UserInfo> readExcel(InputStream in) throws Exception {
return null;
}
}

View File

@ -23,6 +23,7 @@ import org.maxkey.constants.ConstantsStatus;
import org.maxkey.crypto.ReciprocalUtils;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.domain.ChangePassword;
import org.maxkey.domain.ImportResultVO;
import org.maxkey.domain.UserInfo;
import org.maxkey.identity.kafka.KafkaIdentityAction;
import org.maxkey.identity.kafka.KafkaIdentityTopic;
@ -38,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
@ -101,6 +103,18 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
return false;
}
public ImportResultVO importing(MultipartFile file,Integer type){
// 校验当前文件格式是不是excel文件
// 解析excel文件中数据
// 判断当前类型 0忽略 1覆盖 2终止
// 返回导入结果
return new ImportResultVO();
}
public boolean delete(UserInfo userInfo) {
if( super.delete(userInfo)){
kafkaProvisioningService.send(

View File

@ -192,9 +192,36 @@ 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);
}
/**
* 批量删除用户
*
* @param id
* @return
*/