package com.oying.modules.security.rest; import com.oying.modules.security.service.OnlineUserService; import com.oying.modules.security.service.dto.OnlineUserDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import com.oying.utils.EncryptUtils; import com.oying.utils.PageResult; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Set; /** * @author Z */ @RestController @RequiredArgsConstructor @RequestMapping("/auth/online") @Api(tags = "系统:在线用户管理") public class OnlineController { private final OnlineUserService onlineUserService; @ApiOperation("查询在线用户") @GetMapping @PreAuthorize("@el.check()") public ResponseEntity> queryOnlineUser(String username, Pageable pageable){ return new ResponseEntity<>(onlineUserService.getAll(username, pageable),HttpStatus.OK); } @ApiOperation("导出数据") @GetMapping(value = "/download") @PreAuthorize("@el.check()") public void exportOnlineUser(HttpServletResponse response, String username) throws IOException { onlineUserService.download(onlineUserService.getAll(username), response); } @ApiOperation("踢出用户") @DeleteMapping @PreAuthorize("@el.check()") public ResponseEntity deleteOnlineUser(@RequestBody Set keys) throws Exception { for (String token : keys) { // 解密Key token = EncryptUtils.desDecrypt(token); onlineUserService.logout(token); } return new ResponseEntity<>(HttpStatus.OK); } }