|
|
|
@@ -6,6 +6,7 @@ import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.EnumMallUserStatus; |
|
|
|
import com.iformall.enums.EnumUserAdmin; |
|
|
|
import com.iformall.service.*; |
|
|
|
import com.iformall.shiro.PasswordHelper; |
|
|
|
import com.iformall.shiro.UserSession; |
|
|
|
@@ -88,6 +89,10 @@ public class MallUserInfoController extends BaseController { |
|
|
|
@ApiOperation(value = "创建用户接口", response = String.class) |
|
|
|
@PostMapping("add") |
|
|
|
public ResultData createUser(@RequestBody MallUserInfo userInfo) { |
|
|
|
MallUserInfo currentUser = getUser(); |
|
|
|
if(currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { |
|
|
|
return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有超级管理员才能添加用户"); |
|
|
|
} |
|
|
|
|
|
|
|
if(checkUniqueName(userInfo.getUsername(), null)){ |
|
|
|
return new ResultData(ErrorCode.USER_NAME_IS_FOUND,"用户名已存在"); |
|
|
|
@@ -119,18 +124,41 @@ public class MallUserInfoController extends BaseController { |
|
|
|
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); |
|
|
|
|
|
|
|
// is_admin 不能在此系统设置 |
|
|
|
userInfo.setIsAdmin(null); |
|
|
|
if (StringUtils.isNotBlank(userInfo.getPassword()) && userInfo.getPassword().length() > 0) { |
|
|
|
PasswordHelper passwordHelper = new PasswordHelper(); |
|
|
|
passwordHelper.encryptPassword(userInfo); |
|
|
|
} |
|
|
|
userInfo.setTenantId(getTenantId()); |
|
|
|
userInfoService.saveOrUpdate(userInfo); |
|
|
|
if (userInfo.getRoleId() != null) { |
|
|
|
userRoleService.deleteByUserId(userInfo.getId()); |
|
|
|
MallUserRole r = new MallUserRole(); |
|
|
|
r.setRoleId(userInfo.getRoleId()); |
|
|
|
r.setUid(userInfo.getId()); |
|
|
|
userRoleService.saveOrUpdate(r); |
|
|
|
|
|
|
|
MallUserInfo currentUser = getUser(); |
|
|
|
if(currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { |
|
|
|
// 超管 |
|
|
|
boolean bModify = false; |
|
|
|
MallUserInfo adminUser = new MallUserInfo(); |
|
|
|
if (StringUtils.isNotBlank(userInfo.getPassword()) && userInfo.getPassword().length() > 0) { |
|
|
|
adminUser.setPassword(userInfo.getPassword()); |
|
|
|
bModify = true; |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(userInfo.getNickName())) { |
|
|
|
adminUser.setNickName(userInfo.getNickName()); |
|
|
|
} |
|
|
|
if (bModify) { |
|
|
|
userInfoService.saveOrUpdate(adminUser); |
|
|
|
} |
|
|
|
} else { |
|
|
|
userInfoService.saveOrUpdate(userInfo); |
|
|
|
if (userInfo.getRoleId() != null) { |
|
|
|
userRoleService.deleteByUserId(userInfo.getId()); |
|
|
|
MallUserRole r = new MallUserRole(); |
|
|
|
r.setRoleId(userInfo.getRoleId()); |
|
|
|
r.setUid(userInfo.getId()); |
|
|
|
userRoleService.saveOrUpdate(r); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -138,6 +166,9 @@ public class MallUserInfoController extends BaseController { |
|
|
|
@PostMapping("/del") |
|
|
|
public ResultData deleteUser(@RequestBody MallUserInfo userInfo) { |
|
|
|
MallUserInfo currentUser = getUser(); |
|
|
|
if (currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { |
|
|
|
return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有超级管理员才能删除用户"); |
|
|
|
} |
|
|
|
if (currentUser.getId().equals(userInfo.getId())) { |
|
|
|
return new ResultData(ErrorCode.USER_IS_EMPTY); |
|
|
|
} |
|
|
|
@@ -156,6 +187,10 @@ public class MallUserInfoController extends BaseController { |
|
|
|
@ApiOperation(value = "起停用户接口", response = String.class) |
|
|
|
@GetMapping("status") |
|
|
|
public ResultData modifyStatus(Long userId, Integer status) { |
|
|
|
MallUserInfo currentUser = getUser(); |
|
|
|
if (currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { |
|
|
|
return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有超级管理员才能删除用户"); |
|
|
|
} |
|
|
|
MallUserInfo userInfo = userInfoService.getById(userId); |
|
|
|
userInfo.setStatus(status); |
|
|
|
userInfo.setTenantId(getTenantId()); |
|
|
|
@@ -163,21 +198,6 @@ public class MallUserInfoController extends BaseController { |
|
|
|
return new ResultData(userInfo); |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "用户添加角色接口", response = String.class) |
|
|
|
@PostMapping("setRoles") |
|
|
|
public ResultData setRoles(Long userId, String roleIds) { |
|
|
|
/*String[] roIds = roleIds.split(","); |
|
|
|
List<MallUserRole> u2rs = new ArrayList<>(roIds.length); |
|
|
|
for (String roleId : roIds) { |
|
|
|
MallUserRole userRole = new MallUserRole(); |
|
|
|
userRole.setRoleId(roleId); |
|
|
|
userRole.setUid(userId); |
|
|
|
u2rs.add(userRole); |
|
|
|
} |
|
|
|
userRoleService.batchInsert(u2rs);*/ |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkUniqueName(String username, Long id) { |
|
|
|
return userInfoService.cntByUserName(username,id); |
|
|
|
} |
|
|
|
@@ -189,10 +209,11 @@ public class MallUserInfoController extends BaseController { |
|
|
|
|
|
|
|
@GetMapping("hasButtonPermission") |
|
|
|
public ResultData hasButtonPermission(String permissions) { |
|
|
|
MallUserInfo info = getUser(); |
|
|
|
info.setPassword("保密"); |
|
|
|
Map<String, Boolean> map = new HashMap<>(); |
|
|
|
for (String name : permissions.split(",")) { |
|
|
|
Long userId = (Long) |
|
|
|
SecurityUtils.getSubject().getSession().getAttribute(UserSession.userId); |
|
|
|
Long userId = (Long)SecurityUtils.getSubject().getSession().getAttribute(UserSession.userId); |
|
|
|
boolean has = userInfoService.hasButtonPermission(userId, name); |
|
|
|
map.put(name, has); |
|
|
|
} |
|
|
|
@@ -208,9 +229,9 @@ public class MallUserInfoController extends BaseController { |
|
|
|
|
|
|
|
@GetMapping("getUser") |
|
|
|
public ResultData getUserInfo() { |
|
|
|
MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); |
|
|
|
MallUserInfo info = getUser(); |
|
|
|
info.setPassword("保密"); |
|
|
|
if (info.getIsAdmin() == 1) { // isAdmin |
|
|
|
if (info.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { // isAdmin |
|
|
|
MallPermission q = new MallPermission(); |
|
|
|
PageInfo<MallPermission> list = mallPermissionService.listAsPage(q, 1, 100); |
|
|
|
String menus = ""; |
|
|
|
|