调整用户信息编辑接口
This commit is contained in:
parent
cc481438df
commit
b4be4a1e86
|
|
@ -1,8 +1,8 @@
|
|||
package com.mdd.admin.controller.user;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
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;
|
||||
|
|
@ -55,12 +55,15 @@ public class UserController {
|
|||
* 用户编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param userInfoParam 用户参数
|
||||
* @param params 参数
|
||||
* @return Object
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public Object edit(@Validated @RequestBody UserInfoParam userInfoParam) {
|
||||
iUserService.edit(userInfoParam);
|
||||
public Object edit(@RequestBody Map<String, String> params) {
|
||||
Assert.notNull(params.get("id"), "id参数缺失");
|
||||
Assert.notNull(params.get("field"), "field参数缺失");
|
||||
Assert.notNull(params.get("value"), "value参数缺失");
|
||||
iUserService.edit(params);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
||||
|
|
@ -35,8 +34,8 @@ public interface IUserService {
|
|||
* 用户编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param userInfoParam 参数
|
||||
* @param params 参数
|
||||
*/
|
||||
void edit(UserInfoParam userInfoParam);
|
||||
void edit(Map<String, String> params);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ 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;
|
||||
|
|
@ -17,7 +15,6 @@ 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;
|
||||
|
||||
|
|
@ -136,39 +133,56 @@ public class UserServiceImpl implements IUserService {
|
|||
* 用户编辑
|
||||
*
|
||||
* @author fzr
|
||||
* @param userInfoParam 参数
|
||||
* @param params 参数
|
||||
*/
|
||||
@Override
|
||||
public void edit(UserInfoParam userInfoParam) {
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("id", userInfoParam.getId())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
public void edit(Map<String, String> params) {
|
||||
Integer id = Integer.parseInt(params.get("id"));
|
||||
String field = params.get("field").trim();
|
||||
String value = params.get("value").trim();
|
||||
|
||||
Assert.notNull(user, "用户不存在!");
|
||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
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("当前账号已存在!");
|
||||
Assert.notNull(user, "用户不存在!");
|
||||
|
||||
switch (field) {
|
||||
case "username":
|
||||
if (!user.getUsername().equals(value)) {
|
||||
User u = userMapper.selectOne(new QueryWrapper<User>()
|
||||
.eq("username", value)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNotNull(u) && !u.getId().equals(id)) {
|
||||
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(value);
|
||||
break;
|
||||
case "realName":
|
||||
user.setRealName(value);
|
||||
break;
|
||||
case "sex":
|
||||
user.setSex(Integer.parseInt(value));
|
||||
break;
|
||||
case "mobile":
|
||||
if (!value.equals("")) {
|
||||
if(!Pattern.matches("^[1][3,4,5,6,7,8,9][0-9]{9}$", value)){
|
||||
throw new OperateException("手机号格式不正确!");
|
||||
}
|
||||
}
|
||||
}
|
||||
user.setMobile(value);
|
||||
break;
|
||||
default:
|
||||
throw new OperateException("不被支持的字段类型!");
|
||||
}
|
||||
|
||||
user.setUsername(userInfoParam.getUsername());
|
||||
user.setRealName(userInfoParam.getRealName());
|
||||
user.setSex(userInfoParam.getSex());
|
||||
user.setMobile(userInfoParam.getMobile());
|
||||
userMapper.updateById(user);
|
||||
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
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