mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-08 09:58:56 +08:00
1.添加用户导入controller
This commit is contained in:
parent
6fd8255d87
commit
9b39775eb0
@ -28,4 +28,7 @@ public final class ConstantsOperateMessage {
|
|||||||
public static final String DELETE_SUCCESS = "message.action.delete.success";
|
public static final String DELETE_SUCCESS = "message.action.delete.success";
|
||||||
public static final String DELETE_ERROR = "message.action.delete.error";
|
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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
105
maxkey-core/src/main/java/org/maxkey/domain/ImportResultVO.java
Normal file
105
maxkey-core/src/main/java/org/maxkey/domain/ImportResultVO.java
Normal 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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
20
maxkey-core/src/main/java/org/maxkey/util/ExcelUtils.java
Normal file
20
maxkey-core/src/main/java/org/maxkey/util/ExcelUtils.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ import org.maxkey.constants.ConstantsStatus;
|
|||||||
import org.maxkey.crypto.ReciprocalUtils;
|
import org.maxkey.crypto.ReciprocalUtils;
|
||||||
import org.maxkey.crypto.password.PasswordReciprocal;
|
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||||
import org.maxkey.domain.ChangePassword;
|
import org.maxkey.domain.ChangePassword;
|
||||||
|
import org.maxkey.domain.ImportResultVO;
|
||||||
import org.maxkey.domain.UserInfo;
|
import org.maxkey.domain.UserInfo;
|
||||||
import org.maxkey.identity.kafka.KafkaIdentityAction;
|
import org.maxkey.identity.kafka.KafkaIdentityAction;
|
||||||
import org.maxkey.identity.kafka.KafkaIdentityTopic;
|
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.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,6 +103,18 @@ public class UserInfoService extends JpaBaseService<UserInfo> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImportResultVO importing(MultipartFile file,Integer type){
|
||||||
|
|
||||||
|
// 校验当前文件格式是不是excel文件
|
||||||
|
|
||||||
|
// 解析excel文件中数据
|
||||||
|
|
||||||
|
// 判断当前类型 0忽略 1覆盖 2终止
|
||||||
|
// 返回导入结果
|
||||||
|
|
||||||
|
return new ImportResultVO();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean delete(UserInfo userInfo) {
|
public boolean delete(UserInfo userInfo) {
|
||||||
if( super.delete(userInfo)){
|
if( super.delete(userInfo)){
|
||||||
kafkaProvisioningService.send(
|
kafkaProvisioningService.send(
|
||||||
|
|||||||
@ -172,107 +172,134 @@ public class UserInfoController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RequestMapping(value="/update")
|
@RequestMapping(value = "/update")
|
||||||
public ModelAndView updateUsers(@Valid @ModelAttribute("userInfo")UserInfo userInfo,BindingResult result) {
|
public ModelAndView updateUsers(@Valid @ModelAttribute("userInfo") UserInfo userInfo, BindingResult result) {
|
||||||
_logger.debug(userInfo.toString());
|
_logger.debug(userInfo.toString());
|
||||||
if(result.hasErrors()){
|
if (result.hasErrors()) {
|
||||||
// new Message(WebContext.getValidErrorText(),result);
|
// new Message(WebContext.getValidErrorText(),result);
|
||||||
}
|
}
|
||||||
_logger.info(userInfo.getExtraAttributeName());
|
_logger.info(userInfo.getExtraAttributeName());
|
||||||
_logger.info(userInfo.getExtraAttributeValue());
|
_logger.info(userInfo.getExtraAttributeValue());
|
||||||
//userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true));
|
//userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true));
|
||||||
//userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false));
|
//userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false));
|
||||||
convertExtraAttribute(userInfo) ;
|
convertExtraAttribute(userInfo);
|
||||||
_logger.info(userInfo.getExtraAttribute());
|
_logger.info(userInfo.getExtraAttribute());
|
||||||
if(userInfoService.update(userInfo)) {
|
if (userInfoService.update(userInfo)) {
|
||||||
new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),userInfo,MessageType.success,OperateType.add,MessageScope.DB);
|
new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS), userInfo, MessageType.success, OperateType.add, MessageScope.DB);
|
||||||
|
|
||||||
}
|
}
|
||||||
new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error);
|
new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR), MessageType.error);
|
||||||
return WebContext.forward("forwardUpdate/"+userInfo.getId());
|
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
|
* @param id
|
||||||
*/
|
* @return
|
||||||
@ResponseBody
|
*/
|
||||||
@RequestMapping(value="/batchDelete")
|
@ResponseBody
|
||||||
public Message batchDeleteUsers(@RequestParam("id")String id) {
|
@RequestMapping(value = "/batchDelete")
|
||||||
_logger.debug(id);
|
public Message batchDeleteUsers(@RequestParam("id") String id) {
|
||||||
if(userInfoService.batchDelete(StringUtils.string2List(id, ","))) {
|
_logger.debug(id);
|
||||||
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_SUCCESS),MessageType.success);
|
if (userInfoService.batchDelete(StringUtils.string2List(id, ","))) {
|
||||||
|
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_SUCCESS), MessageType.success);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_ERROR),MessageType.error);
|
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_ERROR), MessageType.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户id删除用户
|
* 根据用户id删除用户
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping(value="/delete")
|
@RequestMapping(value = "/delete")
|
||||||
public Message deleteUsersById(@RequestParam("id") String id) {
|
public Message deleteUsersById(@RequestParam("id") String id) {
|
||||||
_logger.debug(id);
|
_logger.debug(id);
|
||||||
if(userInfoService.batchDelete(StringUtils.string2List(id, ","))) {
|
if (userInfoService.batchDelete(StringUtils.string2List(id, ","))) {
|
||||||
//provisioningPrepare.prepare(userInfo, OPERATEACTION.DELETE_ACTION);
|
//provisioningPrepare.prepare(userInfo, OPERATEACTION.DELETE_ACTION);
|
||||||
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_SUCCESS),MessageType.success);
|
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_SUCCESS), MessageType.success);
|
||||||
} else {
|
} else {
|
||||||
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_ERROR),MessageType.error);
|
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.DELETE_ERROR), MessageType.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void convertExtraAttribute(UserInfo userInfo) {
|
protected void convertExtraAttribute(UserInfo userInfo) {
|
||||||
if(userInfo.getExtraAttributeValue()!=null){
|
if (userInfo.getExtraAttributeValue() != null) {
|
||||||
String []extraAttributeLabel=userInfo.getExtraAttributeName().split(",");
|
String[] extraAttributeLabel = userInfo.getExtraAttributeName().split(",");
|
||||||
String []extraAttributeValue=userInfo.getExtraAttributeValue().split(",");
|
String[] extraAttributeValue = userInfo.getExtraAttributeValue().split(",");
|
||||||
Map<String,String> extraAttributeMap=new HashMap<String,String> ();
|
Map<String, String> extraAttributeMap = new HashMap<String, String>();
|
||||||
for(int i=0;i<extraAttributeLabel.length;i++){
|
for (int i = 0; i < extraAttributeLabel.length; i++) {
|
||||||
extraAttributeMap.put(extraAttributeLabel[i], extraAttributeValue[i]);
|
extraAttributeMap.put(extraAttributeLabel[i], extraAttributeValue[i]);
|
||||||
}
|
}
|
||||||
String extraAttribute=JsonUtils.object2Json(extraAttributeMap);
|
String extraAttribute = JsonUtils.object2Json(extraAttributeMap);
|
||||||
userInfo.setExtraAttribute(extraAttribute);
|
userInfo.setExtraAttribute(extraAttribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value={"/forwardChangePassword/{id}"})
|
@RequestMapping(value = {"/forwardChangePassword/{id}"})
|
||||||
public ModelAndView forwardChangePassword(@PathVariable("id")String id){
|
public ModelAndView forwardChangePassword(@PathVariable("id") String id) {
|
||||||
ModelAndView modelAndView=new ModelAndView("/userinfo/changePassword");
|
ModelAndView modelAndView = new ModelAndView("/userinfo/changePassword");
|
||||||
UserInfo userInfo=userInfoService.get(id);
|
UserInfo userInfo = userInfoService.get(id);
|
||||||
|
|
||||||
modelAndView.addObject("model", userInfo);
|
modelAndView.addObject("model", userInfo);
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping(value="/changePassword")
|
@RequestMapping(value = "/changePassword")
|
||||||
public Message changePassword( @ModelAttribute("userInfo")UserInfo userInfo) {
|
public Message changePassword(@ModelAttribute("userInfo") UserInfo userInfo) {
|
||||||
_logger.debug(userInfo.getId());
|
_logger.debug(userInfo.getId());
|
||||||
if(userInfoService.changePassword(userInfo)) {
|
if (userInfoService.changePassword(userInfo)) {
|
||||||
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),MessageType.success);
|
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS), MessageType.success);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error);
|
return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR), MessageType.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@InitBinder
|
@InitBinder
|
||||||
public void binder(WebDataBinder binder) {
|
public void binder(WebDataBinder binder) {
|
||||||
binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
|
binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
|
||||||
@Override
|
@Override
|
||||||
public void setAsText(String value) {
|
public void setAsText(String value) {
|
||||||
if(StringUtils.isNullOrBlank(value)){
|
if (StringUtils.isNullOrBlank(value)) {
|
||||||
setValue(null);
|
setValue(null);
|
||||||
}else{
|
} else {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user