| | |
| | | import com.moon.server.entity.all.ResponseMsg; |
| | | import com.moon.server.entity.sys.TokenEntity; |
| | | import com.moon.server.entity.sys.UserEntity; |
| | | import com.moon.server.helper.StringHelper; |
| | | import com.moon.server.service.sys.TokenService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "插入多条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "List<TokenEntity>", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/insertTokens", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<Integer> insertTokens(@RequestBody List<TokenEntity> list, HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | for (TokenEntity entity : list) { |
| | | entity.setCreateUser(ue.getId()); |
| | | } |
| | | } |
| | | |
| | | int count = tokenService.insertTokens(list); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "删除一条") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") |
| | |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID更新令牌为失效") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "令牌ID", dataType = "Integer", paramType = "query", example = "6563") |
| | | }) |
| | | @GetMapping(value = "/updateExpireById") |
| | | public ResponseMsg<Integer> updateExpireById(Integer id, HttpServletRequest req) { |
| | | try { |
| | | if (null == id || id < 0) { |
| | | return fail("id参数无效", 0); |
| | | } |
| | | TokenEntity entity = tokenService.selectOneById(id); |
| | | if (null == entity) { |
| | | return fail("该id不存在", 0); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | entity.setUpdateUser(ue.getId()); |
| | | int count = tokenService.updateTokenExpire(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据Token更新令牌为失效") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tk", value = "令牌", dataType = "String", paramType = "query", example = "2edea2a2-e307-4baa-992c-b477ce0566dd") |
| | | }) |
| | | @GetMapping(value = "/updateExpireByToken") |
| | | public ResponseMsg<Integer> updateExpireByToken(String tk, HttpServletRequest req) { |
| | | try { |
| | | if (StringHelper.isEmpty(tk)) { |
| | | return fail("token参数无效", 0); |
| | | } |
| | | TokenEntity entity = tokenService.selectOneByToken(tk); |
| | | if (null == entity) { |
| | | return fail("该token不存在或已失效", 0); |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | entity.setUpdateUser(ue.getId()); |
| | | int count = tokenService.updateTokenExpire(entity); |
| | | |
| | | return success(count); |
| | | } catch (Exception ex) { |
| | | return fail(ex, -1); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1658") |
| | |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据ID查询(有效期内的)") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "6563") |
| | | }) |
| | | @GetMapping(value = "/selectOneById") |
| | | public ResponseMsg<TokenEntity> selectOneById(Integer id) { |
| | | try { |
| | | if (null == id || id < 0) { |
| | | return fail("id参数无效", null); |
| | | } |
| | | TokenEntity tokenEntity = tokenService.selectOneById(id); |
| | | |
| | | return success(tokenEntity); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据token查询(有效期内的)") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tk", value = "令牌", dataType = "String", paramType = "query", example = "2edea2a2-e307-4baa-992c-b477ce0566dd") |
| | | }) |
| | | @GetMapping(value = "/selectOneByToken") |
| | | public ResponseMsg<TokenEntity> selectOneByToken(String tk) { |
| | | try { |
| | | if (StringHelper.isEmpty(tk)) { |
| | | return fail("token参数无效", null); |
| | | } |
| | | TokenEntity tokenEntity = tokenService.selectOneByToken(tk); |
| | | |
| | | return success(tokenEntity); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | } |