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 currentUserId
* @return
@ -79,6 +80,7 @@ public class ProjectService implements IProjectService {
/**
* 查找本月哪一天有项目
*
* @param currentUserId
* @param date
* @return
@ -102,6 +104,7 @@ public class ProjectService implements IProjectService {
}
return dateList;
}
private List<String> getTimeList(List<String> dateList, Long startTime, Long endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("dd");
Date s = new Date(startTime);
@ -125,6 +128,7 @@ public class ProjectService implements IProjectService {
/**
* 根据用户和日期查找项目
*
* @param currentUserId
* @param date
* @return
@ -172,6 +176,7 @@ public class ProjectService implements IProjectService {
// }
return projectInfoList;
}
private List<ProjectVo.ProjectInfo> projectInfoByProject(List<SysProject> projectList, Long currentUserId) {
List<ProjectVo.ProjectInfo> projectInfoList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(projectList)) {
@ -208,6 +213,7 @@ public class ProjectService implements IProjectService {
/**
* 通过项目id查询项目
*
* @param userId 用户id
* @param projectId
* @return
@ -253,6 +259,7 @@ public class ProjectService implements IProjectService {
/**
* 根据类型查项目 项目类型 0普通项目 1模板项目 2常驻项目
*
* @return
*/
@Override
@ -369,13 +376,14 @@ public class ProjectService implements IProjectService {
return sysProjectDao.getProjectByKey(currentUserId, key);
}
//===========================================================================
/**
* 删除项目
*/
@Override
public void deleteProject(Long currentUserId, Long projectId) throws Exception {
//本用户在项目中的角色
List<ProRole> proRoles = proRoleService.getProRoleByProjectIdAndUserId(projectId, currentUserId);
SysProject project = sysProjectDao.selectByPrimaryKey(projectId);
if (ObjectUtil.isNotNull(project)) {
//用户在项目中的最高权限
int power = proRoleService.selectPowerByRoleName(currentUserId, projectId);
if (power > 1) {
@ -388,7 +396,11 @@ public class ProjectService implements IProjectService {
} else {
throw new BaseException(CodeEnum.NOT_POWER);
}
} else {
throw new BaseException(CodeEnum.NOT_PROJECT);
}
}
/**
* 删除项目
*/
@ -441,6 +453,7 @@ public class ProjectService implements IProjectService {
return projectInfo;
}
/**
* 复制角色
*/
@ -479,6 +492,7 @@ public class ProjectService implements IProjectService {
copyTask(oldProjectId, newProjectId, oldRoleMap, newRoleMap);
}
}
private void copyRoleExeclude(List<ProRole> oldRoleList, Map<Long, String> oldRoleMap, Map<String, Long> newRoleMap) {
if (CollectionUtil.isNotEmpty(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.extra.servlet.ServletUtil;
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.exception.UserLoginException;
import com.ccsens.tall.service.IUserService;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.JwtUtil;
import com.ccsens.util.WebConstant;
import com.ccsens.util.*;
import com.ccsens.util.exception.BaseException;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.SignatureException;
@ -193,8 +193,8 @@ public class UserController {
@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> getNodeMessage(@RequestParam(required = true) String token) throws Exception {
@RequestMapping(value = "claims",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.TokenToUserId> getNodeMessage(HttpServletRequest request, @RequestParam(required = true) String token) throws Exception {
//验证token是否有效
UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId();
Claims claims = null;
@ -218,6 +218,43 @@ public class UserController {
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