增加用户编辑功能
This commit is contained in:
parent
a40d4c8986
commit
3a641675e3
|
|
@ -2,15 +2,13 @@ package com.mdd.admin.controller.user;
|
|||
|
||||
import com.mdd.admin.service.user.IUserService;
|
||||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.validate.user.UserInfoParam;
|
||||
import com.mdd.admin.vo.user.UserVo;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
|
@ -53,4 +51,17 @@ public class UserController {
|
|||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param userInfoParam 用户参数
|
||||
* @return Object
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public Object edit(@Validated @RequestBody UserInfoParam userInfoParam) {
|
||||
iUserService.edit(userInfoParam);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.mdd.admin.service.user;
|
||||
|
||||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.validate.user.UserInfoParam;
|
||||
import com.mdd.admin.vo.user.UserVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
|
||||
|
|
@ -30,4 +31,12 @@ public interface IUserService {
|
|||
*/
|
||||
UserVo detail(Integer id);
|
||||
|
||||
/**
|
||||
* 用户编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param userInfoParam 参数
|
||||
*/
|
||||
void edit(UserInfoParam userInfoParam);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,18 @@ import com.baomidou.mybatisplus.core.toolkit.Assert;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mdd.admin.service.user.IUserService;
|
||||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.validate.user.UserInfoParam;
|
||||
import com.mdd.admin.vo.article.ArticleListVo;
|
||||
import com.mdd.admin.vo.user.UserVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.TimeUtil;
|
||||
import com.mdd.common.utils.UrlUtil;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -22,6 +25,7 @@ import javax.annotation.Resource;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 用户服务实现类
|
||||
|
|
@ -128,4 +132,43 @@ public class UserServiceImpl implements IUserService {
|
|||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param userInfoParam 参数
|
||||
*/
|
||||
@Override
|
||||
public void edit(UserInfoParam userInfoParam) {
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("id", userInfoParam.getId())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(user, "用户不存在!");
|
||||
|
||||
if (!user.getUsername().equals(userInfoParam.getUsername())) {
|
||||
User u = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("username", userInfoParam.getUsername())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
System.out.println(u);
|
||||
if (StringUtil.isNotNull(u) && !u.getId().equals(userInfoParam.getId())) {
|
||||
throw new OperateException("当前账号已存在!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!userInfoParam.getMobile().equals("")) {
|
||||
if(!Pattern.matches("^[1][3,4,5,6,7,8,9][0-9]{9}$", userInfoParam.getMobile())){
|
||||
throw new OperateException("手机号格式不正确!");
|
||||
}
|
||||
}
|
||||
|
||||
user.setUsername(userInfoParam.getUsername());
|
||||
user.setRealName(userInfoParam.getRealName());
|
||||
user.setSex(userInfoParam.getSex());
|
||||
user.setMobile(userInfoParam.getMobile());
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package com.mdd.admin.validate.user;
|
||||
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import com.mdd.common.validator.annotation.IntegerContains;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户信息参数
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class UserInfoParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0")
|
||||
private Integer id;
|
||||
|
||||
@NotNull(message = "username参数缺失")
|
||||
@NotEmpty(message = "账号不能为空")
|
||||
private String username;
|
||||
|
||||
@NotNull(message = "realName参数缺失")
|
||||
@NotEmpty(message = "真实名称不能为空")
|
||||
private String realName;
|
||||
|
||||
@NotNull(message = "sex参数缺失")
|
||||
@IntegerContains(values = {0, 1, 2}, message = "请正确选择性别")
|
||||
private Integer sex;
|
||||
|
||||
private String mobile;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue