调整用户信息编辑接口
This commit is contained in:
parent
cc481438df
commit
b4be4a1e86
|
|
@ -1,8 +1,8 @@
|
||||||
package com.mdd.admin.controller.user;
|
package com.mdd.admin.controller.user;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
import com.mdd.admin.service.user.IUserService;
|
import com.mdd.admin.service.user.IUserService;
|
||||||
import com.mdd.admin.validate.common.PageParam;
|
import com.mdd.admin.validate.common.PageParam;
|
||||||
import com.mdd.admin.validate.user.UserInfoParam;
|
|
||||||
import com.mdd.admin.vo.user.UserVo;
|
import com.mdd.admin.vo.user.UserVo;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
import com.mdd.common.core.PageResult;
|
import com.mdd.common.core.PageResult;
|
||||||
|
|
@ -55,12 +55,15 @@ public class UserController {
|
||||||
* 用户编辑
|
* 用户编辑
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param userInfoParam 用户参数
|
* @param params 参数
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@PostMapping("/edit")
|
@PostMapping("/edit")
|
||||||
public Object edit(@Validated @RequestBody UserInfoParam userInfoParam) {
|
public Object edit(@RequestBody Map<String, String> params) {
|
||||||
iUserService.edit(userInfoParam);
|
Assert.notNull(params.get("id"), "id参数缺失");
|
||||||
|
Assert.notNull(params.get("field"), "field参数缺失");
|
||||||
|
Assert.notNull(params.get("value"), "value参数缺失");
|
||||||
|
iUserService.edit(params);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.mdd.admin.service.user;
|
package com.mdd.admin.service.user;
|
||||||
|
|
||||||
import com.mdd.admin.validate.common.PageParam;
|
import com.mdd.admin.validate.common.PageParam;
|
||||||
import com.mdd.admin.validate.user.UserInfoParam;
|
|
||||||
import com.mdd.admin.vo.user.UserVo;
|
import com.mdd.admin.vo.user.UserVo;
|
||||||
import com.mdd.common.core.PageResult;
|
import com.mdd.common.core.PageResult;
|
||||||
|
|
||||||
|
|
@ -35,8 +34,8 @@ public interface IUserService {
|
||||||
* 用户编辑
|
* 用户编辑
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @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.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.mdd.admin.service.user.IUserService;
|
import com.mdd.admin.service.user.IUserService;
|
||||||
import com.mdd.admin.validate.common.PageParam;
|
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.admin.vo.user.UserVo;
|
||||||
import com.mdd.common.core.PageResult;
|
import com.mdd.common.core.PageResult;
|
||||||
import com.mdd.common.entity.user.User;
|
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.StringUtil;
|
||||||
import com.mdd.common.utils.TimeUtil;
|
import com.mdd.common.utils.TimeUtil;
|
||||||
import com.mdd.common.utils.UrlUtil;
|
import com.mdd.common.utils.UrlUtil;
|
||||||
import org.checkerframework.checker.units.qual.A;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
@ -136,39 +133,56 @@ public class UserServiceImpl implements IUserService {
|
||||||
* 用户编辑
|
* 用户编辑
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param userInfoParam 参数
|
* @param params 参数
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void edit(UserInfoParam userInfoParam) {
|
public void edit(Map<String, String> params) {
|
||||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
Integer id = Integer.parseInt(params.get("id"));
|
||||||
.eq("id", userInfoParam.getId())
|
String field = params.get("field").trim();
|
||||||
.eq("is_delete", 0)
|
String value = params.get("value").trim();
|
||||||
.last("limit 1"));
|
|
||||||
|
|
||||||
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())) {
|
Assert.notNull(user, "用户不存在!");
|
||||||
User u = userMapper.selectOne(new QueryWrapper<User>()
|
|
||||||
.eq("username", userInfoParam.getUsername())
|
switch (field) {
|
||||||
.eq("is_delete", 0)
|
case "username":
|
||||||
.last("limit 1"));
|
if (!user.getUsername().equals(value)) {
|
||||||
System.out.println(u);
|
User u = userMapper.selectOne(new QueryWrapper<User>()
|
||||||
if (StringUtil.isNotNull(u) && !u.getId().equals(userInfoParam.getId())) {
|
.eq("username", value)
|
||||||
throw new OperateException("当前账号已存在!");
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
if (StringUtil.isNotNull(u) && !u.getId().equals(id)) {
|
||||||
|
throw new OperateException("当前账号已存在!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!userInfoParam.getMobile().equals("")) {
|
user.setUsername(value);
|
||||||
if(!Pattern.matches("^[1][3,4,5,6,7,8,9][0-9]{9}$", userInfoParam.getMobile())){
|
break;
|
||||||
throw new OperateException("手机号格式不正确!");
|
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.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||||
user.setRealName(userInfoParam.getRealName());
|
userMapper.updateById(user);
|
||||||
user.setSex(userInfoParam.getSex());
|
|
||||||
user.setMobile(userInfoParam.getMobile());
|
|
||||||
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