Browse Source

获取userid

master
zhangye 6 years ago
parent
commit
843354a6f1
  1. 0
      origin)
  2. 18
      tall/src/main/java/com/ccsens/tall/service/ProjectService.java
  3. 47
      tall/src/main/java/com/ccsens/tall/web/UserController.java

0
origin)

18
tall/src/main/java/com/ccsens/tall/service/ProjectService.java

@ -61,6 +61,7 @@ public class ProjectService implements IProjectService {
/** /**
* 根据名字查找此用户创建的项目 * 根据名字查找此用户创建的项目
*
* @param subProject * @param subProject
* @param currentUserId * @param currentUserId
* @return * @return
@ -79,6 +80,7 @@ public class ProjectService implements IProjectService {
/** /**
* 查找本月哪一天有项目 * 查找本月哪一天有项目
*
* @param currentUserId * @param currentUserId
* @param date * @param date
* @return * @return
@ -102,6 +104,7 @@ public class ProjectService implements IProjectService {
} }
return dateList; return dateList;
} }
private List<String> getTimeList(List<String> dateList, Long startTime, Long endTime) { private List<String> getTimeList(List<String> dateList, Long startTime, Long endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("dd"); SimpleDateFormat sdf = new SimpleDateFormat("dd");
Date s = new Date(startTime); Date s = new Date(startTime);
@ -125,6 +128,7 @@ public class ProjectService implements IProjectService {
/** /**
* 根据用户和日期查找项目 * 根据用户和日期查找项目
*
* @param currentUserId * @param currentUserId
* @param date * @param date
* @return * @return
@ -172,6 +176,7 @@ public class ProjectService implements IProjectService {
// } // }
return projectInfoList; return projectInfoList;
} }
private List<ProjectVo.ProjectInfo> projectInfoByProject(List<SysProject> projectList, Long currentUserId) { private List<ProjectVo.ProjectInfo> projectInfoByProject(List<SysProject> projectList, Long currentUserId) {
List<ProjectVo.ProjectInfo> projectInfoList = new ArrayList<>(); List<ProjectVo.ProjectInfo> projectInfoList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(projectList)) { if (CollectionUtil.isNotEmpty(projectList)) {
@ -208,6 +213,7 @@ public class ProjectService implements IProjectService {
/** /**
* 通过项目id查询项目 * 通过项目id查询项目
*
* @param userId 用户id * @param userId 用户id
* @param projectId * @param projectId
* @return * @return
@ -253,6 +259,7 @@ public class ProjectService implements IProjectService {
/** /**
* 根据类型查项目 项目类型 0普通项目 1模板项目 2常驻项目 * 根据类型查项目 项目类型 0普通项目 1模板项目 2常驻项目
*
* @return * @return
*/ */
@Override @Override
@ -369,13 +376,14 @@ public class ProjectService implements IProjectService {
return sysProjectDao.getProjectByKey(currentUserId, key); return sysProjectDao.getProjectByKey(currentUserId, key);
} }
//=========================================================================== //===========================================================================
/** /**
* 删除项目 * 删除项目
*/ */
@Override @Override
public void deleteProject(Long currentUserId, Long projectId) throws Exception { public void deleteProject(Long currentUserId, Long projectId) throws Exception {
//本用户在项目中的角色 SysProject project = sysProjectDao.selectByPrimaryKey(projectId);
List<ProRole> proRoles = proRoleService.getProRoleByProjectIdAndUserId(projectId, currentUserId); if (ObjectUtil.isNotNull(project)) {
//用户在项目中的最高权限 //用户在项目中的最高权限
int power = proRoleService.selectPowerByRoleName(currentUserId, projectId); int power = proRoleService.selectPowerByRoleName(currentUserId, projectId);
if (power > 1) { if (power > 1) {
@ -388,7 +396,11 @@ public class ProjectService implements IProjectService {
} else { } else {
throw new BaseException(CodeEnum.NOT_POWER); throw new BaseException(CodeEnum.NOT_POWER);
} }
} else {
throw new BaseException(CodeEnum.NOT_PROJECT);
}
} }
/** /**
* 删除项目 * 删除项目
*/ */
@ -441,6 +453,7 @@ public class ProjectService implements IProjectService {
return projectInfo; return projectInfo;
} }
/** /**
* 复制角色 * 复制角色
*/ */
@ -479,6 +492,7 @@ public class ProjectService implements IProjectService {
copyTask(oldProjectId, newProjectId, oldRoleMap, newRoleMap); copyTask(oldProjectId, newProjectId, oldRoleMap, newRoleMap);
} }
} }
private void copyRoleExeclude(List<ProRole> oldRoleList, Map<Long, String> oldRoleMap, Map<String, Long> newRoleMap) { private void copyRoleExeclude(List<ProRole> oldRoleList, Map<Long, String> oldRoleMap, Map<String, Long> newRoleMap) {
if (CollectionUtil.isNotEmpty(oldRoleList)) { if (CollectionUtil.isNotEmpty(oldRoleList)) {
for (ProRole oldRole : oldRoleList) { for (ProRole oldRole : oldRoleList) {

47
tall/src/main/java/com/ccsens/tall/web/UserController.java

@ -5,12 +5,12 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import com.ccsens.tall.bean.dto.UserDto; import com.ccsens.tall.bean.dto.UserDto;
import com.ccsens.tall.bean.po.SysUser;
import com.ccsens.tall.bean.vo.UserVo; import com.ccsens.tall.bean.vo.UserVo;
import com.ccsens.tall.exception.UserLoginException; import com.ccsens.tall.exception.UserLoginException;
import com.ccsens.tall.service.IUserService; import com.ccsens.tall.service.IUserService;
import com.ccsens.util.JsonResponse; import com.ccsens.util.*;
import com.ccsens.util.JwtUtil; import com.ccsens.util.exception.BaseException;
import com.ccsens.util.WebConstant;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.SignatureException; import io.jsonwebtoken.SignatureException;
@ -193,8 +193,8 @@ public class UserController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="token",value = "token",required = true,paramType = "query") @ApiImplicitParam(name="token",value = "token",required = true,paramType = "query")
}) })
@RequestMapping(value = "token",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) @RequestMapping(value = "claims",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.TokenToUserId> getNodeMessage(@RequestParam(required = true) String token) throws Exception { public JsonResponse<UserVo.TokenToUserId> getNodeMessage(HttpServletRequest request, @RequestParam(required = true) String token) throws Exception {
//验证token是否有效 //验证token是否有效
UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId(); UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId();
Claims claims = null; Claims claims = null;
@ -218,6 +218,43 @@ public class UserController {
return JsonResponse.newInstance().ok(tokenToUserId); return JsonResponse.newInstance().ok(tokenToUserId);
} }
@ApiOperation(value = "根据token字符串获取userId",notes = "")
@ApiImplicitParams({
@ApiImplicitParam(name="token",value = "token",required = true,paramType = "query")
})
@RequestMapping(value = "token",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.TokenToUserId> getUserByToken(HttpServletRequest request, @RequestParam(required = true) String token) throws Exception {
UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId();
// 验证token是否存在
String tokenStr = token;
if (tokenStr == null || !tokenStr.startsWith(WebConstant.HEADER_KEY_TOKEN_PREFIX)) {
throw new BaseException(CodeEnum.NOT_LOGIN);
}
String userToken = tokenStr.substring(WebConstant.HEADER_KEY_TOKEN_PREFIX.length());
//验证token是否有效
Claims claims = null;
try {
claims = JwtUtil.parseJWT(userToken, WebConstant.JWT_ACCESS_TOKEN_SECERT);
}catch(Exception e){
throw new BaseException(CodeEnum.NOT_LOGIN);
}
//验证用户存根
if(userService.tokenNotExistInCache(Long.valueOf(claims.getSubject()))){
throw new BaseException(CodeEnum.NOT_LOGIN);
}
//验证用户是否禁用
SysUser user = userService.getUserById(Long.valueOf(claims.getSubject()));
if(user.getRecStatus() == WebConstant.REC_STATUS.Disabled.value){
throw new BaseException(CodeEnum.NOT_LOGIN);
}
tokenToUserId.setId(Long.valueOf(claims.getSubject()));
return JsonResponse.newInstance().ok(tokenToUserId);
}
} }

Loading…
Cancel
Save