| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.cache.CacheNames; |
| | | import org.springblade.common.config.ServerConfig; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.jwt.JwtUtil; |
| | | import org.springblade.core.jwt.props.JwtProperties; |
| | |
| | | import org.springblade.modules.exam.entity.ExamPaper; |
| | | import org.springblade.modules.exam.service.ExamPaperService; |
| | | import org.springblade.modules.exam.vo.ExamPaperVO; |
| | | import org.springblade.modules.loginrecord.entity.LoginRecord; |
| | | import org.springblade.modules.loginrecord.service.LoginRecordService; |
| | | import org.springblade.modules.system.entity.UserInfo; |
| | | import org.springblade.modules.zc.service.IZcService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.time.Duration; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | |
| | | private final JwtProperties jwtProperties; |
| | | private final IZcService iZcService; |
| | | private final ExamPaperService examPaperService; |
| | | |
| | | private final LoginRecordService loginRecordService; |
| | | |
| | | private final ServerConfig serverConfig; |
| | | |
| | | /** |
| | | * 登录 |
| | |
| | | if (loginType.equals(1)) { |
| | | //判断角色 |
| | | if (!userInfo.getRoles().get(0).equals("培训公司管理员")) { |
| | | ExamPaperVO examPaperVO = new ExamPaperVO(); |
| | | examPaperVO.setUserId(userInfo.getUser().getId().toString()); |
| | | //查询考生考试信息 |
| | | List<ExamPaperVO> examDetail = examPaperService.getExamDetail(userInfo.getUser().getId().toString()); |
| | | List<ExamPaperVO> examDetail = examPaperService.getExamDetail(examPaperVO); |
| | | if (examDetail.size()==0) { |
| | | return authInfo.set("error_description", "当前没有查询到考试信息"); |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | System.out.println("grantType = " + grantType); |
| | | //刷新 token 不新增登录记录 |
| | | if (!grantType.equals("refresh_token")){ |
| | | //新增登录记录 |
| | | this.saveLoginRecord(userInfo); |
| | | } |
| | | } |
| | | return TokenUtil.createAuthInfo(userInfo); |
| | | } |
| | | |
| | | /** |
| | | * 新增登录记录信息 |
| | | * @param userInfo |
| | | */ |
| | | private void saveLoginRecord(UserInfo userInfo) { |
| | | //创建对象 |
| | | LoginRecord loginRecord = new LoginRecord(); |
| | | //request 对象获取 |
| | | ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
| | | HttpServletRequest request = requestAttributes.getRequest(); |
| | | //数据封装 |
| | | loginRecord.setCreateTime(new Date()); |
| | | loginRecord.setServerIp(serverConfig.getServerIp()); |
| | | loginRecord.setServerHost(serverConfig.getServerHostName()); |
| | | loginRecord.setRequestUri(request.getRequestURI()); |
| | | loginRecord.setRemoteIp(request.getRemoteAddr()); |
| | | loginRecord.setDeptId(userInfo.getUser().getDeptId()); |
| | | loginRecord.setUserId(userInfo.getUser().getId()); |
| | | loginRecord.setType("1"); |
| | | loginRecord.setCreateBy(userInfo.getUser().getRealName()); |
| | | //新增 |
| | | loginRecordService.save(loginRecord); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/oauth/logout") |
| | | @ApiOperation(value = "退出登录") |