|
|
|
@@ -1,6 +1,7 @@ |
|
|
|
package com.simple.controller; |
|
|
|
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.simple.common.ErrorCode; |
|
|
|
import com.simple.common.ResultData; |
|
|
|
import com.simple.domain.po.*; |
|
|
|
import com.simple.service.*; |
|
|
|
@@ -78,8 +79,13 @@ public class MallUserInfoController extends BaseController { |
|
|
|
@ApiOperation(value = "创建用户接口", response = String.class) |
|
|
|
@PostMapping("add") |
|
|
|
public ResultData createUser(@RequestBody MallUserInfo userInfo) { |
|
|
|
Assert.notNull(userInfo.getUsername(), "用户名不能为空"); |
|
|
|
Assert.isTrue(checkUnique(userInfo.getUsername(), 0), "重复的用户名"); |
|
|
|
|
|
|
|
if(checkUniqueName(userInfo.getUsername(), null)){ |
|
|
|
return new ResultData(ErrorCode.USER_NAME_IS_FOUND,"用户名已存在"); |
|
|
|
} |
|
|
|
if(checkUniquePhone(userInfo.getPhone(), null)){ |
|
|
|
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND,"手机号已存在"); |
|
|
|
} |
|
|
|
Assert.notNull(userInfo.getPassword(), "密码不能为空"); |
|
|
|
PasswordHelper passwordHelper = new PasswordHelper(); |
|
|
|
passwordHelper.encryptPassword(userInfo); |
|
|
|
@@ -97,8 +103,13 @@ public class MallUserInfoController extends BaseController { |
|
|
|
@ApiOperation(value = "修改用户接口", response = String.class) |
|
|
|
@PostMapping("update") |
|
|
|
public ResultData updateUser(@RequestBody MallUserInfo userInfo) { |
|
|
|
Assert.notNull(userInfo.getUsername(), "用户名不能为空"); |
|
|
|
Assert.isTrue(checkUnique(userInfo.getUsername(), 1), "重复的用户名"); |
|
|
|
//Assert.notNull(userInfo.getUsername(), "用户名不能为空"); |
|
|
|
if(checkUniqueName(userInfo.getUsername(), userInfo.getId())){ |
|
|
|
return new ResultData(ErrorCode.USER_NAME_IS_FOUND,"用户名已存在"); |
|
|
|
} |
|
|
|
if(checkUniquePhone(userInfo.getPhone(), userInfo.getId())){ |
|
|
|
return new ResultData(ErrorCode.USER_PHONE_IS_FOUND,"手机号已存在"); |
|
|
|
} |
|
|
|
// Assert.notNull(userInfo.getPassword(), "密码不能为空"); |
|
|
|
// PasswordHelper passwordHelper = new PasswordHelper(); |
|
|
|
// passwordHelper.encryptPassword(userInfo); |
|
|
|
@@ -155,18 +166,12 @@ public class MallUserInfoController extends BaseController { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkUnique(String username, Integer type) { |
|
|
|
if (type == 0) { |
|
|
|
if (userInfoService.cntByUserName(username) > 0) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (type == 1) { |
|
|
|
if (userInfoService.cntByUserName(username) > 1) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
private boolean checkUniqueName(String username, Long id) { |
|
|
|
return userInfoService.cntByUserName(username,id); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkUniquePhone(String phone, Long id) { |
|
|
|
return userInfoService.cntByUserPhone(phone,id); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|