|
|
|
@@ -3,6 +3,8 @@ package com.simple.controller; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import com.simple.domain.po.*; |
|
|
|
import com.simple.service.*; |
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
@@ -14,14 +16,6 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.simple.common.ResultData; |
|
|
|
import com.simple.domain.po.MallRole; |
|
|
|
import com.simple.domain.po.MallRolePermission; |
|
|
|
import com.simple.domain.po.MallUserInfo; |
|
|
|
import com.simple.domain.po.MallUserRole; |
|
|
|
import com.simple.service.MallRolePermissionService; |
|
|
|
import com.simple.service.MallRoleService; |
|
|
|
import com.simple.service.MallUserInfoService; |
|
|
|
import com.simple.service.MallUserRoleService; |
|
|
|
import com.simple.shiro.PasswordHelper; |
|
|
|
import com.simple.shiro.UserSession; |
|
|
|
|
|
|
|
@@ -35,7 +29,7 @@ import io.swagger.annotations.ApiOperation; |
|
|
|
@Api(value = "API - UserInfoController", description = "用户接口") |
|
|
|
@RestController |
|
|
|
@RequestMapping("user") |
|
|
|
public class MallUserInfoController { |
|
|
|
public class MallUserInfoController extends BaseController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MallUserInfoService userInfoService; |
|
|
|
@@ -48,12 +42,17 @@ public class MallUserInfoController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MallUserRoleService mallUserRoleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MallPermissionService mallPermissionService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MallRolePermissionService mallRolePermissionService; |
|
|
|
|
|
|
|
@ApiOperation(value = "用户分页接口", response = String.class) |
|
|
|
@GetMapping("lists") |
|
|
|
public ResultData listAsPage(MallUserInfo userInfo, Integer pageNum, Integer pageSize){ |
|
|
|
userInfo.setTenantId(getTenantId()); |
|
|
|
final PageInfo<MallUserInfo> page = userInfoService.listAsPage(userInfo, pageNum, pageSize); |
|
|
|
for(MallUserInfo u:page.getList()) { |
|
|
|
MallUserRole r =new MallUserRole(); |
|
|
|
@@ -61,8 +60,10 @@ public class MallUserInfoController { |
|
|
|
PageInfo<MallUserRole> ur = userRoleService.listAsPage(r, 1, 1); |
|
|
|
if(ur.getSize()>0) { |
|
|
|
MallRole role = mallRoleService.getById(ur.getList().get(0).getRoleId()); |
|
|
|
u.setRoleName(role.getName()); |
|
|
|
u.setRoleId(role.getId()); |
|
|
|
if (role != null) { |
|
|
|
u.setRoleName(role.getName()); |
|
|
|
u.setRoleId(role.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
u.setPassword(null);//不返回密码 |
|
|
|
} |
|
|
|
@@ -84,6 +85,7 @@ public class MallUserInfoController { |
|
|
|
Assert.notNull(userInfo.getPassword(), "密码不能为空"); |
|
|
|
PasswordHelper passwordHelper = new PasswordHelper(); |
|
|
|
passwordHelper.encryptPassword(userInfo); |
|
|
|
userInfo.setTenantId(getTenantId()); |
|
|
|
userInfoService.saveOrUpdate(userInfo); |
|
|
|
if(userInfo.getRoleId()!=null) { |
|
|
|
MallUserRole r = new MallUserRole(); |
|
|
|
@@ -103,6 +105,7 @@ public class MallUserInfoController { |
|
|
|
// PasswordHelper passwordHelper = new PasswordHelper(); |
|
|
|
// passwordHelper.encryptPassword(userInfo); |
|
|
|
userInfo.setPassword(null); |
|
|
|
userInfo.setTenantId(getTenantId()); |
|
|
|
userInfoService.saveOrUpdate(userInfo); |
|
|
|
if(userInfo.getRoleId()!=null) { |
|
|
|
userRoleService.deleteByUserId(userInfo.getId()); |
|
|
|
@@ -133,6 +136,7 @@ public class MallUserInfoController { |
|
|
|
public ResultData modifyStatus(Long userId, Integer status) { |
|
|
|
MallUserInfo userInfo = userInfoService.getById(userId); |
|
|
|
userInfo.setStatus(status); |
|
|
|
userInfo.setTenantId(getTenantId()); |
|
|
|
userInfoService.saveOrUpdate(userInfo); |
|
|
|
return new ResultData(userInfo); |
|
|
|
} |
|
|
|
@@ -190,27 +194,38 @@ public class MallUserInfoController { |
|
|
|
public ResultData getUserInfo(){ |
|
|
|
MallUserInfo info =(MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); |
|
|
|
info.setPassword("保密"); |
|
|
|
// System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); |
|
|
|
MallUserRole ur = new MallUserRole(); |
|
|
|
ur.setUid(info.getId()); |
|
|
|
PageInfo<MallUserRole> page = mallUserRoleService.listAsPage(ur, 1, 1); |
|
|
|
if(page.getSize()>0) { |
|
|
|
Long roleId = page.getList().get(0).getRoleId(); |
|
|
|
MallRolePermission p = new MallRolePermission(); |
|
|
|
p.setRoleId(roleId); |
|
|
|
p.setTenantId(info.getTenantId()); |
|
|
|
PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); |
|
|
|
String menus = ""; |
|
|
|
for(MallRolePermission rp :listAsPage.getList()) { |
|
|
|
menus+=rp.getPermissionId()+","; |
|
|
|
} |
|
|
|
if(menus.length()>0) { |
|
|
|
menus = menus.substring(0, menus.length()-1); |
|
|
|
} |
|
|
|
info.setMenus(menus); |
|
|
|
} |
|
|
|
ResultData data = new ResultData(); |
|
|
|
data.data=info; |
|
|
|
return data; |
|
|
|
if (info.getIsAdmin() == 1) { // isAdmin |
|
|
|
MallPermission q = new MallPermission(); |
|
|
|
PageInfo<MallPermission> list = mallPermissionService.listAsPage(q,1,100); |
|
|
|
String menus = ""; |
|
|
|
for(MallPermission rp :list.getList()) { |
|
|
|
menus+=rp.getId()+","; |
|
|
|
} |
|
|
|
if(menus.length()>0) { |
|
|
|
menus = menus.substring(0, menus.length()-1); |
|
|
|
} |
|
|
|
info.setMenus(menus); |
|
|
|
} else { |
|
|
|
// System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); |
|
|
|
MallUserRole ur = new MallUserRole(); |
|
|
|
ur.setUid(info.getId()); |
|
|
|
PageInfo<MallUserRole> page = mallUserRoleService.listAsPage(ur, 1, 1); |
|
|
|
if(page.getSize()>0) { |
|
|
|
Long roleId = page.getList().get(0).getRoleId(); |
|
|
|
MallRolePermission p = new MallRolePermission(); |
|
|
|
p.setRoleId(roleId); |
|
|
|
p.setTenantId(info.getTenantId()); |
|
|
|
PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); |
|
|
|
String menus = ""; |
|
|
|
for(MallRolePermission rp :listAsPage.getList()) { |
|
|
|
menus+=rp.getPermissionId()+","; |
|
|
|
} |
|
|
|
if(menus.length()>0) { |
|
|
|
menus = menus.substring(0, menus.length()-1); |
|
|
|
} |
|
|
|
info.setMenus(menus); |
|
|
|
} |
|
|
|
} |
|
|
|
return new ResultData(info); |
|
|
|
} |
|
|
|
} |