diff --git a/origin) b/origin) new file mode 100644 index 00000000..e69de29b diff --git a/tall/src/main/java/com/ccsens/tall/service/ProjectService.java b/tall/src/main/java/com/ccsens/tall/service/ProjectService.java index c858f597..2c46efa9 100644 --- a/tall/src/main/java/com/ccsens/tall/service/ProjectService.java +++ b/tall/src/main/java/com/ccsens/tall/service/ProjectService.java @@ -26,7 +26,7 @@ import java.util.*; @Slf4j @Service -@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class ProjectService implements IProjectService { @Autowired private SysProjectDao sysProjectDao; @@ -61,12 +61,13 @@ public class ProjectService implements IProjectService { /** * 根据名字查找此用户创建的项目 + * * @param subProject * @param currentUserId * @return */ @Override - public SysProject selectByNameAndUserId(String subProject, Long currentUserId) throws Exception{ + public SysProject selectByNameAndUserId(String subProject, Long currentUserId) throws Exception { SysProject project = new SysProject(); SysProjectExample projectExample = new SysProjectExample(); projectExample.createCriteria().andCreatorIdEqualTo(currentUserId).andNameEqualTo(subProject); @@ -79,6 +80,7 @@ public class ProjectService implements IProjectService { /** * 查找本月哪一天有项目 + * * @param currentUserId * @param date * @return @@ -87,22 +89,23 @@ public class ProjectService implements IProjectService { public List haveProjectDay(Long currentUserId, String date) throws Exception { List dateList = new ArrayList<>(); //获取日期的开始结束时间 - Map timeMap = new HashMap<>(); + Map timeMap = new HashMap<>(); timeMap = DateUtil.projectFormatDateTime(date); Long startMillisTime = timeMap.get("startMillisTime"); Long endMillisTime = timeMap.get("endMillisTime"); //查找此用户关注的项目 - List projectList = sysProjectDao.findProjectIdByUserId(currentUserId,startMillisTime,endMillisTime); - if(CollectionUtil.isNotEmpty(projectList)){ - for(SysProject sysProject:projectList){ + List projectList = sysProjectDao.findProjectIdByUserId(currentUserId, startMillisTime, endMillisTime); + if (CollectionUtil.isNotEmpty(projectList)) { + for (SysProject sysProject : projectList) { startMillisTime = sysProject.getBeginTime() > startMillisTime ? sysProject.getBeginTime() : startMillisTime; endMillisTime = sysProject.getEndTime() < endMillisTime ? sysProject.getEndTime() : endMillisTime; - dateList = getTimeList(dateList,startMillisTime,endMillisTime); + dateList = getTimeList(dateList, startMillisTime, endMillisTime); } } return dateList; } - private List getTimeList(List dateList, Long startTime,Long endTime){ + + private List getTimeList(List dateList, Long startTime, Long endTime) { SimpleDateFormat sdf = new SimpleDateFormat("dd"); Date s = new Date(startTime); Date e = new Date(endTime); @@ -113,8 +116,8 @@ public class ProjectService implements IProjectService { max.setTime(e); Calendar curr = min; while (curr.before(max)) { - for(String str:dateList){ - if(!sdf.format(min.getTime()).equalsIgnoreCase(str)){ + for (String str : dateList) { + if (!sdf.format(min.getTime()).equalsIgnoreCase(str)) { dateList.add(sdf.format(min.getTime())); } } @@ -125,6 +128,7 @@ public class ProjectService implements IProjectService { /** * 根据用户和日期查找项目 + * * @param currentUserId * @param date * @return @@ -134,13 +138,13 @@ public class ProjectService implements IProjectService { public List getProjectInfo(Long currentUserId, String date) throws Exception { List projectInfoList = new ArrayList<>(); //获取日期的开始结束时间 - Map timeMap = new HashMap<>(); + Map timeMap = new HashMap<>(); timeMap = DateUtil.projectFormatDateTime(date); Long startMillisTime = timeMap.get("startMillisTime"); Long endMillisTime = timeMap.get("endMillisTime"); //查找此用户关注的项目 - List projectList = sysProjectDao.findProjectIdByUserId(currentUserId,startMillisTime,endMillisTime); - projectInfoList = projectInfoByProject(projectList,currentUserId); + List projectList = sysProjectDao.findProjectIdByUserId(currentUserId, startMillisTime, endMillisTime); + projectInfoList = projectInfoByProject(projectList, currentUserId); // if(CollectionUtil.isNotEmpty(projectList)){ // ProjectVo.ProjectInfo projectInfo = null; // for(SysProject project:projectList){ @@ -172,17 +176,18 @@ public class ProjectService implements IProjectService { // } return projectInfoList; } - private List projectInfoByProject(List projectList, Long currentUserId){ + + private List projectInfoByProject(List projectList, Long currentUserId) { List projectInfoList = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(projectList)){ + if (CollectionUtil.isNotEmpty(projectList)) { ProjectVo.ProjectInfo projectInfo = null; - for(SysProject project:projectList){ + for (SysProject project : projectList) { projectInfo = new ProjectVo.ProjectInfo(); - BeanUtil.copyProperties(project,projectInfo); + BeanUtil.copyProperties(project, projectInfo); projectInfo.setCreator(false); projectInfo.setRoles(new ArrayList<>()); //是否是创建者 - if(project.getCreatorId().longValue()==currentUserId.longValue()){ + if (project.getCreatorId().longValue() == currentUserId.longValue()) { projectInfo.getRoles().add(WebConstant.ROLE_NAME.Creator.phase); projectInfo.setCreator(true); } @@ -193,11 +198,11 @@ public class ProjectService implements IProjectService { projectInfo.getRoles().add(proRole.getDescription()); } } - if(CollectionUtil.isEmpty(projectInfo.getRoles())){ + if (CollectionUtil.isEmpty(projectInfo.getRoles())) { projectInfo.getRoles().add(WebConstant.ROLE_NAME.Attention.phase); } //用户在项目中的最高权限 - int power = proRoleService.selectPowerByRoleName(currentUserId,project.getId()); + int power = proRoleService.selectPowerByRoleName(currentUserId, project.getId()); projectInfo.setPower(power); projectInfoList.add(projectInfo); @@ -208,7 +213,8 @@ public class ProjectService implements IProjectService { /** * 通过项目id查询项目 - * @param userId 用户id + * + * @param userId 用户id * @param projectId * @return */ @@ -216,11 +222,11 @@ public class ProjectService implements IProjectService { public ProjectVo.ProjectInfo getProjectInfoById(Long userId, Long projectId) { SysProject sysProject = sysProjectDao.selectByPrimaryKey(projectId); ProjectVo.ProjectInfo projectInfo = new ProjectVo.ProjectInfo(); - BeanUtil.copyProperties(sysProject,projectInfo); + BeanUtil.copyProperties(sysProject, projectInfo); projectInfo.setCreator(false); projectInfo.setRoles(new ArrayList<>()); //是否是创建者 - if(sysProject.getCreatorId().longValue()==userId.longValue()){ + if (sysProject.getCreatorId().longValue() == userId.longValue()) { projectInfo.getRoles().add(WebConstant.ROLE_NAME.Creator.phase); projectInfo.setCreator(true); } @@ -231,17 +237,17 @@ public class ProjectService implements IProjectService { projectInfo.getRoles().add(proRole.getDescription()); } } - if(CollectionUtil.isEmpty(projectInfo.getRoles())){ + if (CollectionUtil.isEmpty(projectInfo.getRoles())) { projectInfo.getRoles().add(WebConstant.ROLE_NAME.Attention.phase); } //用户在项目中的最高权限 - int power = proRoleService.selectPowerByRoleName(userId,projectId); + int power = proRoleService.selectPowerByRoleName(userId, projectId); projectInfo.setPower(power); //获取项目配置 ProShowExample proShowExample = new ProShowExample(); proShowExample.createCriteria().andProjectIdEqualTo(projectId); List proShowList = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(proShowList)){ + if (CollectionUtil.isNotEmpty(proShowList)) { ProjectVo.ProjectConfig projectConfig = new ProjectVo.ProjectConfig(); projectConfig.setSlide(proShowList.get(0).getSlide()); projectConfig.setFilter(proShowList.get(0).getFilter()); @@ -253,6 +259,7 @@ public class ProjectService implements IProjectService { /** * 根据类型查项目 项目类型 0普通项目 1模板项目 2常驻项目 + * * @return */ @Override @@ -275,8 +282,8 @@ public class ProjectService implements IProjectService { @Override public List getForever() { List templateProject = sysProjectDao.selectByTemplateStatus(2); - if(CollectionUtil.isNotEmpty(templateProject)){ - for(ProjectVo.TemplateStatus templateStatus:templateProject){ + if (CollectionUtil.isNotEmpty(templateProject)) { + for (ProjectVo.TemplateStatus templateStatus : templateProject) { templateStatus.setProcess(1); } } @@ -294,18 +301,18 @@ public class ProjectService implements IProjectService { //获取日期的开始结束时间 Long startMillisTime = null; Long endMillisTime = null; - Map timeMap = null; - if(StrUtil.isNotEmpty(start)){ + Map timeMap = null; + if (StrUtil.isNotEmpty(start)) { timeMap = DateUtil.projectFormatDateTime(start); startMillisTime = timeMap.get("startMillisTime"); } - if(StrUtil.isNotEmpty(end)){ + if (StrUtil.isNotEmpty(end)) { timeMap = DateUtil.projectFormatDateTime(start); endMillisTime = timeMap.get("endMillisTime"); } - List projectList = sysProjectDao.findProjectIdByUserId(currentUserId,startMillisTime,endMillisTime); + List projectList = sysProjectDao.findProjectIdByUserId(currentUserId, startMillisTime, endMillisTime); // List projectList = attentionService.findProjectIdByUserId(currentUserId); - projectInfoList = projectInfoByProject(projectList,currentUserId); + projectInfoList = projectInfoByProject(projectList, currentUserId); //关键字模糊查询和是否创建者 if (CollectionUtil.isNotEmpty(projectInfoList) && StrUtil.isNotEmpty(key)) { Iterator it = projectInfoList.iterator(); @@ -314,10 +321,10 @@ public class ProjectService implements IProjectService { if (!projectInfo.getName().contains(key)) { it.remove(); } - if(StrUtil.isNotEmpty(role)){ - if("创建者".equalsIgnoreCase(role)&&!projectInfo.isCreator()){ + if (StrUtil.isNotEmpty(role)) { + if ("创建者".equalsIgnoreCase(role) && !projectInfo.isCreator()) { it.remove(); - }else if("参与者".equalsIgnoreCase(role)&&projectInfo.isCreator()){ + } else if ("参与者".equalsIgnoreCase(role) && projectInfo.isCreator()) { it.remove(); } } @@ -366,33 +373,38 @@ public class ProjectService implements IProjectService { @Override public List getProjectByKey(Long currentUserId, String key) throws Exception { - return sysProjectDao.getProjectByKey(currentUserId,key); + return sysProjectDao.getProjectByKey(currentUserId, key); } //=========================================================================== + /** * 删除项目 */ @Override public void deleteProject(Long currentUserId, Long projectId) throws Exception { - //本用户在项目中的角色 - List proRoles = proRoleService.getProRoleByProjectIdAndUserId(projectId, currentUserId); - //用户在项目中的最高权限 - int power = proRoleService.selectPowerByRoleName(currentUserId,projectId); - if(power>1){ + SysProject project = sysProjectDao.selectByPrimaryKey(projectId); + if (ObjectUtil.isNotNull(project)) { + //用户在项目中的最高权限 + int power = proRoleService.selectPowerByRoleName(currentUserId, projectId); + if (power > 1) { // //修改项目状态 // SysProject project = sysProjectDao.selectByPrimaryKey(projectId); // project.setRecStatus((byte) 1); // sysProjectDao.updateByPrimaryKeySelective(project); - //彻底删除项目 - deleteProjectById(projectId); - }else { - throw new BaseException(CodeEnum.NOT_POWER); + //彻底删除项目 + deleteProjectById(projectId); + } else { + throw new BaseException(CodeEnum.NOT_POWER); + } + } else { + throw new BaseException(CodeEnum.NOT_PROJECT); } } + /** * 删除项目 */ - private void deleteProjectById(Long projectId){ + private void deleteProjectById(Long projectId) { //删除任务下的角色 proRoleService.deleteRoleByProjectId(projectId); //删除这个项目被关注的信息 @@ -407,13 +419,13 @@ public class ProjectService implements IProjectService { * 复制项目 */ @Override - public ProjectVo.ProjectInfo copyProject(Long userId ,Long projectId) { + public ProjectVo.ProjectInfo copyProject(Long userId, Long projectId) { ProjectVo.ProjectInfo projectInfo = new ProjectVo.ProjectInfo(); SysProject oldProject = sysProjectDao.selectByPrimaryKey(projectId); SysProject newProject = new SysProject(); - if(ObjectUtil.isNotNull(oldProject)){ - BeanUtil.copyProperties(oldProject,newProject); + if (ObjectUtil.isNotNull(oldProject)) { + BeanUtil.copyProperties(oldProject, newProject); newProject.setId(snowflake.nextId()); newProject.setCreatorId(userId); saveProject(newProject); @@ -424,8 +436,8 @@ public class ProjectService implements IProjectService { userAttention.setProjectId(newProject.getId()); attentionDao.insertSelective(userAttention); //添加角色 - copyRole(oldProject.getId(),newProject.getId()); - }else { + copyRole(oldProject.getId(), newProject.getId()); + } else { throw new BaseException(CodeEnum.NOT_PROJECT); } //返回参数 @@ -441,52 +453,54 @@ public class ProjectService implements IProjectService { return projectInfo; } + /** * 复制角色 */ - private void copyRole(Long oldProjectId,Long newProjectId){ + private void copyRole(Long oldProjectId, Long newProjectId) { //查找被复制的项目下的二级角色 - Map oldRoleMap = new HashMap<>(); - Map newRoleMap = new HashMap<>(); + Map oldRoleMap = new HashMap<>(); + Map newRoleMap = new HashMap<>(); List newRoleList = new ArrayList<>(); ProRoleExample roleExample = new ProRoleExample(); roleExample.createCriteria().andProjectIdEqualTo(oldProjectId); List oldRoleList = proRoleDao.selectByExample(roleExample); - if(CollectionUtil.isNotEmpty(oldRoleList)){ - for(ProRole oldRole:oldRoleList){ - oldRoleMap.put(oldRole.getId(),oldRole.getName()); + if (CollectionUtil.isNotEmpty(oldRoleList)) { + for (ProRole oldRole : oldRoleList) { + oldRoleMap.put(oldRole.getId(), oldRole.getName()); //创建新的角色 ProRole newRole = new ProRole(); - BeanUtil.copyProperties(oldRole,newRole); + BeanUtil.copyProperties(oldRole, newRole); newRole.setId(snowflake.nextId()); newRole.setProjectId(newProjectId); proRoleDao.insertSelective(newRole); newRoleList.add(newRole); - newRoleMap.put(newRole.getName(),newRole.getId()); + newRoleMap.put(newRole.getName(), newRole.getId()); } //修改角色的parentId - if(CollectionUtil.isNotEmpty(newRoleList)){ - for(ProRole role:newRoleList){ - if(role.getParentId() != 0){ + if (CollectionUtil.isNotEmpty(newRoleList)) { + for (ProRole role : newRoleList) { + if (role.getParentId() != 0) { role.setParentId(newRoleMap.get(oldRoleMap.get(role.getParentId()))); proRoleDao.updateByPrimaryKeySelective(role); } } } //添加对谁不可见 - copyRoleExeclude(oldRoleList,oldRoleMap,newRoleMap); + copyRoleExeclude(oldRoleList, oldRoleMap, newRoleMap); //复制任务 - copyTask(oldProjectId,newProjectId,oldRoleMap,newRoleMap); + copyTask(oldProjectId, newProjectId, oldRoleMap, newRoleMap); } } - private void copyRoleExeclude(List oldRoleList, Map oldRoleMap, Map newRoleMap){ - if(CollectionUtil.isNotEmpty(oldRoleList)) { + + private void copyRoleExeclude(List oldRoleList, Map oldRoleMap, Map newRoleMap) { + if (CollectionUtil.isNotEmpty(oldRoleList)) { for (ProRole oldRole : oldRoleList) { ProRoleExcludeExample execludeExample = new ProRoleExcludeExample(); execludeExample.createCriteria().andRoleIdEqualTo(oldRole.getId()); List roleExecludeList = roleExcludeDao.selectByExample(execludeExample); - if(CollectionUtil.isNotEmpty(roleExecludeList)){ - for(ProRoleExclude roleExeclude:roleExecludeList){ + if (CollectionUtil.isNotEmpty(roleExecludeList)) { + for (ProRoleExclude roleExeclude : roleExecludeList) { ProRoleExclude newRoleExeclude = new ProRoleExclude(); newRoleExeclude.setRoleId(newRoleMap.get(oldRoleMap.get(roleExeclude.getRoleId()))); newRoleExeclude.setOtherRoleId(newRoleMap.get(oldRoleMap.get(roleExeclude.getRoleId()))); @@ -500,18 +514,18 @@ public class ProjectService implements IProjectService { /** * 复制任务 */ - private void copyTask(Long oldProjectId,Long newProjectId,Map oldRoleMap, Map newRoleMap){ + private void copyTask(Long oldProjectId, Long newProjectId, Map oldRoleMap, Map newRoleMap) { ProTaskDetailExample detailExample = new ProTaskDetailExample(); detailExample.createCriteria().andProjectIdEqualTo(oldProjectId).andLevelEqualTo((byte) 1); List detailList = taskDetailDao.selectByExample(detailExample); - if(CollectionUtil.isNotEmpty(detailList)){ - for(ProTaskDetail oldDetail: detailList){ + if (CollectionUtil.isNotEmpty(detailList)) { + for (ProTaskDetail oldDetail : detailList) { ProTaskDetail newDetail = new ProTaskDetail(); - BeanUtil.copyProperties(oldDetail,newDetail); + BeanUtil.copyProperties(oldDetail, newDetail); newDetail.setId(snowflake.nextId()); newDetail.setProjectId(newProjectId); newDetail.setExecutorRole(newRoleMap.get(oldRoleMap.get(newDetail.getExecutorRole()))); - if(newDetail.getCheckerRole() != 0){ + if (newDetail.getCheckerRole() != 0) { newDetail.setCheckerRole(newRoleMap.get(oldRoleMap.get(newDetail.getCheckerRole()))); } taskDetailDao.insertSelective(newDetail); @@ -519,15 +533,15 @@ public class ProjectService implements IProjectService { ProTaskDetailExample oldSecondTask = new ProTaskDetailExample(); oldSecondTask.createCriteria().andParentIdEqualTo(oldDetail.getId()).andLevelEqualTo((byte) 2); List secondTaskList = taskDetailDao.selectByExample(oldSecondTask); - if(CollectionUtil.isNotEmpty(secondTaskList)){ - for(ProTaskDetail oldSecondDetail: secondTaskList){ + if (CollectionUtil.isNotEmpty(secondTaskList)) { + for (ProTaskDetail oldSecondDetail : secondTaskList) { ProTaskDetail newSecondDetail = new ProTaskDetail(); - BeanUtil.copyProperties(oldSecondDetail,newSecondDetail); + BeanUtil.copyProperties(oldSecondDetail, newSecondDetail); newSecondDetail.setId(snowflake.nextId()); newSecondDetail.setProjectId(newProjectId); newSecondDetail.setParentId(newDetail.getId()); newSecondDetail.setExecutorRole(newRoleMap.get(oldRoleMap.get(newSecondDetail.getExecutorRole()))); - if(newSecondDetail.getCheckerRole() != 0){ + if (newSecondDetail.getCheckerRole() != 0) { newSecondDetail.setCheckerRole(newRoleMap.get(oldRoleMap.get(newSecondDetail.getCheckerRole()))); } taskDetailDao.insertSelective(newSecondDetail); @@ -537,27 +551,27 @@ public class ProjectService implements IProjectService { ProTaskDetailExample oldSubTask = new ProTaskDetailExample(); oldSubTask.createCriteria().andParentIdEqualTo(oldSecondDetail.getId()).andLevelEqualTo((byte) 3); List subTaskList = taskDetailDao.selectByExample(oldSubTask); - if(CollectionUtil.isNotEmpty(subTaskList)){ - for(ProTaskDetail oldSubDetail: subTaskList){ + if (CollectionUtil.isNotEmpty(subTaskList)) { + for (ProTaskDetail oldSubDetail : subTaskList) { ProTaskDetail newSubDetail = new ProTaskDetail(); - BeanUtil.copyProperties(oldSubDetail,newSubDetail); + BeanUtil.copyProperties(oldSubDetail, newSubDetail); newSubDetail.setId(snowflake.nextId()); newSubDetail.setProjectId(newProjectId); newSubDetail.setParentId(newSecondDetail.getId()); newSubDetail.setExecutorRole(newRoleMap.get(oldRoleMap.get(newSubDetail.getExecutorRole()))); - if(newSubDetail.getCheckerRole() != 0){ + if (newSubDetail.getCheckerRole() != 0) { newSubDetail.setCheckerRole(newRoleMap.get(oldRoleMap.get(newSubDetail.getCheckerRole()))); } taskDetailDao.insertSelective(newSubDetail); //分解时间 taskToSubTime(newSubDetail); - copyPluginAndDeliver(oldDetail.getId(),newDetail.getId(),oldRoleMap,newRoleMap); + copyPluginAndDeliver(oldDetail.getId(), newDetail.getId(), oldRoleMap, newRoleMap); } } - copyPluginAndDeliver(oldDetail.getId(),newDetail.getId(),oldRoleMap,newRoleMap); + copyPluginAndDeliver(oldDetail.getId(), newDetail.getId(), oldRoleMap, newRoleMap); } } - copyPluginAndDeliver(oldDetail.getId(),newDetail.getId(),oldRoleMap,newRoleMap); + copyPluginAndDeliver(oldDetail.getId(), newDetail.getId(), oldRoleMap, newRoleMap); } } } @@ -565,9 +579,9 @@ public class ProjectService implements IProjectService { /** * 根据时间分解任务 */ - private void taskToSubTime(ProTaskDetail taskDetail){ + private void taskToSubTime(ProTaskDetail taskDetail) { //cycle为空,只加一条数据 - if(ObjectUtil.isNotNull(taskDetail)) { + if (ObjectUtil.isNotNull(taskDetail)) { if (StrUtil.isEmpty(taskDetail.getCycle())) { ProTaskSubTime proTaskSubTime = new ProTaskSubTime(); proTaskSubTime.setId(snowflake.nextId()); @@ -597,15 +611,15 @@ public class ProjectService implements IProjectService { /** * 复制插件和交付物 */ - private void copyPluginAndDeliver(Long oldTaskId,Long newTaskId,Map oldRoleMap, Map newRoleMap){ + private void copyPluginAndDeliver(Long oldTaskId, Long newTaskId, Map oldRoleMap, Map newRoleMap) { //插件 ProTaskPluginExample pluginExample = new ProTaskPluginExample(); pluginExample.createCriteria().andTaskDetailIdEqualTo(oldTaskId); List pluginList = pluginDao.selectByExample(pluginExample); - if(CollectionUtil.isNotEmpty(pluginList)){ - for(ProTaskPlugin plugin:pluginList){ + if (CollectionUtil.isNotEmpty(pluginList)) { + for (ProTaskPlugin plugin : pluginList) { ProTaskPlugin newPlugin = new ProTaskPlugin(); - BeanUtil.copyProperties(plugin,newPlugin); + BeanUtil.copyProperties(plugin, newPlugin); newPlugin.setId(snowflake.nextId()); newPlugin.setTaskDetailId(newTaskId); newPlugin.setMemberRoleId(newRoleMap.get(oldRoleMap.get(newPlugin.getMemberRoleId()))); @@ -616,10 +630,10 @@ public class ProjectService implements IProjectService { ProTaskDeliverExample deliverExample = new ProTaskDeliverExample(); deliverExample.createCriteria().andTaskDetailIdEqualTo(oldTaskId); List proTaskDeliverList = taskDeliverDao.selectByExample(deliverExample); - if(CollectionUtil.isNotEmpty(proTaskDeliverList)){ - for(ProTaskDeliver taskDeliver:proTaskDeliverList){ + if (CollectionUtil.isNotEmpty(proTaskDeliverList)) { + for (ProTaskDeliver taskDeliver : proTaskDeliverList) { ProTaskDeliver newTaskDeliver = new ProTaskDeliver(); - BeanUtil.copyProperties(taskDeliver,newTaskDeliver); + BeanUtil.copyProperties(taskDeliver, newTaskDeliver); newTaskDeliver.setId(snowflake.nextId()); newTaskDeliver.setTaskDetailId(newTaskId); newTaskDeliver.setCheckStatus(0); diff --git a/tall/src/main/java/com/ccsens/tall/web/UserController.java b/tall/src/main/java/com/ccsens/tall/web/UserController.java index 6cd0fd03..ce8b64f2 100644 --- a/tall/src/main/java/com/ccsens/tall/web/UserController.java +++ b/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 getNodeMessage(@RequestParam(required = true) String token) throws Exception { + @RequestMapping(value = "claims",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) + public JsonResponse 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 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); + } }